From: Robo Date: Tue, 22 Sep 2015 16:51:49 +0000 (+0530) Subject: browser: hide webcontents when window not shown X-Git-Tag: v0.33.2~9^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=5ca5c4fb92ab2ba75308d91796e0113869148d8a;p=electron.git browser: hide webcontents when window not shown --- diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 4d5f2733..e06633d7 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -159,8 +159,13 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) { // Then show it. bool show = true; options.Get(switches::kShow, &show); - if (show) + if (show) { Show(); + } else { + // When RenderView is created it sets to visible, this is to prevent + // breaking the visibility API. + web_contents()->WasHidden(); + } } void NativeWindow::SetSize(const gfx::Size& size) { diff --git a/spec/chromium-spec.coffee b/spec/chromium-spec.coffee index 4dd39aff..a7820790 100644 --- a/spec/chromium-spec.coffee +++ b/spec/chromium-spec.coffee @@ -23,6 +23,23 @@ describe 'chromium feature', -> {port} = server.address() $.get "http://127.0.0.1:#{port}" + describe 'document.hidden', -> + BrowserWindow = remote.require 'browser-window' + ipc = remote.require 'ipc' + url = "file://#{fixtures}/pages/document-hidden.html" + w = null + + afterEach -> + w?.destroy() + ipc.removeAllListeners 'hidden' + + it 'is set correctly when window is not shown', (done) -> + ipc.once 'hidden', (event, hidden) -> + assert hidden + done() + w = new BrowserWindow(show:false) + w.loadUrl url + describe 'navigator.webkitGetUserMedia', -> it 'calls its callbacks', (done) -> @timeout 5000 diff --git a/spec/fixtures/pages/document-hidden.html b/spec/fixtures/pages/document-hidden.html new file mode 100644 index 00000000..17920bff --- /dev/null +++ b/spec/fixtures/pages/document-hidden.html @@ -0,0 +1,7 @@ + + + + +