Fix crashing when setting web-preferences, closes #443.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 21 Jul 2014 05:08:52 +0000 (13:08 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 21 Jul 2014 05:08:52 +0000 (13:08 +0800)
atom/browser/native_window.cc
atom/browser/native_window.h
spec/static/main.js
vendor/native_mate

index 3b95926..f99f783 100644 (file)
@@ -79,9 +79,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
   options.Get(switches::kNodeIntegration, &node_integration_);
 
   // Read the web preferences.
-  scoped_ptr<mate::Dictionary> web_preferences(new mate::Dictionary);
-  if (options.Get(switches::kWebPreferences, web_preferences.get()))
-    web_preferences_.reset(web_preferences.release());
+  options.Get(switches::kWebPreferences, &web_preferences_);
 
   // Read the zoom factor before any navigation.
   options.Get(switches::kZoomFactor, &zoom_factor_);
@@ -329,29 +327,32 @@ void NativeWindow::AppendExtraCommandLineSwitches(
 }
 
 void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) {
+  if (web_preferences_.IsEmpty())
+    return;
+
   bool b;
   std::vector<base::FilePath> list;
-  if (!web_preferences_)
-    return;
-  if (web_preferences_->Get("javascript", &b))
+  mate::Dictionary web_preferences(web_preferences_.isolate(),
+                                   web_preferences_.NewHandle());
+  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("accelerated-compositing", &b))
+  if (web_preferences.Get("accelerated-compositing", &b))
     prefs->accelerated_compositing_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]);
 }
index d77e761..fdb7fa6 100644 (file)
@@ -19,6 +19,7 @@
 #include "atom/browser/ui/accelerator_util.h"
 #include "content/public/browser/notification_registrar.h"
 #include "content/public/browser/notification_observer.h"
+#include "native_mate/scoped_persistent.h"
 #include "vendor/brightray/browser/default_web_contents_delegate.h"
 #include "vendor/brightray/browser/inspectable_web_contents_delegate.h"
 #include "vendor/brightray/browser/inspectable_web_contents_impl.h"
@@ -290,7 +291,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   base::CancelableClosure window_unresposive_closure_;
 
   // Web preferences.
-  scoped_ptr<mate::Dictionary> web_preferences_;
+  mate::ScopedPersistent<v8::Object> web_preferences_;
 
   // Page's default zoom factor.
   double zoom_factor_;
index 5b0817c..af9c0fd 100644 (file)
@@ -139,7 +139,10 @@ app.on('ready', function() {
     title: 'atom-shell tests',
     show: false,
     width: 800,
-    height: 600
+    height: 600,
+    'web-preferences': {
+      javascript: true  // Test whether web-preferences crashes.
+    },
   });
   window.loadUrl('file://' + __dirname + '/index.html');
   window.on('unresponsive', function() {
index 14c851e..3d713ba 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 14c851e9f887a09ac3e055aacb930b0b3c690df4
+Subproject commit 3d713baa4c33baebfac82b242e8897504592c590