提交 de6af75d 编写于 作者: M Matt Bierner

Basic modifications to get webview resources loading

上级 71145e6a
......@@ -23,7 +23,8 @@
};
window.addEventListener('message', (e) => {
if (e.origin === 'TODO - Does this come from the inner iframe we created?') {
if (e.data && (e.data.command === 'onmessage' || e.data.command === 'do-update-state')) {
// Came from inner iframe
postMessageToVsCode(e.data.command, e.data.data);
return;
}
......@@ -46,7 +47,7 @@
handlers[channel] = handler;
},
preProcessHtml: (text) => {
return text.replace(/(?:["'])vscode-resource:([^\s'"]+)(?:["'])/gi, '/resource?path=$1');
return text.replace(/(?:["'])vscode-resource:([^\s'"]+)(?:["'])/gi, '/vscode-resource$1');
}
});
}());
......
......@@ -256,6 +256,7 @@
defaultScript.textContent = `
const acquireVsCodeApi = (function() {
const originalPostMessage = window.parent.postMessage.bind(window.parent);
const targetOrigin = window.parent.origin;
let acquired = false;
let state = ${data.state ? `JSON.parse(${JSON.stringify(data.state)})` : undefined};
......@@ -267,11 +268,11 @@
acquired = true;
return Object.freeze({
postMessage: function(msg) {
return originalPostMessage({ command: 'onmessage', data: msg }, '*');
return originalPostMessage({ command: 'onmessage', data: msg }, targetOrigin);
},
setState: function(newState) {
state = newState;
originalPostMessage({ command: 'do-update-state', data: JSON.stringify(newState) }, '*');
originalPostMessage({ command: 'do-update-state', data: JSON.stringify(newState) }, targetOrigin);
return newState;
},
getState: function() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册