JNIEXPORT jboolean JNICALL Java_org_cef_callback_CefSchemeRegistrar_1N_N_1AddCustomScheme
  (JNIEnv *env, jobject obj, jstring jSchemeName, jboolean jIsStandard, 
   jboolean jIsLocal, jboolean jIsDisplayIsolated) {

  CefRefPtr<CefSchemeRegistrar> registrar =
      GetCefFromJNIObject<CefSchemeRegistrar>(env, obj, "CefSchemeRegistrar");
  if (!registrar.get())
    return JNI_FALSE;
  CefString schemeName = GetJNIString(env, jSchemeName);
  bool result = registrar->AddCustomScheme(schemeName,
                                           jIsStandard != JNI_FALSE,
                                           jIsLocal != JNI_FALSE,
                                           jIsDisplayIsolated != JNI_FALSE);
  if (!result)
    return JNI_FALSE;

  // The registered scheme has to be forwarded to all other processes which will
  // be created by the browser process (e.g. the render-process). Otherwise
  // things like JS "localStorage" get/set will end up in a crashed
  // render process.
  std::string tmpName = util::GetTempFileName("scheme", false);

  std::ofstream fStream(tmpName.c_str(), std::ofstream::out |
      std::ofstream::app);

  if (fStream.is_open()) {
    // 1) Write the scheme name and the params to the file.
    fStream << schemeName.ToString().c_str() << "," <<
        (jIsStandard != JNI_FALSE) << (jIsLocal != JNI_FALSE) <<
        (jIsDisplayIsolated != JNI_FALSE);
    fStream.close();

    // 2) Register file to be deleted in CefShutdown()
    ClientApp::registerTempFile(tmpName);
  }
  return JNI_TRUE;
}
Ejemplo n.º 2
0
//////////////////////////////////////////////////////////////
//                CefApp implementation                     //
//////////////////////////////////////////////////////////////
void CCefApp::OnRegisterCustomSchemes ( CefRefPtr < CefSchemeRegistrar > registrar )
{
    // Register custom MTA scheme (has to be called in all proceseses)
    registrar->AddCustomScheme ( "mtalocal", false, false, false );
}