From a64978b812848e037a9ff81b1b4e2555aff8ad87 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Mon, 5 Sep 2016 22:28:40 -0300 Subject: [PATCH] Use the routing id on api::WebContents::GetID The sandbox option allows multiple webContents in one renderer process, so using the only the renderer id to identify WebContents instances is no longer an option. WebContents::GetID now returns a 64-bit integer, which is composed of both the process id(high 32), and the RenderViewHost routing id(low 32). Also add a `GetProcessID` that retrieves the renderer process id, a requirement in some of our javascript code. --- atom/browser/api/atom_api_web_contents.cc | 10 +++++++++- atom/browser/api/atom_api_web_contents.h | 3 ++- atom/common/api/atom_api_v8_util.cc | 2 +- lib/browser/chrome-extension.js | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index d6af1b672208..8b84b74f59d4 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -841,7 +841,14 @@ void WebContents::NavigationEntryCommitted( details.is_in_page, details.did_replace_entry); } -int WebContents::GetID() const { +int64_t WebContents::GetID() const { + int64_t process_id = web_contents()->GetRenderProcessHost()->GetID(); + int64_t routing_id = web_contents()->GetRoutingID(); + int64_t rv = (process_id << 32) + routing_id; + return rv; +} + +int WebContents::GetProcessID() const { return web_contents()->GetRenderProcessHost()->GetID(); } @@ -1536,6 +1543,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .MakeDestroyable() .SetMethod("getId", &WebContents::GetID) + .SetMethod("getProcessId", &WebContents::GetProcessID) .SetMethod("equal", &WebContents::Equal) .SetMethod("_loadURL", &WebContents::LoadURL) .SetMethod("downloadURL", &WebContents::DownloadURL) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index cfc3ccc4ab26..d0dceb1a98f0 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -68,7 +68,8 @@ class WebContents : public mate::TrackableObject, static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); - int GetID() const; + int64_t GetID() const; + int GetProcessID() const; Type GetType() const; bool Equal(const WebContents* web_contents) const; void LoadURL(const GURL& url, const mate::Dictionary& options); diff --git a/atom/common/api/atom_api_v8_util.cc b/atom/common/api/atom_api_v8_util.cc index 7b7655c6cd2e..ddacbb080899 100644 --- a/atom/common/api/atom_api_v8_util.cc +++ b/atom/common/api/atom_api_v8_util.cc @@ -104,7 +104,7 @@ void Initialize(v8::Local exports, v8::Local unused, dict.SetMethod("setRemoteObjectFreer", &atom::RemoteObjectFreer::BindTo); dict.SetMethod("createIDWeakMap", &atom::api::KeyWeakMap::Create); dict.SetMethod("createDoubleIDWeakMap", - &atom::api::KeyWeakMap>::Create); + &atom::api::KeyWeakMap>::Create); } } // namespace diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index 2088f39b37e7..840715a08a17 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -123,7 +123,7 @@ const hookWebContentsEvents = function (webContents) { sendToBackgroundPages('CHROME_WEBNAVIGATION_ONBEFORENAVIGATE', { frameId: 0, parentFrameId: -1, - processId: webContents.getId(), + processId: webContents.getProcessId(), tabId: tabId, timeStamp: Date.now(), url: url @@ -134,7 +134,7 @@ const hookWebContentsEvents = function (webContents) { sendToBackgroundPages('CHROME_WEBNAVIGATION_ONCOMPLETED', { frameId: 0, parentFrameId: -1, - processId: webContents.getId(), + processId: webContents.getProcessId(), tabId: tabId, timeStamp: Date.now(), url: url