Use ES6 style class for WebViewImpl
This commit is contained in:
parent
76f96bd99c
commit
6eab14359c
1 changed files with 18 additions and 20 deletions
|
@ -16,8 +16,8 @@ const getNextId = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Represents the internal state of the WebView node.
|
// Represents the internal state of the WebView node.
|
||||||
const WebViewImpl = (function () {
|
class WebViewImpl {
|
||||||
function WebViewImpl (webviewNode) {
|
constructor (webviewNode) {
|
||||||
this.webviewNode = webviewNode
|
this.webviewNode = webviewNode
|
||||||
v8Util.setHiddenValue(this.webviewNode, 'internal', this)
|
v8Util.setHiddenValue(this.webviewNode, 'internal', this)
|
||||||
this.attached = false
|
this.attached = false
|
||||||
|
@ -46,7 +46,7 @@ const WebViewImpl = (function () {
|
||||||
ipcRenderer.on('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', this.onVisibilityChanged)
|
ipcRenderer.on('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', this.onVisibilityChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.createBrowserPluginNode = function () {
|
createBrowserPluginNode () {
|
||||||
// We create BrowserPlugin as a custom element in order to observe changes
|
// We create BrowserPlugin as a custom element in order to observe changes
|
||||||
// to attributes synchronously.
|
// to attributes synchronously.
|
||||||
const browserPluginNode = new WebViewImpl.BrowserPlugin()
|
const browserPluginNode = new WebViewImpl.BrowserPlugin()
|
||||||
|
@ -55,7 +55,7 @@ const WebViewImpl = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resets some state upon reattaching <webview> element to the DOM.
|
// Resets some state upon reattaching <webview> element to the DOM.
|
||||||
WebViewImpl.prototype.reset = function () {
|
reset () {
|
||||||
// Unlisten the zoom-level-changed event.
|
// Unlisten the zoom-level-changed event.
|
||||||
webFrame.removeListener('zoom-level-changed', this.onZoomLevelChanged)
|
webFrame.removeListener('zoom-level-changed', this.onZoomLevelChanged)
|
||||||
ipcRenderer.removeListener('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', this.onVisibilityChanged)
|
ipcRenderer.removeListener('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', this.onVisibilityChanged)
|
||||||
|
@ -78,14 +78,14 @@ const WebViewImpl = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the <webview>.request property.
|
// Sets the <webview>.request property.
|
||||||
WebViewImpl.prototype.setRequestPropertyOnWebViewNode = function (request) {
|
setRequestPropertyOnWebViewNode (request) {
|
||||||
Object.defineProperty(this.webviewNode, 'request', {
|
Object.defineProperty(this.webviewNode, 'request', {
|
||||||
value: request,
|
value: request,
|
||||||
enumerable: true
|
enumerable: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.setupFocusPropagation = function () {
|
setupFocusPropagation () {
|
||||||
if (!this.webviewNode.hasAttribute('tabIndex')) {
|
if (!this.webviewNode.hasAttribute('tabIndex')) {
|
||||||
// <webview> needs a tabIndex in order to be focusable.
|
// <webview> needs a tabIndex in order to be focusable.
|
||||||
// TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
|
// TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
|
||||||
|
@ -110,7 +110,7 @@ const WebViewImpl = (function () {
|
||||||
// a BrowserPlugin property will update the corresponding BrowserPlugin
|
// a BrowserPlugin property will update the corresponding BrowserPlugin
|
||||||
// attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
|
// attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more
|
||||||
// details.
|
// details.
|
||||||
WebViewImpl.prototype.handleWebviewAttributeMutation = function (attributeName, oldValue, newValue) {
|
handleWebviewAttributeMutation (attributeName, oldValue, newValue) {
|
||||||
if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) {
|
if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ const WebViewImpl = (function () {
|
||||||
this.attributes[attributeName].handleMutation(oldValue, newValue)
|
this.attributes[attributeName].handleMutation(oldValue, newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.handleBrowserPluginAttributeMutation = function (attributeName, oldValue, newValue) {
|
handleBrowserPluginAttributeMutation (attributeName, oldValue, newValue) {
|
||||||
if (attributeName === webViewConstants.ATTRIBUTE_INTERNALINSTANCEID && !oldValue && !!newValue) {
|
if (attributeName === webViewConstants.ATTRIBUTE_INTERNALINSTANCEID && !oldValue && !!newValue) {
|
||||||
this.browserPluginNode.removeAttribute(webViewConstants.ATTRIBUTE_INTERNALINSTANCEID)
|
this.browserPluginNode.removeAttribute(webViewConstants.ATTRIBUTE_INTERNALINSTANCEID)
|
||||||
this.internalInstanceId = parseInt(newValue)
|
this.internalInstanceId = parseInt(newValue)
|
||||||
|
@ -132,7 +132,7 @@ const WebViewImpl = (function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.onSizeChanged = function (webViewEvent) {
|
onSizeChanged (webViewEvent) {
|
||||||
const {newHeight, newWidth} = webViewEvent
|
const {newHeight, newWidth} = webViewEvent
|
||||||
const node = this.webviewNode
|
const node = this.webviewNode
|
||||||
const width = node.offsetWidth
|
const width = node.offsetWidth
|
||||||
|
@ -155,7 +155,7 @@ const WebViewImpl = (function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.onElementResize = function (newSize) {
|
onElementResize (newSize) {
|
||||||
// Dispatch the 'resize' event.
|
// Dispatch the 'resize' event.
|
||||||
const resizeEvent = new Event('resize', {
|
const resizeEvent = new Event('resize', {
|
||||||
bubbles: true
|
bubbles: true
|
||||||
|
@ -176,19 +176,19 @@ const WebViewImpl = (function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.createGuest = function () {
|
createGuest () {
|
||||||
return guestViewInternal.createGuest(this.buildParams(), (event, guestInstanceId) => {
|
return guestViewInternal.createGuest(this.buildParams(), (event, guestInstanceId) => {
|
||||||
this.attachGuestInstance(guestInstanceId)
|
this.attachGuestInstance(guestInstanceId)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.dispatchEvent = function (webViewEvent) {
|
dispatchEvent (webViewEvent) {
|
||||||
this.webviewNode.dispatchEvent(webViewEvent)
|
this.webviewNode.dispatchEvent(webViewEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds an 'on<event>' property on the webview, which can be used to set/unset
|
// Adds an 'on<event>' property on the webview, which can be used to set/unset
|
||||||
// an event handler.
|
// an event handler.
|
||||||
WebViewImpl.prototype.setupEventProperty = function (eventName) {
|
setupEventProperty (eventName) {
|
||||||
const propertyName = `on${eventName.toLowerCase()}`
|
const propertyName = `on${eventName.toLowerCase()}`
|
||||||
return Object.defineProperty(this.webviewNode, propertyName, {
|
return Object.defineProperty(this.webviewNode, propertyName, {
|
||||||
get: () => {
|
get: () => {
|
||||||
|
@ -208,7 +208,7 @@ const WebViewImpl = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates state upon loadcommit.
|
// Updates state upon loadcommit.
|
||||||
WebViewImpl.prototype.onLoadCommit = function (webViewEvent) {
|
onLoadCommit (webViewEvent) {
|
||||||
const oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC)
|
const oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC)
|
||||||
const newValue = webViewEvent.url
|
const newValue = webViewEvent.url
|
||||||
if (webViewEvent.isMainFrame && (oldValue !== newValue)) {
|
if (webViewEvent.isMainFrame && (oldValue !== newValue)) {
|
||||||
|
@ -219,11 +219,11 @@ const WebViewImpl = (function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.onAttach = function (storagePartitionId) {
|
onAttach (storagePartitionId) {
|
||||||
return this.attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue(storagePartitionId)
|
return this.attributes[webViewConstants.ATTRIBUTE_PARTITION].setValue(storagePartitionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.buildParams = function () {
|
buildParams () {
|
||||||
const params = {
|
const params = {
|
||||||
instanceId: this.viewInstanceId,
|
instanceId: this.viewInstanceId,
|
||||||
userAgentOverride: this.userAgentOverride,
|
userAgentOverride: this.userAgentOverride,
|
||||||
|
@ -247,7 +247,7 @@ const WebViewImpl = (function () {
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
WebViewImpl.prototype.attachGuestInstance = function (guestInstanceId) {
|
attachGuestInstance (guestInstanceId) {
|
||||||
this.guestInstanceId = guestInstanceId
|
this.guestInstanceId = guestInstanceId
|
||||||
this.attributes[webViewConstants.ATTRIBUTE_GUESTINSTANCE].setValueIgnoreMutation(guestInstanceId)
|
this.attributes[webViewConstants.ATTRIBUTE_GUESTINSTANCE].setValueIgnoreMutation(guestInstanceId)
|
||||||
this.webContents = remote.getGuestWebContents(this.guestInstanceId)
|
this.webContents = remote.getGuestWebContents(this.guestInstanceId)
|
||||||
|
@ -256,9 +256,7 @@ const WebViewImpl = (function () {
|
||||||
}
|
}
|
||||||
return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams())
|
return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return WebViewImpl
|
|
||||||
})()
|
|
||||||
|
|
||||||
// Registers browser plugin <object> custom element.
|
// Registers browser plugin <object> custom element.
|
||||||
const registerBrowserPluginElement = function () {
|
const registerBrowserPluginElement = function () {
|
||||||
|
|
Loading…
Reference in a new issue