 Issue 5749582424178688:
  Ported over anti-adblock message notification  (Closed)
    
  
    Issue 5749582424178688:
  Ported over anti-adblock message notification  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 1 /* | 1 /* | 
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 23 matching lines...) Expand all Loading... | |
| 34 this.isFrameWhitelisted = isFrameWhitelisted; | 34 this.isFrameWhitelisted = isFrameWhitelisted; | 
| 35 this.processKeyException = processKeyException; | 35 this.processKeyException = processKeyException; | 
| 36 } | 36 } | 
| 37 var FilterStorage = require("filterStorage").FilterStorage; | 37 var FilterStorage = require("filterStorage").FilterStorage; | 
| 38 var ElemHide = require("elemHide").ElemHide; | 38 var ElemHide = require("elemHide").ElemHide; | 
| 39 var defaultMatcher = require("matcher").defaultMatcher; | 39 var defaultMatcher = require("matcher").defaultMatcher; | 
| 40 var Prefs = require("prefs").Prefs; | 40 var Prefs = require("prefs").Prefs; | 
| 41 var Synchronizer = require("synchronizer").Synchronizer; | 41 var Synchronizer = require("synchronizer").Synchronizer; | 
| 42 var Utils = require("utils").Utils; | 42 var Utils = require("utils").Utils; | 
| 43 var Notification = require("notification").Notification; | 43 var Notification = require("notification").Notification; | 
| 44 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication; | |
| 44 | 45 | 
| 45 // Some types cannot be distinguished | 46 // Some types cannot be distinguished | 
| 46 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 47 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 
| 47 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; | 48 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; | 
| 48 | 49 | 
| 49 var isFirstRun = false; | 50 var isFirstRun = false; | 
| 50 var seenDataCorruption = false; | 51 var seenDataCorruption = false; | 
| 51 require("filterNotifier").FilterNotifier.addListener(function(action) | 52 require("filterNotifier").FilterNotifier.addListener(function(action) | 
| 52 { | 53 { | 
| 53 if (action == "load") | 54 if (action == "load") | 
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 246 | 
| 246 notifyUser(); | 247 notifyUser(); | 
| 247 } | 248 } | 
| 248 }, false); | 249 }, false); | 
| 249 request.send(null); | 250 request.send(null); | 
| 250 } | 251 } | 
| 251 else | 252 else | 
| 252 notifyUser(); | 253 notifyUser(); | 
| 253 } | 254 } | 
| 254 | 255 | 
| 255 function initAntiAdblockNotification() | |
| 
Felix Dahlke
2014/03/18 14:21:41
This is pretty much the same code we have in Firef
 
Thomas Greiner
2014/03/19 13:45:40
Done.
 | |
| 256 { | |
| 257 var notification = { | |
| 258 id: "antiadblock", | |
| 259 type: "question", | |
| 260 title: ext.i18n.getMessage("global_notification_antiadblock_title"), | |
| 261 message: ext.i18n.getMessage("global_notification_antiadblock_message"), | |
| 262 urlFilters: [] | |
| 263 }; | |
| 264 | |
| 265 function notificationListener(approved) | |
| 266 { | |
| 267 var subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); | |
| 268 if (subscription.url in FilterStorage.knownSubscriptions) | |
| 269 subscription.disabled = !approved; | |
| 270 } | |
| 271 | |
| 272 function addAntiAdblockNotification(subscription) | |
| 273 { | |
| 274 var urlFilters = []; | |
| 275 subscription.filters.forEach(function(filter) | |
| 276 { | |
| 277 if (filter instanceof ActiveFilter) | |
| 278 for (var domain in filter.domains) | |
| 279 if (domain && urlFilters.indexOf(domain) == -1) | |
| 280 urlFilters.push(domain); | |
| 281 }); | |
| 282 notification.urlFilters = urlFilters; | |
| 283 Notification.addNotification(notification); | |
| 284 Notification.addQuestionListener(notification.id, notificationListener); | |
| 285 } | |
| 286 | |
| 287 function removeAntiAdblockNotification() | |
| 288 { | |
| 289 Notification.removeNotification(notification); | |
| 290 Notification.removeQuestionListener(notification.id, notificationListener); | |
| 291 } | |
| 292 | |
| 293 var subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); | |
| 294 if (subscription.lastDownload && subscription.disabled) | |
| 295 addAntiAdblockNotification(subscription); | |
| 296 | |
| 297 FilterNotifier.addListener(function(action, value, newItem, oldItem) | |
| 298 { | |
| 299 if (!/^subscription\.(updated|removed|disabled)$/.test(action) || value.url != Prefs.subscriptions_antiadblockurl) | |
| 300 return; | |
| 301 | |
| 302 if (action == "subscription.updated") | |
| 303 addAntiAdblockNotification(value); | |
| 304 else if (action == "subscription.removed" || (action == "subscription.disabl ed" && !value.disabled)) | |
| 305 removeAntiAdblockNotification(); | |
| 306 }); | |
| 307 } | |
| 308 | |
| 309 function setContextMenu() | 256 function setContextMenu() | 
| 310 { | 257 { | 
| 311 if (Prefs.shouldShowBlockElementMenu) | 258 if (Prefs.shouldShowBlockElementMenu) | 
| 312 { | 259 { | 
| 313 // Register context menu item | 260 // Register context menu item | 
| 314 ext.contextMenus.addMenuItem(ext.i18n.getMessage("block_element"), ["image", "video", "audio"], function(srcUrl, tab) | 261 ext.contextMenus.addMenuItem(ext.i18n.getMessage("block_element"), ["image", "video", "audio"], function(srcUrl, tab) | 
| 315 { | 262 { | 
| 316 if (srcUrl) | 263 if (srcUrl) | 
| 317 tab.sendMessage({type: "clickhide-new-filter", filter: srcUrl}); | 264 tab.sendMessage({type: "clickhide-new-filter", filter: srcUrl}); | 
| 318 }); | 265 }); | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 win.openTab(optionsUrl, callback && function(tab) | 302 win.openTab(optionsUrl, callback && function(tab) | 
| 356 { | 303 { | 
| 357 tab.onCompleted.addListener(callback); | 304 tab.onCompleted.addListener(callback); | 
| 358 }); | 305 }); | 
| 359 }); | 306 }); | 
| 360 }); | 307 }); | 
| 361 } | 308 } | 
| 362 | 309 | 
| 363 function prepareNotificationIconAndPopup() | 310 function prepareNotificationIconAndPopup() | 
| 364 { | 311 { | 
| 312 var animateIcon = (activeNotification.type !== "question"); | |
| 365 activeNotification.onClicked = function() | 313 activeNotification.onClicked = function() | 
| 366 { | 314 { | 
| 367 iconAnimation.stop(); | 315 if (animateIcon) | 
| 316 iconAnimation.stop(); | |
| 368 activeNotification = null; | 317 activeNotification = null; | 
| 369 }; | 318 }; | 
| 370 iconAnimation.update(activeNotification.type); | 319 if (animateIcon) | 
| 320 iconAnimation.update(activeNotification.type); | |
| 371 } | 321 } | 
| 372 | 322 | 
| 373 function openNotificationLinks() | 323 function openNotificationLinks() | 
| 374 { | 324 { | 
| 375 if (activeNotification.links) | 325 if (activeNotification.links) | 
| 376 { | 326 { | 
| 377 activeNotification.links.forEach(function(link) | 327 activeNotification.links.forEach(function(link) | 
| 378 { | 328 { | 
| 379 ext.windows.getLastFocused(function(win) | 329 ext.windows.getLastFocused(function(win) | 
| 380 { | 330 { | 
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 tab.sendMessage({type: "clickhide-deactivate"}); | 528 tab.sendMessage({type: "clickhide-deactivate"}); | 
| 579 refreshIconAndContextMenu(tab); | 529 refreshIconAndContextMenu(tab); | 
| 580 }); | 530 }); | 
| 581 | 531 | 
| 582 setTimeout(function() | 532 setTimeout(function() | 
| 583 { | 533 { | 
| 584 var notificationToShow = Notification.getNextToShow(); | 534 var notificationToShow = Notification.getNextToShow(); | 
| 585 if (notificationToShow) | 535 if (notificationToShow) | 
| 586 showNotification(notificationToShow); | 536 showNotification(notificationToShow); | 
| 587 }, 3 * 60 * 1000); | 537 }, 3 * 60 * 1000); | 
| LEFT | RIGHT |