Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset render_frame_disposed_ after render frame host change #31401

Merged
merged 2 commits into from Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/browser/api/web-frame-main.ts
Expand Up @@ -7,15 +7,23 @@ WebFrameMain.prototype.send = function (channel, ...args) {
throw new Error('Missing required channel argument');
}

return this._send(false /* internal */, channel, args);
try {
return this._send(false /* internal */, channel, args);
} catch (e) {
Copy link
Contributor

@poiru poiru Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is an ideal fix. I don't think we want to swallow all exceptions like for example:

if (!gin::ConvertFromV8(isolate, args, &message)) {
isolate->ThrowException(v8::Exception::Error(
gin::StringToV8(isolate, "Failed to serialize arguments")));
return;
}

That should continue to throw. We only want to avoid the exception from:

bool WebFrameMain::CheckRenderFrame() const {
if (render_frame_disposed_) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::Locker locker(isolate);
v8::HandleScope scope(isolate);
gin_helper::ErrorThrower(isolate).ThrowError(
"Render frame was disposed before WebFrameMain could be accessed");
return false;
}
return true;
}

IMO we should instead avoid throwing in the first place in WebFrameMain::Send, WebFrameMain::PostMessage, and perhaps WebContents::MessageTo. We could do that by replacing the CheckRenderFrame() call with something that just checks the status instead of also throwing.

cc @VerteDinde

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @poiru! Just saw your comments here, will open a new PR with those improvements. We're in the middle of a December quiet period, so we may not have a new release with the fix until January, but will work on getting that fix ready.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you @VerteDinde!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VerteDinde Friendly reminder about this!

console.error('Error sending from webFrameMain: ', e);
}
};

WebFrameMain.prototype._sendInternal = function (channel, ...args) {
if (typeof channel !== 'string') {
throw new Error('Missing required channel argument');
}

return this._send(true /* internal */, channel, args);
try {
return this._send(true /* internal */, channel, args);
} catch (e) {
console.error('Error sending from webFrameMain: ', e);
}
};

WebFrameMain.prototype.postMessage = function (...args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The this._postMessage call below can also throw in the same way as the calls above. We should fix it too.

Expand Down
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_web_frame_main.cc
Expand Up @@ -100,7 +100,7 @@ void WebFrameMain::MarkRenderFrameDisposed() {

void WebFrameMain::UpdateRenderFrameHost(content::RenderFrameHost* rfh) {
// Should only be called when swapping frames.
DCHECK(render_frame_);
render_frame_disposed_ = false;
render_frame_ = rfh;
renderer_api_.reset();
}
Expand Down