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

Delta Between Two Patch Sets: background.js

Issue 5279235799252992: Issue 491 - Validate custom filters (Closed)
Left Patch Set: Created Nov. 18, 2014, 3:57 p.m.
Right Patch Set: Improved test messages Created Nov. 21, 2014, 8:07 a.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 | « _locales/en_US/messages.json ('k') | block.js » ('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 <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 with(require("filterClasses")) 18 with(require("filterClasses"))
19 { 19 {
20 this.Filter = Filter; 20 this.Filter = Filter;
21 this.RegExpFilter = RegExpFilter; 21 this.RegExpFilter = RegExpFilter;
22 this.BlockingFilter = BlockingFilter; 22 this.BlockingFilter = BlockingFilter;
23 this.WhitelistFilter = WhitelistFilter; 23 this.WhitelistFilter = WhitelistFilter;
24 this.InvalidFilter = InvalidFilter;
25 } 24 }
26 with(require("subscriptionClasses")) 25 with(require("subscriptionClasses"))
27 { 26 {
28 this.Subscription = Subscription; 27 this.Subscription = Subscription;
29 this.DownloadableSubscription = DownloadableSubscription; 28 this.DownloadableSubscription = DownloadableSubscription;
30 this.SpecialSubscription = SpecialSubscription; 29 this.SpecialSubscription = SpecialSubscription;
31 } 30 }
32 with(require("whitelisting")) 31 with(require("whitelisting"))
33 { 32 {
34 this.isWhitelisted = isWhitelisted; 33 this.isWhitelisted = isWhitelisted;
35 this.isFrameWhitelisted = isFrameWhitelisted; 34 this.isFrameWhitelisted = isFrameWhitelisted;
36 this.processKey = processKey; 35 this.processKey = processKey;
37 this.getKey = getKey; 36 this.getKey = getKey;
38 } 37 }
39 var FilterStorage = require("filterStorage").FilterStorage; 38 var FilterStorage = require("filterStorage").FilterStorage;
40 var ElemHide = require("elemHide").ElemHide; 39 var ElemHide = require("elemHide").ElemHide;
41 var defaultMatcher = require("matcher").defaultMatcher; 40 var defaultMatcher = require("matcher").defaultMatcher;
42 var Prefs = require("prefs").Prefs; 41 var Prefs = require("prefs").Prefs;
43 var Synchronizer = require("synchronizer").Synchronizer; 42 var Synchronizer = require("synchronizer").Synchronizer;
44 var Utils = require("utils").Utils; 43 var Utils = require("utils").Utils;
45 var Notification = require("notification").Notification; 44 var Notification = require("notification").Notification;
46 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication; 45 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication;
46 var parseFilters = require("filterValidation").parseFilters;
47 47
48 // Some types cannot be distinguished 48 // Some types cannot be distinguished
49 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 49 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
50 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; 50 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER;
51 51
52 // Chrome on Linux does not fully support chrome.notifications until version 35 52 // Chrome on Linux does not fully support chrome.notifications until version 35
53 // https://code.google.com/p/chromium/issues/detail?id=291485 53 // https://code.google.com/p/chromium/issues/detail?id=291485
54 var canUseChromeNotifications = require("info").platform == "chromium" 54 var canUseChromeNotifications = require("info").platform == "chromium"
55 && "notifications" in chrome 55 && "notifications" in chrome
56 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34); 56 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34);
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 case "get-domain-enabled-state": 518 case "get-domain-enabled-state":
519 // Returns whether this domain is in the exclusion list. 519 // Returns whether this domain is in the exclusion list.
520 // The browser action popup asks us this. 520 // The browser action popup asks us this.
521 if(sender.page) 521 if(sender.page)
522 { 522 {
523 sendResponse({enabled: !isWhitelisted(sender.page.url)}); 523 sendResponse({enabled: !isWhitelisted(sender.page.url)});
524 return; 524 return;
525 } 525 }
526 break; 526 break;
527 case "add-filters": 527 case "add-filters":
528 var filters = []; 528 var filters;
529 529 try
kzar 2014/11/18 16:32:10 How come you don't check that msg.filters and msg.
Sebastian Noack 2014/11/18 17:42:55 There was no point in checking it in the first pla
530 for (var i = 0; i < msg.filters.length; i++) 530 {
531 { 531 filters = parseFilters(msg.text);
532 var filter = Filter.fromText(msg.filters[i], true); 532 }
kzar 2014/11/18 16:32:10 Instead of having this separate filter variable ho
Sebastian Noack 2014/11/18 17:42:55 We have to access the filter object 3 times (or 2
533 if (filter instanceof InvalidFilter) 533 catch (error)
534 { 534 {
535 sendResponse({status: "invalid", error: filter.reason}); 535 sendResponse({status: "invalid", error: error});
536 return; 536 break;
537 }
538 filters.push(filter);
539 } 537 }
540 538
541 for (var i = 0; i < filters.length; i++) 539 for (var i = 0; i < filters.length; i++)
kzar 2014/11/18 16:32:10 You've re-declared the `i` variable here.
542 FilterStorage.addFilter(filters[i]); 540 FilterStorage.addFilter(filters[i]);
543 541
544 sendResponse({status: "ok"}); 542 sendResponse({status: "ok"});
545 break; 543 break;
546 case "add-subscription": 544 case "add-subscription":
547 ext.showOptions(function(page) 545 ext.showOptions(function(page)
548 { 546 {
549 page.sendMessage(msg); 547 page.sendMessage(msg);
550 }); 548 });
551 break; 549 break;
(...skipping 25 matching lines...) Expand all
577 page.sendMessage({type: "clickhide-deactivate"}); 575 page.sendMessage({type: "clickhide-deactivate"});
578 refreshIconAndContextMenu(page); 576 refreshIconAndContextMenu(page);
579 }); 577 });
580 578
581 setTimeout(function() 579 setTimeout(function()
582 { 580 {
583 var notificationToShow = Notification.getNextToShow(); 581 var notificationToShow = Notification.getNextToShow();
584 if (notificationToShow) 582 if (notificationToShow)
585 showNotification(notificationToShow); 583 showNotification(notificationToShow);
586 }, 3 * 60 * 1000); 584 }, 3 * 60 * 1000);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld