Merge branch 'chromium' into merge/chromium

This commit is contained in:
hackademix 2019-03-27 23:43:34 +01:00
commit b9373c65b1
23 changed files with 1288 additions and 41 deletions

View File

@ -51,6 +51,10 @@
} }
}; };
if (!browser.contentScripts) { // #chromium fallback
Scripts.register = () => {};
}
let flatten = arr => arr.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []); let flatten = arr => arr.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []);
let protocolRx = /^(\w+):/i; let protocolRx = /^(\w+):/i;

View File

@ -20,7 +20,10 @@ var RequestGuard = (() => {
media: "media", media: "media",
other: "", other: "",
}; };
const allTypes = Object.keys(policyTypesMap); const allTypes = UA.isMozilla ? Object.keys(policyTypesMap)
: ["main_frame", "sub_frame", "stylesheet", "script", "image", "font",
"object", "xmlhttprequest", "ping", "csp_report", "media", "websocket", "other"];
Object.assign(policyTypesMap, {"webgl": "webgl"}); // fake types Object.assign(policyTypesMap, {"webgl": "webgl"}); // fake types
const TabStatus = { const TabStatus = {
map: new Map(), map: new Map(),
@ -254,7 +257,7 @@ var RequestGuard = (() => {
return redirected; return redirected;
} }
const ABORT = {cancel: true}, ALLOW = {}; const ABORT = {cancel: true}, ALLOW = {};
const INTERNAL_SCHEME = /^(?:chrome|resource|moz-extension|about):/; const INTERNAL_SCHEME = /^(?:chrome|resource|(?:moz|chrome)-extension|about):/;
const listeners = { const listeners = {
onBeforeRequest(request) { onBeforeRequest(request) {
try { try {
@ -326,7 +329,7 @@ var RequestGuard = (() => {
capabilities = perms.capabilities; capabilities = perms.capabilities;
} else { } else {
capabilities = perms.capabilities; capabilities = perms.capabilities;
if (frameAncestors.length > 0 && ns.sync.cascadeRestrictions) { if (frameAncestors && frameAncestors.length > 0 && ns.sync.cascadeRestrictions) {
// cascade top document's restrictions to subframes // cascade top document's restrictions to subframes
let topUrl = frameAncestors.pop().url; let topUrl = frameAncestors.pop().url;
let topPerms = policy.get(topUrl, topUrl).perms; let topPerms = policy.get(topUrl, topUrl).perms;

View File

@ -31,7 +31,7 @@ function deferWebTraffic(promiseToWaitFor, next) {
if (type === "main_frame") { if (type === "main_frame") {
seenTabs.add(tabId); seenTabs.add(tabId);
} else if (documentUrl) { } else if (documentUrl) {
if (frameId !== 0) { if (frameId !== 0 && request.frameAncestors) {
documentUrl = request.frameAncestors.pop().url; documentUrl = request.frameAncestors.pop().url;
} }
reloadTab(tabId); reloadTab(tabId);

View File

@ -9,7 +9,7 @@
) { ) {
return; return;
} }
gTable = document.getElementsByTagName("table")[0]; gTable = document.getElementsByTagName("table")[0];
gTBody = gTable.tBodies[0]; gTBody = gTable.tBodies[0];
if (gTBody.rows.length < 2) if (gTBody.rows.length < 2)
@ -31,7 +31,7 @@
headCells[i].addEventListener("click", rowAction(i), true); headCells[i].addEventListener("click", rowAction(i), true);
} }
if (gUI_showHidden) { if (gUI_showHidden) {
gRows = Array.slice(gTBody.rows); gRows = Array.from(gTBody.rows);
hiddenObjects = gRows.some(row => row.className == "hidden-object"); hiddenObjects = gRows.some(row => row.className == "hidden-object");
} }
gTable.setAttribute("order", ""); gTable.setAttribute("order", "");
@ -60,7 +60,7 @@
} }
function orderBy(column) { function orderBy(column) {
if (!gRows) if (!gRows)
gRows = Array.slice(gTBody.rows); gRows = Array.from(gTBody.rows);
var order; var order;
if (gOrderBy == column) { if (gOrderBy == column) {
order = gTable.getAttribute("order") == "asc" ? "desc" : "asc"; order = gTable.getAttribute("order") == "asc" ? "desc" : "asc";

12
src/lib/UA.js Normal file
View File

@ -0,0 +1,12 @@
var UA = {
isMozilla: document.URL.startsWith("moz-"),
}
if (!UA.isMozilla) {
if (typeof chrome === "object" && !chrome.tabs && typeof exportFunction === "undefined") {
// content script shims
window.exportFunction = () => {};
}
} else {
document.documentElement.classList.add("mozwebext");
}

1186
src/lib/browser-polyfill.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,12 +7,12 @@ if (typeof flextabs === "function") {
let rx = new RegExp(`(?:^|[#;])tab-${id}=(\\d+)(?:;|$)`); let rx = new RegExp(`(?:^|[#;])tab-${id}=(\\d+)(?:;|$)`);
let current = location.hash.match(rx); let current = location.hash.match(rx);
console.log(`persisted %o`, current); console.log(`persisted %o`, current);
let toggles = tabs.querySelectorAll(".flextabs__toggle"); let toggles = Array.from(tabs.querySelectorAll(".flextabs__toggle"));
let currentToggle = toggles[current && parseInt(current[1]) || 0]; let currentToggle = toggles[current && parseInt(current[1]) || 0];
if (currentToggle) currentToggle.click(); if (currentToggle) currentToggle.click();
for (let toggle of toggles) { for (let toggle of toggles) {
toggle.addEventListener("click", e => { toggle.addEventListener("click", e => {
let currentIdx = Array.indexOf(toggles, toggle); let currentIdx = toggles.indexOf(toggle);
location.hash = location.hash.split(";").filter(p => !rx.test(p)) location.hash = location.hash.split(";").filter(p => !rx.test(p))
.concat(`tab-${id}=${currentIdx}`).join(";"); .concat(`tab-${id}=${currentIdx}`).join(";");
}); });

View File

@ -1,22 +1,22 @@
{ {
// see https://bugzilla.mozilla.org/show_bug.cgi?id=1415644 // see https://bugzilla.mozilla.org/show_bug.cgi?id=1415644
let domains = [ let domains = UA.isMozilla ? [
"accounts-static.cdn.mozilla.net", "accounts-static.cdn.mozilla.net",
"accounts.firefox.com", "accounts.firefox.com",
"addons.cdn.mozilla.net", "addons.cdn.mozilla.net",
"addons.mozilla.org", "addons.mozilla.org",
"api.accounts.firefox.com", "api.accounts.firefox.com",
"content.cdn.mozilla.net", "content.cdn.mozilla.net",
"content.cdn.mozilla.net", "content.cdn.mozilla.net",
"discovery.addons.mozilla.org", "discovery.addons.mozilla.org",
"input.mozilla.org", "input.mozilla.org",
"install.mozilla.org", "install.mozilla.org",
"oauth.accounts.firefox.com", "oauth.accounts.firefox.com",
"profile.accounts.firefox.com", "profile.accounts.firefox.com",
"support.mozilla.org", "support.mozilla.org",
"sync.services.mozilla.com", "sync.services.mozilla.com",
"testpilot.firefox.com", "testpilot.firefox.com",
]; ] : [ "chrome.google.com" ];
function isRestrictedURL(u) { function isRestrictedURL(u) {
try { try {

View File

@ -8,10 +8,10 @@
"strict_min_version": "59.0" "strict_min_version": "59.0"
} }
}, },
"version": "10.2.5", "version": "10.5rc1",
"description": "__MSG_Description__", "description": "__MSG_Description__",
"incognito": "spanning", "incognito": "spanning",
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'none'", "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'none'",
"icons": { "icons": {
@ -35,6 +35,8 @@
"background": { "background": {
"persistent": true, "persistent": true,
"scripts": [ "scripts": [
"lib/UA.js",
"lib/browser-polyfill.js",
"lib/uuid.js", "lib/uuid.js",
"lib/log.js", "lib/log.js",
"lib/include.js", "lib/include.js",
@ -77,6 +79,8 @@
"match_about_blank": true, "match_about_blank": true,
"all_frames": true, "all_frames": true,
"js": [ "js": [
"lib/UA.js",
"lib/browser-polyfill.js",
"lib/log.js", "lib/log.js",
"lib/uuid.js", "lib/uuid.js",
"lib/sha256.js", "lib/sha256.js",
@ -117,11 +121,13 @@
"commands": { "commands": {
"_execute_browser_action": { "_execute_browser_action": {
"description": "NoScript UI",
"suggested_key": { "suggested_key": {
"default": "Alt+Shift+N" "default": "Alt+Shift+N"
} }
}, },
"togglePermissions": { "togglePermissions": {
"description": "Toggle permissions",
"suggested_key": { "suggested_key": {
"default": "Ctrl+Shift+T" "default": "Ctrl+Shift+T"
} }

View File

@ -26,7 +26,7 @@ var Test = (() => {
error(e); error(e);
} }
this[r ? "passed" : "failed"]++; this[r ? "passed" : "failed"]++;
log(`${r ? "PASSED" : "FAILED"} ${msg || uneval(test)}`); log(`${r ? "PASSED" : "FAILED"} ${msg || test}`);
if (typeof callback === "function") try { if (typeof callback === "function") try {
callback(r, test, msg); callback(r, test, msg);
} catch(e) { } catch(e) {

View File

@ -7,14 +7,16 @@ var Prompts = (() => {
async open(data) { async open(data) {
promptData = data; promptData = data;
this.close(); this.close();
this.currentWindow = await browser.windows.create({ let options = {
url: browser.extension.getURL("ui/prompt.html"), url: browser.extension.getURL("ui/prompt.html"),
type: "panel", type: "panel",
allowScriptsToClose: true,
// titlePreface: "NoScript ",
width: data.features.width, width: data.features.width,
height: data.features.height, height: data.features.height,
}); };
if (UA.isMozilla) {
options.allowScriptsToClose = true;
}
this.currentWindow = await browser.windows.create(options);
} }
async close() { async close() {
if (this.currentWindow) { if (this.currentWindow) {

View File

@ -195,3 +195,11 @@ input[type="file"] {
border-radius: .2em .2em 0 0; border-radius: .2em .2em 0 0;
padding: .2em .4em; padding: .2em .4em;
} }
#xss-options {
display: none;
}
.mozwebext #xss-options {
display: block;
}

View File

@ -8,6 +8,8 @@
<link rel="stylesheet" href="/lib/flextabs.css" /> <link rel="stylesheet" href="/lib/flextabs.css" />
<link rel="stylesheet" href="options.css" /> <link rel="stylesheet" href="options.css" />
<link rel="stylesheet" href="whirlpool.css" /> <link rel="stylesheet" href="whirlpool.css" />
<script src="/lib/UA.js"></script>
<script src="/lib/browser-polyfill.js"></script>
<script src="/lib/include.js"></script> <script src="/lib/include.js"></script>
<script src="/lib/log.js"></script> <script src="/lib/log.js"></script>
<script src="/lib/flextabs.js"></script> <script src="/lib/flextabs.js"></script>

View File

@ -103,7 +103,7 @@
} }
let button = document.querySelector("#btn-delete-xss-choices"); let button = document.querySelector("#btn-delete-xss-choices");
let choices = UI.xssUserChoices; let choices = UI.xssUserChoices;
button.disabled = Object.keys(choices).length === 0; button.disabled = !choices || Object.keys(choices).length === 0;
button.onclick = () => { button.onclick = () => {
UI.updateSettings({ UI.updateSettings({
xssUserChoices: {} xssUserChoices: {}

View File

@ -16,6 +16,7 @@ body {
#top a { #top a {
appearance: none !important; appearance: none !important;
webkit-appearance: none !important;
-moz-appearance: none !important; -moz-appearance: none !important;
width: 2em; width: 2em;
height: 2em; height: 2em;
@ -119,8 +120,9 @@ body {
} }
.hider-close { .hider-close {
-moz-appearance: none;
appearance: none; appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
color: black; color: black;
background: transparent; background: transparent;
padding: 0; padding: 0;

View File

@ -6,6 +6,8 @@
<title>NoScript Settings</title> <title>NoScript Settings</title>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="popup.css" /> <link rel="stylesheet" type="text/css" href="popup.css" />
<script src="/lib/UA.js"></script>
<script src="/lib/browser-polyfill.js"></script>
<script src="/lib/include.js"></script> <script src="/lib/include.js"></script>
<script src="/lib/log.js"></script> <script src="/lib/log.js"></script>
<script src="/common/locale.js"></script> <script src="/common/locale.js"></script>

View File

@ -5,6 +5,8 @@
<title></title> <title></title>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="prompt.css" /> <link rel="stylesheet" type="text/css" href="prompt.css" />
<script src="/lib/UA.js"></script>
<script src="/lib/browser-polyfill.js"></script>
<script src="/lib/include.js"></script> <script src="/lib/include.js"></script>
<script src="/lib/log.js"></script> <script src="/lib/log.js"></script>
<script src="/common/locale.js"></script> <script src="/common/locale.js"></script>

View File

@ -1,5 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<meta charset="utf-8"> <meta charset="utf-8">
<script src="/lib/UA.js"></script>
<script src="/lib/browser-polyfill.js"></script>
<script src="/lib/log.js"></script> <script src="/lib/log.js"></script>
<script src="/lib/include.js"></script> <script src="/lib/include.js"></script>
<script src="siteInfo.js"></script> <script src="siteInfo.js"></script>

View File

@ -87,7 +87,7 @@
} }
UI.local.toolbarLayout = { UI.local.toolbarLayout = {
left, right, left, right,
hidden: Array.map(document.querySelectorAll("#top > .hider > .icon"), el => el.id), hidden: Array.from(document.querySelectorAll("#top > .hider > .icon")).map(el => el.id),
}; };
debug("%o", UI.local); debug("%o", UI.local);

View File

@ -5,10 +5,14 @@ input {
} }
input[type="radio"] { input[type="radio"] {
appearance: radio !important;
-webkit-appearance: radio !important;
-moz-appearance: radio !important; -moz-appearance: radio !important;
padding-right: .2em !important; padding-right: .2em !important;
} }
input[type="checkbox"] { input[type="checkbox"] {
appearance: checkbox !important;
-webkit-appearance: checkbox !important;
-moz-appearance: checkbox !important; -moz-appearance: checkbox !important;
} }

View File

@ -3,6 +3,7 @@ body {
font-family: sans-serif; font-family: sans-serif;
font: -moz-use-system-font; font: -moz-use-system-font;
font-size: 12px; font-size: 12px;
min-width: 600px;
} }
.mobile > body { .mobile > body {
@ -139,6 +140,8 @@ input[type="checkbox"] {
input.https-only { input.https-only {
font-size: 1em; font-size: 1em;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none; -moz-appearance: none;
background: url(/img/ui-http64.png) no-repeat center; background: url(/img/ui-http64.png) no-repeat center;
background-size: 1.5em; background-size: 1.5em;
@ -186,6 +189,8 @@ span.preset {
.presets input.preset { .presets input.preset {
font-size: 1em; font-size: 1em;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none; -moz-appearance: none;
background: url(/img/ui-no64.png) no-repeat center left; background: url(/img/ui-no64.png) no-repeat center left;
background-size: 1.5em; background-size: 1.5em;
@ -264,6 +269,8 @@ input.preset:active, input.preset:focus, input.preset:hover {
} }
button.options { button.options {
appearance: none;
-webkit-appearance: none;
-moz-appearance: none; -moz-appearance: none;
border: none; border: none;
background: none transparent; background: none transparent;
@ -276,6 +283,8 @@ button.options {
} }
.preset .options { .preset .options {
appearance: none;
-webkit-appearance: none;
-moz-appearance: none; -moz-appearance: none;
border: 0; border: 0;
@ -315,6 +324,8 @@ input.preset[value="CUSTOM"] {
input.temp { input.temp {
font-size: 1em; font-size: 1em;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none; -moz-appearance: none;
margin: 0; margin: 0;
padding: 0; padding: 0;

View File

@ -107,11 +107,10 @@ XSS.InjectionChecker = (async () => {
var bs = { var bs = {
nq: new RegExp("[" + def + "]") nq: new RegExp("[" + def + "]")
}; };
Array.forEach("'\"`", // special treatment for quotes for (let c of ['"', '"', '`']) {
function(c) { // special treatment for quotes
bs[c] = new RegExp("[" + def + c + "]"); bs[c] = new RegExp("[" + def + c + "]");
} }
);
delete this.breakStops; delete this.breakStops;
return (this.breakStops = bs); return (this.breakStops = bs);
}, },

View File

@ -113,6 +113,8 @@ var XSS = (() => {
return { return {
async start() { async start() {
if (!UA.isMozilla) return; // async webRequest is supported on Mozilla only
let {onBeforeRequest} = browser.webRequest; let {onBeforeRequest} = browser.webRequest;
let {xssScanRequestBody} = ns.sync; let {xssScanRequestBody} = ns.sync;
if (xssScanRequestBody !== this.xssScanRequestBody) { if (xssScanRequestBody !== this.xssScanRequestBody) {