1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-2015 Eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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");
let {Utils} = require("utils");
/**
* about: URL module used to count hits.
* @class
*/
let AboutHandler = exports.AboutHandler =
{
classID: Components.ID("{55fb7be0-1dd2-11b2-98e6-9e97caf8ba67}"),
classDescription: "Element hiding hit registration protocol handler",
aboutPrefix: "abp-elemhidehit",
/**
* Registers handler on startup.
*/
init: function()
{
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(this.classID, this.classDescription,
"@mozilla.org/network/protocol/about;1?what=" + this.aboutPrefix, this);
onShutdown.add(function()
{
registrar.unregisterFactory(this.classID, this);
}.bind(this));
},
//
// Factory implementation
//
createInstance: function(outer, iid)
{
if (outer != null)
throw Cr.NS_ERROR_NO_AGGREGATION;
return this.QueryInterface(iid);
},
//
// About module implementation
//
getURIFlags: function(uri)
{
return ("HIDE_FROM_ABOUTABOUT" in Ci.nsIAboutModule ? Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT : 0);
},
newChannel: function(uri)
{
let match = /\?(\d+)/.exec(uri.path);
if (!match)
throw Cr.NS_ERROR_FAILURE;
return new HitRegistrationChannel(uri, match[1]);
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory, Ci.nsIAboutModule])
};
AboutHandler.init();
/**
* Channel returning data for element hiding hits.
* @constructor
*/
function HitRegistrationChannel(uri, key)
{
this.key = key;
this.URI = this.originalURI = uri;
}
HitRegistrationChannel.prototype = {
key: null,
URI: null,
originalURI: null,
contentCharset: "utf-8",
contentLength: 0,
contentType: "text/xml",
owner: Utils.systemPrincipal,
securityInfo: null,
notificationCallbacks: null,
loadFlags: 0,
loadGroup: null,
name: null,
status: Cr.NS_OK,
asyncOpen: function(listener, context)
{
let stream = this.open();
Utils.runAsync(function()
{
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) {}
}, this);
},
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;
},
isPending: function()
{
return false;
},
cancel: function()
{
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
suspend: function()
{
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
resume: function()
{
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel, Ci.nsIRequest])
};
|