Avoid using global BrowserContext
This commit is contained in:
parent
502c0f0df7
commit
2c61070b36
4 changed files with 34 additions and 25 deletions
|
@ -39,10 +39,9 @@ v8::Persistent<v8::ObjectTemplate> template_;
|
||||||
|
|
||||||
// Get the window that has the |guest| embedded.
|
// Get the window that has the |guest| embedded.
|
||||||
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
|
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
|
||||||
auto manager = AtomBrowserContext::Get()->GetGuestManager();
|
auto process = guest->GetRenderProcessHost();
|
||||||
int guest_process_id = guest->GetRenderProcessHost()->GetID();
|
|
||||||
WebViewManager::WebViewInfo info;
|
WebViewManager::WebViewInfo info;
|
||||||
if (!static_cast<WebViewManager*>(manager)->GetInfo(guest_process_id, &info))
|
if (WebViewManager::GetInfoForProcess(process, &info))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return NativeWindow::FromRenderView(
|
return NativeWindow::FromRenderView(
|
||||||
info.embedder->GetRenderProcessHost()->GetID(),
|
info.embedder->GetRenderProcessHost()->GetID(),
|
||||||
|
|
|
@ -44,19 +44,6 @@ struct FindByProcessId {
|
||||||
int child_process_id_;
|
int child_process_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool GetWebViewInfo(content::RenderProcessHost* host,
|
|
||||||
WebViewManager::WebViewInfo* info) {
|
|
||||||
if (!host)
|
|
||||||
return false;
|
|
||||||
auto context = host->GetBrowserContext();
|
|
||||||
if (!context)
|
|
||||||
return false;
|
|
||||||
auto manager = context->GetGuestManager();
|
|
||||||
if (!manager)
|
|
||||||
return false;
|
|
||||||
return static_cast<WebViewManager*>(manager)->GetInfo(host->GetID(), info);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
AtomBrowserClient::AtomBrowserClient()
|
AtomBrowserClient::AtomBrowserClient()
|
||||||
|
@ -110,15 +97,15 @@ void AtomBrowserClient::OverrideWebkitPrefs(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom preferences of guest page.
|
// Custom preferences of guest page.
|
||||||
|
auto process = render_view_host->GetProcess();
|
||||||
WebViewManager::WebViewInfo info;
|
WebViewManager::WebViewInfo info;
|
||||||
if (GetWebViewInfo(render_view_host->GetProcess(), &info)) {
|
if (WebViewManager::GetInfoForProcess(process, &info)) {
|
||||||
prefs->web_security_enabled = !info.disable_web_security;
|
prefs->web_security_enabled = !info.disable_web_security;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeWindow* window = NativeWindow::FromRenderView(
|
NativeWindow* window = NativeWindow::FromRenderView(
|
||||||
render_view_host->GetProcess()->GetID(),
|
process->GetID(), render_view_host->GetRoutingID());
|
||||||
render_view_host->GetRoutingID());
|
|
||||||
if (window)
|
if (window)
|
||||||
window->OverrideWebkitPrefs(url, prefs);
|
window->OverrideWebkitPrefs(url, prefs);
|
||||||
}
|
}
|
||||||
|
@ -168,7 +155,7 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
||||||
// Append commnad line arguments for guest web view.
|
// Append commnad line arguments for guest web view.
|
||||||
auto child_process = content::RenderProcessHost::FromID(child_process_id);
|
auto child_process = content::RenderProcessHost::FromID(child_process_id);
|
||||||
WebViewManager::WebViewInfo info;
|
WebViewManager::WebViewInfo info;
|
||||||
if (GetWebViewInfo(child_process, &info)) {
|
if (WebViewManager::GetInfoForProcess(child_process, &info)) {
|
||||||
command_line->AppendSwitchASCII(
|
command_line->AppendSwitchASCII(
|
||||||
switches::kGuestInstanceID,
|
switches::kGuestInstanceID,
|
||||||
base::IntToString(info.guest_instance_id));
|
base::IntToString(info.guest_instance_id));
|
||||||
|
|
|
@ -42,8 +42,11 @@ struct Converter<atom::WebViewManager::WebViewInfo> {
|
||||||
if (!options.Get("preloadUrl", &preload_url))
|
if (!options.Get("preloadUrl", &preload_url))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return net::FileURLToFilePath(preload_url, &(out->preload_script)) &&
|
if (!preload_url.is_empty() &&
|
||||||
options.Get("nodeIntegration", &(out->node_integration)) &&
|
!net::FileURLToFilePath(preload_url, &(out->preload_script)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return options.Get("nodeIntegration", &(out->node_integration)) &&
|
||||||
options.Get("plugins", &(out->plugins)) &&
|
options.Get("plugins", &(out->plugins)) &&
|
||||||
options.Get("disableWebSecurity", &(out->disable_web_security));
|
options.Get("disableWebSecurity", &(out->disable_web_security));
|
||||||
}
|
}
|
||||||
|
@ -53,6 +56,20 @@ struct Converter<atom::WebViewManager::WebViewInfo> {
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
// static
|
||||||
|
bool WebViewManager::GetInfoForProcess(content::RenderProcessHost* process,
|
||||||
|
WebViewInfo* info) {
|
||||||
|
if (!process)
|
||||||
|
return false;
|
||||||
|
auto context = process->GetBrowserContext();
|
||||||
|
if (!context)
|
||||||
|
return false;
|
||||||
|
auto manager = context->GetGuestManager();
|
||||||
|
if (!manager)
|
||||||
|
return false;
|
||||||
|
return static_cast<WebViewManager*>(manager)->GetInfo(process->GetID(), info);
|
||||||
|
}
|
||||||
|
|
||||||
WebViewManager::WebViewManager(content::BrowserContext* context) {
|
WebViewManager::WebViewManager(content::BrowserContext* context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,13 @@
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class BrowserContext;
|
class BrowserContext;
|
||||||
|
class RenderProcessHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class WebViewManager : public content::BrowserPluginGuestManager {
|
class WebViewManager : public content::BrowserPluginGuestManager {
|
||||||
public:
|
public:
|
||||||
explicit WebViewManager(content::BrowserContext* context);
|
|
||||||
virtual ~WebViewManager();
|
|
||||||
|
|
||||||
struct WebViewInfo {
|
struct WebViewInfo {
|
||||||
int guest_instance_id;
|
int guest_instance_id;
|
||||||
content::WebContents* embedder;
|
content::WebContents* embedder;
|
||||||
|
@ -32,6 +30,14 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
||||||
base::FilePath preload_script;
|
base::FilePath preload_script;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Finds the WebViewManager attached with |process| and returns the
|
||||||
|
// WebViewInfo of it.
|
||||||
|
static bool GetInfoForProcess(content::RenderProcessHost* process,
|
||||||
|
WebViewInfo* info);
|
||||||
|
|
||||||
|
explicit WebViewManager(content::BrowserContext* context);
|
||||||
|
virtual ~WebViewManager();
|
||||||
|
|
||||||
void AddGuest(int guest_instance_id,
|
void AddGuest(int guest_instance_id,
|
||||||
int element_instance_id,
|
int element_instance_id,
|
||||||
content::WebContents* embedder,
|
content::WebContents* embedder,
|
||||||
|
|
Loading…
Reference in a new issue