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

Side by Side Diff: background.js

Issue 6393086494113792: Issue 154 - Added devtools panel showing blocked and blockable items (Closed)
Patch Set: Fixed typo in JSDoc syntax Created Feb. 2, 2016, 4:31 p.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 | chrome/devtools.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2016 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
(...skipping 12 matching lines...) Expand all
23 this.RegExpFilter = RegExpFilter; 23 this.RegExpFilter = RegExpFilter;
24 } 24 }
25 with(require("subscriptionClasses")) 25 with(require("subscriptionClasses"))
26 { 26 {
27 this.Subscription = Subscription; 27 this.Subscription = Subscription;
28 this.DownloadableSubscription = DownloadableSubscription; 28 this.DownloadableSubscription = DownloadableSubscription;
29 this.SpecialSubscription = SpecialSubscription; 29 this.SpecialSubscription = SpecialSubscription;
30 } 30 }
31 with(require("whitelisting")) 31 with(require("whitelisting"))
32 { 32 {
33 this.isPageWhitelisted = isPageWhitelisted; 33 this.checkWhitelisted = checkWhitelisted;
34 this.isFrameWhitelisted = isFrameWhitelisted;
35 this.processKey = processKey; 34 this.processKey = processKey;
36 this.getKey = getKey; 35 this.getKey = getKey;
37 } 36 }
38 with(require("url")) 37 with(require("url"))
39 { 38 {
40 this.stringifyURL = stringifyURL; 39 this.stringifyURL = stringifyURL;
41 this.isThirdParty = isThirdParty; 40 this.isThirdParty = isThirdParty;
42 this.extractHostFromFrame = extractHostFromFrame; 41 this.extractHostFromFrame = extractHostFromFrame;
43 } 42 }
44 var FilterStorage = require("filterStorage").FilterStorage; 43 var FilterStorage = require("filterStorage").FilterStorage;
45 var FilterNotifier = require("filterNotifier").FilterNotifier; 44 var FilterNotifier = require("filterNotifier").FilterNotifier;
46 var ElemHide = require("elemHide").ElemHide; 45 var ElemHide = require("elemHide").ElemHide;
47 var defaultMatcher = require("matcher").defaultMatcher; 46 var defaultMatcher = require("matcher").defaultMatcher;
48 var Prefs = require("prefs").Prefs; 47 var Prefs = require("prefs").Prefs;
49 var Synchronizer = require("synchronizer").Synchronizer; 48 var Synchronizer = require("synchronizer").Synchronizer;
50 var Utils = require("utils").Utils; 49 var Utils = require("utils").Utils;
51 var parseFilters = require("filterValidation").parseFilters; 50 var parseFilters = require("filterValidation").parseFilters;
52 var composeFilters = require("filterComposer").composeFilters; 51 var composeFilters = require("filterComposer").composeFilters;
53 var updateIcon = require("icon").updateIcon; 52 var updateIcon = require("icon").updateIcon;
54 var initNotifications = require("notificationHelper").initNotifications; 53 var initNotifications = require("notificationHelper").initNotifications;
55 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl; 54 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat ionForUrl;
55 var devtools = require("devtools");
56 56
57 var seenDataCorruption = false; 57 var seenDataCorruption = false;
58 var filterlistsReinitialized = false; 58 var filterlistsReinitialized = false;
59 59
60 function init() 60 function init()
61 { 61 {
62 var filtersLoaded = new Promise(function(resolve) 62 var filtersLoaded = new Promise(function(resolve)
63 { 63 {
64 function onFilterAction(action) 64 function onFilterAction(action)
65 { 65 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 contexts: ["image", "video", "audio"], 119 contexts: ["image", "video", "audio"],
120 onclick: function(page) 120 onclick: function(page)
121 { 121 {
122 page.sendMessage({type: "clickhide-new-filter"}); 122 page.sendMessage({type: "clickhide-new-filter"});
123 } 123 }
124 }; 124 };
125 125
126 // Adds or removes browser action icon according to options. 126 // Adds or removes browser action icon according to options.
127 function refreshIconAndContextMenu(page) 127 function refreshIconAndContextMenu(page)
128 { 128 {
129 var whitelisted = isPageWhitelisted(page); 129 var whitelisted = !!checkWhitelisted(page);
130 updateIcon(page, whitelisted); 130 updateIcon(page, whitelisted);
131 131
132 // show or hide the context menu entry dependent on whether 132 // show or hide the context menu entry dependent on whether
133 // adblocking is active on that page 133 // adblocking is active on that page
134 page.contextMenus.remove(contextMenuItem); 134 page.contextMenus.remove(contextMenuItem);
135 if (Prefs.shouldShowBlockElementMenu && !whitelisted && htmlPages.has(page)) 135 if (Prefs.shouldShowBlockElementMenu && !whitelisted && htmlPages.has(page))
136 page.contextMenus.create(contextMenuItem); 136 page.contextMenus.create(contextMenuItem);
137 } 137 }
138 138
139 function refreshIconAndContextMenuForAllPages() 139 function refreshIconAndContextMenuForAllPages()
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 return {filters: filters, exceptions: exceptions}; 279 return {filters: filters, exceptions: exceptions};
280 } 280 }
281 281
282 ext.onMessage.addListener(function (msg, sender, sendResponse) 282 ext.onMessage.addListener(function (msg, sender, sendResponse)
283 { 283 {
284 switch (msg.type) 284 switch (msg.type)
285 { 285 {
286 case "get-selectors": 286 case "get-selectors":
287 var selectors = []; 287 var selectors = [];
288 var trace = devtools && devtools.hasPanel(sender.page);
288 289
289 if (!isFrameWhitelisted(sender.page, sender.frame, 290 if (!checkWhitelisted(sender.page, sender.frame,
290 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeM ap.ELEMHIDE)) 291 RegExpFilter.typeMap.DOCUMENT |
292 RegExpFilter.typeMap.ELEMHIDE))
291 { 293 {
292 var noStyleRules = false; 294 var noStyleRules = false;
293 var specificOnly = isFrameWhitelisted(sender.page, sender.frame, 295 var specificOnly = checkWhitelisted(sender.page, sender.frame,
294 RegExpFilter.typeMap.GENERICHIDE); 296 RegExpFilter.typeMap.GENERICHIDE);
295 var host = extractHostFromFrame(sender.frame); 297 var host = extractHostFromFrame(sender.frame);
296 298
297 for (var i = 0; i < noStyleRulesHosts.length; i++) 299 for (var i = 0; i < noStyleRulesHosts.length; i++)
298 { 300 {
299 var noStyleHost = noStyleRulesHosts[i]; 301 var noStyleHost = noStyleRulesHosts[i];
300 if (host == noStyleHost || (host.length > noStyleHost.length && 302 if (host == noStyleHost || (host.length > noStyleHost.length &&
301 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost)) 303 host.substr(host.length - noStyleHost.leng th - 1) == "." + noStyleHost))
302 { 304 {
303 noStyleRules = true; 305 noStyleRules = true;
304 } 306 }
305 } 307 }
306 selectors = ElemHide.getSelectorsForDomain(host, specificOnly); 308 selectors = ElemHide.getSelectorsForDomain(host, specificOnly);
307 if (noStyleRules) 309 if (noStyleRules)
308 { 310 {
309 selectors = selectors.filter(function(s) 311 selectors = selectors.filter(function(s)
310 { 312 {
311 return !/\[style[\^\$]?=/.test(s); 313 return !/\[style[\^\$]?=/.test(s);
312 }); 314 });
313 } 315 }
314 } 316 }
315 317
316 sendResponse(selectors); 318 sendResponse({selectors: selectors, trace: trace});
317 break; 319 break;
318 case "should-collapse": 320 case "should-collapse":
319 if (isFrameWhitelisted(sender.page, sender.frame, RegExpFilter.typeMap.DOC UMENT)) 321 if (checkWhitelisted(sender.page, sender.frame))
320 { 322 {
321 sendResponse(false); 323 sendResponse(false);
322 break; 324 break;
323 } 325 }
324 326
325 var typeMask = RegExpFilter.typeMap[msg.mediatype]; 327 var typeMask = RegExpFilter.typeMap[msg.mediatype];
326 var documentHost = extractHostFromFrame(sender.frame); 328 var documentHost = extractHostFromFrame(sender.frame);
327 var sitekey = getKey(sender.page, sender.frame); 329 var sitekey = getKey(sender.page, sender.frame);
328 var blocked = false; 330 var blocked = false;
329 331
(...skipping 17 matching lines...) Expand all
347 } 349 }
348 } 350 }
349 351
350 sendResponse(blocked && Prefs.hidePlaceholders); 352 sendResponse(blocked && Prefs.hidePlaceholders);
351 break; 353 break;
352 case "get-domain-enabled-state": 354 case "get-domain-enabled-state":
353 // Returns whether this domain is in the exclusion list. 355 // Returns whether this domain is in the exclusion list.
354 // The browser action popup asks us this. 356 // The browser action popup asks us this.
355 if(sender.page) 357 if(sender.page)
356 { 358 {
357 sendResponse({enabled: !isPageWhitelisted(sender.page)}); 359 sendResponse({enabled: !checkWhitelisted(sender.page)});
358 return; 360 return;
359 } 361 }
360 break; 362 break;
361 case "add-filters": 363 case "add-filters":
362 var result = parseFilters(msg.text); 364 var result = parseFilters(msg.text);
363 365
364 if (result.errors.length > 0) 366 if (result.errors.length > 0)
365 { 367 {
366 sendResponse({status: "invalid", error: result.errors.join("\n")}); 368 sendResponse({status: "invalid", error: result.errors.join("\n")});
367 break; 369 break;
(...skipping 18 matching lines...) Expand all
386 src: msg.src, 388 src: msg.src,
387 style: msg.style, 389 style: msg.style,
388 classes: msg.classes, 390 classes: msg.classes,
389 urls: msg.urls, 391 urls: msg.urls,
390 type: msg.mediatype, 392 type: msg.mediatype,
391 baseURL: msg.baseURL, 393 baseURL: msg.baseURL,
392 page: sender.page, 394 page: sender.page,
393 frame: sender.frame 395 frame: sender.frame
394 })); 396 }));
395 break; 397 break;
398 case "trace-elemhide":
399 devtools.logHiddenElements(
400 sender.page, msg.selectors,
401 extractHostFromFrame(sender.frame)
402 );
403 break;
396 case "forward": 404 case "forward":
397 if (sender.page) 405 if (sender.page)
398 { 406 {
399 if (msg.expectsResponse) 407 if (msg.expectsResponse)
400 { 408 {
401 sender.page.sendMessage(msg.payload, sendResponse); 409 sender.page.sendMessage(msg.payload, sendResponse);
402 return true; 410 return true;
403 } 411 }
404 412
405 sender.page.sendMessage(msg.payload); 413 sender.page.sendMessage(msg.payload);
406 } 414 }
407 break; 415 break;
408 } 416 }
409 }); 417 });
410 418
411 // update icon when page changes location 419 // update icon when page changes location
412 ext.pages.onLoading.addListener(function(page) 420 ext.pages.onLoading.addListener(function(page)
413 { 421 {
414 page.sendMessage({type: "clickhide-deactivate"}); 422 page.sendMessage({type: "clickhide-deactivate"});
415 refreshIconAndContextMenu(page); 423 refreshIconAndContextMenu(page);
416 showNextNotificationForUrl(page.url); 424 showNextNotificationForUrl(page.url);
417 }); 425 });
OLDNEW
« no previous file with comments | « no previous file | chrome/devtools.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld