void ClientHandler::SendNotification(NotificationType type) { if (type == NOTIFY_DOWNLOAD_COMPLETE) { std::string downloadedFile(GetLastDownloadFile()); GtkWidget* widget = NULL; CefPostTask(TID_UI, NewCefRunnableFunction(AppCreateWebinosBrowser,downloadedFile,false,true,widget,0,0)); } }
// Change the zoom factor on the UI thread. static void ModifyZoom(CefRefPtr<CefBrowser> browser, double delta) { if (CefCurrentlyOn(TID_UI)) { browser->GetHost()->SetZoomLevel( browser->GetHost()->GetZoomLevel() + delta); } else { CefPostTask(TID_UI, NewCefRunnableFunction(ModifyZoom, browser, delta)); } }
bool Application::Execute( const CefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception ) { if (name == "exit") { printf("Exiting with value %d!\n", arguments[0]->GetIntValue()); this->firstBrowser = NULL; // see http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=891 for the 'right' way to do this CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create("quit"); message->GetArgumentList()->SetInt(0, arguments[0]->GetIntValue()); message->GetArgumentList()->SetString(1, this->outBuffer); if(CefV8Context::GetEnteredContext()->GetBrowser()->SendProcessMessage(PID_BROWSER, message)) { printf("Got true from quit send process\n"); } else { printf("Got false from quit send process message\n"); } return true; } else if (name == "open") { } else if (name == "openWindow") { CefPostTask( TID_UI, NewCefRunnableFunction(&noOpenWindow) ); return true; } else if (name == "nop") { return true; } else if (name == "log") { /*if (object->IsSame(this->leprechaunObj)) { // Figure out if we need this some day... return false; }*/ std::wstringstream ss; for (size_t i = 0; i < arguments.size(); ++i) { ss << arguments[i]->GetStringValue().ToWString(); } printf("Got log: %S\n", ss.str().c_str()); return true; } else if (name == "echo") { std::wstringstream ss; for (size_t i = 0; i < arguments.size(); ++i) { ss << arguments[i]->GetStringValue().ToWString(); } this->outBuffer += ss.str().c_str(); this->outBuffer += L"\n"; return true; } else if (name == "onerror") { return true; } return false; }
void RunJavaScriptInvokeTest(CefRefPtr<CefBrowser> browser) { if (CefCurrentlyOn(TID_UI)) { UIT_InvokeScript(browser); } else { // Execute on the UI thread. CefPostTask(TID_UI, NewCefRunnableFunction(&UIT_InvokeScript, browser)); } }
JNIEXPORT void JNICALL Java_org_cef_browser_CefBrowser_1N_N_1UpdateUI (JNIEnv *env, jobject obj, jobject jcontentRect, jobject jbrowserRect) { CefRefPtr<CefBrowser> browser = JNI_GET_BROWSER_OR_RETURN(env, obj); CefRect contentRect = GetJNIRect(env, jcontentRect); #if defined(OS_MACOSX) CefRect browserRect = GetJNIRect(env, jbrowserRect); util_mac::UpdateView(browser->GetHost()->GetWindowHandle(), contentRect, browserRect); #elif defined(OS_WIN) HWND hwnd = browser->GetHost()->GetWindowHandle(); if (CefCurrentlyOn(TID_UI)) UpdateWindowRgn(hwnd, contentRect); else CefPostTask(TID_UI, NewCefRunnableFunction(&UpdateWindowRgn, hwnd, contentRect)); #endif }
JNIEXPORT void JNICALL Java_org_cef_browser_CefBrowser_1N_N_1WasResized (JNIEnv *env, jobject obj, jint width, jint height) { CefRefPtr<CefBrowser> browser = JNI_GET_BROWSER_OR_RETURN(env, obj); if( browser->GetHost()->IsWindowRenderingDisabled() ) { browser->GetHost()->WasResized(); } #if defined(OS_WIN) else { HWND handle = browser->GetHost()->GetWindowHandle(); if (CefCurrentlyOn(TID_UI)) SetWindowPos(handle, NULL, 0, 0, width, height, SWP_NOZORDER|SWP_NOMOVE); else CefPostTask(TID_UI, NewCefRunnableFunction(&SetWindowPos, handle, (HWND)NULL, 0, 0, (int)width, (int)height, (UINT)(SWP_NOZORDER | SWP_NOMOVE))); } #endif }
JNIEXPORT jdouble JNICALL Java_org_cef_browser_CefBrowser_1N_N_1GetZoomLevel (JNIEnv *env, jobject obj) { CefRefPtr<CefBrowser> browser = JNI_GET_BROWSER_OR_RETURN(env, obj, 0.0); CefRefPtr<CefBrowserHost> host = browser->GetHost(); double result = 0.0; if (CefCurrentlyOn(TID_UI)) result = host->GetZoomLevel(); else { CriticalLock lock; CriticalWait waitCond(&lock); lock.Lock(); CefPostTask(TID_UI, NewCefRunnableFunction(getZoomLevel, host, &waitCond, &result)); waitCond.Wait(1000); lock.Unlock(); } return result; }
JNIEXPORT void JNICALL Java_org_cef_browser_CefBrowser_1N_N_1SetFocus (JNIEnv *env, jobject obj, jboolean enable) { CefRefPtr<CefBrowser> browser = JNI_GET_BROWSER_OR_RETURN(env, obj); if (browser->GetHost()->IsWindowRenderingDisabled()) { browser->GetHost()->SendFocusEvent(enable != JNI_FALSE); } else { browser->GetHost()->SetFocus(enable != JNI_FALSE); } #if defined(OS_WIN) if (enable == JNI_FALSE) { HWND browserHandle = browser->GetHost()->GetWindowHandle(); if (CefCurrentlyOn(TID_UI)) FocusParent(browserHandle); else CefPostTask(TID_UI, NewCefRunnableFunction(&FocusParent, browserHandle)); } #endif }
// static void ClientHandler::LaunchExternalBrowser(const std::string& url) { if (CefCurrentlyOn(TID_PROCESS_LAUNCHER)) { // Retrieve the current executable path. CefString file_exe; if (!CefGetPath(PK_FILE_EXE, file_exe)) return; // Create the command line. CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine(); command_line->SetProgram(file_exe); command_line->AppendSwitchWithValue(cefclient::kUrl, url); // Launch the process. CefLaunchProcess(command_line); } else { // Execute on the PROCESS_LAUNCHER thread. CefPostTask(TID_PROCESS_LAUNCHER, NewCefRunnableFunction(&ClientHandler::LaunchExternalBrowser, url)); } }
~ClientDownloadHandler() { //ASSERT(pending_data_.empty()); //ASSERT(file_ == NULL); if (!pending_data_.empty()) { // Delete remaining pending data. std::vector<std::vector<char>*>::iterator it = pending_data_.begin(); for (; it != pending_data_.end(); ++it) delete (*it); } if (file_) { // Close the dangling file pointer on the FILE thread. CefPostTask(TID_FILE, NewCefRunnableFunction(&ClientDownloadHandler::CloseDanglingFile, file_)); // Notify the listener that the download failed. send_download_status(jdw, S_ERROR); } }
void SetBrowserDpiSettings(CefRefPtr<CefBrowser> cefBrowser, CefString autoZooming) { // Setting zoom level immediately after browser was created // won't work. We need to wait a moment before we can set it. REQUIRE_UI_THREAD(); double oldZoomLevel = cefBrowser->GetHost()->GetZoomLevel(); double newZoomLevel = 0.0; int dpix = 0; int dpiy = 0; GetSystemDpi(&dpix, &dpiy); if (autoZooming.ToString() == "system_dpi") { // Using only "dpix" value to calculate zoom level. All // modern displays have equal horizontal/vertical resolution. // Examples: // dpix=96 zoom=0.0 // dpix=120 zoom=1.0 // dpix=144 zoom=2.0 // dpix=72 zoom=-1.0 newZoomLevel = (dpix - DEFAULT_DPIX) / 24; } else { // When atof() fails converting string to double, then // 0.0 is returned. newZoomLevel = atof(autoZooming.ToString().c_str()); } if (oldZoomLevel != newZoomLevel) { cefBrowser->GetHost()->SetZoomLevel(newZoomLevel); if (cefBrowser->GetHost()->GetZoomLevel() != oldZoomLevel) { // OK succes. LOG_DEBUG << "Browser: SetBrowserDpiSettings: " << "DPI=" << dpix << " " << "zoom=" << cefBrowser->GetHost()->GetZoomLevel(); } } else { // This code block running can also be a result of executing // SetZoomLevel(), as GetZoomLevel() didn't return the new // value that was set. Documentation says that if SetZoomLevel // is called on the UI thread, then GetZoomLevel should // immediately return the same value that was set. Unfortunately // this seems not to be true. static bool already_logged = false; if (!already_logged) { already_logged = true; // OK success. LOG_DEBUG << "Browser: SetBrowserDpiSettings: " << "DPI=" << dpix << " " << "zoom=" << cefBrowser->GetHost()->GetZoomLevel(); } } // We need to check zooming constantly, during loading of pages. // If we set zooming to 2.0 for localhost/ and then it navigates // to google.com, then the zomming is back at 0.0 and needs to // be set again. CefPostDelayedTask( TID_UI, NewCefRunnableFunction(&SetBrowserDpiSettings, cefBrowser, autoZooming), 50); }
void RunGetImageTest(CefRefPtr<CefBrowser> browser) { // Execute the test function on the UI thread. CefPostTask(TID_UI, NewCefRunnableFunction(UIT_RunGetImageTest, browser)); }
void RunGetSourceTest(CefRefPtr<CefBrowser> browser) { // Execute the GetSource() call on the UI thread. CefPostTask(TID_UI, NewCefRunnableFunction(&ExecuteGetSource, browser->GetMainFrame())); }