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

ipc: remove vscode:setHeaders

#10587
上级 caef03e4
...@@ -16,6 +16,7 @@ import { ILogService } from 'vs/code/electron-main/log'; ...@@ -16,6 +16,7 @@ import { ILogService } from 'vs/code/electron-main/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { parseArgs, ParsedArgs } from 'vs/platform/environment/node/argv'; import { parseArgs, ParsedArgs } from 'vs/platform/environment/node/argv';
import product from 'vs/platform/product'; import product from 'vs/platform/product';
import { getCommonHTTPHeaders } from 'vs/platform/environment/common/http';
export interface IWindowState { export interface IWindowState {
width?: number; width?: number;
...@@ -180,6 +181,21 @@ export class VSCodeWindow { ...@@ -180,6 +181,21 @@ export class VSCodeWindow {
this._win = new BrowserWindow(options); this._win = new BrowserWindow(options);
this._id = this._win.id; 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) { if (isFullscreenOrMaximized) {
this.win.maximize(); this.win.maximize();
......
...@@ -232,20 +232,6 @@ export class WindowsManager implements IWindowsMainService, IWindowEventService ...@@ -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; }) => { ipc.on('vscode:broadcast', (event, windowId: number, target: string, broadcast: { channel: string; payload: any; }) => {
if (broadcast.channel && !types.isUndefinedOrNull(broadcast.payload)) { if (broadcast.channel && !types.isUndefinedOrNull(broadcast.payload)) {
this.logService.log('IPC#vscode:broadcast', target, broadcast.channel, 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'; ...@@ -23,7 +23,7 @@ import pkg from 'vs/platform/package';
import product from 'vs/platform/product'; import product from 'vs/platform/product';
import { isVersionValid } from 'vs/platform/extensions/node/extensionValidator'; import { isVersionValid } from 'vs/platform/extensions/node/extensionValidator';
import * as url from 'url'; import * as url from 'url';
import { getMachineId } from 'vs/base/node/id'; import { getCommonHTTPHeaders } from 'vs/platform/environment/common/http';
interface IRawGalleryExtensionFile { interface IRawGalleryExtensionFile {
assetType: string; assetType: string;
...@@ -262,12 +262,8 @@ export class ExtensionGalleryService implements IExtensionGalleryService { ...@@ -262,12 +262,8 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
private extensionsGalleryUrl: string; private extensionsGalleryUrl: string;
@memoize @memoize
private get commonHeaders(): TPromise<{ [key: string]: string; }> { private get commonHTTPHeaders(): TPromise<{ [key: string]: string; }> {
return getMachineId().then(machineId => ({ return getCommonHTTPHeaders();
'X-Market-Client-Id': `VSCode ${pkg.version}`,
'User-Agent': `VSCode ${pkg.version}`,
'X-Market-User-Id': machineId
}));
} }
constructor( constructor(
...@@ -288,7 +284,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService { ...@@ -288,7 +284,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
} }
getRequestHeaders(): TPromise<{ [key: string]: string; }> { getRequestHeaders(): TPromise<{ [key: string]: string; }> {
return this.commonHeaders; return this.commonHTTPHeaders;
} }
query(options: IQueryOptions = {}): TPromise<IPager<IGalleryExtension>> { query(options: IQueryOptions = {}): TPromise<IPager<IGalleryExtension>> {
...@@ -338,7 +334,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService { ...@@ -338,7 +334,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
} }
private queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> { private queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
return this.commonHeaders return this.commonHTTPHeaders
.then(headers => { .then(headers => {
const data = JSON.stringify(query.raw); const data = JSON.stringify(query.raw);
...@@ -478,7 +474,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService { ...@@ -478,7 +474,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
parsedUrl.search = undefined; parsedUrl.search = undefined;
parsedUrl.query['redirect'] = 'true'; parsedUrl.query['redirect'] = 'true';
return this.commonHeaders.then(headers => { return this.commonHTTPHeaders.then(headers => {
headers = assign({}, headers, options.headers || {}); headers = assign({}, headers, options.headers || {});
options = assign({}, options, { headers }); options = assign({}, options, { headers });
......
...@@ -34,7 +34,6 @@ import { IPath, IOpenFileRequest, IWindowConfiguration } from 'vs/workbench/elec ...@@ -34,7 +34,6 @@ import { IPath, IOpenFileRequest, IWindowConfiguration } from 'vs/workbench/elec
import { IResourceInput } from 'vs/platform/editor/common/editor'; import { IResourceInput } from 'vs/platform/editor/common/editor';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; 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 URI from 'vs/base/common/uri';
import { ipcRenderer as ipc, webFrame, remote } from 'electron'; import { ipcRenderer as ipc, webFrame, remote } from 'electron';
...@@ -69,7 +68,6 @@ export class ElectronIntegration { ...@@ -69,7 +68,6 @@ export class ElectronIntegration {
@IMessageService private messageService: IMessageService, @IMessageService private messageService: IMessageService,
@IContextMenuService private contextMenuService: IContextMenuService, @IContextMenuService private contextMenuService: IContextMenuService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService, @IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService @IUntitledEditorService private untitledEditorService: IUntitledEditorService
) { ) {
} }
...@@ -194,13 +192,6 @@ export class ElectronIntegration { ...@@ -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; }[]> { 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.
先完成此消息的编辑!
想要评论请 注册