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

Side by Side Diff: background.js

Issue 5279235799252992: Issue 491 - Validate custom filters (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « _locales/en_US/messages.json ('k') | block.js » ('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 <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
(...skipping 25 matching lines...) Expand all
36 this.getKey = getKey; 36 this.getKey = getKey;
37 } 37 }
38 var FilterStorage = require("filterStorage").FilterStorage; 38 var FilterStorage = require("filterStorage").FilterStorage;
39 var ElemHide = require("elemHide").ElemHide; 39 var ElemHide = require("elemHide").ElemHide;
40 var defaultMatcher = require("matcher").defaultMatcher; 40 var defaultMatcher = require("matcher").defaultMatcher;
41 var Prefs = require("prefs").Prefs; 41 var Prefs = require("prefs").Prefs;
42 var Synchronizer = require("synchronizer").Synchronizer; 42 var Synchronizer = require("synchronizer").Synchronizer;
43 var Utils = require("utils").Utils; 43 var Utils = require("utils").Utils;
44 var Notification = require("notification").Notification; 44 var Notification = require("notification").Notification;
45 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication; 45 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication;
46 var parseFilters = require("filterValidation").parseFilters;
46 47
47 // Some types cannot be distinguished 48 // Some types cannot be distinguished
48 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 49 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
49 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; 50 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER;
50 51
51 // 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
52 // https://code.google.com/p/chromium/issues/detail?id=291485 53 // https://code.google.com/p/chromium/issues/detail?id=291485
53 var canUseChromeNotifications = require("info").platform == "chromium" 54 var canUseChromeNotifications = require("info").platform == "chromium"
54 && "notifications" in chrome 55 && "notifications" in chrome
55 && (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
517 case "get-domain-enabled-state": 518 case "get-domain-enabled-state":
518 // Returns whether this domain is in the exclusion list. 519 // Returns whether this domain is in the exclusion list.
519 // The browser action popup asks us this. 520 // The browser action popup asks us this.
520 if(sender.page) 521 if(sender.page)
521 { 522 {
522 sendResponse({enabled: !isWhitelisted(sender.page.url)}); 523 sendResponse({enabled: !isWhitelisted(sender.page.url)});
523 return; 524 return;
524 } 525 }
525 break; 526 break;
526 case "add-filters": 527 case "add-filters":
527 if (msg.filters && msg.filters.length) 528 var filters;
529 try
528 { 530 {
529 for (var i = 0; i < msg.filters.length; i++) 531 filters = parseFilters(msg.text);
530 FilterStorage.addFilter(Filter.fromText(msg.filters[i]));
531 } 532 }
533 catch (error)
534 {
535 sendResponse({status: "invalid", error: error});
536 break;
537 }
538
539 for (var i = 0; i < filters.length; i++)
540 FilterStorage.addFilter(filters[i]);
541
542 sendResponse({status: "ok"});
532 break; 543 break;
533 case "add-subscription": 544 case "add-subscription":
534 ext.showOptions(function(page) 545 ext.showOptions(function(page)
535 { 546 {
536 page.sendMessage(msg); 547 page.sendMessage(msg);
537 }); 548 });
538 break; 549 break;
539 case "add-sitekey": 550 case "add-sitekey":
540 processKey(msg.token, sender.page, sender.frame); 551 processKey(msg.token, sender.page, sender.frame);
541 break; 552 break;
(...skipping 22 matching lines...) Expand all
564 page.sendMessage({type: "clickhide-deactivate"}); 575 page.sendMessage({type: "clickhide-deactivate"});
565 refreshIconAndContextMenu(page); 576 refreshIconAndContextMenu(page);
566 }); 577 });
567 578
568 setTimeout(function() 579 setTimeout(function()
569 { 580 {
570 var notificationToShow = Notification.getNextToShow(); 581 var notificationToShow = Notification.getNextToShow();
571 if (notificationToShow) 582 if (notificationToShow)
572 showNotification(notificationToShow); 583 showNotification(notificationToShow);
573 }, 3 * 60 * 1000); 584 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « _locales/en_US/messages.json ('k') | block.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld