2017-01-31 21:31:55 +01:00
|
|
|
/* 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";
|
2017-07-07 08:49:12 +02:00
|
|
|
|
2017-01-31 21:31:55 +01:00
|
|
|
const {intercept} = require("./intercept.js");
|
|
|
|
const {ask} = require("./askForPermission.js");
|
2017-09-23 23:37:46 +02:00
|
|
|
const lists = require("./lists.js");
|
2017-01-31 21:31:55 +01:00
|
|
|
const {check: originalCheck, checkStack: originalCheckStack} = require("./check.js");
|
|
|
|
|
2017-09-23 23:37:46 +02:00
|
|
|
const logging = require("./logging");
|
|
|
|
const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = logging;
|
2017-07-27 19:14:04 +02:00
|
|
|
setLogPrefix("frame script");
|
|
|
|
|
2017-01-31 21:31:55 +01:00
|
|
|
// Variable to "unload" the script
|
|
|
|
var enabled = true;
|
|
|
|
|
2017-07-27 19:14:04 +02:00
|
|
|
message("starting", location.href);
|
2017-01-31 21:31:55 +01:00
|
|
|
|
|
|
|
function check(message){
|
|
|
|
if (enabled){
|
|
|
|
return originalCheck(message);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return {type: [], mode: "allow"};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function checkStack(stack){
|
|
|
|
if (enabled){
|
|
|
|
return originalCheckStack(stack);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const _ = require("sdk/l10n").get;
|
|
|
|
function askWrapper(data){
|
|
|
|
return ask(data, {
|
|
|
|
_,
|
|
|
|
prefs
|
|
|
|
});
|
|
|
|
}
|
2017-07-16 00:25:19 +02:00
|
|
|
|
2017-07-27 19:14:04 +02:00
|
|
|
message("open port to background script");
|
2017-06-29 07:21:36 +02:00
|
|
|
var port = browser.runtime.connect();
|
|
|
|
var tabId;
|
|
|
|
port.onMessage.addListener(function(data){
|
|
|
|
if (data.hasOwnProperty("tabId")){
|
2017-07-27 19:14:04 +02:00
|
|
|
notice("my tab id is", data.tabId);
|
2017-06-29 07:21:36 +02:00
|
|
|
tabId = data.tabId;
|
|
|
|
}
|
2017-09-23 23:37:46 +02:00
|
|
|
if (data.hasOwnProperty("persistentRnd")){
|
|
|
|
notice("got persistent random data", data.persistentRnd);
|
|
|
|
const {persistent: persistentRnd} = require("./randomSupplies.js");
|
|
|
|
Object.keys(data.persistentRnd).forEach(function(domain){
|
|
|
|
verbose("random data for", domain, data.persistentRnd[domain]);
|
|
|
|
persistentRnd.setDomainRnd(domain, data.persistentRnd[domain]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (settings.isStillDefault && data.hasOwnProperty("settings")){
|
|
|
|
notice("got settings from background script");
|
|
|
|
Object.keys(data.settings).forEach(function(key){
|
|
|
|
settings[key] = data.settings[key];
|
|
|
|
});
|
|
|
|
settings.isStillDefault = false;
|
|
|
|
logging.clearQueue();
|
|
|
|
lists.updateAll();
|
|
|
|
}
|
2017-06-29 07:21:36 +02:00
|
|
|
});
|
|
|
|
var notifications = [];
|
2017-01-31 21:31:55 +01:00
|
|
|
function notify(data){
|
2017-06-29 07:21:36 +02:00
|
|
|
notifications.push(data);
|
|
|
|
port.postMessage({"canvasBlocker-notify": data});
|
2017-01-31 21:31:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function prefs(name){
|
2017-09-23 23:40:57 +02:00
|
|
|
return settings[name];
|
2017-01-31 21:31:55 +01:00
|
|
|
}
|
|
|
|
|
2017-06-25 22:33:12 +02:00
|
|
|
|
|
|
|
var interceptedWindows = new WeakMap();
|
|
|
|
function interceptWindow(window){
|
2017-07-07 08:49:12 +02:00
|
|
|
if (!enabled || interceptedWindows.get(window)){
|
2017-06-25 22:33:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-07-16 00:25:19 +02:00
|
|
|
|
2017-07-18 16:14:03 +02:00
|
|
|
try {
|
|
|
|
var href = window.location.href;
|
|
|
|
}
|
|
|
|
catch (e){
|
|
|
|
// we are unable to read the location due to SOP
|
|
|
|
// therefore we also can not intercept anything.
|
2017-09-23 23:40:57 +02:00
|
|
|
warning("NOT intercepting window due to SOP", window);
|
2017-07-18 16:14:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-27 19:14:04 +02:00
|
|
|
message("intercepting window", window);
|
2017-06-25 22:33:12 +02:00
|
|
|
intercept(
|
|
|
|
{subject: window},
|
|
|
|
{check, checkStack, ask: askWrapper, notify, prefs}
|
|
|
|
);
|
2017-07-27 19:14:04 +02:00
|
|
|
message("prepare to intercept (i)frames.");
|
2017-06-25 22:33:12 +02:00
|
|
|
|
|
|
|
[window.HTMLIFrameElement, window.HTMLFrameElement].forEach(function(constructor){
|
|
|
|
var oldContentWindowGetter = constructor.prototype.__lookupGetter__("contentWindow");
|
|
|
|
Object.defineProperty(
|
|
|
|
constructor.prototype.wrappedJSObject,
|
|
|
|
"contentWindow",
|
|
|
|
{
|
|
|
|
enumerable: true,
|
|
|
|
configureable: true,
|
|
|
|
get: exportFunction(function(){
|
|
|
|
var window = oldContentWindowGetter.call(this);
|
|
|
|
interceptWindow(window);
|
|
|
|
return window;
|
|
|
|
}, window)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
var oldContentDocumentGetter = constructor.prototype.__lookupGetter__("contentDocument");
|
|
|
|
Object.defineProperty(
|
|
|
|
constructor.prototype.wrappedJSObject,
|
|
|
|
"contentDocument",
|
|
|
|
{
|
|
|
|
enumerable: true,
|
|
|
|
configureable: true,
|
|
|
|
get: exportFunction(function(){
|
|
|
|
var document = oldContentDocumentGetter.call(this);
|
|
|
|
interceptWindow(document.defaultView);
|
|
|
|
return document;
|
|
|
|
}, window)
|
|
|
|
}
|
|
|
|
);
|
2017-01-31 21:31:55 +01:00
|
|
|
});
|
2017-06-25 22:33:12 +02:00
|
|
|
|
|
|
|
interceptedWindows.set(window, true);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2017-09-23 23:40:57 +02:00
|
|
|
if (settings.isStillDefault){
|
|
|
|
message("load settings");
|
|
|
|
browser.storage.local.get().then(function(data){
|
|
|
|
Object.keys(data).forEach(function(key){
|
|
|
|
notice("loaded setting:", key, ":", data[key]);
|
|
|
|
settings[key] = data[key];
|
|
|
|
});
|
|
|
|
settings.isStillDefault = false;
|
|
|
|
logging.clearQueue();
|
2017-09-24 10:07:33 +02:00
|
|
|
lists.updateAll();
|
2017-09-23 23:40:57 +02:00
|
|
|
interceptWindow(window);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
interceptWindow(window);
|
|
|
|
}
|
2017-07-07 08:49:12 +02:00
|
|
|
|
2017-07-27 19:14:04 +02:00
|
|
|
message("register listener for messages from background script");
|
2017-06-25 22:33:12 +02:00
|
|
|
browser.runtime.onMessage.addListener(function(data){
|
|
|
|
if (data["canvasBlocker-unload"]){
|
|
|
|
enabled = false;
|
|
|
|
}
|
2017-07-18 16:16:38 +02:00
|
|
|
if (data.hasOwnProperty("canvasBlocker-sendNotifications") && data["canvasBlocker-sendNotifications"] === tabId){
|
2017-07-27 19:14:04 +02:00
|
|
|
notice("sending notifications:", notifications);
|
2017-06-29 07:21:36 +02:00
|
|
|
browser.runtime.sendMessage({
|
|
|
|
sender: tabId,
|
|
|
|
"canvasBlocker-notifications": notifications
|
|
|
|
});
|
2017-07-27 19:14:04 +02:00
|
|
|
notice("notifications sent");
|
2017-06-29 07:21:36 +02:00
|
|
|
}
|
2017-01-31 21:31:55 +01:00
|
|
|
});
|
2017-07-07 08:49:12 +02:00
|
|
|
|
2017-07-18 16:17:19 +02:00
|
|
|
|
2017-07-27 19:14:04 +02:00
|
|
|
message("register listener for settings changes");
|
2017-07-07 08:49:12 +02:00
|
|
|
browser.storage.onChanged.addListener(function(change, area){
|
|
|
|
if (area === "local"){
|
|
|
|
Object.keys(change).forEach(function(key){
|
2017-07-27 19:14:04 +02:00
|
|
|
notice("setting changed:", key, ":", change[key].newValue);
|
2017-07-07 08:49:12 +02:00
|
|
|
settings[key] = change[key].newValue;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-01-31 21:31:55 +01:00
|
|
|
}());
|