mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-31 09:01:56 +01:00
parent
ef1c45efab
commit
c3d4a1901c
@ -11,43 +11,52 @@
|
|||||||
else {
|
else {
|
||||||
scope = require.register("./iframeProtection", {});
|
scope = require.register("./iframeProtection", {});
|
||||||
}
|
}
|
||||||
const {getWrapped} = require("./modifiedAPIFunctions");
|
|
||||||
|
|
||||||
scope.protect = function protect(window, wrappedWindow, singleCallback, allCallback){
|
scope.protect = function protect(window, wrappedWindow, singleCallback, allCallback){
|
||||||
|
|
||||||
[window.HTMLIFrameElement, window.HTMLFrameElement].forEach(function(constructor){
|
["HTMLIFrameElement", "HTMLFrameElement"].forEach(function(constructorName){
|
||||||
var oldContentWindowGetter = constructor.prototype.__lookupGetter__("contentWindow");
|
const constructor = window[constructorName];
|
||||||
Object.defineProperty(
|
const wrappedConstructor = wrappedWindow[constructorName];
|
||||||
getWrapped(constructor.prototype),
|
|
||||||
"contentWindow",
|
const contentWindowDescriptor = Object.getOwnPropertyDescriptor(
|
||||||
{
|
constructor.prototype,
|
||||||
enumerable: true,
|
"contentWindow"
|
||||||
configurable: true,
|
|
||||||
get: exportFunction(function(){
|
|
||||||
var window = oldContentWindowGetter.call(this);
|
|
||||||
if (window){
|
|
||||||
singleCallback(window);
|
|
||||||
}
|
|
||||||
return window;
|
|
||||||
}, window)
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
var oldContentDocumentGetter = constructor.prototype.__lookupGetter__("contentDocument");
|
const originalContentWindowGetter = contentWindowDescriptor.get;
|
||||||
Object.defineProperty(
|
const contentWindowTemp = {
|
||||||
getWrapped(constructor.prototype),
|
get contentWindow(){
|
||||||
"contentDocument",
|
var window = originalContentWindowGetter.call(this);
|
||||||
{
|
if (window){
|
||||||
enumerable: true,
|
singleCallback(window);
|
||||||
configurable: true,
|
}
|
||||||
get: exportFunction(function(){
|
return window;
|
||||||
var document = oldContentDocumentGetter.call(this);
|
|
||||||
if (document){
|
|
||||||
singleCallback(document.defaultView);
|
|
||||||
}
|
|
||||||
return document;
|
|
||||||
}, window)
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
contentWindowDescriptor.get = exportFunction(
|
||||||
|
Object.getOwnPropertyDescriptor(contentWindowTemp, "contentWindow").get,
|
||||||
|
window
|
||||||
);
|
);
|
||||||
|
Object.defineProperty(wrappedConstructor.prototype, "contentWindow", contentWindowDescriptor);
|
||||||
|
|
||||||
|
const contentDocumentDescriptor = Object.getOwnPropertyDescriptor(
|
||||||
|
constructor.prototype,
|
||||||
|
"contentDocument"
|
||||||
|
);
|
||||||
|
const originalContentDocumentGetter = contentDocumentDescriptor.get;
|
||||||
|
const contentDocumentTemp = {
|
||||||
|
get contentDocument(){
|
||||||
|
var document = originalContentDocumentGetter.call(this);
|
||||||
|
if (document){
|
||||||
|
singleCallback(document.defaultView);
|
||||||
|
}
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
contentDocumentDescriptor.get = exportFunction(
|
||||||
|
Object.getOwnPropertyDescriptor(contentDocumentTemp, "contentDocument").get,
|
||||||
|
window
|
||||||
|
);
|
||||||
|
Object.defineProperty(wrappedConstructor.prototype, "contentDocument", contentDocumentDescriptor);
|
||||||
});
|
});
|
||||||
[
|
[
|
||||||
// useless as length could be obtained before the iframe is created and window.frames === window
|
// useless as length could be obtained before the iframe is created and window.frames === window
|
||||||
|
@ -6,7 +6,7 @@ Version 0.5.11:
|
|||||||
-
|
-
|
||||||
|
|
||||||
fixes:
|
fixes:
|
||||||
-
|
- improved protection of (i)frame properties
|
||||||
|
|
||||||
known issues:
|
known issues:
|
||||||
- if a data URL is blocked the page action button does not appear
|
- if a data URL is blocked the page action button does not appear
|
||||||
|
@ -200,6 +200,10 @@ addTest("function name", function(log){
|
|||||||
func: window.__lookupSetter__("name"),
|
func: window.__lookupSetter__("name"),
|
||||||
expectedName: "set name"
|
expectedName: "set name"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
func: HTMLIFrameElement.prototype.__lookupGetter__("contentDocument"),
|
||||||
|
expectedName: "get contentDocument"
|
||||||
|
},
|
||||||
].map(checkName).some(function(b){return b;});
|
].map(checkName).some(function(b){return b;});
|
||||||
});
|
});
|
||||||
addTest("property descriptor", function(log){
|
addTest("property descriptor", function(log){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user