refactor: remove duplicate <webview> event list (#25697)
This commit is contained in:
parent
8207f6901d
commit
db911f29ad
4 changed files with 46 additions and 73 deletions
|
@ -140,6 +140,7 @@ auto_filenames = {
|
||||||
"lib/common/api/shell.ts",
|
"lib/common/api/shell.ts",
|
||||||
"lib/common/define-properties.ts",
|
"lib/common/define-properties.ts",
|
||||||
"lib/common/type-utils.ts",
|
"lib/common/type-utils.ts",
|
||||||
|
"lib/common/web-view-events.ts",
|
||||||
"lib/common/web-view-methods.ts",
|
"lib/common/web-view-methods.ts",
|
||||||
"lib/common/webpack-globals-provider.ts",
|
"lib/common/webpack-globals-provider.ts",
|
||||||
"lib/renderer/api/context-bridge.ts",
|
"lib/renderer/api/context-bridge.ts",
|
||||||
|
@ -247,6 +248,7 @@ auto_filenames = {
|
||||||
"lib/common/parse-features-string.ts",
|
"lib/common/parse-features-string.ts",
|
||||||
"lib/common/reset-search-paths.ts",
|
"lib/common/reset-search-paths.ts",
|
||||||
"lib/common/type-utils.ts",
|
"lib/common/type-utils.ts",
|
||||||
|
"lib/common/web-view-events.ts",
|
||||||
"lib/common/web-view-methods.ts",
|
"lib/common/web-view-methods.ts",
|
||||||
"lib/common/webpack-globals-provider.ts",
|
"lib/common/webpack-globals-provider.ts",
|
||||||
"lib/renderer/ipc-renderer-internal-utils.ts",
|
"lib/renderer/ipc-renderer-internal-utils.ts",
|
||||||
|
@ -268,6 +270,7 @@ auto_filenames = {
|
||||||
"lib/common/init.ts",
|
"lib/common/init.ts",
|
||||||
"lib/common/reset-search-paths.ts",
|
"lib/common/reset-search-paths.ts",
|
||||||
"lib/common/type-utils.ts",
|
"lib/common/type-utils.ts",
|
||||||
|
"lib/common/web-view-events.ts",
|
||||||
"lib/common/web-view-methods.ts",
|
"lib/common/web-view-methods.ts",
|
||||||
"lib/common/webpack-globals-provider.ts",
|
"lib/common/webpack-globals-provider.ts",
|
||||||
"lib/common/webpack-provider.ts",
|
"lib/common/webpack-provider.ts",
|
||||||
|
|
|
@ -5,46 +5,13 @@ const { ipcMainInternal } = require('@electron/internal/browser/ipc-main-interna
|
||||||
const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils');
|
const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils');
|
||||||
const { parseWebViewWebPreferences } = require('@electron/internal/common/parse-features-string');
|
const { parseWebViewWebPreferences } = require('@electron/internal/common/parse-features-string');
|
||||||
const { syncMethods, asyncMethods, properties } = require('@electron/internal/common/web-view-methods');
|
const { syncMethods, asyncMethods, properties } = require('@electron/internal/common/web-view-methods');
|
||||||
|
const { webViewEvents } = require('@electron/internal/common/web-view-events');
|
||||||
const { serialize } = require('@electron/internal/common/type-utils');
|
const { serialize } = require('@electron/internal/common/type-utils');
|
||||||
|
|
||||||
// Doesn't exist in early initialization.
|
// Doesn't exist in early initialization.
|
||||||
let webViewManager = null;
|
let webViewManager = null;
|
||||||
|
|
||||||
const supportedWebViewEvents = [
|
const supportedWebViewEvents = Object.keys(webViewEvents);
|
||||||
'load-commit',
|
|
||||||
'did-attach',
|
|
||||||
'did-finish-load',
|
|
||||||
'did-fail-load',
|
|
||||||
'did-frame-finish-load',
|
|
||||||
'did-start-loading',
|
|
||||||
'did-stop-loading',
|
|
||||||
'dom-ready',
|
|
||||||
'console-message',
|
|
||||||
'context-menu',
|
|
||||||
'devtools-opened',
|
|
||||||
'devtools-closed',
|
|
||||||
'devtools-focused',
|
|
||||||
'will-navigate',
|
|
||||||
'did-start-navigation',
|
|
||||||
'did-navigate',
|
|
||||||
'did-frame-navigate',
|
|
||||||
'did-navigate-in-page',
|
|
||||||
'focus-change',
|
|
||||||
'close',
|
|
||||||
'crashed',
|
|
||||||
'render-process-gone',
|
|
||||||
'plugin-crashed',
|
|
||||||
'destroyed',
|
|
||||||
'page-title-updated',
|
|
||||||
'page-favicon-updated',
|
|
||||||
'enter-html-full-screen',
|
|
||||||
'leave-html-full-screen',
|
|
||||||
'media-started-playing',
|
|
||||||
'media-paused',
|
|
||||||
'found-in-page',
|
|
||||||
'did-change-theme-color',
|
|
||||||
'update-target-url'
|
|
||||||
];
|
|
||||||
|
|
||||||
const guestInstances = {};
|
const guestInstances = {};
|
||||||
const embedderElementsMap = {};
|
const embedderElementsMap = {};
|
||||||
|
@ -119,8 +86,10 @@ const createGuest = function (embedder, params) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
for (const event of supportedWebViewEvents) {
|
for (const event of supportedWebViewEvents) {
|
||||||
|
if (event !== 'new-window') {
|
||||||
fn(event);
|
fn(event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
guest.on('new-window', function (event, url, frameName, disposition, options, additionalFeatures, referrer) {
|
guest.on('new-window', function (event, url, frameName, disposition, options, additionalFeatures, referrer) {
|
||||||
sendToEmbedder('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT', 'new-window', url,
|
sendToEmbedder('ELECTRON_GUEST_VIEW_INTERNAL_DISPATCH_EVENT', 'new-window', url,
|
||||||
|
|
36
lib/common/web-view-events.ts
Normal file
36
lib/common/web-view-events.ts
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
export const webViewEvents: Record<string, string[]> = {
|
||||||
|
'load-commit': ['url', 'isMainFrame'],
|
||||||
|
'did-attach': [],
|
||||||
|
'did-finish-load': [],
|
||||||
|
'did-fail-load': ['errorCode', 'errorDescription', 'validatedURL', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||||
|
'did-frame-finish-load': ['isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||||
|
'did-start-loading': [],
|
||||||
|
'did-stop-loading': [],
|
||||||
|
'dom-ready': [],
|
||||||
|
'console-message': ['level', 'message', 'line', 'sourceId'],
|
||||||
|
'context-menu': ['params'],
|
||||||
|
'devtools-opened': [],
|
||||||
|
'devtools-closed': [],
|
||||||
|
'devtools-focused': [],
|
||||||
|
'new-window': ['url', 'frameName', 'disposition', 'options'],
|
||||||
|
'will-navigate': ['url'],
|
||||||
|
'did-start-navigation': ['url', 'isInPlace', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||||
|
'did-navigate': ['url', 'httpResponseCode', 'httpStatusText'],
|
||||||
|
'did-frame-navigate': ['url', 'httpResponseCode', 'httpStatusText', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||||
|
'did-navigate-in-page': ['url', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
||||||
|
'focus-change': ['focus', 'guestInstanceId'],
|
||||||
|
close: [],
|
||||||
|
crashed: [],
|
||||||
|
'render-process-gone': ['details'],
|
||||||
|
'plugin-crashed': ['name', 'version'],
|
||||||
|
destroyed: [],
|
||||||
|
'page-title-updated': ['title', 'explicitSet'],
|
||||||
|
'page-favicon-updated': ['favicons'],
|
||||||
|
'enter-html-full-screen': [],
|
||||||
|
'leave-html-full-screen': [],
|
||||||
|
'media-started-playing': [],
|
||||||
|
'media-paused': [],
|
||||||
|
'found-in-page': ['result'],
|
||||||
|
'did-change-theme-color': ['themeColor'],
|
||||||
|
'update-target-url': ['url']
|
||||||
|
};
|
|
@ -1,45 +1,10 @@
|
||||||
import { webFrame, IpcMessageEvent } from 'electron';
|
import { webFrame, IpcMessageEvent } from 'electron';
|
||||||
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal';
|
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal';
|
||||||
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
|
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
|
||||||
|
import { webViewEvents } from '@electron/internal/common/web-view-events';
|
||||||
|
|
||||||
import { WebViewImpl } from '@electron/internal/renderer/web-view/web-view-impl';
|
import { WebViewImpl } from '@electron/internal/renderer/web-view/web-view-impl';
|
||||||
|
|
||||||
const WEB_VIEW_EVENTS: Record<string, Array<string>> = {
|
|
||||||
'load-commit': ['url', 'isMainFrame'],
|
|
||||||
'did-attach': [],
|
|
||||||
'did-finish-load': [],
|
|
||||||
'did-fail-load': ['errorCode', 'errorDescription', 'validatedURL', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
|
||||||
'did-frame-finish-load': ['isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
|
||||||
'did-start-loading': [],
|
|
||||||
'did-stop-loading': [],
|
|
||||||
'dom-ready': [],
|
|
||||||
'console-message': ['level', 'message', 'line', 'sourceId'],
|
|
||||||
'context-menu': ['params'],
|
|
||||||
'devtools-opened': [],
|
|
||||||
'devtools-closed': [],
|
|
||||||
'devtools-focused': [],
|
|
||||||
'new-window': ['url', 'frameName', 'disposition', 'options'],
|
|
||||||
'will-navigate': ['url'],
|
|
||||||
'did-start-navigation': ['url', 'isInPlace', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
|
||||||
'did-navigate': ['url', 'httpResponseCode', 'httpStatusText'],
|
|
||||||
'did-frame-navigate': ['url', 'httpResponseCode', 'httpStatusText', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
|
||||||
'did-navigate-in-page': ['url', 'isMainFrame', 'frameProcessId', 'frameRoutingId'],
|
|
||||||
'focus-change': ['focus', 'guestInstanceId'],
|
|
||||||
close: [],
|
|
||||||
crashed: [],
|
|
||||||
'plugin-crashed': ['name', 'version'],
|
|
||||||
destroyed: [],
|
|
||||||
'page-title-updated': ['title', 'explicitSet'],
|
|
||||||
'page-favicon-updated': ['favicons'],
|
|
||||||
'enter-html-full-screen': [],
|
|
||||||
'leave-html-full-screen': [],
|
|
||||||
'media-started-playing': [],
|
|
||||||
'media-paused': [],
|
|
||||||
'found-in-page': ['result'],
|
|
||||||
'did-change-theme-color': ['themeColor'],
|
|
||||||
'update-target-url': ['url']
|
|
||||||
};
|
|
||||||
|
|
||||||
const DEPRECATED_EVENTS: Record<string, string> = {
|
const DEPRECATED_EVENTS: Record<string, string> = {
|
||||||
'page-title-updated': 'page-title-set'
|
'page-title-updated': 'page-title-set'
|
||||||
};
|
};
|
||||||
|
@ -52,7 +17,7 @@ const dispatchEvent = function (
|
||||||
}
|
}
|
||||||
|
|
||||||
const domEvent = new Event(eventName) as ElectronInternal.WebViewEvent;
|
const domEvent = new Event(eventName) as ElectronInternal.WebViewEvent;
|
||||||
WEB_VIEW_EVENTS[eventKey].forEach((prop, index) => {
|
webViewEvents[eventKey].forEach((prop, index) => {
|
||||||
(domEvent as any)[prop] = args[index];
|
(domEvent as any)[prop] = args[index];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue