Add WebContentsPrefrences class
This commit is contained in:
Родитель
81d423c547
Коммит
dd871812b7
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
|
@ -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_
|
|
@ -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',
|
||||
|
|
Загрузка…
Ссылка в новой задаче