Skip to content

Commit 725dac3

Browse files
miniakzcbenz
authored andcommitted
fix: pass frameId to v8Util.setRemoteCallbackFreer() (electron#20732) (electron#20814)
1 parent 6e32da3 commit 725dac3

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lib/browser/rpc-server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const unwrapArgs = function (sender, frameId, contextId, args) {
231231
v8Util.setHiddenValue(callIntoRenderer, 'location', meta.location)
232232
Object.defineProperty(callIntoRenderer, 'length', { value: meta.length })
233233

234-
v8Util.setRemoteCallbackFreer(callIntoRenderer, contextId, meta.id, sender)
234+
v8Util.setRemoteCallbackFreer(callIntoRenderer, frameId, contextId, meta.id, sender)
235235
rendererFunctions.set(objectId, callIntoRenderer)
236236
return callIntoRenderer
237237
}

shell/common/api/remote_callback_freer.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ namespace electron {
1616
// static
1717
void RemoteCallbackFreer::BindTo(v8::Isolate* isolate,
1818
v8::Local<v8::Object> target,
19+
int frame_id,
1920
const std::string& context_id,
2021
int object_id,
2122
content::WebContents* web_contents) {
22-
new RemoteCallbackFreer(isolate, target, context_id, object_id, web_contents);
23+
new RemoteCallbackFreer(isolate, target, frame_id, context_id, object_id,
24+
web_contents);
2325
}
2426

2527
RemoteCallbackFreer::RemoteCallbackFreer(v8::Isolate* isolate,
2628
v8::Local<v8::Object> target,
29+
int frame_id,
2730
const std::string& context_id,
2831
int object_id,
2932
content::WebContents* web_contents)
3033
: ObjectLifeMonitor(isolate, target),
3134
content::WebContentsObserver(web_contents),
35+
frame_id_(frame_id),
3236
context_id_(context_id),
3337
object_id_(object_id) {}
3438

@@ -40,10 +44,15 @@ void RemoteCallbackFreer::RunDestructor() {
4044
int32_t sender_id = 0;
4145
args.AppendString(context_id_);
4246
args.AppendInteger(object_id_);
43-
auto* frame_host = web_contents()->GetMainFrame();
44-
if (frame_host) {
47+
48+
auto frames = web_contents()->GetAllFrames();
49+
auto iter = std::find_if(frames.begin(), frames.end(), [this](auto* f) {
50+
return f->GetRoutingID() == frame_id_;
51+
});
52+
53+
if (iter != frames.end() && (*iter)->IsRenderFrameLive()) {
4554
mojom::ElectronRendererAssociatedPtr electron_ptr;
46-
frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
55+
(*iter)->GetRemoteAssociatedInterfaces()->GetInterface(
4756
mojo::MakeRequest(&electron_ptr));
4857
electron_ptr->Message(true /* internal */, false /* send_to_all */, channel,
4958
args.Clone(), sender_id);

shell/common/api/remote_callback_freer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ class RemoteCallbackFreer : public ObjectLifeMonitor,
1717
public:
1818
static void BindTo(v8::Isolate* isolate,
1919
v8::Local<v8::Object> target,
20+
int frame_id,
2021
const std::string& context_id,
2122
int object_id,
2223
content::WebContents* web_conents);
2324

2425
protected:
2526
RemoteCallbackFreer(v8::Isolate* isolate,
2627
v8::Local<v8::Object> target,
28+
int frame_id,
2729
const std::string& context_id,
2830
int object_id,
2931
content::WebContents* web_conents);
@@ -35,6 +37,7 @@ class RemoteCallbackFreer : public ObjectLifeMonitor,
3537
void RenderViewDeleted(content::RenderViewHost*) override;
3638

3739
private:
40+
int frame_id_;
3841
std::string context_id_;
3942
int object_id_;
4043

0 commit comments

Comments
 (0)