/*--cef(optional_param=process_type)--*/ void App::OnBeforeCommandLineProcessing( const CefString& process_type, CefRefPtr<CefCommandLine> command_line) { // May be called on any thread? if (process_type.empty()) { // Browser process. json_value* appSettings = GetApplicationSettings(); json_value switches = (*appSettings)["chrome"]["command_line_switches"]; if (switches.type == json_object) { int length = switches.u.object.length; for (int i = 0; i < length; i++) { std::string name = switches.u.object.values[i].name; std::string value = (*switches.u.object.values[i].value); if (name.find("-") == 0) { LOG_WARNING << "Invalid command line switch: " << name; continue; } if (command_line->HasSwitch(name)) { if (value.empty()) { // Switch already set, do nothing. } else { std::string oldValue = command_line->GetSwitchValue(name); if (oldValue != value) { // Overwrite the switch with a new value. command_line->AppendSwitchWithValue(name, value); } } } else { if (value.empty()) { command_line->AppendSwitch(name); } else { command_line->AppendSwitchWithValue(name, value); } } } } } std::string process_name = "browser"; if (!process_type.empty()) { process_name = process_type; } LOG_DEBUG << "Command line string for the " << process_name << " process: " << command_line->GetCommandLineString().ToString(); }
void LootApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) { if (process_type.empty()) { // Browser process, OK to modify the command line. // Disable spell checking. command_line->AppendSwitch("--disable-spell-checking"); command_line->AppendSwitch("--disable-extensions"); } }
bool XAsyncBrowserHandler::AddFn(const CefString & protocol, const CefString & name, XCB_INFO & fun_info) { if (protocol.empty() || name.empty()) { DCHECK(!protocol.empty() && !name.empty()); return false; } // ProtocolFunctionHashMap::iterator it_map = fn_protocol_map_.find(protocol); // FunctionHashMap * fn_map = NULL; // if (fn_protocol_map_.end() == it_map) // { // auto it_inserted = fn_protocol_map_.insert(std::make_pair(name, FunctionHashMap())); // DCHECK(it_inserted.second); // fn_map = &it_inserted.first->second; // } // else // { // fn_map = &it_map->second; // } // fn_map->insert(std::make_pair(name, fun_info)); fn_protocol_map_[protocol].insert(std::make_pair(name, fun_info)); return true; }
virtual void HandleEvent(CefRefPtr<CefDOMEvent> event) { CefRefPtr<CefBrowser> browser = GetOffScreenBrowser(); CefRefPtr<CefDOMNode> element = event->GetTarget(); ASSERT(element.get()); std::string elementId = element->GetElementAttribute("id"); if (elementId == "back") { browser->GoBack(); } else if(elementId == "forward") { browser->GoForward(); } else if(elementId == "stop") { browser->Reload(); } else if(elementId == "reload") { browser->StopLoad(); } else if (elementId == "go") { // Retrieve the value of the "url" field and load it in the off-screen // browser window. CefRefPtr<CefDOMDocument> document = event->GetDocument(); ASSERT(document.get()); CefRefPtr<CefDOMNode> url = document->GetElementById("url"); ASSERT(url.get()); CefString value = url->GetValue(); if (!value.empty()) browser->GetMainFrame()->LoadURL(value); } else if(elementId == "testTransparency") { // Transparency test. browser->GetMainFrame()->LoadURL( "http://tests/transparency"); } else if(elementId == "testWindowlessPlugin") { // Load flash, which is a windowless plugin. browser->GetMainFrame()->LoadURL( "http://www.adobe.com/software/flash/about/"); } else if(elementId == "viewSource") { // View the page source for the host browser window. AppGetBrowser()->GetMainFrame()->ViewSource(); } else { // Not reached. ASSERT(false); } }
////////////////////////////////////////////////////////////////////////////////////////// // CefApp methods. void ClientApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line) { // Pass additional command-line flags to the browser process. if (process_type.empty()) { command_line->AppendSwitchWithValue("ppapi-flash-version", "20.0.0.228"); command_line->AppendSwitchWithValue("ppapi-flash-path", "PepperFlash\\pepflashplayer.dll"); //同一个域下的使用同一个渲染进程 command_line->AppendSwitch("process-per-site"); command_line->AppendSwitch("disable-gpu"); command_line->AppendSwitch("disable-gpu-compositing"); //command_line->AppendSwitchWithValue("proxy-server", "SOCKS5://127.0.0.1:1080"); // 开启离屏渲染 if (CefManager::GetInstance()->IsEnableOffsetRender()) { command_line->AppendSwitch("disable-surfaces"); command_line->AppendSwitch("enable-begin-frame-scheduling"); } } }
CefSettings GetJNISettings(JNIEnv* env, jobject obj) { CefString tmp; CefSettings settings; if (!obj) return settings; jclass cls = env->FindClass("org/cef/CefSettings"); if (!cls) return settings; if (GetJNIFieldString(env, cls, obj, "browser_subprocess_path", &tmp) && !tmp.empty()) { CefString(&settings.browser_subprocess_path) = tmp; tmp.clear(); } GetJNIFieldBoolean(env, cls, obj, "windowless_rendering_enabled", &settings.windowless_rendering_enabled); GetJNIFieldBoolean(env, cls, obj, "command_line_args_disabled", &settings.command_line_args_disabled); if (GetJNIFieldString(env, cls, obj, "cache_path", &tmp) && !tmp.empty()) { CefString(&settings.cache_path) = tmp; tmp.clear(); } GetJNIFieldBoolean(env, cls, obj, "persist_session_cookies", &settings.persist_session_cookies); if (GetJNIFieldString(env, cls, obj, "user_agent", &tmp) && !tmp.empty()) { CefString(&settings.user_agent) = tmp; tmp.clear(); } if (GetJNIFieldString(env, cls, obj, "product_version", &tmp) && !tmp.empty()) { CefString(&settings.product_version) = tmp; tmp.clear(); } if (GetJNIFieldString(env, cls, obj, "locale", &tmp) && !tmp.empty()) { CefString(&settings.locale) = tmp; tmp.clear(); } if (GetJNIFieldString(env, cls, obj, "log_file", &tmp) && !tmp.empty()) { CefString(&settings.log_file) = tmp; tmp.clear(); } jobject obj_sev = NULL; if (GetJNIFieldObject(env, cls, obj, "log_severity", &obj_sev, "Lorg/cef/CefSettings$LogSeverity;")) { if (obj_sev != NULL) { if (IsJNIEnumValue(env, obj_sev, "org/cef/CefSettings$LogSeverity", "LOGSEVERITY_VERBOSE")) settings.log_severity = LOGSEVERITY_VERBOSE; else if (IsJNIEnumValue(env, obj_sev, "org/cef/CefSettings$LogSeverity", "LOGSEVERITY_INFO")) settings.log_severity = LOGSEVERITY_INFO; else if (IsJNIEnumValue(env, obj_sev, "org/cef/CefSettings$LogSeverity", "LOGSEVERITY_WARNING")) settings.log_severity = LOGSEVERITY_WARNING; else if (IsJNIEnumValue(env, obj_sev, "org/cef/CefSettings$LogSeverity", "LOGSEVERITY_ERROR")) settings.log_severity = LOGSEVERITY_ERROR; else if (IsJNIEnumValue(env, obj_sev, "org/cef/CefSettings$LogSeverity", "LOGSEVERITY_DISABLE")) settings.log_severity = LOGSEVERITY_DISABLE; else settings.log_severity = LOGSEVERITY_DEFAULT; } } if (GetJNIFieldString(env, cls, obj, "javascript_flags", &tmp) && !tmp.empty()) { CefString(&settings.javascript_flags) = tmp; tmp.clear(); } if (GetJNIFieldString(env, cls, obj, "resources_dir_path", &tmp) && !tmp.empty()) { CefString(&settings.resources_dir_path) = tmp; tmp.clear(); } if (GetJNIFieldString(env, cls, obj, "locales_dir_path", &tmp) && !tmp.empty()) { CefString(&settings.locales_dir_path) = tmp; tmp.clear(); } GetJNIFieldBoolean(env, cls, obj, "pack_loading_disabled", &settings.pack_loading_disabled); GetJNIFieldInt(env, cls, obj, "remote_debugging_port", &settings.remote_debugging_port); GetJNIFieldInt(env, cls, obj, "uncaught_exception_stack_size", &settings.uncaught_exception_stack_size); GetJNIFieldInt(env, cls, obj, "context_safety_implementation", &settings.context_safety_implementation); GetJNIFieldBoolean(env, cls, obj, "ignore_certificate_errors", &settings.ignore_certificate_errors); jobject obj_col = NULL; if (GetJNIFieldObject(env, cls, obj, "background_color", &obj_col, "Lorg/cef/CefSettings$ColorType;")) { if (obj_col != NULL) { jlong jcolor = 0; JNI_CALL_METHOD(env, obj_col, "getColor", "()J", Long, jcolor); settings.background_color = (cef_color_t)jcolor; } } return settings; }
CefRefPtr<CefResourceHandler> CCefApp::Create ( CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& scheme_name, CefRefPtr<CefRequest> request ) { // browser or frame are NULL if the request does not orginate from a browser window // This is for exmaple true for the application cache or CEFURLRequests // (http://www.html5rocks.com/en/tutorials/appcache/beginner/) if ( !browser || !frame ) return nullptr; CWebCore* pWebCore = static_cast<CWebCore*> ( g_pCore->GetWebCore () ); auto pWebView = pWebCore->FindWebView ( browser ); if ( !pWebView || !pWebView->IsLocal () ) return nullptr; CefURLParts urlParts; if ( !CefParseURL ( request->GetURL (), urlParts ) ) return nullptr; if ( scheme_name == "mtalocal" ) // Backward compatibility { // Get full path SString path = UTF16ToMbUTF8 ( urlParts.path.str ).substr ( 2 ); // Check if we're dealing with an external resource if ( path[0] == ':' ) { size_t end = path.find_first_of ( '/' ); if ( end != std::string::npos ) { SString resourceName = path.substr ( 1, end-1 ); SString resourcePath = path.substr ( end ); // Call this function recursively and use the mta scheme instead request->SetURL ( "http://mta/local/" + resourceName + resourcePath ); return Create ( browser, frame, "http", request ); } return nullptr; } // Redirect mtalocal://* to http://mta/local/*, call recursively request->SetURL ( "http://mta/local/" + path ); return Create ( browser, frame, "http", request ); } SString host = UTF16ToMbUTF8 ( urlParts.host.str ); if ( scheme_name == "http" && host == "mta" ) { // Scheme format: http://mta/resourceName/file.html or http://mta/local/file.html for the current resource // Get resource name and path SString path = UTF16ToMbUTF8 ( urlParts.path.str ).substr ( 1 ); // Remove slash at the front size_t slashPos = path.find ( '/' ); if ( slashPos == std::string::npos ) return nullptr; SString resourceName = path.substr ( 0, slashPos ); SString resourcePath = path.substr ( slashPos + 1 ); if ( resourcePath.empty () ) return nullptr; // Get mime type from extension CefString mimeType; size_t pos = resourcePath.find_last_of ( '.' ); if ( pos != std::string::npos ) mimeType = CefGetMimeType ( resourcePath.substr ( pos + 1 ) ); // Make sure we provide a mime type, even // when we cannot deduct it from the file extension if ( mimeType.empty () ) mimeType = "application/octet-stream"; if ( pWebView->HasAjaxHandler ( resourcePath ) ) { std::vector<SString> vecGet; std::vector<SString> vecPost; if ( urlParts.query.str != nullptr ) { SString strGet = UTF16ToMbUTF8 ( urlParts.query.str ); std::vector<SString> vecTmp; strGet.Split ( "&", vecTmp ); SString key; SString value; for ( auto&& param : vecTmp ) { param.Split ( "=", &key, &value ); vecGet.push_back ( key ); vecGet.push_back ( value ); } } CefPostData::ElementVector vecPostElements; auto postData = request->GetPostData (); if ( postData.get () ) { request->GetPostData ()->GetElements ( vecPostElements ); SString key; SString value; for ( auto&& post : vecPostElements ) { // Limit to 5MiB and allow byte data only size_t bytesCount = post->GetBytesCount (); if ( bytesCount > 5*1024*1024 || post->GetType () != CefPostDataElement::Type::PDE_TYPE_BYTES ) continue; // Make string from buffer std::unique_ptr<char[]> buffer { new char[bytesCount] }; post->GetBytes ( bytesCount, buffer.get () ); SStringX param ( buffer.get (), bytesCount ); // Parse POST data into vector std::vector<SString> vecTmp; param.Split ( "&", vecTmp ); for ( auto&& param : vecTmp ) { param.Split ( "=", &key, &value ); vecPost.push_back ( key ); vecPost.push_back ( value ); } } } auto handler = new CAjaxResourceHandler ( vecGet, vecPost, mimeType ); pWebView->HandleAjaxRequest ( resourcePath, handler ); return handler; } else { // Calculate MTA resource path if ( resourceName != "local" ) path = ":" + resourceName + "/" + resourcePath; else path = resourcePath; // Calculate absolute path if ( !pWebView->GetFullPathFromLocal ( path ) ) return nullptr; // Finally, load the file stream auto stream = CefStreamReader::CreateForFile ( path ); if ( stream.get () ) return new CefStreamResourceHandler ( mimeType, stream ); } return nullptr; } // Return null if there is no matching scheme return nullptr; }
// Returns the application settings based on command line arguments. void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app) { ASSERT(app.get()); ASSERT(g_command_line.get()); if (!g_command_line.get()) return; CefString str; #if defined(OS_WIN) settings.multi_threaded_message_loop = g_command_line->HasSwitch(cefclient::kMultiThreadedMessageLoop); #endif CefString(&settings.cache_path) = g_command_line->GetSwitchValue(cefclient::kCachePath); CefString(&settings.log_file) = g_command_line->GetSwitchValue(cefclient::kLogFile); { std::string str = g_command_line->GetSwitchValue(cefclient::kLogSeverity); // Default to LOGSEVERITY_DISABLE settings.log_severity = LOGSEVERITY_DISABLE; if (!str.empty()) { if (str == cefclient::kLogSeverity_Verbose) settings.log_severity = LOGSEVERITY_VERBOSE; else if (str == cefclient::kLogSeverity_Info) settings.log_severity = LOGSEVERITY_INFO; else if (str == cefclient::kLogSeverity_Warning) settings.log_severity = LOGSEVERITY_WARNING; else if (str == cefclient::kLogSeverity_Error) settings.log_severity = LOGSEVERITY_ERROR; else if (str == cefclient::kLogSeverity_ErrorReport) settings.log_severity = LOGSEVERITY_ERROR_REPORT; else if (str == cefclient::kLogSeverity_Disable) settings.log_severity = LOGSEVERITY_DISABLE; } } // Don't update the settings.locale with the locale that we detected from the OS. // Otherwise, CEF will use it to find the resources and when it fails in finding resources // for some locales that are not available in resources, it crashes. //CefString(&settings.locale) = app->GetCurrentLanguage( ); CefString(&settings.javascript_flags) = g_command_line->GetSwitchValue(cefclient::kJavascriptFlags); // Retrieve command-line proxy configuration, if any. bool has_proxy = false; cef_proxy_type_t proxy_type = CEF_PROXY_TYPE_DIRECT; CefString proxy_config; if (g_command_line->HasSwitch(cefclient::kProxyType)) { std::string str = g_command_line->GetSwitchValue(cefclient::kProxyType); if (str == cefclient::kProxyType_Direct) { has_proxy = true; proxy_type = CEF_PROXY_TYPE_DIRECT; } else if (str == cefclient::kProxyType_Named || str == cefclient::kProxyType_Pac) { proxy_config = g_command_line->GetSwitchValue(cefclient::kProxyConfig); if (!proxy_config.empty()) { has_proxy = true; proxy_type = (str == cefclient::kProxyType_Named? CEF_PROXY_TYPE_NAMED:CEF_PROXY_TYPE_PAC_STRING); } } } if (has_proxy) { // Provide a ClientApp instance to handle proxy resolution. app->SetProxyConfig(proxy_type, proxy_config); } // Enable dev tools settings.remote_debugging_port = REMOTE_DEBUGGING_PORT; // Set product version, which gets added to the User Agent string CefString(&settings.product_version) = AppGetProductVersionString(); }
// Returns the application settings based on command line arguments. void AppGetSettings(CefSettings& settings, CefRefPtr<ClientApp> app) { ASSERT(app.get()); ASSERT(g_command_line.get()); if (!g_command_line.get()) return; CefString str; #if defined(OS_WIN) settings.multi_threaded_message_loop = g_command_line->HasSwitch(cefclient::kMultiThreadedMessageLoop); #endif CefString(&settings.cache_path) = g_command_line->GetSwitchValue(cefclient::kCachePath); CefString(&settings.log_file) = g_command_line->GetSwitchValue(cefclient::kLogFile); { std::string str = g_command_line->GetSwitchValue(cefclient::kLogSeverity); bool invalid = false; if (!str.empty()) { if (str == cefclient::kLogSeverity_Verbose) settings.log_severity = LOGSEVERITY_VERBOSE; else if (str == cefclient::kLogSeverity_Info) settings.log_severity = LOGSEVERITY_INFO; else if (str == cefclient::kLogSeverity_Warning) settings.log_severity = LOGSEVERITY_WARNING; else if (str == cefclient::kLogSeverity_Error) settings.log_severity = LOGSEVERITY_ERROR; else if (str == cefclient::kLogSeverity_ErrorReport) settings.log_severity = LOGSEVERITY_ERROR_REPORT; else if (str == cefclient::kLogSeverity_Disable) settings.log_severity = LOGSEVERITY_DISABLE; else invalid = true; } if (str.empty() || invalid) { #ifdef NDEBUG // Only log error messages and higher in release build. settings.log_severity = LOGSEVERITY_ERROR; #endif } } { std::string str = g_command_line->GetSwitchValue(cefclient::kGraphicsImpl); if (!str.empty()) { #if defined(OS_WIN) if (str == cefclient::kGraphicsImpl_Angle) settings.graphics_implementation = ANGLE_IN_PROCESS; else if (str == cefclient::kGraphicsImpl_AngleCmdBuffer) settings.graphics_implementation = ANGLE_IN_PROCESS_COMMAND_BUFFER; else #endif if (str == cefclient::kGraphicsImpl_Desktop) settings.graphics_implementation = DESKTOP_IN_PROCESS; else if (str == cefclient::kGraphicsImpl_DesktopCmdBuffer) settings.graphics_implementation = DESKTOP_IN_PROCESS_COMMAND_BUFFER; } } settings.local_storage_quota = GetIntValue( g_command_line->GetSwitchValue(cefclient::kLocalStorageQuota)); settings.session_storage_quota = GetIntValue( g_command_line->GetSwitchValue(cefclient::kSessionStorageQuota)); CefString(&settings.javascript_flags) = g_command_line->GetSwitchValue(cefclient::kJavascriptFlags); // Retrieve command-line proxy configuration, if any. bool has_proxy = false; cef_proxy_type_t proxy_type = PROXY_TYPE_DIRECT; CefString proxy_config; if (g_command_line->HasSwitch(cefclient::kProxyType)) { std::string str = g_command_line->GetSwitchValue(cefclient::kProxyType); if (str == cefclient::kProxyType_Direct) { has_proxy = true; proxy_type = PROXY_TYPE_DIRECT; } else if (str == cefclient::kProxyType_Named || str == cefclient::kProxyType_Pac) { proxy_config = g_command_line->GetSwitchValue(cefclient::kProxyConfig); if (!proxy_config.empty()) { has_proxy = true; proxy_type = (str == cefclient::kProxyType_Named? PROXY_TYPE_NAMED:PROXY_TYPE_PAC_STRING); } } } if (has_proxy) { // Provide a ClientApp instance to handle proxy resolution. app->SetProxyConfig(proxy_type, proxy_config); } // Enable dev tools settings.remote_debugging_port = 9234; }
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) { CEF_REQUIRE_UI_THREAD(); GtkButtonsType buttons = GTK_BUTTONS_NONE; GtkMessageType gtk_message_type = GTK_MESSAGE_OTHER; std::string title; switch (dialog_type) { case JSDIALOGTYPE_ALERT: buttons = GTK_BUTTONS_NONE; gtk_message_type = GTK_MESSAGE_WARNING; title = "JavaScript Alert"; break; case JSDIALOGTYPE_CONFIRM: buttons = GTK_BUTTONS_CANCEL; gtk_message_type = GTK_MESSAGE_QUESTION; title = "JavaScript Confirm"; break; case JSDIALOGTYPE_PROMPT: buttons = GTK_BUTTONS_CANCEL; gtk_message_type = GTK_MESSAGE_QUESTION; title = "JavaScript Prompt"; break; } js_dialog_callback_ = callback; if (!origin_url.empty()) { title += " - "; title += origin_url.ToString(); } GtkWidget* window = gtk_widget_get_ancestor( GTK_WIDGET(GetMainWindowHandle()), GTK_TYPE_WINDOW); gtk_dialog_ = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL, gtk_message_type, buttons, "%s", message_text.ToString().c_str()); g_signal_connect(gtk_dialog_, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL); gtk_window_set_title(GTK_WINDOW(gtk_dialog_), title.c_str()); GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), GTK_STOCK_OK, GTK_RESPONSE_OK); if (dialog_type != JSDIALOGTYPE_PROMPT) gtk_widget_grab_focus(ok_button); if (dialog_type == JSDIALOGTYPE_PROMPT) { GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(gtk_dialog_)); GtkWidget* text_box = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(text_box), default_prompt_text.ToString().c_str()); gtk_box_pack_start(GTK_BOX(content_area), text_box, TRUE, TRUE, 0); g_object_set_data(G_OBJECT(gtk_dialog_), kPromptTextId, text_box); gtk_entry_set_activates_default(GTK_ENTRY(text_box), TRUE); } gtk_dialog_set_default_response(GTK_DIALOG(gtk_dialog_), GTK_RESPONSE_OK); g_signal_connect(gtk_dialog_, "response", G_CALLBACK(OnDialogResponse), this); gtk_widget_show_all(GTK_WIDGET(gtk_dialog_)); return true; }
bool ClientHandler::OnFileDialog(CefRefPtr<CefBrowser> browser, FileDialogMode mode, const CefString& title, const CefString& default_file_name, const std::vector<CefString>& accept_types, CefRefPtr<CefFileDialogCallback> callback) { std::vector<CefString> files; GtkFileChooserAction action; const gchar* accept_button; if (mode == FILE_DIALOG_OPEN || mode == FILE_DIALOG_OPEN_MULTIPLE) { action = GTK_FILE_CHOOSER_ACTION_OPEN; accept_button = GTK_STOCK_OPEN; } else if (mode == FILE_DIALOG_SAVE) { action = GTK_FILE_CHOOSER_ACTION_SAVE; accept_button = GTK_STOCK_SAVE; } else { NOTREACHED(); return false; } std::string base_name; if (!default_file_name.empty()) { base_name = basename(const_cast<char*>(default_file_name.ToString().c_str())); } std::string title_str; if (!title.empty()) { title_str = title; } else { switch (mode) { case FILE_DIALOG_OPEN: title_str = "Open File"; break; case FILE_DIALOG_OPEN_MULTIPLE: title_str = "Open Files"; break; case FILE_DIALOG_SAVE: title_str = "Save File"; break; default: break; } } GtkWidget* window = gtk_widget_get_ancestor( GTK_WIDGET(GetMainWindowHandle()), GTK_TYPE_WINDOW); GtkWidget* dialog = gtk_file_chooser_dialog_new( title_str.c_str(), GTK_WINDOW(window), action, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, accept_button, GTK_RESPONSE_ACCEPT, NULL); if (mode == FILE_DIALOG_OPEN_MULTIPLE) { gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); } else if (mode == FILE_DIALOG_SAVE) { gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); } if (mode == FILE_DIALOG_SAVE && !base_name.empty()) { gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), base_name.c_str()); } AddFiltersForAcceptTypes(GTK_FILE_CHOOSER(dialog), accept_types, true); bool success = false; if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { if (mode == FILE_DIALOG_OPEN || mode == FILE_DIALOG_SAVE) { char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); files.push_back(std::string(filename)); success = true; } else if (mode == FILE_DIALOG_OPEN_MULTIPLE) { GSList* filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)); if (filenames) { for (GSList* iter = filenames; iter != NULL; iter = g_slist_next(iter)) { std::string path(static_cast<char*>(iter->data)); g_free(iter->data); files.push_back(path); } g_slist_free(filenames); success = true; } } } gtk_widget_destroy(dialog); if (success) callback->Continue(files); else callback->Cancel(); return true; }
virtual bool Execute(const CefString& InName, CefRefPtr<CefV8Value> InObject, const CefV8ValueList& InArguments, CefRefPtr<CefV8Value>& OutRetval, CefString& OutException) { bool Handled = false; bool ValidAPI = true; if (InName == "TriggerEvent") { // dispatch hook to the browser process for execution on the game thread if ((InArguments.size() == 1) && InArguments[0]->IsArray()) { CefRefPtr<CefV8Value> ArgumentArray = InArguments[0]; if (ArgumentArray->GetArrayLength() > 0) { CefRefPtr<CefBrowser> Browser = CefV8Context::GetCurrentContext()->GetBrowser(); ASSERT(Browser.get()); CefString HookName = ArgumentArray->GetValue(0)->GetStringValue(); if (!HookName.empty()) { CefRefPtr<CefProcessMessage> Message = CefProcessMessage::Create(HookName); // translate remaining args. if ((ArgumentArray->GetArrayLength() > 1) && ArgumentArray->GetValue(1)->IsArray()) { CefRefPtr<CefV8Value> InParameters = ArgumentArray->GetValue(1); const int NumParameters = InParameters->GetArrayLength(); CefRefPtr<CefListValue> OutParameters = Message->GetArgumentList(); OutParameters->SetSize(NumParameters); for (int i = 0; i < (int)NumParameters; ++i) { V8ValueToListItem_RenderThread(InParameters->GetValue(i), OutParameters, i); } } Browser->SendProcessMessage(PID_BROWSER, Message); Handled = true; } } } } else if (InName == "SetHook") { if ((InArguments.size() == 2) && (InArguments[0]->IsString()) && (InArguments[1]->IsFunction())) { CefString HookName = InArguments[0]->GetStringValue().ToString(); CefRefPtr<CefV8Context> Context = CefV8Context::GetCurrentContext(); App->SetJSHook(HookName, Context->GetBrowser()->GetIdentifier(), Context, InArguments[1]); Handled = true; } } else if (InName == "RemoveHook") { if ((InArguments.size() == 1) && InArguments[0]->IsString()) { CefRefPtr<CefV8Context> Context = CefV8Context::GetCurrentContext(); App->RemoveJSHook(InArguments[0]->GetStringValue(), Context->GetBrowser()->GetIdentifier()); Handled = true; } } else { ValidAPI = false; OutException = std::string("Unrecognized JSHook API Call: '") + InName.ToString() + std::string("'"); } if (!Handled && ValidAPI) { OutException = std::string("Invalid Arguments Passed To '") + InName.ToString() + std::string("'"); } return Handled; }