mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
Rename markdown to markdown-language-features
This commit is contained in:
49
extensions/markdown-language-features/preview-src/csp.ts
Normal file
49
extensions/markdown-language-features/preview-src/csp.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { getSettings } from './settings';
|
||||
import { getStrings } from './strings';
|
||||
import { postCommand } from './messaging';
|
||||
|
||||
/**
|
||||
* Shows an alert when there is a content security policy violation.
|
||||
*/
|
||||
export class CspAlerter {
|
||||
private didShow = false;
|
||||
|
||||
constructor() {
|
||||
document.addEventListener('securitypolicyviolation', () => {
|
||||
this.showCspWarning();
|
||||
});
|
||||
|
||||
window.addEventListener('message', (event) => {
|
||||
if (event && event.data && event.data.name === 'vscode-did-block-svg') {
|
||||
this.showCspWarning();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private showCspWarning() {
|
||||
const strings = getStrings();
|
||||
const settings = getSettings();
|
||||
|
||||
if (this.didShow || settings.disableSecurityWarnings) {
|
||||
return;
|
||||
}
|
||||
this.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 = () => {
|
||||
postCommand('markdown.showPreviewSecuritySelector', [settings.source]);
|
||||
};
|
||||
document.body.appendChild(notification);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user