// 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) {
namespace atom {
-// static
-bool WebViewManager::GetInfoForProcess(content::RenderProcessHost* process,
- WebViewInfo* info) {
+namespace {
+
+WebViewManager* GetManagerFromProcess(content::RenderProcessHost* process) {
if (!process)
- return false;
+ return nullptr;
auto context = process->GetBrowserContext();
if (!context)
- return false;
- auto manager = context->GetGuestManager();
+ return nullptr;
+ return static_cast<WebViewManager*>(context->GetGuestManager());
+}
+
+} // namespace
+
+// static
+bool WebViewManager::GetInfoForProcess(content::RenderProcessHost* process,
+ WebViewInfo* info) {
+ 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) {
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();