| 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 |
| (...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 |
| 69 { | 79 function init() |
| 70 if (action == "load") | 80 { |
| 71 { | 81 var filtersLoaded = false; |
| 72 ext.storage.get(["currentVersion"], function(items) | 82 var prefsLoaded = false; |
| 73 { | 83 |
| 74 var addonVersion = require("info").addonVersion; | 84 var checkLoaded = function() |
| 75 var prevVersion = items.currentVersion; | 85 { |
| 76 | 86 if (!filtersLoaded || !prefsLoaded) |
| 77 // There are no filters stored so we need to reinitialize all filterlists | 87 return; |
| 78 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) | 88 |
| 79 { | 89 var info = require("info"); |
| 80 filterlistsReinitialized = true; | 90 var previousVersion = Prefs.currentVersion; |
| 81 prevVersion = null; | 91 |
| 82 } | 92 // There are no filters stored so we need to reinitialize all filterlists |
| 83 | 93 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) |
| 84 if (prevVersion != addonVersion || FilterStorage.firstRun) | 94 { |
| 85 { | 95 filterlistsReinitialized = true; |
| 86 seenDataCorruption = prevVersion && FilterStorage.firstRun; | 96 previousVersion = null; |
| 87 ext.storage.set("currentVersion", addonVersion); | 97 } |
| 88 addSubscription(prevVersion); | 98 |
| 89 } | 99 if (previousVersion != info.addonVersion || FilterStorage.firstRun) |
| 90 | 100 { |
| 91 // The "Hide placeholders" option has been removed from the UI in 1.8.8.12
85 | 101 seenDataCorruption = previousVersion && FilterStorage.firstRun; |
| 92 // So we reset the option for users updating from older versions. | 102 Prefs.currentVersion = info.addonVersion; |
| 93 if (prevVersion && Services.vc.compare(prevVersion, "1.8.8.1285") < 0) | 103 addSubscription(previousVersion); |
| 94 Prefs.hidePlaceholders = true; | 104 } |
| 95 }); | 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; |
| 96 | 110 |
| 97 if (canUseChromeNotifications) | 111 if (canUseChromeNotifications) |
| 98 initChromeNotifications(); | 112 initChromeNotifications(); |
| 99 initAntiAdblockNotification(); | 113 initAntiAdblockNotification(); |
| 100 } | 114 |
| 101 | 115 // Update browser actions and context menus when whitelisting might have |
| 102 // update browser actions when whitelisting might have changed, | 116 // changed. That is now when initally loading the filters and later when |
| 103 // due to loading filters or saving filter changes | 117 // importing backups or saving filter changes. |
| 104 if (action == "load" || action == "save") | 118 FilterNotifier.addListener(function(action) |
| 119 { |
| 120 if (action == "load" || action == "save") |
| 121 refreshIconAndContextMenuForAllPages(); |
| 122 }); |
| 105 refreshIconAndContextMenuForAllPages(); | 123 refreshIconAndContextMenuForAllPages(); |
| 106 }); | 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(); |
| 107 | 147 |
| 108 // 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. |
| 109 // See http://crbug.com/68705. | 149 // See http://crbug.com/68705. |
| 110 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; | 150 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; |
| 111 | 151 |
| 112 var htmlPages = new ext.PageMap(); | 152 var htmlPages = new ext.PageMap(); |
| 113 var activeNotification = null; | 153 var activeNotification = null; |
| 114 | 154 |
| 115 var contextMenuItem = { | 155 var contextMenuItem = { |
| 116 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... |
| 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); |
| LEFT | RIGHT |