2019-03-07 23:26:23 +00:00
|
|
|
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal';
|
2020-10-13 21:11:06 +00:00
|
|
|
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
|
2019-01-22 01:08:16 +00:00
|
|
|
|
2021-05-15 07:42:07 +00:00
|
|
|
import type * as webViewElementModule from '@electron/internal/renderer/web-view/web-view-element';
|
|
|
|
import type * as guestViewInternalModule from '@electron/internal/renderer/web-view/guest-view-internal';
|
2021-05-06 01:05:01 +00:00
|
|
|
|
2020-06-23 03:32:45 +00:00
|
|
|
const v8Util = process._linkedBinding('electron_common_v8_util');
|
2021-05-15 07:42:07 +00:00
|
|
|
const { mainFrame: webFrame } = process._linkedBinding('electron_renderer_web_frame');
|
2019-01-22 01:08:16 +00:00
|
|
|
|
2021-05-05 18:37:40 +00:00
|
|
|
function handleFocusBlur () {
|
2019-01-22 01:08:16 +00:00
|
|
|
// Note that while Chromium content APIs have observer for focus/blur, they
|
|
|
|
// unfortunately do not work for webview.
|
|
|
|
|
|
|
|
window.addEventListener('focus', () => {
|
2021-05-05 18:37:40 +00:00
|
|
|
ipcRendererInternal.send(IPC_MESSAGES.GUEST_VIEW_MANAGER_FOCUS_CHANGE, true);
|
2019-01-22 01:08:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener('blur', () => {
|
2021-05-05 18:37:40 +00:00
|
|
|
ipcRendererInternal.send(IPC_MESSAGES.GUEST_VIEW_MANAGER_FOCUS_CHANGE, false);
|
2019-01-22 01:08:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-11-08 16:57:56 +00:00
|
|
|
export function webViewInit (webviewTag: boolean, isWebView: boolean) {
|
2019-01-24 18:53:16 +00:00
|
|
|
// Don't allow recursive `<webview>`.
|
2021-07-28 22:32:53 +00:00
|
|
|
if (webviewTag && !isWebView) {
|
2021-05-15 07:42:07 +00:00
|
|
|
const guestViewInternal = require('@electron/internal/renderer/web-view/guest-view-internal') as typeof guestViewInternalModule;
|
2021-11-08 16:57:56 +00:00
|
|
|
if (process.contextIsolated) {
|
2021-05-15 07:42:07 +00:00
|
|
|
v8Util.setHiddenValue(window, 'guestViewInternal', guestViewInternal);
|
2019-01-22 01:08:16 +00:00
|
|
|
} else {
|
2021-05-15 07:42:07 +00:00
|
|
|
const { setupWebView } = require('@electron/internal/renderer/web-view/web-view-element') as typeof webViewElementModule;
|
|
|
|
setupWebView({
|
|
|
|
guestViewInternal,
|
|
|
|
allowGuestViewElementDefinition: webFrame.allowGuestViewElementDefinition,
|
|
|
|
setIsWebView: iframe => v8Util.setHiddenValue(iframe, 'isWebView', true)
|
|
|
|
});
|
2019-01-22 01:08:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-28 22:32:53 +00:00
|
|
|
if (isWebView) {
|
2019-01-22 01:08:16 +00:00
|
|
|
// Report focus/blur events of webview to browser.
|
2021-05-05 18:37:40 +00:00
|
|
|
handleFocusBlur();
|
2019-01-22 01:08:16 +00:00
|
|
|
}
|
|
|
|
}
|