2016-02-13 12:48:22 +01:00
|
|
|
/* jslint moz: true */
|
2016-02-13 12:28:36 +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/. */
|
|
|
|
(function(){
|
|
|
|
"use strict";
|
|
|
|
|
2016-08-06 19:17:36 +02:00
|
|
|
const {changedFunctions, setRandomSupply} = require("./modifiedAPI");
|
|
|
|
const randomSupplies = require("./randomSupplies");
|
|
|
|
setRandomSupply(randomSupplies.nonPersistent);
|
2016-02-13 12:28:36 +01:00
|
|
|
var apiNames = Object.keys(changedFunctions);
|
|
|
|
var undef;
|
2016-10-24 22:30:57 +02:00
|
|
|
var exportFunction = require("chrome").Cu.exportFunction;
|
2016-08-06 19:17:36 +02:00
|
|
|
function setRandomSupplyByType(type){
|
|
|
|
switch (type){
|
|
|
|
case "persistent":
|
|
|
|
setRandomSupply(randomSupplies.persistent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
setRandomSupply(randomSupplies.nonPersistent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.setRandomSupplyByType = setRandomSupplyByType;
|
2017-01-31 20:00:02 +01:00
|
|
|
|
|
|
|
function getURL(window){
|
2017-02-01 11:15:05 +01:00
|
|
|
if (!window.location.href || window.location.href === "about:blank"){
|
2017-01-31 20:00:02 +01:00
|
|
|
if (window !== window.parent){
|
|
|
|
return getURL(window.parent);
|
|
|
|
}
|
|
|
|
else if (window.opener){
|
|
|
|
return getURL(window.opener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return window.location.href;
|
|
|
|
}
|
|
|
|
|
2016-11-13 15:09:03 +01:00
|
|
|
exports.intercept = function intercept({subject: window}, {check, checkStack, ask, notify, prefs}){
|
2017-01-31 20:00:02 +01:00
|
|
|
var siteStatus = check({url: getURL(window)});
|
2016-11-19 15:35:00 +01:00
|
|
|
if (siteStatus.mode !== "allow"){
|
|
|
|
apiNames.forEach(function(name){
|
|
|
|
var changedFunction = changedFunctions[name];
|
|
|
|
if (changedFunction.getStatus(undefined, siteStatus).active){
|
2016-12-26 14:36:01 +01:00
|
|
|
(Array.isArray(changedFunction.object)? changedFunction.object: [changedFunction.object]).forEach(function(object){
|
2017-02-22 17:46:17 +01:00
|
|
|
var constructor = window.wrappedJSObject[object];
|
|
|
|
if (constructor){
|
|
|
|
var original = constructor.prototype[name];
|
|
|
|
|
|
|
|
Object.defineProperty(
|
|
|
|
constructor.prototype,
|
|
|
|
name,
|
|
|
|
{
|
|
|
|
enumerable: true,
|
|
|
|
configureable: false,
|
|
|
|
get: function(){
|
|
|
|
var url = getURL(window);
|
|
|
|
if (!url){
|
|
|
|
return undef;
|
2016-12-26 14:36:01 +01:00
|
|
|
}
|
2017-02-22 17:46:17 +01:00
|
|
|
var error = new Error();
|
|
|
|
if (checkStack(error.stack)){
|
|
|
|
return original;
|
|
|
|
}
|
|
|
|
var funcStatus = changedFunction.getStatus(this, siteStatus);
|
|
|
|
|
|
|
|
if (funcStatus.active){
|
|
|
|
if (funcStatus.mode === "ask"){
|
|
|
|
funcStatus.mode = ask({window: window, type: changedFunction.type, canvas: this, errorStack: error.stack});
|
|
|
|
}
|
|
|
|
switch (funcStatus.mode){
|
|
|
|
case "allow":
|
|
|
|
return original;
|
|
|
|
case "fake":
|
|
|
|
setRandomSupplyByType(prefs("rng"));
|
|
|
|
var fake = changedFunction.fakeGenerator(prefs, function(messageId){
|
|
|
|
notify({url, errorStack: error.stack, messageId});
|
|
|
|
}, original);
|
|
|
|
switch (fake){
|
|
|
|
case true:
|
|
|
|
return original;
|
|
|
|
case false:
|
|
|
|
return undef;
|
|
|
|
default:
|
|
|
|
return exportFunction(fake, window.wrappedJSObject);
|
|
|
|
}
|
|
|
|
//case "block":
|
|
|
|
default:
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return original;
|
2016-12-26 14:36:01 +01:00
|
|
|
}
|
2016-11-19 15:35:00 +01:00
|
|
|
}
|
2016-11-13 15:09:03 +01:00
|
|
|
}
|
2017-02-22 17:46:17 +01:00
|
|
|
);
|
|
|
|
}
|
2016-12-26 14:36:01 +01:00
|
|
|
});
|
2016-11-19 15:35:00 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-02-13 12:48:22 +01:00
|
|
|
};
|
2016-02-13 12:28:36 +01:00
|
|
|
}());
|