From 48064ee7e9a81ed431649e883d42e8e0908da4e4 Mon Sep 17 00:00:00 2001 From: Robo Date: Mon, 14 Mar 2016 03:53:39 +0530 Subject: [PATCH] browser: fix retrieving webcontents from associated process id --- atom/browser/atom_browser_client.cc | 9 ++------- atom/browser/atom_permission_manager.cc | 16 ++++++---------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index ca12723..63a1ea4 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -46,11 +46,6 @@ namespace atom { namespace { -// The default routing id of WebContents. -// In Electron each RenderProcessHost only has one WebContents, so this ID is -// same for every WebContents. -int kDefaultRoutingID = 1; - // Next navigation should not restart renderer process. bool g_suppress_renderer_process_restart = false; @@ -278,8 +273,8 @@ brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts( void AtomBrowserClient::WebNotificationAllowed( int render_process_id, const base::Callback& callback) { - content::WebContents* web_contents = content::WebContents::FromRenderViewHost( - content::RenderViewHost::FromID(render_process_id, kDefaultRoutingID)); + content::WebContents* web_contents = + WebContentsPreferences::GetWebContentsFromProcessID(render_process_id); if (!web_contents) { callback.Run(false); return; diff --git a/atom/browser/atom_permission_manager.cc b/atom/browser/atom_permission_manager.cc index 720d1f9..f7523c0 100644 --- a/atom/browser/atom_permission_manager.cc +++ b/atom/browser/atom_permission_manager.cc @@ -6,6 +6,7 @@ #include +#include "atom/browser/web_contents_preferences.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/permission_type.h" #include "content/public/browser/render_frame_host.h" @@ -17,17 +18,12 @@ namespace atom { namespace { -// Must be kept in sync with atom_browser_client.cc -int kDefaultRoutingID = 2; - bool WebContentsDestroyed(int process_id) { - auto rvh = content::RenderViewHost::FromID(process_id, kDefaultRoutingID); - if (rvh) { - auto contents = content::WebContents::FromRenderViewHost(rvh); - return contents->IsBeingDestroyed(); - } - - return true; + auto contents = + WebContentsPreferences::GetWebContentsFromProcessID(process_id); + if (!contents) + return true; + return contents->IsBeingDestroyed(); } } // namespace -- 2.7.4