Avoid storing unrelated things in WebContentsPreferences
authorCheng Zhao <zcbenz@gmail.com>
Wed, 11 Nov 2015 02:32:25 +0000 (10:32 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 11 Nov 2015 02:37:34 +0000 (10:37 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/web_contents_preferences.cc
atom/browser/web_contents_preferences.h

index 5165877d1670d3c62e675ba21c31374a1700bffb..d67794a91aeb53c7fe64ea2c969bad8c285e21ee 100644 (file)
@@ -269,9 +269,7 @@ WebContents::WebContents(v8::Isolate* isolate,
   managed_web_contents()->GetView()->SetDelegate(this);
 
   // Save the preferences in C++.
-  base::DictionaryValue web_preferences;
-  mate::ConvertFromV8(isolate, options.GetHandle(), &web_preferences);
-  new WebContentsPreferences(web_contents, &web_preferences);
+  new WebContentsPreferences(web_contents, options);
 
   web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
 
index a0088221ba2c826ff5f8c993e85751c1447489a1..2adb77211b27cf4fb30a961993de88f24d1c8e21 100644 (file)
@@ -6,10 +6,12 @@
 
 #include <string>
 
+#include "atom/common/native_mate_converters/value_converter.h"
 #include "atom/common/options_switches.h"
 #include "base/command_line.h"
 #include "base/strings/string_number_conversions.h"
 #include "content/public/common/web_preferences.h"
+#include "native_mate/dictionary.h"
 #include "net/base/filename_util.h"
 
 #if defined(OS_WIN)
@@ -36,12 +38,16 @@ const char* kWebRuntimeFeatures[] = {
 
 WebContentsPreferences::WebContentsPreferences(
     content::WebContents* web_contents,
-    base::DictionaryValue* web_preferences) {
-  web_preferences_.Swap(web_preferences);
+    const mate::Dictionary& web_preferences) {
+  v8::Isolate* isolate = web_preferences.isolate();
+  mate::Dictionary copied(isolate, web_preferences.GetHandle()->Clone());
+  // Following fields should not be stored.
+  copied.Delete("embedder");
+  copied.Delete("isGuest");
+  copied.Delete("session");
+
+  mate::ConvertFromV8(isolate, copied.GetHandle(), &web_preferences_);
   web_contents->SetUserData(UserDataKey(), this);
-
-  // The "isGuest" is not a preferences field.
-  web_preferences_.Remove("isGuest", nullptr);
 }
 
 WebContentsPreferences::~WebContentsPreferences() {
index 3e36df02147829ed548ba79faddd3295b59ae295..8b04f9ee24e617e3060e02473977a5b64b771009 100644 (file)
@@ -16,6 +16,10 @@ namespace content {
 struct WebPreferences;
 }
 
+namespace mate {
+class Dictionary;
+}
+
 namespace atom {
 
 // Stores and applies the preferences of WebContents.
@@ -31,7 +35,7 @@ class WebContentsPreferences
       content::WebContents* web_contents, content::WebPreferences* prefs);
 
   WebContentsPreferences(content::WebContents* web_contents,
-                         base::DictionaryValue* web_preferences);
+                         const mate::Dictionary& web_preferences);
   ~WebContentsPreferences() override;
 
   // $.extend(|web_preferences_|, |new_web_preferences|).