feat: add WebContents.opener and webContents.fromFrame() (#35140)
* feat: add WebContents.opener * feat: add webContents.fromFrame(frame) * fix: unknown type name * test: fix and add more fromFrame cases * docs: clarified terminology
This commit is contained in:
parent
697a219bcb
commit
c09c94fc98
5 changed files with 104 additions and 1 deletions
|
@ -3449,6 +3449,10 @@ content::RenderFrameHost* WebContents::MainFrame() {
|
|||
return web_contents()->GetPrimaryMainFrame();
|
||||
}
|
||||
|
||||
content::RenderFrameHost* WebContents::Opener() {
|
||||
return web_contents()->GetOpener();
|
||||
}
|
||||
|
||||
void WebContents::NotifyUserActivation() {
|
||||
content::RenderFrameHost* frame = web_contents()->GetPrimaryMainFrame();
|
||||
if (frame)
|
||||
|
@ -4060,6 +4064,7 @@ v8::Local<v8::ObjectTemplate> WebContents::FillObjectTemplate(
|
|||
.SetProperty("devToolsWebContents", &WebContents::DevToolsWebContents)
|
||||
.SetProperty("debugger", &WebContents::Debugger)
|
||||
.SetProperty("mainFrame", &WebContents::MainFrame)
|
||||
.SetProperty("opener", &WebContents::Opener)
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
@ -4174,6 +4179,7 @@ namespace {
|
|||
|
||||
using electron::api::GetAllWebContents;
|
||||
using electron::api::WebContents;
|
||||
using electron::api::WebFrameMain;
|
||||
|
||||
gin::Handle<WebContents> WebContentsFromID(v8::Isolate* isolate, int32_t id) {
|
||||
WebContents* contents = WebContents::FromID(id);
|
||||
|
@ -4181,6 +4187,15 @@ gin::Handle<WebContents> WebContentsFromID(v8::Isolate* isolate, int32_t id) {
|
|||
: gin::Handle<WebContents>();
|
||||
}
|
||||
|
||||
gin::Handle<WebContents> WebContentsFromFrame(v8::Isolate* isolate,
|
||||
WebFrameMain* web_frame) {
|
||||
content::RenderFrameHost* rfh = web_frame->render_frame_host();
|
||||
content::WebContents* source = content::WebContents::FromRenderFrameHost(rfh);
|
||||
WebContents* contents = WebContents::From(source);
|
||||
return contents ? gin::CreateHandle(isolate, contents)
|
||||
: gin::Handle<WebContents>();
|
||||
}
|
||||
|
||||
gin::Handle<WebContents> WebContentsFromDevToolsTargetID(
|
||||
v8::Isolate* isolate,
|
||||
std::string target_id) {
|
||||
|
@ -4209,6 +4224,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
|||
gin_helper::Dictionary dict(isolate, exports);
|
||||
dict.Set("WebContents", WebContents::GetConstructor(context));
|
||||
dict.SetMethod("fromId", &WebContentsFromID);
|
||||
dict.SetMethod("fromFrame", &WebContentsFromFrame);
|
||||
dict.SetMethod("fromDevToolsTargetId", &WebContentsFromDevToolsTargetID);
|
||||
dict.SetMethod("getAllWebContents", &GetAllWebContentsAsV8);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue