fix: pass frameId to v8Util.setRemoteCallbackFreer() (#20732)
This commit is contained in:
parent
375e612ac5
commit
0f7ebff81e
4 changed files with 17 additions and 7 deletions
|
@ -309,7 +309,7 @@ const unwrapArgs = function (sender: electron.WebContents, frameId: number, cont
|
||||||
v8Util.setHiddenValue(callIntoRenderer, 'location', meta.location)
|
v8Util.setHiddenValue(callIntoRenderer, 'location', meta.location)
|
||||||
Object.defineProperty(callIntoRenderer, 'length', { value: meta.length })
|
Object.defineProperty(callIntoRenderer, 'length', { value: meta.length })
|
||||||
|
|
||||||
v8Util.setRemoteCallbackFreer(callIntoRenderer, contextId, meta.id, sender)
|
v8Util.setRemoteCallbackFreer(callIntoRenderer, frameId, contextId, meta.id, sender)
|
||||||
rendererFunctions.set(objectId, callIntoRenderer)
|
rendererFunctions.set(objectId, callIntoRenderer)
|
||||||
return callIntoRenderer
|
return callIntoRenderer
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,30 +17,37 @@ namespace electron {
|
||||||
// static
|
// static
|
||||||
void RemoteCallbackFreer::BindTo(v8::Isolate* isolate,
|
void RemoteCallbackFreer::BindTo(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> target,
|
v8::Local<v8::Object> target,
|
||||||
|
int frame_id,
|
||||||
const std::string& context_id,
|
const std::string& context_id,
|
||||||
int object_id,
|
int object_id,
|
||||||
content::WebContents* web_contents) {
|
content::WebContents* web_contents) {
|
||||||
new RemoteCallbackFreer(isolate, target, context_id, object_id, web_contents);
|
new RemoteCallbackFreer(isolate, target, frame_id, context_id, object_id,
|
||||||
|
web_contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteCallbackFreer::RemoteCallbackFreer(v8::Isolate* isolate,
|
RemoteCallbackFreer::RemoteCallbackFreer(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> target,
|
v8::Local<v8::Object> target,
|
||||||
|
int frame_id,
|
||||||
const std::string& context_id,
|
const std::string& context_id,
|
||||||
int object_id,
|
int object_id,
|
||||||
content::WebContents* web_contents)
|
content::WebContents* web_contents)
|
||||||
: ObjectLifeMonitor(isolate, target),
|
: ObjectLifeMonitor(isolate, target),
|
||||||
content::WebContentsObserver(web_contents),
|
content::WebContentsObserver(web_contents),
|
||||||
|
frame_id_(frame_id),
|
||||||
context_id_(context_id),
|
context_id_(context_id),
|
||||||
object_id_(object_id) {}
|
object_id_(object_id) {}
|
||||||
|
|
||||||
RemoteCallbackFreer::~RemoteCallbackFreer() = default;
|
RemoteCallbackFreer::~RemoteCallbackFreer() = default;
|
||||||
|
|
||||||
void RemoteCallbackFreer::RunDestructor() {
|
void RemoteCallbackFreer::RunDestructor() {
|
||||||
auto* frame_host = web_contents()->GetMainFrame();
|
auto frames = web_contents()->GetAllFrames();
|
||||||
if (frame_host) {
|
auto iter = std::find_if(frames.begin(), frames.end(), [this](auto* f) {
|
||||||
|
return f->GetRoutingID() == frame_id_;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (iter != frames.end() && (*iter)->IsRenderFrameLive()) {
|
||||||
mojo::AssociatedRemote<mojom::ElectronRenderer> electron_renderer;
|
mojo::AssociatedRemote<mojom::ElectronRenderer> electron_renderer;
|
||||||
frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
|
(*iter)->GetRemoteAssociatedInterfaces()->GetInterface(&electron_renderer);
|
||||||
&electron_renderer);
|
|
||||||
electron_renderer->DereferenceRemoteJSCallback(context_id_, object_id_);
|
electron_renderer->DereferenceRemoteJSCallback(context_id_, object_id_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ class RemoteCallbackFreer : public ObjectLifeMonitor,
|
||||||
public:
|
public:
|
||||||
static void BindTo(v8::Isolate* isolate,
|
static void BindTo(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> target,
|
v8::Local<v8::Object> target,
|
||||||
|
int frame_id,
|
||||||
const std::string& context_id,
|
const std::string& context_id,
|
||||||
int object_id,
|
int object_id,
|
||||||
content::WebContents* web_conents);
|
content::WebContents* web_conents);
|
||||||
|
@ -24,6 +25,7 @@ class RemoteCallbackFreer : public ObjectLifeMonitor,
|
||||||
protected:
|
protected:
|
||||||
RemoteCallbackFreer(v8::Isolate* isolate,
|
RemoteCallbackFreer(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> target,
|
v8::Local<v8::Object> target,
|
||||||
|
int frame_id,
|
||||||
const std::string& context_id,
|
const std::string& context_id,
|
||||||
int object_id,
|
int object_id,
|
||||||
content::WebContents* web_conents);
|
content::WebContents* web_conents);
|
||||||
|
@ -35,6 +37,7 @@ class RemoteCallbackFreer : public ObjectLifeMonitor,
|
||||||
void RenderViewDeleted(content::RenderViewHost*) override;
|
void RenderViewDeleted(content::RenderViewHost*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int frame_id_;
|
||||||
std::string context_id_;
|
std::string context_id_;
|
||||||
int object_id_;
|
int object_id_;
|
||||||
|
|
||||||
|
|
2
typings/internal-ambient.d.ts
vendored
2
typings/internal-ambient.d.ts
vendored
|
@ -30,7 +30,7 @@ declare namespace NodeJS {
|
||||||
deleteHiddenValue(obj: any, key: string): void;
|
deleteHiddenValue(obj: any, key: string): void;
|
||||||
requestGarbageCollectionForTesting(): void;
|
requestGarbageCollectionForTesting(): void;
|
||||||
createDoubleIDWeakMap(): any;
|
createDoubleIDWeakMap(): any;
|
||||||
setRemoteCallbackFreer(fn: Function, contextId: String, id: number, sender: any): void
|
setRemoteCallbackFreer(fn: Function, frameId: number, contextId: String, id: number, sender: any): void
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Process {
|
interface Process {
|
||||||
|
|
Loading…
Reference in a new issue