提交 8bc1d445 编写于 作者: M Matt Bierner

Splitting webview into browser and electron-browser sections

上级 4e25bc19
......@@ -16,9 +16,9 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewInsetHandle, WebviewPanelHandle, WebviewPanelShowOptions } from 'vs/workbench/api/common/extHost.protocol';
import { editorGroupToViewColumn, EditorViewColumn, viewColumnToEditorGroup } from 'vs/workbench/api/common/shared/editor';
import { CodeInsetController } from 'vs/workbench/contrib/codeinset/electron-browser/codeInset.contribution';
import { WebviewEditor } from 'vs/workbench/contrib/webview/electron-browser/webviewEditor';
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorInput';
import { ICreateWebViewShowOptions, IWebviewEditorService, WebviewInputOptions } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorService';
import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor';
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/browser/webviewEditorInput';
import { ICreateWebViewShowOptions, IWebviewEditorService, WebviewInputOptions } from 'vs/workbench/contrib/webview/browser/webviewEditorService';
import { WebviewElement } from 'vs/workbench/contrib/webview/electron-browser/webviewElement';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/common/editorService';
......
......@@ -20,9 +20,9 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IRequestService } from 'vs/platform/request/node/request';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { addGAParameters } from 'vs/platform/telemetry/node/telemetryNodeUtils';
import { IWebviewEditorService } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorService';
import { IWebviewEditorService } from 'vs/workbench/contrib/webview/browser/webviewEditorService';
import { IEditorService, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorInput';
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/browser/webviewEditorInput';
import { KeybindingParser } from 'vs/base/common/keybindingParser';
import { CancellationToken } from 'vs/base/common/cancellation';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
......
......@@ -8,7 +8,7 @@ import { Command } from 'vs/editor/browser/editorExtensions';
import * as nls from 'vs/nls';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { WebviewEditor } from 'vs/workbench/contrib/webview/electron-browser/webviewEditor';
import { WebviewEditor } from 'vs/workbench/contrib/webview/browser/webviewEditor';
export class ShowWebViewEditorFindWidgetCommand extends Command {
public static readonly ID = 'editor.action.webvieweditor.showFind';
......
......@@ -9,7 +9,6 @@ import { Emitter, Event } from 'vs/base/common/event';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
......@@ -17,11 +16,10 @@ import { IWindowService } from 'vs/platform/windows/common/windows';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { EditorOptions } from 'vs/workbench/common/editor';
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorInput';
import { WebviewEditorInput } from 'vs/workbench/contrib/webview/browser/webviewEditorInput';
import { IWebviewService, Webview } from 'vs/workbench/contrib/webview/browser/webviewService';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
import { WebviewElement } from './webviewElement';
/** A context key that is set when the find widget in a webview is visible. */
export const KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE = new RawContextKey<boolean>('webviewFindWidgetVisible', false);
......@@ -29,7 +27,7 @@ export const KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE = new RawContextKey<
export class WebviewEditor extends BaseEditor {
protected _webview: WebviewElement | undefined;
protected _webview: Webview | undefined;
protected findWidgetVisible: IContextKey<boolean>;
public static readonly ID = 'WebviewEditor';
......@@ -50,9 +48,8 @@ export class WebviewEditor extends BaseEditor {
@ITelemetryService telemetryService: ITelemetryService,
@IThemeService themeService: IThemeService,
@IContextKeyService private _contextKeyService: IContextKeyService,
@IWorkbenchLayoutService private readonly _layoutService: IWorkbenchLayoutService,
@IWebviewService private readonly _webviewService: IWebviewService,
@IWorkspaceContextService private readonly _contextService: IWorkspaceContextService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IEditorService private readonly _editorService: IEditorService,
@IWindowService private readonly _windowService: IWindowService,
@IStorageService storageService: IStorageService
......@@ -178,7 +175,7 @@ export class WebviewEditor extends BaseEditor {
this.withWebviewElement(webview => webview.redo());
}
private withWebviewElement(f: (element: WebviewElement) => void): void {
private withWebviewElement(f: (element: Webview) => void): void {
if (this._webview) {
f(this._webview);
}
......@@ -264,7 +261,7 @@ export class WebviewEditor extends BaseEditor {
return rootPaths;
}
private getWebview(input: WebviewEditorInput): WebviewElement {
private getWebview(input: WebviewEditorInput): Webview {
if (this._webview) {
return this._webview;
}
......@@ -279,14 +276,12 @@ export class WebviewEditor extends BaseEditor {
this.findWidgetVisible = KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE.bindTo(this._contextKeyService);
}
this._webview = this._instantiationService.createInstance(WebviewElement,
this._layoutService.getContainer(Parts.EDITOR_PART),
this._webview = this._webviewService.createWebview(
{
allowSvgs: true,
extension: input.extension,
enableFindWidget: input.options.enableFindWidget
},
{});
}, {});
this._webview.mountTo(this._webviewContent);
input.webview = this._webview;
......
......@@ -11,7 +11,7 @@ import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { EditorInput, EditorModel, GroupIdentifier, IEditorInput } from 'vs/workbench/common/editor';
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
import { WebviewEvents, WebviewInputOptions } from './webviewEditorService';
import { WebviewElement, WebviewOptions } from './webviewElement';
import { Webview, WebviewOptions } from 'vs/workbench/contrib/webview/browser/webviewService';
export class WebviewEditorInput extends EditorInput {
private static handlePool = 0;
......@@ -57,7 +57,7 @@ export class WebviewEditorInput extends EditorInput {
private _currentWebviewHtml: string = '';
public _events: WebviewEvents | undefined;
private _container?: HTMLElement;
private _webview: WebviewElement | undefined;
private _webview?: Webview;
private _webviewOwner: any;
private _webviewDisposables: IDisposable[] = [];
private _group?: GroupIdentifier;
......@@ -234,11 +234,11 @@ export class WebviewEditorInput extends EditorInput {
return this._container;
}
public get webview(): WebviewElement | undefined {
public get webview(): Webview | undefined {
return this._webview;
}
public set webview(value: WebviewElement | undefined) {
public set webview(value: Webview | undefined) {
this._webviewDisposables = dispose(this._webviewDisposables);
this._webview = value;
......@@ -272,6 +272,7 @@ export class WebviewEditorInput extends EditorInput {
}
public claimWebview(owner: any) {
this._webviewOwner = owner;
}
......
......@@ -5,13 +5,13 @@
import { SimpleFindWidget } from 'vs/editor/contrib/find/simpleFindWidget';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { WebviewElement } from './webviewElement';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { Webview } from 'vs/workbench/contrib/webview/browser/webviewService';
export class WebviewFindWidget extends SimpleFindWidget {
constructor(
private _webview: WebviewElement | undefined,
private _webview: Webview | undefined,
@IContextViewService contextViewService: IContextViewService,
@IContextKeyService contextKeyService: IContextKeyService
) {
......@@ -29,7 +29,7 @@ export class WebviewFindWidget extends SimpleFindWidget {
}
const val = this.inputValue;
if (val) {
this._webview.find(val, { findNext: true, forward: !previous });
this._webview.find(val, previous);
}
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const IWebviewService = createDecorator<IWebviewService>('webviewService');
export interface IWebviewService {
_serviceBrand: any;
createWebview(
options: WebviewOptions,
contentOptions: WebviewContentOptions,
): Webview;
}
export interface WebviewPortMapping {
readonly port: number;
readonly resolvedPort: number;
}
export interface WebviewOptions {
readonly allowSvgs?: boolean;
readonly extension?: {
readonly location: URI;
readonly id?: ExtensionIdentifier;
};
readonly enableFindWidget?: boolean;
}
export interface WebviewContentOptions {
readonly allowScripts?: boolean;
readonly svgWhiteList?: string[];
readonly localResourceRoots?: ReadonlyArray<URI>;
readonly portMappings?: ReadonlyArray<WebviewPortMapping>;
}
export interface Webview {
contents: string;
options: WebviewContentOptions;
initialScrollProgress: number;
state: string | undefined;
readonly onDidFocus: Event<void>;
readonly onDidClickLink: Event<URI>;
readonly onDidScroll: Event<{ scrollYPercentage: number }>;
readonly onDidUpdateState: Event<string | undefined>;
readonly onMessage: Event<any>;
sendMessage(data: any): void;
update(
value: string,
options: WebviewContentOptions,
retainContextWhenHidden: boolean
): void;
layout(): void;
mountTo(parent: HTMLElement): void;
focus(): void;
dispose(): void;
showFind(): void;
hideFind(): void;
reload(): void;
selectAll(): void;
copy(): void;
paste(): void;
cut(): void;
undo(): void;
redo(): void;
find(value: string, previous: boolean): void;
startFind(value: string): void;
stopFind(keepSelection?: boolean): void;
}
......@@ -14,13 +14,15 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { EditorDescriptor, Extensions as EditorExtensions, IEditorRegistry } from 'vs/workbench/browser/editor';
import { Extensions as ActionExtensions, IWorkbenchActionRegistry } from 'vs/workbench/common/actions';
import { Extensions as EditorInputExtensions, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
import { WebviewEditorInputFactory } from 'vs/workbench/contrib/webview/electron-browser/webviewEditorInputFactory';
import { HideWebViewEditorFindCommand, OpenWebviewDeveloperToolsAction, ReloadWebviewAction, ShowWebViewEditorFindWidgetCommand, SelectAllWebviewEditorCommand, CopyWebviewEditorCommand, PasteWebviewEditorCommand, CutWebviewEditorCommand, UndoWebviewEditorCommand, RedoWebviewEditorCommand } from './webviewCommands';
import { WebviewEditor, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from './webviewEditor';
import { WebviewEditorInput } from './webviewEditorInput';
import { IWebviewEditorService, WebviewEditorService } from './webviewEditorService';
import { WebviewEditorInputFactory } from 'vs/workbench/contrib/webview/browser/webviewEditorInputFactory';
import { HideWebViewEditorFindCommand, OpenWebviewDeveloperToolsAction, ReloadWebviewAction, ShowWebViewEditorFindWidgetCommand, SelectAllWebviewEditorCommand, CopyWebviewEditorCommand, PasteWebviewEditorCommand, CutWebviewEditorCommand, UndoWebviewEditorCommand, RedoWebviewEditorCommand } from '../browser/webviewCommands';
import { WebviewEditor, KEYBINDING_CONTEXT_WEBVIEW_FIND_WIDGET_VISIBLE } from '../browser/webviewEditor';
import { WebviewEditorInput } from '../browser/webviewEditorInput';
import { IWebviewEditorService, WebviewEditorService } from '../browser/webviewEditorService';
import { InputFocusedContextKey } from 'vs/platform/contextkey/common/contextkeys';
import { isMacintosh } from 'vs/base/common/platform';
import { IWebviewService } from 'vs/workbench/contrib/webview/browser/webviewService';
import { WebviewService } from 'vs/workbench/contrib/webview/electron-browser/webviewService';
(Registry.as<IEditorRegistry>(EditorExtensions.Editors)).registerEditor(new EditorDescriptor(
WebviewEditor,
......@@ -33,6 +35,7 @@ Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactor
WebviewEditorInputFactory);
registerSingleton(IWebviewEditorService, WebviewEditorService, true);
registerSingleton(IWebviewService, WebviewService, true);
const webviewDeveloperCategory = localize('developer', "Developer");
......
......@@ -17,36 +17,12 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import * as colorRegistry from 'vs/platform/theme/common/colorRegistry';
import { DARK, ITheme, IThemeService, LIGHT } from 'vs/platform/theme/common/themeService';
import { registerFileProtocol, WebviewProtocol } from 'vs/workbench/contrib/webview/electron-browser/webviewProtocols';
import { areWebviewInputOptionsEqual } from './webviewEditorService';
import { WebviewFindWidget } from './webviewFindWidget';
import { areWebviewInputOptionsEqual } from '../browser/webviewEditorService';
import { WebviewFindWidget } from '../browser/webviewFindWidget';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { WebviewContentOptions, WebviewPortMapping, WebviewOptions, Webview } from 'vs/workbench/contrib/webview/browser/webviewService';
export interface WebviewPortMapping {
readonly port: number;
readonly resolvedPort: number;
}
export interface WebviewPortMapping {
readonly port: number;
readonly resolvedPort: number;
}
export interface WebviewOptions {
readonly allowSvgs?: boolean;
readonly extension?: {
readonly location: URI;
readonly id?: ExtensionIdentifier;
};
readonly enableFindWidget?: boolean;
}
export interface WebviewContentOptions {
readonly allowScripts?: boolean;
readonly svgWhiteList?: string[];
readonly localResourceRoots?: ReadonlyArray<URI>;
readonly portMappings?: ReadonlyArray<WebviewPortMapping>;
}
interface IKeydownEvent {
key: string;
......@@ -316,7 +292,7 @@ class WebviewKeyboardHandler extends Disposable {
}
export class WebviewElement extends Disposable {
export class WebviewElement extends Disposable implements Webview {
private _webview: Electron.WebviewTag;
private _ready: Promise<void>;
......@@ -640,12 +616,13 @@ export class WebviewElement extends Disposable {
*
* @param value The string to search for. Empty strings are ignored.
*/
public find(value: string, options?: Electron.FindInPageOptions): void {
public find(value: string, previous: boolean): void {
// Searching with an empty value will throw an exception
if (!value) {
return;
}
const options = { findNext: true, forward: !previous };
if (!this._findStarted) {
this.startFind(value, options);
return;
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { WebviewElement } from 'vs/workbench/contrib/webview/electron-browser/webviewElement';
import { IWorkbenchLayoutService, Parts } from 'vs/workbench/services/layout/browser/layoutService';
import { IWebviewService, WebviewOptions, WebviewContentOptions, Webview } from 'vs/workbench/contrib/webview/browser/webviewService';
export class WebviewService implements IWebviewService {
_serviceBrand: any;
constructor(
@IWorkbenchLayoutService private readonly _layoutService: IWorkbenchLayoutService,
@IInstantiationService private readonly _instantiationService: IInstantiationService,
) { }
createWebview(
options: WebviewOptions,
contentOptions: WebviewContentOptions
): Webview {
const element = this._instantiationService.createInstance(WebviewElement,
this._layoutService.getContainer(Parts.EDITOR_PART),
options,
contentOptions);
return element;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册