Path: blob/main/src/vs/workbench/contrib/browserView/electron-browser/browserView.contribution.ts
4779 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { localize } from '../../../../nls.js';6import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';7import { Registry } from '../../../../platform/registry/common/platform.js';8import { EditorPaneDescriptor, IEditorPaneRegistry } from '../../../browser/editor.js';9import { EditorExtensions, IEditorFactoryRegistry } from '../../../common/editor.js';10import { BrowserEditor } from './browserEditor.js';11import { BrowserEditorInput, BrowserEditorSerializer } from './browserEditorInput.js';12import { BrowserViewUri } from '../../../../platform/browserView/common/browserViewUri.js';13import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';14import { registerSingleton, InstantiationType } from '../../../../platform/instantiation/common/extensions.js';15import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from '../../../../platform/configuration/common/configurationRegistry.js';16import { workbenchConfigurationNodeBase } from '../../../common/configuration.js';17import { IEditorResolverService, RegisteredEditorPriority } from '../../../services/editor/common/editorResolverService.js';18import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js';19import { Schemas } from '../../../../base/common/network.js';20import { IBrowserViewWorkbenchService } from '../common/browserView.js';21import { BrowserViewWorkbenchService } from './browserViewWorkbenchService.js';22import { BrowserViewStorageScope } from '../../../../platform/browserView/common/browserView.js';2324// Register actions25import './browserViewActions.js';2627Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane(28EditorPaneDescriptor.create(29BrowserEditor,30BrowserEditor.ID,31localize('browser.editorLabel', "Browser")32),33[34new SyncDescriptor(BrowserEditorInput)35]36);3738Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerEditorSerializer(39BrowserEditorInput.ID,40BrowserEditorSerializer41);4243class BrowserEditorResolverContribution implements IWorkbenchContribution {44static readonly ID = 'workbench.contrib.browserEditorResolver';4546constructor(47@IEditorResolverService editorResolverService: IEditorResolverService,48@IInstantiationService instantiationService: IInstantiationService49) {50editorResolverService.registerEditor(51`${Schemas.vscodeBrowser}:/**`,52{53id: BrowserEditorInput.ID,54label: localize('browser.editorLabel', "Browser"),55priority: RegisteredEditorPriority.exclusive56},57{58canSupportResource: resource => resource.scheme === Schemas.vscodeBrowser,59singlePerResource: true60},61{62createEditorInput: ({ resource, options }) => {63const parsed = BrowserViewUri.parse(resource);64if (!parsed) {65throw new Error(`Invalid browser view resource: ${resource.toString()}`);66}6768const browserInput = instantiationService.createInstance(BrowserEditorInput, {69id: parsed.id,70url: parsed.url71});7273// Start resolving the input right away. This will create the browser view.74// This allows browser views to be loaded in the background.75void browserInput.resolve();7677return {78editor: browserInput,79options: {80...options,81pinned: !!parsed.url // pin if navigated82}83};84}85}86);87}88}8990registerWorkbenchContribution2(BrowserEditorResolverContribution.ID, BrowserEditorResolverContribution, WorkbenchPhase.BlockStartup);9192registerSingleton(IBrowserViewWorkbenchService, BrowserViewWorkbenchService, InstantiationType.Delayed);9394Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({95...workbenchConfigurationNodeBase,96properties: {97'workbench.browser.dataStorage': {98type: 'string',99enum: [100BrowserViewStorageScope.Global,101BrowserViewStorageScope.Workspace,102BrowserViewStorageScope.Ephemeral103],104markdownEnumDescriptions: [105localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'browser.dataStorage.global' }, 'All browser views share a single persistent session across all workspaces.'),106localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'browser.dataStorage.workspace' }, 'Browser views within the same workspace share a persistent session.'),107localize({ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'browser.dataStorage.ephemeral' }, 'Each browser view has its own session that is cleaned up when closed.')108],109restricted: true,110default: BrowserViewStorageScope.Global,111markdownDescription: localize(112{ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'browser.dataStorage' },113'Controls how browser data (cookies, cache, storage) is shared between browser views.\n\n**Note**: In untrusted workspaces, this setting is ignored and `ephemeral` storage is always used.'114),115scope: ConfigurationScope.WINDOW,116order: 100117}118}119});120121122