LEFT | RIGHT |
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 |
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; | |
22 this.BlockingFilter = BlockingFilter; | 21 this.BlockingFilter = BlockingFilter; |
23 this.WhitelistFilter = WhitelistFilter; | 22 this.WhitelistFilter = WhitelistFilter; |
24 } | 23 } |
25 with(require("subscriptionClasses")) | 24 with(require("subscriptionClasses")) |
26 { | 25 { |
27 this.Subscription = Subscription; | 26 this.Subscription = Subscription; |
28 this.DownloadableSubscription = DownloadableSubscription; | 27 this.DownloadableSubscription = DownloadableSubscription; |
29 this.SpecialSubscription = SpecialSubscription; | 28 this.SpecialSubscription = SpecialSubscription; |
30 } | 29 } |
31 with(require("whitelisting")) | 30 with(require("whitelisting")) |
32 { | 31 { |
33 this.isPageWhitelisted = isPageWhitelisted; | 32 this.isPageWhitelisted = isPageWhitelisted; |
34 this.isFrameWhitelisted = isFrameWhitelisted; | 33 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 with(require("icon")) | 43 with(require("icon")) |
45 { | 44 { |
46 this.updateIcon = updateIcon; | 45 this.updateIcon = updateIcon; |
47 this.startIconAnimation = startIconAnimation; | 46 this.startIconAnimation = startIconAnimation; |
48 this.stopIconAnimation = stopIconAnimation; | 47 this.stopIconAnimation = stopIconAnimation; |
49 } | 48 } |
50 var FilterStorage = require("filterStorage").FilterStorage; | 49 var FilterStorage = require("filterStorage").FilterStorage; |
| 50 var FilterNotifier = require("filterNotifier").FilterNotifier; |
51 var ElemHide = require("elemHide").ElemHide; | 51 var ElemHide = require("elemHide").ElemHide; |
52 var defaultMatcher = require("matcher").defaultMatcher; | 52 var defaultMatcher = require("matcher").defaultMatcher; |
53 var Prefs = require("prefs").Prefs; | 53 var Prefs = require("prefs").Prefs; |
54 var Synchronizer = require("synchronizer").Synchronizer; | 54 var Synchronizer = require("synchronizer").Synchronizer; |
55 var Utils = require("utils").Utils; | 55 var Utils = require("utils").Utils; |
56 var NotificationStorage = require("notification").Notification; | 56 var NotificationStorage = require("notification").Notification; |
57 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti
fication; | 57 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti
fication; |
58 var parseFilters = require("filterValidation").parseFilters; | 58 var parseFilters = require("filterValidation").parseFilters; |
59 | 59 var composeFilters = require("filterComposer").composeFilters; |
60 // Some types cannot be distinguished | |
61 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | |
62 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT
HER; | |
63 | 60 |
64 // Chrome on Linux does not fully support chrome.notifications until version 35 | 61 // Chrome on Linux does not fully support chrome.notifications until version 35 |
65 // https://code.google.com/p/chromium/issues/detail?id=291485 | 62 // https://code.google.com/p/chromium/issues/detail?id=291485 |
66 var canUseChromeNotifications = require("info").platform == "chromium" | 63 var canUseChromeNotifications = (function() |
67 && "notifications" in chrome | 64 { |
68 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl
icationVersion, 10) > 34); | 65 var info = require("info"); |
| 66 if (info.platform == "chromium" && "notifications" in chrome) |
| 67 { |
| 68 if (navigator.platform.indexOf("Linux") == -1) |
| 69 return true; |
| 70 if (Services.vc.compare(info.applicationVersion, "35") >= 0) |
| 71 return true; |
| 72 } |
| 73 return false; |
| 74 })(); |
69 | 75 |
70 var seenDataCorruption = false; | 76 var seenDataCorruption = false; |
71 var filterlistsReinitialized = false; | 77 var filterlistsReinitialized = false; |
72 require("filterNotifier").FilterNotifier.addListener(function(action) | 78 |
73 { | 79 function init() |
74 if (action == "load") | 80 { |
75 { | 81 var filtersLoaded = false; |
76 ext.storage.get(["currentVersion"], function(items) | 82 var prefsLoaded = false; |
77 { | 83 |
78 var addonVersion = require("info").addonVersion; | 84 var checkLoaded = function() |
79 var prevVersion = items.currentVersion; | 85 { |
80 | 86 if (!filtersLoaded || !prefsLoaded) |
81 // There are no filters stored so we need to reinitialize all filterlists | 87 return; |
82 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) | 88 |
83 { | 89 var info = require("info"); |
84 filterlistsReinitialized = true; | 90 var previousVersion = Prefs.currentVersion; |
85 prevVersion = null; | 91 |
86 } | 92 // There are no filters stored so we need to reinitialize all filterlists |
87 | 93 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) |
88 if (prevVersion != addonVersion || FilterStorage.firstRun) | 94 { |
89 { | 95 filterlistsReinitialized = true; |
90 seenDataCorruption = prevVersion && FilterStorage.firstRun; | 96 previousVersion = null; |
91 ext.storage.set("currentVersion", addonVersion); | 97 } |
92 addSubscription(prevVersion); | 98 |
93 } | 99 if (previousVersion != info.addonVersion || FilterStorage.firstRun) |
94 | 100 { |
95 // The "Hide placeholders" option has been removed from the UI in 1.8.8.12
85 | 101 seenDataCorruption = previousVersion && FilterStorage.firstRun; |
96 // So we reset the option for users updating from older versions. | 102 Prefs.currentVersion = info.addonVersion; |
97 if (prevVersion && Services.vc.compare(prevVersion, "1.8.8.1285") < 0) | 103 addSubscription(previousVersion); |
98 Prefs.hidePlaceholders = true; | 104 } |
99 }); | 105 |
| 106 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285 |
| 107 // So we reset the option for users updating from older versions. |
| 108 if (previousVersion && Services.vc.compare(previousVersion, "1.8.8.1285") <
0) |
| 109 Prefs.hidePlaceholders = true; |
100 | 110 |
101 if (canUseChromeNotifications) | 111 if (canUseChromeNotifications) |
102 initChromeNotifications(); | 112 initChromeNotifications(); |
103 initAntiAdblockNotification(); | 113 initAntiAdblockNotification(); |
104 } | 114 |
105 | 115 // Update browser actions and context menus when whitelisting might have |
106 // update browser actions when whitelisting might have changed, | 116 // changed. That is now when initally loading the filters and later when |
107 // due to loading filters or saving filter changes | 117 // importing backups or saving filter changes. |
108 if (action == "load" || action == "save") | 118 FilterNotifier.addListener(function(action) |
| 119 { |
| 120 if (action == "load" || action == "save") |
| 121 refreshIconAndContextMenuForAllPages(); |
| 122 }); |
109 refreshIconAndContextMenuForAllPages(); | 123 refreshIconAndContextMenuForAllPages(); |
110 }); | 124 }; |
| 125 |
| 126 var onFilterAction = function(action) |
| 127 { |
| 128 if (action == "load") |
| 129 { |
| 130 FilterNotifier.removeListener(onFilterAction); |
| 131 filtersLoaded = true; |
| 132 checkLoaded(); |
| 133 } |
| 134 }; |
| 135 |
| 136 var onPrefsLoaded = function() |
| 137 { |
| 138 Prefs.onLoaded.removeListener(onPrefsLoaded); |
| 139 prefsLoaded = true; |
| 140 checkLoaded(); |
| 141 }; |
| 142 |
| 143 FilterNotifier.addListener(onFilterAction); |
| 144 Prefs.onLoaded.addListener(onPrefsLoaded); |
| 145 } |
| 146 init(); |
111 | 147 |
112 // Special-case domains for which we cannot use style-based hiding rules. | 148 // Special-case domains for which we cannot use style-based hiding rules. |
113 // See http://crbug.com/68705. | 149 // See http://crbug.com/68705. |
114 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; | 150 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; |
115 | 151 |
116 var htmlPages = new ext.PageMap(); | 152 var htmlPages = new ext.PageMap(); |
117 var activeNotification = null; | 153 var activeNotification = null; |
118 | 154 |
119 var contextMenuItem = { | 155 var contextMenuItem = { |
120 title: ext.i18n.getMessage("block_element"), | 156 title: ext.i18n.getMessage("block_element"), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 276 |
241 notifyUser(); | 277 notifyUser(); |
242 } | 278 } |
243 }, false); | 279 }, false); |
244 request.send(null); | 280 request.send(null); |
245 } | 281 } |
246 else | 282 else |
247 notifyUser(); | 283 notifyUser(); |
248 } | 284 } |
249 | 285 |
250 Prefs.addListener(function(name) | 286 Prefs.onChanged.addListener(function(name) |
251 { | 287 { |
252 if (name == "shouldShowBlockElementMenu") | 288 if (name == "shouldShowBlockElementMenu") |
253 refreshIconAndContextMenuForAllPages(); | 289 refreshIconAndContextMenuForAllPages(); |
254 }); | 290 }); |
255 | 291 |
256 function prepareNotificationIconAndPopup() | 292 function prepareNotificationIconAndPopup() |
257 { | 293 { |
258 var animateIcon = (activeNotification.type !== "question"); | 294 var animateIcon = (activeNotification.type !== "question"); |
259 activeNotification.onClicked = function() | 295 activeNotification.onClicked = function() |
260 { | 296 { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 { | 382 { |
347 if (activeNotification && activeNotification.id === notification.id) | 383 if (activeNotification && activeNotification.id === notification.id) |
348 return; | 384 return; |
349 | 385 |
350 activeNotification = notification; | 386 activeNotification = notification; |
351 if (activeNotification.type === "critical" || activeNotification.type === "que
stion") | 387 if (activeNotification.type === "critical" || activeNotification.type === "que
stion") |
352 { | 388 { |
353 var texts = NotificationStorage.getLocalizedTexts(notification); | 389 var texts = NotificationStorage.getLocalizedTexts(notification); |
354 var title = texts.title || ""; | 390 var title = texts.title || ""; |
355 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "")
: ""; | 391 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "")
: ""; |
356 var iconUrl = ext.getURL("icons/abp-128.png"); | 392 var iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
357 var hasLinks = activeNotification.links && activeNotification.links.length >
0; | 393 var hasLinks = activeNotification.links && activeNotification.links.length >
0; |
358 | 394 |
359 if (canUseChromeNotifications) | 395 if (canUseChromeNotifications) |
360 { | 396 { |
361 var opts = { | 397 var opts = { |
362 type: "basic", | 398 type: "basic", |
363 title: title, | 399 title: title, |
364 message: message, | 400 message: message, |
365 buttons: [], | 401 buttons: [], |
366 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically | 402 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 page.sendMessage(msg); | 574 page.sendMessage(msg); |
539 }); | 575 }); |
540 break; | 576 break; |
541 case "add-sitekey": | 577 case "add-sitekey": |
542 processKey(msg.token, sender.page, sender.frame); | 578 processKey(msg.token, sender.page, sender.frame); |
543 break; | 579 break; |
544 case "report-html-page": | 580 case "report-html-page": |
545 htmlPages.set(sender.page, null); | 581 htmlPages.set(sender.page, null); |
546 refreshIconAndContextMenu(sender.page); | 582 refreshIconAndContextMenu(sender.page); |
547 break; | 583 break; |
| 584 case "compose-filters": |
| 585 sendResponse(composeFilters({ |
| 586 tagName: msg.tagName, |
| 587 id: msg.id, |
| 588 src: msg.src, |
| 589 style: msg.style, |
| 590 classes: msg.classes, |
| 591 urls: msg.urls, |
| 592 type: msg.mediatype, |
| 593 baseURL: msg.baseURL, |
| 594 page: sender.page, |
| 595 frame: sender.frame |
| 596 })); |
| 597 break; |
548 case "forward": | 598 case "forward": |
549 if (sender.page) | 599 if (sender.page) |
550 { | 600 { |
551 if (msg.expectsResponse) | 601 if (msg.expectsResponse) |
552 { | 602 { |
553 sender.page.sendMessage(msg.payload, sendResponse); | 603 sender.page.sendMessage(msg.payload, sendResponse); |
554 return true; | 604 return true; |
555 } | 605 } |
556 | 606 |
557 sender.page.sendMessage(msg.payload); | 607 sender.page.sendMessage(msg.payload); |
558 } | 608 } |
559 break; | 609 break; |
560 } | 610 } |
561 }); | 611 }); |
562 | 612 |
563 // update icon when page changes location | 613 // update icon when page changes location |
564 ext.pages.onLoading.addListener(function(page) | 614 ext.pages.onLoading.addListener(function(page) |
565 { | 615 { |
566 page.sendMessage({type: "clickhide-deactivate"}); | 616 page.sendMessage({type: "clickhide-deactivate"}); |
567 refreshIconAndContextMenu(page); | 617 refreshIconAndContextMenu(page); |
568 }); | 618 }); |
569 | 619 |
570 setTimeout(function() | 620 setTimeout(function() |
571 { | 621 { |
572 var notificationToShow = NotificationStorage.getNextToShow(); | 622 var notificationToShow = NotificationStorage.getNextToShow(); |
573 if (notificationToShow) | 623 if (notificationToShow) |
574 showNotification(notificationToShow); | 624 showNotification(notificationToShow); |
575 }, 3 * 60 * 1000); | 625 }, 3 * 60 * 1000); |
LEFT | RIGHT |