mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 22:12:26 +01:00
* Webview API prototype 3 Part of #43713 Third try at refining the webview api. This pass reworks #44165. Major changes: - Adds an `id` field to webviews. The id is provided by the extension and identifies the webview. It is used with the new event handling apis. - Adds a new `onDidChangeActiveEditor` api. This is similar to `onDidChangeActiveTextEditor` but is also fired when you change webviews. It replaces the old `onFocus` and `onBlur` events on the webview itself - Adds an `onDispose` event ot webviews. This is fired when a webview is closed by the user - Perist webview state when the editor group changes. This is enabled for all webviews, not just those with keep alive. * Throw error when trying to access disposed webview * Improving webview documentation * Clean up dispose management * Throw if we receive a bad handle * Move more event handling to input * Simplify input updating * Remove extra container property * Fixing md security alert button * Remove extra update container call * Restore syncing of preview to active editor * Fixing posting to webview * Debounce preview updates * Remove previewUri * Enable direct window.postMessage instead of window.parent.postMessage * Fixing scroll position not preserved when updating previews * Revert parent.postMessage change. Old behavior was correct * Properly hide webview container on tab switch * Make sure we only handle scroll events for the correct document * Don't try setting negative scroll * Revert vs code whitespace change
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
'use strict';
|
|
|
|
(function () {
|
|
const settings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-settings'));
|
|
const strings = JSON.parse(document.getElementById('vscode-markdown-preview-data').getAttribute('data-strings'));
|
|
|
|
let didShow = false;
|
|
|
|
const showCspWarning = () => {
|
|
if (didShow || settings.disableSecurityWarnings) {
|
|
return;
|
|
}
|
|
didShow = true;
|
|
|
|
const notification = document.createElement('a');
|
|
notification.innerText = strings.cspAlertMessageText;
|
|
notification.setAttribute('id', 'code-csp-warning');
|
|
notification.setAttribute('title', strings.cspAlertMessageTitle);
|
|
|
|
notification.setAttribute('role', 'button');
|
|
notification.setAttribute('aria-label', strings.cspAlertMessageLabel);
|
|
notification.onclick = () => {
|
|
window.parent.postMessage({
|
|
command: 'markdown.showPreviewSecuritySelector',
|
|
args: [settings.source]
|
|
}, '*');
|
|
};
|
|
document.body.appendChild(notification);
|
|
};
|
|
|
|
document.addEventListener('securitypolicyviolation', () => {
|
|
showCspWarning();
|
|
});
|
|
|
|
window.addEventListener('message', (event) => {
|
|
if (event && event.data && event.data.name === 'vscode-did-block-svg') {
|
|
showCspWarning();
|
|
}
|
|
});
|
|
}()); |