]> khamidou — GitHub mirrors - electron.git/commitdiff
No need to define WebContentsPreferences::From
authorCheng Zhao <zcbenz@gmail.com>
Mon, 7 Sep 2015 07:55:08 +0000 (15:55 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 7 Sep 2015 08:16:34 +0000 (16:16 +0800)
atom/browser/api/atom_api_web_view_manager.cc
atom/browser/web_contents_preferences.cc
atom/browser/web_contents_preferences.h

index 83287ac8b2f12b467bf8e4dff2cb36ebf3285821..e57c5ffb6bb4aea16b72f29e53ec48a269d2d08e 100644 (file)
@@ -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) {
index 19ea826a5ff7f371e57033ea3ebc731778006f80..db55eddf7e2d43e007c00a29177a5f45ebd962e4 100644 (file)
 #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() {
@@ -50,17 +49,10 @@ void WebContentsPreferences::Merge(const base::DictionaryValue& extend) {
   web_preferences_.MergeDictionary(&extend);
 }
 
-// static
-WebContentsPreferences* WebContentsPreferences::From(
-    content::WebContents* web_contents) {
-  return static_cast<WebContentsPreferences*>(
-      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;
 
index 310456725aafed7e28c48d355c46981ad588522e..83b485f449bc7b3d8682724cf65c24ef4296ba80 100644 (file)
@@ -22,9 +22,6 @@ namespace atom {
 class WebContentsPreferences
     : public content::WebContentsUserData<WebContentsPreferences> {
  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);