| Left: | ||
| Right: |
| 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; | |
|
kzar
2015/03/19 15:20:37
Shouldn't this be `FilterNotifier`?
Sebastian Noack
2015/03/20 13:26:12
No, the module is still called "filterNotifier".
kzar
2015/03/20 14:47:44
I meant the variable name.
Sebastian Noack
2015/03/20 15:40:55
I see ,you are right. Surprisingly, it still worke
| |
| 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 = require("info").platform == "chromium" |
| 63 && "notifications" in chrome | 64 && "notifications" in chrome |
| 64 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34); | 65 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34); |
| 65 | 66 |
| 66 var seenDataCorruption = false; | 67 var seenDataCorruption = false; |
| 67 var filterlistsReinitialized = false; | 68 var filterlistsReinitialized = false; |
| 68 require("filterNotifier").FilterNotifier.addListener(function(action) | 69 |
| 70 function init() | |
| 69 { | 71 { |
| 70 if (action == "load") | 72 var previousVersion = null; |
| 73 | |
| 74 var filtersLoaded = false; | |
| 75 var prefsLoaded = false; | |
| 76 | |
| 77 var onLoaded = function() | |
| 71 { | 78 { |
| 72 ext.storage.get(["currentVersion"], function(items) | 79 var addonVersion = require("info").addonVersion; |
| 80 | |
| 81 // There are no filters stored so we need to reinitialize all filterlists | |
| 82 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) | |
| 73 { | 83 { |
| 74 var addonVersion = require("info").addonVersion; | 84 filterlistsReinitialized = true; |
| 75 var prevVersion = items.currentVersion; | 85 previousVersion = null; |
| 86 } | |
| 76 | 87 |
| 77 // There are no filters stored so we need to reinitialize all filterlists | 88 if (previousVersion != addonVersion || FilterStorage.firstRun) |
| 78 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) | 89 { |
| 79 { | 90 seenDataCorruption = previousVersion && FilterStorage.firstRun; |
| 80 filterlistsReinitialized = true; | 91 ext.storage.set("currentVersion", addonVersion); |
|
Wladimir Palant
2015/03/19 16:57:04
Prefs.currentVersion = addonVersion?
Sebastian Noack
2015/03/20 13:26:12
currentVersion isn't a preference, but I agree we
| |
| 81 prevVersion = null; | 92 addSubscription(previousVersion); |
| 82 } | 93 } |
| 83 | 94 |
| 84 if (prevVersion != addonVersion || FilterStorage.firstRun) | 95 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285 |
| 85 { | 96 // So we reset the option for users updating from older versions. |
| 86 seenDataCorruption = prevVersion && FilterStorage.firstRun; | 97 if (previousVersion && Services.vc.compare(previousVersion, "1.8.8.1285") < 0) |
| 87 ext.storage.set("currentVersion", addonVersion); | 98 Prefs.hidePlaceholders = true; |
| 88 addSubscription(prevVersion); | |
| 89 } | |
| 90 | |
| 91 // The "Hide placeholders" option has been removed from the UI in 1.8.8.12 85 | |
| 92 // So we reset the option for users updating from older versions. | |
| 93 if (prevVersion && Services.vc.compare(prevVersion, "1.8.8.1285") < 0) | |
| 94 Prefs.hidePlaceholders = true; | |
| 95 }); | |
| 96 | 99 |
| 97 if (canUseChromeNotifications) | 100 if (canUseChromeNotifications) |
| 98 initChromeNotifications(); | 101 initChromeNotifications(); |
| 99 initAntiAdblockNotification(); | 102 initAntiAdblockNotification(); |
| 100 } | |
| 101 | 103 |
| 102 // update browser actions when whitelisting might have changed, | 104 // Update browser actions and context menus when whitelisting might have cha nged, |
| 103 // due to loading filters or saving filter changes | 105 // now when initally loading the filters, or later when saving filter chang es. |
|
kzar
2015/03/19 15:20:37
nit: The second line of this comment doesn't read
Sebastian Noack
2015/03/20 13:26:12
I had to rephrase it anyway while addressing Wladi
| |
| 104 if (action == "load" || action == "save") | 106 FilterNotifier.addListener(function(action) |
| 107 { | |
| 108 if (action == "save") | |
|
Wladimir Palant
2015/03/19 16:57:04
Please check for action == "load" as well here. Wh
Sebastian Noack
2015/03/20 13:26:12
Done.
| |
| 109 refreshIconAndContextMenuForAllPages(); | |
| 110 }); | |
| 105 refreshIconAndContextMenuForAllPages(); | 111 refreshIconAndContextMenuForAllPages(); |
| 106 }); | 112 }; |
| 113 | |
| 114 var onFilterAction = function(action) | |
| 115 { | |
| 116 if (action == "load") | |
| 117 { | |
| 118 filtersLoaded = true; | |
| 119 if (prefsLoaded) | |
|
Wladimir Palant
2015/03/19 16:57:04
This makes the condition you are checking for (and
Sebastian Noack
2015/03/20 13:26:12
The reason I didn't put it into onLoading in the f
| |
| 120 onLoaded(); | |
| 121 | |
| 122 FilterNotifier.removeListener(onFilterAction); | |
|
Wladimir Palant
2015/03/19 16:57:04
Please always clean up before you run complicated
Sebastian Noack
2015/03/20 13:26:12
Done.
| |
| 123 } | |
| 124 }; | |
| 125 | |
| 126 var onPrefsLoaded = function() | |
| 127 { | |
| 128 // We have to wait for Prefs.onLoaded before retrieving "currentVersion". | |
| 129 // Otherwise it might not be migrated from localStorage yet. | |
| 130 ext.storage.get(["currentVersion"], function(items) | |
|
Wladimir Palant
2015/03/19 16:57:04
This shouldn't be necessary, you can simply use Pr
Sebastian Noack
2015/03/20 13:26:12
See above, currentVersion wasn't a pref yet. Now w
| |
| 131 { | |
| 132 previousVersion = items.currentVersion; | |
| 133 | |
| 134 prefsLoaded = true; | |
| 135 if (filtersLoaded) | |
| 136 onLoaded(); | |
| 137 }); | |
| 138 | |
| 139 Prefs.onLoaded.removeListener(onPrefsLoaded); | |
| 140 }; | |
| 141 | |
| 142 FilterNotifier.addListener(onFilterAction); | |
| 143 Prefs.onLoaded.addListener(onPrefsLoaded); | |
| 144 } | |
| 145 init(); | |
| 107 | 146 |
| 108 // Special-case domains for which we cannot use style-based hiding rules. | 147 // Special-case domains for which we cannot use style-based hiding rules. |
| 109 // See http://crbug.com/68705. | 148 // See http://crbug.com/68705. |
| 110 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; | 149 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; |
| 111 | 150 |
| 112 var htmlPages = new ext.PageMap(); | 151 var htmlPages = new ext.PageMap(); |
| 113 var activeNotification = null; | 152 var activeNotification = null; |
| 114 | 153 |
| 115 var contextMenuItem = { | 154 var contextMenuItem = { |
| 116 title: ext.i18n.getMessage("block_element"), | 155 title: ext.i18n.getMessage("block_element"), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 if (subscription instanceof DownloadableSubscription && !subscription.last Download) | 245 if (subscription instanceof DownloadableSubscription && !subscription.last Download) |
| 207 Synchronizer.execute(subscription); | 246 Synchronizer.execute(subscription); |
| 208 } | 247 } |
| 209 } | 248 } |
| 210 | 249 |
| 211 if (!addSubscription && !addAcceptable) | 250 if (!addSubscription && !addAcceptable) |
| 212 return; | 251 return; |
| 213 | 252 |
| 214 function notifyUser() | 253 function notifyUser() |
| 215 { | 254 { |
| 216 ext.pages.open(ext.getURL("firstRun.html")); | 255 if (!Prefs.suppress_first_run_page) |
| 256 ext.pages.open(ext.getURL("firstRun.html")); | |
| 217 } | 257 } |
| 218 | 258 |
| 219 if (addSubscription) | 259 if (addSubscription) |
| 220 { | 260 { |
| 221 // Load subscriptions data | 261 // Load subscriptions data |
| 222 var request = new XMLHttpRequest(); | 262 var request = new XMLHttpRequest(); |
| 223 request.open("GET", "subscriptions.xml"); | 263 request.open("GET", "subscriptions.xml"); |
| 224 request.addEventListener("load", function() | 264 request.addEventListener("load", function() |
| 225 { | 265 { |
| 226 var node = Utils.chooseFilterSubscription(request.responseXML.getElementsB yTagName("subscription")); | 266 var node = Utils.chooseFilterSubscription(request.responseXML.getElementsB yTagName("subscription")); |
| 227 var subscription = (node ? Subscription.fromURL(node.getAttribute("url")) : null); | 267 var subscription = (node ? Subscription.fromURL(node.getAttribute("url")) : null); |
| 228 if (subscription) | 268 if (subscription) |
| 229 { | 269 { |
| 230 FilterStorage.addSubscription(subscription); | 270 FilterStorage.addSubscription(subscription); |
| 231 subscription.disabled = false; | 271 subscription.disabled = false; |
| 232 subscription.title = node.getAttribute("title"); | 272 subscription.title = node.getAttribute("title"); |
| 233 subscription.homepage = node.getAttribute("homepage"); | 273 subscription.homepage = node.getAttribute("homepage"); |
| 234 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) | 274 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) |
| 235 Synchronizer.execute(subscription); | 275 Synchronizer.execute(subscription); |
| 236 | 276 |
| 237 notifyUser(); | 277 notifyUser(); |
| 238 } | 278 } |
| 239 }, false); | 279 }, false); |
| 240 request.send(null); | 280 request.send(null); |
| 241 } | 281 } |
| 242 else | 282 else |
| 243 notifyUser(); | 283 notifyUser(); |
| 244 } | 284 } |
| 245 | 285 |
| 246 Prefs.addListener(function(name) | 286 Prefs.onChanged.addListener(function(name) |
| 247 { | 287 { |
| 248 if (name == "shouldShowBlockElementMenu") | 288 if (name == "shouldShowBlockElementMenu") |
| 249 refreshIconAndContextMenuForAllPages(); | 289 refreshIconAndContextMenuForAllPages(); |
| 250 }); | 290 }); |
| 251 | 291 |
| 252 function prepareNotificationIconAndPopup() | 292 function prepareNotificationIconAndPopup() |
| 253 { | 293 { |
| 254 var animateIcon = (activeNotification.type !== "question"); | 294 var animateIcon = (activeNotification.type !== "question"); |
| 255 activeNotification.onClicked = function() | 295 activeNotification.onClicked = function() |
| 256 { | 296 { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 page.sendMessage({type: "clickhide-deactivate"}); | 616 page.sendMessage({type: "clickhide-deactivate"}); |
| 577 refreshIconAndContextMenu(page); | 617 refreshIconAndContextMenu(page); |
| 578 }); | 618 }); |
| 579 | 619 |
| 580 setTimeout(function() | 620 setTimeout(function() |
| 581 { | 621 { |
| 582 var notificationToShow = NotificationStorage.getNextToShow(); | 622 var notificationToShow = NotificationStorage.getNextToShow(); |
| 583 if (notificationToShow) | 623 if (notificationToShow) |
| 584 showNotification(notificationToShow); | 624 showNotification(notificationToShow); |
| 585 }, 3 * 60 * 1000); | 625 }, 3 * 60 * 1000); |
| OLD | NEW |