Avoid storing unrelated things in WebContentsPreferences

This commit is contained in:
Cheng Zhao 2015-11-11 10:32:25 +08:00
parent b807685453
commit ba457681b2
3 changed files with 17 additions and 9 deletions

View file

@ -269,9 +269,7 @@ WebContents::WebContents(v8::Isolate* isolate,
managed_web_contents()->GetView()->SetDelegate(this); managed_web_contents()->GetView()->SetDelegate(this);
// Save the preferences in C++. // Save the preferences in C++.
base::DictionaryValue web_preferences; new WebContentsPreferences(web_contents, options);
mate::ConvertFromV8(isolate, options.GetHandle(), &web_preferences);
new WebContentsPreferences(web_contents, &web_preferences);
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent()); web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());

View file

@ -6,10 +6,12 @@
#include <string> #include <string>
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/options_switches.h" #include "atom/common/options_switches.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "content/public/common/web_preferences.h" #include "content/public/common/web_preferences.h"
#include "native_mate/dictionary.h"
#include "net/base/filename_util.h" #include "net/base/filename_util.h"
#if defined(OS_WIN) #if defined(OS_WIN)
@ -36,12 +38,16 @@ const char* kWebRuntimeFeatures[] = {
WebContentsPreferences::WebContentsPreferences( WebContentsPreferences::WebContentsPreferences(
content::WebContents* web_contents, content::WebContents* web_contents,
base::DictionaryValue* web_preferences) { const mate::Dictionary& web_preferences) {
web_preferences_.Swap(web_preferences); v8::Isolate* isolate = web_preferences.isolate();
web_contents->SetUserData(UserDataKey(), this); mate::Dictionary copied(isolate, web_preferences.GetHandle()->Clone());
// Following fields should not be stored.
copied.Delete("embedder");
copied.Delete("isGuest");
copied.Delete("session");
// The "isGuest" is not a preferences field. mate::ConvertFromV8(isolate, copied.GetHandle(), &web_preferences_);
web_preferences_.Remove("isGuest", nullptr); web_contents->SetUserData(UserDataKey(), this);
} }
WebContentsPreferences::~WebContentsPreferences() { WebContentsPreferences::~WebContentsPreferences() {

View file

@ -16,6 +16,10 @@ namespace content {
struct WebPreferences; struct WebPreferences;
} }
namespace mate {
class Dictionary;
}
namespace atom { namespace atom {
// Stores and applies the preferences of WebContents. // Stores and applies the preferences of WebContents.
@ -31,7 +35,7 @@ class WebContentsPreferences
content::WebContents* web_contents, content::WebPreferences* prefs); content::WebContents* web_contents, content::WebPreferences* prefs);
WebContentsPreferences(content::WebContents* web_contents, WebContentsPreferences(content::WebContents* web_contents,
base::DictionaryValue* web_preferences); const mate::Dictionary& web_preferences);
~WebContentsPreferences() override; ~WebContentsPreferences() override;
// $.extend(|web_preferences_|, |new_web_preferences|). // $.extend(|web_preferences_|, |new_web_preferences|).