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: correctly notify WebViewGuestDelegate when webview is detached #31374

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
6 changes: 4 additions & 2 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -928,8 +928,6 @@ WebContents::~WebContents() {
}

inspectable_web_contents_->GetView()->SetDelegate(nullptr);
if (guest_delegate_)
guest_delegate_->WillDestroy();

// This event is only for internal use, which is emitted when WebContents is
// being destroyed.
Expand Down Expand Up @@ -1937,6 +1935,10 @@ void WebContents::WebContentsDestroyed() {
return;
wrapper->SetAlignedPointerInInternalField(0, nullptr);

// Tell WebViewGuestDelegate that the WebContents has been destroyed.
if (guest_delegate_)
guest_delegate_->WillDestroy();

Observe(nullptr);
Emit("destroyed");
}
Expand Down
17 changes: 17 additions & 0 deletions spec-main/webview-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,23 @@ describe('<webview> tag', function () {
expect(webview.getZoomFactor()).to.equal(1.2);
await w.loadURL(`${zoomScheme}://host1`);
});

it('does not crash when changing zoom level after webview is destroyed', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
webviewTag: true,
nodeIntegration: true,
session: webviewSession,
contextIsolation: false
}
});
const attachPromise = emittedOnce(w.webContents, 'did-attach-webview');
await w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-inherited.html'));
await attachPromise;
await w.webContents.executeJavaScript('view.remove()');
w.webContents.setZoomLevel(0.5);
});
});

describe('requestFullscreen from webview', () => {
Expand Down