From 4d9fe432c3c42950a987788f1a2b3093cd2f62f3 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Fri, 21 Oct 2016 11:33:27 +0200 Subject: [PATCH] send gallery requests for all URLs fixes #14139 --- src/vs/code/electron-main/windows.ts | 14 ++++++++++++++ .../common/extensionManagement.ts | 1 + .../node/extensionGalleryService.ts | 4 ++++ src/vs/workbench/electron-browser/integration.ts | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/src/vs/code/electron-main/windows.ts b/src/vs/code/electron-main/windows.ts index 2171303a5eb..aabf064105f 100644 --- a/src/vs/code/electron-main/windows.ts +++ b/src/vs/code/electron-main/windows.ts @@ -422,6 +422,20 @@ export class WindowsManager implements IWindowsService { } }); + ipc.on('vscode:setHeaders', (event, windowId: number, urls: string[], headers: any) => { + this.logService.log('IPC#vscode:setHeaders'); + + const vscodeWindow = this.getWindowById(windowId); + + if (!vscodeWindow || !urls || !urls.length || !headers) { + return; + } + + vscodeWindow.win.webContents.session.webRequest.onBeforeSendHeaders({ urls }, (details, cb) => { + cb({ cancel: false, requestHeaders: assign(details.requestHeaders, headers) }); + }); + }); + ipc.on('vscode:broadcast', (event, windowId: number, target: string, broadcast: { channel: string; payload: any; }) => { if (broadcast.channel && !types.isUndefinedOrNull(broadcast.payload)) { this.logService.log('IPC#vscode:broadcast', target, broadcast.channel, broadcast.payload); diff --git a/src/vs/platform/extensionManagement/common/extensionManagement.ts b/src/vs/platform/extensionManagement/common/extensionManagement.ts index 71a90178609..96bbe6beb85 100644 --- a/src/vs/platform/extensionManagement/common/extensionManagement.ts +++ b/src/vs/platform/extensionManagement/common/extensionManagement.ts @@ -191,6 +191,7 @@ export interface IQueryOptions { export interface IExtensionGalleryService { _serviceBrand: any; isEnabled(): boolean; + getRequestHeaders(): TPromise<{ [key: string]: string; }>; query(options?: IQueryOptions): TPromise>; download(extension: IGalleryExtension): TPromise; getAsset(url: string): TPromise; diff --git a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts index 32bfbca9b20..3c7e702fef8 100644 --- a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts +++ b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts @@ -293,6 +293,10 @@ export class ExtensionGalleryService implements IExtensionGalleryService { return !!this.extensionsGalleryUrl; } + getRequestHeaders(): TPromise<{ [key: string]: string; }> { + return this.commonHeaders; + } + query(options: IQueryOptions = {}): TPromise> { if (!this.isEnabled()) { return TPromise.wrapError(new Error('No extension gallery service configured.')); diff --git a/src/vs/workbench/electron-browser/integration.ts b/src/vs/workbench/electron-browser/integration.ts index c5b11e1d9ad..b23d999bd56 100644 --- a/src/vs/workbench/electron-browser/integration.ts +++ b/src/vs/workbench/electron-browser/integration.ts @@ -34,6 +34,7 @@ import { IPath, IOpenFileRequest, IWindowConfiguration } from 'vs/workbench/elec import { IResourceInput } from 'vs/platform/editor/common/editor'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; +import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement'; import URI from 'vs/base/common/uri'; import { ipcRenderer as ipc, webFrame, remote } from 'electron'; @@ -68,6 +69,7 @@ export class ElectronIntegration { @IMessageService private messageService: IMessageService, @IContextMenuService private contextMenuService: IContextMenuService, @IWorkbenchEditorService private editorService: IWorkbenchEditorService, + @IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService, @IUntitledEditorService private untitledEditorService: IUntitledEditorService ) { } @@ -192,6 +194,11 @@ export class ElectronIntegration { } } }); + + this.extensionGalleryService.getRequestHeaders().done(headers => { + const urls = ['https://marketplace.visualstudio.com/*', 'https://*.vsassets.io/*']; + ipc.send('vscode:setHeaders', this.windowService.getWindowId(), urls, headers); + }); } private resolveKeybindings(actionIds: string[]): TPromise<{ id: string; binding: number; }[]> { -- GitLab