refactor: remove setupWebViewAttributes gymnastics (#29032)
This commit is contained in:
parent
d5f2eb5a81
commit
25f5c01cec
3 changed files with 21 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { WebViewImpl } from '@electron/internal/renderer/web-view/web-view-impl';
|
import type { WebViewImpl } from '@electron/internal/renderer/web-view/web-view-impl';
|
||||||
import { WEB_VIEW_CONSTANTS } from '@electron/internal/renderer/web-view/web-view-constants';
|
import { WEB_VIEW_CONSTANTS } from '@electron/internal/renderer/web-view/web-view-constants';
|
||||||
|
|
||||||
const resolveURL = function (url?: string | null) {
|
const resolveURL = function (url?: string | null) {
|
||||||
|
@ -249,18 +249,20 @@ class WebPreferencesAttribute extends WebViewAttribute {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets up all of the webview attributes.
|
// Sets up all of the webview attributes.
|
||||||
WebViewImpl.prototype.setupWebViewAttributes = function () {
|
export function setupWebViewAttributes (self: WebViewImpl) {
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_PARTITION, new PartitionAttribute(this));
|
return new Map<string, WebViewAttribute>([
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_SRC, new SrcAttribute(this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_PARTITION, new PartitionAttribute(self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_HTTPREFERRER, new HttpReferrerAttribute(this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_SRC, new SrcAttribute(self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_USERAGENT, new UserAgentAttribute(this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_HTTPREFERRER, new HttpReferrerAttribute(self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_NODEINTEGRATION, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_NODEINTEGRATION, this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_USERAGENT, new UserAgentAttribute(self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_NODEINTEGRATIONINSUBFRAMES, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_NODEINTEGRATIONINSUBFRAMES, this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_NODEINTEGRATION, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_NODEINTEGRATION, self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_PLUGINS, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_PLUGINS, this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_NODEINTEGRATIONINSUBFRAMES, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_NODEINTEGRATIONINSUBFRAMES, self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_DISABLEWEBSECURITY, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_DISABLEWEBSECURITY, this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_PLUGINS, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_PLUGINS, self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_ALLOWPOPUPS, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_ALLOWPOPUPS, this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_DISABLEWEBSECURITY, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_DISABLEWEBSECURITY, self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_PRELOAD, new PreloadAttribute(this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_ALLOWPOPUPS, new BooleanAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_ALLOWPOPUPS, self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_BLINKFEATURES, new BlinkFeaturesAttribute(this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_PRELOAD, new PreloadAttribute(self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_DISABLEBLINKFEATURES, new DisableBlinkFeaturesAttribute(this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_BLINKFEATURES, new BlinkFeaturesAttribute(self)],
|
||||||
this.attributes.set(WEB_VIEW_CONSTANTS.ATTRIBUTE_WEBPREFERENCES, new WebPreferencesAttribute(this));
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_DISABLEBLINKFEATURES, new DisableBlinkFeaturesAttribute(self)],
|
||||||
};
|
[WEB_VIEW_CONSTANTS.ATTRIBUTE_WEBPREFERENCES, new WebPreferencesAttribute(self)]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
|
@ -115,7 +115,6 @@ export const setupWebView = (v8Util: NodeJS.V8UtilBinding, webViewImpl: typeof w
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
webViewImpl.setupAttributes();
|
|
||||||
registerWebViewElement(v8Util, webViewImpl);
|
registerWebViewElement(v8Util, webViewImpl);
|
||||||
|
|
||||||
window.removeEventListener(event.type, listener, useCapture);
|
window.removeEventListener(event.type, listener, useCapture);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import * as guestViewInternal from '@electron/internal/renderer/web-view/guest-v
|
||||||
import { WEB_VIEW_CONSTANTS } from '@electron/internal/renderer/web-view/web-view-constants';
|
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 { syncMethods, asyncMethods, properties } from '@electron/internal/common/web-view-methods';
|
||||||
import type { WebViewAttribute, PartitionAttribute } from '@electron/internal/renderer/web-view/web-view-attributes';
|
import type { WebViewAttribute, PartitionAttribute } from '@electron/internal/renderer/web-view/web-view-attributes';
|
||||||
|
import { setupWebViewAttributes } from '@electron/internal/renderer/web-view/web-view-attributes';
|
||||||
import { deserialize } from '@electron/internal/common/type-utils';
|
import { deserialize } from '@electron/internal/common/type-utils';
|
||||||
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
|
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
|
||||||
|
|
||||||
|
@ -34,9 +35,7 @@ export class WebViewImpl {
|
||||||
public on: Record<string, any> = {}
|
public on: Record<string, any> = {}
|
||||||
public internalElement: HTMLIFrameElement
|
public internalElement: HTMLIFrameElement
|
||||||
|
|
||||||
// Replaced in web-view-attributes
|
public attributes: Map<string, WebViewAttribute>;
|
||||||
public attributes = new Map<string, WebViewAttribute>();
|
|
||||||
public setupWebViewAttributes (): void {}
|
|
||||||
|
|
||||||
public dispatchEventInMainWorld?: (eventName: string, props: any) => boolean;
|
public dispatchEventInMainWorld?: (eventName: string, props: any) => boolean;
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ export class WebViewImpl {
|
||||||
const style = shadowRoot.ownerDocument.createElement('style');
|
const style = shadowRoot.ownerDocument.createElement('style');
|
||||||
style.textContent = ':host { display: flex; }';
|
style.textContent = ':host { display: flex; }';
|
||||||
shadowRoot.appendChild(style);
|
shadowRoot.appendChild(style);
|
||||||
this.setupWebViewAttributes();
|
this.attributes = setupWebViewAttributes(this);
|
||||||
this.viewInstanceId = getNextId();
|
this.viewInstanceId = getNextId();
|
||||||
shadowRoot.appendChild(this.internalElement);
|
shadowRoot.appendChild(this.internalElement);
|
||||||
|
|
||||||
|
@ -208,10 +207,6 @@ export class WebViewImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setupAttributes = () => {
|
|
||||||
require('@electron/internal/renderer/web-view/web-view-attributes');
|
|
||||||
};
|
|
||||||
|
|
||||||
// I wish eslint wasn't so stupid, but it is
|
// I wish eslint wasn't so stupid, but it is
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
export const setupMethods = (WebViewElement: typeof ElectronInternal.WebViewElement) => {
|
export const setupMethods = (WebViewElement: typeof ElectronInternal.WebViewElement) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue