Merge pull request #9741 from electron/webview-visibility-state
Send window visibility to webview after DOM ready
This commit is contained in:
commit
5b0290bf88
2 changed files with 48 additions and 13 deletions
|
@ -143,6 +143,15 @@ const createGuest = function (embedder, params) {
|
||||||
sendToEmbedder('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED', ...args)
|
sendToEmbedder('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED', ...args)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Notify guest of embedder window visibility when it is ready
|
||||||
|
// FIXME Remove once https://github.com/electron/electron/issues/6828 is fixed
|
||||||
|
guest.on('dom-ready', function () {
|
||||||
|
const guestInstance = guestInstances[guestInstanceId]
|
||||||
|
if (guestInstance != null && guestInstance.visibilityState != null) {
|
||||||
|
guest.send('ELECTRON_GUEST_INSTANCE_VISIBILITY_CHANGE', guestInstance.visibilityState)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Forward internal web contents event to embedder to handle
|
// Forward internal web contents event to embedder to handle
|
||||||
// native window.open setup
|
// native window.open setup
|
||||||
guest.on('-add-new-contents', (...args) => {
|
guest.on('-add-new-contents', (...args) => {
|
||||||
|
@ -280,6 +289,7 @@ const watchEmbedder = function (embedder) {
|
||||||
const onVisibilityChange = function (visibilityState) {
|
const onVisibilityChange = function (visibilityState) {
|
||||||
for (const guestInstanceId of Object.keys(guestInstances)) {
|
for (const guestInstanceId of Object.keys(guestInstances)) {
|
||||||
const guestInstance = guestInstances[guestInstanceId]
|
const guestInstance = guestInstances[guestInstanceId]
|
||||||
|
guestInstance.visibilityState = visibilityState
|
||||||
if (guestInstance.embedder === embedder) {
|
if (guestInstance.embedder === embedder) {
|
||||||
guestInstance.guest.send('ELECTRON_GUEST_INSTANCE_VISIBILITY_CHANGE', visibilityState)
|
guestInstance.guest.send('ELECTRON_GUEST_INSTANCE_VISIBILITY_CHANGE', visibilityState)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1097,25 +1097,50 @@ describe('<webview> tag', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('inherits the parent window visibility state and receives visibilitychange events', function (done) {
|
describe('document.visibilityState/hidden', function () {
|
||||||
w = new BrowserWindow({
|
afterEach(function () {
|
||||||
show: false
|
ipcMain.removeAllListeners('pong')
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.once('pong', function (event, visibilityState, hidden) {
|
it('updates when the window is shown after the ready-to-show event', function (done) {
|
||||||
assert.equal(visibilityState, 'hidden')
|
w = new BrowserWindow({
|
||||||
assert.equal(hidden, true)
|
show: false
|
||||||
|
|
||||||
ipcMain.once('pong', function (event, visibilityState, hidden) {
|
|
||||||
assert.equal(visibilityState, 'visible')
|
|
||||||
assert.equal(hidden, false)
|
|
||||||
done()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
w.webContents.emit('-window-visibility-change', 'visible')
|
w.once('ready-to-show', function () {
|
||||||
|
w.show()
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('pong', function (event, visibilityState, hidden) {
|
||||||
|
if (!hidden) {
|
||||||
|
assert.equal(visibilityState, 'visible')
|
||||||
|
done()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
w.loadURL('file://' + fixtures + '/pages/webview-visibilitychange.html')
|
||||||
})
|
})
|
||||||
|
|
||||||
w.loadURL('file://' + fixtures + '/pages/webview-visibilitychange.html')
|
it('inherits the parent window visibility state and receives visibilitychange events', function (done) {
|
||||||
|
w = new BrowserWindow({
|
||||||
|
show: false
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.once('pong', function (event, visibilityState, hidden) {
|
||||||
|
assert.equal(visibilityState, 'hidden')
|
||||||
|
assert.equal(hidden, true)
|
||||||
|
|
||||||
|
ipcMain.once('pong', function (event, visibilityState, hidden) {
|
||||||
|
assert.equal(visibilityState, 'visible')
|
||||||
|
assert.equal(hidden, false)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
w.webContents.emit('-window-visibility-change', 'visible')
|
||||||
|
})
|
||||||
|
|
||||||
|
w.loadURL('file://' + fixtures + '/pages/webview-visibilitychange.html')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('will-attach-webview event', () => {
|
describe('will-attach-webview event', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue