fix: register webview in main world when using contextIsolation (#16067)

This commit is contained in:
Cheng Zhao 2018-12-14 15:38:35 +09:00 committed by GitHub
parent dbda1a1b05
commit 8584c2f14b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 56 additions and 20 deletions

View file

@ -198,8 +198,8 @@ class WebViewImpl {
}
// Registers <webview> custom element.
const registerWebViewElement = function () {
const proto = Object.create(HTMLObjectElement.prototype)
const registerWebViewElement = (window) => {
const proto = Object.create(window.HTMLObjectElement.prototype)
proto.createdCallback = function () {
return new WebViewImpl(this)
}
@ -288,7 +288,7 @@ const registerWebViewElement = function () {
this.contentWindow.focus()
}
window.WebView = webFrame.registerEmbedderCustomElement('webview', {
window.WebView = webFrame.registerEmbedderCustomElement(window, 'webview', {
prototype: proto
})
@ -300,16 +300,17 @@ const registerWebViewElement = function () {
delete proto.attributeChangedCallback
}
const useCapture = true
const setupWebView = (window) => {
require('@electron/internal/renderer/web-view/web-view-attributes')
const listener = function (event) {
if (document.readyState === 'loading') {
return
}
registerWebViewElement()
window.removeEventListener(event.type, listener, useCapture)
const useCapture = true
window.addEventListener('readystatechange', function listener (event) {
if (document.readyState === 'loading') {
return
}
registerWebViewElement(window)
window.removeEventListener(event.type, listener, useCapture)
}, useCapture)
}
window.addEventListener('readystatechange', listener, true)
module.exports = WebViewImpl
module.exports = { setupWebView, WebViewImpl }