]> khamidou — GitHub mirrors - electron.git/commitdiff
Pass web runtime features by command line.
authorCheng Zhao <zcbenz@gmail.com>
Tue, 9 Sep 2014 03:08:30 +0000 (11:08 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 9 Sep 2014 03:08:30 +0000 (11:08 +0800)
atom/browser/native_window.cc
atom/renderer/atom_renderer_client.cc
atom/renderer/atom_renderer_client.h

index d3fed614547bb8c642fe6286836b3a21d9220f23..7b8e2ab29b70f5265ff8505c320a29d48efb1471 100644 (file)
@@ -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) {
index 8739efef4572c82f9835c13013156f233edf8905..fb935fc1f235dc8f1666d6b75d1724b1594d7f02 100644 (file)
@@ -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
index 818c65ed6be6ed26c3d3d76b97750496d6add211..ca76147ddf60ae80bd061b758d636cc5244ea2fb 100644 (file)
@@ -61,6 +61,8 @@ class AtomRendererClient : public content::ContentRendererClient,
                           bool is_server_redirect,
                           bool* send_referrer) OVERRIDE;
 
+  void EnableWebRuntimeFeatures();
+
   std::vector<node::Environment*> web_page_envs_;
 
   scoped_ptr<NodeBindings> node_bindings_;