mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
First working webExtesion.
This commit is contained in:
parent
4ea073132d
commit
cba5680406
9 changed files with 266 additions and 310 deletions
70
lib/frame.js
70
lib/frame.js
|
@ -4,7 +4,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
(function(){
|
||||
"use strict";
|
||||
const {process, frames} = require("sdk/remote/child");
|
||||
const {intercept} = require("./intercept.js");
|
||||
const {ask} = require("./askForPermission.js");
|
||||
const {check: originalCheck, checkStack: originalCheckStack} = require("./check.js");
|
||||
|
@ -38,7 +37,7 @@
|
|||
});
|
||||
}
|
||||
function notify(data){
|
||||
process.port.emit("canvasBlocker-notify", data);
|
||||
browser.runtime.sendMessage({"canvasBlocker-notify": data});
|
||||
}
|
||||
|
||||
const preferences = require("sdk/simple-prefs");
|
||||
|
@ -46,22 +45,59 @@
|
|||
return preferences.prefs[name];
|
||||
}
|
||||
|
||||
frames.forEvery(function(frame){
|
||||
frame.addEventListener("DOMWindowCreated", function(ev){
|
||||
function notify(data){
|
||||
frame.port.emit("canvasBlocker-notify", data);
|
||||
}
|
||||
if (enabled){
|
||||
var subject = ev.target.defaultView;
|
||||
intercept(
|
||||
{subject},
|
||||
{check, checkStack, ask: askWrapper, notify, prefs}
|
||||
);
|
||||
}
|
||||
|
||||
var interceptedWindows = new WeakMap();
|
||||
function interceptWindow(window){
|
||||
if (interceptedWindows.get(window)){
|
||||
return false;
|
||||
}
|
||||
intercept(
|
||||
{subject: window},
|
||||
{check, checkStack, ask: askWrapper, notify, prefs}
|
||||
);
|
||||
|
||||
[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)
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
interceptedWindows.set(window, true);
|
||||
return true;
|
||||
};
|
||||
|
||||
if (enabled){
|
||||
interceptWindow(window);
|
||||
}
|
||||
|
||||
process.port.on("canvasBlocker-unload", function unload(){
|
||||
enabled = false;
|
||||
browser.runtime.onMessage.addListener(function(data){
|
||||
if (data["canvasBlocker-unload"]){
|
||||
enabled = false;
|
||||
}
|
||||
});
|
||||
}());
|
Loading…
Add table
Add a link
Reference in a new issue