]> khamidou — GitHub mirrors - electron.git/commitdiff
browser: hide webcontents when window not shown
authorRobo <hop2deep@gmail.com>
Tue, 22 Sep 2015 16:51:49 +0000 (22:21 +0530)
committerRobo <hop2deep@gmail.com>
Thu, 24 Sep 2015 05:00:18 +0000 (10:30 +0530)
atom/browser/native_window.cc
spec/chromium-spec.coffee
spec/fixtures/pages/document-hidden.html [new file with mode: 0644]

index 4d5f273340abcd730766f244a80635b01ddf98e5..e06633d7b7ca0afd1473d824deb5ebc048069320 100644 (file)
@@ -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) {
index 4dd39aff5fdb10ea6a875af7fbf0c170f3ea2d29..a782079026a7df9d78fee6ab25cdb48c83ff0a16 100644 (file)
@@ -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 (file)
index 0000000..17920bf
--- /dev/null
@@ -0,0 +1,7 @@
+<html>
+<body>
+<script type="text/javascript" charset="utf-8">
+  require('ipc').send('hidden', document.hidden);
+</script>
+</body>
+</html>