diff --git a/atom/browser/api/atom_api_browser_window.cc b/atom/browser/api/atom_api_browser_window.cc index 3607077b69c2..33695d5ef293 100644 --- a/atom/browser/api/atom_api_browser_window.cc +++ b/atom/browser/api/atom_api_browser_window.cc @@ -115,7 +115,7 @@ BrowserWindow::BrowserWindow(v8::Isolate* isolate, // These preferences will be used when the webContent launches new // render processes. auto* existing_preferences = - WebContentsPreferences::FromWebContents(web_contents->web_contents()); + WebContentsPreferences::From(web_contents->web_contents()); base::DictionaryValue web_preferences_dict; if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(), &web_preferences_dict)) { diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index a3db5dbd19e0..d702a8e5a131 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1122,8 +1122,7 @@ void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { // created after loading a page. const auto view = web_contents()->GetRenderWidgetHostView(); if (view) { - WebContentsPreferences* web_preferences = - WebContentsPreferences::FromWebContents(web_contents()); + auto* web_preferences = WebContentsPreferences::From(web_contents()); std::string color_name; if (web_preferences->dict()->GetString(options::kBackgroundColor, &color_name)) { @@ -1840,8 +1839,7 @@ void WebContents::OnGetZoomLevel(content::RenderFrameHost* rfh, } v8::Local WebContents::GetWebPreferences(v8::Isolate* isolate) { - WebContentsPreferences* web_preferences = - WebContentsPreferences::FromWebContents(web_contents()); + auto* web_preferences = WebContentsPreferences::From(web_contents()); if (!web_preferences) return v8::Null(isolate); return mate::ConvertToV8(isolate, *web_preferences->dict()); diff --git a/atom/browser/api/atom_api_web_view_manager.cc b/atom/browser/api/atom_api_web_view_manager.cc index 2a0cbd8a3ebf..347bcc2336bc 100644 --- a/atom/browser/api/atom_api_web_view_manager.cc +++ b/atom/browser/api/atom_api_web_view_manager.cc @@ -34,7 +34,7 @@ void AddGuest(int guest_instance_id, ->SetDefaultZoomFactor(zoom_factor); } - WebContentsPreferences::FromWebContents(guest_web_contents)->Merge(options); + WebContentsPreferences::From(guest_web_contents)->Merge(options); } void RemoveGuest(content::WebContents* embedder, int guest_instance_id) { diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index d7c6857c7f7f..f96f3ce6d31f 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -235,8 +235,7 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation( // Do we have an affinity site to manage ? std::string affinity; auto* web_contents = content::WebContents::FromRenderFrameHost(rfh); - auto* web_preferences = web_contents ? - WebContentsPreferences::FromWebContents(web_contents) : nullptr; + auto* web_preferences = WebContentsPreferences::From(web_contents); if (web_preferences && web_preferences->dict()->GetString("affinity", &affinity) && !affinity.empty()) { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 5bb9fe65ed2f..c824d0a76d1c 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -1370,14 +1370,12 @@ void NativeWindowViews::ShowAutofillPopup( bool is_offsceen = false; bool is_embedder_offscreen = false; - auto* web_contents_preferences = - WebContentsPreferences::FromWebContents(web_contents); - if (web_contents_preferences) { - const auto* web_preferences = web_contents_preferences->dict(); - - web_preferences->GetBoolean("offscreen", &is_offsceen); + auto* web_preferences = WebContentsPreferences::From(web_contents); + if (web_preferences) { + web_preferences->dict()->GetBoolean("offscreen", &is_offsceen); int guest_instance_id = 0; - web_preferences->GetInteger(options::kGuestInstanceID, &guest_instance_id); + web_preferences->dict()->GetInteger(options::kGuestInstanceID, + &guest_instance_id); if (guest_instance_id) { auto manager = WebViewManager::GetWebViewManager(web_contents); diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 8b0b6bc9a641..e45a6167c99b 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -105,6 +105,14 @@ content::WebContents* WebContentsPreferences::GetWebContentsFromProcessID( return nullptr; } +// static +WebContentsPreferences* WebContentsPreferences::From( + content::WebContents* web_contents) { + if (!web_contents) + return nullptr; + return FromWebContents(web_contents); +} + // static void WebContentsPreferences::AppendExtraCommandLineSwitches( content::WebContents* web_contents, base::CommandLine* command_line) { diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 7493523e0272..50165bbc43e3 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -33,6 +33,9 @@ class WebContentsPreferences // FIXME(zcbenz): This method does not belong here. static content::WebContents* GetWebContentsFromProcessID(int process_id); + // Get self from WebContents. + 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);