diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js
index e967d70925..4183e178da 100644
--- a/lib/browser/guest-view-manager.js
+++ b/lib/browser/guest-view-manager.js
@@ -77,7 +77,6 @@ const createGuest = function (embedder, params) {
// Init guest web view after attached.
guest.on('did-attach', function () {
- let opts
params = this.attachParams
delete this.attachParams
this.viewInstanceId = params.instanceId
@@ -97,7 +96,7 @@ const createGuest = function (embedder, params) {
}
})
if (params.src) {
- opts = {}
+ const opts = {}
if (params.httpreferrer) {
opts.httpReferrer = params.httpreferrer
}
@@ -146,11 +145,9 @@ const createGuest = function (embedder, params) {
// Attach the guest to an element of embedder.
const attachGuest = function (embedder, elementInstanceId, guestInstanceId, params) {
- let guest, guestInstance, key, oldKey, oldGuestInstanceId, ref1, webPreferences
-
// Destroy the old guest when attaching.
- key = (embedder.getId()) + '-' + elementInstanceId
- oldGuestInstanceId = embedderElementsMap[key]
+ const key = (embedder.getId()) + '-' + elementInstanceId
+ const oldGuestInstanceId = embedderElementsMap[key]
if (oldGuestInstanceId != null) {
// Reattachment to the same guest is just a no-op.
if (oldGuestInstanceId === guestInstanceId) {
@@ -160,24 +157,24 @@ const attachGuest = function (embedder, elementInstanceId, guestInstanceId, para
destroyGuest(embedder, oldGuestInstanceId)
}
- guestInstance = guestInstances[guestInstanceId]
+ const guestInstance = guestInstances[guestInstanceId]
// If this isn't a valid guest instance then do nothing.
if (!guestInstance) {
return
}
- guest = guestInstance.guest
+ const {guest} = guestInstance
// If this guest is already attached to an element then remove it
if (guestInstance.elementInstanceId) {
- oldKey = (guestInstance.embedder.getId()) + '-' + guestInstance.elementInstanceId
+ const oldKey = (guestInstance.embedder.getId()) + '-' + guestInstance.elementInstanceId
delete embedderElementsMap[oldKey]
webViewManager.removeGuest(guestInstance.embedder, guestInstanceId)
guestInstance.embedder.send('ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-' + guest.viewInstanceId)
}
- webPreferences = {
+ const webPreferences = {
guestInstanceId: guestInstanceId,
- nodeIntegration: (ref1 = params.nodeintegration) != null ? ref1 : false,
+ nodeIntegration: params.nodeintegration != null ? params.nodeintegration : false,
plugins: params.plugins,
zoomFactor: params.zoomFactor,
webSecurity: !params.disablewebsecurity,
@@ -217,7 +214,7 @@ const destroyGuest = function (embedder, guestInstanceId) {
return
}
- let guestInstance = guestInstances[guestInstanceId]
+ const guestInstance = guestInstances[guestInstanceId]
if (embedder !== guestInstance.embedder) {
return
}
@@ -280,12 +277,12 @@ ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_DESTROY_GUEST', function (event, guestIn
})
ipcMain.on('ELECTRON_GUEST_VIEW_MANAGER_SET_SIZE', function (event, guestInstanceId, params) {
- const guestInstance = guestInstances[guestInstanceId]
- guestInstance != null ? guestInstance.guest.setSize(params) : void 0
+ const guest = getGuest(guestInstanceId)
+ if (guest != null) guest.setSize(params)
})
// Returns WebContents from its guest id.
-exports.getGuest = function (guestInstanceId) {
+const getGuest = function (guestInstanceId) {
const guestInstance = guestInstances[guestInstanceId]
return guestInstance != null ? guestInstance.guest : void 0
}
@@ -295,4 +292,6 @@ const getEmbedder = function (guestInstanceId) {
const guestInstance = guestInstances[guestInstanceId]
return guestInstance != null ? guestInstance.embedder : void 0
}
+
+exports.getGuest = getGuest
exports.getEmbedder = getEmbedder
diff --git a/lib/renderer/web-view/guest-view-internal.js b/lib/renderer/web-view/guest-view-internal.js
index 0bc1787a9f..1f3ba1b193 100644
--- a/lib/renderer/web-view/guest-view-internal.js
+++ b/lib/renderer/web-view/guest-view-internal.js
@@ -1,11 +1,10 @@
'use strict'
-const ipcRenderer = require('electron').ipcRenderer
-const webFrame = require('electron').webFrame
+const {ipcRenderer, webFrame} = require('electron')
-var requestId = 0
+let requestId = 0
-var WEB_VIEW_EVENTS = {
+const WEB_VIEW_EVENTS = {
'load-commit': ['url', 'isMainFrame'],
'did-attach': [],
'did-finish-load': [],
@@ -40,19 +39,19 @@ var WEB_VIEW_EVENTS = {
'update-target-url': ['url']
}
-var DEPRECATED_EVENTS = {
+const DEPRECATED_EVENTS = {
'page-title-updated': 'page-title-set'
}
-var dispatchEvent = function (webView, eventName, eventKey, ...args) {
- var domEvent, f, i, j, len, ref1
+const dispatchEvent = function (webView, eventName, eventKey, ...args) {
+ let f, i, j, len
if (DEPRECATED_EVENTS[eventName] != null) {
dispatchEvent.apply(null, [webView, DEPRECATED_EVENTS[eventName], eventKey].concat(args))
}
- domEvent = new Event(eventName)
- ref1 = WEB_VIEW_EVENTS[eventKey]
- for (i = j = 0, len = ref1.length; j < len; i = ++j) {
- f = ref1[i]
+ const domEvent = new Event(eventName)
+ const props = WEB_VIEW_EVENTS[eventKey]
+ for (i = j = 0, len = props.length; j < len; i = ++j) {
+ f = props[i]
domEvent[f] = args[i]
}
webView.dispatchEvent(domEvent)
@@ -64,11 +63,10 @@ var dispatchEvent = function (webView, eventName, eventKey, ...args) {
module.exports = {
registerEvents: function (webView, viewInstanceId) {
ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_DESTROY_GUEST-' + viewInstanceId, function () {
- var domEvent
webFrame.detachGuest(webView.internalInstanceId)
webView.guestInstanceId = undefined
webView.reset()
- domEvent = new Event('destroyed')
+ const domEvent = new Event('destroyed')
webView.dispatchEvent(domEvent)
})
@@ -77,18 +75,18 @@ module.exports = {
})
ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_IPC_MESSAGE-' + viewInstanceId, function (event, channel, ...args) {
- var domEvent = new Event('ipc-message')
+ const domEvent = new Event('ipc-message')
domEvent.channel = channel
domEvent.args = args
webView.dispatchEvent(domEvent)
})
ipcRenderer.on('ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + viewInstanceId, function (event, ...args) {
- var domEvent, f, i, j, len, ref1
- domEvent = new Event('size-changed')
- ref1 = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
- for (i = j = 0, len = ref1.length; j < len; i = ++j) {
- f = ref1[i]
+ let f, i, j, len
+ const domEvent = new Event('size-changed')
+ const props = ['oldWidth', 'oldHeight', 'newWidth', 'newHeight']
+ for (i = j = 0, len = props.length; j < len; i = ++j) {
+ f = props[i]
domEvent[f] = args[i]
}
webView.onSizeChanged(domEvent)
diff --git a/lib/renderer/web-view/web-view-attributes.js b/lib/renderer/web-view/web-view-attributes.js
index 8c2ec0944e..fdd76c8572 100644
--- a/lib/renderer/web-view/web-view-attributes.js
+++ b/lib/renderer/web-view/web-view-attributes.js
@@ -6,9 +6,9 @@ const webViewConstants = require('./web-view-constants')
const remote = require('electron').remote
// Helper function to resolve url set in attribute.
-var a = document.createElement('a')
+const a = document.createElement('a')
-var resolveURL = function (url) {
+const resolveURL = function (url) {
if (url === '') return ''
a.href = url
return a.href
@@ -211,9 +211,8 @@ class SrcAttribute extends WebViewAttribute {
// where the webview guest has crashed and navigating to the same address
// spawns off a new process.
setupMutationObserver () {
- var params
this.observer = new MutationObserver((mutations) => {
- var i, len, mutation, newValue, oldValue
+ let i, len, mutation, newValue, oldValue
for (i = 0, len = mutations.length; i < len; i++) {
mutation = mutations[i]
oldValue = mutation.oldValue
@@ -224,7 +223,7 @@ class SrcAttribute extends WebViewAttribute {
this.handleMutation(oldValue, newValue)
}
})
- params = {
+ const params = {
attributes: true,
attributeOldValue: true,
attributeFilter: [this.name]
@@ -233,7 +232,6 @@ class SrcAttribute extends WebViewAttribute {
}
parse () {
- var guestContents, httpreferrer, opts, useragent
if (!this.webViewImpl.elementAttached || !this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_PARTITION].validPartitionId || !this.getValue()) {
return
}
@@ -246,16 +244,16 @@ class SrcAttribute extends WebViewAttribute {
}
// Navigate to |this.src|.
- opts = {}
- httpreferrer = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue()
+ const opts = {}
+ const httpreferrer = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_HTTPREFERRER].getValue()
if (httpreferrer) {
opts.httpReferrer = httpreferrer
}
- useragent = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_USERAGENT].getValue()
+ const useragent = this.webViewImpl.attributes[webViewConstants.ATTRIBUTE_USERAGENT].getValue()
if (useragent) {
opts.userAgent = useragent
}
- guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId)
+ const guestContents = remote.getGuestWebContents(this.webViewImpl.guestInstanceId)
guestContents.loadURL(this.getValue(), opts)
}
}
@@ -281,12 +279,11 @@ class PreloadAttribute extends WebViewAttribute {
}
getValue () {
- var preload, protocol
if (!this.webViewImpl.webviewNode.hasAttribute(this.name)) {
return this.value
}
- preload = resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name))
- protocol = preload.substr(0, 5)
+ let preload = resolveURL(this.webViewImpl.webviewNode.getAttribute(this.name))
+ const protocol = preload.substr(0, 5)
if (protocol !== 'file:') {
console.error(webViewConstants.ERROR_MSG_INVALID_PRELOAD_ATTRIBUTE)
preload = ''
diff --git a/lib/renderer/web-view/web-view.js b/lib/renderer/web-view/web-view.js
index cb63627ddd..b6818e344a 100644
--- a/lib/renderer/web-view/web-view.js
+++ b/lib/renderer/web-view/web-view.js
@@ -8,19 +8,18 @@ const v8Util = process.atomBinding('v8_util')
const guestViewInternal = require('./guest-view-internal')
const webViewConstants = require('./web-view-constants')
-var hasProp = {}.hasOwnProperty
+const hasProp = {}.hasOwnProperty
// ID generator.
-var nextId = 0
+let nextId = 0
-var getNextId = function () {
+const getNextId = function () {
return ++nextId
}
// Represents the internal state of the WebView node.
-var WebViewImpl = (function () {
+const WebViewImpl = (function () {
function WebViewImpl (webviewNode) {
- var shadowRoot
this.webviewNode = webviewNode
v8Util.setHiddenValue(this.webviewNode, 'internal', this)
this.attached = false
@@ -30,7 +29,7 @@ var WebViewImpl = (function () {
// on* Event handlers.
this.on = {}
this.browserPluginNode = this.createBrowserPluginNode()
- shadowRoot = this.webviewNode.createShadowRoot()
+ const shadowRoot = this.webviewNode.createShadowRoot()
shadowRoot.innerHTML = ''
this.setupWebViewAttributes()
this.setupFocusPropagation()
@@ -52,7 +51,7 @@ var WebViewImpl = (function () {
WebViewImpl.prototype.createBrowserPluginNode = function () {
// We create BrowserPlugin as a custom element in order to observe changes
// to attributes synchronously.
- var browserPluginNode = new WebViewImpl.BrowserPlugin()
+ const browserPluginNode = new WebViewImpl.BrowserPlugin()
v8Util.setHiddenValue(browserPluginNode, 'internal', this)
return browserPluginNode
}
@@ -136,18 +135,16 @@ var WebViewImpl = (function () {
}
WebViewImpl.prototype.onSizeChanged = function (webViewEvent) {
- var maxHeight, maxWidth, minHeight, minWidth, newHeight, newWidth, node, width
- newWidth = webViewEvent.newWidth
- newHeight = webViewEvent.newHeight
- node = this.webviewNode
- width = node.offsetWidth
+ const {newHeight, newWidth} = webViewEvent
+ const node = this.webviewNode
+ const width = node.offsetWidth
// Check the current bounds to make sure we do not resize
// outside of current constraints.
- maxWidth = this.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() | width
- maxHeight = this.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() | width
- minWidth = this.attributes[webViewConstants.ATTRIBUTE_MINWIDTH].getValue() | width
- minHeight = this.attributes[webViewConstants.ATTRIBUTE_MINHEIGHT].getValue() | width
+ const maxWidth = this.attributes[webViewConstants.ATTRIBUTE_MAXWIDTH].getValue() | width
+ const maxHeight = this.attributes[webViewConstants.ATTRIBUTE_MAXHEIGHT].getValue() | width
+ let minWidth = this.attributes[webViewConstants.ATTRIBUTE_MINWIDTH].getValue() | width
+ let minHeight = this.attributes[webViewConstants.ATTRIBUTE_MINHEIGHT].getValue() | width
minWidth = Math.min(minWidth, maxWidth)
minHeight = Math.min(minHeight, maxHeight)
if (!this.attributes[webViewConstants.ATTRIBUTE_AUTOSIZE].getValue() || (newWidth >= minWidth && newWidth <= maxWidth && newHeight >= minHeight && newHeight <= maxHeight)) {
@@ -162,8 +159,7 @@ var WebViewImpl = (function () {
WebViewImpl.prototype.onElementResize = function (newSize) {
// Dispatch the 'resize' event.
- var resizeEvent
- resizeEvent = new Event('resize', {
+ const resizeEvent = new Event('resize', {
bubbles: true
})
@@ -195,8 +191,7 @@ var WebViewImpl = (function () {
// Adds an 'on' property on the webview, which can be used to set/unset
// an event handler.
WebViewImpl.prototype.setupEventProperty = function (eventName) {
- var propertyName
- propertyName = 'on' + eventName.toLowerCase()
+ const propertyName = 'on' + eventName.toLowerCase()
return Object.defineProperty(this.webviewNode, propertyName, {
get: () => {
return this.on[propertyName]
@@ -216,14 +211,13 @@ var WebViewImpl = (function () {
// Updates state upon loadcommit.
WebViewImpl.prototype.onLoadCommit = function (webViewEvent) {
- var newValue, oldValue
- oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC)
- newValue = webViewEvent.url
+ const oldValue = this.webviewNode.getAttribute(webViewConstants.ATTRIBUTE_SRC)
+ const newValue = webViewEvent.url
if (webViewEvent.isMainFrame && (oldValue !== newValue)) {
// Touching the src attribute triggers a navigation. To avoid
// triggering a page reload on every guest-initiated navigation,
// we do not handle this mutation.
- return this.attributes[webViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation(newValue)
+ this.attributes[webViewConstants.ATTRIBUTE_SRC].setValueIgnoreMutation(newValue)
}
}
@@ -232,17 +226,15 @@ var WebViewImpl = (function () {
}
WebViewImpl.prototype.buildParams = function () {
- var attribute, attributeName, css, elementRect, params, ref1
- params = {
+ const params = {
instanceId: this.viewInstanceId,
userAgentOverride: this.userAgentOverride,
zoomFactor: webFrame.getZoomFactor()
}
- ref1 = this.attributes
- for (attributeName in ref1) {
- if (!hasProp.call(ref1, attributeName)) continue
- attribute = ref1[attributeName]
- params[attributeName] = attribute.getValue()
+ for (const attributeName in this.attributes) {
+ if (hasProp.call(this.attributes, attributeName)) {
+ params[attributeName] = this.attributes[attributeName].getValue()
+ }
}
// When the WebView is not participating in layout (display:none)
@@ -250,8 +242,8 @@ var WebViewImpl = (function () {
// However, in the case where the WebView has a fixed size we can
// use that value to initially size the guest so as to avoid a relayout of
// the on display:block.
- css = window.getComputedStyle(this.webviewNode, null)
- elementRect = this.webviewNode.getBoundingClientRect()
+ const css = window.getComputedStyle(this.webviewNode, null)
+ const elementRect = this.webviewNode.getBoundingClientRect()
params.elementWidth = parseInt(elementRect.width) || parseInt(css.getPropertyValue('width'))
params.elementHeight = parseInt(elementRect.height) || parseInt(css.getPropertyValue('height'))
return params
@@ -271,8 +263,8 @@ var WebViewImpl = (function () {
})()
// Registers browser plugin