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

index b0b99081e3c1c7257b15a855d30e3120792edc51..51762d9c00af3181f8821545c09e4d1692a7eebc 100644 (file)
 #include "ui/gfx/screen.h"
 #include "ui/gl/gpu_switching_manager.h"
 
-#if defined(OS_WIN)
-#include "ui/gfx/switches.h"
-#endif
-
 using content::NavigationEntry;
 using content::RenderWidgetHostView;
 using content::RenderWidgetHost;
@@ -57,17 +53,6 @@ namespace atom {
 
 namespace {
 
-// Array of available web runtime features.
-const char* kWebRuntimeFeatures[] = {
-  switches::kExperimentalFeatures,
-  switches::kExperimentalCanvasFeatures,
-  switches::kSubpixelFontScaling,
-  switches::kOverlayScrollbars,
-  switches::kOverlayFullscreenVideo,
-  switches::kSharedWorker,
-  switches::kPageVisibility,
-};
-
 // Convert draggable regions in raw format to SkRegion format. Caller is
 // responsible for deleting the returned SkRegion instance.
 scoped_ptr<SkRegion> DraggableRegionsToSkRegion(
@@ -395,28 +380,6 @@ void NativeWindow::AppendExtraCommandLineSwitches(
   if (zoom_factor_ != 1.0)
     command_line->AppendSwitchASCII(switches::kZoomFactor,
                                     base::DoubleToString(zoom_factor_));
-
-  if (web_preferences_.IsEmpty())
-    return;
-
-  bool b;
-#if defined(OS_WIN)
-  // Check if DirectWrite is disabled.
-  if (web_preferences_.Get(switches::kDirectWrite, &b) && !b)
-    command_line->AppendSwitch(::switches::kDisableDirectWrite);
-#endif
-
-  // Check if plugins are enabled.
-  if (web_preferences_.Get("plugins", &b) && b)
-    command_line->AppendSwitch(switches::kEnablePlugins);
-
-  // This set of options are not availabe in WebPreferences, so we have to pass
-  // them via command line and enable them in renderer procss.
-  for (size_t i = 0; i < arraysize(kWebRuntimeFeatures); ++i) {
-    const char* feature = kWebRuntimeFeatures[i];
-    if (web_preferences_.Get(feature, &b))
-      command_line->AppendSwitchASCII(feature, b ? "true" : "false");
-  }
 }
 
 void NativeWindow::OverrideWebkitPrefs(content::WebPreferences* prefs) {
index fbd2c7661a74e9122bcc68eec97b4df0718111fe..44525a8612e3549a25a58f40a5215161d2ef06bd 100644 (file)
@@ -4,12 +4,31 @@
 
 #include "atom/browser/web_contents_preferences.h"
 
+#include "atom/common/options_switches.h"
+#include "base/command_line.h"
+
+#if defined(OS_WIN)
+#include "ui/gfx/switches.h"
+#endif
+
 namespace atom {
 
 namespace {
 
+// Pointer as WebContents's user data key.
 const char* kWebPreferencesKey = "WebContentsPreferences";
 
+// Array of available web runtime features.
+const char* kWebRuntimeFeatures[] = {
+  switches::kExperimentalFeatures,
+  switches::kExperimentalCanvasFeatures,
+  switches::kSubpixelFontScaling,
+  switches::kOverlayScrollbars,
+  switches::kOverlayFullscreenVideo,
+  switches::kSharedWorker,
+  switches::kPageVisibility,
+};
+
 }  // namespace
 
 WebContentsPreferences::WebContentsPreferences(
@@ -29,4 +48,30 @@ WebContentsPreferences* WebContentsPreferences::From(
       web_contents->GetUserData(kWebPreferencesKey));
 }
 
+// static
+void WebContentsPreferences::AppendExtraCommandLineSwitches(
+    content::WebContents* web_contents, base::CommandLine* command_line) {
+  WebContentsPreferences* self = From(web_contents);
+  CHECK(self);
+
+  bool b;
+#if defined(OS_WIN)
+  // Check if DirectWrite is disabled.
+  if (self->web_preferences_.GetBoolean(switches::kDirectWrite, &b) && !b)
+    command_line->AppendSwitch(::switches::kDisableDirectWrite);
+#endif
+
+  // Check if plugins are enabled.
+  if (self->web_preferences_.GetBoolean("plugins", &b) && b)
+    command_line->AppendSwitch(switches::kEnablePlugins);
+
+  // This set of options are not availabe in WebPreferences, so we have to pass
+  // them via command line and enable them in renderer procss.
+  for (size_t i = 0; i < arraysize(kWebRuntimeFeatures); ++i) {
+    const char* feature = kWebRuntimeFeatures[i];
+    if (self->web_preferences_.GetBoolean(feature, &b))
+      command_line->AppendSwitchASCII(feature, b ? "true" : "false");
+  }
+}
+
 }  // namespace atom
index c4c50dc070723c7aad735e1e05cbb5914c8f3aa1..4c606f779d46ee354fa7e2eb7f362f312059e6e5 100644 (file)
@@ -8,6 +8,10 @@
 #include "base/values.h"
 #include "content/public/browser/web_contents_user_data.h"
 
+namespace base {
+class CommandLine;
+}
+
 namespace atom {
 
 // Stores and applies the preferences of WebContents.
@@ -17,6 +21,10 @@ class WebContentsPreferences
   // Get the preferences of |web_contents|.
   static WebContentsPreferences* From(content::WebContents* web_contents);
 
+  // Append command paramters appending to |web_contents|'s preferences.
+  static void AppendExtraCommandLineSwitches(
+      content::WebContents* web_contents, base::CommandLine* command_line);
+
   WebContentsPreferences(content::WebContents* web_contents,
                          base::DictionaryValue&& web_preferences);
   ~WebContentsPreferences() override;