Dialog with custom UI API (#561)

* initial checkin for dialog with custom UI API
This commit is contained in:
Leila Lali
2018-01-29 14:31:12 -08:00
committed by GitHub
parent 495c2e62e6
commit 1b2e264c7d
12 changed files with 499 additions and 4 deletions

View File

@@ -12,6 +12,8 @@
var firstLoad = true;
var loadTimeout;
var pendingMessages = [];
// {{SQL CARBON EDIT}}
var enableWrappedPostMessage = false;
const initData = {
initialScrollProgress: undefined
@@ -124,6 +126,8 @@
// update iframe-contents
ipcRenderer.on('content', function (_event, data) {
const options = data.options;
// {{SQL CARBON EDIT}}
enableWrappedPostMessage = options && options.enableWrappedPostMessage;
const text = data.contents.join('\n');
const newDocument = new DOMParser().parseFromString(text, 'text/html');
@@ -301,8 +305,16 @@
});
// forward messages from the embedded iframe
window.onmessage = function (message) {
ipcRenderer.sendToHost(message.data.command, message.data.data);
// {{SQL CARBON EDIT}}
if (enableWrappedPostMessage) {
// Modern webview. Forward wrapped message
ipcRenderer.sendToHost('onmessage', message.data);
} else {
// Old school webview. Forward exact message
ipcRenderer.sendToHost(message.data.command, message.data.data);
}
};
// signal ready

View File

@@ -37,6 +37,9 @@ export interface WebviewOptions {
allowScripts?: boolean;
allowSvgs?: boolean;
svgWhiteList?: string[];
// {{SQL CARBON EDIT}}
enableWrappedPostMessage?: boolean;
hideFind?: boolean;
}
export default class Webview {
@@ -49,6 +52,8 @@ export default class Webview {
private _onDidScroll = new Emitter<{ scrollYPercentage: number }>();
private _onFoundInPageResults = new Emitter<FoundInPageResults>();
// {{SQL CARBON EDIT}}
private _onMessage = new Emitter<any>();
private _webviewFindWidget: WebviewFindWidget;
private _findStarted: boolean = false;
@@ -141,6 +146,13 @@ export default class Webview {
console.error('embedded page crashed');
}),
addDisposableListener(this._webview, 'ipc-message', (event) => {
// {{SQL CARBON EDIT}}
if (event.channel === 'onmessage') {
if (this._options.enableWrappedPostMessage && event.args && event.args.length) {
this._onMessage.fire(event.args[0]);
}
return;
}
if (event.channel === 'did-click-link') {
let [uri] = event.args;
this._onDidClickLink.fire(URI.parse(uri));
@@ -181,7 +193,10 @@ export default class Webview {
this._disposables.push(this._webviewFindWidget);
if (parent) {
// {{SQL CARBON EDIT}}
if (!this._options.hideFind) {
parent.appendChild(this._webviewFindWidget.getDomNode());
}
parent.appendChild(this._webview);
}
}
@@ -217,6 +232,11 @@ export default class Webview {
return this._onFoundInPageResults.event;
}
// {{SQL CARBON EDIT}}
get onMessage(): Event<any> {
return this._onMessage.event;
}
private _send(channel: string, ...args: any[]): void {
this._ready
.then(() => this._webview.send(channel, ...args))

View File

@@ -160,3 +160,5 @@ import 'sql/parts/dashboard/widgets/tasks/tasksWidget.contribution';
import 'sql/parts/dashboard/dashboardConfig.contribution';
/* Tasks */
import 'sql/workbench/common/actions.contribution';
/* Extension Host */
import 'sql/workbench/api/electron-browser/sqlExtensionHost.contribution';