From 683917ae67109a855c4e7fae4dbd418c4415ea91 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 1 Jun 2015 12:58:20 +0530 Subject: [PATCH] renderer: option to override page visiblity state --- atom/browser/native_window.cc | 1 + atom/common/options_switches.cc | 3 +++ atom/common/options_switches.h | 1 + atom/renderer/atom_renderer_client.cc | 15 +++++++++++++++ atom/renderer/atom_renderer_client.h | 3 +++ docs/api/browser-window.md | 2 ++ 6 files changed, 25 insertions(+) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 3698d8b94594..c2326debc99b 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -78,6 +78,7 @@ const char* kWebRuntimeFeatures[] = { switches::kOverlayScrollbars, switches::kOverlayFullscreenVideo, switches::kSharedWorker, + switches::kPageVisibility, }; std::string RemoveWhitespace(const std::string& str) { diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 7f642ecbbabd..c9997996fed8 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -95,6 +95,9 @@ const char kOverlayScrollbars[] = "overlay-scrollbars"; const char kOverlayFullscreenVideo[] = "overlay-fullscreen-video"; const char kSharedWorker[] = "shared-worker"; +// Set page visiblity to always visible. +const char kPageVisibility[] = "page-visibility"; + // Disable HTTP cache. const char kDisableHttpCache[] = "disable-http-cache"; diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index aaaa86addb15..071459afac73 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -52,6 +52,7 @@ extern const char kSubpixelFontScaling[]; extern const char kOverlayScrollbars[]; extern const char kOverlayFullscreenVideo[]; extern const char kSharedWorker[]; +extern const char kPageVisibility[]; extern const char kDisableHttpCache[]; diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 1dc4e45b03d7..e2a114af0141 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -191,6 +191,21 @@ content::BrowserPluginDelegate* AtomRendererClient::CreateBrowserPluginDelegate( } } +bool AtomRendererClient::ShouldOverridePageVisibilityState( + const content::RenderFrame* render_frame, + blink::WebPageVisibilityState* override_state) { + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + bool b; + + if (IsSwitchEnabled(command_line, switches::kPageVisibility, &b) + && b) { + *override_state = blink::WebPageVisibilityStateVisible; + return true; + } + + return false; +} + void AtomRendererClient::EnableWebRuntimeFeatures() { base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); bool b; diff --git a/atom/renderer/atom_renderer_client.h b/atom/renderer/atom_renderer_client.h index af264d59792d..68201f3cd435 100644 --- a/atom/renderer/atom_renderer_client.h +++ b/atom/renderer/atom_renderer_client.h @@ -55,6 +55,9 @@ class AtomRendererClient : public content::ContentRendererClient, content::RenderFrame* render_frame, const std::string& mime_type, const GURL& original_url) override; + bool ShouldOverridePageVisibilityState( + const content::RenderFrame* render_frame, + blink::WebPageVisibilityState* override_state) override; void EnableWebRuntimeFeatures(); diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 30055dccb0af..c97bec0ebbb1 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -97,6 +97,8 @@ You can also create a window without chrome by using * `shared-worker` Boolean * `direct-write` Boolean - Whether the DirectWrite font rendering system on Windows is enabled + * `page-visibility` Boolean - Sets the page visibility state + to visible, prevents throttling of DOM timers. Creates a new `BrowserWindow` with native properties set by the `options`. Usually you only need to set the `width` and `height`, other properties will