From 24bbe5dabf36b3a7a3937821d91db6caa9ebad60 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 7 Sep 2015 15:55:08 +0800 Subject: [PATCH] No need to define WebContentsPreferences::From --- atom/browser/api/atom_api_web_view_manager.cc | 4 +++- atom/browser/web_contents_preferences.cc | 18 +++++------------- atom/browser/web_contents_preferences.h | 3 --- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/atom/browser/api/atom_api_web_view_manager.cc b/atom/browser/api/atom_api_web_view_manager.cc index 83287ac..e57c5ff 100644 --- a/atom/browser/api/atom_api_web_view_manager.cc +++ b/atom/browser/api/atom_api_web_view_manager.cc @@ -10,6 +10,8 @@ #include "content/public/browser/browser_context.h" #include "native_mate/dictionary.h" +using atom::WebContentsPreferences; + namespace mate { template<> @@ -48,7 +50,7 @@ void AddGuest(int guest_instance_id, manager->AddGuest(guest_instance_id, element_instance_id, embedder, guest_web_contents); - atom::WebContentsPreferences::From(guest_web_contents)->Merge(options); + WebContentsPreferences::FromWebContents(guest_web_contents)->Merge(options); } void RemoveGuest(content::WebContents* embedder, int guest_instance_id) { diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 19ea826..db55edd 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -16,13 +16,12 @@ #include "ui/gfx/switches.h" #endif +DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::WebContentsPreferences); + namespace atom { namespace { -// Pointer as WebContents's user data key. -const char* kWebPreferencesKey = "WebContentsPreferences"; - // Array of available web runtime features. const char* kWebRuntimeFeatures[] = { switches::kExperimentalFeatures, @@ -40,7 +39,7 @@ WebContentsPreferences::WebContentsPreferences( content::WebContents* web_contents, base::DictionaryValue* web_preferences) { web_preferences_.Swap(web_preferences); - web_contents->SetUserData(kWebPreferencesKey, this); + web_contents->SetUserData(UserDataKey(), this); } WebContentsPreferences::~WebContentsPreferences() { @@ -51,16 +50,9 @@ void WebContentsPreferences::Merge(const base::DictionaryValue& extend) { } // static -WebContentsPreferences* WebContentsPreferences::From( - content::WebContents* web_contents) { - return static_cast( - web_contents->GetUserData(kWebPreferencesKey)); -} - -// static void WebContentsPreferences::AppendExtraCommandLineSwitches( content::WebContents* web_contents, base::CommandLine* command_line) { - WebContentsPreferences* self = From(web_contents); + WebContentsPreferences* self = FromWebContents(web_contents); if (!self) return; @@ -130,7 +122,7 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( // static void WebContentsPreferences::OverrideWebkitPrefs( content::WebContents* web_contents, content::WebPreferences* prefs) { - WebContentsPreferences* self = From(web_contents); + WebContentsPreferences* self = FromWebContents(web_contents); if (!self) return; diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 3104567..83b485f 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -22,9 +22,6 @@ namespace atom { class WebContentsPreferences : public content::WebContentsUserData { public: - // Get the preferences of |web_contents|. - static WebContentsPreferences* From(content::WebContents* web_contents); - // Append command paramters according to |web_contents|'s preferences. static void AppendExtraCommandLineSwitches( content::WebContents* web_contents, base::CommandLine* command_line); -- 2.7.4