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

Delta Between Two Patch Sets: background.js

Issue 5646124035604480: Issue 154 - Added UI for devtools panel on Chrome (Closed)
Left Patch Set: Rebased and adapted for API changes Created March 12, 2015, 4:08 p.m.
Right Patch Set: Added new request types Created Jan. 28, 2016, 7:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | devtools-panel.html » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
(...skipping 10 matching lines...) Expand all
24 var params = window.location.search.substr(1).split("&"); 24 var params = window.location.search.substr(1).split("&");
25 for (var i = 0; i < params.length; i++) 25 for (var i = 0; i < params.length; i++)
26 { 26 {
27 var parts = params[i].split("=", 2); 27 var parts = params[i].split("=", 2);
28 if (parts.length == 2 && parts[0] in data) 28 if (parts.length == 2 && parts[0] in data)
29 data[parts[0]] = decodeURIComponent(parts[1]); 29 data[parts[0]] = decodeURIComponent(parts[1]);
30 } 30 }
31 } 31 }
32 } 32 }
33 33
34 var subscriptions =[ 34 var params = {
35 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", 35 blockedURLs: "",
36 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", 36 seenDataCorruption: false,
37 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" 37 filterlistsReinitialized: false,
38 ]; 38 addSubscription: false,
39 filterError: false
40 };
41 updateFromURL(params);
39 42
40 var modules = {}; 43 var modules = {};
41 global.require = function(module) 44 global.require = function(module)
42 { 45 {
43 return modules[module]; 46 return modules[module];
44 }; 47 };
45 48
46 modules.utils = { 49 modules.utils = {
47 Utils: { 50 Utils: {
48 getDocLink: function(link) 51 getDocLink: function(link)
49 { 52 {
50 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin k); 53 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin k);
51 }, 54 },
52 get appLocale() 55 get appLocale()
53 { 56 {
54 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); 57 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
55 } 58 }
59 }
60 };
61
62 modules.prefs = {
63 Prefs: {
64 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org /exceptionrules.txt"
56 } 65 }
57 }; 66 };
58 67
59 modules.subscriptionClasses = { 68 modules.subscriptionClasses = {
60 Subscription: function(url) 69 Subscription: function(url)
61 { 70 {
62 this.url = url; 71 this.url = url;
63 this.title = "Subscription " + url; 72 this.title = "Subscription " + url;
64 this.disabled = false; 73 this.disabled = false;
65 this.lastDownload = 1234; 74 this.lastDownload = 1234;
66 }, 75 },
67 76
68 SpecialSubscription: function() {} 77 SpecialSubscription: function(url)
78 {
79 this.url = url;
80 this.disabled = false;
81 this.filters = knownFilters.slice();
82 }
69 }; 83 };
70 modules.subscriptionClasses.Subscription.fromURL = function(url) 84 modules.subscriptionClasses.Subscription.fromURL = function(url)
71 { 85 {
72 return new modules.subscriptionClasses.Subscription(url); 86 if (/^https?:\/\//.test(url))
87 return new modules.subscriptionClasses.Subscription(url);
88 else
89 return new modules.subscriptionClasses.SpecialSubscription(url);
73 }; 90 };
74 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription; 91 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription;
75 92
76 modules.filterStorage = { 93 modules.filterStorage = {
77 FilterStorage: { 94 FilterStorage: {
78 get subscriptions() 95 get subscriptions()
79 { 96 {
80 return subscriptions.map(modules.subscriptionClasses.Subscription.fromUR L); 97 var subscriptions = [];
98 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions)
99 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]);
100 return subscriptions;
81 }, 101 },
82 102
83 get knownSubscriptions() 103 get knownSubscriptions()
84 { 104 {
85 var result = {}; 105 return knownSubscriptions;
86 for (var i = 0; i < subscriptions.length; i++)
87 result[subscriptions[i]] = modules.subscriptionClasses.Subscription.fr omURL(subscriptions[i]);
88 return result;
89 }, 106 },
90 107
91 addSubscription: function(subscription) 108 addSubscription: function(subscription)
92 { 109 {
93 var index = subscriptions.indexOf(subscription.url); 110 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc riptions))
94 if (index < 0)
95 { 111 {
96 subscriptions.push(subscription.url); 112 knownSubscriptions[subscription.url] = modules.subscriptionClasses.Sub scription.fromURL(subscription.url);
97 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a dded", subscription); 113 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a dded", subscription);
98 } 114 }
99 }, 115 },
100 116
101 removeSubscription: function(subscription) 117 removeSubscription: function(subscription)
102 { 118 {
103 var index = subscriptions.indexOf(subscription.url); 119 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri ptions)
104 if (index >= 0)
105 { 120 {
106 subscriptions.splice(index, 1); 121 delete knownSubscriptions[subscription.url];
107 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r emoved", subscription); 122 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r emoved", subscription);
108 } 123 }
109 }, 124 },
110 125
111 addFilter: function() {}, 126 addFilter: function(filter)
112 removeFilter: function() {} 127 {
128 for (var i = 0; i < customSubscription.filters.length; i++)
129 {
130 if (customSubscription.filters[i].text == filter.text)
131 return;
132 }
133 customSubscription.filters.push(filter);
134 modules.filterNotifier.FilterNotifier.triggerListeners("filter.added", f ilter);
135 },
136
137 removeFilter: function(filter)
138 {
139 for (var i = 0; i < customSubscription.filters.length; i++)
140 {
141 if (customSubscription.filters[i].text == filter.text)
142 {
143 customSubscription.filters.splice(i, 1);
144 modules.filterNotifier.FilterNotifier.triggerListeners("filter.remov ed", filter);
145 return;
146 }
147 }
148 }
113 } 149 }
114 }; 150 };
115 151
116 modules.filterClasses = { 152 modules.filterClasses = {
153 BlockingFilter: function() {},
117 Filter: function(text) 154 Filter: function(text)
118 { 155 {
119 this.text = text; 156 this.text = text;
157 this.disabled = false;
158 }
159 };
160 modules.filterClasses.Filter.fromText = function(text)
161 {
162 return new modules.filterClasses.Filter(text);
163 };
164
165 modules.filterValidation =
166 {
167 parseFilter: function(text)
168 {
169 if (params.filterError)
170 return {error: "Invalid filter"};
171 return {filter: modules.filterClasses.Filter.fromText(text)};
120 }, 172 },
121 BlockingFilter: function() {} 173 parseFilters: function(text)
122 }; 174 {
123 modules.filterClasses.Filter.fromText = function(text) 175 if (params.filterError)
124 { 176 return {errors: ["Invalid filter"]};
125 return new modules.filterClasses.Filter(text); 177 return {
178 filters: text.split("\n")
179 .filter(function(filter) {return !!filter;})
180 .map(modules.filterClasses.Filter.fromText),
181 errors: []
182 };
183 }
126 }; 184 };
127 185
128 modules.synchronizer = { 186 modules.synchronizer = {
129 Synchronizer: {} 187 Synchronizer: {}
130 }; 188 };
131 189
132 modules.matcher = { 190 modules.matcher = {
133 defaultMatcher: { 191 defaultMatcher: {
134 matchesAny: function(url, requestType, docDomain, thirdParty) 192 matchesAny: function(url, requestType, docDomain, thirdParty)
135 { 193 {
136 var params = {blockedURLs: ""};
137 updateFromURL(params);
138 var blocked = params.blockedURLs.split(","); 194 var blocked = params.blockedURLs.split(",");
139 if (blocked.indexOf(url) >= 0) 195 if (blocked.indexOf(url) >= 0)
140 return new modules.filterClasses.BlockingFilter(); 196 return new modules.filterClasses.BlockingFilter();
141 else 197 else
142 return null; 198 return null;
143 } 199 }
144 } 200 }
145 }; 201 };
146 202
203 modules.cssRules = {
204 CSSRules: {
205 getRulesForDomain: function(domain) { }
206 }
207 };
208
147 var notifierListeners = []; 209 var notifierListeners = [];
148 modules.filterNotifier = { 210 modules.filterNotifier = {
149 FilterNotifier: { 211 FilterNotifier: {
150 addListener: function(listener) 212 addListener: function(listener)
151 { 213 {
152 if (notifierListeners.indexOf(listener) < 0) 214 if (notifierListeners.indexOf(listener) < 0)
153 notifierListeners.push(listener); 215 notifierListeners.push(listener);
154 }, 216 },
155 217
156 removeListener: function(listener) 218 removeListener: function(listener)
(...skipping 10 matching lines...) Expand all
167 for (var i = 0; i < listeners.length; i++) 229 for (var i = 0; i < listeners.length; i++)
168 listeners[i].apply(null, args); 230 listeners[i].apply(null, args);
169 } 231 }
170 } 232 }
171 }; 233 };
172 234
173 modules.info = { 235 modules.info = {
174 platform: "gecko", 236 platform: "gecko",
175 platformVersion: "34.0", 237 platformVersion: "34.0",
176 application: "firefox", 238 application: "firefox",
177 applicationVersion: "34.0" 239 applicationVersion: "34.0",
240 addonName: "adblockplus",
241 addonVersion: "2.6.7"
178 }; 242 };
179 updateFromURL(modules.info); 243 updateFromURL(modules.info);
180 244
181 global.Services = { 245 global.Services = {
182 vc: { 246 vc: {
183 compare: function(v1, v2) 247 compare: function(v1, v2)
184 { 248 {
185 return parseFloat(v1) - parseFloat(v2); 249 return parseFloat(v1) - parseFloat(v2);
186 } 250 }
187 } 251 }
188 }; 252 };
189 253
190 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; 254 var filters = [
191 updateFromURL(issues); 255 "@@||alternate.de^$document",
192 global.seenDataCorruption = issues.seenDataCorruption; 256 "@@||der.postillion.com^$document",
193 global.filterlistsReinitialized = issues.filterlistsReinitialized; 257 "@@||taz.de^$document",
258 "@@||amazon.de^$document",
259 "||biglemon.am/bg_poster/banner.jpg",
260 "winfuture.de###header_logo_link",
261 "###WerbungObenRechts10_GesamtDIV",
262 "###WerbungObenRechts8_GesamtDIV",
263 "###WerbungObenRechts9_GesamtDIV",
264 "###WerbungUntenLinks4_GesamtDIV",
265 "###WerbungUntenLinks7_GesamtDIV",
266 "###WerbungUntenLinks8_GesamtDIV",
267 "###WerbungUntenLinks9_GesamtDIV",
268 "###Werbung_Sky",
269 "###Werbung_Wide",
270 "###__ligatus_placeholder__",
271 "###ad-bereich1-08",
272 "###ad-bereich1-superbanner",
273 "###ad-bereich2-08",
274 "###ad-bereich2-skyscrapper"
275 ];
276 var knownFilters = filters.map(modules.filterClasses.Filter.fromText);
277
278 var subscriptions = [
279 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
280 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
281 "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
282 "~user~786254"
283 ];
284 var knownSubscriptions = Object.create(null);
285 for (var subscriptionUrl of subscriptions)
286 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl);
287 var customSubscription = knownSubscriptions["~user~786254"];
288
289 global.seenDataCorruption = params.seenDataCorruption;
290 global.filterlistsReinitialized = params.filterlistsReinitialized;
291
292 if (params.addSubscription)
293 {
294 // We don't know how long it will take for the page to fully load
295 // so we'll post the message after one second
296 setTimeout(function()
297 {
298 window.postMessage({
299 type: "message",
300 payload: {
301 title: "Custom subscription",
302 url: "http://example.com/custom.txt",
303 type: "add-subscription"
304 }
305 }, "*");
306 }, 1000);
307 }
194 308
195 ext.devtools.onCreated.addListener(function(panel) 309 ext.devtools.onCreated.addListener(function(panel)
196 { 310 {
197 // blocked request 311 // blocked request
198 panel.sendMessage({ 312 panel.sendMessage({
199 type: "add-record", 313 type: "add-record",
200 request: { 314 request: {
201 url: "http://adserver.example.com/ad_banner.png", 315 url: "http://adserver.example.com/ad_banner.png",
202 type: "IMAGE", 316 type: "IMAGE",
203 docDomain: "example.com" 317 docDomain: "example.com"
204 }, 318 },
205 filter: { 319 filter: {
206 text: "/ad_banner*$domain=example.com", 320 text: "/ad_banner*$domain=example.com",
207 whitelisted: false, 321 whitelisted: false,
208 userDefined: false, 322 userDefined: false,
209 subscription: "EasyList" 323 subscription: "EasyList"
210 } 324 }
211 }); 325 });
212 326
213 // whiletisted request 327 // whitelisted request
Thomas Greiner 2015/03/13 11:11:05 Replace "whiletisted" with "whitelisted"
Sebastian Noack 2015/03/13 13:07:38 Done.
214 panel.sendMessage({ 328 panel.sendMessage({
215 type: "add-record", 329 type: "add-record",
216 request: { 330 request: {
217 url: "http://example.com/looks_like_an_ad_but_isnt_one.html", 331 url: "http://example.com/looks_like_an_ad_but_isnt_one.html",
218 type: "SUBDOCUMENT", 332 type: "SUBDOCUMENT",
219 docDomain: "example.com" 333 docDomain: "example.com"
220 }, 334 },
221 filter: { 335 filter: {
222 text: "@@||example.com/looks_like_an_ad_but_isnt_one.html", 336 text: "@@||example.com/looks_like_an_ad_but_isnt_one.html",
223 whitelisted: true, 337 whitelisted: true,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 }, 376 },
263 filter: { 377 filter: {
264 text: "||example.com/some-annoying-popup$popup", 378 text: "||example.com/some-annoying-popup$popup",
265 whitelisted: false, 379 whitelisted: false,
266 userDefined: true, 380 userDefined: true,
267 subscription: null 381 subscription: null
268 } 382 }
269 }); 383 });
270 }); 384 });
271 })(this); 385 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld