提交 ae4a7512 编写于 作者: R rebornix

Allow multiple api acquire

上级 56660bef
......@@ -297,6 +297,7 @@ export class BackLayerWebView extends Disposable {
const webview = webviewService.createWebviewElement('' + UUID.generateUuid(), {
enableFindWidget: false,
}, {
allowMultipleAPIAcquire: true,
allowScripts: true,
localResourceRoots: this.localResourceRootsCache
});
......@@ -409,6 +410,7 @@ export class BackLayerWebView extends Disposable {
const mixedResourceRoots = [...(this.localResourceRootsCache || []), ...this.rendererRootsCache];
this.webview.contentOptions = {
allowMultipleAPIAcquire: true,
allowScripts: true,
enableCommandUris: true,
localResourceRoots: mixedResourceRoots
......
......@@ -128,7 +128,7 @@
* @param {*} [state]
* @return {string}
*/
function getVsCodeApiScript(state) {
function getVsCodeApiScript(allowMultipleAPIAcquire, state) {
return `
const acquireVsCodeApi = (function() {
const originalPostMessage = window.parent.postMessage.bind(window.parent);
......@@ -138,7 +138,7 @@
let state = ${state ? `JSON.parse(${JSON.stringify(state)})` : undefined};
return () => {
if (acquired) {
if (acquired && !${allowMultipleAPIAcquire}) {
throw new Error('An instance of the VS Code API has already been acquired');
}
acquired = true;
......@@ -325,7 +325,7 @@
if (options.allowScripts) {
const defaultScript = newDocument.createElement('script');
defaultScript.id = '_vscodeApiScript';
defaultScript.textContent = getVsCodeApiScript(data.state);
defaultScript.textContent = getVsCodeApiScript(options.allowMultipleAPIAcquire, data.state);
newDocument.head.prepend(defaultScript);
}
......
......@@ -59,6 +59,7 @@ export interface WebviewOptions {
}
export interface WebviewContentOptions {
readonly allowMultipleAPIAcquire?: boolean;
readonly allowScripts?: boolean;
readonly localResourceRoots?: ReadonlyArray<URI>;
readonly portMapping?: ReadonlyArray<modes.IWebviewPortMapping>;
......
......@@ -36,6 +36,7 @@ export function areWebviewInputOptionsEqual(a: WebviewInputOptions, b: WebviewIn
return a.enableCommandUris === b.enableCommandUris
&& a.enableFindWidget === b.enableFindWidget
&& a.allowScripts === b.allowScripts
&& a.allowMultipleAPIAcquire === b.allowMultipleAPIAcquire
&& a.retainContextWhenHidden === b.retainContextWhenHidden
&& a.tryRestoreScrollPosition === b.tryRestoreScrollPosition
&& equals(a.localResourceRoots, b.localResourceRoots, isEqual)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册