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

Side by Side Diff: background.js

Issue 5564089086509056: Issue 1801 - Use URL objects to process URLs in the background page (Closed)
Patch Set: Rebased and addressed comments Created Feb. 11, 2015, 10:54 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 | « no previous file | chrome/ext/background.js » ('j') | chrome/ext/background.js » ('J')
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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.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 this.SpecialSubscription = SpecialSubscription;
30 } 30 }
31 with(require("whitelisting")) 31 with(require("whitelisting"))
32 { 32 {
33 this.isWhitelisted = isWhitelisted; 33 this.isPageWhitelisted = isPageWhitelisted;
34 this.isFrameWhitelisted = isFrameWhitelisted; 34 this.isFrameWhitelisted = isFrameWhitelisted;
35 this.processKey = processKey; 35 this.processKey = processKey;
36 this.getKey = getKey; 36 this.getKey = getKey;
37 } 37 }
38 with(require("url"))
39 {
40 this.stringifyURL = stringifyURL;
41 this.isThirdParty = isThirdParty;
42 this.extractHostFromFrame = extractHostFromFrame;
43 }
38 var FilterStorage = require("filterStorage").FilterStorage; 44 var FilterStorage = require("filterStorage").FilterStorage;
39 var ElemHide = require("elemHide").ElemHide; 45 var ElemHide = require("elemHide").ElemHide;
40 var defaultMatcher = require("matcher").defaultMatcher; 46 var defaultMatcher = require("matcher").defaultMatcher;
41 var Prefs = require("prefs").Prefs; 47 var Prefs = require("prefs").Prefs;
42 var Synchronizer = require("synchronizer").Synchronizer; 48 var Synchronizer = require("synchronizer").Synchronizer;
43 var Utils = require("utils").Utils; 49 var Utils = require("utils").Utils;
44 var NotificationStorage = require("notification").Notification; 50 var NotificationStorage = require("notification").Notification;
45 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication; 51 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication;
46 var parseFilters = require("filterValidation").parseFilters; 52 var parseFilters = require("filterValidation").parseFilters;
47 53
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 contexts: ["image", "video", "audio"], 126 contexts: ["image", "video", "audio"],
121 onclick: function(page) 127 onclick: function(page)
122 { 128 {
123 page.sendMessage({type: "clickhide-new-filter"}); 129 page.sendMessage({type: "clickhide-new-filter"});
124 } 130 }
125 }; 131 };
126 132
127 // Adds or removes browser action icon according to options. 133 // Adds or removes browser action icon according to options.
128 function refreshIconAndContextMenu(page) 134 function refreshIconAndContextMenu(page)
129 { 135 {
130 var whitelisted = isWhitelisted(page.url); 136 var whitelisted = isPageWhitelisted(page);
131 137
132 var iconFilename; 138 var iconFilename;
133 if (whitelisted && require("info").platform != "safari") 139 if (whitelisted && require("info").platform != "safari")
134 // There is no grayscale version of the icon for whitelisted pages 140 // There is no grayscale version of the icon for whitelisted pages
135 // when using Safari, because icons are grayscale already and icons 141 // when using Safari, because icons are grayscale already and icons
136 // aren't per page in Safari. 142 // aren't per page in Safari.
137 iconFilename = "icons/abp-$size-whitelisted.png"; 143 iconFilename = "icons/abp-$size-whitelisted.png";
138 else 144 else
139 iconFilename = "icons/abp-$size.png"; 145 iconFilename = "icons/abp-$size.png";
140 146
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 499
494 sendResponse(selectors); 500 sendResponse(selectors);
495 break; 501 break;
496 case "should-collapse": 502 case "should-collapse":
497 if (isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT")) 503 if (isFrameWhitelisted(sender.page, sender.frame, "DOCUMENT"))
498 { 504 {
499 sendResponse(false); 505 sendResponse(false);
500 break; 506 break;
501 } 507 }
502 508
503 var requestHost = extractHostFromURL(msg.url); 509 var url = new URL(msg.url);
504 var documentHost = extractHostFromFrame(sender.frame); 510 var documentHost = extractHostFromFrame(sender.frame);
505 var thirdParty = isThirdParty(requestHost, documentHost); 511 var filter = defaultMatcher.matchesAny(
506 var filter = defaultMatcher.matchesAny(msg.url, msg.mediatype, documentHos t, thirdParty); 512 stringifyURL(url), msg.mediatype,
513 documentHost, isThirdParty(url, documentHost)
514 );
515
507 if (filter instanceof BlockingFilter) 516 if (filter instanceof BlockingFilter)
508 { 517 {
509 var collapse = filter.collapse; 518 var collapse = filter.collapse;
510 if (collapse == null) 519 if (collapse == null)
511 collapse = Prefs.hidePlaceholders; 520 collapse = Prefs.hidePlaceholders;
512 sendResponse(collapse); 521 sendResponse(collapse);
513 } 522 }
514 else 523 else
515 sendResponse(false); 524 sendResponse(false);
516 break; 525 break;
517 case "get-domain-enabled-state": 526 case "get-domain-enabled-state":
518 // Returns whether this domain is in the exclusion list. 527 // Returns whether this domain is in the exclusion list.
519 // The browser action popup asks us this. 528 // The browser action popup asks us this.
520 if(sender.page) 529 if(sender.page)
521 { 530 {
522 sendResponse({enabled: !isWhitelisted(sender.page.url)}); 531 sendResponse({enabled: !isPageWhitelisted(sender.page)});
523 return; 532 return;
524 } 533 }
525 break; 534 break;
526 case "add-filters": 535 case "add-filters":
527 var filters; 536 var filters;
528 try 537 try
529 { 538 {
530 filters = parseFilters(msg.text); 539 filters = parseFilters(msg.text);
531 } 540 }
532 catch (error) 541 catch (error)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 page.sendMessage({type: "clickhide-deactivate"}); 583 page.sendMessage({type: "clickhide-deactivate"});
575 refreshIconAndContextMenu(page); 584 refreshIconAndContextMenu(page);
576 }); 585 });
577 586
578 setTimeout(function() 587 setTimeout(function()
579 { 588 {
580 var notificationToShow = NotificationStorage.getNextToShow(); 589 var notificationToShow = NotificationStorage.getNextToShow();
581 if (notificationToShow) 590 if (notificationToShow)
582 showNotification(notificationToShow); 591 showNotification(notificationToShow);
583 }, 3 * 60 * 1000); 592 }, 3 * 60 * 1000);
OLDNEW
« no previous file with comments | « no previous file | chrome/ext/background.js » ('j') | chrome/ext/background.js » ('J')

Powered by Google App Engine
This is Rietveld