browser: fix retrieving webcontents from associated process id

This commit is contained in:
Robo 2016-03-14 03:53:39 +05:30
parent b2059ec8af
commit 48064ee7e9
2 changed files with 8 additions and 17 deletions

View file

@ -46,11 +46,6 @@ namespace atom {
namespace { 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. // Next navigation should not restart renderer process.
bool g_suppress_renderer_process_restart = false; bool g_suppress_renderer_process_restart = false;
@ -278,8 +273,8 @@ brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts(
void AtomBrowserClient::WebNotificationAllowed( void AtomBrowserClient::WebNotificationAllowed(
int render_process_id, int render_process_id,
const base::Callback<void(bool)>& callback) { const base::Callback<void(bool)>& callback) {
content::WebContents* web_contents = content::WebContents::FromRenderViewHost( content::WebContents* web_contents =
content::RenderViewHost::FromID(render_process_id, kDefaultRoutingID)); WebContentsPreferences::GetWebContentsFromProcessID(render_process_id);
if (!web_contents) { if (!web_contents) {
callback.Run(false); callback.Run(false);
return; return;

View file

@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include "atom/browser/web_contents_preferences.h"
#include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/child_process_security_policy.h"
#include "content/public/browser/permission_type.h" #include "content/public/browser/permission_type.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
@ -17,17 +18,12 @@ namespace atom {
namespace { namespace {
// Must be kept in sync with atom_browser_client.cc
int kDefaultRoutingID = 2;
bool WebContentsDestroyed(int process_id) { bool WebContentsDestroyed(int process_id) {
auto rvh = content::RenderViewHost::FromID(process_id, kDefaultRoutingID); auto contents =
if (rvh) { WebContentsPreferences::GetWebContentsFromProcessID(process_id);
auto contents = content::WebContents::FromRenderViewHost(rvh); if (!contents)
return contents->IsBeingDestroyed(); return true;
} return contents->IsBeingDestroyed();
return true;
} }
} // namespace } // namespace