forked from electron/electron
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: <webview> not working with contextIsolation + sandbox (electron#…
- Loading branch information
Showing
8 changed files
with
164 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
|
||
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal') | ||
const v8Util = process.atomBinding('v8_util') | ||
|
||
function handleFocusBlur (guestInstanceId) { | ||
// Note that while Chromium content APIs have observer for focus/blur, they | ||
// unfortunately do not work for webview. | ||
|
||
window.addEventListener('focus', () => { | ||
ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', true, guestInstanceId) | ||
}) | ||
|
||
window.addEventListener('blur', () => { | ||
ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', false, guestInstanceId) | ||
}) | ||
} | ||
|
||
module.exports = function (contextIsolation, webviewTag, guestInstanceId) { | ||
// Load webview tag implementation. | ||
if (webviewTag && guestInstanceId == null) { | ||
const webViewImpl = require('@electron/internal/renderer/web-view/web-view-impl') | ||
if (contextIsolation) { | ||
v8Util.setHiddenValue(window, 'web-view-impl', webViewImpl) | ||
} else { | ||
const { setupWebView } = require('@electron/internal/renderer/web-view/web-view-element') | ||
setupWebView(v8Util, webViewImpl) | ||
} | ||
} | ||
|
||
if (guestInstanceId) { | ||
// Report focus/blur events of webview to browser. | ||
handleFocusBlur(guestInstanceId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters