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);
|
content::WebContents* web_contents = GetWebContentsFromProcessID(process_id);
|
||||||
ProcessPreferences process_prefs;
|
ProcessPreferences process_prefs;
|
||||||
process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents);
|
process_prefs.sandbox =
|
||||||
process_prefs.native_window_open
|
WebContentsPreferences::IsPreferenceEnabled("sandbox", web_contents);
|
||||||
= WebContentsPreferences::UsesNativeWindowOpen(web_contents);
|
process_prefs.native_window_open =
|
||||||
process_prefs.disable_popups
|
WebContentsPreferences::IsPreferenceEnabled("nativeWindowOpen",
|
||||||
= WebContentsPreferences::DisablePopups(web_contents);
|
web_contents);
|
||||||
|
process_prefs.disable_popups =
|
||||||
|
WebContentsPreferences::IsPreferenceEnabled("disablePopups",
|
||||||
|
web_contents);
|
||||||
AddProcessPreferences(host->GetID(), process_prefs);
|
AddProcessPreferences(host->GetID(), process_prefs);
|
||||||
// ensure the ProcessPreferences is removed later
|
// ensure the ProcessPreferences is removed later
|
||||||
host->AddObserver(this);
|
host->AddObserver(this);
|
||||||
|
@ -204,7 +207,7 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* rfh,
|
||||||
content::BrowserContext* browser_context,
|
content::BrowserContext* browser_context,
|
||||||
content::SiteInstance* current_instance,
|
content::SiteInstance* current_instance,
|
||||||
const GURL& url,
|
const GURL& url,
|
||||||
|
@ -214,8 +217,7 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ShouldCreateNewSiteInstance(render_frame_host, browser_context,
|
if (!ShouldCreateNewSiteInstance(rfh, browser_context, current_instance, url))
|
||||||
current_instance, url))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool is_new_instance = true;
|
bool is_new_instance = true;
|
||||||
|
@ -223,10 +225,12 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation(
|
||||||
|
|
||||||
// Do we have an affinity site to manage ?
|
// Do we have an affinity site to manage ?
|
||||||
std::string affinity;
|
std::string affinity;
|
||||||
auto web_contents =
|
auto* web_contents = content::WebContents::FromRenderFrameHost(rfh);
|
||||||
content::WebContents::FromRenderFrameHost(render_frame_host);
|
auto* web_preferences = web_contents ?
|
||||||
if (WebContentsPreferences::GetAffinity(web_contents, &affinity)
|
WebContentsPreferences::FromWebContents(web_contents) : nullptr;
|
||||||
&& !affinity.empty()) {
|
if (web_preferences &&
|
||||||
|
web_preferences->web_preferences()->GetString("affinity", &affinity) &&
|
||||||
|
!affinity.empty()) {
|
||||||
affinity = base::ToLowerASCII(affinity);
|
affinity = base::ToLowerASCII(affinity);
|
||||||
auto iter = site_per_affinities.find(affinity);
|
auto iter = site_per_affinities.find(affinity);
|
||||||
if (iter != site_per_affinities.end()) {
|
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(
|
void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
base::CommandLine* command_line,
|
base::CommandLine* command_line,
|
||||||
int process_id) {
|
int process_id) {
|
||||||
|
@ -436,6 +427,19 @@ void AtomBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
|
||||||
additional_schemes->push_back(content::kChromeDevToolsScheme);
|
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(
|
brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
|
||||||
const content::MainFunctionParams&) {
|
const content::MainFunctionParams&) {
|
||||||
v8::V8::Initialize(); // Init V8 before creating main parts.
|
v8::V8::Initialize(); // Init V8 before creating main parts.
|
||||||
|
|
|
@ -98,6 +98,7 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
||||||
bool* no_javascript_access) override;
|
bool* no_javascript_access) override;
|
||||||
void GetAdditionalAllowedSchemesForFileSystem(
|
void GetAdditionalAllowedSchemesForFileSystem(
|
||||||
std::vector<std::string>* schemes) override;
|
std::vector<std::string>* schemes) override;
|
||||||
|
void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
|
||||||
|
|
||||||
// brightray::BrowserClient:
|
// brightray::BrowserClient:
|
||||||
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
brightray::BrowserMainParts* OverrideCreateBrowserMainParts(
|
||||||
|
@ -113,17 +114,15 @@ class AtomBrowserClient : public brightray::BrowserClient,
|
||||||
base::TerminationStatus status,
|
base::TerminationStatus status,
|
||||||
int exit_code) override;
|
int exit_code) override;
|
||||||
|
|
||||||
void SiteInstanceDeleting(content::SiteInstance* site_instance) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ShouldCreateNewSiteInstance(content::RenderFrameHost* render_frame_host,
|
bool ShouldCreateNewSiteInstance(content::RenderFrameHost* render_frame_host,
|
||||||
content::BrowserContext* browser_context,
|
content::BrowserContext* browser_context,
|
||||||
content::SiteInstance* current_instance,
|
content::SiteInstance* current_instance,
|
||||||
const GURL& dest_url);
|
const GURL& dest_url);
|
||||||
struct ProcessPreferences {
|
struct ProcessPreferences {
|
||||||
bool sandbox;
|
bool sandbox = false;
|
||||||
bool native_window_open;
|
bool native_window_open = false;
|
||||||
bool disable_popups;
|
bool disable_popups = false;
|
||||||
};
|
};
|
||||||
void AddProcessPreferences(int process_id, ProcessPreferences prefs);
|
void AddProcessPreferences(int process_id, ProcessPreferences prefs);
|
||||||
void RemoveProcessPreferences(int process_id);
|
void RemoveProcessPreferences(int process_id);
|
||||||
|
|
|
@ -75,7 +75,7 @@ void OnPdfResourceIntercepted(
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!WebContentsPreferences::IsPluginsEnabled(web_contents)) {
|
if (!WebContentsPreferences::IsPreferenceEnabled("plugins", web_contents)) {
|
||||||
auto browser_context = web_contents->GetBrowserContext();
|
auto browser_context = web_contents->GetBrowserContext();
|
||||||
auto download_manager =
|
auto download_manager =
|
||||||
content::BrowserContext::GetDownloadManager(browser_context);
|
content::BrowserContext::GetDownloadManager(browser_context);
|
||||||
|
|
|
@ -112,7 +112,8 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
||||||
// If the `sandbox` option was passed to the BrowserWindow's webPreferences,
|
// 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
|
// pass `--enable-sandbox` to the renderer so it won't have any node.js
|
||||||
// integration.
|
// integration.
|
||||||
if (IsSandboxed(web_contents)) {
|
bool sandbox = false;
|
||||||
|
if (web_preferences.GetBoolean("sandbox", &sandbox) && sandbox) {
|
||||||
command_line->AppendSwitch(switches::kEnableSandbox);
|
command_line->AppendSwitch(switches::kEnableSandbox);
|
||||||
} else if (!command_line->HasSwitch(switches::kEnableSandbox)) {
|
} else if (!command_line->HasSwitch(switches::kEnableSandbox)) {
|
||||||
command_line->AppendSwitch(::switches::kNoSandbox);
|
command_line->AppendSwitch(::switches::kNoSandbox);
|
||||||
|
@ -237,47 +238,6 @@ bool WebContentsPreferences::IsPreferenceEnabled(
|
||||||
return bool_value;
|
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
|
// static
|
||||||
void WebContentsPreferences::OverrideWebkitPrefs(
|
void WebContentsPreferences::OverrideWebkitPrefs(
|
||||||
content::WebContents* web_contents, content::WebPreferences* prefs) {
|
content::WebContents* web_contents, content::WebPreferences* prefs) {
|
||||||
|
|
|
@ -39,15 +39,6 @@ class WebContentsPreferences
|
||||||
|
|
||||||
static bool IsPreferenceEnabled(const std::string& attribute_name,
|
static bool IsPreferenceEnabled(const std::string& attribute_name,
|
||||||
content::WebContents* web_contents);
|
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.
|
// Modify the WebPreferences according to |web_contents|'s preferences.
|
||||||
static void OverrideWebkitPrefs(
|
static void OverrideWebkitPrefs(
|
||||||
|
|
Loading…
Reference in a new issue