fix: use OOPIF for webview tag (#13869)
* fix: use OOIF for webview tag * fix: do not call GetNativeView for webview * fix: OOIPF webview's WebContents is managed by embedder frame * fix: guest view can not be focused * fix: clear zoom controller when guest is destroyed * fix: implement the webview resize event The webview is no longer a browser plugin with the resize event, use ResizeObserver instead. * test: disable failed tests due to OOPIF webview * fix: embedder can be destroyed earlier than guest This happens when embedder is manually destroyed. * fix: don't double attach * fix: recreate iframe when webview is reattached * fix: resize event may happen very early * test: some tests are working after OOPIF webview * chore: remove unused browser plugin webview code * fix: get embedder via closure When the "destroyed" event is emitted, the entry in guestInstances would be cleared. * chore: rename browserPluginNode to internalElement * test: make the visibilityState test more robust * chore: guestinstance can not work with OOPIF webview * fix: element could be detached before got response from browser
This commit is contained in:
parent
48407c5b93
commit
dd5b8769be
28 changed files with 268 additions and 1008 deletions
|
@ -1,7 +1,6 @@
|
|||
'use strict'
|
||||
|
||||
const WebViewImpl = require('./web-view')
|
||||
const guestViewInternal = require('./guest-view-internal')
|
||||
const webViewConstants = require('./web-view-constants')
|
||||
const {remote} = require('electron')
|
||||
|
||||
|
@ -74,39 +73,6 @@ class BooleanAttribute extends WebViewAttribute {
|
|||
}
|
||||
}
|
||||
|
||||
// Attribute used to define the demension limits of autosizing.
|
||||
class AutosizeDimensionAttribute extends WebViewAttribute {
|
||||
getValue () {
|
||||
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name)) || 0
|
||||
}
|
||||
|
||||
handleMutation () {
|
||||
if (!this.webViewImpl.guestInstanceId) {
|
||||
return
|
||||
}
|
||||
guestViewInternal.setSize(this.webViewImpl.guestInstanceId, {
|
||||
enableAutoSize: this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue(),
|
||||
min: {
|
||||
width: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MINWIDTH].getValue() || 0),
|
||||
height: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MINHEIGHT].getValue() || 0)
|
||||
},
|
||||
max: {
|
||||
width: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() || 0),
|
||||
height: parseInt(this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() || 0)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Attribute that specifies whether the webview should be autosized.
|
||||
class AutosizeAttribute extends BooleanAttribute {
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_AUTOSIZE, webViewImpl)
|
||||
}
|
||||
}
|
||||
|
||||
AutosizeAttribute.prototype.handleMutation = AutosizeDimensionAttribute.prototype.handleMutation
|
||||
|
||||
// Attribute representing the state of the storage partition.
|
||||
class PartitionAttribute extends WebViewAttribute {
|
||||
constructor (webViewImpl) {
|
||||
|
@ -130,43 +96,6 @@ class PartitionAttribute extends WebViewAttribute {
|
|||
}
|
||||
}
|
||||
|
||||
// An attribute that controls the guest instance this webview is connected to
|
||||
class GuestInstanceAttribute extends WebViewAttribute {
|
||||
constructor (webViewImpl) {
|
||||
super(webViewConstants.ATTRIBUTE_GUESTINSTANCE, webViewImpl)
|
||||
}
|
||||
|
||||
// Retrieves and returns the attribute's value.
|
||||
getValue () {
|
||||
if (this.webViewImpl.webviewNode.hasAttribute(this.name)) {
|
||||
return parseInt(this.webViewImpl.webviewNode.getAttribute(this.name))
|
||||
}
|
||||
}
|
||||
|
||||
// Sets the attribute's value.
|
||||
setValue (value) {
|
||||
if (!value) {
|
||||
this.webViewImpl.webviewNode.removeAttribute(this.name)
|
||||
} else if (!isNaN(value)) {
|
||||
this.webViewImpl.webviewNode.setAttribute(this.name, value)
|
||||
}
|
||||
}
|
||||
|
||||
handleMutation (oldValue, newValue) {
|
||||
if (!newValue) {
|
||||
this.webViewImpl.reset()
|
||||
return
|
||||
}
|
||||
|
||||
const intVal = parseInt(newValue)
|
||||
if (!isNaN(newValue) && remote.getGuestWebContents(intVal)) {
|
||||
this.webViewImpl.attachGuestInstance(intVal)
|
||||
} else {
|
||||
this.setValueIgnoreMutation(oldValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attribute that handles the location and navigation of the webview.
|
||||
class SrcAttribute extends WebViewAttribute {
|
||||
constructor (webViewImpl) {
|
||||
|
@ -314,7 +243,6 @@ class WebPreferencesAttribute extends WebViewAttribute {
|
|||
// Sets up all of the webview attributes.
|
||||
WebViewImpl.prototype.setupWebViewAttributes = function () {
|
||||
this.attributes = {}
|
||||
this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE] = new AutosizeAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_PARTITION] = new PartitionAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_SRC] = new SrcAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER] = new HttpReferrerAttribute(this)
|
||||
|
@ -326,12 +254,5 @@ WebViewImpl.prototype.setupWebViewAttributes = function () {
|
|||
this.attributes[webViewConstants.ATTRIBUTE_PRELOAD] = new PreloadAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_BLINKFEATURES] = new BlinkFeaturesAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_DISABLEBLINKFEATURES] = new DisableBlinkFeaturesAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_GUESTINSTANCE] = new GuestInstanceAttribute(this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_DISABLEGUESTRESIZE] = new BooleanAttribute(webViewConstants.ATTRIBUTE_DISABLEGUESTRESIZE, this)
|
||||
this.attributes[webViewConstants.ATTRIBUTE_WEBPREFERENCES] = new WebPreferencesAttribute(this)
|
||||
|
||||
const autosizeAttributes = [webViewConstants.ATTRIBUTE_MAXHEIGHT, webViewConstants.ATTRIBUTE_MAXWIDTH, webViewConstants.ATTRIBUTE_MINHEIGHT, webViewConstants.ATTRIBUTE_MINWIDTH]
|
||||
autosizeAttributes.forEach((attribute) => {
|
||||
this.attributes[attribute] = new AutosizeDimensionAttribute(attribute, this)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue