mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
Use electron webview tag instead of WebviewElement
This commit is contained in:
@@ -17,7 +17,6 @@ import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
|
||||
import { MenuRegistry } from 'vs/platform/actions/common/actions';
|
||||
import { WebviewElement } from 'vs/workbench/parts/html/browser/webview';
|
||||
import { IExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/common/extensions';
|
||||
import { IEditorRegistry, EditorDescriptor, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
|
||||
|
||||
@@ -118,7 +117,7 @@ CommandsRegistry.registerCommand('_webview.openDevTools', function () {
|
||||
const elements = document.querySelectorAll('webview.ready');
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
try {
|
||||
(elements.item(i) as WebviewElement).openDevTools();
|
||||
(elements.item(i) as Electron.WebviewTag).openDevTools();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
@@ -16,22 +16,6 @@ import { WebviewFindWidget } from './webviewFindWidget';
|
||||
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
|
||||
import { IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
|
||||
export declare interface WebviewElement extends HTMLElement {
|
||||
src: string;
|
||||
preload: string;
|
||||
send(channel: string, ...args: any[]);
|
||||
openDevTools(): any;
|
||||
getWebContents(): any;
|
||||
findInPage(value: string, options?: WebviewElementFindInPageOptions);
|
||||
stopFindInPage(action: string);
|
||||
}
|
||||
|
||||
export class StopFindInPageActions {
|
||||
static clearSelection = 'clearSelection';
|
||||
static keepSelection = 'keepSelection';
|
||||
static activateSelection = 'activateSelection';
|
||||
}
|
||||
|
||||
export interface WebviewElementFindInPageOptions {
|
||||
forward?: boolean;
|
||||
findNext?: boolean;
|
||||
@@ -58,7 +42,7 @@ export interface WebviewOptions {
|
||||
export default class Webview {
|
||||
private static index: number = 0;
|
||||
|
||||
private _webview: WebviewElement;
|
||||
private readonly _webview: Electron.WebviewTag;
|
||||
private _ready: TPromise<this>;
|
||||
private _disposables: IDisposable[] = [];
|
||||
private _onDidClickLink = new Emitter<URI>();
|
||||
@@ -70,14 +54,14 @@ export default class Webview {
|
||||
private _findStarted: boolean = false;
|
||||
|
||||
constructor(
|
||||
private parent: HTMLElement,
|
||||
private _styleElement: Element,
|
||||
@IContextViewService private _contextViewService: IContextViewService,
|
||||
private _contextKey: IContextKey<boolean>,
|
||||
private _findInputContextKey: IContextKey<boolean>,
|
||||
private readonly parent: HTMLElement,
|
||||
private readonly _styleElement: Element,
|
||||
@IContextViewService private readonly _contextViewService: IContextViewService,
|
||||
private readonly _contextKey: IContextKey<boolean>,
|
||||
private readonly _findInputContextKey: IContextKey<boolean>,
|
||||
private _options: WebviewOptions = {},
|
||||
) {
|
||||
this._webview = <any>document.createElement('webview');
|
||||
this._webview = document.createElement('webview');
|
||||
this._webview.setAttribute('partition', this._options.allowSvgs ? 'webview' : `webview${Webview.index++}`);
|
||||
|
||||
// disable auxclick events (see https://developers.google.com/web/updates/2016/10/auxclick)
|
||||
@@ -119,7 +103,7 @@ export default class Webview {
|
||||
return;
|
||||
}
|
||||
|
||||
contents.session.webRequest.onBeforeRequest((details, callback) => {
|
||||
(contents.session.webRequest as any).onBeforeRequest((details, callback) => {
|
||||
if (details.url.indexOf('.svg') > 0) {
|
||||
const uri = URI.parse(details.url);
|
||||
if (uri && !uri.scheme.match(/file/i) && (uri.path as any).endsWith('.svg') && !this.isAllowedSvg(uri)) {
|
||||
@@ -130,7 +114,7 @@ export default class Webview {
|
||||
return callback({});
|
||||
});
|
||||
|
||||
contents.session.webRequest.onHeadersReceived((details, callback) => {
|
||||
(contents.session.webRequest as any).onHeadersReceived((details, callback) => {
|
||||
const contentType: string[] = (details.responseHeaders['content-type'] || details.responseHeaders['Content-Type']) as any;
|
||||
if (contentType && Array.isArray(contentType) && contentType.some(x => x.toLowerCase().indexOf('image/svg') >= 0)) {
|
||||
const uri = URI.parse(details.url);
|
||||
@@ -295,7 +279,6 @@ export default class Webview {
|
||||
styles['scrollbar-thumb-hover'] = 'rgba(100, 100, 100, 0.7)';
|
||||
styles['scrollbar-thumb-active'] = 'rgba(85, 85, 85, 0.8)';
|
||||
activeTheme = 'vscode-dark';
|
||||
|
||||
} else {
|
||||
styles['scrollbar-thumb'] = 'rgba(111, 195, 223, 0.3)';
|
||||
styles['scrollbar-thumb-hover'] = 'rgba(111, 195, 223, 0.8)';
|
||||
@@ -392,7 +375,7 @@ export default class Webview {
|
||||
|
||||
public stopFind(keepSelection?: boolean): void {
|
||||
this._findStarted = false;
|
||||
this._webview.stopFindInPage(keepSelection ? StopFindInPageActions.keepSelection : StopFindInPageActions.clearSelection);
|
||||
this._webview.stopFindInPage(keepSelection ? 'keepSelection' : 'clearSelection');
|
||||
}
|
||||
|
||||
public showFind() {
|
||||
|
||||
Reference in New Issue
Block a user