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; |
| 42 } |
| 43 with(require("icon")) |
| 44 { |
| 45 this.updateIcon = updateIcon; |
| 46 this.startIconAnimation = startIconAnimation; |
| 47 this.stopIconAnimation = stopIconAnimation; |
43 } | 48 } |
44 var FilterStorage = require("filterStorage").FilterStorage; | 49 var FilterStorage = require("filterStorage").FilterStorage; |
45 var ElemHide = require("elemHide").ElemHide; | 50 var ElemHide = require("elemHide").ElemHide; |
46 var defaultMatcher = require("matcher").defaultMatcher; | 51 var defaultMatcher = require("matcher").defaultMatcher; |
47 var Prefs = require("prefs").Prefs; | 52 var Prefs = require("prefs").Prefs; |
48 var Synchronizer = require("synchronizer").Synchronizer; | 53 var Synchronizer = require("synchronizer").Synchronizer; |
49 var Utils = require("utils").Utils; | 54 var Utils = require("utils").Utils; |
50 var NotificationStorage = require("notification").Notification; | 55 var NotificationStorage = require("notification").Notification; |
51 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti
fication; | 56 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti
fication; |
52 var parseFilters = require("filterValidation").parseFilters; | 57 var parseFilters = require("filterValidation").parseFilters; |
53 var composeFilters = require("filterComposer").composeFilters; | 58 var composeFilters = require("filterComposer").composeFilters; |
54 | 59 |
55 // Some types cannot be distinguished | |
56 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | |
57 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT
HER; | |
58 | |
59 // Chrome on Linux does not fully support chrome.notifications until version 35 | 60 // Chrome on Linux does not fully support chrome.notifications until version 35 |
60 // https://code.google.com/p/chromium/issues/detail?id=291485 | 61 // https://code.google.com/p/chromium/issues/detail?id=291485 |
61 var canUseChromeNotifications = require("info").platform == "chromium" | 62 var canUseChromeNotifications = require("info").platform == "chromium" |
62 && "notifications" in chrome | 63 && "notifications" in chrome |
63 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl
icationVersion, 10) > 34); | 64 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl
icationVersion, 10) > 34); |
64 | 65 |
65 var seenDataCorruption = false; | 66 var seenDataCorruption = false; |
66 var filterlistsReinitialized = false; | 67 var filterlistsReinitialized = false; |
67 require("filterNotifier").FilterNotifier.addListener(function(action) | 68 require("filterNotifier").FilterNotifier.addListener(function(action) |
68 { | 69 { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 onclick: function(page) | 129 onclick: function(page) |
129 { | 130 { |
130 page.sendMessage({type: "clickhide-new-filter"}); | 131 page.sendMessage({type: "clickhide-new-filter"}); |
131 } | 132 } |
132 }; | 133 }; |
133 | 134 |
134 // Adds or removes browser action icon according to options. | 135 // Adds or removes browser action icon according to options. |
135 function refreshIconAndContextMenu(page) | 136 function refreshIconAndContextMenu(page) |
136 { | 137 { |
137 var whitelisted = isPageWhitelisted(page); | 138 var whitelisted = isPageWhitelisted(page); |
138 | 139 updateIcon(page, whitelisted); |
139 var iconFilename; | |
140 if (whitelisted && require("info").platform != "safari") | |
141 // There is no grayscale version of the icon for whitelisted pages | |
142 // when using Safari, because icons are grayscale already and icons | |
143 // aren't per page in Safari. | |
144 iconFilename = "icons/abp-$size-whitelisted.png"; | |
145 else | |
146 iconFilename = "icons/abp-$size.png"; | |
147 | |
148 page.browserAction.setIcon(iconFilename); | |
149 iconAnimation.registerPage(page, iconFilename); | |
150 | 140 |
151 // show or hide the context menu entry dependent on whether | 141 // show or hide the context menu entry dependent on whether |
152 // adblocking is active on that page | 142 // adblocking is active on that page |
153 page.contextMenus.removeAll(); | 143 page.contextMenus.removeAll(); |
154 | |
155 if (Prefs.shouldShowBlockElementMenu && !whitelisted && htmlPages.has(page)) | 144 if (Prefs.shouldShowBlockElementMenu && !whitelisted && htmlPages.has(page)) |
156 page.contextMenus.create(contextMenuItem); | 145 page.contextMenus.create(contextMenuItem); |
157 } | 146 } |
158 | 147 |
159 function refreshIconAndContextMenuForAllPages() | 148 function refreshIconAndContextMenuForAllPages() |
160 { | 149 { |
161 ext.pages.query({}, function(pages) | 150 ext.pages.query({}, function(pages) |
162 { | 151 { |
163 pages.forEach(refreshIconAndContextMenu); | 152 pages.forEach(refreshIconAndContextMenu); |
164 }); | 153 }); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 if (name == "shouldShowBlockElementMenu") | 259 if (name == "shouldShowBlockElementMenu") |
271 refreshIconAndContextMenuForAllPages(); | 260 refreshIconAndContextMenuForAllPages(); |
272 }); | 261 }); |
273 | 262 |
274 function prepareNotificationIconAndPopup() | 263 function prepareNotificationIconAndPopup() |
275 { | 264 { |
276 var animateIcon = (activeNotification.type !== "question"); | 265 var animateIcon = (activeNotification.type !== "question"); |
277 activeNotification.onClicked = function() | 266 activeNotification.onClicked = function() |
278 { | 267 { |
279 if (animateIcon) | 268 if (animateIcon) |
280 iconAnimation.stop(); | 269 stopIconAnimation(); |
281 notificationClosed(); | 270 notificationClosed(); |
282 }; | 271 }; |
283 if (animateIcon) | 272 if (animateIcon) |
284 iconAnimation.update(activeNotification.type); | 273 startIconAnimation(activeNotification.type); |
285 } | 274 } |
286 | 275 |
287 function openNotificationLinks() | 276 function openNotificationLinks() |
288 { | 277 { |
289 if (activeNotification.links) | 278 if (activeNotification.links) |
290 { | 279 { |
291 activeNotification.links.forEach(function(link) | 280 activeNotification.links.forEach(function(link) |
292 { | 281 { |
293 ext.windows.getLastFocused(function(win) | 282 ext.windows.getLastFocused(function(win) |
294 { | 283 { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 { | 353 { |
365 if (activeNotification && activeNotification.id === notification.id) | 354 if (activeNotification && activeNotification.id === notification.id) |
366 return; | 355 return; |
367 | 356 |
368 activeNotification = notification; | 357 activeNotification = notification; |
369 if (activeNotification.type === "critical" || activeNotification.type === "que
stion") | 358 if (activeNotification.type === "critical" || activeNotification.type === "que
stion") |
370 { | 359 { |
371 var texts = NotificationStorage.getLocalizedTexts(notification); | 360 var texts = NotificationStorage.getLocalizedTexts(notification); |
372 var title = texts.title || ""; | 361 var title = texts.title || ""; |
373 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "")
: ""; | 362 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "")
: ""; |
374 var iconUrl = ext.getURL("icons/abp-128.png"); | 363 var iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
375 var hasLinks = activeNotification.links && activeNotification.links.length >
0; | 364 var hasLinks = activeNotification.links && activeNotification.links.length >
0; |
376 | 365 |
377 if (canUseChromeNotifications) | 366 if (canUseChromeNotifications) |
378 { | 367 { |
379 var opts = { | 368 var opts = { |
380 type: "basic", | 369 type: "basic", |
381 title: title, | 370 title: title, |
382 message: message, | 371 message: message, |
383 buttons: [], | 372 buttons: [], |
384 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically | 373 priority: 2 // We use the highest priority to prevent the notification f
rom closing automatically |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 }); | 546 }); |
558 break; | 547 break; |
559 case "add-sitekey": | 548 case "add-sitekey": |
560 processKey(msg.token, sender.page, sender.frame); | 549 processKey(msg.token, sender.page, sender.frame); |
561 break; | 550 break; |
562 case "report-html-page": | 551 case "report-html-page": |
563 htmlPages.set(sender.page, null); | 552 htmlPages.set(sender.page, null); |
564 refreshIconAndContextMenu(sender.page); | 553 refreshIconAndContextMenu(sender.page); |
565 break; | 554 break; |
566 case "compose-filters": | 555 case "compose-filters": |
567 sendResponse(composeFilters( | 556 sendResponse(composeFilters({ |
568 msg.tagName, msg.id, msg.src, msg.style, | 557 tagName: msg.tagName, |
569 msg.classes, msg.urls, msg.mediatype, | 558 id: msg.id, |
570 msg.baseURL, sender.page, sender.frame | 559 src: msg.src, |
571 )); | 560 style: msg.style, |
| 561 classes: msg.classes, |
| 562 urls: msg.urls, |
| 563 type: msg.mediatype, |
| 564 baseURL: msg.baseURL, |
| 565 page: sender.page, |
| 566 frame: sender.frame |
| 567 })); |
572 break; | 568 break; |
573 case "forward": | 569 case "forward": |
574 if (sender.page) | 570 if (sender.page) |
575 { | 571 { |
576 if (msg.expectsResponse) | 572 if (msg.expectsResponse) |
577 { | 573 { |
578 sender.page.sendMessage(msg.payload, sendResponse); | 574 sender.page.sendMessage(msg.payload, sendResponse); |
579 return true; | 575 return true; |
580 } | 576 } |
581 | 577 |
582 sender.page.sendMessage(msg.payload); | 578 sender.page.sendMessage(msg.payload); |
583 } | 579 } |
584 break; | 580 break; |
585 } | 581 } |
586 }); | 582 }); |
587 | 583 |
588 // update icon when page changes location | 584 // update icon when page changes location |
589 ext.pages.onLoading.addListener(function(page) | 585 ext.pages.onLoading.addListener(function(page) |
590 { | 586 { |
591 page.sendMessage({type: "clickhide-deactivate"}); | 587 page.sendMessage({type: "clickhide-deactivate"}); |
592 refreshIconAndContextMenu(page); | 588 refreshIconAndContextMenu(page); |
593 }); | 589 }); |
594 | 590 |
595 setTimeout(function() | 591 setTimeout(function() |
596 { | 592 { |
597 var notificationToShow = NotificationStorage.getNextToShow(); | 593 var notificationToShow = NotificationStorage.getNextToShow(); |
598 if (notificationToShow) | 594 if (notificationToShow) |
599 showNotification(notificationToShow); | 595 showNotification(notificationToShow); |
600 }, 3 * 60 * 1000); | 596 }, 3 * 60 * 1000); |
LEFT | RIGHT |