Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: inject.preload.js

Issue 29586710: Issue 5382 - Wrap DOM mutation APIs to protect frames (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Oct. 23, 2017, 10:09 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: inject.preload.js
===================================================================
--- a/inject.preload.js
+++ b/inject.preload.js
@@ -67,16 +67,41 @@
"(" + injectedToString() + ")('" + eventName + "', true);"
);
delete contentWindow[eventName];
}
catch (e) {}
}
}
+ function wrapAPIForIFrame(object, api)
+ {
+ let func = object[api];
+ object[api] = function(...args)
+ {
+ let returnValue = func.apply(this, args);
+ for (let i = 0; i < window.length; i++)
+ injectIntoContentWindow(window[i]);
+ return returnValue;
+ };
+ }
+
+ function wrapPropertyAPIForIFrame(object, api)
+ {
+ let descriptor = Object.getOwnPropertyDescriptor(object, api);
+ wrapAPIForIFrame(descriptor, "set");
+ Object.defineProperty(object, api, descriptor);
+ }
+
+ wrapAPIForIFrame(Node.prototype, "appendChild");
+ wrapAPIForIFrame(Node.prototype, "insertBefore");
+ wrapAPIForIFrame(Node.prototype, "replaceChild");
+
+ wrapPropertyAPIForIFrame(Element.prototype, "innerHTML");
+
for (let element of [HTMLFrameElement, HTMLIFrameElement, HTMLObjectElement])
{
let contentDocumentDesc = Object.getOwnPropertyDescriptor(
element.prototype, "contentDocument"
);
let contentWindowDesc = Object.getOwnPropertyDescriptor(
element.prototype, "contentWindow"
);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld