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

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

Issue 6590816134889472: Noissue - Removed unused assets (Closed)
Patch Set: Created Oct. 14, 2014, 9:51 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 | « assets/js/FilterClasses.jsm ('k') | assets/js/FilterNotifier.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 file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18
19 //
20 // This file has been generated automatically from Adblock Plus source code
21 //
22
23 (function (_patchFunc2) {
24 const cacheVersion = 3;
25 var batchMode = false;
26 var isDirty = 0;
27 var FilterListener = {
28 startup: function () {
29 FilterNotifier.addListener(function (action, item, newValue, oldValue) {
30 if (/^filter\.(.*)/.test(action))
31 onFilterChange(RegExp["$1"], item, newValue, oldValue);
32 else
33 if (/^subscription\.(.*)/.test(action))
34 onSubscriptionChange(RegExp["$1"], item, newValue, oldValue);
35 else
36 onGenericChange(action, item);
37 }
38 );
39 ElemHide.init();
40 var initialized = false;
41 var cacheFile = Utils.resolveFilePath(Prefs.data_directory);
42 cacheFile.append("cache.js");
43 if (cacheFile.exists()) {
44 try {
45 var stream = Cc["@mozilla.org/network/file-input-stream;1"].createInst ance(Ci.nsIFileInputStream);
46 stream.init(cacheFile, 1, 292, 0);
47 var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
48 var cache = json.decodeFromStream(stream, "UTF-8");
49 stream.close();
50 if (cache.version == cacheVersion && cache.patternsTimestamp == Filter Storage.sourceFile.clone().lastModifiedTime) {
51 defaultMatcher.fromCache(cache);
52 ElemHide.fromCache(cache);
53 var loadDone = false;
54 function trapProperty(obj, prop) {
55 var origValue = obj[prop];
56 delete obj[prop];
57 obj.__defineGetter__(prop, function () {
58 delete obj[prop];
59 obj[prop] = origValue;
60 if (!loadDone) {
61 loadDone = true;
62 FilterStorage.loadFromDisk(null, true);
63 }
64 return obj[prop];
65 }
66 );
67 obj.__defineSetter__(prop, function (value) {
68 delete obj[prop];
69 return obj[prop] = value;
70 }
71 );
72 }
73 for (var _loopIndex0 = 0;
74 _loopIndex0 < ["fileProperties", "subscriptions", "knownSubscription s", "addSubscription", "removeSubscription", "updateSubscriptionFilters", "addFi lter", "removeFilter", "increaseHitCount", "resetHitCounts"].length; ++ _loopInd ex0) {
75 var prop = ["fileProperties", "subscriptions", "knownSubscriptions ", "addSubscription", "removeSubscription", "updateSubscriptionFilters", "addFil ter", "removeFilter", "increaseHitCount", "resetHitCounts"][_loopIndex0];
76 trapProperty(FilterStorage, prop);
77 }
78 trapProperty(Filter, "fromText");
79 trapProperty(Filter, "knownFilters");
80 trapProperty(Subscription, "fromURL");
81 trapProperty(Subscription, "knownSubscriptions");
82 initialized = true;
83 ElemHide.apply();
84 }
85 }
86 catch (e){
87 Cu.reportError(e);
88 }
89 }
90 if (!initialized)
91 FilterStorage.loadFromDisk();
92 Utils.observerService.addObserver(FilterListenerPrivate, "browser:purge-se ssion-history", true);
93 }
94 ,
95 shutdown: function () {
96 if (isDirty > 0)
97 FilterStorage.saveToDisk();
98 }
99 ,
100 get batchMode() {
101 return batchMode;
102 }
103 ,
104 set batchMode(value) {
105 batchMode = value;
106 flushElemHide();
107 }
108 ,
109 setDirty: function (factor) {
110 if (factor == 0 && isDirty > 0)
111 isDirty = 1;
112 else
113 isDirty += factor;
114 if (isDirty >= 1 && !filtersFlushScheduled) {
115 Utils.runAsync(flushFiltersInternal);
116 filtersFlushScheduled = true;
117 }
118 }
119
120 };
121 var FilterListenerPrivate = {
122 observe: function (subject, topic, data) {
123 if (topic == "browser:purge-session-history" && Prefs.clearStatsOnHistoryP urge) {
124 FilterStorage.resetHitCounts();
125 FilterListener.setDirty(0);
126 Prefs.recentReports = "[]";
127 }
128 }
129 ,
130 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIOb server])
131 };
132 var elemhideFlushScheduled = false;
133 function flushElemHide() {
134 if (elemhideFlushScheduled)
135 return ;
136 Utils.runAsync(flushElemHideInternal);
137 elemhideFlushScheduled = true;
138 }
139 function flushElemHideInternal() {
140 elemhideFlushScheduled = false;
141 if (!batchMode && ElemHide.isDirty)
142 ElemHide.apply();
143 }
144 var filtersFlushScheduled = false;
145 function flushFiltersInternal() {
146 filtersFlushScheduled = false;
147 FilterStorage.saveToDisk();
148 }
149 function addFilter(filter) {
150 if (!(filter instanceof ActiveFilter) || filter.disabled)
151 return ;
152 var hasEnabled = false;
153 for (var i = 0;
154 i < filter.subscriptions.length; i++)
155 if (!filter.subscriptions[i].disabled)
156 hasEnabled = true;
157 if (!hasEnabled)
158 return ;
159 if (filter instanceof RegExpFilter)
160 defaultMatcher.add(filter);
161 else
162 if (filter instanceof ElemHideFilter)
163 ElemHide.add(filter);
164 }
165 function removeFilter(filter) {
166 if (!(filter instanceof ActiveFilter))
167 return ;
168 if (!filter.disabled) {
169 var hasEnabled = false;
170 for (var i = 0;
171 i < filter.subscriptions.length; i++)
172 if (!filter.subscriptions[i].disabled)
173 hasEnabled = true;
174 if (hasEnabled)
175 return ;
176 }
177 if (filter instanceof RegExpFilter)
178 defaultMatcher.remove(filter);
179 else
180 if (filter instanceof ElemHideFilter)
181 ElemHide.remove(filter);
182 }
183 function onSubscriptionChange(action, subscription, newValue, oldValue) {
184 if (action == "homepage" || action == "downloadStatus" || action == "lastDow nload")
185 FilterListener.setDirty(0.2);
186 else
187 FilterListener.setDirty(1);
188 if (action != "added" && action != "removed" && action != "disabled" && acti on != "updated")
189 return ;
190 if (action != "removed" && !(subscription.url in FilterStorage.knownSubscrip tions)) {
191 return ;
192 }
193 if ((action == "added" || action == "removed" || action == "updated") && sub scription.disabled) {
194 return ;
195 }
196 if (action == "added" || action == "removed" || action == "disabled") {
197 var method = (action == "added" || (action == "disabled" && newValue == fa lse) ? addFilter : removeFilter);
198 if (subscription.filters)
199 subscription.filters.forEach(method);
200 }
201 else
202 if (action == "updated") {
203 subscription.oldFilters.forEach(removeFilter);
204 subscription.filters.forEach(addFilter);
205 }
206 flushElemHide();
207 }
208 function onFilterChange(action, filter, newValue, oldValue) {
209 if (action == "hitCount" || action == "lastHit")
210 FilterListener.setDirty(0.0001);
211 else
212 if (action == "disabled" || action == "moved")
213 FilterListener.setDirty(0.2);
214 else
215 FilterListener.setDirty(1);
216 if (action != "added" && action != "removed" && action != "disabled")
217 return ;
218 if ((action == "added" || action == "removed") && filter.disabled) {
219 return ;
220 }
221 if (action == "added" || (action == "disabled" && newValue == false))
222 addFilter(filter);
223 else
224 removeFilter(filter);
225 flushElemHide();
226 }
227 function onGenericChange(action) {
228 if (action == "load") {
229 isDirty = 0;
230 defaultMatcher.clear();
231 ElemHide.clear();
232 for (var _loopIndex1 = 0;
233 _loopIndex1 < FilterStorage.subscriptions.length; ++ _loopIndex1) {
234 var subscription = FilterStorage.subscriptions[_loopIndex1];
235 if (!subscription.disabled)
236 subscription.filters.forEach(addFilter);
237 }
238 flushElemHide();
239 }
240 else
241 if (action == "save") {
242 isDirty = 0;
243 var cache = {
244 version: cacheVersion,
245 patternsTimestamp: FilterStorage.sourceFile.clone().lastModifiedTime
246 };
247 defaultMatcher.toCache(cache);
248 ElemHide.toCache(cache);
249 var cacheFile = Utils.resolveFilePath(Prefs.data_directory);
250 cacheFile.append("cache.js");
251 try {
252 cacheFile.parent.create(Ci.nsIFile.DIRECTORY_TYPE, 493);
253 }
254 catch (e){}
255 try {
256 var fileStream = Cc["@mozilla.org/network/file-output-stream;1"].creat eInstance(Ci.nsIFileOutputStream);
257 fileStream.init(cacheFile, 2 | 8 | 32, 420, 0);
258 var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
259 if (Utils.versionComparator.compare(Utils.platformVersion, "5.0") >= 0 ) {
260 json.encodeToStream(fileStream, "UTF-8", false, cache);
261 fileStream.close();
262 }
263 else {
264 var stream = Cc["@mozilla.org/intl/converter-output-stream;1"].creat eInstance(Ci.nsIConverterOutputStream);
265 stream.init(fileStream, "UTF-8", 16384, Ci.nsIConverterInputStream.D EFAULT_REPLACEMENT_CHARACTER);
266 stream.writeString(json.encode(cache));
267 stream.close();
268 }
269 }
270 catch (e){
271 delete FilterStorage.fileProperties.cacheTimestamp;
272 Cu.reportError(e);
273 }
274 }
275 }
276 if (typeof _patchFunc2 != "undefined")
277 eval("(" + _patchFunc2.toString() + ")()");
278 window.FilterListener = FilterListener;
279 }
280 )(window.FilterListenerPatch);
OLDNEW
« no previous file with comments | « assets/js/FilterClasses.jsm ('k') | assets/js/FilterNotifier.jsm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld