bool ClientPrintHandlerGtk::OnPrintJob(
    const CefString& document_name,
    const CefString& pdf_file_path,
    CefRefPtr<CefPrintJobCallback> callback) {
  // If |printer_| is NULL then somehow the GTK printer list changed out under
  // us. In which case, just bail out.
  if (!printer_)
    return false;

  job_callback_ = callback;

  // Save the settings for next time.
  GetLastUsedSettings()->SetLastUsedSettings(gtk_settings_);

  GtkPrintJob* print_job = gtk_print_job_new(
      document_name.ToString().c_str(),
      printer_,
      gtk_settings_,
      page_setup_);
  gtk_print_job_set_source_file(print_job,
                                pdf_file_path.ToString().c_str(),
                                NULL);
  gtk_print_job_send(print_job, OnJobCompletedThunk, this, NULL);

  return true;
}
Пример #2
0
// Called due to cefQuery execution in binding.html.
bool QueryHandler::OnQuery(CefRefPtr<CefBrowser> browser,
                           CefRefPtr<CefFrame> frame,
                           int64 query_id,
                           const CefString& request,
                           bool persistent,
                           CefRefPtr<Callback> callback) {
  try {
    auto query = createQuery(browser, frame, request.ToString());

    if (!query)
      return false;

    CefPostTask(TID_FILE, base::Bind(&Query::execute, query, callback));
  } catch (std::exception& e) {
    auto logger = lootState_.getLogger();
    if (logger) {
      logger->error("Failed to parse CEF query request \"{}\": {}",
        request.ToString(),
        e.what());
    }
    callback->Failure(-1, e.what());
  }

  return true;
}
Пример #3
0
void TransparentWnd::Download(CefString url,CefString filename){
	std::stringstream ss;
	string s=url.ToString();
	ss<<"var img = new Image();"
		<<"img.src='"<<url.ToString();
	if(s.find("?")==string::npos){
		ss<<"?t='+Date.now()+'&AlloyDesktop_download=";
	}
	else{
		ss<<"&AlloyDesktop_download=";
	}
	ss<<filename.ToString()<<"';";
	this->ExecJS(ss.str());
}
CefString CefControlBase::GetMainURL(const CefString& url)
{
	std::string temp = url.ToString();
	int end_pos = temp.find("#") == std::string::npos ? temp.length() : temp.find("#");
	temp = temp.substr(0, end_pos);
	return CefString(temp.c_str());
}
Пример #5
0
CefString CaffeineClientApp::decrypt(const CefString &blob)
{
    string ConvertedData = blob.ToString();
    string retval;

    BYTE B64DecodeBuf[B64_BUFFER_LEN] = {0,};
    int B64DecodeBufLen = B64_BUFFER_LEN;

    if (Base64Decode(ConvertedData.data(), ConvertedData.length(), B64DecodeBuf, &B64DecodeBufLen))
    {
        DATA_BLOB DataIn = {0,};
        DATA_BLOB DataOut = {0,};

        DataIn.pbData = B64DecodeBuf;
        DataIn.cbData = B64DecodeBufLen;

        if(CryptUnprotectData(&DataIn, NULL, NULL, NULL, NULL, 0, &DataOut))
        {
            retval = string(reinterpret_cast<char *>(DataOut.pbData), static_cast<size_t>(DataOut.cbData));
            LocalFree(DataOut.pbData);
        }
    }

    return retval;
}
Пример #6
0
//  TODO:  Dynamically size the base64 buffers
string CaffeineClientApp::encrypt(const CefString &plaintext)
{
    DATA_BLOB DataIn = {0,};
    DATA_BLOB DataOut = {0,};
    string ConvertedData = plaintext.ToString();
    string retval;
    
    DataIn.pbData = reinterpret_cast<BYTE *>(const_cast<char *>(ConvertedData.data()));
    DataIn.cbData = ConvertedData.length();

    string temp;

    if(CryptProtectData(&DataIn, TEXT("Login Token"), NULL, NULL, NULL, 0, &DataOut))
    {
        char B64Buf[B64_BUFFER_LEN] = {0,};
        int B64BufLen = B64_BUFFER_LEN;

        if (Base64Encode(DataOut.pbData, DataOut.cbData, B64Buf, &B64BufLen, ATL_BASE64_FLAG_NOCRLF))
        {
            retval = string(B64Buf);
        }

        LocalFree(DataOut.pbData);
    }

    return retval;
}
void CWebBrowserDownloadHandler::OnBeforeDownload(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDownloadItem> download_item,
                                                  const CefString& suggested_name, CefRefPtr<CefBeforeDownloadCallback> callback)
{
  std::string suggestedName = suggested_name.ToString();
  std::string url = download_item->GetOriginalUrl().ToString();
  int64 totalBytes = download_item->GetTotalBytes();
  std::thread(OnBeforeDownloadProcess, this, url, totalBytes, suggestedName, callback).detach();
}
Пример #8
0
bool ClientHandler::OnJSDialog(CefRefPtr<CefBrowser> browser, const CefString& origin_url, 
								const CefString& accept_lang, JSDialogType dialog_type, 
								const CefString& message_text, const CefString& default_prompt_text, 
								CefRefPtr<CefJSDialogCallback> callback, bool& suppress_message)
{
	RLOG(message_text.ToString().c_str());
	return false;
}
Пример #9
0
void BrowserClient::OnTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title)
{
    osgViewer::Viewer::Windows ViewerWindow; 
    _viewer->getWindows(ViewerWindow); 

    if (!ViewerWindow.empty()) 
    { 
        ViewerWindow.front()->setWindowName(title.ToString()); 
    }
}
Пример #10
0
void TransparentWnd::CreateBrowserWindowBase(CefString path, UINT ex_style, bool isTransparent){
	TCHAR   szPath[1000];   
	GetModuleFileName(NULL,szPath,MAX_PATH);
	wstring _path(szPath);
	_path=_path.substr(0,_path.find_last_of('\\')+1);
	replace_allW(_path, L"\\", L"/");
	CefString pathC(_path);
	std::stringstream ss;
	ss<<pathC.ToString().c_str()<<path.ToString().c_str();
	CefString s(ss.str());
	CreateBrowserWindow(s, ex_style, isTransparent);
}
Пример #11
0
	void IBrowserHandler::OnAddressChange(	CefRefPtr<CefBrowser>	browser, 
											CefRefPtr<CefFrame>		frame, 
											const CefString			&url)
	{
		REQUIRE_UI_THREAD();

		if(m_browserId == browser->GetIdentifier() && frame->IsMain())
		{
			// ::SetWindowText(m_editHwnd, std::wstring(url).c_str());
			SignalsSlots::GetCurrentSignals()->SetCurrentTittle(url.ToString());
		}
	}
Пример #12
0
	void IBrowserHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
									  const CefString& title) 
	{
		REQUIRE_UI_THREAD();

		CefWindowHandle hwnd = browser->GetHost()->GetWindowHandle();
		if(m_browserId == browser->GetIdentifier())
		{
			hwnd = ::GetParent(::GetParent(hwnd));
		}
		// ::SetWindowText(hwnd, std::wstring(title).c_str());
		SignalsSlots::GetCurrentSignals()->SetCurrentTittle(title.ToString());
	}
Пример #13
0
void TransparentWnd::replaceRequest(CefString request, LPVOID pParam){
	EnterCriticalSection(&cs);
	MelodyProxy::ProxyParam* pProxyParam=(MelodyProxy::ProxyParam*)pParam;
	if(IsBadReadPtr(pProxyParam,sizeof(MelodyProxy::ProxyParam))){
		LeaveCriticalSection(&cs);
		return;
	}
	pProxyParam->isReplaceRequest=true;
	strcpy(pProxyParam->Request,request.ToString().c_str());
	::PulseEvent(pProxyParam->ResponseOK);
	::WaitForSingleObject(pProxyParam->ResponseEnd,3000);
	LeaveCriticalSection(&cs);
}
Пример #14
0
void TransparentWnd::CreateBrowser(CefString url, CefString param){
	HANDLE m_hRead;
	HANDLE m_hWrite;
	SECURITY_ATTRIBUTES sa;   // 父进程传递给子进程的一些信息
	sa.bInheritHandle = TRUE; // 还记得我上面的提醒吧,这个来允许子进程继承父进程的管道句柄
	sa.lpSecurityDescriptor = NULL;
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);
	if (!CreatePipe(&m_hRead, &m_hWrite, &sa, 0))
	{
		return;
	}

	STARTUPINFO sui;    
	PROCESS_INFORMATION pi; // 保存了所创建子进程的信息
	ZeroMemory(&sui, sizeof(STARTUPINFO)); // 对一个内存区清零,最好用ZeroMemory, 它的速度要快于memset
	sui.cb = sizeof(STARTUPINFO);
	sui.dwFlags = STARTF_USESTDHANDLES;

	sui.hStdInput = m_hRead;
	sui.hStdOutput = m_hWrite;
	/* 以上两行也许大家要有些疑问,为什么把管道读句柄(m_hRead)赋值给了hStdInput, 因为管道是双向的,对于父进程写的一端正好是子进程读的一端,而m_hRead就是父进程中对管道读的一端, 自然要把这个句柄给子进程让它来写数据了(sui是父进程传给子进程的数据结构,里面包含了一些父进程要告诉子进程的一些信息),反之一样*/
	sui.hStdError = GetStdHandle(STD_ERROR_HANDLE);
	TCHAR   szPath[1000];   
	GetModuleFileName(NULL,szPath,MAX_PATH);
	DWORD d;
	if(::WriteFile(m_hWrite,param.ToString().c_str(),strlen(param.ToString().c_str()),&d,NULL)==FALSE){
		MessageBox(NULL,L"写入失败",L"错误",0);
	}
	if (!CreateProcess(szPath, (LPWSTR)url.ToWString().c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &sui, &pi))
	{
		CloseHandle(m_hRead);
		CloseHandle(m_hWrite);
	}
	else
	{
		CloseHandle(pi.hProcess); // 子进程的进程句柄
		CloseHandle(pi.hThread); // 子进程的线程句柄,windows中进程就是一个线程的容器,每个进程至少有一个线程在执行
	}
}
Пример #15
0
bool CSJsSocket::Connect(const CefString &hostname, int port)
{
    int s = socket(AF_INET, SOCK_STREAM, 0);
    struct hostent *he;
    struct sockaddr_in saddr = {0};
    
    saddr.sin_addr.s_addr = inet_addr(hostname.ToString().c_str());
    if (saddr.sin_addr.s_addr == INADDR_NONE)
    {
        he = gethostbyname(hostname.ToString().c_str());
        if (he)
            memcpy(&saddr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
    }
    
    saddr.sin_port = htons(port);
	saddr.sin_family = AF_INET;
    
    if (connect(s, (struct sockaddr *)&saddr, sizeof(saddr)) == 0)
    {
        mSocket = s;
        
        if (mOpenCallback)
        {
            CefV8ValueList args;
            CefRefPtr<CefV8Value> retval;
            CefRefPtr<CefV8Exception> exception;     
            
            mOpenCallback->ExecuteFunctionWithContext(mOpenContext, NULL, args, retval, exception, false);                        
        }
        
        event_set(&mEventRead, mSocket, EV_READ|EV_PERSIST, &CSJsSocket::OnReadStatic, this);
        event_add(&mEventRead, NULL);        
        
        return true;
    }
    
    return false;    
}
bool ClientHandler::OnBeforeUnloadDialog(
    CefRefPtr<CefBrowser> browser,
    const CefString& message_text,
    bool is_reload,
    CefRefPtr<CefJSDialogCallback> callback) {
  CEF_REQUIRE_UI_THREAD();

  const std::string& new_message_text =
      message_text.ToString() + "\n\nIs it OK to leave/reload this page?";
  bool suppress_message = false;

  return OnJSDialog(browser, CefString(), CefString(), JSDIALOGTYPE_CONFIRM,
                    new_message_text, CefString(), callback, suppress_message);
}
Пример #17
0
void CaffeineClientHandler::CreateAndDispatchCustomEvent(const CefString &eventName, const CefString &obj)
{
    if (this->GetBrowser())
    {
        CefRefPtr<CefFrame> frame = this->GetBrowser()->GetMainFrame();
        if (frame.get() && frame->IsValid())
        {
            string jsCode =
                "var event = new CustomEvent(\"" + eventName.ToString() + "\", {bubbles: true, cancelable: true, detail: JSON.parse('" + obj.ToString() + "')});"
                "window.dispatchEvent(event);";
            frame->ExecuteJavaScript(jsCode, frame->GetURL(), 0);
        }
    }
}
int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging)
{
    const char *remoteDebuggingFormat = "--no-first-run --no-default-browser-check --allow-file-access-from-files --temp-profile --user-data-dir=%s --remote-debugging-port=9222";
    gchar *remoteDebugging;
    gchar *cmdline;
    int error = ERR_BROWSER_NOT_INSTALLED;
    GError *gerror = NULL;
    
    if (enableRemoteDebugging) {
        CefString appSupportDirectory = ClientApp::AppGetSupportDirectory();

        // TODO: (INGO) to better understand to string conversion issue, I need a consultant
        // here. Getting the char* from CefString I had to call ToString().c_str()
        // Calling only c_str() didn't return anything.
        gchar *userDataDir = g_strdup_printf("%s/live-dev-profile",
                                        appSupportDirectory.ToString().c_str());  
        g_message("USERDATADIR= %s", userDataDir);
        remoteDebugging = g_strdup_printf(remoteDebuggingFormat, userDataDir);
        
        g_free(userDataDir);
    } else {
        remoteDebugging = g_strdup("");
    }

    // check for supported browsers (in PATH directories)
    for (size_t i = 0; i < sizeof(browsers) / sizeof(browsers[0]); i++) {
        cmdline = g_strdup_printf("%s %s %s", browsers[i].c_str(), argURL.c_str(), remoteDebugging);

        if (g_spawn_command_line_async(cmdline, &gerror)) {
            // browser is found in os; stop iterating
            error = NO_ERROR;
        } else {
            error = ConvertGnomeErrorCode(gerror);
        }

        g_free(cmdline);
        
        if (error == NO_ERROR) {
            break;
        } else {
            g_error_free(gerror);
            gerror = NULL;
        }
    }
    
    g_free(remoteDebugging);

    return error;
}
Пример #19
0
void Application::SetJSHook(
	const CefString& InHookName,
	int InBrowserID,
	CefRefPtr<CefV8Context> InContext,
	CefRefPtr<CefV8Value> InFunction
	)
{
	REQUIRE_RENDER_THREAD()

	JSHook Hook;
	Hook.Context = InContext;
	Hook.Function = InFunction;

	Hooks.insert(JSHookMap::value_type(std::make_pair(InHookName.ToString(), InBrowserID), Hook));
}
Пример #20
0
// Called due to cefQuery execution in binding.html.
bool QueryHandler::OnQuery(CefRefPtr<CefBrowser> browser,
                           CefRefPtr<CefFrame> frame,
                           int64 query_id,
                           const CefString& request,
                           bool persistent,
                           CefRefPtr<Callback> callback) {
  YAML::Node parsedRequest;
  try {
    parsedRequest = JSON::parse(request.ToString());
  } catch (exception &e) {
    BOOST_LOG_TRIVIAL(error) << "Failed to parse CEF query request \"" << request.ToString() << "\": " << e.what();
    callback->Failure(-1, e.what());
    return true;
  }

  auto query = createQuery(browser, frame, parsedRequest);

  if (!query)
    return false;

  CefPostTask(TID_FILE, base::Bind(&Query::execute, query, callback));

  return true;
}
Пример #21
0
bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> browser,
                             CefRefPtr<CefFrame> frame,
                             const CefString& target_url,
                             const CefString& target_frame_name,
                             const CefPopupFeatures& popupFeatures,
                             CefWindowInfo& windowInfo,
                             CefRefPtr<CefClient>& client,
                             CefBrowserSettings& settings,
                             bool* no_javascript_access)
#endif
{
    RLOG(Upp::Format("Popup canceled, frame name: '%s', url '%s'", target_frame_name.ToString().c_str(), target_url.ToString().c_str()));
	// Cancel popups
    return true;
}
Пример #22
0
PageSize getPageSize(const CefString& str)
{
    std::string lhs = strtolower(str.ToString());
    PageSizesMap::const_iterator it;

    for (it = pageSizesMap.begin(); it != pageSizesMap.end(); ++it) {
        std::string rhs = strtolower(it->name);
        if (lhs == rhs) {
            return *it;
        }
    }

    PageSize pageSize;
    pageSize.name = "Custom";
    parseCustomPageSize(pageSize, lhs);
    return pageSize;
}
Пример #23
0
bool NUIApp::Execute(const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception)
{
	auto handler = m_v8Handlers.find(name);
	bool success = false;

	if (handler != m_v8Handlers.end())
	{
		retval = handler->second(arguments, exception);

		success = true;
	}
	else
	{
		trace("Unknown NUI function: %s\n", name.ToString().c_str());
	}

	return success;
}
Пример #24
0
PageMargin getPageMargin(const CefString& str)
{
    PageMargin pageMargin;

    std::string input = strtolower(str.ToString());

    if ("default" == input) {
        pageMargin.type = PDF_PRINT_MARGIN_DEFAULT;
    } else if ("minimum" == input) {
        pageMargin.type = PDF_PRINT_MARGIN_MINIMUM;
    } else if ("none" == input) {
        pageMargin.type = PDF_PRINT_MARGIN_NONE;
    } else { // Custom
        pageMargin.type = PDF_PRINT_MARGIN_CUSTOM;
        parseCustomPageMargin(pageMargin, input);
    }

    return pageMargin;
}
Пример #25
0
void TransparentWnd::replaceResponse(CefString response, LPVOID pParam){
	EnterCriticalSection(&cs);
	MelodyProxy::ProxyParam* pProxyParam=(MelodyProxy::ProxyParam*)pParam;
	if(IsBadReadPtr(pProxyParam,sizeof(MelodyProxy::ProxyParam))){
		LeaveCriticalSection(&cs);
		return;
	}
	if(pProxyParam->replaceResponse!=NULL){
		delete pProxyParam->replaceResponse;
		pProxyParam->replaceResponse=NULL;
	}
	pProxyParam->isReplaceRequest=false;
	pProxyParam->replaceResponse=new char[MAXBUFFERSIZE*50];
	strcpy(pProxyParam->replaceResponse,response.ToString().c_str());
	pProxyParam->CancelReplaceResponse=false;
	::PulseEvent(pProxyParam->ReplaceResponseOK);
	::WaitForSingleObject(pProxyParam->ReplaceResponseEnd,3000);
	LeaveCriticalSection(&cs);
}
Пример #26
0
void TransparentWnd::ShowTip(CefString& text){
	return;
	TransparentWnd* pWin;
	if(!pTipWin){
		if(text.length()){
			pWin=new TransparentWnd();
			pTipWin=(void *)pWin;
			std::stringstream ss;
			POINT pt;
			GetCursorPos(&pt);
			ss<<"{\"text\":\""<<text.ToString()<<"\",\"x\":"<<pt.x<<",\"y\":"<<pt.y<<"}";
			pWin->RunAppIn("tip/index.app",ss.str());
		}
	}
	else{
		pWin=(TransparentWnd *)pTipWin;
		if(text.length()){
			std::wstringstream ss;
			POINT pt;
			GetCursorPos(&pt);
			wstring t=text.ToWString();
			replace_allW(t,L"'",L"\'");
			ss<<"var e = new CustomEvent('AlloyDesktopShowTip', {"
				"detail: {"
				"	'text':'"<<t<<"',"<<
				"   'x':"<<pt.x<<","
				"   'y':"<<pt.y<<
				"}"
				"});"
				"dispatchEvent(e);";
			pWin->ExecJS(ss.str());
			ExecJS(ss.str());
			if(pWin->isHide){
				pWin->Restore();
			}
		}
		else{
			pWin->Hide();
		}
	}
}
Пример #27
0
void PhantomJSHandler::handleLoadEnd(CefRefPtr<CefBrowser> browser, int statusCode, const CefString& url, bool success)
{
  qCDebug(handler) << browser->GetIdentifier() << statusCode << url << success;

  auto& browserInfo = m_browsers[browser->GetIdentifier()];
  if (!browserInfo.firstLoadFinished) {
    browserInfo.firstLoadFinished = true;
    return;
  }

  if (canEmitSignal(browser)) {
    emitSignal(browser, QStringLiteral("onLoadEnd"), {QString::fromStdString(url), success}, true);
  }

  while (auto callback = takeCallback(&m_waitForLoadedCallbacks, browser)) {
    if (success) {
      callback->Success(std::to_string(statusCode));
    } else {
      callback->Failure(statusCode, "Failed to load URL: " + url.ToString());
    }
  }
}
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;
}
Пример #29
0
bool ClientHandler::OnCertificateError(CefRefPtr<CefBrowser> browser, ErrorCode cert_error,
										const CefString& request_url, CefRefPtr<CefSSLInfo> ssl_info,
										CefRefPtr<CefRequestCallback> callback)
{
	ASSERT(CefCurrentlyOn(TID_UI));

	bool cont = WhenCertificateError(request_url.ToString());

	if (!cont){
		CefRefPtr<CefSSLCertPrincipal> subject = ssl_info->GetSubject();
		CefRefPtr<CefSSLCertPrincipal> issuer = ssl_info->GetIssuer();
	
		// Build a table showing certificate information.
		Upp::String ss;
		ss << "<html><head></head><body>"
			"<center><h1>Page certificate is not trusted</h1></center>"
			"<br/>Certificate Information:"
	        "<table border=1><tr><th>Field</th><th>Value</th></tr>"
	        "<tr><td>Subject</td><td>" <<
	            (subject.get() ? subject->GetDisplayName().ToString().c_str() : "&nbsp;") <<
	            "</td></tr>"
	        "<tr><td>Issuer</td><td>" <<
	            (issuer.get() ? issuer->GetDisplayName().ToString().c_str() : "&nbsp;") <<
	            "</td></tr>"
	        "<tr><td>Valid Start</td><td>" <<
	            GetCefTimeString(ssl_info->GetValidStart()) << "</td></tr>"
	        "<tr><td>Valid Expiry</td><td>" <<
	            GetCefTimeString(ssl_info->GetValidExpiry()) << "</td></tr>"
	        "</table>"
	        "</body></html>";
	
		browser->GetMainFrame()->LoadString(~ss, request_url);
	}
	
	callback->Continue(cont);
	return cont;
}
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();
}