diff --git a/lib/renderer/web-view/web-view.js b/lib/renderer/web-view/web-view.js index 70b5a88f01c1..755173422130 100644 --- a/lib/renderer/web-view/web-view.js +++ b/lib/renderer/web-view/web-view.js @@ -16,8 +16,8 @@ const getNextId = function () { } // Represents the internal state of the WebView node. -const WebViewImpl = (function () { - function WebViewImpl (webviewNode) { +class WebViewImpl { + constructor (webviewNode) { this.webviewNode = webviewNode v8Util.setHiddenValue(this.webviewNode, 'internal', this) this.attached = false @@ -46,7 +46,7 @@ const WebViewImpl = (function () { 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 // to attributes synchronously. const browserPluginNode = new WebViewImpl.BrowserPlugin() @@ -55,7 +55,7 @@ const WebViewImpl = (function () { } // Resets some state upon reattaching element to the DOM. - WebViewImpl.prototype.reset = function () { + reset () { // Unlisten the zoom-level-changed event. webFrame.removeListener('zoom-level-changed', this.onZoomLevelChanged) ipcRenderer.removeListener('ELECTRON_RENDERER_WINDOW_VISIBILITY_CHANGE', this.onVisibilityChanged) @@ -78,14 +78,14 @@ const WebViewImpl = (function () { } // Sets the .request property. - WebViewImpl.prototype.setRequestPropertyOnWebViewNode = function (request) { + setRequestPropertyOnWebViewNode (request) { Object.defineProperty(this.webviewNode, 'request', { value: request, enumerable: true }) } - WebViewImpl.prototype.setupFocusPropagation = function () { + setupFocusPropagation () { if (!this.webviewNode.hasAttribute('tabIndex')) { // needs a tabIndex in order to be focusable. // 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 // attribute, if necessary. See BrowserPlugin::UpdateDOMAttribute for more // details. - WebViewImpl.prototype.handleWebviewAttributeMutation = function (attributeName, oldValue, newValue) { + handleWebviewAttributeMutation (attributeName, oldValue, newValue) { if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) { return } @@ -119,7 +119,7 @@ const WebViewImpl = (function () { this.attributes[attributeName].handleMutation(oldValue, newValue) } - WebViewImpl.prototype.handleBrowserPluginAttributeMutation = function (attributeName, oldValue, newValue) { + handleBrowserPluginAttributeMutation (attributeName, oldValue, newValue) { if (attributeName === webViewConstants.ATTRIBUTE_INTERNALINSTANCEID && !oldValue && !!newValue) { this.browserPluginNode.removeAttribute(webViewConstants.ATTRIBUTE_INTERNALINSTANCEID) this.internalInstanceId = parseInt(newValue) @@ -132,7 +132,7 @@ const WebViewImpl = (function () { } } - WebViewImpl.prototype.onSizeChanged = function (webViewEvent) { + onSizeChanged (webViewEvent) { const {newHeight, newWidth} = webViewEvent const node = this.webviewNode const width = node.offsetWidth @@ -155,7 +155,7 @@ const WebViewImpl = (function () { } } - WebViewImpl.prototype.onElementResize = function (newSize) { + onElementResize (newSize) { // Dispatch the 'resize' event. const resizeEvent = new Event('resize', { bubbles: true @@ -176,19 +176,19 @@ const WebViewImpl = (function () { } } - WebViewImpl.prototype.createGuest = function () { + createGuest () { return guestViewInternal.createGuest(this.buildParams(), (event, guestInstanceId) => { this.attachGuestInstance(guestInstanceId) }) } - WebViewImpl.prototype.dispatchEvent = function (webViewEvent) { + dispatchEvent (webViewEvent) { this.webviewNode.dispatchEvent(webViewEvent) } // Adds an 'on' property on the webview, which can be used to set/unset // an event handler. - WebViewImpl.prototype.setupEventProperty = function (eventName) { + setupEventProperty (eventName) { const propertyName = `on${eventName.toLowerCase()}` return Object.defineProperty(this.webviewNode, propertyName, { get: () => { @@ -208,7 +208,7 @@ const WebViewImpl = (function () { } // Updates state upon loadcommit. - WebViewImpl.prototype.onLoadCommit = function (webViewEvent) { + onLoadCommit (webViewEvent) { const oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC) const newValue = webViewEvent.url 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) } - WebViewImpl.prototype.buildParams = function () { + buildParams () { const params = { instanceId: this.viewInstanceId, userAgentOverride: this.userAgentOverride, @@ -247,7 +247,7 @@ const WebViewImpl = (function () { return params } - WebViewImpl.prototype.attachGuestInstance = function (guestInstanceId) { + attachGuestInstance (guestInstanceId) { this.guestInstanceId = guestInstanceId this.attributes[webViewConstants.ATTRIBUTE_GUESTINSTANCE].setValueIgnoreMutation(guestInstanceId) this.webContents = remote.getGuestWebContents(this.guestInstanceId) @@ -256,9 +256,7 @@ const WebViewImpl = (function () { } return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams()) } - - return WebViewImpl -})() +} // Registers browser plugin custom element. const registerBrowserPluginElement = function () {