Skip to content

Commit

Permalink
Log missing csp on extension host instead of main window
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Aug 26, 2019
1 parent f3e9e7c commit 78879b6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/vs/workbench/api/browser/mainThreadWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
}
webview.webview.state = newState;
});
input.webview.onMissingCsp((extension: ExtensionIdentifier) => this._proxy.$onMissingCsp(handle, extension.value));
}

private updateWebviewViewStates() {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ export interface WebviewPanelViewStateData {

export interface ExtHostWebviewsShape {
$onMessage(handle: WebviewPanelHandle, message: any): void;
$onMissingCsp(handle: WebviewPanelHandle, extensionId: string): void;
$onDidChangeWebviewPanelViewStates(newState: WebviewPanelViewStateData): void;
$onDidDisposeWebviewPanel(handle: WebviewPanelHandle): Promise<void>;
$deserializeWebviewPanel(newWebviewHandle: WebviewPanelHandle, viewType: string, title: string, state: any, position: EditorViewColumn, options: modes.IWebviewOptions & modes.IWebviewPanelOptions): Promise<void>;
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/api/common/extHostWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ export class ExtHostWebviews implements ExtHostWebviewsShape {
}
}

public $onMissingCsp(
_handle: WebviewPanelHandle,
extensionId: string
): void {
console.warn(`${extensionId} created a webview without a content security policy: https://aka.ms/vscode-webview-missing-csp`);
}

public $onDidChangeWebviewPanelViewStates(newStates: WebviewPanelViewStateData): void {
const handles = Object.keys(newStates);
// Notify webviews of state changes in the following order:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { memoize } from 'vs/base/common/decorators';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable, DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IWebviewService, Webview, WebviewContentOptions, WebviewEditorOverlay, WebviewElement, WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview';
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
import { memoize } from 'vs/base/common/decorators';

/**
* Webview editor overlay that creates and destroys the underlying webview as needed.
Expand Down Expand Up @@ -76,6 +77,7 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd
webview.onDidFocus(() => { this._onDidFocus.fire(); }, undefined, this._webviewEvents);
webview.onDidClickLink(x => { this._onDidClickLink.fire(x); }, undefined, this._webviewEvents);
webview.onMessage(x => { this._onMessage.fire(x); }, undefined, this._webviewEvents);
webview.onMissingCsp(x => { this._onMissingCsp.fire(x); }, undefined, this._webviewEvents);

webview.onDidScroll(x => {
this._initialScrollProgress = x.scrollYPercentage;
Expand Down Expand Up @@ -132,6 +134,9 @@ export class DynamicWebviewEditorOverlay extends Disposable implements WebviewEd
private readonly _onMessage = this._register(new Emitter<any>());
public readonly onMessage: Event<any> = this._onMessage.event;

private readonly _onMissingCsp = this._register(new Emitter<ExtensionIdentifier>());
public readonly onMissingCsp: Event<any> = this._onMissingCsp.event;

sendMessage(data: any): void {
if (this._webview.value) {
this._webview.value.sendMessage(data);
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/webview/browser/webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export interface Webview extends IDisposable {
readonly onDidScroll: Event<{ scrollYPercentage: number }>;
readonly onDidUpdateState: Event<string | undefined>;
readonly onMessage: Event<any>;
readonly onMissingCsp: Event<ExtensionIdentifier>;

sendMessage(data: any): void;
update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import { URI } from 'vs/base/common/uri';
import * as modes from 'vs/editor/common/modes';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IFileService } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ITunnelService } from 'vs/platform/remote/common/tunnel';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ITheme, IThemeService } from 'vs/platform/theme/common/themeService';
import { Webview, WebviewContentOptions, WebviewOptions, WebviewResourceScheme } from 'vs/workbench/contrib/webview/browser/webview';
import { WebviewPortMappingManager } from 'vs/workbench/contrib/webview/common/portMapping';
import { getWebviewThemeData } from 'vs/workbench/contrib/webview/common/themeing';
import { Webview, WebviewContentOptions, WebviewOptions, WebviewResourceScheme } from 'vs/workbench/contrib/webview/browser/webview';
import { registerFileProtocol } from 'vs/workbench/contrib/webview/electron-browser/webviewProtocols';
import { areWebviewInputOptionsEqual } from '../browser/webviewEditorService';
import { WebviewFindWidget } from '../browser/webviewFindWidget';
Expand Down Expand Up @@ -426,6 +427,9 @@ export class ElectronWebviewBasedWebview extends Disposable implements Webview {
private readonly _onMessage = this._register(new Emitter<any>());
public readonly onMessage = this._onMessage.event;

private readonly _onMissingCsp = this._register(new Emitter<ExtensionIdentifier>());
public readonly onMissingCsp = this._onMissingCsp.event;

private _send(channel: string, data?: any): void {
this._ready
.then(() => {
Expand Down Expand Up @@ -522,7 +526,7 @@ export class ElectronWebviewBasedWebview extends Disposable implements Webview {

if (this._options.extension && this._options.extension.id) {
if (this._environementService.isExtensionDevelopment) {
console.warn(`${this._options.extension.id.value} created a webview without a content security policy: https://aka.ms/vscode-webview-missing-csp`);
this._onMissingCsp.fire(this._options.extension.id);
}

type TelemetryClassification = {
Expand Down

0 comments on commit 78879b6

Please sign in to comment.