Detect and prefer browser.proxy.register if available. Fix #1446.

This commit is contained in:
FelisCatus 2018-04-30 17:36:15 -07:00
parent 0cb6f516dd
commit 15b7257a80
2 changed files with 7 additions and 17 deletions

View File

@ -3,16 +3,6 @@ OmegaPac = OmegaTarget.OmegaPac
Promise = OmegaTarget.Promise Promise = OmegaTarget.Promise
querystring = require('querystring') querystring = require('querystring')
chromeApiPromisify = require('./chrome_api').chromeApiPromisify chromeApiPromisify = require('./chrome_api').chromeApiPromisify
if chrome?.proxy?.settings
proxySettings =
clearAsync: chromeApiPromisify(chrome.proxy.settings, 'clear')
setAsync: chromeApiPromisify(chrome.proxy.settings, 'set')
get: chrome.proxy.settings.get.bind(chrome.proxy.settings)
else
proxySettings =
setAsync: -> Promise.resolve()
clearAsync: -> Promise.resolve()
get: -> null
parseExternalProfile = require('./parse_external_profile') parseExternalProfile = require('./parse_external_profile')
ProxyAuth = require('./proxy_auth') ProxyAuth = require('./proxy_auth')
WebRequestMonitor = require('./web_request_monitor') WebRequestMonitor = require('./web_request_monitor')
@ -131,10 +121,10 @@ class ChromeOptions extends OmegaTarget.Options
chrome.proxy.settings.onChange.addListener @_proxyChangeListener chrome.proxy.settings.onChange.addListener @_proxyChangeListener
@_proxyChangeWatchers.push(callback) @_proxyChangeWatchers.push(callback)
applyProfileProxy: (profile, meta) -> applyProfileProxy: (profile, meta) ->
if chrome?.proxy?.settings? if browser?.proxy?.register? or browser?.proxy?.registerProxyScript?
return @applyProfileProxySettings(profile, meta)
else if browser?.proxy?.registerProxyScript?
return @applyProfileProxyScript(profile, meta) return @applyProfileProxyScript(profile, meta)
else if chrome?.proxy?.settings?
return @applyProfileProxySettings(profile, meta)
else else
ex = new Error('Your browser does not support proxy settings!') ex = new Error('Your browser does not support proxy settings!')
return Promise.reject ex return Promise.reject ex
@ -143,7 +133,7 @@ class ChromeOptions extends OmegaTarget.Options
if profile.profileType == 'SystemProfile' if profile.profileType == 'SystemProfile'
# Clear proxy settings, returning proxy control to Chromium. # Clear proxy settings, returning proxy control to Chromium.
return chromeApiPromisify(chrome.proxy.settings, 'clear')({}).then => return chromeApiPromisify(chrome.proxy.settings, 'clear')({}).then =>
proxySettings.get {}, @_proxyChangeListener chrome.proxy.settings.get {}, @_proxyChangeListener
return return
config = {} config = {}
if profile.profileType == 'DirectProfile' if profile.profileType == 'DirectProfile'
@ -177,9 +167,9 @@ class ChromeOptions extends OmegaTarget.Options
@_proxyAuth ?= new ProxyAuth(this) @_proxyAuth ?= new ProxyAuth(this)
@_proxyAuth.listen() @_proxyAuth.listen()
@_proxyAuth.setProxies(@_watchingProfiles) @_proxyAuth.setProxies(@_watchingProfiles)
proxySettings.setAsync({value: config}) chromeApiPromisify(chrome.proxy.settings, 'set')({value: config})
).then => ).then =>
proxySettings.get {}, @_proxyChangeListener chrome.proxy.settings.get {}, @_proxyChangeListener
return return
_proxyScriptUrl: 'js/omega_webext_proxy_script.min.js' _proxyScriptUrl: 'js/omega_webext_proxy_script.min.js'

View File

@ -3,7 +3,7 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
$timeout, $location, $filter, getAttachedName, isProfileNameReserved, $timeout, $location, $filter, getAttachedName, isProfileNameReserved,
isProfileNameHidden, dispNameFilter, downloadFile) -> isProfileNameHidden, dispNameFilter, downloadFile) ->
if not chrome?.proxy?.settings? if browser?.proxy?.register? or browser?.proxy?.registerProxyScript?
$scope.isExperimental = true $scope.isExperimental = true
$scope.pacProfilesUnsupported = true $scope.pacProfilesUnsupported = true