Skip to content

Commit

Permalink
Merge pull request #98628 from microsoft/ben/gh-pr
Browse files Browse the repository at this point in the history
Introduce electron-sandbox
  • Loading branch information
bpasero authored May 27, 2020
2 parents 876f2e7 + aa1adb6 commit 9451800
Show file tree
Hide file tree
Showing 138 changed files with 1,504 additions and 669 deletions.
181 changes: 153 additions & 28 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,18 @@
"browser": [
"common"
],
"electron-main": [
"electron-sandbox": [
"common",
"node"
"browser"
],
"electron-browser": [
"common",
"browser",
"node",
"electron-sandbox"
],
"electron-main": [
"common",
"node"
]
}
Expand Down Expand Up @@ -104,6 +109,14 @@
"**/vs/base/{common,browser}/**"
]
},
{
"target": "**/vs/base/electron-sandbox/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/{common,browser,electron-sandbox}/**"
]
},
{
"target": "**/vs/base/node/**",
"restrictions": [
Expand Down Expand Up @@ -149,13 +162,22 @@
"*" // node modules
]
},
{
"target": "**/vs/base/parts/*/electron-sandbox/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/{common,browser,electron-sandbox}/**",
"**/vs/base/parts/*/{common,browser,electron-sandbox}/**"
]
},
{
"target": "**/vs/base/parts/*/electron-browser/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/{common,browser,node,electron-browser}/**",
"**/vs/base/parts/*/{common,browser,node,electron-browser}/**",
"**/vs/base/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/base/parts/*/{common,browser,node,electron-sandbox,electron-browser}/**",
"*" // node modules
]
},
Expand Down Expand Up @@ -210,14 +232,24 @@
"*" // node modules
]
},
{
"target": "**/vs/platform/*/electron-sandbox/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/{common,browser,electron-sandbox}/**",
"**/vs/base/parts/*/{common,browser,electron-sandbox}/**",
"**/vs/platform/*/{common,browser,electron-sandbox}/**"
]
},
{
"target": "**/vs/platform/*/electron-browser/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/{common,browser,node}/**",
"**/vs/base/parts/*/{common,browser,node,electron-browser}/**",
"**/vs/platform/*/{common,browser,node,electron-browser}/**",
"**/vs/base/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/base/parts/*/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/platform/*/{common,browser,node,electron-sandbox,electron-browser}/**",
"*" // node modules
]
},
Expand Down Expand Up @@ -421,18 +453,34 @@
"**/vs/**/{common,worker}/**"
]
},
{
"target": "**/vs/workbench/electron-sandbox/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/{common,browser,electron-sandbox}/**",
"**/vs/base/parts/*/{common,browser,electron-sandbox}/**",
"**/vs/platform/*/{common,browser,electron-sandbox}/**",
"**/vs/editor/{common,browser,electron-sandbox}/**",
"**/vs/editor/contrib/**", // editor/contrib is equivalent to /browser/ by convention
"**/vs/workbench/{common,browser,electron-sandbox}/**",
"**/vs/workbench/api/{common,browser,electron-sandbox}/**",
"**/vs/workbench/services/*/{common,browser,electron-sandbox}/**"
]
},
{
"target": "**/vs/workbench/electron-browser/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/{common,browser,node,electron-browser}/**",
"**/vs/base/parts/*/{common,browser,node,electron-browser}/**",
"**/vs/platform/*/{common,browser,node,electron-browser}/**",
"**/vs/editor/{common,browser,node,electron-browser}/**",
"**/vs/base/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/base/parts/*/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/platform/*/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/editor/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/editor/contrib/**", // editor/contrib is equivalent to /browser/ by convention
"**/vs/workbench/{common,browser,node,electron-browser,api}/**",
"**/vs/workbench/services/*/{common,browser,node,electron-browser}/**",
"**/vs/workbench/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/workbench/api/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/workbench/services/*/{common,browser,node,electron-sandbox,electron-browser}/**",
"*" // node modules
]
},
Expand All @@ -444,7 +492,7 @@
"**/vs/base/**",
"**/vs/platform/**",
"**/vs/editor/**",
"**/vs/workbench/{common,browser,node,electron-browser}/**",
"**/vs/workbench/{common,browser,node,electron-sandbox,electron-browser}/**",
"vs/workbench/contrib/files/common/editors/fileEditorInput",
"**/vs/workbench/services/**",
"**/vs/workbench/test/**",
Expand Down Expand Up @@ -508,16 +556,30 @@
"*" // node modules
]
},
{
"target": "**/vs/workbench/services/**/electron-sandbox/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/**/{common,browser,worker,electron-sandbox}/**",
"**/vs/platform/**/{common,browser,electron-sandbox}/**",
"**/vs/editor/**",
"**/vs/workbench/{common,browser,electron-sandbox}/**",
"**/vs/workbench/api/{common,browser,electron-sandbox}/**",
"**/vs/workbench/services/**/{common,browser,electron-sandbox}/**"
]
},
{
"target": "**/vs/workbench/services/**/electron-browser/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/**/{common,browser,worker,node,electron-browser}/**",
"**/vs/platform/**/{common,browser,node,electron-browser}/**",
"**/vs/base/**/{common,browser,worker,node,electron-sandbox,electron-browser}/**",
"**/vs/platform/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/editor/**",
"**/vs/workbench/{common,browser,node,electron-browser,api}/**",
"**/vs/workbench/services/**/{common,browser,node,electron-browser}/**",
"**/vs/workbench/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/workbench/api/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/workbench/services/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"*" // node modules
]
},
Expand All @@ -530,7 +592,7 @@
"**/vs/base/**",
"**/vs/platform/**",
"**/vs/editor/**",
"**/vs/workbench/{common,browser,node,electron-browser}/**",
"**/vs/workbench/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/workbench/services/**",
"**/vs/workbench/contrib/**",
"**/vs/workbench/test/**",
Expand Down Expand Up @@ -624,17 +686,32 @@
"*" // node modules
]
},
{
"target": "**/vs/workbench/contrib/**/electron-sandbox/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/**/{common,browser,worker,electron-sandbox}/**",
"**/vs/platform/**/{common,browser,electron-sandbox}/**",
"**/vs/editor/**",
"**/vs/workbench/{common,browser,electron-sandbox}/**",
"**/vs/workbench/api/{common,browser,electron-sandbox}/**",
"**/vs/workbench/services/**/{common,browser,electron-sandbox}/**",
"**/vs/workbench/contrib/**/{common,browser,electron-sandbox}/**"
]
},
{
"target": "**/vs/workbench/contrib/**/electron-browser/**",
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/**/{common,browser,worker,node,electron-browser}/**",
"**/vs/platform/**/{common,browser,node,electron-browser}/**",
"**/vs/base/**/{common,browser,worker,node,electron-sandbox,electron-browser}/**",
"**/vs/platform/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/editor/**",
"**/vs/workbench/{common,browser,node,electron-browser,api}/**",
"**/vs/workbench/services/**/{common,browser,node,electron-browser}/**",
"**/vs/workbench/contrib/**/{common,browser,node,electron-browser}/**",
"**/vs/workbench/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/workbench/api/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/workbench/services/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/workbench/contrib/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"*" // node modules
]
},
Expand All @@ -654,10 +731,10 @@
"restrictions": [
"vs/nls",
"vs/css!./**/*",
"**/vs/base/**/{common,browser,node,electron-browser}/**",
"**/vs/base/parts/**/{common,browser,node,electron-browser}/**",
"**/vs/platform/**/{common,browser,node,electron-browser}/**",
"**/vs/code/**/{common,browser,node,electron-browser}/**",
"**/vs/base/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/base/parts/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/platform/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/code/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"*" // node modules
]
},
Expand Down Expand Up @@ -685,6 +762,54 @@
"*" // node modules
]
},
{
"target": "**/src/vs/workbench/workbench.common.main.ts",
"restrictions": [
"vs/nls",
"**/vs/base/**/{common,browser}/**",
"**/vs/base/parts/**/{common,browser}/**",
"**/vs/platform/**/{common,browser}/**",
"**/vs/editor/**",
"**/vs/workbench/**/{common,browser}/**"
]
},
{
"target": "**/src/vs/workbench/workbench.web.main.ts",
"restrictions": [
"vs/nls",
"**/vs/base/**/{common,browser}/**",
"**/vs/base/parts/**/{common,browser}/**",
"**/vs/platform/**/{common,browser}/**",
"**/vs/editor/**",
"**/vs/workbench/**/{common,browser}/**",
"**/vs/workbench/workbench.common.main"
]
},
{
"target": "**/src/vs/workbench/workbench.sandbox.main.ts",
"restrictions": [
"vs/nls",
"**/vs/base/**/{common,browser,electron-sandbox}/**",
"**/vs/base/parts/**/{common,browser,electron-sandbox}/**",
"**/vs/platform/**/{common,browser,electron-sandbox}/**",
"**/vs/editor/**",
"**/vs/workbench/**/{common,browser,electron-sandbox}/**",
"**/vs/workbench/workbench.common.main"
]
},
{
"target": "**/src/vs/workbench/workbench.desktop.main.ts",
"restrictions": [
"vs/nls",
"**/vs/base/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/base/parts/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/platform/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/editor/**",
"**/vs/workbench/**/{common,browser,node,electron-sandbox,electron-browser}/**",
"**/vs/workbench/workbench.common.main",
"**/vs/workbench/workbench.sandbox.main"
]
},
{
"target": "**/extensions/**",
"restrictions": "**/*"
Expand Down
2 changes: 2 additions & 0 deletions build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const vscodeResources = [
'out-build/vs/base/node/languagePacks.js',
'out-build/vs/base/node/{stdForkStart.js,terminateProcess.sh,cpuUsage.sh,ps.sh}',
'out-build/vs/base/browser/ui/codicons/codicon/**',
'out-build/vs/base/parts/sandbox/electron-browser/preload.js',
'out-build/vs/workbench/browser/media/*-theme.css',
'out-build/vs/workbench/contrib/debug/**/*.json',
'out-build/vs/workbench/contrib/externalTerminal/**/*.scpt',
Expand Down Expand Up @@ -154,6 +155,7 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op
const out = sourceFolderName;

const checksums = computeChecksums(out, [
'vs/base/parts/sandbox/electron-browser/preload.js',
'vs/workbench/workbench.desktop.main.js',
'vs/workbench/workbench.desktop.main.css',
'vs/workbench/services/extensions/node/extensionHostProcess.js',
Expand Down
8 changes: 8 additions & 0 deletions build/lib/layersChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ const RULES = [
'lib.dom.d.ts' // no DOM
]
},
// Electron (sandbox)
{
target: '**/vs/**/electron-sandbox/**',
allowedTypes: CORE_TYPES,
disallowedDefinitions: [
'@types/node' // no node.js
]
},
// Electron (renderer): skip
{
target: '**/vs/**/electron-browser/**',
Expand Down
9 changes: 9 additions & 0 deletions build/lib/layersChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ const RULES = [
]
},

// Electron (sandbox)
{
target: '**/vs/**/electron-sandbox/**',
allowedTypes: CORE_TYPES,
disallowedDefinitions: [
'@types/node' // no node.js
]
},

// Electron (renderer): skip
{
target: '**/vs/**/electron-browser/**',
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/common/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ export namespace Event {
}

export interface NodeEventEmitter {
on(event: string | symbol, listener: Function): this;
removeListener(event: string | symbol, listener: Function): this;
on(event: string | symbol, listener: Function): unknown;
removeListener(event: string | symbol, listener: Function): unknown;
}

export function fromNodeEventEmitter<T>(emitter: NodeEventEmitter, eventName: string, map: (...args: any[]) => T = id => id): Event<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ipcRenderer, Event } from 'electron';
import { ipcRenderer } from 'vs/base/parts/sandbox/electron-sandbox/globals';
import { IContextMenuItem, ISerializableContextMenuItem, CONTEXT_MENU_CLOSE_CHANNEL, CONTEXT_MENU_CHANNEL, IPopupOptions, IContextMenuEvent } from 'vs/base/parts/contextmenu/common/contextmenu';

let contextMenuIdPool = 0;
Expand All @@ -13,15 +13,15 @@ export function popup(items: IContextMenuItem[], options?: IPopupOptions): void

const contextMenuId = contextMenuIdPool++;
const onClickChannel = `vscode:onContextMenu${contextMenuId}`;
const onClickChannelHandler = (_event: Event, itemId: number, context: IContextMenuEvent) => {
const onClickChannelHandler = (event: unknown, itemId: number, context: IContextMenuEvent) => {
const item = processedItems[itemId];
if (item.click) {
item.click(context);
}
};

ipcRenderer.once(onClickChannel, onClickChannelHandler);
ipcRenderer.once(CONTEXT_MENU_CLOSE_CHANNEL, (_event: Event, closedContextMenuId: number) => {
ipcRenderer.once(CONTEXT_MENU_CLOSE_CHANNEL, (event: unknown, closedContextMenuId: number) => {
if (closedContextMenuId !== contextMenuId) {
return;
}
Expand Down
Loading

0 comments on commit 9451800

Please sign in to comment.