2016-02-13 12:28:36 +01:00
|
|
|
/* global console,exports */
|
|
|
|
/* jslint moz: true */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
(function(){
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const lists = require("./lists");
|
|
|
|
const preferences = require("sdk/simple-prefs");
|
|
|
|
const prefs = preferences.prefs;
|
|
|
|
const {parseErrorStack} = require("./callingStack");
|
|
|
|
const {URL} = require("sdk/url");
|
|
|
|
|
|
|
|
exports.check = function check({url, errorStack}){
|
2016-11-13 14:51:58 +01:00
|
|
|
var match = checkBoth(errorStack, url, prefs.blockMode).match(/^(block|allow|fake|ask)(|Readout|Everything|Context|Input|Internal)$/);
|
2016-02-13 12:28:36 +01:00
|
|
|
if (match){
|
|
|
|
return {
|
|
|
|
type: (match[2] === "Everything" || match[2] === "")?
|
2016-10-22 13:32:48 +02:00
|
|
|
["context", "readout", "input"]:
|
2016-02-13 12:28:36 +01:00
|
|
|
[match[2].toLowerCase()],
|
|
|
|
mode: match[1]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return {
|
2016-10-22 13:32:48 +02:00
|
|
|
type: ["context", "readout", "input"],
|
2016-02-13 12:28:36 +01:00
|
|
|
mode: "block"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-13 14:51:58 +01:00
|
|
|
function checkBoth(errorStack, url, blockMode){
|
|
|
|
if (prefs.enableStackList && errorStack && checkStack(errorStack)){
|
2016-02-13 12:28:36 +01:00
|
|
|
return "allow";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return checkURL(url, blockMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkURL(url, blockMode){
|
2016-11-13 14:51:58 +01:00
|
|
|
url = new URL(url || "about:blank");
|
2016-02-13 12:28:36 +01:00
|
|
|
switch (url.protocol){
|
|
|
|
case "about:":
|
|
|
|
if (url.href === "about:blank"){
|
|
|
|
break;
|
|
|
|
}
|
2016-11-13 14:51:58 +01:00
|
|
|
return "allowInternal";
|
2016-02-13 12:28:36 +01:00
|
|
|
case "chrome:":
|
2016-11-13 14:51:58 +01:00
|
|
|
return "allowInternal";
|
2016-02-13 12:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var mode = "block";
|
|
|
|
switch (blockMode){
|
|
|
|
case "blockEverything":
|
|
|
|
mode = "block";
|
|
|
|
break;
|
|
|
|
case "block":
|
|
|
|
case "blockContext":
|
|
|
|
case "blockReadout":
|
2016-10-22 13:32:48 +02:00
|
|
|
case "blockInput":
|
2016-02-13 12:28:36 +01:00
|
|
|
case "ask":
|
|
|
|
case "askContext":
|
|
|
|
case "askReadout":
|
2016-10-22 13:32:48 +02:00
|
|
|
case "askInput":
|
2016-02-13 12:28:36 +01:00
|
|
|
case "fake":
|
|
|
|
case "fakeContext":
|
|
|
|
case "fakeReadout":
|
2016-10-22 13:32:48 +02:00
|
|
|
case "fakeInput":
|
2016-02-13 12:28:36 +01:00
|
|
|
case "allow":
|
|
|
|
case "allowContext":
|
|
|
|
case "allowReadout":
|
2016-10-22 13:32:48 +02:00
|
|
|
case "allowInput":
|
2016-02-13 12:28:36 +01:00
|
|
|
if (url && lists.get("white").match(url)){
|
|
|
|
mode = "allow";
|
|
|
|
}
|
|
|
|
else if (url && lists.get("black").match(url)){
|
|
|
|
mode = "block";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mode = blockMode;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "allowEverything":
|
|
|
|
mode = "allow";
|
|
|
|
break;
|
|
|
|
default:
|
2016-11-13 15:34:33 +01:00
|
|
|
// console.log("Unknown blocking mode (" + blockMode + "). Default to block everything.");
|
2016-02-13 12:28:36 +01:00
|
|
|
}
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
2016-11-13 14:51:58 +01:00
|
|
|
function checkStack(errorStack){
|
|
|
|
var callingStack = parseErrorStack(errorStack);
|
|
|
|
return lists.get("stack").match(callingStack);
|
2016-02-13 12:28:36 +01:00
|
|
|
}
|
2016-11-13 14:51:58 +01:00
|
|
|
exports.checkStack = checkStack;
|
2016-02-13 12:28:36 +01:00
|
|
|
}());
|