JNIEXPORT void JNICALL Java_org_embedded_browser_Chromium_browser_1init
(JNIEnv *env, jobject jobj, jlong hwnd, jstring url, jobject chromiumset)
{
// Enable High-DPI support on Windows 7 or newer.
//CefEnableHighDPISupport();
CefMainArgs main_args(GetModuleHandle(NULL));
CefRefPtr<client::ClientApp> app(new client::ClientAppBrowser);
// Parse command line arguments. The passed in values are ignored on Windows.
//AppInitCommandLine(0, NULL);
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
command_line->InitFromString(::GetCommandLineW());
// Create the main context object.
scoped_ptr<client::MainContextImpl> context(new client::MainContextImpl(command_line, false));
CefSettings settings;
// Populate the settings based on command line arguments.
//AppGetSettings(settings);
// Populate the settings based on argument provided from Java
populate_cef_settings(env, chromiumset, settings);
// if set to true, the process crashes in SWT
settings.multi_threaded_message_loop = false;
// Initialize CEF.
//CefInitialize(main_args, settings, app.get(), NULL);
context->Initialize(main_args, settings, app.get(), NULL);
HWND hMain;
hMain = (HWND)((void*)hwnd);
const char* chr = env->GetStringUTFChars(url, 0);
CefString wc = chr;
CefRefPtr<ClientHandler> gh = NewBrowser(hMain, 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 browser 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);
if (gh->csettings.run_modal_message_loop_in_init) {
// Run the CEF message loop. This function will block until the application
// recieves a WM_QUIT message.
message_loop = new client::MainMessageLoopStd;
message_loop->Run();
//CefRunMessageLoop();
cleanup_jvm(env);
//CefShutdown();
context->Shutdown();
}
DLOG(INFO) << "Exit init method!";
}
CEF_GLOBAL bool CefInitialize(const CefMainArgs& args,
const CefSettings& settings, CefRefPtr<CefApp> application,
void* windows_sandbox_info) {
const char* api_hash = cef_api_hash(0);
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: application, windows_sandbox_info
// Execute
int _retval = cef_initialize(
&args,
&settings,
CefAppCppToC::Wrap(application),
windows_sandbox_info);
return _retval?true:false;
}
Users browsing this forum: No registered users and 18 guests