No need to define WebContentsPreferences::From

This commit is contained in:
Cheng Zhao 2015-09-07 15:55:08 +08:00
parent 3717f5b7f2
commit 24bbe5dabf
3 changed files with 8 additions and 17 deletions

View file

@ -10,6 +10,8 @@
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
using atom::WebContentsPreferences;
namespace mate { namespace mate {
template<> template<>
@ -48,7 +50,7 @@ void AddGuest(int guest_instance_id,
manager->AddGuest(guest_instance_id, element_instance_id, embedder, manager->AddGuest(guest_instance_id, element_instance_id, embedder,
guest_web_contents); 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) { void RemoveGuest(content::WebContents* embedder, int guest_instance_id) {

View file

@ -16,13 +16,12 @@
#include "ui/gfx/switches.h" #include "ui/gfx/switches.h"
#endif #endif
DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::WebContentsPreferences);
namespace atom { namespace atom {
namespace { namespace {
// Pointer as WebContents's user data key.
const char* kWebPreferencesKey = "WebContentsPreferences";
// Array of available web runtime features. // Array of available web runtime features.
const char* kWebRuntimeFeatures[] = { const char* kWebRuntimeFeatures[] = {
switches::kExperimentalFeatures, switches::kExperimentalFeatures,
@ -40,7 +39,7 @@ WebContentsPreferences::WebContentsPreferences(
content::WebContents* web_contents, content::WebContents* web_contents,
base::DictionaryValue* web_preferences) { base::DictionaryValue* web_preferences) {
web_preferences_.Swap(web_preferences); web_preferences_.Swap(web_preferences);
web_contents->SetUserData(kWebPreferencesKey, this); web_contents->SetUserData(UserDataKey(), this);
} }
WebContentsPreferences::~WebContentsPreferences() { WebContentsPreferences::~WebContentsPreferences() {
@ -50,17 +49,10 @@ void WebContentsPreferences::Merge(const base::DictionaryValue& extend) {
web_preferences_.MergeDictionary(&extend); web_preferences_.MergeDictionary(&extend);
} }
// static
WebContentsPreferences* WebContentsPreferences::From(
content::WebContents* web_contents) {
return static_cast<WebContentsPreferences*>(
web_contents->GetUserData(kWebPreferencesKey));
}
// static // static
void WebContentsPreferences::AppendExtraCommandLineSwitches( void WebContentsPreferences::AppendExtraCommandLineSwitches(
content::WebContents* web_contents, base::CommandLine* command_line) { content::WebContents* web_contents, base::CommandLine* command_line) {
WebContentsPreferences* self = From(web_contents); WebContentsPreferences* self = FromWebContents(web_contents);
if (!self) if (!self)
return; return;
@ -130,7 +122,7 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
// static // static
void WebContentsPreferences::OverrideWebkitPrefs( void WebContentsPreferences::OverrideWebkitPrefs(
content::WebContents* web_contents, content::WebPreferences* prefs) { content::WebContents* web_contents, content::WebPreferences* prefs) {
WebContentsPreferences* self = From(web_contents); WebContentsPreferences* self = FromWebContents(web_contents);
if (!self) if (!self)
return; return;

View file

@ -22,9 +22,6 @@ namespace atom {
class WebContentsPreferences class WebContentsPreferences
: public content::WebContentsUserData<WebContentsPreferences> { : public content::WebContentsUserData<WebContentsPreferences> {
public: public:
// Get the preferences of |web_contents|.
static WebContentsPreferences* From(content::WebContents* web_contents);
// Append command paramters according to |web_contents|'s preferences. // Append command paramters according to |web_contents|'s preferences.
static void AppendExtraCommandLineSwitches( static void AppendExtraCommandLineSwitches(
content::WebContents* web_contents, base::CommandLine* command_line); content::WebContents* web_contents, base::CommandLine* command_line);