|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 | // @ts-check |
| 6 | + |
| 7 | +/** |
| 8 | + * @typedef {{ |
| 9 | + * postMessage: (channel: string, data?: any) => void, |
| 10 | + * onMessage: (channel: string, handler: any) => void, |
| 11 | + * focusIframeOnCreate?: boolean, |
| 12 | + * ready?: Promise<void>, |
| 13 | + * onIframeLoaded: (iframe: HTMLIFrameElement) => void |
| 14 | + * }} WebviewHost |
| 15 | + */ |
| 16 | + |
6 | 17 | (function () { |
7 | 18 | 'use strict'; |
8 | 19 |
|
|
134 | 145 | } |
135 | 146 |
|
136 | 147 | /** |
137 | | - * @typedef {{ |
138 | | - * postMessage: (channel: string, data?: any) => void, |
139 | | - * onMessage: (channel: string, handler: any) => void, |
140 | | - * focusIframeOnCreate?: boolean, |
141 | | - * ready?: Promise<void> |
142 | | - * }} HostCommunications |
143 | | - */ |
144 | | - |
145 | | - /** |
146 | | - * @param {HostCommunications} host |
| 148 | + * @param {WebviewHost} host |
147 | 149 | */ |
148 | 150 | function createWebviewManager(host) { |
149 | 151 | // state |
150 | 152 | let firstLoad = true; |
151 | 153 | let loadTimeout; |
152 | 154 | let pendingMessages = []; |
153 | | - let isInDevelopmentMode = false; |
154 | 155 |
|
155 | 156 | const initData = { |
156 | 157 | initialScrollProgress: undefined |
|
442 | 443 | } |
443 | 444 | }); |
444 | 445 |
|
445 | | - if (!FAKE_LOAD) { |
446 | | - newFrame.contentWindow.onbeforeunload = () => { |
447 | | - if (isInDevelopmentMode) { // Allow reloads while developing a webview |
448 | | - host.postMessage('do-reload'); |
449 | | - return false; |
450 | | - } |
451 | | - |
452 | | - // Block navigation when not in development mode |
453 | | - console.log('prevented webview navigation'); |
454 | | - return false; |
455 | | - }; |
456 | | - } |
457 | | - |
458 | 446 | // Bubble out link clicks |
459 | 447 | newFrame.contentWindow.addEventListener('click', handleInnerClick); |
460 | 448 |
|
461 | | - // Electron 4 eats mouseup events from inside webviews |
462 | | - // https://github.com/microsoft/vscode/issues/75090 |
463 | | - // Try to fix this by rebroadcasting mouse moves and mouseups so that we can |
464 | | - // emulate these on the main window |
465 | | - if (!FAKE_LOAD) { |
466 | | - let isMouseDown = false; |
467 | | - |
468 | | - newFrame.contentWindow.addEventListener('mousedown', () => { |
469 | | - isMouseDown = true; |
470 | | - }); |
471 | | - |
472 | | - const tryDispatchSyntheticMouseEvent = (e) => { |
473 | | - if (!isMouseDown) { |
474 | | - host.postMessage('synthetic-mouse-event', { type: e.type, screenX: e.screenX, screenY: e.screenY, clientX: e.clientX, clientY: e.clientY }); |
475 | | - } |
476 | | - }; |
477 | | - newFrame.contentWindow.addEventListener('mouseup', e => { |
478 | | - tryDispatchSyntheticMouseEvent(e); |
479 | | - isMouseDown = false; |
480 | | - }); |
481 | | - newFrame.contentWindow.addEventListener('mousemove', tryDispatchSyntheticMouseEvent); |
482 | | - } |
| 449 | + host.onIframeLoaded(newFrame); |
483 | 450 | } |
484 | 451 |
|
485 | 452 | if (!FAKE_LOAD) { |
|
511 | 478 | initData.initialScrollProgress = progress; |
512 | 479 | }); |
513 | 480 |
|
514 | | - host.onMessage('devtools-opened', () => { |
515 | | - isInDevelopmentMode = true; |
516 | | - }); |
517 | 481 |
|
518 | 482 | trackFocus({ |
519 | 483 | onFocus: () => host.postMessage('did-focus'), |
|
0 commit comments