Remove unnecessary methods on WebContentsPreferences
This commit is contained in:
parent
2b623f5d86
commit
affa21600c
5 changed files with 36 additions and 82 deletions
|
@ -167,11 +167,14 @@ void AtomBrowserClient::RenderProcessWillLaunch(
|
|||
|
||||
content::WebContents* web_contents = GetWebContentsFromProcessID(process_id);
|
||||
ProcessPreferences process_prefs;
|
||||
process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents);
|
||||
process_prefs.native_window_open
|
||||
= WebContentsPreferences::UsesNativeWindowOpen(web_contents);
|
||||
process_prefs.disable_popups
|
||||
= WebContentsPreferences::DisablePopups(web_contents);
|
||||
process_prefs.sandbox =
|
||||
WebContentsPreferences::IsPreferenceEnabled("sandbox", web_contents);
|
||||
process_prefs.native_window_open =
|
||||
WebContentsPreferences::IsPreferenceEnabled("nativeWindowOpen",
|
||||
web_contents);
|
||||
process_prefs.disable_popups =
|
||||
WebContentsPreferences::IsPreferenceEnabled("disablePopups",
|
||||
web_contents);
|
||||
AddProcessPreferences(host->GetID(), process_prefs);
|
||||
// ensure the ProcessPreferences is removed later
|
||||
host->AddObserver(this);
|
||||
|
@ -204,7 +207,7 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
|||
}
|
||||
|
||||
void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
||||
content::RenderFrameHost* render_frame_host,
|
||||
content::RenderFrameHost* rfh,
|
||||
content::BrowserContext* browser_context,
|
||||
content::SiteInstance* current_instance,
|
||||
const GURL& url,
|
||||
|
@ -214,8 +217,7 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
|||
return;
|
||||
}
|
||||
|
||||
if (!ShouldCreateNewSiteInstance(render_frame_host, browser_context,
|
||||
current_instance, url))
|
||||
if (!ShouldCreateNewSiteInstance(rfh, browser_context, current_instance, url))
|
||||
return;
|
||||
|
||||
bool is_new_instance = true;
|
||||
|
@ -223,10 +225,12 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
|||
|
||||
// Do we have an affinity site to manage ?
|
||||
std::string affinity;
|
||||
auto web_contents =
|
||||
content::WebContents::FromRenderFrameHost(render_frame_host);
|
||||
if (WebContentsPreferences::GetAffinity(web_contents, &affinity)
|
||||
&& !affinity.empty()) {
|
||||
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
||||
auto* web_preferences = web_contents ?
|
||||
WebContentsPreferences::FromWebContents(web_contents) : nullptr;
|
||||
if (web_preferences &&
|
||||
web_preferences->web_preferences()->GetString("affinity", &affinity) &&
|
||||
!affinity.empty()) {
|
||||
affinity = base::ToLowerASCII(affinity);
|
||||
auto iter = site_per_affinities.find(affinity);
|
||||
if (iter != site_per_affinities.end()) {
|
||||
|
@ -262,19 +266,6 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
|||
}
|
||||
}
|
||||
|
||||
// We are storing weak_ptr, is it fundamental to maintain the map up-to-date
|
||||
// when an instance is destroyed.
|
||||
void AtomBrowserClient::SiteInstanceDeleting(
|
||||
content::SiteInstance* site_instance) {
|
||||
for (auto iter = site_per_affinities.begin();
|
||||
iter != site_per_affinities.end(); ++iter) {
|
||||
if (iter->second == site_instance) {
|
||||
site_per_affinities.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||
base::CommandLine* command_line,
|
||||
int process_id) {
|
||||
|
@ -436,6 +427,19 @@ void AtomBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
|
|||
additional_schemes->push_back(content::kChromeDevToolsScheme);
|
||||
}
|
||||
|
||||
void AtomBrowserClient::SiteInstanceDeleting(
|
||||
content::SiteInstance* site_instance) {
|
||||
// We are storing weak_ptr, is it fundamental to maintain the map up-to-date
|
||||
// when an instance is destroyed.
|
||||
for (auto iter = site_per_affinities.begin();
|
||||
iter != site_per_affinities.end(); ++iter) {
|
||||
if (iter->second == site_instance) {
|
||||
site_per_affinities.erase(iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
||||
const content::MainFunctionParams&) {
|
||||
v8::V8::Initialize(); // Init V8 before creating main parts.
|
||||
|
|
|
@ -98,6 +98,7 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
|||
bool* no_javascript_access) override;
|
||||
void GetAdditionalAllowedSchemesForFileSystem(
|
||||
std::vector<std::string>* schemes) override;
|
||||
void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
|
||||
|
||||
// brightray::BrowserClient:
|
||||
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||
|
@ -113,17 +114,15 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
|||
base::TerminationStatus status,
|
||||
int exit_code) override;
|
||||
|
||||
void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
|
||||
|
||||
private:
|
||||
bool ShouldCreateNewSiteInstance(content::RenderFrameHost* render_frame_host,
|
||||
content::BrowserContext* browser_context,
|
||||
content::SiteInstance* current_instance,
|
||||
const GURL& dest_url);
|
||||
struct ProcessPreferences {
|
||||
bool sandbox;
|
||||
bool native_window_open;
|
||||
bool disable_popups;
|
||||
bool sandbox = false;
|
||||
bool native_window_open = false;
|
||||
bool disable_popups = false;
|
||||
};
|
||||
void AddProcessPreferences(int process_id, ProcessPreferences prefs);
|
||||
void RemoveProcessPreferences(int process_id);
|
||||
|
|
|
@ -75,7 +75,7 @@ void OnPdfResourceIntercepted(
|
|||
if (!web_contents)
|
||||
return;
|
||||
|
||||
if (!WebContentsPreferences::IsPluginsEnabled(web_contents)) {
|
||||
if (!WebContentsPreferences::IsPreferenceEnabled("plugins", web_contents)) {
|
||||
auto browser_context = web_contents->GetBrowserContext();
|
||||
auto download_manager =
|
||||
content::BrowserContext::GetDownloadManager(browser_context);
|
||||
|
|
|
@ -112,7 +112,8 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
|||
// If the `sandbox` option was passed to the BrowserWindow's webPreferences,
|
||||
// pass `--enable-sandbox` to the renderer so it won't have any node.js
|
||||
// integration.
|
||||
if (IsSandboxed(web_contents)) {
|
||||
bool sandbox = false;
|
||||
if (web_preferences.GetBoolean("sandbox", &sandbox) && sandbox) {
|
||||
command_line->AppendSwitch(switches::kEnableSandbox);
|
||||
} else if (!command_line->HasSwitch(switches::kEnableSandbox)) {
|
||||
command_line->AppendSwitch(::switches::kNoSandbox);
|
||||
|
@ -237,47 +238,6 @@ bool WebContentsPreferences::IsPreferenceEnabled(
|
|||
return bool_value;
|
||||
}
|
||||
|
||||
bool WebContentsPreferences::GetPreferenceString(
|
||||
const std::string& attribute_name,
|
||||
content::WebContents* web_contents,
|
||||
std::string* strValue) {
|
||||
WebContentsPreferences* self;
|
||||
if (!web_contents)
|
||||
return false;
|
||||
|
||||
self = FromWebContents(web_contents);
|
||||
if (!self)
|
||||
return false;
|
||||
|
||||
base::DictionaryValue& web_preferences = self->web_preferences_;
|
||||
return web_preferences.GetString(attribute_name, strValue);
|
||||
}
|
||||
|
||||
bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) {
|
||||
return IsPreferenceEnabled("sandbox", web_contents);
|
||||
}
|
||||
|
||||
bool WebContentsPreferences::UsesNativeWindowOpen(
|
||||
content::WebContents* web_contents) {
|
||||
return IsPreferenceEnabled("nativeWindowOpen", web_contents);
|
||||
}
|
||||
|
||||
bool WebContentsPreferences::IsPluginsEnabled(
|
||||
content::WebContents* web_contents) {
|
||||
return IsPreferenceEnabled("plugins", web_contents);
|
||||
}
|
||||
|
||||
bool WebContentsPreferences::DisablePopups(
|
||||
content::WebContents* web_contents) {
|
||||
return IsPreferenceEnabled("disablePopups", web_contents);
|
||||
}
|
||||
|
||||
bool WebContentsPreferences::GetAffinity(
|
||||
content::WebContents* web_contents,
|
||||
std::string* string_value) {
|
||||
return GetPreferenceString("affinity", web_contents, string_value);
|
||||
}
|
||||
|
||||
// static
|
||||
void WebContentsPreferences::OverrideWebkitPrefs(
|
||||
content::WebContents* web_contents, content::WebPreferences* prefs) {
|
||||
|
|
|
@ -39,15 +39,6 @@ class WebContentsPreferences
|
|||
|
||||
static bool IsPreferenceEnabled(const std::string& attribute_name,
|
||||
content::WebContents* web_contents);
|
||||
static bool GetPreferenceString(const std::string& attribute_name,
|
||||
content::WebContents* web_contents,
|
||||
std::string* strValue);
|
||||
static bool IsSandboxed(content::WebContents* web_contents);
|
||||
static bool UsesNativeWindowOpen(content::WebContents* web_contents);
|
||||
static bool DisablePopups(content::WebContents* web_contents);
|
||||
static bool IsPluginsEnabled(content::WebContents* web_contents);
|
||||
static bool GetAffinity(content::WebContents* web_contents,
|
||||
std::string* string_value);
|
||||
|
||||
// Modify the WebPreferences according to |web_contents|'s preferences.
|
||||
static void OverrideWebkitPrefs(
|
||||
|
|
Loading…
Reference in a new issue