build: enable JS semicolons (#22783)
This commit is contained in:
parent
24e21467b9
commit
5d657dece4
354 changed files with 21512 additions and 21510 deletions
|
@ -1,21 +1,21 @@
|
|||
import * as electron from 'electron'
|
||||
import * as electron from 'electron';
|
||||
|
||||
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal'
|
||||
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils'
|
||||
import * as guestViewInternal from '@electron/internal/renderer/web-view/guest-view-internal'
|
||||
import { WEB_VIEW_CONSTANTS } from '@electron/internal/renderer/web-view/web-view-constants'
|
||||
import { syncMethods, asyncMethods, properties } from '@electron/internal/common/web-view-methods'
|
||||
import { deserialize } from '@electron/internal/common/type-utils'
|
||||
const { webFrame } = electron
|
||||
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal';
|
||||
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
|
||||
import * as guestViewInternal from '@electron/internal/renderer/web-view/guest-view-internal';
|
||||
import { WEB_VIEW_CONSTANTS } from '@electron/internal/renderer/web-view/web-view-constants';
|
||||
import { syncMethods, asyncMethods, properties } from '@electron/internal/common/web-view-methods';
|
||||
import { deserialize } from '@electron/internal/common/type-utils';
|
||||
const { webFrame } = electron;
|
||||
|
||||
const v8Util = process.electronBinding('v8_util')
|
||||
const v8Util = process.electronBinding('v8_util');
|
||||
|
||||
// ID generator.
|
||||
let nextId = 0
|
||||
let nextId = 0;
|
||||
|
||||
const getNextId = function () {
|
||||
return ++nextId
|
||||
}
|
||||
return ++nextId;
|
||||
};
|
||||
|
||||
// Represents the internal state of the WebView node.
|
||||
export class WebViewImpl {
|
||||
|
@ -38,29 +38,29 @@ export class WebViewImpl {
|
|||
|
||||
constructor (public webviewNode: HTMLElement) {
|
||||
// Create internal iframe element.
|
||||
this.internalElement = this.createInternalElement()
|
||||
const shadowRoot = this.webviewNode.attachShadow({ mode: 'open' })
|
||||
shadowRoot.innerHTML = '<!DOCTYPE html><style type="text/css">:host { display: flex; }</style>'
|
||||
this.setupWebViewAttributes()
|
||||
this.viewInstanceId = getNextId()
|
||||
shadowRoot.appendChild(this.internalElement)
|
||||
this.internalElement = this.createInternalElement();
|
||||
const shadowRoot = this.webviewNode.attachShadow({ mode: 'open' });
|
||||
shadowRoot.innerHTML = '<!DOCTYPE html><style type="text/css">:host { display: flex; }</style>';
|
||||
this.setupWebViewAttributes();
|
||||
this.viewInstanceId = getNextId();
|
||||
shadowRoot.appendChild(this.internalElement);
|
||||
|
||||
// Provide access to contentWindow.
|
||||
Object.defineProperty(this.webviewNode, 'contentWindow', {
|
||||
get: () => {
|
||||
return this.internalElement.contentWindow
|
||||
return this.internalElement.contentWindow;
|
||||
},
|
||||
enumerable: true
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
createInternalElement () {
|
||||
const iframeElement = document.createElement('iframe')
|
||||
iframeElement.style.flex = '1 1 auto'
|
||||
iframeElement.style.width = '100%'
|
||||
iframeElement.style.border = '0'
|
||||
v8Util.setHiddenValue(iframeElement, 'internal', this)
|
||||
return iframeElement
|
||||
const iframeElement = document.createElement('iframe');
|
||||
iframeElement.style.flex = '1 1 auto';
|
||||
iframeElement.style.width = '100%';
|
||||
iframeElement.style.border = '0';
|
||||
v8Util.setHiddenValue(iframeElement, 'internal', this);
|
||||
return iframeElement;
|
||||
}
|
||||
|
||||
// Resets some state upon reattaching <webview> element to the DOM.
|
||||
|
@ -72,20 +72,20 @@ export class WebViewImpl {
|
|||
// heard back from createGuest yet. We will not reset the flag in this case so
|
||||
// that we don't end up allocating a second guest.
|
||||
if (this.guestInstanceId) {
|
||||
this.guestInstanceId = undefined
|
||||
this.guestInstanceId = undefined;
|
||||
}
|
||||
|
||||
this.beforeFirstNavigation = true
|
||||
this.attributes[WEB_VIEW_CONSTANTS.ATTRIBUTE_PARTITION].validPartitionId = true
|
||||
this.beforeFirstNavigation = true;
|
||||
this.attributes[WEB_VIEW_CONSTANTS.ATTRIBUTE_PARTITION].validPartitionId = true;
|
||||
|
||||
// Since attachment swaps a local frame for a remote frame, we need our
|
||||
// internal iframe element to be local again before we can reattach.
|
||||
const newFrame = this.createInternalElement()
|
||||
const oldFrame = this.internalElement
|
||||
this.internalElement = newFrame
|
||||
const newFrame = this.createInternalElement();
|
||||
const oldFrame = this.internalElement;
|
||||
this.internalElement = newFrame;
|
||||
|
||||
if (oldFrame && oldFrame.parentNode) {
|
||||
oldFrame.parentNode.replaceChild(newFrame, oldFrame)
|
||||
oldFrame.parentNode.replaceChild(newFrame, oldFrame);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,179 +96,179 @@ export class WebViewImpl {
|
|||
// details.
|
||||
handleWebviewAttributeMutation (attributeName: string, oldValue: any, newValue: any) {
|
||||
if (!this.attributes[attributeName] || this.attributes[attributeName].ignoreMutation) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// Let the changed attribute handle its own mutation
|
||||
this.attributes[attributeName].handleMutation(oldValue, newValue)
|
||||
this.attributes[attributeName].handleMutation(oldValue, newValue);
|
||||
}
|
||||
|
||||
onElementResize () {
|
||||
const resizeEvent = new Event('resize') as ElectronInternal.WebFrameResizeEvent
|
||||
resizeEvent.newWidth = this.webviewNode.clientWidth
|
||||
resizeEvent.newHeight = this.webviewNode.clientHeight
|
||||
this.dispatchEvent(resizeEvent)
|
||||
const resizeEvent = new Event('resize') as ElectronInternal.WebFrameResizeEvent;
|
||||
resizeEvent.newWidth = this.webviewNode.clientWidth;
|
||||
resizeEvent.newHeight = this.webviewNode.clientHeight;
|
||||
this.dispatchEvent(resizeEvent);
|
||||
}
|
||||
|
||||
createGuest () {
|
||||
guestViewInternal.createGuest(this.buildParams()).then(guestInstanceId => {
|
||||
this.attachGuestInstance(guestInstanceId)
|
||||
})
|
||||
this.attachGuestInstance(guestInstanceId);
|
||||
});
|
||||
}
|
||||
|
||||
dispatchEvent (webViewEvent: Electron.Event) {
|
||||
this.webviewNode.dispatchEvent(webViewEvent)
|
||||
this.webviewNode.dispatchEvent(webViewEvent);
|
||||
}
|
||||
|
||||
// Adds an 'on<event>' property on the webview, which can be used to set/unset
|
||||
// an event handler.
|
||||
setupEventProperty (eventName: string) {
|
||||
const propertyName = `on${eventName.toLowerCase()}`
|
||||
const propertyName = `on${eventName.toLowerCase()}`;
|
||||
return Object.defineProperty(this.webviewNode, propertyName, {
|
||||
get: () => {
|
||||
return this.on[propertyName]
|
||||
return this.on[propertyName];
|
||||
},
|
||||
set: (value) => {
|
||||
if (this.on[propertyName]) {
|
||||
this.webviewNode.removeEventListener(eventName, this.on[propertyName])
|
||||
this.webviewNode.removeEventListener(eventName, this.on[propertyName]);
|
||||
}
|
||||
this.on[propertyName] = value
|
||||
this.on[propertyName] = value;
|
||||
if (value) {
|
||||
return this.webviewNode.addEventListener(eventName, value)
|
||||
return this.webviewNode.addEventListener(eventName, value);
|
||||
}
|
||||
},
|
||||
enumerable: true
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Updates state upon loadcommit.
|
||||
onLoadCommit (webViewEvent: ElectronInternal.WebViewEvent) {
|
||||
const oldValue = this.webviewNode.getAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_SRC)
|
||||
const newValue = webViewEvent.url
|
||||
const oldValue = this.webviewNode.getAttribute(WEB_VIEW_CONSTANTS.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.
|
||||
this.attributes[WEB_VIEW_CONSTANTS.ATTRIBUTE_SRC].setValueIgnoreMutation(newValue)
|
||||
this.attributes[WEB_VIEW_CONSTANTS.ATTRIBUTE_SRC].setValueIgnoreMutation(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
// Emits focus/blur events.
|
||||
onFocusChange () {
|
||||
const hasFocus = document.activeElement === this.webviewNode
|
||||
const hasFocus = document.activeElement === this.webviewNode;
|
||||
if (hasFocus !== this.hasFocus) {
|
||||
this.hasFocus = hasFocus
|
||||
this.dispatchEvent(new Event(hasFocus ? 'focus' : 'blur'))
|
||||
this.hasFocus = hasFocus;
|
||||
this.dispatchEvent(new Event(hasFocus ? 'focus' : 'blur'));
|
||||
}
|
||||
}
|
||||
|
||||
onAttach (storagePartitionId: number) {
|
||||
return this.attributes[WEB_VIEW_CONSTANTS.ATTRIBUTE_PARTITION].setValue(storagePartitionId)
|
||||
return this.attributes[WEB_VIEW_CONSTANTS.ATTRIBUTE_PARTITION].setValue(storagePartitionId);
|
||||
}
|
||||
|
||||
buildParams () {
|
||||
const params: Record<string, any> = {
|
||||
instanceId: this.viewInstanceId,
|
||||
userAgentOverride: this.userAgentOverride
|
||||
}
|
||||
};
|
||||
|
||||
for (const attributeName in this.attributes) {
|
||||
if (Object.prototype.hasOwnProperty.call(this.attributes, attributeName)) {
|
||||
params[attributeName] = this.attributes[attributeName].getValue()
|
||||
params[attributeName] = this.attributes[attributeName].getValue();
|
||||
}
|
||||
}
|
||||
|
||||
return params
|
||||
return params;
|
||||
}
|
||||
|
||||
attachGuestInstance (guestInstanceId: number) {
|
||||
if (!this.elementAttached) {
|
||||
// The element could be detached before we got response from browser.
|
||||
return
|
||||
return;
|
||||
}
|
||||
this.internalInstanceId = getNextId()
|
||||
this.guestInstanceId = guestInstanceId
|
||||
this.internalInstanceId = getNextId();
|
||||
this.guestInstanceId = guestInstanceId;
|
||||
|
||||
guestViewInternal.attachGuest(
|
||||
this.internalInstanceId,
|
||||
this.guestInstanceId,
|
||||
this.buildParams(),
|
||||
this.internalElement.contentWindow!
|
||||
)
|
||||
);
|
||||
|
||||
// ResizeObserver is a browser global not recognized by "standard".
|
||||
/* globals ResizeObserver */
|
||||
// TODO(zcbenz): Should we deprecate the "resize" event? Wait, it is not
|
||||
// even documented.
|
||||
this.resizeObserver = new ResizeObserver(this.onElementResize.bind(this))
|
||||
this.resizeObserver.observe(this.internalElement)
|
||||
this.resizeObserver = new ResizeObserver(this.onElementResize.bind(this));
|
||||
this.resizeObserver.observe(this.internalElement);
|
||||
}
|
||||
}
|
||||
|
||||
export const setupAttributes = () => {
|
||||
require('@electron/internal/renderer/web-view/web-view-attributes')
|
||||
}
|
||||
require('@electron/internal/renderer/web-view/web-view-attributes');
|
||||
};
|
||||
|
||||
// I wish eslint wasn't so stupid, but it is
|
||||
// eslint-disable-next-line
|
||||
export const setupMethods = (WebViewElement: typeof ElectronInternal.WebViewElement) => {
|
||||
WebViewElement.prototype.getWebContentsId = function () {
|
||||
const internal = v8Util.getHiddenValue<WebViewImpl>(this, 'internal')
|
||||
const internal = v8Util.getHiddenValue<WebViewImpl>(this, 'internal');
|
||||
if (!internal.guestInstanceId) {
|
||||
throw new Error('The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.')
|
||||
throw new Error('The WebView must be attached to the DOM and the dom-ready event emitted before this method can be called.');
|
||||
}
|
||||
return internal.guestInstanceId
|
||||
}
|
||||
return internal.guestInstanceId;
|
||||
};
|
||||
|
||||
// Focusing the webview should move page focus to the underlying iframe.
|
||||
WebViewElement.prototype.focus = function () {
|
||||
this.contentWindow.focus()
|
||||
}
|
||||
this.contentWindow.focus();
|
||||
};
|
||||
|
||||
// Forward proto.foo* method calls to WebViewImpl.foo*.
|
||||
const createBlockHandler = function (method: string) {
|
||||
return function (this: ElectronInternal.WebViewElement, ...args: Array<any>) {
|
||||
return ipcRendererUtils.invokeSync('ELECTRON_GUEST_VIEW_MANAGER_CALL', this.getWebContentsId(), method, args)
|
||||
}
|
||||
}
|
||||
return ipcRendererUtils.invokeSync('ELECTRON_GUEST_VIEW_MANAGER_CALL', this.getWebContentsId(), method, args);
|
||||
};
|
||||
};
|
||||
|
||||
for (const method of syncMethods) {
|
||||
(WebViewElement.prototype as Record<string, any>)[method] = createBlockHandler(method)
|
||||
(WebViewElement.prototype as Record<string, any>)[method] = createBlockHandler(method);
|
||||
}
|
||||
|
||||
const createNonBlockHandler = function (method: string) {
|
||||
return function (this: ElectronInternal.WebViewElement, ...args: Array<any>) {
|
||||
return ipcRendererInternal.invoke('ELECTRON_GUEST_VIEW_MANAGER_CALL', this.getWebContentsId(), method, args)
|
||||
}
|
||||
}
|
||||
return ipcRendererInternal.invoke('ELECTRON_GUEST_VIEW_MANAGER_CALL', this.getWebContentsId(), method, args);
|
||||
};
|
||||
};
|
||||
|
||||
for (const method of asyncMethods) {
|
||||
(WebViewElement.prototype as Record<string, any>)[method] = createNonBlockHandler(method)
|
||||
(WebViewElement.prototype as Record<string, any>)[method] = createNonBlockHandler(method);
|
||||
}
|
||||
|
||||
WebViewElement.prototype.capturePage = async function (...args) {
|
||||
return deserialize(await ipcRendererInternal.invoke('ELECTRON_GUEST_VIEW_MANAGER_CAPTURE_PAGE', this.getWebContentsId(), args))
|
||||
}
|
||||
return deserialize(await ipcRendererInternal.invoke('ELECTRON_GUEST_VIEW_MANAGER_CAPTURE_PAGE', this.getWebContentsId(), args));
|
||||
};
|
||||
|
||||
const createPropertyGetter = function (property: string) {
|
||||
return function (this: ElectronInternal.WebViewElement) {
|
||||
return ipcRendererUtils.invokeSync('ELECTRON_GUEST_VIEW_MANAGER_PROPERTY_GET', this.getWebContentsId(), property)
|
||||
}
|
||||
}
|
||||
return ipcRendererUtils.invokeSync('ELECTRON_GUEST_VIEW_MANAGER_PROPERTY_GET', this.getWebContentsId(), property);
|
||||
};
|
||||
};
|
||||
|
||||
const createPropertySetter = function (property: string) {
|
||||
return function (this: ElectronInternal.WebViewElement, arg: any) {
|
||||
return ipcRendererUtils.invokeSync('ELECTRON_GUEST_VIEW_MANAGER_PROPERTY_SET', this.getWebContentsId(), property, arg)
|
||||
}
|
||||
}
|
||||
return ipcRendererUtils.invokeSync('ELECTRON_GUEST_VIEW_MANAGER_PROPERTY_SET', this.getWebContentsId(), property, arg);
|
||||
};
|
||||
};
|
||||
|
||||
for (const property of properties) {
|
||||
Object.defineProperty(WebViewElement.prototype, property, {
|
||||
get: createPropertyGetter(property) as any,
|
||||
set: createPropertySetter(property)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const webViewImplModule = {
|
||||
setupAttributes,
|
||||
|
@ -276,4 +276,4 @@ export const webViewImplModule = {
|
|||
guestViewInternal,
|
||||
webFrame,
|
||||
WebViewImpl
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue