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

Side by Side Diff: assets/js/ElemHide.jsm

Issue 8482109: ABP/Android JavaScript code (Closed)
Patch Set: ABP/Android JavaScript code Created Nov. 13, 2012, 9:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | assets/js/FilterClasses.jsm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/.
5 */
6
7 //
8 // This file has been generated automatically from Adblock Plus source code
9 //
10
11 (function (_patchFunc0) {
12 var filterByKey = {
13 __proto__: null
14 };
15 var styleURL = null;
16 var ElemHide = {
17 isDirty: false,
18 applied: false,
19 keyByFilter: {
20 __proto__: null
21 },
22 init: function () {
23 Prefs.addListener(function (name) {
24 if (name == "enabled")
25 ElemHide.apply();
26 }
27 );
28 var styleFile = Utils.resolveFilePath(Prefs.data_directory);
29 styleFile.append("elemhide.css");
30 styleURL = Utils.ioService.newFileURI(styleFile).QueryInterface(Ci.nsIFile URL);
31 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar );
32 registrar.registerFactory(ElemHidePrivate.classID, ElemHidePrivate.classDe scription, "@mozilla.org/network/protocol/about;1?what=" + ElemHidePrivate.about Prefix, ElemHidePrivate);
33 }
34 ,
35 clear: function () {
36 filterByKey = {
37 __proto__: null
38 };
39 ElemHide.keyByFilter = {
40 __proto__: null
41 };
42 ElemHide.isDirty = false;
43 ElemHide.unapply();
44 }
45 ,
46 add: function (filter) {
47 if (filter.text in ElemHide.keyByFilter)
48 return ;
49 var key;
50 do {
51 key = Math.random().toFixed(15).substr(5);
52 }
53 while (key in filterByKey);
54 filterByKey[key] = filter.text;
55 ElemHide.keyByFilter[filter.text] = key;
56 ElemHide.isDirty = true;
57 }
58 ,
59 remove: function (filter) {
60 if (!(filter.text in ElemHide.keyByFilter))
61 return ;
62 var key = ElemHide.keyByFilter[filter.text];
63 delete filterByKey[key];
64 delete ElemHide.keyByFilter[filter.text];
65 ElemHide.isDirty = true;
66 }
67 ,
68 apply: function () {
69 if (ElemHide.applied)
70 ElemHide.unapply();
71 try {
72 if (!Prefs.enabled) {
73 return ;
74 }
75 if (ElemHide.isDirty) {
76 ElemHide.isDirty = false;
77 var domains = {
78 __proto__: null
79 };
80 var hasFilters = false;
81 for (var key in filterByKey) {
82 var filter = Filter.knownFilters[filterByKey[key]];
83 if (!filter) {
84 delete filterByKey[key];
85 continue;
86 }
87 var domain = filter.selectorDomain || "";
88 var list;
89 if (domain in domains)
90 list = domains[domain];
91 else {
92 list = {
93 __proto__: null
94 };
95 domains[domain] = list;
96 }
97 list[filter.selector] = key;
98 hasFilters = true;
99 }
100 if (!hasFilters) {
101 return ;
102 }
103 try {
104 styleURL.file.parent.create(Ci.nsIFile.DIRECTORY_TYPE, 493);
105 }
106 catch (e){}
107 var stream;
108 try {
109 stream = Cc["@mozilla.org/network/safe-file-output-stream;1"].create Instance(Ci.nsIFileOutputStream);
110 stream.init(styleURL.file, 2 | 8 | 32, 420, 0);
111 }
112 catch (e){
113 Cu.reportError(e);
114 return ;
115 }
116 var buf = [];
117 var maxBufLen = 1024;
118 function escapeChar(match) {
119 return "\\" + match.charCodeAt(0).toString(16) + " ";
120 }
121 function writeString(str, forceWrite) {
122 buf.push(str);
123 if (buf.length >= maxBufLen || forceWrite) {
124 var output = buf.join("").replace(/[^\x01-\x7F]/g, escapeChar);
125 stream.write(output, output.length);
126 buf.splice(0, buf.length);
127 }
128 }
129 var cssTemplate = "-moz-binding: url(about:" + ElemHidePrivate.aboutPr efix + "?%ID%#dummy) !important;";
130 for (var domain in domains) {
131 var rules = [];
132 var list = domains[domain];
133 if (domain)
134 writeString("@-moz-document domain(\"" + domain.split(",").join("\ "),domain(\"") + "\"){\n");
135 else {
136 writeString("@-moz-document url-prefix(\"http://\"),url-prefix(\"h ttps://\"),url-prefix(\"mailbox://\"),url-prefix(\"imap://\"),url-prefix(\"news: //\"),url-prefix(\"snews://\"){\n");
137 }
138 for (var selector in list)
139 writeString(selector + "{" + cssTemplate.replace("%ID%", list[sele ctor]) + "}\n");
140 writeString("}\n");
141 }
142 writeString("", true);
143 try {
144 stream.QueryInterface(Ci.nsISafeOutputStream).finish();
145 }
146 catch (e){
147 Cu.reportError(e);
148 return ;
149 }
150 }
151 try {
152 Utils.styleService.loadAndRegisterSheet(styleURL, Ci.nsIStyleSheetServ ice.USER_SHEET);
153 ElemHide.applied = true;
154 }
155 catch (e){
156 Cu.reportError(e);
157 }
158 }
159 finally {
160 FilterNotifier.triggerListeners("elemhideupdate");
161 }
162 }
163 ,
164 unapply: function () {
165 if (ElemHide.applied) {
166 try {
167 Utils.styleService.unregisterSheet(styleURL, Ci.nsIStyleSheetService.U SER_SHEET);
168 }
169 catch (e){
170 Cu.reportError(e);
171 }
172 ElemHide.applied = false;
173 }
174 }
175 ,
176 get styleURL() {
177 return ElemHide.applied ? styleURL.spec : null;
178 },
179 getFilterByKey: function (key) {
180 return (key in filterByKey ? Filter.knownFilters[filterByKey[key]] : null) ;
181 }
182 ,
183 toCache: function (cache) {
184 cache.elemhide = {
185 filterByKey: filterByKey
186 };
187 }
188 ,
189 fromCache: function (cache) {
190 filterByKey = cache.elemhide.filterByKey;
191 filterByKey.__proto__ = null;
192 delete ElemHide.keyByFilter;
193 ElemHide.__defineGetter__("keyByFilter", function () {
194 var result = {
195 __proto__: null
196 };
197 for (var k in filterByKey)
198 result[filterByKey[k]] = k;
199 return ElemHide.keyByFilter = result;
200 }
201 );
202 ElemHide.__defineSetter__("keyByFilter", function (value) {
203 delete ElemHide.keyByFilter;
204 return ElemHide.keyByFilter = value;
205 }
206 );
207 }
208
209 };
210 var ElemHidePrivate = {
211 classID: Components.ID("{55fb7be0-1dd2-11b2-98e6-9e97caf8ba67}"),
212 classDescription: "Element hiding hit registration protocol handler",
213 aboutPrefix: "abp-elemhidehit",
214 createInstance: function (outer, iid) {
215 if (outer != null)
216 throw Cr.NS_ERROR_NO_AGGREGATION;
217 return this.QueryInterface(iid);
218 }
219 ,
220 getURIFlags: function (uri) {
221 return ("HIDE_FROM_ABOUTABOUT" in Ci.nsIAboutModule ? Ci.nsIAboutModule.HI DE_FROM_ABOUTABOUT : 0);
222 }
223 ,
224 newChannel: function (uri) {
225 if (!/\?(\d+)/.test(uri.path))
226 throw Cr.NS_ERROR_FAILURE;
227 return new HitRegistrationChannel(uri, RegExp["$1"]);
228 }
229 ,
230 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory, Ci.nsIAboutModule])
231 };
232 function HitRegistrationChannel(uri, key) {
233 this.key = key;
234 this.URI = this.originalURI = uri;
235 }
236 HitRegistrationChannel.prototype = {
237 key: null,
238 URI: null,
239 originalURI: null,
240 contentCharset: "utf-8",
241 contentLength: 0,
242 contentType: "text/xml",
243 owner: Utils.systemPrincipal,
244 securityInfo: null,
245 notificationCallbacks: null,
246 loadFlags: 0,
247 loadGroup: null,
248 name: null,
249 status: Cr.NS_OK,
250 asyncOpen: function (listener, context) {
251 var stream = this.open();
252 Utils.runAsync(function () {
253 try {
254 listener.onStartRequest(this, context);
255 }
256 catch (e){}
257 try {
258 listener.onDataAvailable(this, context, stream, 0, stream.available()) ;
259 }
260 catch (e){}
261 try {
262 listener.onStopRequest(this, context, Cr.NS_OK);
263 }
264 catch (e){}
265 }
266 , this);
267 }
268 ,
269 open: function () {
270 var data = "<bindings xmlns='http://www.mozilla.org/xbl'><binding id='dumm y'/></bindings>";
271 if (this.key in filterByKey) {
272 var wnd = Utils.getRequestWindow(this);
273 if (wnd && wnd.document && !Policy.processNode(wnd, wnd.document, Policy .type.ELEMHIDE, Filter.knownFilters[filterByKey[this.key]]))
274 data = "<bindings xmlns='http://www.mozilla.org/xbl'/>";
275 }
276 var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci .nsIStringInputStream);
277 stream.setData(data, data.length);
278 return stream;
279 }
280 ,
281 isPending: function () {
282 return false;
283 }
284 ,
285 cancel: function () {
286 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
287 }
288 ,
289 suspend: function () {
290 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
291 }
292 ,
293 resume: function () {
294 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
295 }
296 ,
297 QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel, Ci.nsIRequest])
298 };
299 if (typeof _patchFunc0 != "undefined")
300 eval("(" + _patchFunc0.toString() + ")()");
301 window.ElemHide = ElemHide;
302 }
303 )(window.ElemHidePatch);
OLDNEW
« no previous file with comments | « no previous file | assets/js/FilterClasses.jsm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld