From db911f29ada1d6fdecffc968d6dda665b21a8752 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 6 Oct 2020 15:11:26 +0200 Subject: [PATCH] refactor: remove duplicate event list (#25697) --- filenames.auto.gni | 3 ++ lib/browser/guest-view-manager.js | 41 +++----------------- lib/common/web-view-events.ts | 36 +++++++++++++++++ lib/renderer/web-view/guest-view-internal.ts | 39 +------------------ 4 files changed, 46 insertions(+), 73 deletions(-) create mode 100644 lib/common/web-view-events.ts diff --git a/filenames.auto.gni b/filenames.auto.gni index 31c2ef639fe..3d41b7718aa 100644 --- a/filenames.auto.gni +++ b/filenames.auto.gni @@ -140,6 +140,7 @@ auto_filenames = { "lib/common/api/shell.ts", "lib/common/define-properties.ts", "lib/common/type-utils.ts", + "lib/common/web-view-events.ts", "lib/common/web-view-methods.ts", "lib/common/webpack-globals-provider.ts", "lib/renderer/api/context-bridge.ts", @@ -247,6 +248,7 @@ auto_filenames = { "lib/common/parse-features-string.ts", "lib/common/reset-search-paths.ts", "lib/common/type-utils.ts", + "lib/common/web-view-events.ts", "lib/common/web-view-methods.ts", "lib/common/webpack-globals-provider.ts", "lib/renderer/ipc-renderer-internal-utils.ts", @@ -268,6 +270,7 @@ auto_filenames = { "lib/common/init.ts", "lib/common/reset-search-paths.ts", "lib/common/type-utils.ts", + "lib/common/web-view-events.ts", "lib/common/web-view-methods.ts", "lib/common/webpack-globals-provider.ts", "lib/common/webpack-provider.ts", diff --git a/lib/browser/guest-view-manager.js b/lib/browser/guest-view-manager.js index 3b20b2800c6..2470d7f7dc1 100644 --- a/lib/browser/guest-view-manager.js +++ b/lib/browser/guest-view-manager.js @@ -5,46 +5,13 @@ const { ipcMainInternal } = require('@electron/internal/browser/ipc-main-interna const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils'); const { parseWebViewWebPreferences } = require('@electron/internal/common/parse-features-string'); 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'); // Doesn't exist in early initialization. let webViewManager = null; -const supportedWebViewEvents = [ - '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 supportedWebViewEvents = Object.keys(webViewEvents); const guestInstances = {}; const embedderElementsMap = {}; @@ -119,7 +86,9 @@ const createGuest = function (embedder, params) { }); }; for (const event of supportedWebViewEvents) { - fn(event); + if (event !== 'new-window') { + fn(event); + } } guest.on('new-window', function (event, url, frameName, disposition, options, additionalFeatures, referrer) { diff --git a/lib/common/web-view-events.ts b/lib/common/web-view-events.ts new file mode 100644 index 00000000000..7b8e8ff9ec6 --- /dev/null +++ b/lib/common/web-view-events.ts @@ -0,0 +1,36 @@ +export const webViewEvents: Record = { + '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'] +}; diff --git a/lib/renderer/web-view/guest-view-internal.ts b/lib/renderer/web-view/guest-view-internal.ts index 73d3b2b56a8..768b8659b8b 100644 --- a/lib/renderer/web-view/guest-view-internal.ts +++ b/lib/renderer/web-view/guest-view-internal.ts @@ -1,45 +1,10 @@ import { webFrame, IpcMessageEvent } from 'electron'; import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal'; 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'; -const WEB_VIEW_EVENTS: Record> = { - '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 = { 'page-title-updated': 'page-title-set' }; @@ -52,7 +17,7 @@ const dispatchEvent = function ( } 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]; });