Support document visiblity state and events in webviews

This commit is contained in:
Kevin Sawicki 2016-05-24 12:44:09 -07:00
parent 1e15ce6ccd
commit 73b07f76a3
6 changed files with 25 additions and 4 deletions

View file

@ -160,7 +160,14 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
if (window) { if (window) {
bool visible = window->IsVisible() && !window->IsMinimized(); bool visible = window->IsVisible() && !window->IsMinimized();
if (!visible) // Default state is visible. if (!visible) // Default state is visible.
command_line->AppendSwitch("hidden-page"); command_line->AppendSwitch(switches::kHiddenPage);
} else {
// Inherit initial visibilty state from parent window in webviews
bool hidden_page;
if (web_preferences.GetBoolean(options::kHiddenPage, &hidden_page) &&
hidden_page) {
command_line->AppendSwitch(switches::kHiddenPage);
}
} }
} }

View file

@ -103,6 +103,9 @@ const char kExperimentalCanvasFeatures[] = "experimentalCanvasFeatures";
// Opener window's ID. // Opener window's ID.
const char kOpenerID[] = "openerId"; const char kOpenerID[] = "openerId";
// Page is hidden.
const char kHiddenPage[] = "hiddenPage";
// Enable the rubber banding effect. // Enable the rubber banding effect.
const char kScrollBounce[] = "scrollBounce"; const char kScrollBounce[] = "scrollBounce";
@ -146,6 +149,7 @@ const char kPreloadURL[] = "preload-url";
const char kNodeIntegration[] = "node-integration"; const char kNodeIntegration[] = "node-integration";
const char kGuestInstanceID[] = "guest-instance-id"; const char kGuestInstanceID[] = "guest-instance-id";
const char kOpenerID[] = "opener-id"; const char kOpenerID[] = "opener-id";
const char kHiddenPage[] = "hidden-page";
const char kScrollBounce[] = "scroll-bounce"; const char kScrollBounce[] = "scroll-bounce";
// Widevine options // Widevine options

View file

@ -56,6 +56,7 @@ extern const char kGuestInstanceID[];
extern const char kExperimentalFeatures[]; extern const char kExperimentalFeatures[];
extern const char kExperimentalCanvasFeatures[]; extern const char kExperimentalCanvasFeatures[];
extern const char kOpenerID[]; extern const char kOpenerID[];
extern const char kHiddenPage[];
extern const char kScrollBounce[]; extern const char kScrollBounce[];
extern const char kBlinkFeatures[]; extern const char kBlinkFeatures[];
@ -82,6 +83,7 @@ extern const char kPreloadURL[];
extern const char kNodeIntegration[]; extern const char kNodeIntegration[];
extern const char kGuestInstanceID[]; extern const char kGuestInstanceID[];
extern const char kOpenerID[]; extern const char kOpenerID[];
extern const char kHiddenPage[];
extern const char kScrollBounce[]; extern const char kScrollBounce[];
extern const char kWidevineCdmPath[]; extern const char kWidevineCdmPath[];

View file

@ -181,7 +181,8 @@ var attachGuest = function (embedder, elementInstanceId, guestInstanceId, params
plugins: params.plugins, plugins: params.plugins,
zoomFactor: params.zoomFactor, zoomFactor: params.zoomFactor,
webSecurity: !params.disablewebsecurity, webSecurity: !params.disablewebsecurity,
blinkFeatures: params.blinkfeatures blinkFeatures: params.blinkfeatures,
hiddenPage: params.hiddenPage
} }
if (params.preload) { if (params.preload) {

View file

@ -42,6 +42,11 @@ var WebViewImpl = (function () {
this.webviewNode.setZoomLevel(zoomLevel) this.webviewNode.setZoomLevel(zoomLevel)
} }
webFrame.on('zoom-level-changed', this.onZoomLevelChanged) webFrame.on('zoom-level-changed', this.onZoomLevelChanged)
this.onVisibilityChanged = (event, visibilityState) => {
this.webviewNode.send('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', visibilityState)
}
ipcRenderer.on('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', this.onVisibilityChanged)
} }
WebViewImpl.prototype.createBrowserPluginNode = function () { WebViewImpl.prototype.createBrowserPluginNode = function () {
@ -56,6 +61,7 @@ var WebViewImpl = (function () {
WebViewImpl.prototype.reset = function () { WebViewImpl.prototype.reset = function () {
// Unlisten the zoom-level-changed event. // Unlisten the zoom-level-changed event.
webFrame.removeListener('zoom-level-changed', this.onZoomLevelChanged) webFrame.removeListener('zoom-level-changed', this.onZoomLevelChanged)
ipcRenderer.removeListener('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', this.onVisibilityChanged)
// If guestInstanceId is defined then the <webview> has navigated and has // If guestInstanceId is defined then the <webview> has navigated and has
// already picked up a partition ID. Thus, we need to reset the initialization // already picked up a partition ID. Thus, we need to reset the initialization
@ -224,7 +230,8 @@ var WebViewImpl = (function () {
params = { params = {
instanceId: this.viewInstanceId, instanceId: this.viewInstanceId,
userAgentOverride: this.userAgentOverride, userAgentOverride: this.userAgentOverride,
zoomFactor: webFrame.getZoomFactor() zoomFactor: webFrame.getZoomFactor(),
hiddenPage: document.hidden
} }
ref1 = this.attributes ref1 = this.attributes
for (attributeName in ref1) { for (attributeName in ref1) {

View file

@ -868,7 +868,7 @@ describe('<webview> tag', function () {
w.loadURL('file://' + fixtures + '/pages/webview-zoom-factor.html') w.loadURL('file://' + fixtures + '/pages/webview-zoom-factor.html')
}) })
it('has the initial hidden state and receives visibilitychange events', function (done) { it('inherits the parent window hidden state and receives visibilitychange events', function (done) {
w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false
}) })