From 81241b38eb5587bfc2045ebb54b62f44b1e9751e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Sep 2014 10:33:31 +0800 Subject: [PATCH 1/5] Add switches of web runtime flags. --- atom/common/options_switches.cc | 18 ++++++++++++++++++ atom/common/options_switches.h | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index e322c2230f09..7c23c86416eb 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -57,6 +57,24 @@ const char kEnableLargerThanScreen[] = "enable-larger-than-screen"; // Forces to use dark theme on Linux. const char kDarkTheme[] = "dark-theme"; +// Array of availabe web runtime features. +const char kExperimentalFeatures[] = "experimental-features"; +const char kExperimentalCanvasFeatures[] = "experimental-canvas-features"; +const char kSubpixelFontScaling[] = "subpixel-font-scaling"; +const char kOverlayScrollbars[] = "overlay-scrollbars"; +const char kOverlayFullscreenVideo[] = "overlay-fullscreen-video"; +const char kSharedWorker[] = "shared-worker"; + +const int kWebRuntimeFeaturesFlagsSize = 6; +const char* kWebRuntimeFeaturesFlags[kWebRuntimeFeaturesFlagsSize] = { + kExperimentalFeatures, + kExperimentalCanvasFeatures, + kSubpixelFontScaling, + kOverlayScrollbars, + kOverlayFullscreenVideo, + kSharedWorker, +}; + } // namespace switches } // namespace atom diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index f571e3f431d1..1e504ef161b9 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -36,6 +36,15 @@ extern const char kAutoHideMenuBar[]; extern const char kEnableLargerThanScreen[]; extern const char kDarkTheme[]; +extern const char kExperimentalFeatures[]; +extern const char kExperimentalCanvasFeatures[]; +extern const char kSubpixelFontScaling[]; +extern const char kOverlayScrollbars[]; +extern const char kOverlayFullscreenVideo[]; +extern const char kSharedWorker[]; +extern const int kWebRuntimeFeaturesFlagsSize; +extern const char* kWebRuntimeFeaturesFlags[]; + } // namespace switches } // namespace atom From 8de90db429110b5e2af8f8ee755c4e746497da4a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Sep 2014 11:08:30 +0800 Subject: [PATCH 2/5] Pass web runtime features by command line. --- atom/browser/native_window.cc | 15 ++++++++++++ atom/renderer/atom_renderer_client.cc | 33 +++++++++++++++++++++++++++ atom/renderer/atom_renderer_client.h | 2 ++ 3 files changed, 50 insertions(+) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index d3fed614547b..7b8e2ab29b70 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -325,6 +325,21 @@ void NativeWindow::AppendExtraCommandLineSwitches( if (zoom_factor_ != 1.0) command_line->AppendSwitchASCII(switches::kZoomFactor, base::DoubleToString(zoom_factor_)); + + if (web_preferences_.IsEmpty()) + return; + + // This set of options are not availabe in WebPreferences, so we have to pass + // them via command line and enable them in renderer procss. + bool b; + std::string web_runtime_features; + mate::Dictionary web_preferences(web_preferences_.isolate(), + web_preferences_.NewHandle()); + for (int i = 0; i < switches::kWebRuntimeFeaturesFlagsSize; ++i) { + const char* feature_flag = switches::kWebRuntimeFeaturesFlags[i]; + if (web_preferences.Get(feature_flag, &b)) + command_line->AppendSwitchASCII(feature_flag, b ? "true" : "false"); + } } void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) { diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 8739efef4572..fb935fc1f235 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -20,6 +20,7 @@ #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebFrame.h" #include "third_party/WebKit/public/web/WebKit.h" +#include "third_party/WebKit/public/web/WebRuntimeFeatures.h" #include "atom/common/node_includes.h" @@ -34,6 +35,19 @@ const char* kSecurityManualEnableIframe = "manual-enable-iframe"; const char* kSecurityDisable = "disable"; const char* kSecurityEnableNodeIntegration = "enable-node-integration"; +bool IsSwitchEnabled(base::CommandLine* command_line, + const char* switch_string, + bool* enabled) { + std::string value = command_line->GetSwitchValueASCII(switch_string); + if (value == "true") + *enabled = true; + else if (value == "false") + *enabled = false; + else + return false; + return true; +} + // Helper class to forward the WillReleaseScriptContext message to the client. class AtomRenderFrameObserver : public content::RenderFrameObserver { public: @@ -86,6 +100,8 @@ AtomRendererClient::~AtomRendererClient() { } void AtomRendererClient::WebKitInitialized() { + EnableWebRuntimeFeatures(); + if (!IsNodeBindingEnabled()) return; @@ -220,4 +236,21 @@ bool AtomRendererClient::IsNodeBindingEnabled(blink::WebFrame* frame) { return true; } +void AtomRendererClient::EnableWebRuntimeFeatures() { + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + bool b; + if (IsSwitchEnabled(command_line, switches::kExperimentalFeatures, &b)) + blink::WebRuntimeFeatures::enableExperimentalFeatures(b); + if (IsSwitchEnabled(command_line, switches::kExperimentalCanvasFeatures, &b)) + blink::WebRuntimeFeatures::enableExperimentalCanvasFeatures(b); + if (IsSwitchEnabled(command_line, switches::kSubpixelFontScaling, &b)) + blink::WebRuntimeFeatures::enableSubpixelFontScaling(b); + if (IsSwitchEnabled(command_line, switches::kOverlayScrollbars, &b)) + blink::WebRuntimeFeatures::enableOverlayScrollbars(b); + if (IsSwitchEnabled(command_line, switches::kOverlayFullscreenVideo, &b)) + blink::WebRuntimeFeatures::enableOverlayFullscreenVideo(b); + if (IsSwitchEnabled(command_line, switches::kSharedWorker, &b)) + blink::WebRuntimeFeatures::enableSharedWorker(b); +} + } // namespace atom diff --git a/atom/renderer/atom_renderer_client.h b/atom/renderer/atom_renderer_client.h index 818c65ed6be6..ca76147ddf60 100644 --- a/atom/renderer/atom_renderer_client.h +++ b/atom/renderer/atom_renderer_client.h @@ -61,6 +61,8 @@ class AtomRendererClient : public content::ContentRendererClient, bool is_server_redirect, bool* send_referrer) OVERRIDE; + void EnableWebRuntimeFeatures(); + std::vector web_page_envs_; scoped_ptr node_bindings_; From f08c3f91347861c8f37388802810f366ffef713b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Sep 2014 11:14:44 +0800 Subject: [PATCH 3/5] docs: Add options for web runtime features. --- docs/api/browser-window.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index f50021e464fa..ea6d36d9818f 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -80,6 +80,12 @@ normal browsers, see [Web Security](web-security.md) for more. should use `__dirname` or `process.resourcesPath` to join the paths to make them absolute, using relative paths would make atom-shell search under current working directory. + * `experimental-features` Boolean + * `experimental-canvas-features` Boolean + * `subpixel-font-scaling` Boolean + * `overlay-scrollbars` Boolean + * `overlay-fullscreen-video` Boolean + * `shared-worker` Boolean Creates a new `BrowserWindow` with native properties set by the `options`. Usually you only need to set the `width` and `height`, other properties will From 44d3e58ddb17f7f34f2fff454a71cdbd8fc38cc8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Sep 2014 13:21:15 +0800 Subject: [PATCH 4/5] Make code more tidy. --- atom/browser/native_window.cc | 23 ++++++++++++++++++----- atom/common/options_switches.cc | 22 ++++++---------------- atom/common/options_switches.h | 2 -- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 7b8e2ab29b70..6cc0bc8fe052 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -55,6 +55,20 @@ using content::NavigationEntry; namespace atom { +namespace { + +// Array of available web runtime features. +const char* kWebRuntimeFeatures[] = { + switches::kExperimentalFeatures, + switches::kExperimentalCanvasFeatures, + switches::kSubpixelFontScaling, + switches::kOverlayScrollbars, + switches::kOverlayFullscreenVideo, + switches::kSharedWorker, +}; + +} // namespace + NativeWindow::NativeWindow(content::WebContents* web_contents, const mate::Dictionary& options) : content::WebContentsObserver(web_contents), @@ -332,13 +346,12 @@ void NativeWindow::AppendExtraCommandLineSwitches( // This set of options are not availabe in WebPreferences, so we have to pass // them via command line and enable them in renderer procss. bool b; - std::string web_runtime_features; mate::Dictionary web_preferences(web_preferences_.isolate(), web_preferences_.NewHandle()); - for (int i = 0; i < switches::kWebRuntimeFeaturesFlagsSize; ++i) { - const char* feature_flag = switches::kWebRuntimeFeaturesFlags[i]; - if (web_preferences.Get(feature_flag, &b)) - command_line->AppendSwitchASCII(feature_flag, b ? "true" : "false"); + 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"); } } diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 7c23c86416eb..806191750c40 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -57,23 +57,13 @@ const char kEnableLargerThanScreen[] = "enable-larger-than-screen"; // Forces to use dark theme on Linux. const char kDarkTheme[] = "dark-theme"; -// Array of availabe web runtime features. -const char kExperimentalFeatures[] = "experimental-features"; +// Web runtime features. +const char kExperimentalFeatures[] = "experimental-features"; const char kExperimentalCanvasFeatures[] = "experimental-canvas-features"; -const char kSubpixelFontScaling[] = "subpixel-font-scaling"; -const char kOverlayScrollbars[] = "overlay-scrollbars"; -const char kOverlayFullscreenVideo[] = "overlay-fullscreen-video"; -const char kSharedWorker[] = "shared-worker"; - -const int kWebRuntimeFeaturesFlagsSize = 6; -const char* kWebRuntimeFeaturesFlags[kWebRuntimeFeaturesFlagsSize] = { - kExperimentalFeatures, - kExperimentalCanvasFeatures, - kSubpixelFontScaling, - kOverlayScrollbars, - kOverlayFullscreenVideo, - kSharedWorker, -}; +const char kSubpixelFontScaling[] = "subpixel-font-scaling"; +const char kOverlayScrollbars[] = "overlay-scrollbars"; +const char kOverlayFullscreenVideo[] = "overlay-fullscreen-video"; +const char kSharedWorker[] = "shared-worker"; } // namespace switches diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index 1e504ef161b9..8bdc3bcdda1f 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -42,8 +42,6 @@ extern const char kSubpixelFontScaling[]; extern const char kOverlayScrollbars[]; extern const char kOverlayFullscreenVideo[]; extern const char kSharedWorker[]; -extern const int kWebRuntimeFeaturesFlagsSize; -extern const char* kWebRuntimeFeaturesFlags[]; } // namespace switches From 33b94edcf0c52587e530bd5643b60fe48957e70e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Sep 2014 14:13:21 +0800 Subject: [PATCH 5/5] Use PersistentDictionary to store web perferences. --- atom/browser/api/atom_api_dialog.cc | 2 +- atom/browser/native_window.cc | 24 ++++++++++-------------- atom/browser/native_window.h | 4 ++-- vendor/native_mate | 2 +- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/atom/browser/api/atom_api_dialog.cc b/atom/browser/api/atom_api_dialog.cc index 6a1a7a4b5763..64c4d2fd863a 100644 --- a/atom/browser/api/atom_api_dialog.cc +++ b/atom/browser/api/atom_api_dialog.cc @@ -23,7 +23,7 @@ struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Handle val, file_dialog::Filter* out) { - mate::Dictionary dict(isolate); + mate::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; if (!dict.Get("name", &(out->first))) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 6cc0bc8fe052..be41bf25e177 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -346,11 +346,9 @@ void NativeWindow::AppendExtraCommandLineSwitches( // This set of options are not availabe in WebPreferences, so we have to pass // them via command line and enable them in renderer procss. bool b; - mate::Dictionary web_preferences(web_preferences_.isolate(), - web_preferences_.NewHandle()); for (size_t i = 0; i < arraysize(kWebRuntimeFeatures); ++i) { const char* feature = kWebRuntimeFeatures[i]; - if (web_preferences.Get(feature, &b)) + if (web_preferences_.Get(feature, &b)) command_line->AppendSwitchASCII(feature, b ? "true" : "false"); } } @@ -361,25 +359,23 @@ void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) { bool b; std::vector list; - mate::Dictionary web_preferences(web_preferences_.isolate(), - web_preferences_.NewHandle()); - if (web_preferences.Get("javascript", &b)) + if (web_preferences_.Get("javascript", &b)) prefs->javascript_enabled = b; - if (web_preferences.Get("web-security", &b)) + if (web_preferences_.Get("web-security", &b)) prefs->web_security_enabled = b; - if (web_preferences.Get("images", &b)) + if (web_preferences_.Get("images", &b)) prefs->images_enabled = b; - if (web_preferences.Get("java", &b)) + if (web_preferences_.Get("java", &b)) prefs->java_enabled = b; - if (web_preferences.Get("text-areas-are-resizable", &b)) + if (web_preferences_.Get("text-areas-are-resizable", &b)) prefs->text_areas_are_resizable = b; - if (web_preferences.Get("webgl", &b)) + if (web_preferences_.Get("webgl", &b)) prefs->experimental_webgl_enabled = b; - if (web_preferences.Get("webaudio", &b)) + if (web_preferences_.Get("webaudio", &b)) prefs->webaudio_enabled = b; - if (web_preferences.Get("plugins", &b)) + if (web_preferences_.Get("plugins", &b)) prefs->plugins_enabled = b; - if (web_preferences.Get("extra-plugin-dirs", &list)) + if (web_preferences_.Get("extra-plugin-dirs", &list)) for (size_t i = 0; i < list.size(); ++i) content::PluginService::GetInstance()->AddExtraPluginDir(list[i]); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index bc052a8e105d..1da62ce3f7bd 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -20,7 +20,7 @@ #include "brightray/browser/inspectable_web_contents_impl.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_observer.h" -#include "native_mate/scoped_persistent.h" +#include "native_mate/persistent_dictionary.h" #include "ui/gfx/image/image_skia.h" struct WebPreferences; @@ -298,7 +298,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, base::CancelableClosure window_unresposive_closure_; // Web preferences. - mate::ScopedPersistent web_preferences_; + mate::PersistentDictionary web_preferences_; // Page's default zoom factor. double zoom_factor_; diff --git a/vendor/native_mate b/vendor/native_mate index 980036b78a13..12f4e9b7ea00 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit 980036b78a132ab820ed1d7866a06aac9a5c95a8 +Subproject commit 12f4e9b7ea0038e58e52839142eff0a4d17069bf