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: crash when navigating from a page with webview that has inherited zoom level #24766

Merged
merged 1 commit into from Aug 3, 2020
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
5 changes: 5 additions & 0 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -1352,6 +1352,11 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
// we need to make sure the api::WebContents is also deleted.
// For #4, the WebContents will be destroyed by embedder.
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.
RemoveFromWeakMap();

Expand Down
4 changes: 4 additions & 0 deletions shell/browser/web_view_guest_delegate.cc
Expand Up @@ -58,6 +58,10 @@ void WebViewGuestDelegate::AttachToIframe(
api_web_contents_->Emit("did-attach");
}

void WebViewGuestDelegate::WillDestroy() {
ResetZoomController();
}

void WebViewGuestDelegate::DidDetach() {
ResetZoomController();
}
Expand Down
1 change: 1 addition & 0 deletions shell/browser/web_view_guest_delegate.h
Expand Up @@ -24,6 +24,7 @@ class WebViewGuestDelegate : public content::BrowserPluginGuestDelegate,
// Attach to the iframe.
void AttachToIframe(content::WebContents* embedder_web_contents,
int embedder_frame_id);
void WillDestroy();

protected:
// content::BrowserPluginGuestDelegate:
Expand Down
19 changes: 19 additions & 0 deletions spec-main/webview-spec.ts
Expand Up @@ -273,6 +273,25 @@ describe('<webview> tag', function () {
const [, zoomLevel] = await emittedOnce(ipcMain, 'webview-origin-zoom-level')
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', () => {
Expand Down
12 changes: 12 additions & 0 deletions spec/fixtures/pages/webview-zoom-inherited.html
@@ -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>