Start work on proxies
This commit is contained in:
parent
24f893c043
commit
207cdebb2e
7 changed files with 87 additions and 1 deletions
|
@ -34,7 +34,8 @@
|
|||
"clipboardRead",
|
||||
"notifications",
|
||||
"bookmarks",
|
||||
"browserSettings"
|
||||
"browserSettings",
|
||||
"proxy"
|
||||
],
|
||||
"web_accessible_resources": [
|
||||
"build/console.html",
|
||||
|
|
|
@ -47,6 +47,8 @@ export default class CommandController {
|
|||
return this.completionsUseCase.queryBdeleteForce(name, keywords);
|
||||
case 'set':
|
||||
return this.completionsUseCase.querySet(name, keywords);
|
||||
case 'proxy':
|
||||
return this.completionsUseCase.queryProxy(name, keywords);
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
@ -99,6 +101,8 @@ export default class CommandController {
|
|||
case 'h':
|
||||
case 'help':
|
||||
return this.commandIndicator.help();
|
||||
case 'proxy':
|
||||
return this.commandIndicator.proxy(keywords);
|
||||
}
|
||||
throw new Error(words[0] + ' command is not defined');
|
||||
}
|
||||
|
|
|
@ -9,4 +9,5 @@ export default {
|
|||
quit: 'Close the current tab',
|
||||
quitall: 'Close all tabs',
|
||||
help: 'Open Vim Vixen help in new tab',
|
||||
proxy: 'Set a proxy'
|
||||
} as {[key: string]: string};
|
||||
|
|
|
@ -17,6 +17,17 @@ declare namespace browser.browserSettings.homepageOverride {
|
|||
function get(param: object): Promise<BrowserSettings>;
|
||||
}
|
||||
|
||||
declare namespace browser.proxy.settings {
|
||||
|
||||
type BrowserSettings = {
|
||||
value: string;
|
||||
};
|
||||
|
||||
function get(param: object): Promise<BrowserSettings>;
|
||||
function set(param: object): Promise<any>;
|
||||
function clear(param: object): Promise<any>;
|
||||
}
|
||||
|
||||
@injectable()
|
||||
export default class BrowserSettingRepository {
|
||||
async getHomepageUrls(): Promise<string[]> {
|
||||
|
@ -24,3 +35,25 @@ export default class BrowserSettingRepository {
|
|||
return value.split('|').map(urls.normalizeUrl);
|
||||
}
|
||||
}
|
||||
|
||||
export class ProxyRepository {
|
||||
private clearProxySettings(): Promise<any>{
|
||||
return browser.proxy.settings.clear({});
|
||||
}
|
||||
|
||||
private setProxySettings(address: string): Promise<any>{
|
||||
return browser.proxy.settings.set({value: {
|
||||
proxyType: "manual",
|
||||
http: address,
|
||||
httpProxyAll: true
|
||||
}});
|
||||
}
|
||||
|
||||
set(address: string): Promise<any> {
|
||||
if( address.toLowerCase() == 'none' ){
|
||||
return this.clearProxySettings();
|
||||
}
|
||||
return this.setProxySettings(address);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import BookmarkRepository from '../repositories/BookmarkRepository';
|
|||
import ConsoleClient from '../infrastructures/ConsoleClient';
|
||||
import ContentMessageClient from '../infrastructures/ContentMessageClient';
|
||||
import RepeatUseCase from '../usecases/RepeatUseCase';
|
||||
import { ProxyRepository } from '../repositories/BrowserSettingRepository';
|
||||
|
||||
@injectable()
|
||||
export default class CommandIndicator {
|
||||
|
@ -22,6 +23,7 @@ export default class CommandIndicator {
|
|||
private consoleClient: ConsoleClient,
|
||||
private contentMessageClient: ContentMessageClient,
|
||||
private repeatUseCase: RepeatUseCase,
|
||||
private proxyRepository: ProxyRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -142,6 +144,13 @@ export default class CommandIndicator {
|
|||
return this.helpPresenter.open();
|
||||
}
|
||||
|
||||
async proxy(keywords: string): Promise<any> {
|
||||
if (keywords.length === 0) {
|
||||
return this.proxyRepository.set('none');
|
||||
}
|
||||
return this.proxyRepository.set(keywords);
|
||||
}
|
||||
|
||||
private async urlOrSearch(keywords: string): Promise<any> {
|
||||
let settings = await this.settingRepository.get();
|
||||
return urls.searchUrl(keywords, settings.search);
|
||||
|
|
|
@ -217,4 +217,36 @@ export default class CompletionsUseCase {
|
|||
url: page.url
|
||||
}));
|
||||
}
|
||||
|
||||
async queryProxyItems(name: string, keywords: string) {
|
||||
let proxies = [{
|
||||
caption: "burp",
|
||||
url: "127.0.0.1:8080"
|
||||
},{
|
||||
caption: "none",
|
||||
url: "none"
|
||||
} ].filter(proxy=>{
|
||||
if( keywords == '' ){ return true; }
|
||||
if( proxy.caption.startsWith(keywords) ){ return true; }
|
||||
if( proxy.url.startsWith(keywords) ){ return true; }
|
||||
return false;
|
||||
});
|
||||
return proxies;
|
||||
return proxies.map(proxy => ({
|
||||
caption: proxy.caption,
|
||||
content: name + ' ' + proxy.url,
|
||||
url: proxy.url
|
||||
}));
|
||||
}
|
||||
|
||||
async queryProxy(name: string, keywords: string): Promise<CompletionGroup[]> {
|
||||
let groups: CompletionGroup[] = [];
|
||||
let items = await this.queryProxyItems( name, keywords );
|
||||
groups.push({
|
||||
name: 'Saved Proxies',
|
||||
items: items
|
||||
});
|
||||
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import validate from './validate';
|
|||
export type SettingsJSON = {
|
||||
keymaps?: KeymapsJSON,
|
||||
search?: SearchJSON,
|
||||
//proxies?: ProxiesJSON,
|
||||
properties?: PropertiesJSON,
|
||||
blacklist?: BlacklistJSON,
|
||||
};
|
||||
|
@ -162,5 +163,10 @@ export const DefaultSettingJSONText = `{
|
|||
]
|
||||
}`;
|
||||
|
||||
//"proxies": {
|
||||
// "burp": "127.0.0.1:8080",
|
||||
// "none": "none"
|
||||
//},
|
||||
|
||||
export const DefaultSetting: Settings =
|
||||
Settings.fromJSON(JSON.parse(DefaultSettingJSONText));
|
||||
|
|
Reference in a new issue