Support document visiblity state and events in webviews
This commit is contained in:
parent
1e15ce6ccd
commit
73b07f76a3
6 changed files with 25 additions and 4 deletions
|
@ -160,7 +160,14 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
|
|||
if (window) {
|
||||
bool visible = window->IsVisible() && !window->IsMinimized();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,9 @@ const char kExperimentalCanvasFeatures[] = "experimentalCanvasFeatures";
|
|||
// Opener window's ID.
|
||||
const char kOpenerID[] = "openerId";
|
||||
|
||||
// Page is hidden.
|
||||
const char kHiddenPage[] = "hiddenPage";
|
||||
|
||||
// Enable the rubber banding effect.
|
||||
const char kScrollBounce[] = "scrollBounce";
|
||||
|
||||
|
@ -146,6 +149,7 @@ const char kPreloadURL[] = "preload-url";
|
|||
const char kNodeIntegration[] = "node-integration";
|
||||
const char kGuestInstanceID[] = "guest-instance-id";
|
||||
const char kOpenerID[] = "opener-id";
|
||||
const char kHiddenPage[] = "hidden-page";
|
||||
const char kScrollBounce[] = "scroll-bounce";
|
||||
|
||||
// Widevine options
|
||||
|
|
|
@ -56,6 +56,7 @@ extern const char kGuestInstanceID[];
|
|||
extern const char kExperimentalFeatures[];
|
||||
extern const char kExperimentalCanvasFeatures[];
|
||||
extern const char kOpenerID[];
|
||||
extern const char kHiddenPage[];
|
||||
extern const char kScrollBounce[];
|
||||
extern const char kBlinkFeatures[];
|
||||
|
||||
|
@ -82,6 +83,7 @@ extern const char kPreloadURL[];
|
|||
extern const char kNodeIntegration[];
|
||||
extern const char kGuestInstanceID[];
|
||||
extern const char kOpenerID[];
|
||||
extern const char kHiddenPage[];
|
||||
extern const char kScrollBounce[];
|
||||
|
||||
extern const char kWidevineCdmPath[];
|
||||
|
|
|
@ -181,7 +181,8 @@ var attachGuest = function (embedder, elementInstanceId, guestInstanceId, params
|
|||
plugins: params.plugins,
|
||||
zoomFactor: params.zoomFactor,
|
||||
webSecurity: !params.disablewebsecurity,
|
||||
blinkFeatures: params.blinkfeatures
|
||||
blinkFeatures: params.blinkfeatures,
|
||||
hiddenPage: params.hiddenPage
|
||||
}
|
||||
|
||||
if (params.preload) {
|
||||
|
|
|
@ -42,6 +42,11 @@ var WebViewImpl = (function () {
|
|||
this.webviewNode.setZoomLevel(zoomLevel)
|
||||
}
|
||||
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 () {
|
||||
|
@ -56,6 +61,7 @@ var WebViewImpl = (function () {
|
|||
WebViewImpl.prototype.reset = function () {
|
||||
// Unlisten the zoom-level-changed event.
|
||||
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
|
||||
// already picked up a partition ID. Thus, we need to reset the initialization
|
||||
|
@ -224,7 +230,8 @@ var WebViewImpl = (function () {
|
|||
params = {
|
||||
instanceId: this.viewInstanceId,
|
||||
userAgentOverride: this.userAgentOverride,
|
||||
zoomFactor: webFrame.getZoomFactor()
|
||||
zoomFactor: webFrame.getZoomFactor(),
|
||||
hiddenPage: document.hidden
|
||||
}
|
||||
ref1 = this.attributes
|
||||
for (attributeName in ref1) {
|
||||
|
|
|
@ -868,7 +868,7 @@ describe('<webview> tag', function () {
|
|||
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({
|
||||
show: false
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue