Clean up code
This commit is contained in:
parent
d4be2da70e
commit
34cd1435b4
1 changed files with 11 additions and 22 deletions
|
@ -38,21 +38,20 @@ int kDefaultRoutingID = 2;
|
||||||
// Next navigation should not restart renderer process.
|
// Next navigation should not restart renderer process.
|
||||||
bool g_suppress_renderer_process_restart = false;
|
bool g_suppress_renderer_process_restart = false;
|
||||||
|
|
||||||
// Returns the WebContents from process.
|
|
||||||
inline content::WebContents* GetWebContentsFromProcess(int process_id) {
|
|
||||||
return content::WebContents::FromRenderViewHost(
|
|
||||||
content::RenderViewHost::FromID(process_id, kDefaultRoutingID));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find out the owner of the child process according to child_process_id.
|
// Find out the owner of the child process according to child_process_id.
|
||||||
enum WebContentsOwner {
|
enum ProcessOwner {
|
||||||
OWNER_NATIVE_WINDOW,
|
OWNER_NATIVE_WINDOW,
|
||||||
OWNER_GUEST_WEB_CONTENTS,
|
OWNER_GUEST_WEB_CONTENTS,
|
||||||
OWNER_NONE, // it might be devtools though.
|
OWNER_NONE, // it might be devtools though.
|
||||||
};
|
};
|
||||||
WebContentsOwner GetWebContentsOwner(content::WebContents* web_contents,
|
ProcessOwner GetProcessOwner(int process_id,
|
||||||
NativeWindow** window,
|
NativeWindow** window,
|
||||||
WebViewManager::WebViewInfo* info) {
|
WebViewManager::WebViewInfo* info) {
|
||||||
|
auto web_contents = content::WebContents::FromRenderViewHost(
|
||||||
|
content::RenderViewHost::FromID(process_id, kDefaultRoutingID));
|
||||||
|
if (!web_contents)
|
||||||
|
return OWNER_NONE;
|
||||||
|
|
||||||
// First search for NativeWindow.
|
// First search for NativeWindow.
|
||||||
for (auto native_window : *WindowList::GetInstance())
|
for (auto native_window : *WindowList::GetInstance())
|
||||||
if (web_contents == native_window->GetWebContents()) {
|
if (web_contents == native_window->GetWebContents()) {
|
||||||
|
@ -115,14 +114,8 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
||||||
prefs->allow_displaying_insecure_content = false;
|
prefs->allow_displaying_insecure_content = false;
|
||||||
prefs->allow_running_insecure_content = false;
|
prefs->allow_running_insecure_content = false;
|
||||||
|
|
||||||
// Turn off web security for devtools.
|
|
||||||
auto web_contents = content::WebContents::FromRenderViewHost(host);
|
|
||||||
if (web_contents && web_contents->GetURL().SchemeIs("chrome-devtools")) {
|
|
||||||
prefs->web_security_enabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom preferences of guest page.
|
// Custom preferences of guest page.
|
||||||
|
auto web_contents = content::WebContents::FromRenderViewHost(host);
|
||||||
WebViewManager::WebViewInfo info;
|
WebViewManager::WebViewInfo info;
|
||||||
if (WebViewManager::GetInfoForWebContents(web_contents, &info)) {
|
if (WebViewManager::GetInfoForWebContents(web_contents, &info)) {
|
||||||
prefs->web_security_enabled = !info.disable_web_security;
|
prefs->web_security_enabled = !info.disable_web_security;
|
||||||
|
@ -162,13 +155,9 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
if (process_type != "renderer")
|
if (process_type != "renderer")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto web_contents = GetWebContentsFromProcess(process_id);
|
|
||||||
if (!web_contents)
|
|
||||||
return;
|
|
||||||
|
|
||||||
NativeWindow* window;
|
NativeWindow* window;
|
||||||
WebViewManager::WebViewInfo info;
|
WebViewManager::WebViewInfo info;
|
||||||
WebContentsOwner owner = GetWebContentsOwner(web_contents, &window, &info);
|
ProcessOwner owner = GetProcessOwner(process_id, &window, &info);
|
||||||
|
|
||||||
if (owner == OWNER_NATIVE_WINDOW) {
|
if (owner == OWNER_NATIVE_WINDOW) {
|
||||||
window->AppendExtraCommandLineSwitches(command_line);
|
window->AppendExtraCommandLineSwitches(command_line);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue