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

Unified Diff: lib/elemHideHitRegistration.js

Issue 29329246: Issue 3108 - Inject our about: module into all processes (Closed)
Patch Set: Created Oct. 16, 2015, 12:02 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
Index: lib/elemHideHitRegistration.js
===================================================================
--- a/lib/elemHideHitRegistration.js
+++ b/lib/elemHideHitRegistration.js
@@ -14,25 +14,70 @@
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @fileOverview Hit counts for element hiding.
*/
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+try
+{
+ // Hack: SDK loader masks our Components object with a getter.
+ let proto = Object.getPrototypeOf(this);
+ let property = Object.getOwnPropertyDescriptor(proto, "Components");
+ if (property && property.get)
+ delete proto.Components;
+}
+catch (e)
+{
+ Cu.reportError(e);
+}
+
+let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
+let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm")
let {Utils} = require("utils");
+let messageID = 0;
+
+// The allowXBL binding below won't have any effect on the element. For elements
+// that should be hidden however we don't return any binding at all, this makes
+// Gecko stop constructing the node - it cannot be shown.
+const allowXBL = "<bindings xmlns='http://www.mozilla.org/xbl'><binding id='dummy' bindToUntrustedContent='true'/></bindings>";
+const hideXBL = "<bindings xmlns='http://www.mozilla.org/xbl'/>";
+
+function getFrames(window)
+{
+ let frames = [];
+ while (window)
+ {
+ let frame = {
+ location: window.location.href,
+ sitekey: null
+ };
+
+ let documentElement = window.document && window.document.documentElement;
+ if (documentElement)
+ frame.sitekey = documentElement.getAttribute("data-adblockkey")
+
+ if (window == window.parent)
+ frame.privateBrowsing = PrivateBrowsingUtils.isWindowPrivate(window);
+
+ frames.push(frame);
+ window = (window != window.parent ? window.parent : null);
+ }
+ return frames;
+}
+
/**
* about: URL module used to count hits.
* @class
*/
-let AboutHandler = exports.AboutHandler =
+let AboutHandler =
{
classID: Components.ID("{55fb7be0-1dd2-11b2-98e6-9e97caf8ba67}"),
classDescription: "Element hiding hit registration protocol handler",
aboutPrefix: "abp-elemhidehit",
/**
* Registers handler on startup.
*/
@@ -103,58 +148,55 @@ HitRegistrationChannel.prototype = {
notificationCallbacks: null,
loadFlags: 0,
loadGroup: null,
name: null,
status: Cr.NS_OK,
asyncOpen: function(listener, context)
{
- let stream = this.open();
- Utils.runAsync(() =>
+ let responseMessage = "AdblockPlus:ElemHideHit:Response" + (++messageID);
+
+ let processResponse = (message) =>
{
+ removeMessageListener(responseMessage, processResponse);
+
+ let data = (message.data ? hideXBL : allowXBL);
+ let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
+ stream.setData(data, data.length);
+
try {
listener.onStartRequest(this, context);
} catch(e) {}
try {
listener.onDataAvailable(this, context, stream, 0, stream.available());
} catch(e) {}
try {
listener.onStopRequest(this, context, Cr.NS_OK);
} catch(e) {}
+ };
+
+ addMessageListener(responseMessage, processResponse);
+ sendAsyncMessage("AdblockPlus:ElemHideHit", {
+ responseMessage,
+ key: this.key,
+ frames: getFrames(Utils.getRequestWindow(this))
});
},
asyncOpen2: function(listener)
{
if (!this.loadInfo.triggeringPrincipal.equals(Utils.systemPrincipal))
throw Cr.NS_ERROR_FAILURE;
this.asyncOpen(listener, null);
},
open: function()
{
- let {Policy} = require("contentPolicy");
- let {ElemHide} = require("elemHide");
-
- // This dummy binding below won't have any effect on the element. For
- // elements that should be hidden however we don't return any binding at
- // all, this makes Gecko stop constructing the node - it cannot be shown.
- let data = "<bindings xmlns='http://www.mozilla.org/xbl'><binding id='dummy' bindToUntrustedContent='true'/></bindings>";
- let filter = ElemHide.getFilterByKey(this.key);
- if (filter)
- {
- let wnd = Utils.getRequestWindow(this);
- if (wnd && wnd.document && !Policy.processNode(wnd, wnd.document, Policy.type.ELEMHIDE, filter))
- data = "<bindings xmlns='http://www.mozilla.org/xbl'/>";
- }
-
- let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
- stream.setData(data, data.length);
- return stream;
+ throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
isPending: function()
{
return false;
},
cancel: function()
{
throw Cr.NS_ERROR_NOT_IMPLEMENTED;

Powered by Google App Engine
This is Rietveld