]> khamidou — GitHub mirrors - electron.git/commitdiff
Move OverrideWebkitPrefs to WebContentsPreferences
authorCheng Zhao <zcbenz@gmail.com>
Fri, 4 Sep 2015 17:12:32 +0000 (02:12 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 6 Sep 2015 02:53:03 +0000 (10:53 +0800)
atom/browser/atom_browser_client.cc
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/web_contents_preferences.cc
atom/browser/web_contents_preferences.h

index fad952d53365cc1754afccf2166f060d9f232f1e..ce333a58579c28d152c527efa6ac5ab3599359cd 100644 (file)
@@ -15,6 +15,7 @@
 #include "atom/browser/atom_speech_recognition_manager_delegate.h"
 #include "atom/browser/browser.h"
 #include "atom/browser/native_window.h"
+#include "atom/browser/web_contents_preferences.h"
 #include "atom/browser/web_view_manager.h"
 #include "atom/browser/web_view_constants.h"
 #include "atom/browser/window_list.h"
@@ -169,7 +170,7 @@ void AtomBrowserClient::OverrideWebkitPrefs(
 
   NativeWindow* window = NativeWindow::FromWebContents(web_contents);
   if (window)
-    window->OverrideWebkitPrefs(prefs);
+    WebContentsPreferences::OverrideWebkitPrefs(web_contents, prefs);
 }
 
 std::string AtomBrowserClient::GetApplicationLocale() {
@@ -231,6 +232,8 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
 
   if (owner == OWNER_NATIVE_WINDOW) {
     window->AppendExtraCommandLineSwitches(command_line);
+    WebContentsPreferences::AppendExtraCommandLineSwitches(
+        window->web_contents(), command_line);
   } else if (owner == OWNER_GUEST_WEB_CONTENTS) {
     command_line->AppendSwitchASCII(
         switches::kGuestInstanceID, base::IntToString(info.guest_instance_id));
index 51762d9c00af3181f8821545c09e4d1692a7eebc..eb7f314fe889287b35dc45b115c74fa687d8fef5 100644 (file)
@@ -31,8 +31,6 @@
 #include "content/public/browser/render_view_host.h"
 #include "content/public/browser/render_widget_host_view.h"
 #include "content/public/common/content_switches.h"
-#include "content/public/common/renderer_preferences.h"
-#include "content/public/common/web_preferences.h"
 #include "ipc/ipc_message_macros.h"
 #include "native_mate/dictionary.h"
 #include "ui/gfx/codec/png_codec.h"
@@ -382,34 +380,6 @@ void NativeWindow::AppendExtraCommandLineSwitches(
                                     base::DoubleToString(zoom_factor_));
 }
 
-void NativeWindow::OverrideWebkitPrefs(content::WebPreferences* prefs) {
-  if (web_preferences_.IsEmpty())
-    return;
-
-  bool b;
-  if (web_preferences_.Get("javascript", &b))
-    prefs->javascript_enabled = b;
-  if (web_preferences_.Get("images", &b))
-    prefs->images_enabled = b;
-  if (web_preferences_.Get("java", &b))
-    prefs->java_enabled = b;
-  if (web_preferences_.Get("text-areas-are-resizable", &b))
-    prefs->text_areas_are_resizable = b;
-  if (web_preferences_.Get("webgl", &b))
-    prefs->experimental_webgl_enabled = b;
-  if (web_preferences_.Get("webaudio", &b))
-    prefs->webaudio_enabled = b;
-  if (web_preferences_.Get("web-security", &b)) {
-    prefs->web_security_enabled = b;
-    prefs->allow_displaying_insecure_content = !b;
-    prefs->allow_running_insecure_content = !b;
-  }
-  if (web_preferences_.Get("allow-displaying-insecure-content", &b))
-    prefs->allow_displaying_insecure_content = b;
-  if (web_preferences_.Get("allow-running-insecure-content", &b))
-    prefs->allow_running_insecure_content = b;
-}
-
 void NativeWindow::NotifyWindowClosed() {
   if (is_closed_)
     return;
index 10889a5ccaf9e4aec50bd5f7cf1bc2e61e344410..4f074010ec40042f8b2cef11c5fb8fab7107afe1 100644 (file)
@@ -35,7 +35,6 @@ class InspectableWebContents;
 
 namespace content {
 struct NativeWebKeyboardEvent;
-struct WebPreferences;
 }
 
 namespace gfx {
@@ -191,7 +190,6 @@ class NativeWindow : public content::WebContentsObserver,
 
   // Called when renderer process is going to be started.
   void AppendExtraCommandLineSwitches(base::CommandLine* command_line);
-  void OverrideWebkitPrefs(content::WebPreferences* prefs);
 
   // Public API used by platform-dependent delegates and observers to send UI
   // related notifications.
index 44525a8612e3549a25a58f40a5215161d2ef06bd..ad5e04fcdbf34f20d474f67e1305875503f97e7b 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "atom/common/options_switches.h"
 #include "base/command_line.h"
+#include "content/public/common/web_preferences.h"
 
 #if defined(OS_WIN)
 #include "ui/gfx/switches.h"
@@ -74,4 +75,34 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
   }
 }
 
+void WebContentsPreferences::OverrideWebkitPrefs(
+    content::WebContents* web_contents, content::WebPreferences* prefs) {
+  WebContentsPreferences* self = From(web_contents);
+  CHECK(self);
+
+  bool b;
+  if (self->web_preferences_.GetBoolean("javascript", &b))
+    prefs->javascript_enabled = b;
+  if (self->web_preferences_.GetBoolean("images", &b))
+    prefs->images_enabled = b;
+  if (self->web_preferences_.GetBoolean("java", &b))
+    prefs->java_enabled = b;
+  if (self->web_preferences_.GetBoolean("text-areas-are-resizable", &b))
+    prefs->text_areas_are_resizable = b;
+  if (self->web_preferences_.GetBoolean("webgl", &b))
+    prefs->experimental_webgl_enabled = b;
+  if (self->web_preferences_.GetBoolean("webaudio", &b))
+    prefs->webaudio_enabled = b;
+  if (self->web_preferences_.GetBoolean("web-security", &b)) {
+    prefs->web_security_enabled = b;
+    prefs->allow_displaying_insecure_content = !b;
+    prefs->allow_running_insecure_content = !b;
+  }
+  if (self->web_preferences_.GetBoolean("allow-displaying-insecure-content",
+                                        &b))
+    prefs->allow_displaying_insecure_content = b;
+  if (self->web_preferences_.GetBoolean("allow-running-insecure-content", &b))
+    prefs->allow_running_insecure_content = b;
+}
+
 }  // namespace atom
index 4c606f779d46ee354fa7e2eb7f362f312059e6e5..a2a63415047daae28a45539d060bf43e29d4eddb 100644 (file)
@@ -12,6 +12,10 @@ namespace base {
 class CommandLine;
 }
 
+namespace content {
+struct WebPreferences;
+}
+
 namespace atom {
 
 // Stores and applies the preferences of WebContents.
@@ -21,10 +25,14 @@ class WebContentsPreferences
   // Get the preferences of |web_contents|.
   static WebContentsPreferences* From(content::WebContents* web_contents);
 
-  // Append command paramters appending to |web_contents|'s preferences.
+  // Append command paramters according to |web_contents|'s preferences.
   static void AppendExtraCommandLineSwitches(
       content::WebContents* web_contents, base::CommandLine* command_line);
 
+  // Modify the WebPreferences according to |web_contents|'s preferences.
+  static void OverrideWebkitPrefs(
+      content::WebContents* web_contents, content::WebPreferences* prefs);
+
   WebContentsPreferences(content::WebContents* web_contents,
                          base::DictionaryValue&& web_preferences);
   ~WebContentsPreferences() override;