Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/browserView/electron-browser/browserView.contribution.ts
4779 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { localize } from '../../../../nls.js';
7
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
8
import { Registry } from '../../../../platform/registry/common/platform.js';
9
import { EditorPaneDescriptor, IEditorPaneRegistry } from '../../../browser/editor.js';
10
import { EditorExtensions, IEditorFactoryRegistry } from '../../../common/editor.js';
11
import { BrowserEditor } from './browserEditor.js';
12
import { BrowserEditorInput, BrowserEditorSerializer } from './browserEditorInput.js';
13
import { BrowserViewUri } from '../../../../platform/browserView/common/browserViewUri.js';
14
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
15
import { registerSingleton, InstantiationType } from '../../../../platform/instantiation/common/extensions.js';
16
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from '../../../../platform/configuration/common/configurationRegistry.js';
17
import { workbenchConfigurationNodeBase } from '../../../common/configuration.js';
18
import { IEditorResolverService, RegisteredEditorPriority } from '../../../services/editor/common/editorResolverService.js';
19
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js';
20
import { Schemas } from '../../../../base/common/network.js';
21
import { IBrowserViewWorkbenchService } from '../common/browserView.js';
22
import { BrowserViewWorkbenchService } from './browserViewWorkbenchService.js';
23
import { BrowserViewStorageScope } from '../../../../platform/browserView/common/browserView.js';
24
25
// Register actions
26
import './browserViewActions.js';
27
28
Registry.as<IEditorPaneRegistry>(EditorExtensions.EditorPane).registerEditorPane(
29
EditorPaneDescriptor.create(
30
BrowserEditor,
31
BrowserEditor.ID,
32
localize('browser.editorLabel', "Browser")
33
),
34
[
35
new SyncDescriptor(BrowserEditorInput)
36
]
37
);
38
39
Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerEditorSerializer(
40
BrowserEditorInput.ID,
41
BrowserEditorSerializer
42
);
43
44
class BrowserEditorResolverContribution implements IWorkbenchContribution {
45
static readonly ID = 'workbench.contrib.browserEditorResolver';
46
47
constructor(
48
@IEditorResolverService editorResolverService: IEditorResolverService,
49
@IInstantiationService instantiationService: IInstantiationService
50
) {
51
editorResolverService.registerEditor(
52
`${Schemas.vscodeBrowser}:/**`,
53
{
54
id: BrowserEditorInput.ID,
55
label: localize('browser.editorLabel', "Browser"),
56
priority: RegisteredEditorPriority.exclusive
57
},
58
{
59
canSupportResource: resource => resource.scheme === Schemas.vscodeBrowser,
60
singlePerResource: true
61
},
62
{
63
createEditorInput: ({ resource, options }) => {
64
const parsed = BrowserViewUri.parse(resource);
65
if (!parsed) {
66
throw new Error(`Invalid browser view resource: ${resource.toString()}`);
67
}
68
69
const browserInput = instantiationService.createInstance(BrowserEditorInput, {
70
id: parsed.id,
71
url: parsed.url
72
});
73
74
// Start resolving the input right away. This will create the browser view.
75
// This allows browser views to be loaded in the background.
76
void browserInput.resolve();
77
78
return {
79
editor: browserInput,
80
options: {
81
...options,
82
pinned: !!parsed.url // pin if navigated
83
}
84
};
85
}
86
}
87
);
88
}
89
}
90
91
registerWorkbenchContribution2(BrowserEditorResolverContribution.ID, BrowserEditorResolverContribution, WorkbenchPhase.BlockStartup);
92
93
registerSingleton(IBrowserViewWorkbenchService, BrowserViewWorkbenchService, InstantiationType.Delayed);
94
95
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
96
...workbenchConfigurationNodeBase,
97
properties: {
98
'workbench.browser.dataStorage': {
99
type: 'string',
100
enum: [
101
BrowserViewStorageScope.Global,
102
BrowserViewStorageScope.Workspace,
103
BrowserViewStorageScope.Ephemeral
104
],
105
markdownEnumDescriptions: [
106
localize({ 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.'),
107
localize({ 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.'),
108
localize({ 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.')
109
],
110
restricted: true,
111
default: BrowserViewStorageScope.Global,
112
markdownDescription: localize(
113
{ comment: ['This is the description for a setting. Values surrounded by single quotes are not to be translated.'], key: 'browser.dataStorage' },
114
'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.'
115
),
116
scope: ConfigurationScope.WINDOW,
117
order: 100
118
}
119
}
120
});
121
122