diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index b0b99081e3..51762d9c00 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -43,10 +43,6 @@ #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 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) { diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index fbd2c7661a..44525a8612 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -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 diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index c4c50dc070..4c606f779d 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -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;