fix: [webview] fix missing properties on events when contextIsolation: true (#26289)
This commit is contained in:
parent
c856b5fa53
commit
34156c424c
5 changed files with 51 additions and 24 deletions
|
@ -38,6 +38,8 @@ export class WebViewImpl {
|
|||
public attributes = new Map<string, WebViewAttribute>();
|
||||
public setupWebViewAttributes (): void {}
|
||||
|
||||
public dispatchEventInMainWorld?: (eventName: string, props: any) => boolean;
|
||||
|
||||
constructor (public webviewNode: HTMLElement) {
|
||||
// Create internal iframe element.
|
||||
this.internalElement = this.createInternalElement();
|
||||
|
@ -106,10 +108,11 @@ export class WebViewImpl {
|
|||
}
|
||||
|
||||
onElementResize () {
|
||||
const resizeEvent = new Event('resize') as ElectronInternal.WebFrameResizeEvent;
|
||||
resizeEvent.newWidth = this.webviewNode.clientWidth;
|
||||
resizeEvent.newHeight = this.webviewNode.clientHeight;
|
||||
this.dispatchEvent(resizeEvent);
|
||||
const props = {
|
||||
newWidth: this.webviewNode.clientWidth,
|
||||
newHeight: this.webviewNode.clientHeight
|
||||
};
|
||||
this.dispatchEvent('resize', props);
|
||||
}
|
||||
|
||||
createGuest () {
|
||||
|
@ -118,8 +121,8 @@ export class WebViewImpl {
|
|||
});
|
||||
}
|
||||
|
||||
dispatchEvent (webViewEvent: Electron.Event) {
|
||||
this.webviewNode.dispatchEvent(webViewEvent);
|
||||
dispatchEvent (eventName: string, props: Record<string, any> = {}) {
|
||||
this.dispatchEventInMainWorld!(eventName, props);
|
||||
}
|
||||
|
||||
// Adds an 'on<event>' property on the webview, which can be used to set/unset
|
||||
|
@ -144,10 +147,10 @@ export class WebViewImpl {
|
|||
}
|
||||
|
||||
// Updates state upon loadcommit.
|
||||
onLoadCommit (webViewEvent: ElectronInternal.WebViewEvent) {
|
||||
onLoadCommit (props: Record<string, any>) {
|
||||
const oldValue = this.webviewNode.getAttribute(WEB_VIEW_CONSTANTS.ATTRIBUTE_SRC);
|
||||
const newValue = webViewEvent.url;
|
||||
if (webViewEvent.isMainFrame && (oldValue !== newValue)) {
|
||||
const newValue = props.url;
|
||||
if (props.isMainFrame && (oldValue !== newValue)) {
|
||||
// Touching the src attribute triggers a navigation. To avoid
|
||||
// triggering a page reload on every guest-initiated navigation,
|
||||
// we do not handle this mutation.
|
||||
|
@ -160,7 +163,7 @@ export class WebViewImpl {
|
|||
const hasFocus = document.activeElement === this.webviewNode;
|
||||
if (hasFocus !== this.hasFocus) {
|
||||
this.hasFocus = hasFocus;
|
||||
this.dispatchEvent(new Event(hasFocus ? 'focus' : 'blur'));
|
||||
this.dispatchEvent(hasFocus ? 'focus' : 'blur');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue