Fix crashing when setting web-preferences, closes #443.

This commit is contained in:
Cheng Zhao 2014-07-21 13:08:52 +08:00
parent 365638f1d5
commit fab11950ee
4 changed files with 23 additions and 18 deletions

View file

@ -79,9 +79,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
options.Get(switches::kNodeIntegration, &node_integration_); options.Get(switches::kNodeIntegration, &node_integration_);
// Read the web preferences. // Read the web preferences.
scoped_ptr<mate::Dictionary> web_preferences(new mate::Dictionary); options.Get(switches::kWebPreferences, &web_preferences_);
if (options.Get(switches::kWebPreferences, web_preferences.get()))
web_preferences_.reset(web_preferences.release());
// Read the zoom factor before any navigation. // Read the zoom factor before any navigation.
options.Get(switches::kZoomFactor, &zoom_factor_); options.Get(switches::kZoomFactor, &zoom_factor_);
@ -329,29 +327,32 @@ void NativeWindow::AppendExtraCommandLineSwitches(
} }
void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) { void NativeWindow::OverrideWebkitPrefs(const GURL& url, WebPreferences* prefs) {
if (web_preferences_.IsEmpty())
return;
bool b; bool b;
std::vector<base::FilePath> list; std::vector<base::FilePath> list;
if (!web_preferences_) mate::Dictionary web_preferences(web_preferences_.isolate(),
return; web_preferences_.NewHandle());
if (web_preferences_->Get("javascript", &b)) if (web_preferences.Get("javascript", &b))
prefs->javascript_enabled = b; prefs->javascript_enabled = b;
if (web_preferences_->Get("web-security", &b)) if (web_preferences.Get("web-security", &b))
prefs->web_security_enabled = b; prefs->web_security_enabled = b;
if (web_preferences_->Get("images", &b)) if (web_preferences.Get("images", &b))
prefs->images_enabled = b; prefs->images_enabled = b;
if (web_preferences_->Get("java", &b)) if (web_preferences.Get("java", &b))
prefs->java_enabled = 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; prefs->text_areas_are_resizable = b;
if (web_preferences_->Get("webgl", &b)) if (web_preferences.Get("webgl", &b))
prefs->experimental_webgl_enabled = b; prefs->experimental_webgl_enabled = b;
if (web_preferences_->Get("webaudio", &b)) if (web_preferences.Get("webaudio", &b))
prefs->webaudio_enabled = b; prefs->webaudio_enabled = b;
if (web_preferences_->Get("accelerated-compositing", &b)) if (web_preferences.Get("accelerated-compositing", &b))
prefs->accelerated_compositing_enabled = b; prefs->accelerated_compositing_enabled = b;
if (web_preferences_->Get("plugins", &b)) if (web_preferences.Get("plugins", &b))
prefs->plugins_enabled = 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) for (size_t i = 0; i < list.size(); ++i)
content::PluginService::GetInstance()->AddExtraPluginDir(list[i]); content::PluginService::GetInstance()->AddExtraPluginDir(list[i]);
} }

View file

@ -19,6 +19,7 @@
#include "atom/browser/ui/accelerator_util.h" #include "atom/browser/ui/accelerator_util.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_observer.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/default_web_contents_delegate.h"
#include "vendor/brightray/browser/inspectable_web_contents_delegate.h" #include "vendor/brightray/browser/inspectable_web_contents_delegate.h"
#include "vendor/brightray/browser/inspectable_web_contents_impl.h" #include "vendor/brightray/browser/inspectable_web_contents_impl.h"
@ -290,7 +291,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
base::CancelableClosure window_unresposive_closure_; base::CancelableClosure window_unresposive_closure_;
// Web preferences. // Web preferences.
scoped_ptr<mate::Dictionary> web_preferences_; mate::ScopedPersistent<v8::Object> web_preferences_;
// Page's default zoom factor. // Page's default zoom factor.
double zoom_factor_; double zoom_factor_;

View file

@ -139,7 +139,10 @@ app.on('ready', function() {
title: 'atom-shell tests', title: 'atom-shell tests',
show: false, show: false,
width: 800, width: 800,
height: 600 height: 600,
'web-preferences': {
javascript: true // Test whether web-preferences crashes.
},
}); });
window.loadUrl('file://' + __dirname + '/index.html'); window.loadUrl('file://' + __dirname + '/index.html');
window.on('unresponsive', function() { window.on('unresponsive', function() {

2
vendor/native_mate vendored

@ -1 +1 @@
Subproject commit 14c851e9f887a09ac3e055aacb930b0b3c690df4 Subproject commit 3d713baa4c33baebfac82b242e8897504592c590