feat: add frame and webContents to webRequest details (#27078)
* feat: add frame and webContents to webRequest details * chore: use frame_converter.h Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
This commit is contained in:
parent
81dc8a0d04
commit
088f2e625f
3 changed files with 33 additions and 6 deletions
|
@ -51,6 +51,8 @@ The following methods are available on instances of `WebRequest`:
|
|||
* `url` String
|
||||
* `method` String
|
||||
* `webContentsId` Integer (optional)
|
||||
* `webContents` WebContents (optional)
|
||||
* `frame` WebFrameMain (optional)
|
||||
* `resourceType` String
|
||||
* `referrer` String
|
||||
* `timestamp` Double
|
||||
|
@ -94,6 +96,8 @@ Some examples of valid `urls`:
|
|||
* `url` String
|
||||
* `method` String
|
||||
* `webContentsId` Integer (optional)
|
||||
* `webContents` WebContents (optional)
|
||||
* `frame` WebFrameMain (optional)
|
||||
* `resourceType` String
|
||||
* `referrer` String
|
||||
* `timestamp` Double
|
||||
|
@ -121,6 +125,8 @@ The `callback` has to be called with a `response` object.
|
|||
* `url` String
|
||||
* `method` String
|
||||
* `webContentsId` Integer (optional)
|
||||
* `webContents` WebContents (optional)
|
||||
* `frame` WebFrameMain (optional)
|
||||
* `resourceType` String
|
||||
* `referrer` String
|
||||
* `timestamp` Double
|
||||
|
@ -141,6 +147,8 @@ response are visible by the time this listener is fired.
|
|||
* `url` String
|
||||
* `method` String
|
||||
* `webContentsId` Integer (optional)
|
||||
* `webContents` WebContents (optional)
|
||||
* `frame` WebFrameMain (optional)
|
||||
* `resourceType` String
|
||||
* `referrer` String
|
||||
* `timestamp` Double
|
||||
|
@ -173,6 +181,8 @@ The `callback` has to be called with a `response` object.
|
|||
* `url` String
|
||||
* `method` String
|
||||
* `webContentsId` Integer (optional)
|
||||
* `webContents` WebContents (optional)
|
||||
* `frame` WebFrameMain (optional)
|
||||
* `resourceType` String
|
||||
* `referrer` String
|
||||
* `timestamp` Double
|
||||
|
@ -197,6 +207,8 @@ and response headers are available.
|
|||
* `url` String
|
||||
* `method` String
|
||||
* `webContentsId` Integer (optional)
|
||||
* `webContents` WebContents (optional)
|
||||
* `frame` WebFrameMain (optional)
|
||||
* `resourceType` String
|
||||
* `referrer` String
|
||||
* `timestamp` Double
|
||||
|
@ -222,6 +234,8 @@ redirect is about to occur.
|
|||
* `url` String
|
||||
* `method` String
|
||||
* `webContentsId` Integer (optional)
|
||||
* `webContents` WebContents (optional)
|
||||
* `frame` WebFrameMain (optional)
|
||||
* `resourceType` String
|
||||
* `referrer` String
|
||||
* `timestamp` Double
|
||||
|
@ -245,6 +259,8 @@ completed.
|
|||
* `url` String
|
||||
* `method` String
|
||||
* `webContentsId` Integer (optional)
|
||||
* `webContents` WebContents (optional)
|
||||
* `frame` WebFrameMain (optional)
|
||||
* `resourceType` String
|
||||
* `referrer` String
|
||||
* `timestamp` Double
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
#include "net/http/http_content_disposition.h"
|
||||
#include "shell/browser/api/electron_api_session.h"
|
||||
#include "shell/browser/api/electron_api_web_contents.h"
|
||||
#include "shell/browser/api/electron_api_web_frame_main.h"
|
||||
#include "shell/browser/electron_browser_context.h"
|
||||
#include "shell/browser/javascript_environment.h"
|
||||
#include "shell/common/gin_converters/callback_converter.h"
|
||||
#include "shell/common/gin_converters/frame_converter.h"
|
||||
#include "shell/common/gin_converters/gurl_converter.h"
|
||||
#include "shell/common/gin_converters/net_converter.h"
|
||||
#include "shell/common/gin_converters/std_converter.h"
|
||||
|
@ -156,13 +158,19 @@ void ToDictionary(gin::Dictionary* details, extensions::WebRequestInfo* info) {
|
|||
HttpResponseHeadersToV8(info->response_headers.get()));
|
||||
}
|
||||
|
||||
auto* web_contents = content::WebContents::FromRenderFrameHost(
|
||||
content::RenderFrameHost::FromID(info->render_process_id,
|
||||
info->frame_id));
|
||||
auto* render_frame_host =
|
||||
content::RenderFrameHost::FromID(info->render_process_id, info->frame_id);
|
||||
if (render_frame_host) {
|
||||
details->Set("frame", render_frame_host);
|
||||
auto* web_contents =
|
||||
content::WebContents::FromRenderFrameHost(render_frame_host);
|
||||
auto* api_web_contents = WebContents::From(web_contents);
|
||||
if (api_web_contents)
|
||||
if (api_web_contents) {
|
||||
details->Set("webContents", api_web_contents);
|
||||
details->Set("webContentsId", api_web_contents->ID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ToDictionary(gin::Dictionary* details,
|
||||
const network::ResourceRequest& request) {
|
||||
|
|
|
@ -90,6 +90,9 @@ describe('webRequest module', () => {
|
|||
expect(details.id).to.be.a('number');
|
||||
expect(details.timestamp).to.be.a('number');
|
||||
expect(details.webContentsId).to.be.a('number');
|
||||
expect(details.webContents).to.be.an('object');
|
||||
expect(details.webContents!.id).to.equal(details.webContentsId);
|
||||
expect(details.frame).to.be.an('object');
|
||||
expect(details.url).to.be.a('string').that.is.equal(defaultURL);
|
||||
expect(details.method).to.be.a('string').that.is.equal('GET');
|
||||
expect(details.resourceType).to.be.a('string').that.is.equal('xhr');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue