Update guest process id when navigating
This commit is contained in:
parent
d8adbc0875
commit
36c4b1705d
3 changed files with 46 additions and 10 deletions
|
@ -151,11 +151,21 @@ void AtomBrowserClient::AppendExtraCommandLineSwitches(
|
|||
// uses the old going-to-be-swapped render process, then we try to find the
|
||||
// window from the swapped render process.
|
||||
if (!window && dying_render_process_) {
|
||||
child_process_id = dying_render_process_->GetID();
|
||||
int dying_process_id = dying_render_process_->GetID();
|
||||
WindowList::const_iterator iter = std::find_if(
|
||||
list->begin(), list->end(), FindByProcessId(child_process_id));
|
||||
if (iter != list->end())
|
||||
list->begin(), list->end(), FindByProcessId(dying_process_id));
|
||||
if (iter != list->end()) {
|
||||
window = *iter;
|
||||
child_process_id = dying_process_id;
|
||||
} else {
|
||||
// It appears that the dying process doesn't belong to a BrowserWindow,
|
||||
// then it must be a guest process, we should update its process ID in the
|
||||
// WebViewManager here.
|
||||
auto child_process = content::RenderProcessHost::FromID(child_process_id);
|
||||
// Update the process ID in webview guests.
|
||||
WebViewManager::UpdateGuestProcessID(dying_render_process_,
|
||||
child_process);
|
||||
}
|
||||
}
|
||||
|
||||
if (window) {
|
||||
|
|
|
@ -10,18 +10,40 @@
|
|||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
WebViewManager* GetManagerFromProcess(content::RenderProcessHost* process) {
|
||||
if (!process)
|
||||
return nullptr;
|
||||
auto context = process->GetBrowserContext();
|
||||
if (!context)
|
||||
return nullptr;
|
||||
return static_cast<WebViewManager*>(context->GetGuestManager());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// 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();
|
||||
auto manager = GetManagerFromProcess(process);
|
||||
if (!manager)
|
||||
return false;
|
||||
return static_cast<WebViewManager*>(manager)->GetInfo(process->GetID(), info);
|
||||
return manager->GetInfo(process->GetID(), info);
|
||||
}
|
||||
|
||||
// static
|
||||
void WebViewManager::UpdateGuestProcessID(
|
||||
content::RenderProcessHost* old_process,
|
||||
content::RenderProcessHost* new_process) {
|
||||
auto manager = GetManagerFromProcess(old_process);
|
||||
if (manager) {
|
||||
base::AutoLock auto_lock(manager->lock_);
|
||||
int old_id = old_process->GetID();
|
||||
int new_id = new_process->GetID();
|
||||
manager->webview_info_map_[new_id] = manager->webview_info_map_[old_id];
|
||||
manager->webview_info_map_.erase(old_id);
|
||||
}
|
||||
}
|
||||
|
||||
WebViewManager::WebViewManager(content::BrowserContext* context) {
|
||||
|
|
|
@ -34,6 +34,10 @@ class WebViewManager : public content::BrowserPluginGuestManager {
|
|||
static bool GetInfoForProcess(content::RenderProcessHost* process,
|
||||
WebViewInfo* info);
|
||||
|
||||
// Updates the guest process ID.
|
||||
static void UpdateGuestProcessID(content::RenderProcessHost* old_process,
|
||||
content::RenderProcessHost* new_process);
|
||||
|
||||
explicit WebViewManager(content::BrowserContext* context);
|
||||
virtual ~WebViewManager();
|
||||
|
||||
|
|
Loading…
Reference in a new issue