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; }
FWebBrowserPopupFeatures::FWebBrowserPopupFeatures( const CefPopupFeatures& PopupFeatures ) { X = PopupFeatures.x; bXSet = PopupFeatures.xSet ? true : false; Y = PopupFeatures.y; bYSet = PopupFeatures.ySet ? true : false; Width = PopupFeatures.width; bWidthSet = PopupFeatures.widthSet ? true : false; Height = PopupFeatures.height; bHeightSet = PopupFeatures.heightSet ? true : false; bMenuBarVisible = PopupFeatures.menuBarVisible ? true : false; bStatusBarVisible = PopupFeatures.statusBarVisible ? true : false; bToolBarVisible = PopupFeatures.toolBarVisible ? true : false; bLocationBarVisible = PopupFeatures.locationBarVisible ? true : false; bScrollbarsVisible = PopupFeatures.scrollbarsVisible ? true : false; bResizable = PopupFeatures.resizable ? true : false; bIsFullscreen = PopupFeatures.fullscreen ? true : false; bIsDialog = PopupFeatures.dialog ? true : false; int Count = PopupFeatures.additionalFeatures ? cef_string_list_size(PopupFeatures.additionalFeatures) : 0; CefString ListValue; for(int ListIdx = 0; ListIdx < Count; ListIdx++) { cef_string_list_value(PopupFeatures.additionalFeatures, ListIdx, ListValue.GetWritableStruct()); AdditionalFeatures.Add(ListValue.ToWString().c_str()); } }
QUrl QCefWebView::url() const { if (GetBrowser().get()) { CefString url = GetBrowser()->GetMainFrame()->GetURL(); return QUrl(QString::fromStdWString(url.ToWString())); } return QUrl(); }
// Inject webinos.js // The file is loaded from the webinos\test\client folder if possible. // If this fails, the current folder is used. void ClientApp::InjectWebinos(CefRefPtr<CefFrame> frame) { CefRefPtr<CefCommandLine> commandLine = AppGetCommandLine(); // First try and load the platform-supplied webinos.js std::string pzpPath = AppGetWebinosWRTConfig(NULL,NULL); CefString wrtPath; // Make sure there is a trailing separator on the path. if (pzpPath.length() > 0) { if (pzpPath.find_last_of('/') == pzpPath.length()-1 || pzpPath.find_last_of('\\') == pzpPath.length()-1) wrtPath = pzpPath + "wrt/webinos.js"; else wrtPath = pzpPath + "/wrt/webinos.js"; } #if defined(OS_WIN) base::FilePath webinosJSPath(wrtPath.ToWString().c_str()); #else base::FilePath webinosJSPath(wrtPath); #endif LOG(INFO) << "webinos.js path is " << wrtPath; int64 webinosJSCodeSize; bool gotJSFile = base::GetFileSize(webinosJSPath, &webinosJSCodeSize); if (gotJSFile) { char* webinosJSCode = new char[webinosJSCodeSize+1]; base::ReadFile(webinosJSPath, webinosJSCode, webinosJSCodeSize); webinosJSCode[webinosJSCodeSize] = 0; if (frame == NULL) { // Register as a Cef extension. CefRegisterExtension("webinos", webinosJSCode, NULL); } else { // Run the code in the frame javascript context right now, // but only if the URL refers to the widget server. int widgetServerPort; AppGetWebinosWRTConfig(NULL,&widgetServerPort); char injectionCandidate[MAX_URL_LENGTH]; sprintf(injectionCandidate,"http://localhost:%d",widgetServerPort); std::string url = frame->GetURL(); if (url.substr(0,strlen(injectionCandidate)) == injectionCandidate) frame->ExecuteJavaScript(webinosJSCode, url, 0); } delete[] webinosJSCode; } else { LOG(ERROR) << "Can't find webinos.js"; } }
void QCefView::navigateToUrl(const QString& url) { if (cefWindow_) { CefString strUrl; strUrl.FromString(url.toStdString()); cefWindow_->cefViewHandler()->GetBrowser()->GetMainFrame()->LoadURL(strUrl); } }
JNIEXPORT jstring JNICALL Java_org_limewire_cef_CefV8Value_1N_N_1GetStringValue (JNIEnv *env, jobject obj) { CefRefPtr<CefV8Value> value( (CefV8Value*)GetCefBaseFromJNIObject(env, obj)); if(!value.get()) return NULL; CefString str = value->GetStringValue(); return env->NewString((const jchar*)str.c_str(), str.length()); }
//================================================================================ // Ejecuta JavaScript //================================================================================ void CefBasePanel::ExecuteJavaScript( const char *script ) { if ( !GetClient() ) return; CefString code; code.FromASCII( script ); CefString file; GetClient()->GetBrowser()->GetMainFrame()->ExecuteJavaScript( code, file, 0 ); }
void QCefView::navigateToString(const QString& content, const QString& url) { if (cefWindow_) { CefString strContent; strContent.FromString(content.toStdString()); CefString strUrl; strUrl.FromString(url.toStdString()); cefWindow_->cefViewHandler()->GetBrowser()->GetMainFrame()->LoadString(strContent, strUrl); } }
//================================================================================ // Abre la dirección web //================================================================================ void CefBasePanel::OpenURL( const char *address ) { if ( !GetClient() ) return; CefString str; str.FromASCII( address ); GetClient()->GetBrowser()->GetMainFrame()->LoadURL( str ); ResizeView(); DevMsg( "CefBasePanel::OpenURL: %s \n", address ); }
HICON TransparentWnd::GetIcon(CefString path){ if(path.ToWString().find(L":")==-1){ wstring _path; _path=url.ToWString(); replace_allW(_path, L"\\", L"/"); _path=_path.substr(0,_path.find_last_of('/')+1); path=_path.append(path); } return (HICON)::LoadImage(NULL,path.ToWString().data(),IMAGE_ICON,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE); //Bitmap bm(path.ToWString().data()); //HICON hIcon; //bm.GetHICON(&hIcon); //return hIcon; }
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()); }
bool QCefView::sendEVentNotifyMessage(int frameId, const QString& name, const QCefEvent& event) { CefRefPtr<CefProcessMessage> msg = CefProcessMessage::Create( TRIGGEREVENT_NOTIFY_MESSAGE); CefRefPtr<CefListValue> arguments = msg->GetArgumentList(); int idx = 0; arguments->SetInt(idx++, frameId); CefString eventName = name.toStdString(); arguments->SetString(idx++, eventName); CefRefPtr<CefDictionaryValue> dict = CefDictionaryValue::Create(); CefString cefStr; cefStr.FromWString(event.objectName().toStdWString()); dict->SetString("name", cefStr); QList<QByteArray> keys = event.dynamicPropertyNames(); for (QByteArray key : keys) { QVariant value = event.property(key.data()); if (value.type() == QMetaType::Bool) { dict->SetBool(key.data(), value.toBool()); } else if (value.type() == QMetaType::Int || value.type() == QMetaType::UInt) { dict->SetInt(key.data(), value.toInt()); } else if (value.type() == QMetaType::Double) { dict->SetDouble(key.data(), value.toDouble()); } else if (value.type() == QMetaType::QString) { cefStr.FromWString(value.toString().toStdWString()); dict->SetString(key.data(), cefStr); } else { __noop(_T("QCefView"), _T("Unknow Type!")); } } arguments->SetDictionary(idx++, dict); return cefWindow_->cefViewHandler()->TriggerEvent(msg); }
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; }
bool CaffeineClientHandler::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) { if (dialog_type == JSDIALOGTYPE_ALERT) { #ifdef OS_WIN // TODO: Look up from the string table. MessageBox(m_MainHwnd, message_text.c_str(), FULL_PRODUCT, MB_OK); #else wstring msg = message_text; alertMessage(msg); #endif callback->Continue(true, message_text); return true; } return false; }
CefString TransparentWnd::GetOpenName(CefString fileName){ TCHAR szFile[4096]; OpenFileDialog(hWnd, fileName.ToWString().data(), szFile); wstring d(szFile); CefString s(d); return s; }
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()); }
void TransparentWnd::RunApp(CefString appName, CefString param, CefString baseUrl){ wstring appNameW=appName.ToWString(); wstring path; if(!baseUrl.length()){ path=modulePath; } else{ path=baseUrl.ToWString(); replace_allW(path, L"\\", L"/"); path=path.substr(0,path.find_last_of('/')+1); } if(appNameW.find(L":")==-1){ appNameW=path.append(appNameW); } CreateBrowser(appNameW,param); }
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) { if(browser->GetHost()->IsWindowRenderingDisabled()) { // Cancel popups in off-screen rendering mode. return true; } // set client client = this; // The frame window will be the parent of the browser window HWND hWindow = GetParent( browser->GetHost()->GetWindowHandle() ); // send message LPCTSTR lpszURL(target_url.c_str()); if( ::SendMessage( hWindow, WM_APP_CEF_WINDOW_CHECK, (WPARAM)&popupFeatures, (LPARAM)lpszURL) == S_FALSE ) return true; // send message if( ::SendMessage( hWindow, WM_APP_CEF_NEW_WINDOW, (WPARAM)&popupFeatures, (LPARAM)&windowInfo) == S_FALSE ) return true; // call parent return CefLifeSpanHandler::OnBeforePopup(browser, frame, target_url, target_frame_name, popupFeatures, windowInfo, client, settings, no_javascript_access); }
void TransparentWnd::ToImageEx(CefString path, int _x, int _y, int _width, int _height){ if(!hBitMap){ return; } Bitmap bm(_width,_height); Rect r(0,0,_width,_height); BitmapData bmData; bm.LockBits(&r, ImageLockModeWrite, PixelFormat32bppPARGB, &bmData); int l=width*height*4; PBYTE p1=new BYTE[l]; GetBitmapBits(hBitMap, l, p1); byte* p = (byte*)bmData.Scan0; int count=0; for(int j=0;j<_height;++j){ for (int i = 0; i < _width; i++) { for(int k=0; k<4;++k){ int pos = (_y+j)*width*4+(_x+i)*4; p[count]=p1[pos+k]; ++count; } } } delete []p1; bm.UnlockBits(&bmData); CLSID tiffClsid; GetEncoderClsid((L"image/"+GetExtW(path.ToWString())).data(), &tiffClsid); bm.Save(TranslatePath(path).ToWString().data(), &tiffClsid); }
bool CaffeineClientApp::UploadCrashLogs(CefString AppVersion, CefString UserDescription) { bool retval = false; HANDLE hFind = INVALID_HANDLE_VALUE; WIN32_FIND_DATA ffd; // Get the crash logs folder and append '\*.zip' to it. wstring CrashDir = GetCrashLogsDirectory(); wstring ZippedLogs = CrashDir + L"\\*.zip"; // Find the first file in the directory. hFind = FindFirstFile(ZippedLogs.c_str(), &ffd); if (INVALID_HANDLE_VALUE != hFind) { do { TCHAR szFullPath[MAX_PATH*2] = {0,}; StringCchCopy(szFullPath, MAX_PATH*2, CrashDir.c_str()); PathAppend(szFullPath, ffd.cFileName); InterlockedIncrement(&log_count); InsertDescriptionIntoCrashLogs(szFullPath, UserDescription.ToWString()); PostCrashLogs(szFullPath, AppVersion, UserDescription); } while (FindNextFile(hFind, &ffd) != 0); FindClose(hFind); retval = true; } return retval; }
// 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; }
CefString TransparentWnd::GetSaveName(CefString fileName){ TCHAR szFile[2048]; SaveFileDialog(hWnd, fileName.ToWString().data(), szFile); wstring d(szFile); CefString s(d); return s; }
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; }
void WebBrowserHost::ClearCookies(const String& url, const String& cookieName) { CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager(nullptr); if (!manager.get()) return; CefString cefUrl; cefUrl.FromASCII(url.CString()); CefString cefCookieName; cefCookieName.FromASCII(cookieName.CString()); manager->DeleteCookies(cefUrl, cefCookieName, nullptr); }
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; }
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(); }
virtual void Visit ( const CefString& code ) override { // Limit to 2MiB for now to prevent freezes (TODO: Optimize that and increase later) if ( code.size () <= 2097152 ) { // Call callback on main thread g_pCore->GetWebCore ()->AddEventToEventQueue ( std::bind ( callback, code ), webView, "GetSourceCode_Visit" ); } }
void FCEFWebBrowserWindow::SetToolTip(const CefString& CefToolTip) { FString NewToolTipText = CefToolTip.ToWString().c_str(); if (ToolTipText != NewToolTipText) { ToolTipText = NewToolTipText; OnToolTip().Broadcast(ToolTipText); } }
// CefDisplayHandler void OnTitleChange( CefRefPtr<CefBrowser> browser, const CefString& title ) override { if (!owner_.on_cef_title_change(browser, title)) { auto hwnd = browser->GetHost()->GetWindowHandle(); if (browser_list_.front()->IsSame(browser)) { auto hparent = ::GetAncestor(hwnd, GA_PARENT); if (hparent != nullptr) { ::SetWindowTextW(hparent, title.c_str()); } } else { ::SetWindowTextW(hwnd, title.c_str()); } } }
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title) { REQUIRE_UI_THREAD(); if (!listener_) return; if (m_BrowserId == browser->GetIdentifier()) { listener_->OnTitleChange(QString::fromStdWString(title.ToWString())); } }