fix: crash when navigating from a page with webview that has inherited zoom level (#24757)
* fix: cleanup webview zoom level observers on navigation * add spec * webview should be on same partition * wait for webview to finish loading
This commit is contained in:
parent
38fafe4986
commit
b6321cc22d
5 changed files with 41 additions and 0 deletions
|
@ -1413,6 +1413,11 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
||||||
// we need to make sure the api::WebContents is also deleted.
|
// we need to make sure the api::WebContents is also deleted.
|
||||||
// For #4, the WebContents will be destroyed by embedder.
|
// For #4, the WebContents will be destroyed by embedder.
|
||||||
void WebContents::WebContentsDestroyed() {
|
void WebContents::WebContentsDestroyed() {
|
||||||
|
// Give chance for guest delegate to cleanup its observers
|
||||||
|
// since the native class is only destroyed in the next tick.
|
||||||
|
if (guest_delegate_)
|
||||||
|
guest_delegate_->WillDestroy();
|
||||||
|
|
||||||
// Cleanup relationships with other parts.
|
// Cleanup relationships with other parts.
|
||||||
RemoveFromWeakMap();
|
RemoveFromWeakMap();
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,10 @@ void WebViewGuestDelegate::AttachToIframe(
|
||||||
api_web_contents_->Emit("did-attach");
|
api_web_contents_->Emit("did-attach");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebViewGuestDelegate::WillDestroy() {
|
||||||
|
ResetZoomController();
|
||||||
|
}
|
||||||
|
|
||||||
void WebViewGuestDelegate::DidDetach() {
|
void WebViewGuestDelegate::DidDetach() {
|
||||||
ResetZoomController();
|
ResetZoomController();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
|
||||||
// Attach to the iframe.
|
// Attach to the iframe.
|
||||||
void AttachToIframe(content::WebContents* embedder_web_contents,
|
void AttachToIframe(content::WebContents* embedder_web_contents,
|
||||||
int embedder_frame_id);
|
int embedder_frame_id);
|
||||||
|
void WillDestroy();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// content::BrowserPluginGuestDelegate:
|
// content::BrowserPluginGuestDelegate:
|
||||||
|
|
|
@ -315,6 +315,25 @@ describe('<webview> tag', function () {
|
||||||
const [, zoomLevel] = await emittedOnce(ipcMain, 'webview-origin-zoom-level');
|
const [, zoomLevel] = await emittedOnce(ipcMain, 'webview-origin-zoom-level');
|
||||||
expect(zoomLevel).to.equal(2.0);
|
expect(zoomLevel).to.equal(2.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not crash when navigating with zoom level inherited from parent', async () => {
|
||||||
|
const w = new BrowserWindow({
|
||||||
|
show: false,
|
||||||
|
webPreferences: {
|
||||||
|
webviewTag: true,
|
||||||
|
nodeIntegration: true,
|
||||||
|
zoomFactor: 1.2,
|
||||||
|
session: webviewSession
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const attachPromise = emittedOnce(w.webContents, 'did-attach-webview');
|
||||||
|
const readyPromise = emittedOnce(ipcMain, 'dom-ready');
|
||||||
|
w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-inherited.html'));
|
||||||
|
const [, webview] = await attachPromise;
|
||||||
|
await readyPromise;
|
||||||
|
expect(webview.getZoomFactor()).to.equal(1.2);
|
||||||
|
await w.loadURL(`${zoomScheme}://host1`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('nativeWindowOpen option', () => {
|
describe('nativeWindowOpen option', () => {
|
||||||
|
|
12
spec/fixtures/pages/webview-zoom-inherited.html
vendored
Normal file
12
spec/fixtures/pages/webview-zoom-inherited.html
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<webview src="./a.html" id="view" partition="webview-temp"/>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
const {ipcRenderer} = require('electron')
|
||||||
|
const view = document.getElementById('view')
|
||||||
|
view.addEventListener('dom-ready', () => {
|
||||||
|
ipcRenderer.send('dom-ready')
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</html>
|
Loading…
Reference in a new issue