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

Side by Side Diff: background.js

Issue 6235761431019520: Issue 342 - Speed up options page with many user filters on Safari (Closed)
Patch Set: Created April 16, 2014, 3 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 | options.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
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 } 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 } 30 }
30 with(require("whitelisting")) 31 with(require("whitelisting"))
31 { 32 {
32 this.isWhitelisted = isWhitelisted; 33 this.isWhitelisted = isWhitelisted;
33 this.isFrameWhitelisted = isFrameWhitelisted; 34 this.isFrameWhitelisted = isFrameWhitelisted;
34 this.processKeyException = processKeyException; 35 this.processKeyException = processKeyException;
35 } 36 }
36 var FilterStorage = require("filterStorage").FilterStorage; 37 var FilterStorage = require("filterStorage").FilterStorage;
37 var ElemHide = require("elemHide").ElemHide; 38 var ElemHide = require("elemHide").ElemHide;
38 var defaultMatcher = require("matcher").defaultMatcher; 39 var defaultMatcher = require("matcher").defaultMatcher;
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 var approved = confirm(message); 464 var approved = confirm(message);
464 if (activeNotification.type === "question") 465 if (activeNotification.type === "question")
465 notificationButtonClick(approved ? 0 : 1); 466 notificationButtonClick(approved ? 0 : 1);
466 else if (approved) 467 else if (approved)
467 openNotificationLinks(); 468 openNotificationLinks();
468 } 469 }
469 } 470 }
470 prepareNotificationIconAndPopup(); 471 prepareNotificationIconAndPopup();
471 } 472 }
472 473
474 // This is a hack to speedup loading of the options page on Safari.
475 // Once we replaced the background page proxy with message passing
476 // this global function should removed.
477 function getUserFilter()
Wladimir Palant 2014/04/16 17:25:39 Nit: getUserFilters() please (plural)
478 {
479 var filters = [];
480 var exceptions = [];
481
482 for (var i = 0; i < FilterStorage.subscriptions.length; i++)
483 {
484 var subscription = FilterStorage.subscriptions[i];
485 if (!(subscription instanceof SpecialSubscription))
486 continue;
487
488 for (var j = 0; j < subscription.filters.length; j++)
489 {
490 var filter = subscription.filters[j];
491 if (filter instanceof WhitelistFilter && /^@@\|\|([^\/:]+)\^\$document$/. test(filter.text))
492 exceptions.push(RegExp.$1);
493 else
494 filters.push(filter.text);
495 }
496 }
497
498 return {filters: filters, exceptions: exceptions};
499 }
500
473 ext.onMessage.addListener(function (msg, sender, sendResponse) 501 ext.onMessage.addListener(function (msg, sender, sendResponse)
474 { 502 {
475 switch (msg.type) 503 switch (msg.type)
476 { 504 {
477 case "get-selectors": 505 case "get-selectors":
478 var selectors = []; 506 var selectors = [];
479 507
480 if (!isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT") && 508 if (!isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT") &&
481 !isFrameWhitelisted(sender.page, sender.frame, "ELEMHIDE")) 509 !isFrameWhitelisted(sender.page, sender.frame, "ELEMHIDE"))
482 { 510 {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 page.sendMessage({type: "clickhide-deactivate"}); 598 page.sendMessage({type: "clickhide-deactivate"});
571 refreshIconAndContextMenu(page); 599 refreshIconAndContextMenu(page);
572 }); 600 });
573 601
574 setTimeout(function() 602 setTimeout(function()
575 { 603 {
576 var notificationToShow = Notification.getNextToShow(); 604 var notificationToShow = Notification.getNextToShow();
577 if (notificationToShow) 605 if (notificationToShow)
578 showNotification(notificationToShow); 606 showNotification(notificationToShow);
579 }, 3 * 60 * 1000); 607 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | options.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld