Merge pull request #1030 from FelisCatus/feature/webextension

Feature/webextension
This commit is contained in:
Felis Catus 2017-08-02 23:00:47 -04:00 committed by GitHub
commit 533a91964c
61 changed files with 507 additions and 101 deletions

View File

@ -217,6 +217,9 @@ msgstr "Restore"
msgid "options_title"
msgstr "SwitchyOmega Options"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Settings"
@ -1212,6 +1215,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -219,6 +219,9 @@ msgstr "Obnovit"
msgid "options_title"
msgstr "SwitchyOmega Nastavení"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Nastavení"
@ -1208,6 +1211,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -222,6 +222,9 @@ msgstr "Restore"
msgid "options_title"
msgstr "SwitchyOmega Options"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Settings"
@ -1217,6 +1220,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -4,7 +4,7 @@ msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-02-13 10:29+0000\n"
"PO-Revision-Date: 2015-02-17 07:02+0200\n"
"Last-Translator: FelisCatus <shyc2010@gmail.com>\n"
"Last-Translator: FelisCatus <catux@gmail.com>\n"
"Language-Team: English (United States) "
"<https://hosted.weblate.org/projects/switchyomega/main/en_US/>\n"
"Language: en_US\n"
@ -218,6 +218,9 @@ msgstr "Restore"
msgid "options_title"
msgstr "SwitchyOmega Options"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Settings"
@ -1194,6 +1197,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -222,6 +222,9 @@ msgstr "Restaurar"
msgid "options_title"
msgstr "Opciones SwitchyOmega"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Configuraciones"
@ -1217,6 +1220,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -223,6 +223,9 @@ msgstr "بازگرداندن"
msgid "options_title"
msgstr "تنظیمات SwitchyOmega"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "تنظیمات"
@ -1219,6 +1222,9 @@ msgstr "ابزار پیکربندی پراکسی"
msgid "about_version"
msgstr "نسخه $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -219,6 +219,9 @@ msgstr "Restore"
msgid "options_title"
msgstr "SwitchyOmega Options"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Settings"
@ -1214,6 +1217,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -173,6 +173,9 @@ msgstr ""
msgid "options_title"
msgstr ""
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr ""
@ -1017,6 +1020,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -214,6 +214,9 @@ msgstr "復元"
msgid "options_title"
msgstr "SwitchyOmega オプション"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "設定"
@ -1202,6 +1205,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -181,6 +181,9 @@ msgstr "Gjenopprett"
msgid "options_title"
msgstr "SwitchyOmega-valg"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Innstillinger"
@ -1055,6 +1058,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -163,6 +163,9 @@ msgstr ""
msgid "options_title"
msgstr ""
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr ""
@ -1006,6 +1009,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -218,6 +218,9 @@ msgstr "Restore"
msgid "options_title"
msgstr "SwitchyOmega Options"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Settings"
@ -1213,6 +1216,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -222,6 +222,9 @@ msgstr "Restore"
msgid "options_title"
msgstr "SwitchyOmega Options"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Settings"
@ -1217,6 +1220,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -172,6 +172,9 @@ msgstr ""
msgid "options_title"
msgstr ""
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr ""
@ -1016,6 +1019,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -174,6 +174,9 @@ msgstr ""
msgid "options_title"
msgstr ""
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr ""
@ -1018,6 +1021,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -221,6 +221,9 @@ msgstr "Restore"
msgid "options_title"
msgstr "SwitchyOmega Options"
msgid "options_experimental_badge"
msgstr "α"
msgid "options_navHeader_setting"
msgstr "Settings"
@ -1209,6 +1212,9 @@ msgstr "A proxy configuration tool"
msgid "about_version"
msgstr "Version $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox support is highly experimental! If you encounter issues, please report using the buttons below."
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega does not provide proxies, VPNs, or other network services."

View File

@ -4,7 +4,7 @@ msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-02-13 11:05+0000\n"
"PO-Revision-Date: 2015-02-15 14:52+0200\n"
"Last-Translator: FelisCatus <shyc2010@gmail.com>\n"
"Last-Translator: FelisCatus <catusx@gmail.com>\n"
"Language-Team: Chinese (China) "
"<https://hosted.weblate.org/projects/switchyomega/main/zh_CN/>\n"
"Language: zh_CN\n"
@ -200,6 +200,9 @@ msgstr "还原"
msgid "options_title"
msgstr "SwitchyOmega 选项"
msgid "options_experimental_badge"
msgstr "测试版"
msgid "options_navHeader_setting"
msgstr "设定"
@ -1070,6 +1073,9 @@ msgstr "一个代理设置工具"
msgid "about_version"
msgstr "版本 $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox 浏览器支持目前仍处于早期实验阶段!如果您遇到任何问题,请使用下方的按钮进行反馈。"
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega 不提供代理服务器、VPN等网络服务。"

View File

@ -4,7 +4,7 @@ msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-02-13 11:15+0000\n"
"PO-Revision-Date: 2015-02-28 07:52+0200\n"
"Last-Translator: FelisCatus <shyc2010@gmail.com>\n"
"Last-Translator: FelisCatus <catusx@gmail.com>\n"
"Language-Team: Chinese (Taiwan) "
"<https://hosted.weblate.org/projects/switchyomega/main/zh_TW/>\n"
"Language: zh_TW\n"
@ -200,6 +200,9 @@ msgstr "還原"
msgid "options_title"
msgstr "SwitchyOmega 選項"
msgid "options_experimental_badge"
msgstr "測試版"
msgid "options_navHeader_setting"
msgstr "設定"
@ -1070,6 +1073,9 @@ msgstr "一個代理設置工具"
msgid "about_version"
msgstr "版本 $VERSION$"
msgid "about_experimental_warning_moz"
msgstr "Mozilla Firefox 瀏覽器支持目前仍處於早期實驗階段!如果您遇到任何問題,請使用下方的按鈕進行反饋。"
msgid "about_disclaimer_networkService"
msgstr "SwitchyOmega 不提供代理伺服器、VPN等網絡服務。"

View File

@ -1,5 +1,6 @@
/index.js
/omega_target_*.min.js
/tmp
/build
/release.zip

View File

@ -1,3 +1,8 @@
module.exports = (grunt) ->
require('load-grunt-config')(grunt)
require('./grunt-po2crx')(grunt)
grunt.registerTask 'chromium-manifest', ->
manifest = grunt.file.readJSON('overlay/manifest.json')
manifest.permissions = manifest.permissions.filter (p) -> p != 'downloads'
grunt.file.write('tmp/manifest.json', JSON.stringify(manifest))

View File

@ -7,4 +7,4 @@ module.exports =
'po2crx'
]
test: ['mochaTest']
release: ['default', 'compress']
release: ['default', 'chromium-manifest', 'compress']

View File

@ -1,10 +1,11 @@
path = require('path')
module.exports =
index:
files:
'index.js': 'index.coffee'
options:
transform: ['coffeeify']
exclude: ['bluebird', 'omega-pac']
exclude: ['bluebird', 'omega-pac', 'omega-target']
browserifyOptions:
extensions: '.coffee'
builtins: []
@ -26,3 +27,17 @@ module.exports =
browserifyOptions:
extensions: '.coffee'
standalone: 'OmegaTargetChromium'
omega_webext_proxy_script:
files:
'build/js/omega_webext_proxy_script.min.js':
'src/js/omega_webext_proxy_script.js'
options:
alias:
'omega-pac': 'omega-pac/omega_pac.min.js'
plugin:
if process.env.BUILD == 'release'
[['minifyify', {map: false}]]
else
[]
browserifyOptions:
noParse: [require.resolve('omega-pac/omega_pac.min.js')]

View File

@ -1,13 +1,7 @@
module.exports =
target_web:
files:
'build/js/omega_target_web.js': 'omega_target_web.coffee'
background:
files:
'build/js/background.js': 'background.coffee'
background_preload:
files:
'build/js/background_preload.js': 'background_preload.coffee'
omega_debug:
files:
'build/js/omega_debug.js': 'omega_debug.coffee'
coffee:
expand: true
cwd: 'src/coffee'
src: ['**/*.coffee']
dest: 'build/js/'
ext: '.js'

View File

@ -3,7 +3,16 @@ module.exports =
archive: './release.zip'
mode: 'zip'
build:
cwd: 'build'
src: ['**']
expand: true
filter: 'isFile'
files: [
{
cwd: 'build'
src: ['**', '!manifest.json']
expand: true
filter: 'isFile'
}
{
cwd: 'tmp/'
src: 'manifest.json'
expand: true
}
]

View File

@ -12,6 +12,8 @@ module.exports =
src: 'omega_target_chromium_extension.min.js'
dest: 'build/js/'
target_popup:
expand: true
cwd: 'src/js'
src: 'omega_target_popup.js'
dest: 'build/js/'
overlay:

View File

@ -18,11 +18,11 @@ module.exports =
files: ['overlay/**/*']
tasks: ['copy:overlay']
copy_target_popup:
files: ['omega_target_popup.js']
files: ['src/js/omega_target_popup.js']
tasks: ['copy:target_popup']
src:
files: ['src/**/*.coffee']
tasks: ['coffeelint:src', 'browserify', 'copy:target_self']
coffee:
files: ['src/**/*.coffee', '*.coffee']
tasks: ['coffeelint:src', 'coffee', 'copy:target_self']
files: ['src/**/*.coffee']
tasks: ['coffeelint:src', 'browserify', 'coffee', 'copy:target_self']
browserify_omega_webext_proxy_script:
files: ['src/js/omega_webext_proxy_script.js']
tasks: ['browserify:omega_webext_proxy_script']

View File

@ -1,12 +1 @@
module.exports =
Storage: require('./src/storage')
Options: require('./src/options')
ChromeTabs: require('./src/tabs')
SwitchySharp: require('./src/switchysharp')
ExternalApi: require('./src/external_api.coffee')
WebRequestMonitor: require('./src/web_request_monitor')
Inspect: require('./src/inspect')
Url: require('url')
for name, value of require('omega-target')
module.exports[name] ?= value
module.exports = require('./src/module')

View File

@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "__MSG_manifest_app_name__",
"version": "2.4.5",
"version": "2.4.17",
"description": "__MSG_manifest_app_description__",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkhwZJT76btQ04EEMOFtZPLESD1TmSVjbLjs0OyesD9Ht8YllFPfJ3qmtbSQGVuvmxH1GK/jUO2QcEWb8bHuOjoRlq20fi5j5Aq90O8FKET+y5D8PxCyi3WmnquiEwaE5cNmaCsw/G2JlO+bZOtdQ/QKOvMxBAegABYimEGfSvCMVUEvpymys0gBhLoch72zPAiJUBkf0z8BtjYTueMRcRXkrSeRPLygUDQnZ1TkQWMYYBp/zqpD5ggxytAklEMQzR9Hn0lqu5s7iuUAgihbysPn/8Wh00Zj5FySpK//KcpG3JS7UWxC28oSt8z5ZR3YimnX+HX3P36V0mC1pgM4o7wIDAQAB",
"icons": {
@ -14,6 +14,7 @@
},
"default_locale": "en",
"browser_action": {
"browser_style": false,
"default_icon": {
"16": "img/icons/omega-action-16.png",
"19": "img/icons/omega-action-19.png",
@ -28,18 +29,23 @@
},
"minimum_chrome_version": "22.0.0",
"options_page": "options.html",
"options_ui": {
"page": "options.html",
"browser_style": false,
"open_in_tab": true
},
"permissions": [
"proxy",
"tabs",
"alarms",
"storage",
"webRequest",
"downloads",
"webRequestBlocking",
"contextMenus",
"http://*/*",
"https://*/*",
"ftp://*/*",
"<all_urls>"
],
"commands": {
@ -48,5 +54,11 @@
"default": "Alt+Shift+O"
}
}
},
"applications": {
"gecko": {
"id": "switchyomega@feliscatus.addons.mozilla.org",
"strict_min_version": "55.0a1"
}
}
}

View File

@ -24,12 +24,13 @@
"heap": "^0.2.6",
"omega-target": "../omega-target",
"omega-web": "../omega-web",
"omega-pac": "../omega-pac",
"xhr": "^1.16.0"
},
"browser": {
"omega-target": "./omega_target_shim.js"
},
"scripts": {
"dev": "npm link omega-target && npm link omega-web"
"dev": "npm link omega-target && npm link omega-web && npm link omega-pac"
}
}

View File

@ -147,11 +147,11 @@ actionForUrl = (url) ->
}
storage = new OmegaTargetCurrent.Storage(chrome.storage.local, 'local')
storage = new OmegaTargetCurrent.Storage('local')
state = new OmegaTargetCurrent.BrowserStorage(localStorage, 'omega.local.')
if chrome.storage.sync
syncStorage = new OmegaTargetCurrent.Storage(chrome.storage.sync, 'sync')
if chrome?.storage?.sync or browser?.storage?.sync
syncStorage = new OmegaTargetCurrent.Storage('sync')
sync = new OmegaTargetCurrent.OptionsSync(syncStorage)
if localStorage['omega.local.syncOptions'] != '"sync"'
sync.enabled = false
@ -288,10 +288,15 @@ encodeError = (obj) ->
refreshActivePageIfEnabled = ->
return if localStorage['omega.local.refreshOnProfileChange'] == 'false'
chrome.tabs.query {active: true, lastFocusedWindow: true}, (tabs) ->
if tabs[0].url and tabs[0].url.substr(0, 6) != 'chrome'
chrome.tabs.reload(tabs[0].id, {bypassCache: true})
url = tabs[0].url
return if not url
return if url.substr(0, 6) == 'chrome'
return if url.substr(0, 6) == 'about:'
return if url.substr(0, 4) == 'moz-'
chrome.tabs.reload(tabs[0].id, {bypassCache: true})
chrome.runtime.onMessage.addListener (request, sender, respond) ->
return unless request and request.method
options.ready.then ->
target = options
method = target[request.method]

View File

@ -5,7 +5,13 @@ window.OmegaDebug =
chrome.runtime.getManifest().version
downloadLog: ->
blob = new Blob [localStorage['log']], {type: "text/plain;charset=utf-8"}
saveAs(blob, "OmegaLog_#{Date.now()}.txt")
filename = "OmegaLog_#{Date.now()}.txt"
if browser?.downloads?.download?
url = URL.createObjectURL(blob)
browser.downloads.download({url: url, filename: filename})
else
saveAs(blob, filename)
resetOptions: ->
localStorage.clear()
# Prevent options loading from sync storage after reload.

View File

@ -40,7 +40,8 @@ angular.module('omegaTarget', []).factory 'omegaTarget', ($q) ->
port.onMessage.addListener(callback)
return
isChromeUrl = (url) -> url.substr(0, 6) == 'chrome'
isChromeUrl = (url) -> url.substr(0, 6) == 'chrome' or
url.substr(0, 4) == 'moz-' or url.substr(0, 6) == 'about:'
optionsChangeCallback = []
requestInfoCallback = null

View File

@ -43,7 +43,7 @@ OmegaTargetPopup = {
chrome.tabs.query({
url: options_url
}, function(tabs) {
if (tabs.length > 0) {
if (!chrome.runtime.lastError && tabs && tabs.length > 0) {
var props = {
active: true
};

View File

@ -0,0 +1,89 @@
FindProxyForURL = (function () {
var OmegaPac = require('omega-pac');
var options = {};
var state = {};
var activeProfile = null;
var fallbackResult = 'DIRECT';
var pacCache = {};
init();
return FindProxyForURL;
function FindProxyForURL(url, host, details) {
if (!activeProfile) {
warn('Warning: Proxy script not initialized on handling: ' + url);
return fallbackResult;
}
// Moz: Neither path or query is included url regardless of scheme for now.
// This is even more strict than Chromium restricting HTTPS URLs.
// Therefore, it leads to different behavior than the icon and badge.
// https://bugzilla.mozilla.org/show_bug.cgi?id=1337001
var request = OmegaPac.Conditions.requestFromUrl(url);
var profile = activeProfile;
var matchResult, next;
while (profile) {
matchResult = OmegaPac.Profiles.match(profile, request)
if (!matchResult) {
if (profile.profileType === 'DirectProfile') {
return 'DIRECT';
} else {
warn('Warning: Unsupported profile: ' + profile.profileType);
return fallbackResult;
}
}
if (Array.isArray(matchResult)) {
next = matchResult[0];
// TODO: Maybe also return user/pass if Mozilla supports it or it ends
// up standardized in WebExtensions in the future.
// MOZ: Mozilla has a bug tracked for user/pass in PAC return value.
// https://bugzilla.mozilla.org/show_bug.cgi?id=1319641
if (next.charCodeAt(0) !== 43) {
// MOZ: SOCKS5 proxies are supported under the prefix SOCKS.
// https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ProxyScriptContext.jsm#178
// Note: We have to replace this because MOZ won't process the rest of
// the list if the syntax of the first item is not recognized.
next = next.replace(/SOCKS5 /g, 'SOCKS ');
return next;
}
} else if (matchResult.profileName) {
next = OmegaPac.Profiles.nameAsKey(matchResult.profileName)
} else {
return fallbackResult;
}
profile = OmegaPac.Profiles.byKey(next, options)
}
warn('Warning: Cannot find profile: ' + next);
return fallbackResult;
}
function warn(message, error) {
// We don't have console here and alert is not implemented.
// Throwing and messaging seems to be the only ways to communicate.
// MOZ: alert(): https://bugzilla.mozilla.org/show_bug.cgi?id=1353510
browser.runtime.sendMessage({
event: 'proxyScriptLog',
message: message,
error: error,
level: 'warn',
});
}
function init() {
browser.runtime.sendMessage({event: 'proxyScriptLoaded'});
browser.runtime.onMessage.addListener(function(message) {
if (message.event === 'proxyScriptStateChanged') {
state = message.state;
options = message.options;
if (!state.currentProfileName) {
activeProfile = state.tempProfile;
} else {
activeProfile = OmegaPac.Profiles.byName(state.currentProfileName,
options);
}
}
});
}
})();

View File

@ -34,8 +34,10 @@ class TrackedEvent
constructor: (@event) ->
@callbacks = []
mes = ['hasListener', 'hasListeners', 'addRules', 'getRules', 'removeRules']
for method in mes
this[method] = @event[method].bind(@event)
for methodName in mes
method = @event[methodName]
if method?
this[methodName] = method.bind(@event)
addListener: (callback) ->
@event.addListener(callback)
@ -69,7 +71,7 @@ class TrackedEvent
###
dispose: ->
@removeAllListeners()
if @event.hasListeners()
if @event.hasListeners?()
throw new Error("Underlying Event still has listeners!")
@event = null
@callbacks = null

View File

@ -10,6 +10,7 @@ module.exports = class ExternalApi
'padekgcemlokbadohgkifijomclgjgif': 32
disabled: false
listen: ->
return unless chrome.runtime.onConnectExternal
chrome.runtime.onConnectExternal.addListener (rawPort) =>
port = new ChromePort(rawPort)
port.onMessage.addListener (msg) => @onMessage(msg, port)

View File

@ -0,0 +1,12 @@
module.exports =
Storage: require('./storage')
Options: require('./options')
ChromeTabs: require('./tabs')
SwitchySharp: require('./switchysharp')
ExternalApi: require('./external_api')
WebRequestMonitor: require('./web_request_monitor')
Inspect: require('./inspect')
Url: require('url')
for name, value of require('omega-target')
module.exports[name] ?= value

View File

@ -3,7 +3,14 @@ OmegaPac = OmegaTarget.OmegaPac
Promise = OmegaTarget.Promise
querystring = require('querystring')
chromeApiPromisifyAll = require('./chrome_api')
proxySettings = chromeApiPromisifyAll(chrome.proxy.settings)
if chrome?.proxy?.settings
proxySettings = chromeApiPromisifyAll(chrome.proxy.settings)
else
proxySettings =
setAsync: -> Promise.resolve()
clearAsync: -> Promise.resolve()
get: -> null
onChange: addListener: -> null
parseExternalProfile = require('./parse_external_profile')
ProxyAuth = require('./proxy_auth')
WebRequestMonitor = require('./web_request_monitor')
@ -118,14 +125,22 @@ class ChromeOptions extends OmegaTarget.Options
@_proxyChangeListener = (details) =>
for watcher in @_proxyChangeWatchers
watcher(details)
chrome.proxy.settings.onChange.addListener @_proxyChangeListener
proxySettings.onChange.addListener @_proxyChangeListener
@_proxyChangeWatchers.push(callback)
applyProfileProxy: (profile, meta) ->
if chrome?.proxy?.settings?
return @applyProfileProxySettings(profile, meta)
else if browser?.proxy?.registerProxyScript?
return @applyProfileProxyScript(profile, meta)
else
ex = new Error('Your browser does not support proxy settings!')
return Promise.reject ex
applyProfileProxySettings: (profile, meta) ->
meta ?= profile
if profile.profileType == 'SystemProfile'
# Clear proxy settings, returning proxy control to Chromium.
return proxySettings.clearAsync({}).then =>
chrome.proxy.settings.get {}, @_proxyChangeListener
proxySettings.get {}, @_proxyChangeListener
return
config = {}
if profile.profileType == 'DirectProfile'
@ -161,9 +176,83 @@ class ChromeOptions extends OmegaTarget.Options
@_proxyAuth.setProxies(@_watchingProfiles)
proxySettings.setAsync({value: config})
).then =>
chrome.proxy.settings.get {}, @_proxyChangeListener
proxySettings.get {}, @_proxyChangeListener
return
_proxyScriptUrl: 'js/omega_webext_proxy_script.min.js'
_proxyScriptDisabled: false
applyProfileProxyScript: (profile, state) ->
state = state ? {}
state.currentProfileName = profile.name
if profile.name == ''
state.tempProfile = @_tempProfile
if profile.profileType == 'SystemProfile'
# MOZ: SystemProfile cannot be done now due to lack of "PASS" support.
# https://bugzilla.mozilla.org/show_bug.cgi?id=1319634
# In the mean time, let's just unregister the script.
if browser.proxy.unregister?
browser.proxy.unregister()
else
# Some older browers may not ship with .unregister API.
# In that case, let's just set an invalid script to unregister it.
browser.proxy.registerProxyScript('js/omega_invalid_proxy_script.js')
@_proxyScriptDisabled = true
else
@_proxyScriptState = state
@_initWebextProxyScript().then => @_proxyScriptStateChanged()
# Proxy authentication is not covered in WebExtensions standard now.
# MOZ: Mozilla has a bug tracked to implemented it in PAC return value.
# https://bugzilla.mozilla.org/show_bug.cgi?id=1319641
return Promise.resolve()
_proxyScriptInitialized: false
_proxyScriptState: {}
_initWebextProxyScript: ->
if not @_proxyScriptInitialized
browser.proxy.onProxyError.addListener (err) =>
if err and err.message.indexOf('Invalid Proxy Rule: DIRECT') >= 0
# DIRECT cannot be parsed in Mozilla earlier due to a bug. Even though
# it throws, it actually falls back to direct connection so it works.
# https://bugzilla.mozilla.org/show_bug.cgi?id=1355198
return
@log.error(err)
browser.runtime.onMessage.addListener (message) =>
return unless message.event == 'proxyScriptLog'
if message.level == 'error'
@log.error(message)
else if message.level == 'warn'
@log.error(message)
else
@log.log(message)
if not @_proxyScriptInitialized or @_proxyScriptDisabled
promise = new Promise (resolve) ->
onMessage = (message) ->
return unless message.event == 'proxyScriptLoaded'
resolve()
browser.runtime.onMessage.removeListener onMessage
return
browser.runtime.onMessage.addListener onMessage
# The API has been renamed to .register but for some old browsers' sake:
if browser.proxy.register?
browser.proxy.register(@_proxyScriptUrl)
else
browser.proxy.registerProxyScript(@_proxyScriptUrl)
@_proxyScriptDisabled = false
else
promise = Promise.resolve()
@_proxyScriptInitialized = true
return promise
_proxyScriptStateChanged: ->
browser.runtime.sendMessage({
event: 'proxyScriptStateChanged'
state: @_proxyScriptState
options: @_options
}, {
toProxyScript: true
})
_quickSwitchInit: false
_quickSwitchContextMenuCreated: false
_quickSwitchCanEnable: false
@ -194,8 +283,12 @@ class ChromeOptions extends OmegaTarget.Options
index = (index + 1) % profiles.length
@applyProfile(profiles[index]).then =>
if @_options['-refreshOnProfileChange']
if tab.url and tab.url.indexOf('chrome') != 0
chrome.tabs.reload(tab.id)
url = tab.url
return if not url
return if url.substr(0, 6) == 'chrome'
return if url.substr(0, 6) == 'about:'
return if url.substr(0, 4) == 'moz-'
chrome.tabs.reload(tab.id)
else
chrome.browserAction.setPopup({popup: 'popup/index.html'})
Promise.resolve()
@ -349,6 +442,8 @@ class ChromeOptions extends OmegaTarget.Options
return result if not url
else
return result
return result if url.substr(0, 6) == 'about:'
return result if url.substr(0, 4) == 'moz-'
domain = OmegaPac.getBaseDomain(Url.parse(url).hostname)
return {

View File

@ -13,6 +13,9 @@ module.exports = class ProxyAuth
if not chrome.webRequest
@options.log.error('Proxy auth disabled! No webRequest permission.')
return
if not chrome.webRequest.onAuthRequired
@options.log.error('Proxy auth disabled! onAuthRequired not available.')
return
chrome.webRequest.onAuthRequired.addListener(
@authHandler.bind(this)
{urls: ['<all_urls>']}

View File

@ -28,27 +28,40 @@ class ChromeStorage extends OmegaTarget.Storage
# This could happen if the storage area is not available. For example,
# some Chromium-based browsers disable access to the sync storage.
err = new OmegaTarget.Storage.StorageUnavailableError()
else if err.message.indexOf(
'Please set webextensions.storage.sync.enabled to true') >= 0
# This happens when sync storage is disabled in flags.
err = new OmegaTarget.Storage.StorageUnavailableError()
return Promise.reject(err)
constructor: (storage, @areaName) ->
@storage = chromeApiPromisifyAll(storage)
constructor: (@areaName) ->
if browser?.storage?[@areaName]
@storage = browser.storage[@areaName]
else
wrapper = chromeApiPromisifyAll(chrome.storage[@areaName])
@storage =
get: wrapper.getAsync.bind(wrapper),
set: wrapper.setAsync.bind(wrapper),
remove: wrapper.removeAsync.bind(wrapper),
clear: wrapper.clearAsync.bind(wrapper),
get: (keys) ->
keys ?= null
@storage.getAsync(keys).catch(ChromeStorage.parseStorageErrors)
Promise.resolve(@storage.get(keys)).catch(ChromeStorage.parseStorageErrors)
set: (items) ->
if Object.keys(items).length == 0
return Promise.resolve({})
@storage.setAsync(items).catch(ChromeStorage.parseStorageErrors)
Promise.resolve(@storage.set(items)).catch(ChromeStorage.parseStorageErrors)
remove: (keys) ->
if not keys?
return @storage.clearAsync()
return Promise.resolve(@storage.clear())
if Array.isArray(keys) and keys.length == 0
return Promise.resolve({})
@storage.removeAsync(keys).catch(ChromeStorage.parseStorageErrors)
Promise.resolve(@storage.remove(keys))
.catch(ChromeStorage.parseStorageErrors)
watch: (keys, callback) ->
ChromeStorage.watchers[@areaName] ?= {}

View File

@ -89,6 +89,8 @@ module.exports = class WebRequestMonitor
return if req.error.indexOf('net::ERR_FILE_') == 0
return if req.url.indexOf('file:') == 0
return if req.url.indexOf('chrome') == 0
return if req.url.indexOf('about:') == 0
return if req.url.indexOf('moz-') == 0
# Some ad-blocking extensions may redirect requests to 127.0.0.1.
return if req.url.indexOf('://127.0.0.1') > 0
return unless reqInfo

View File

@ -21,12 +21,12 @@
"tests"
],
"dependencies": {
"angular": "~1.2.16",
"angular": "~1.6.5",
"angular-bootstrap": "~0.12.0",
"angular-animate": "~1.2.16",
"angular-ui-router": "~0.2.10",
"angular-loader": "~1.2.16",
"angular-i18n": "~1.2.16",
"angular-animate": "~1.6.5",
"angular-ui-router": "~0.2.18",
"angular-loader": "~1.6.5",
"angular-i18n": "~1.6.5",
"bootstrap": "~3.3.2",
"script.js": "~2.5.3",
"ngprogress": "~1.0.4",
@ -37,7 +37,7 @@
"FileSaver": "*",
"angular-ui-utils": "bower-validate",
"angular-ladda": "~0.2.1",
"angular-sanitize": "~1.2.26",
"angular-sanitize": "~1.6.5",
"shepherd.js": "~0.5.1"
},
"exportsOverride": {
@ -51,10 +51,10 @@
"": []
},
"angular": {
"": "*.min.js"
"": "angular.min.js"
},
"angular-animate": {
"": "*.min.*"
"": "*.min.js"
},
"angular-bootstrap": {
"": "ui-bootstrap-tpls.min.js"
@ -77,16 +77,16 @@
"": "dist/*.min.js"
},
"angular-ui-router": {
"": "release/*.js"
"": "release/*.min.js"
},
"angular-ui-sortable": {
"": "*.js"
"": "*.min.js"
},
"angular-ui-utils": {
"": "*.js"
"": "*.min.js"
},
"bootstrap": {
"css": "dist/css/*.min.*",
"css": "dist/css/bootstrap.min.css",
"fonts": "dist/fonts/*",
"js": "js/dropdown.*"
},
@ -99,7 +99,7 @@
"shepherd.js": {
"": [
"*.min.js",
"css/*.css"
"css/shepherd-theme-arrows.css"
]
},
"spectrum": {
@ -120,5 +120,8 @@
"dist/ladda.min.js"
]
}
},
"resolutions": {
"angular": "~1.6.5"
}
}

View File

@ -54,7 +54,7 @@ $script.ready ['angular-loader', 'jquery'], ->
$script 'lib/angular/angular.min.js', 'angular'
$script.ready ['angular'], ->
$script 'lib/angular-ui-router/angular-ui-router.js', 'angular-ui-router'
$script 'lib/angular-ui-router/angular-ui-router.min.js', 'angular-ui-router'
$script 'lib/angular-sanitize/angular-sanitize.min.js', 'angular-sanitize'
$script.ready ['angular', 'omega', 'omega-deps', 'angular-ui-router',

View File

@ -66,12 +66,14 @@ angular.module('omega').config ($stateProvider, $urlRouterProvider,
controller: 'AboutCtrl'
)
angular.module('omega').factory 'omegaDebug', ($window, $rootScope) ->
angular.module('omega').factory 'omegaDebug', ($window, $rootScope,
$injector) ->
omegaDebug = $window.OmegaDebug ? {}
omegaDebug.downloadLog ?= ->
downloadFile = $injector.get('downloadFile') ? saveAs
blob = new Blob [localStorage['log']], {type: "text/plain;charset=utf-8"}
saveAs(blob, "OmegaLog_#{Date.now()}.txt")
downloadFile(blob, "OmegaLog_#{Date.now()}.txt")
omegaDebug.reportIssue ?= ->
$window.open(
@ -82,3 +84,14 @@ angular.module('omega').factory 'omegaDebug', ($window, $rootScope) ->
$rootScope.resetOptions()
omegaDebug
angular.module('omega').factory 'downloadFile', ->
if browser?.downloads?.download?
return (blob, filename) ->
url = URL.createObjectURL(blob)
if filename
browser.downloads.download({url: url, filename: filename})
else
browser.downloads.download({url: url})
else
return saveAs

View File

@ -1,4 +1,5 @@
angular.module('omega').controller 'FixedProfileCtrl', ($scope, $modal) ->
angular.module('omega').controller 'FixedProfileCtrl', ($scope, $modal,
trFilter) ->
$scope.urlSchemes = ['', 'http', 'https', 'ftp']
$scope.urlSchemeDefault = 'fallbackProxy'
proxyProperties =
@ -20,6 +21,21 @@ angular.module('omega').controller 'FixedProfileCtrl', ($scope, $modal) ->
$scope.showAdvanced = false
$scope.optionsForScheme = {}
for scheme in $scope.urlSchemes
defaultLabel =
if scheme
trFilter('options_protocol_useDefault')
else
trFilter('options_protocol_direct')
$scope.optionsForScheme[scheme] = [
{label: defaultLabel, value: undefined},
{label: 'HTTP', value: 'http'},
{label: 'HTTPS', value: 'https'},
{label: 'SOCKS4', value: 'socks4'},
{label: 'SOCKS5', value: 'socks5'},
]
$scope.proxyEditors = {}
$scope.authSupported = {"http": true, "https": true}

View File

@ -1,5 +1,5 @@
angular.module('omega').controller 'IoCtrl', ($scope, $rootScope,
$window, $http, omegaTarget) ->
$window, $http, omegaTarget, downloadFile) ->
omegaTarget.state('web.restoreOnlineUrl').then (url) ->
if url
@ -10,7 +10,7 @@ angular.module('omega').controller 'IoCtrl', ($scope, $rootScope,
plainOptions = angular.fromJson(angular.toJson($rootScope.options))
content = JSON.stringify(plainOptions)
blob = new Blob [content], {type: "text/plain;charset=utf-8"}
saveAs(blob, "OmegaOptions.bak")
downloadFile(blob, "OmegaOptions.bak")
$scope.importSuccess = ->
$rootScope.showAlert(

View File

@ -1,7 +1,10 @@
angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
$q, $modal, $state, profileColors, profileIcons, omegaTarget,
$timeout, $location, $filter, getAttachedName, isProfileNameReserved,
isProfileNameHidden, dispNameFilter) ->
isProfileNameHidden, dispNameFilter, downloadFile) ->
if not chrome?.proxy?.settings?
$scope.isExperimental = true
tr = $filter('tr')
@ -42,7 +45,7 @@ angular.module('omega').controller 'MasterCtrl', ($scope, $rootScope, $window,
pac = OmegaPac.PacGenerator.ascii(pac)
blob = new Blob [pac], {type: "text/plain;charset=utf-8"}
fileName = profileName.replace(/\W+/g, '_')
saveAs(blob, "OmegaProfile_#{fileName}.pac")
downloadFile(blob, "OmegaProfile_#{fileName}.pac")
if missingProfile
$timeout ->
$rootScope.showAlert(

View File

@ -1,6 +1,6 @@
angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $rootScope,
$location, $timeout, $q, $modal, profileIcons, getAttachedName, omegaTarget,
trFilter) ->
trFilter, downloadFile) ->
# == Rule list ==
$scope.ruleListFormats = OmegaPac.Profiles.ruleListFormats
@ -20,7 +20,7 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $rootScope,
blob = new Blob [text], {type: "text/plain;charset=utf-8"}
fileName = $scope.profile.name.replace(/\W+/g, '_')
saveAs(blob, "OmegaRules_#{fileName}.sorl")
downloadFile(blob, "OmegaRules_#{fileName}.sorl")
exportLegacyRuleList = ->
wildcardRules = ''
@ -52,7 +52,7 @@ angular.module('omega').controller 'SwitchProfileCtrl', ($scope, $rootScope,
"""
blob = new Blob [text], {type: "text/plain;charset=utf-8"}
fileName = $scope.profile.name.replace(/\W+/g, '_')
saveAs(blob, "SwitchyRules_#{fileName}.ssrl")
downloadFile(blob, "SwitchyRules_#{fileName}.ssrl")
# == Condition types ==
$scope.conditionHelp =

View File

@ -14,6 +14,8 @@ html(lang='en' ng-controller='MasterCtrl' ng-csp)
header.col-lg-2.col-sm-3.side-nav
h1
a(ui-sref='about' title='{{"about_title" | tr}}') {{'appNameShort' | tr}}
sup.om-experimental.text-danger(ng-show='isExperimental')
| {{'options_experimental_badge' | tr}}
nav.nav.nav-pills.nav-stacked
li.nav-header {{'options_navHeader_setting' | tr}}
li(ui-sref-active='active'): a(ui-sref='ui')

View File

@ -1,5 +1,10 @@
.page-header
h2 {{'about_title' | tr}}
section.omega-experimental(ng-show='isExperimental')
p.alert.alert-danger
span.glyphicon.glyphicon-warning-sign
= ' '
span {{'about_experimental_warning_moz' | tr}}
section
.media(style='margin: 1em 0')
.media-left

View File

@ -14,13 +14,8 @@ div(ng-controller='FixedProfileCtrl')
tr(ng-repeat='scheme in urlSchemes' ng-show='scheme == "" || showAdvanced')
td {{schemeDisp[scheme] || ('options_scheme_default' | tr)}}
td
select.form-control(ng-model='proxyEditors[scheme].scheme')
option(value='')
| {{(scheme ? 'options_protocol_useDefault' : 'options_protocol_direct') | tr}}
option(value='http') HTTP
option(value='https') HTTPS
option(value='socks4') SOCKS4
option(value='socks5') SOCKS5
select.form-control(ng-model='proxyEditors[scheme].scheme'
ng-options='opt.value as opt.label for opt in optionsForScheme[scheme]')
td(ng-if='proxyEditors[scheme].scheme')
input.form-control(type='text' ng-model='proxyEditors[scheme].host' required)
td(ng-if='!proxyEditors[scheme].scheme')

View File

@ -44,7 +44,7 @@
</li>
<li class="om-divider"></li>
<li class="om-nav-item">
<a href="#" id="js-option" role="button">
<a href="../options.html" target="_blank" id="js-option" role="button">
<span class="glyphicon glyphicon-wrench"></span>
<span id="js-option-label"></span>
</a>

View File

@ -16,10 +16,14 @@
window.close();
}
function showOptions() {
$script.ready('om-target', function() {
OmegaTargetPopup.openOptions(null, closePopup);
});
function showOptions(e) {
if (typeof OmegaTargetPopup !== 'undefined') {
try {
OmegaTargetPopup.openOptions(null, closePopup);
e.preventDefault();
} catch (_) {
}
}
}
function applyProfile(profileName) {