2019-01-22 01:08:16 +00:00
|
|
|
'use strict'
|
|
|
|
|
2019-02-15 01:24:25 +00:00
|
|
|
const { ipcRendererInternal } = require('@electron/internal/renderer/ipc-renderer-internal')
|
2019-01-22 01:08:16 +00:00
|
|
|
const v8Util = process.atomBinding('v8_util')
|
|
|
|
|
|
|
|
function handleFocusBlur (guestInstanceId) {
|
|
|
|
// Note that while Chromium content APIs have observer for focus/blur, they
|
|
|
|
// unfortunately do not work for webview.
|
|
|
|
|
|
|
|
window.addEventListener('focus', () => {
|
2019-02-15 01:24:25 +00:00
|
|
|
ipcRendererInternal.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', true, guestInstanceId)
|
2019-01-22 01:08:16 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
window.addEventListener('blur', () => {
|
2019-02-15 01:24:25 +00:00
|
|
|
ipcRendererInternal.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', false, guestInstanceId)
|
2019-01-22 01:08:16 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function (contextIsolation, webviewTag, guestInstanceId) {
|
2019-01-24 18:53:16 +00:00
|
|
|
// Don't allow recursive `<webview>`.
|
2019-01-22 01:08:16 +00:00
|
|
|
if (webviewTag && guestInstanceId == null) {
|
|
|
|
const webViewImpl = require('@electron/internal/renderer/web-view/web-view-impl')
|
|
|
|
if (contextIsolation) {
|
|
|
|
v8Util.setHiddenValue(window, 'web-view-impl', webViewImpl)
|
|
|
|
} else {
|
|
|
|
const { setupWebView } = require('@electron/internal/renderer/web-view/web-view-element')
|
|
|
|
setupWebView(v8Util, webViewImpl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (guestInstanceId) {
|
|
|
|
// Report focus/blur events of webview to browser.
|
|
|
|
handleFocusBlur(guestInstanceId)
|
|
|
|
}
|
|
|
|
}
|