-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support browser.proxy.onRequest. Fix #1456.
This commit also refactors other implementations and moves them to dedicated files, using feature detection to select one on runtime.
- Loading branch information
1 parent
7a6cc98
commit 465c98f
Showing
10 changed files
with
345 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
omega-target-chromium-extension/src/module/proxy/index.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
ListenerProxyImpl = require('./proxy_impl_listener') | ||
SettingsProxyImpl = require('./proxy_impl_settings') | ||
ScriptProxyImpl = require('./proxy_impl_script') | ||
|
||
exports.proxyImpls = [ListenerProxyImpl, ScriptProxyImpl, SettingsProxyImpl] | ||
exports.getProxyImpl = (log) -> | ||
for Impl in exports.proxyImpls | ||
if Impl.isSupported() | ||
return new Impl(log) | ||
throw new Error('Your browser does not support proxy settings!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
omega-target-chromium-extension/src/module/proxy/proxy_impl.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
OmegaTarget = require('omega-target') | ||
Promise = OmegaTarget.Promise | ||
ProxyAuth = require('./proxy_auth') | ||
|
||
class ProxyImpl | ||
constructor: (log) -> | ||
@log = log | ||
@isSupported: -> false | ||
applyProfile: (profile, meta) -> Promise.reject() | ||
watchProxyChange: (callback) -> null | ||
_profileNotFound: (name) -> | ||
@log.error("Profile #{name} not found! Things may go very, very wrong.") | ||
return OmegaPac.Profiles.create({ | ||
name: name | ||
profileType: 'VirtualProfile' | ||
defaultProfileName: 'direct' | ||
}) | ||
setProxyAuth: (profile, options) -> | ||
return Promise.try(=> | ||
@_proxyAuth ?= new ProxyAuth(@log) | ||
@_proxyAuth.listen() | ||
referenced_profiles = [] | ||
ref_set = OmegaPac.Profiles.allReferenceSet(profile, | ||
options, profileNotFound: @_profileNotFound.bind(this)) | ||
for own _, name of ref_set | ||
referenced_profiles.push(OmegaPac.Profiles.byName(name, options)) | ||
@_proxyAuth.setProxies(referenced_profiles) | ||
) | ||
getProfilePacScript: (profile, meta, options) -> | ||
meta ?= profile | ||
ast = OmegaPac.PacGenerator.script(options, profile, | ||
profileNotFound: @_profileNotFound.bind(this)) | ||
ast = OmegaPac.PacGenerator.compress(ast) | ||
script = OmegaPac.PacGenerator.ascii(ast.print_to_string()) | ||
profileName = OmegaPac.PacGenerator.ascii(JSON.stringify(meta.name)) | ||
profileName = profileName.replace(/\*/g, '\\u002a') | ||
profileName = profileName.replace(/\\/g, '\\u002f') | ||
prefix = "/*OmegaProfile*#{profileName}*#{meta.revision}*/" | ||
return prefix + script | ||
|
||
module.exports = ProxyImpl |
Oops, something went wrong.