diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 7cefe8e45e3d..d724d1ea4c1c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -11,6 +11,7 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/native_window.h" +#include "atom/browser/web_contents_preferences.h" #include "atom/browser/web_view_guest_delegate.h" #include "atom/common/api/api_messages.h" #include "atom/common/api/event_emitter_caller.h" @@ -153,7 +154,8 @@ WebContents::WebContents(content::WebContents* web_contents) web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent()); } -WebContents::WebContents(const mate::Dictionary& options) { +WebContents::WebContents(v8::Isolate* isolate, + const mate::Dictionary& options) { bool is_guest = false; options.Get("isGuest", &is_guest); @@ -185,6 +187,11 @@ WebContents::WebContents(const mate::Dictionary& options) { AttachAsUserData(web_contents); InitWithWebContents(web_contents); + // Save the preferences. + base::DictionaryValue web_preferences; + mate::ConvertFromV8(isolate, options.GetHandle(), &web_preferences); + new WebContentsPreferences(web_contents, std::move(web_preferences)); + web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent()); if (is_guest) { @@ -890,7 +897,7 @@ mate::Handle WebContents::CreateFrom( // static mate::Handle WebContents::Create( v8::Isolate* isolate, const mate::Dictionary& options) { - auto handle = mate::CreateHandle(isolate, new WebContents(options)); + auto handle = mate::CreateHandle(isolate, new WebContents(isolate, options)); g_wrap_web_contents.Run(handle.ToV8()); return handle; } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index e75e88fd703e..5ea62dabff62 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -116,7 +116,7 @@ class WebContents : public mate::TrackableObject, protected: explicit WebContents(content::WebContents* web_contents); - explicit WebContents(const mate::Dictionary& options); + WebContents(v8::Isolate* isolate, const mate::Dictionary& options); ~WebContents(); // mate::Wrappable: diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc new file mode 100644 index 000000000000..8b956c1b41ac --- /dev/null +++ b/atom/browser/web_contents_preferences.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/web_contents_preferences.h" + +namespace atom { + +namespace { + +const char* kWebPreferencesKey = "WebContentsPreferences"; + +} // namespace + +WebContentsPreferences::WebContentsPreferences( + content::WebContents* web_contents, + base::DictionaryValue&& web_preferences) { + web_preferences_.Swap(&web_preferences); + web_contents->SetUserData(kWebPreferencesKey, this); +} + +WebContentsPreferences::~WebContentsPreferences() { +} + +} // namespace atom diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h new file mode 100644 index 000000000000..bbbc4cf5e2e6 --- /dev/null +++ b/atom/browser/web_contents_preferences.h @@ -0,0 +1,30 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_ +#define ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_ + +#include "base/values.h" +#include "content/public/browser/web_contents_user_data.h" + +namespace atom { + +class WebContentsPreferences + : public content::WebContentsUserData { + public: + WebContentsPreferences(content::WebContents* web_contents, + base::DictionaryValue&& web_preferences); + ~WebContentsPreferences() override; + + private: + friend class content::WebContentsUserData; + + base::DictionaryValue web_preferences_; + + DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences); +}; + +} // namespace atom + +#endif // ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_ diff --git a/filenames.gypi b/filenames.gypi index 2f97d01507e8..b4d3bcb5e186 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -226,14 +226,16 @@ 'atom/browser/ui/x/window_state_watcher.h', 'atom/browser/ui/x/x_window_utils.cc', 'atom/browser/ui/x/x_window_utils.h', + 'atom/browser/web_contents_preferences.cc', + 'atom/browser/web_contents_preferences.h', + 'atom/browser/web_dialog_helper.cc', + 'atom/browser/web_dialog_helper.h', 'atom/browser/web_view_constants.cc', 'atom/browser/web_view_constants.h', 'atom/browser/web_view_guest_delegate.cc', 'atom/browser/web_view_guest_delegate.h', 'atom/browser/web_view_manager.cc', 'atom/browser/web_view_manager.h', - 'atom/browser/web_dialog_helper.cc', - 'atom/browser/web_dialog_helper.h', 'atom/browser/window_list.cc', 'atom/browser/window_list.h', 'atom/browser/window_list_observer.h',