From 15dffb3ddeb6ad5c99d2d53df304d1776a791b52 Mon Sep 17 00:00:00 2001 From: loc Date: Tue, 5 Nov 2019 16:34:45 -0500 Subject: [PATCH] fix: allow iframe-initiated HTML fullscreen to exit while in macOS fullscreen (#20962) * fix: explicitly resize the contents when exiting html fullscreen while in OS fullscreen * test: ensure HTML fullscreen toggles while in OS fullscreen --- shell/browser/common_web_contents_delegate.cc | 7 ++ spec-main/chromium-spec.ts | 78 +++++++++++++++++++ spec/fixtures/pages/fullscreen-ipif.html | 15 ++++ spec/fixtures/pages/fullscreen-oopif.html | 19 +++++ 4 files changed, 119 insertions(+) create mode 100644 spec/fixtures/pages/fullscreen-ipif.html create mode 100644 spec/fixtures/pages/fullscreen-oopif.html diff --git a/shell/browser/common_web_contents_delegate.cc b/shell/browser/common_web_contents_delegate.cc index 7e80b689be..744de040a8 100644 --- a/shell/browser/common_web_contents_delegate.cc +++ b/shell/browser/common_web_contents_delegate.cc @@ -355,6 +355,13 @@ void CommonWebContentsDelegate::ExitFullscreenModeForTab( return; SetHtmlApiFullscreen(false); owner_window_->NotifyWindowLeaveHtmlFullScreen(); + + if (native_fullscreen_) { + // Explicitly trigger a view resize, as the size is not actually changing if + // the browser is fullscreened, too. Chrome does this indirectly from + // `chrome/browser/ui/exclusive_access/fullscreen_controller.cc`. + source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties(); + } } bool CommonWebContentsDelegate::IsFullscreenForTabOrPending( diff --git a/spec-main/chromium-spec.ts b/spec-main/chromium-spec.ts index 44ce99e3f8..999927271b 100644 --- a/spec-main/chromium-spec.ts +++ b/spec-main/chromium-spec.ts @@ -1066,3 +1066,81 @@ describe('font fallback', () => { if (process.platform === 'win32') { expect(fonts[0].familyName).to.be.oneOf(['Meiryo', 'Yu Gothic']) } else if (process.platform === 'darwin') { expect(fonts[0].familyName).to.equal('Hiragino Kaku Gothic ProN') } }) }) + +describe('iframe using HTML fullscreen API while window is OS-fullscreened', () => { + const fullscreenChildHtml = promisify(fs.readFile)( + path.join(fixturesPath, 'pages', 'fullscreen-oopif.html') + ) + let w: BrowserWindow, server: http.Server + + before(() => { + server = http.createServer(async (_req, res) => { + res.writeHead(200, { 'Content-Type': 'text/html' }) + res.write(await fullscreenChildHtml) + res.end() + }) + + server.listen(8989, '127.0.0.1') + }) + + beforeEach(() => { + w = new BrowserWindow({ + show: true, + fullscreen: true, + webPreferences: { + nodeIntegration: true, + nodeIntegrationInSubFrames: true + } + }) + }) + + afterEach(async () => { + await closeAllWindows() + ;(w as any) = null + server.close() + }) + + it('can fullscreen from out-of-process iframes (OOPIFs)', done => { + ipcMain.once('fullscreenChange', async () => { + const fullscreenWidth = await w.webContents.executeJavaScript( + "document.querySelector('iframe').offsetWidth" + ) + expect(fullscreenWidth > 0).to.be.true() + + await w.webContents.executeJavaScript( + "document.querySelector('iframe').contentWindow.postMessage('exitFullscreen', '*')" + ) + + await new Promise(resolve => setTimeout(resolve, 500)) + + const width = await w.webContents.executeJavaScript( + "document.querySelector('iframe').offsetWidth" + ) + expect(width).to.equal(0) + + done() + }) + + const html = + '' + w.loadURL(`data:text/html,${html}`) + }) + + it('can fullscreen from in-process iframes', done => { + ipcMain.once('fullscreenChange', async () => { + const fullscreenWidth = await w.webContents.executeJavaScript( + "document.querySelector('iframe').offsetWidth" + ) + expect(fullscreenWidth > 0).to.true() + + await w.webContents.executeJavaScript('document.exitFullscreen()') + const width = await w.webContents.executeJavaScript( + "document.querySelector('iframe').offsetWidth" + ) + expect(width).to.equal(0) + done() + }) + + w.loadFile(path.join(fixturesPath, 'pages', 'fullscreen-ipif.html')) + }) +}) diff --git a/spec/fixtures/pages/fullscreen-ipif.html b/spec/fixtures/pages/fullscreen-ipif.html new file mode 100644 index 0000000000..dfca5396e1 --- /dev/null +++ b/spec/fixtures/pages/fullscreen-ipif.html @@ -0,0 +1,15 @@ + + + + diff --git a/spec/fixtures/pages/fullscreen-oopif.html b/spec/fixtures/pages/fullscreen-oopif.html new file mode 100644 index 0000000000..db9a24d77f --- /dev/null +++ b/spec/fixtures/pages/fullscreen-oopif.html @@ -0,0 +1,19 @@ + +