2015-09-08 11:41:33 +02:00
|
|
|
/* jslint moz: true */
|
2015-01-16 13:01:01 +01:00
|
|
|
/* 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/. */
|
2014-08-20 10:21:38 +02:00
|
|
|
(function(){
|
2014-10-14 01:06:11 +02:00
|
|
|
"use strict";
|
2015-06-23 13:14:50 +02:00
|
|
|
require("./stylePreferencePane");
|
2015-09-06 12:26:50 +02:00
|
|
|
const {changedFunctions} = require("./modifiedAPI");
|
|
|
|
const {notify} = require("./notifications");
|
2015-09-08 11:41:33 +02:00
|
|
|
const {ask} = require("./askForPermission");
|
2015-09-06 12:26:50 +02:00
|
|
|
const lists = require("./lists");
|
2014-08-01 12:03:23 +02:00
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
const sharedFunctions = require("./sharedFunctions");
|
2014-10-11 00:07:51 +02:00
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
const observers = require("sdk/system/events");
|
|
|
|
const { when: unload } = require("sdk/system/unload");
|
|
|
|
|
|
|
|
const preferences = require("sdk/simple-prefs");
|
|
|
|
const prefs = preferences.prefs;
|
2014-12-15 18:43:47 +01:00
|
|
|
|
2015-12-31 13:37:27 +01:00
|
|
|
function check(callingStack, url){
|
|
|
|
var match = sharedFunctions.check(callingStack, url, prefs.blockMode).match(/^(block|allow|fake|ask)(|Readout|Everything|Context)$/);
|
2015-09-06 15:40:34 +02:00
|
|
|
if (match){
|
|
|
|
return {
|
|
|
|
type: (match[2] === "Everything" || match[2] === "")?
|
|
|
|
["context", "readout"]:
|
|
|
|
[match[2].toLowerCase()],
|
|
|
|
mode: match[1]
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return {
|
|
|
|
type: ["context", "readout"],
|
|
|
|
mode: "block"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-07-31 03:05:51 +02:00
|
|
|
}
|
2015-04-24 01:04:14 +02:00
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
var apiNames = Object.keys(changedFunctions);
|
|
|
|
var undef;
|
|
|
|
|
|
|
|
function intercept({subject: window}){
|
|
|
|
apiNames.forEach(function(name){
|
|
|
|
var changedFunction = changedFunctions[name];
|
|
|
|
var original = window.wrappedJSObject[changedFunction.object].prototype[name];
|
2015-04-14 01:26:04 +02:00
|
|
|
|
2015-09-06 12:26:50 +02:00
|
|
|
Object.defineProperty(
|
|
|
|
window.wrappedJSObject[changedFunction.object].prototype,
|
|
|
|
name,
|
|
|
|
{
|
|
|
|
enumerable: true,
|
|
|
|
configureable: false,
|
|
|
|
get: function(){
|
2015-12-31 13:37:27 +01:00
|
|
|
var callingStack = sharedFunctions.errorToCallingStack(new Error());
|
|
|
|
var status = check(callingStack, window.location);
|
2015-09-06 15:40:34 +02:00
|
|
|
if (status.type.indexOf(changedFunction.type) !== -1){
|
2015-09-08 11:41:33 +02:00
|
|
|
if (status.mode === "ask"){
|
2015-12-31 13:37:27 +01:00
|
|
|
status.mode = ask(window, changedFunction.type, this, callingStack);
|
2015-09-08 11:41:33 +02:00
|
|
|
}
|
2015-09-06 15:40:34 +02:00
|
|
|
switch (status.mode){
|
|
|
|
case "allow":
|
|
|
|
return original;
|
|
|
|
case "fake":
|
2015-12-31 13:37:27 +01:00
|
|
|
notify(window, callingStack);
|
2015-09-06 15:40:34 +02:00
|
|
|
return changedFunction.fake || undef;
|
2015-09-06 12:26:50 +02:00
|
|
|
//case "block":
|
|
|
|
default:
|
|
|
|
return undef;
|
2015-04-24 01:04:14 +02:00
|
|
|
}
|
2015-04-14 01:26:04 +02:00
|
|
|
}
|
2015-09-06 12:26:50 +02:00
|
|
|
else {
|
|
|
|
return original;
|
|
|
|
}
|
|
|
|
}
|
2015-04-14 01:26:04 +02:00
|
|
|
}
|
2015-09-06 12:26:50 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
observers.on("content-document-global-created", intercept);
|
|
|
|
unload(function(){
|
|
|
|
observers.off("content-document-global-created", intercept);
|
2014-08-20 10:21:38 +02:00
|
|
|
});
|
|
|
|
}());
|