Map pending process id to webContents for frame host initiating navigation

This commit is contained in:
Kevin Sawicki 2017-07-10 15:48:12 -07:00
parent 34c5abfe43
commit 06e60e5d4d
2 changed files with 13 additions and 19 deletions

View file

@ -79,9 +79,10 @@ AtomBrowserClient::~AtomBrowserClient() {
content::WebContents* AtomBrowserClient::GetWebContentsFromProcessID(
int process_id) {
// If the process is a pending process, we should use the old one.
// If the process is a pending process, we should use the web contents
// for the frame host passed into OverrideSiteInstanceForNavigation.
if (base::ContainsKey(pending_processes_, process_id))
process_id = pending_processes_[process_id];
return pending_processes_[process_id];
// Certain render process will be created with no associated render view,
// for example: ServiceWorker.
@ -231,12 +232,12 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation(
content::BrowserThread::UI, FROM_HERE,
base::Bind(&Noop, base::RetainedRef(site_instance)));
// Remember the original renderer process of the pending renderer process.
auto current_process = current_instance->GetProcess();
// Remember the original web contents for the pending renderer process.
auto pending_process = (*new_instance)->GetProcess();
pending_processes_[pending_process->GetID()] = current_process->GetID();
pending_processes_[pending_process->GetID()] =
content::WebContents::FromRenderFrameHost(render_frame_host);;
// Clear the entry in map when process ends.
current_process->AddObserver(this);
pending_process->AddObserver(this);
}
void AtomBrowserClient::AppendExtraCommandLineSwitches(
@ -277,11 +278,9 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
}
content::WebContents* web_contents = GetWebContentsFromProcessID(process_id);
if (!web_contents)
return;
WebContentsPreferences::AppendExtraCommandLineSwitches(
web_contents, command_line);
if (web_contents)
WebContentsPreferences::AppendExtraCommandLineSwitches(
web_contents, command_line);
}
void AtomBrowserClient::DidCreatePpapiPlugin(
@ -421,12 +420,7 @@ void AtomBrowserClient::WebNotificationAllowed(
void AtomBrowserClient::RenderProcessHostDestroyed(
content::RenderProcessHost* host) {
int process_id = host->GetID();
for (const auto& entry : pending_processes_) {
if (entry.first == process_id || entry.second == process_id) {
pending_processes_.erase(entry.first);
break;
}
}
pending_processes_.erase(process_id);
RemoveProcessPreferences(process_id);
}

View file

@ -130,8 +130,8 @@ class AtomBrowserClient : public brightray::BrowserClient,
bool RendererUsesNativeWindowOpen(int process_id);
bool RendererDisablesPopups(int process_id);
// pending_render_process => current_render_process.
std::map<int, int> pending_processes_;
// pending_render_process => web contents.
std::map<int, content::WebContents*> pending_processes_;
std::map<int, ProcessPreferences> process_preferences_;
std::map<int, base::ProcessId> render_process_host_pids_;