chore: print error when removed webview attribute is used (#14230)

* chore: print error when removed webview attribute is used

* docs: document removed webview features
This commit is contained in:
Cheng Zhao 2018-08-23 10:45:43 +09:00 committed by GitHub
parent 82b75f863d
commit cd8bb1d3b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 48 additions and 76 deletions

View file

@ -16,6 +16,13 @@ const getNextId = function () {
return ++nextId
}
// A list of removed attributes from 3.0.
const removedAttributes = [
'autoresize',
'disableguestresize',
'guestinstance'
]
// Represents the internal state of the WebView node.
class WebViewImpl {
constructor (webviewNode) {
@ -24,8 +31,16 @@ class WebViewImpl {
this.elementAttached = false
this.beforeFirstNavigation = true
// Check for removed attributes.
for (const attributeName of removedAttributes) {
if (this.webviewNode.hasAttribute(attributeName)) {
this.reportRemovedAttribute(attributeName)
}
}
// on* Event handlers.
this.on = {}
this.internalElement = this.createInternalElement()
const shadowRoot = this.webviewNode.attachShadow({mode: 'open'})
shadowRoot.innerHTML = '<!DOCTYPE html><style type="text/css">:host { display: flex; }</style>'
@ -102,6 +117,11 @@ class WebViewImpl {
// attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
// details.
handleWebviewAttributeMutation (attributeName, oldValue, newValue) {
if (removedAttributes.includes(attributeName)) {
this.reportRemovedAttribute(attributeName)
return
}
if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) {
return
}
@ -197,6 +217,12 @@ class WebViewImpl {
// even documented.
this.resizeObserver = new ResizeObserver(this.onElementResize.bind(this)).observe(this.internalElement)
}
// TODO(zcbenz): Remove the warning in 4.0.
reportRemovedAttribute (attributeName) {
console.error(`The "${attributeName}" attribute has been removed from the <webview> tag,`,
'see https://github.com/electron/electron/issues/14120 for more.')
}
}
// Registers <webview> custom element.