From 2d771674bbd236317aab6f690347f96a166010fd Mon Sep 17 00:00:00 2001 From: Boik Date: Tue, 12 Sep 2017 20:17:11 +0800 Subject: [PATCH] get webContentsId instead --- atom/browser/api/trackable_object.h | 6 +++--- atom/browser/net/atom_network_delegate.cc | 14 ++++++++------ spec/api-web-request-spec.js | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/atom/browser/api/trackable_object.h b/atom/browser/api/trackable_object.h index 7ec544578869..e632f52b84c6 100644 --- a/atom/browser/api/trackable_object.h +++ b/atom/browser/api/trackable_object.h @@ -30,15 +30,15 @@ class TrackableObjectBase { // Wrap TrackableObject into a class that SupportsUserData. void AttachAsUserData(base::SupportsUserData* wrapped); + // Get the weak_map_id from SupportsUserData. + static int32_t GetIDFromWrappedClass(base::SupportsUserData* wrapped); + protected: virtual ~TrackableObjectBase(); // Returns a closure that can destroy the native class. base::Closure GetDestroyClosure(); - // Get the weak_map_id from SupportsUserData. - static int32_t GetIDFromWrappedClass(base::SupportsUserData* wrapped); - // Register a callback that should be destroyed before JavaScript environment // gets destroyed. static base::Closure RegisterDestructionCallback(const base::Closure& c); diff --git a/atom/browser/net/atom_network_delegate.cc b/atom/browser/net/atom_network_delegate.cc index e86198b22ef5..91e3d86e1322 100644 --- a/atom/browser/net/atom_network_delegate.cc +++ b/atom/browser/net/atom_network_delegate.cc @@ -6,11 +6,13 @@ #include +#include "atom/browser/api/atom_api_web_contents.h" #include "atom/common/native_mate_converters/net_converter.h" #include "base/stl_util.h" #include "base/strings/string_util.h" #include "brightray/browser/net/devtools_network_transaction.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/render_frame_host.h" #include "net/url_request/url_request.h" using brightray::DevToolsNetworkTransaction; @@ -74,13 +76,13 @@ void ToDictionary(base::DictionaryValue* details, net::URLRequest* request) { FillRequestDetails(details, request); details->SetInteger("id", request->identifier()); details->SetDouble("timestamp", base::Time::Now().ToDoubleT() * 1000); - auto info = content::ResourceRequestInfo::ForRequest(request); + const content::ResourceRequestInfo* info = content::ResourceRequestInfo::ForRequest(request); if (info) { - int64_t process_id = info->GetChildID(); - int64_t routing_id = info->GetRouteID(); - details->SetDouble("webContentsGetId", (process_id << 32) + routing_id); - details->SetString("resourceType", - ResourceTypeToString(info->GetResourceType())); + int process_id = info->GetChildID(); + int frame_id = info->GetRenderFrameID(); + content::WebContents* webContents + = content::WebContents::FromRenderFrameHost(content::RenderFrameHost::FromID(process_id, frame_id)); + details->SetInteger("webContentsId", atom::api::WebContents::GetIDFromWrappedClass(webContents)); } else { details->SetString("resourceType", "other"); } diff --git a/spec/api-web-request-spec.js b/spec/api-web-request-spec.js index b3a3a4870b3b..85afb4c93998 100644 --- a/spec/api-web-request-spec.js +++ b/spec/api-web-request-spec.js @@ -89,7 +89,7 @@ describe('webRequest module', function () { ses.webRequest.onBeforeRequest(function (details, callback) { assert.equal(typeof details.id, 'number') assert.equal(typeof details.timestamp, 'number') - assert.equal(typeof details.webContentsGetId, 'number') + assert.equal(typeof details.webContentsId, 'number') assert.equal(details.url, defaultURL) assert.equal(details.method, 'GET') assert.equal(details.resourceType, 'xhr')