提交 14f40b4c 编写于 作者: J Joao Moreno

ipc: remove vscode:setHeaders

#10587
上级 caef03e4
......@@ -16,6 +16,7 @@ import { ILogService } from 'vs/code/electron-main/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { parseArgs, ParsedArgs } from 'vs/platform/environment/node/argv';
import product from 'vs/platform/product';
import { getCommonHTTPHeaders } from 'vs/platform/environment/common/http';
export interface IWindowState {
width?: number;
......@@ -180,6 +181,21 @@ export class VSCodeWindow {
this._win = new BrowserWindow(options);
this._id = this._win.id;
// TODO@joao: hook this up to some initialization routine
// this causes a race between setting the headers and doing
// a request that needs them. chances are low
getCommonHTTPHeaders().done(headers => {
if (!this._win) {
return;
}
const urls = ['https://marketplace.visualstudio.com/*', 'https://*.vsassets.io/*'];
this._win.webContents.session.webRequest.onBeforeSendHeaders({ urls }, (details, cb) => {
cb({ cancel: false, requestHeaders: objects.assign(details.requestHeaders, headers) });
});
});
if (isFullscreenOrMaximized) {
this.win.maximize();
......
......@@ -232,20 +232,6 @@ export class WindowsManager implements IWindowsMainService, IWindowEventService
}
});
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);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TPromise } from 'vs/base/common/winjs.base';
import { getMachineId } from 'vs/base/node/id';
import pkg from 'vs/platform/package';
export function getCommonHTTPHeaders(): TPromise<{ [key: string]: string; }> {
return getMachineId().then(machineId => ({
'X-Market-Client-Id': `VSCode ${pkg.version}`,
'User-Agent': `VSCode ${pkg.version}`,
'X-Market-User-Id': machineId
}));
}
\ No newline at end of file
......@@ -23,7 +23,7 @@ import pkg from 'vs/platform/package';
import product from 'vs/platform/product';
import { isVersionValid } from 'vs/platform/extensions/node/extensionValidator';
import * as url from 'url';
import { getMachineId } from 'vs/base/node/id';
import { getCommonHTTPHeaders } from 'vs/platform/environment/common/http';
interface IRawGalleryExtensionFile {
assetType: string;
......@@ -262,12 +262,8 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
private extensionsGalleryUrl: string;
@memoize
private get commonHeaders(): TPromise<{ [key: string]: string; }> {
return getMachineId().then(machineId => ({
'X-Market-Client-Id': `VSCode ${pkg.version}`,
'User-Agent': `VSCode ${pkg.version}`,
'X-Market-User-Id': machineId
}));
private get commonHTTPHeaders(): TPromise<{ [key: string]: string; }> {
return getCommonHTTPHeaders();
}
constructor(
......@@ -288,7 +284,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
}
getRequestHeaders(): TPromise<{ [key: string]: string; }> {
return this.commonHeaders;
return this.commonHTTPHeaders;
}
query(options: IQueryOptions = {}): TPromise<IPager<IGalleryExtension>> {
......@@ -338,7 +334,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
}
private queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
return this.commonHeaders
return this.commonHTTPHeaders
.then(headers => {
const data = JSON.stringify(query.raw);
......@@ -478,7 +474,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
parsedUrl.search = undefined;
parsedUrl.query['redirect'] = 'true';
return this.commonHeaders.then(headers => {
return this.commonHTTPHeaders.then(headers => {
headers = assign({}, headers, options.headers || {});
options = assign({}, options, { headers });
......
......@@ -34,7 +34,6 @@ 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';
......@@ -69,7 +68,6 @@ export class ElectronIntegration {
@IMessageService private messageService: IMessageService,
@IContextMenuService private contextMenuService: IContextMenuService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService
) {
}
......@@ -194,13 +192,6 @@ export class ElectronIntegration {
}
}
});
// Extra request headers
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; }[]> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册