OLD | NEW |
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 29 matching lines...) Expand all Loading... |
40 this.isThirdParty = isThirdParty; | 40 this.isThirdParty = isThirdParty; |
41 this.extractHostFromFrame = extractHostFromFrame; | 41 this.extractHostFromFrame = extractHostFromFrame; |
42 } | 42 } |
43 with(require("icon")) | 43 with(require("icon")) |
44 { | 44 { |
45 this.updateIcon = updateIcon; | 45 this.updateIcon = updateIcon; |
46 this.startIconAnimation = startIconAnimation; | 46 this.startIconAnimation = startIconAnimation; |
47 this.stopIconAnimation = stopIconAnimation; | 47 this.stopIconAnimation = stopIconAnimation; |
48 } | 48 } |
49 var FilterStorage = require("filterStorage").FilterStorage; | 49 var FilterStorage = require("filterStorage").FilterStorage; |
| 50 var FilterNotifier = require("filterNotifier").FilterNotifier; |
50 var ElemHide = require("elemHide").ElemHide; | 51 var ElemHide = require("elemHide").ElemHide; |
51 var defaultMatcher = require("matcher").defaultMatcher; | 52 var defaultMatcher = require("matcher").defaultMatcher; |
52 var Prefs = require("prefs").Prefs; | 53 var Prefs = require("prefs").Prefs; |
53 var Synchronizer = require("synchronizer").Synchronizer; | 54 var Synchronizer = require("synchronizer").Synchronizer; |
54 var Utils = require("utils").Utils; | 55 var Utils = require("utils").Utils; |
55 var NotificationStorage = require("notification").Notification; | 56 var NotificationStorage = require("notification").Notification; |
56 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti
fication; | 57 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti
fication; |
57 var parseFilters = require("filterValidation").parseFilters; | 58 var parseFilters = require("filterValidation").parseFilters; |
58 var composeFilters = require("filterComposer").composeFilters; | 59 var composeFilters = require("filterComposer").composeFilters; |
59 | 60 |
60 // 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 |
61 // https://code.google.com/p/chromium/issues/detail?id=291485 | 62 // https://code.google.com/p/chromium/issues/detail?id=291485 |
62 var canUseChromeNotifications = require("info").platform == "chromium" | 63 var canUseChromeNotifications = (function() |
63 && "notifications" in chrome | 64 { |
64 && (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 })(); |
65 | 75 |
66 var seenDataCorruption = false; | 76 var seenDataCorruption = false; |
67 var filterlistsReinitialized = false; | 77 var filterlistsReinitialized = false; |
68 require("filterNotifier").FilterNotifier.addListener(function(action) | 78 |
| 79 function init() |
69 { | 80 { |
70 if (action == "load") | 81 var filtersLoaded = false; |
| 82 var prefsLoaded = false; |
| 83 |
| 84 var checkLoaded = function() |
71 { | 85 { |
72 var addonVersion = require("info").addonVersion; | 86 if (!filtersLoaded || !prefsLoaded) |
73 var prevVersion = ext.storage.currentVersion; | 87 return; |
| 88 |
| 89 var info = require("info"); |
| 90 var previousVersion = Prefs.currentVersion; |
74 | 91 |
75 // There are no filters stored so we need to reinitialize all filterlists | 92 // There are no filters stored so we need to reinitialize all filterlists |
76 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) | 93 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) |
77 { | 94 { |
78 filterlistsReinitialized = true; | 95 filterlistsReinitialized = true; |
79 prevVersion = null; | 96 previousVersion = null; |
80 } | 97 } |
81 | 98 |
82 if (prevVersion != addonVersion || FilterStorage.firstRun) | 99 if (previousVersion != info.addonVersion || FilterStorage.firstRun) |
83 { | 100 { |
84 seenDataCorruption = prevVersion && FilterStorage.firstRun; | 101 seenDataCorruption = previousVersion && FilterStorage.firstRun; |
85 ext.storage.currentVersion = addonVersion; | 102 Prefs.currentVersion = info.addonVersion; |
86 addSubscription(prevVersion); | 103 addSubscription(previousVersion); |
87 } | 104 } |
88 | 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; |
| 110 |
89 if (canUseChromeNotifications) | 111 if (canUseChromeNotifications) |
90 initChromeNotifications(); | 112 initChromeNotifications(); |
91 initAntiAdblockNotification(); | 113 initAntiAdblockNotification(); |
92 | 114 |
93 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285 | 115 // Update browser actions and context menus when whitelisting might have |
94 // So we reset the option for users updating from older versions. | 116 // changed. That is now when initally loading the filters and later when |
95 if (prevVersion && Services.vc.compare(prevVersion, "1.8.8.1285") < 0) | 117 // importing backups or saving filter changes. |
96 Prefs.hidePlaceholders = true; | 118 FilterNotifier.addListener(function(action) |
97 } | 119 { |
| 120 if (action == "load" || action == "save") |
| 121 refreshIconAndContextMenuForAllPages(); |
| 122 }); |
| 123 refreshIconAndContextMenuForAllPages(); |
| 124 }; |
98 | 125 |
99 // update browser actions when whitelisting might have changed, | 126 var onFilterAction = function(action) |
100 // due to loading filters or saving filter changes | 127 { |
101 if (action == "load" || action == "save") | 128 if (action == "load") |
102 refreshIconAndContextMenuForAllPages(); | 129 { |
103 }); | 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(); |
104 | 147 |
105 // 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. |
106 // See http://crbug.com/68705. | 149 // See http://crbug.com/68705. |
107 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; | 150 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; |
108 | 151 |
109 var htmlPages = new ext.PageMap(); | 152 var htmlPages = new ext.PageMap(); |
110 | |
111 function removeDeprecatedOptions() | |
112 { | |
113 var deprecatedOptions = ["specialCaseYouTube", "experimental", "disableInlineT
extAds"]; | |
114 deprecatedOptions.forEach(function(option) | |
115 { | |
116 if (option in ext.storage) | |
117 delete ext.storage[option]; | |
118 }); | |
119 } | |
120 | |
121 // Remove deprecated options before we do anything else. | |
122 removeDeprecatedOptions(); | |
123 | |
124 var activeNotification = null; | 153 var activeNotification = null; |
125 | 154 |
126 var contextMenuItem = { | 155 var contextMenuItem = { |
127 title: ext.i18n.getMessage("block_element"), | 156 title: ext.i18n.getMessage("block_element"), |
128 contexts: ["image", "video", "audio"], | 157 contexts: ["image", "video", "audio"], |
129 onclick: function(page) | 158 onclick: function(page) |
130 { | 159 { |
131 page.sendMessage({type: "clickhide-new-filter"}); | 160 page.sendMessage({type: "clickhide-new-filter"}); |
132 } | 161 } |
133 }; | 162 }; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 276 |
248 notifyUser(); | 277 notifyUser(); |
249 } | 278 } |
250 }, false); | 279 }, false); |
251 request.send(null); | 280 request.send(null); |
252 } | 281 } |
253 else | 282 else |
254 notifyUser(); | 283 notifyUser(); |
255 } | 284 } |
256 | 285 |
257 Prefs.addListener(function(name) | 286 Prefs.onChanged.addListener(function(name) |
258 { | 287 { |
259 if (name == "shouldShowBlockElementMenu") | 288 if (name == "shouldShowBlockElementMenu") |
260 refreshIconAndContextMenuForAllPages(); | 289 refreshIconAndContextMenuForAllPages(); |
261 }); | 290 }); |
262 | 291 |
263 function prepareNotificationIconAndPopup() | 292 function prepareNotificationIconAndPopup() |
264 { | 293 { |
265 var animateIcon = (activeNotification.type !== "question"); | 294 var animateIcon = (activeNotification.type !== "question"); |
266 activeNotification.onClicked = function() | 295 activeNotification.onClicked = function() |
267 { | 296 { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 page.sendMessage({type: "clickhide-deactivate"}); | 616 page.sendMessage({type: "clickhide-deactivate"}); |
588 refreshIconAndContextMenu(page); | 617 refreshIconAndContextMenu(page); |
589 }); | 618 }); |
590 | 619 |
591 setTimeout(function() | 620 setTimeout(function() |
592 { | 621 { |
593 var notificationToShow = NotificationStorage.getNextToShow(); | 622 var notificationToShow = NotificationStorage.getNextToShow(); |
594 if (notificationToShow) | 623 if (notificationToShow) |
595 showNotification(notificationToShow); | 624 showNotification(notificationToShow); |
596 }, 3 * 60 * 1000); | 625 }, 3 * 60 * 1000); |
OLD | NEW |