}
// 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
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()
}
// Resets some state upon reattaching <webview> 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)
}
// Sets the <webview>.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')) {
// <webview> needs a tabIndex in order to be focusable.
// TODO(fsamuel): It would be nice to avoid exposing a tabIndex attribute
// 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
}
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)
}
}
- WebViewImpl.prototype.onSizeChanged = function (webViewEvent) {
+ onSizeChanged (webViewEvent) {
const {newHeight, newWidth} = webViewEvent
const node = this.webviewNode
const width = node.offsetWidth
}
}
- WebViewImpl.prototype.onElementResize = function (newSize) {
+ onElementResize (newSize) {
// Dispatch the 'resize' event.
const resizeEvent = new Event('resize', {
bubbles: true
}
}
- 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<event>' 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: () => {
}
// 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)) {
}
}
- 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,
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)
}
return guestViewInternal.attachGuest(this.internalInstanceId, this.guestInstanceId, this.buildParams())
}
-
- return WebViewImpl
-})()
+}
// Registers browser plugin <object> custom element.
const registerBrowserPluginElement = function () {