JNIEXPORT void JNICALL Java_org_embedded_browser_Chromium_browser_1new
  (JNIEnv *env, jobject jobj, jlong hwnd, jint id, jstring url, jobject chromiumset)
{
  const char* chr = env->GetStringUTFChars(url, 0);
  CefString wc = chr;

  GtkWidget* canvas = (GtkWidget*)hwnd;
  GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
  gtk_fixed_put(GTK_FIXED(canvas), vbox, 0, 0);

  CefRefPtr<ClientHandler> gh = NewBrowser(vbox, wc);
  gh->id = id;
  gh->vbox = vbox;
  env->ReleaseStringUTFChars(url, chr);
  send_handler(env, jobj, (jlong)(void*)gh);
  get_browser_settings(env, chromiumset, gh->csettings);
}
JNIEXPORT void JNICALL Java_org_embedded_browser_Chromium_browser_1init
  (JNIEnv *env, jobject jobj, jlong hwnd, jstring url, jobject chromiumset)
{
  // Make a simple argument.
  const int argc = 1;
  char** argv = (char**)malloc(argc * sizeof(*argv));
  argv[0] = strdup("java");

  CefMainArgs main_args(argc, argv);
  CefRefPtr<ClientApp> app(new ClientApp);

  // Retrieve the current working directory.
  szWorkingDir = getenv("WSO2_DEVELOPER_STUDIO_PATH");
  if (!szWorkingDir)
    szWorkingDir = (char*)calloc(1, sizeof(char));

  // Parse command line arguments. The passed in values are ignored on Windows.
  AppInitCommandLine(argc, argv);

  CefSettings settings;

  // Populate the settings based on command line arguments.
  AppGetSettings(settings);

  settings.multi_threaded_message_loop = message_loop;
  settings.log_severity = LOGSEVERITY_DISABLE;
  settings.no_sandbox = true;

  CefString path = CefString(szWorkingDir);

#ifndef __LP64__
  CefString(&settings.browser_subprocess_path) = path.ToString() + "/cef/cefclient";
  CefString(&settings.resources_dir_path) = path.ToString() + "/cef";
  CefString(&settings.locales_dir_path) = path.ToString() + "/cef/locales";
#else
  CefString(&settings.browser_subprocess_path) = path.ToString() + "/cef/cefclient";
  CefString(&settings.resources_dir_path) = path.ToString() + "/cef";
  CefString(&settings.locales_dir_path) = path.ToString() + "/cef/locales";
#endif

  BackupSignalHandlers();

  // Initialize CEF.
  CefInitialize(main_args, settings, app.get(), NULL);

  RestoreSignalHandlers();

  GtkWidget* canvas = (GtkWidget*)hwnd;
  GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
  gtk_fixed_put(GTK_FIXED(canvas), vbox, 0, 0);

  const char* chr = env->GetStringUTFChars(url, 0);
  CefString wc = chr;

  CefRefPtr<ClientHandler> gh = InitBrowser(vbox, wc);
  gh->id = 1;
  gh->vbox = vbox;

  env->ReleaseStringUTFChars(url, chr);

  // NOTE: This function (browser_init) should only be called ONCE in one process,
  // which means to call CefInitialize in the first broswer creation, and call 
  // CefShutdown in the exit of the process. Repeated calls to this function will 
  // NOT work, because the web page will not render. Most probably a bug in cef.
  set_jvm(env, jobj);
  send_handler(env, jobj, (jlong)(void*)gh);

  // Have to be here and use own jnienv to avoid errors.
  get_browser_settings(env, chromiumset, gh->csettings);

  //CefRunMessageLoop();
  //CefShutdown();
}
Esempio n. 3
0
JNIEXPORT jlong JNICALL Java_org_embedded_browser_Chromium_browser_1init
(JNIEnv *env, jobject jobj, jlong hwnd, jstring url, jobject chromiumset)
{
    // Make a simple argument.
    const int argc = 1;
    char** argv = (char**)malloc(argc * sizeof(*argv));
    argv[0] = strdup("java");

    CefMainArgs main_args(argc, argv);
    CefRefPtr<ClientApp> app(new ClientApp);
    CefSettings settings;

    // Execute the secondary process, if any.
    int exit_code = CefExecuteProcess(main_args, app.get());
    if (exit_code >= 0)
        return exit_code;

    // Parse command line arguments. The passed in values are ignored on Windows.
    AppInitCommandLine(argc, argv);

    // Populate the settings based on command line arguments.
    AppGetSettings(settings);

    // Initialize CEF.
    CefInitialize(main_args, settings, app.get());

    GtkWidget* canvas = (GtkWidget*)hwnd;
    GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
    gtk_fixed_put(GTK_FIXED(canvas), vbox, 0, 0);

    //GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL);
    //GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
    //gtk_container_add(GTK_CONTAINER(scroll_window), vbox);
    //gtk_fixed_put(GTK_FIXED(canvas), scroll_window, 0, 0);

    set_java_env(env, jobj);

    const char* chr = env->GetStringUTFChars(url, 0);
    CefString wc = chr;

    CefRefPtr<ClientHandler> gh = InitBrowser(vbox, wc);
    gh->id = 1;

    env->ReleaseStringUTFChars(url, chr);

    // NOTE: This function (browser_init) should only be called ONCE in one process,
    // which means to call CefInitialize in the first broswer creation, and call
    // CefShutdown in the exit of the process. Repeated calls to this function will
    // NOT work, because the web page will not render. Most probably a bug in cef.
    send_handler(env, jobj, (jlong)(void*)gh);

    // Have to be here and use own jnienv to avoid errors.
    get_browser_settings(env, chromiumset, gh->csettings);

    //signal(SIGINT, TerminationSignalHandler);
    //signal(SIGTERM, TerminationSignalHandler);

    //CefRunMessageLoop();
    //CefShutdown();
    return (jlong)vbox;
}