]> khamidou — GitHub mirrors - electron.git/commitdiff
Add WebContentsPrefrences class
authorCheng Zhao <zcbenz@gmail.com>
Fri, 4 Sep 2015 16:44:22 +0000 (01:44 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 6 Sep 2015 02:53:03 +0000 (10:53 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/web_contents_preferences.cc [new file with mode: 0644]
atom/browser/web_contents_preferences.h [new file with mode: 0644]
filenames.gypi

index 7cefe8e45e3d35406ae8178611b7459730d5b23a..d724d1ea4c1ca1e5229d845885864a89226d14de 100644 (file)
@@ -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> WebContents::CreateFrom(
 // static
 mate::Handle<WebContents> 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;
 }
index e75e88fd703e878a71c76ba81d2b18dda3d3bec4..5ea62dabff620455c8779f9a641db4f178286b03 100644 (file)
@@ -116,7 +116,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
 
  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 (file)
index 0000000..8b956c1
--- /dev/null
@@ -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 (file)
index 0000000..bbbc4cf
--- /dev/null
@@ -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<WebContentsPreferences> {
+ public:
+  WebContentsPreferences(content::WebContents* web_contents,
+                         base::DictionaryValue&& web_preferences);
+  ~WebContentsPreferences() override;
+
+ private:
+  friend class content::WebContentsUserData<WebContentsPreferences>;
+
+  base::DictionaryValue web_preferences_;
+
+  DISALLOW_COPY_AND_ASSIGN(WebContentsPreferences);
+};
+
+}  // namespace atom
+
+#endif  // ATOM_BROWSER_WEB_CONTENTS_PREFERENCES_H_
index 2f97d01507e8ca431866ee26348ac576a4c59364..b4d3bcb5e1866275c1187942039c122fd3bd9980 100644 (file)
       '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',