From 2204e9bb15c9e8895bfa0896867ac91be5766094 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 22 May 2014 22:54:09 +0800 Subject: [PATCH] Add 'web-preferences' options in BrowserWindow. --- atom/browser/native_window.cc | 27 +++++++++++++++++++++++++++ atom/browser/native_window.h | 3 +++ atom/common/options_switches.cc | 3 +++ atom/common/options_switches.h | 1 + 4 files changed, 34 insertions(+) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 558778029e5..2c8635b91b0 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -76,6 +76,11 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, // Read iframe security before any navigation. options->GetString(switches::kNodeIntegration, &node_integration_); + // Read the web preferences. + base::DictionaryValue* web_preferences; + if (options->GetDictionary(switches::kWebPreferences, &web_preferences)) + web_preferences_.reset(web_preferences->DeepCopy()); + web_contents->SetDelegate(this); inspectable_web_contents()->SetDelegate(this); @@ -348,6 +353,28 @@ void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) { // FIXME Disable accelerated composition in frameless window. if (!has_frame_) prefs->accelerated_compositing_enabled = false; + + bool b; + if (!web_preferences_) + return; + else if (web_preferences_->GetBoolean("javascript", &b)) + prefs->javascript_enabled = b; + else if (web_preferences_->GetBoolean("web-security", &b)) + prefs->web_security_enabled = b; + else if (web_preferences_->GetBoolean("images", &b)) + prefs->images_enabled = b; + else if (web_preferences_->GetBoolean("plugins", &b)) + prefs->plugins_enabled = b; + else if (web_preferences_->GetBoolean("java", &b)) + prefs->java_enabled = b; + else if (web_preferences_->GetBoolean("text-areas-are-resizable", &b)) + prefs->text_areas_are_resizable = b; + else if (web_preferences_->GetBoolean("webgl", &b)) + prefs->experimental_webgl_enabled = b; + else if (web_preferences_->GetBoolean("webaudio", &b)) + prefs->webaudio_enabled = b; + else if (web_preferences_->GetBoolean("accelerated-compositing", &b)) + prefs->accelerated_compositing_enabled = b; } void NativeWindow::NotifyWindowClosed() { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 7c2b6080671..e9bce813970 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -290,6 +290,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // it should be cancelled when we can prove that the window is responsive. base::CancelableClosure window_unresposive_closure_; + // web preferences. + scoped_ptr web_preferences_; + base::WeakPtrFactory weak_factory_; base::WeakPtr devtools_window_; diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 270fc1f4831..05fc8b0f359 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -39,6 +39,9 @@ const char kAcceptFirstMouse[] = "accept-first-mouse"; // Whether window size should include window frame. const char kUseContentSize[] = "use-content-size"; +// The WebPreferences. +const char kWebPreferences[] = "web-preferences"; + } // namespace switches } // namespace atom diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index 8fa105684dc..31463e64d9f 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -29,6 +29,7 @@ extern const char kAlwaysOnTop[]; extern const char kNodeIntegration[]; extern const char kAcceptFirstMouse[]; extern const char kUseContentSize[]; +extern const char kWebPreferences[]; } // namespace switches