| 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-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 28 matching lines...) Expand all Loading... | |
| 39 var Prefs = require("prefs").Prefs; | 39 var Prefs = require("prefs").Prefs; |
| 40 var Synchronizer = require("synchronizer").Synchronizer; | 40 var Synchronizer = require("synchronizer").Synchronizer; |
| 41 var Utils = require("utils").Utils; | 41 var Utils = require("utils").Utils; |
| 42 var Notification = require("notification").Notification; | 42 var Notification = require("notification").Notification; |
| 43 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication; | 43 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication; |
| 44 | 44 |
| 45 // Some types cannot be distinguished | 45 // Some types cannot be distinguished |
| 46 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 46 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
| 47 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; | 47 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; |
| 48 | 48 |
| 49 // Chrome on Linux does not fully support chrome.notifications until version 35 | |
| 50 // https://code.google.com/p/chromium/issues/detail?id=291485 | |
| 51 var canUseChromeNotifications = require("info").platform == "chromium" | |
| 52 && "notifications" in chrome | |
| 53 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion) > 34); | |
| 54 | |
| 49 var isFirstRun = false; | 55 var isFirstRun = false; |
| 50 var seenDataCorruption = false; | 56 var seenDataCorruption = false; |
| 51 require("filterNotifier").FilterNotifier.addListener(function(action) | 57 require("filterNotifier").FilterNotifier.addListener(function(action) |
| 52 { | 58 { |
| 53 if (action == "load") | 59 if (action == "load") |
| 54 { | 60 { |
| 55 var importingOldData = importOldData(); | 61 var importingOldData = importOldData(); |
| 56 | 62 |
| 57 var addonVersion = require("info").addonVersion; | 63 var addonVersion = require("info").addonVersion; |
| 58 var prevVersion = ext.storage.currentVersion; | 64 var prevVersion = ext.storage.currentVersion; |
| 59 if (prevVersion != addonVersion) | 65 if (prevVersion != addonVersion) |
| 60 { | 66 { |
| 61 isFirstRun = !prevVersion; | 67 isFirstRun = !prevVersion; |
| 62 ext.storage.currentVersion = addonVersion; | 68 ext.storage.currentVersion = addonVersion; |
| 63 if (!importingOldData) | 69 if (!importingOldData) |
| 64 addSubscription(prevVersion); | 70 addSubscription(prevVersion); |
| 65 } | 71 } |
| 66 | 72 |
| 73 if (canUseChromeNotifications) | |
| 74 initChromeNotifications(); | |
| 67 initAntiAdblockNotification(); | 75 initAntiAdblockNotification(); |
| 68 } | 76 } |
| 69 | 77 |
| 70 // update browser actions when whitelisting might have changed, | 78 // update browser actions when whitelisting might have changed, |
| 71 // due to loading filters or saving filter changes | 79 // due to loading filters or saving filter changes |
| 72 if (action == "load" || action == "save") | 80 if (action == "load" || action == "save") |
| 73 { | 81 { |
| 74 ext.windows.getAll(function(windows) | 82 ext.windows.getAll(function(windows) |
| 75 { | 83 { |
| 76 for (var i = 0; i < windows.length; i++) | 84 for (var i = 0; i < windows.length; i++) |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 }); | 314 }); |
| 307 } | 315 } |
| 308 | 316 |
| 309 function prepareNotificationIconAndPopup() | 317 function prepareNotificationIconAndPopup() |
| 310 { | 318 { |
| 311 var animateIcon = (activeNotification.type !== "question"); | 319 var animateIcon = (activeNotification.type !== "question"); |
| 312 activeNotification.onClicked = function() | 320 activeNotification.onClicked = function() |
| 313 { | 321 { |
| 314 if (animateIcon) | 322 if (animateIcon) |
| 315 iconAnimation.stop(); | 323 iconAnimation.stop(); |
| 316 activeNotification = null; | 324 notificationClosed(); |
| 317 }; | 325 }; |
| 318 if (animateIcon) | 326 if (animateIcon) |
| 319 iconAnimation.update(activeNotification.type); | 327 iconAnimation.update(activeNotification.type); |
| 320 } | 328 } |
| 321 | 329 |
| 322 function openNotificationLinks() | 330 function openNotificationLinks() |
| 323 { | 331 { |
| 324 if (activeNotification.links) | 332 if (activeNotification.links) |
| 325 { | 333 { |
| 326 activeNotification.links.forEach(function(link) | 334 activeNotification.links.forEach(function(link) |
| 327 { | 335 { |
| 328 ext.windows.getLastFocused(function(win) | 336 ext.windows.getLastFocused(function(win) |
| 329 { | 337 { |
| 330 win.openTab(Utils.getDocLink(link)); | 338 win.openTab(Utils.getDocLink(link)); |
| 331 }); | 339 }); |
| 332 }); | 340 }); |
| 333 } | 341 } |
| 334 } | 342 } |
| 335 | 343 |
| 336 function notificationButtonClick(id, index) | 344 function notificationButtonClick(buttonIndex) |
| 337 { | 345 { |
| 338 if (activeNotification.type === "question") | 346 if (activeNotification.type === "question") |
| 339 { | 347 { |
| 340 Notification.triggerQuestionListeners(activeNotification.id, index === 0); | 348 Notification.triggerQuestionListeners(activeNotification.id, buttonIndex === 0); |
| 341 Notification.markAsShown(activeNotification.id); | 349 Notification.markAsShown(activeNotification.id); |
| 342 activeNotification.onClicked(); | 350 activeNotification.onClicked(); |
| 343 } | 351 } |
| 344 else if (activeNotification.links && activeNotification.links[index]) | 352 else if (activeNotification.links && activeNotification.links[buttonIndex]) |
| 345 { | 353 { |
| 346 ext.windows.getLastFocused(function(win) | 354 ext.windows.getLastFocused(function(win) |
| 347 { | 355 { |
| 348 win.openTab(Utils.getDocLink(activeNotification.links[index])); | 356 win.openTab(Utils.getDocLink(activeNotification.links[buttonIndex])); |
| 349 }); | 357 }); |
| 350 } | 358 } |
| 351 } | 359 } |
| 352 | 360 |
| 353 function notificationClosed() | 361 function notificationClosed() |
| 354 { | 362 { |
| 355 activeNotification = null; | 363 activeNotification = null; |
| 356 } | 364 } |
| 357 | 365 |
| 358 // Chrome on Linux does not fully support chrome.notifications until version 35 | 366 function initChromeNotifications() |
|
Felix Dahlke
2014/03/28 13:10:41
Since this is executed immediately, I would have e
Thomas Greiner
2014/03/28 15:57:08
Done.
| |
| 359 // https://code.google.com/p/chromium/issues/detail?id=291485 | 367 { |
| 360 var canUseChromeNotifications = (require("info").platform == "chromium" && "noti fications" in chrome && (navigator.platform.indexOf("Linux") == -1 || parseInt(r equire("info").applicationVersion) > 34)); | |
|
Felix Dahlke
2014/03/28 13:10:41
The outer parentheses are redundant here. And I'd
Thomas Greiner
2014/03/28 15:57:08
Done.
| |
| 361 if (canUseChromeNotifications) | |
| 362 { | |
| 363 chrome.notifications.onButtonClicked.addListener(notificationButtonClick); | |
| 364 chrome.notifications.onClosed.addListener(notificationClosed); | |
| 365 // Chrome hides notifications in notification center when clicked so we need t o close them | 368 // Chrome hides notifications in notification center when clicked so we need t o close them |
| 366 chrome.notifications.onClicked.addListener(function(id, callback) | 369 function clearActiveNotification(notificationId) |
| 367 { | 370 { |
| 368 chrome.notifications.clear(id, function(wasCleared) | 371 if (activeNotification && activeNotification.type != "question") |
|
Felix Dahlke
2014/03/28 16:16:39
Why check for the notification type here? Seems to
Thomas Greiner
2014/03/28 17:26:51
What this function does is remove the notification
Felix Dahlke
2014/03/28 17:33:46
Ah, no I get it. No it's fine let's go with 2 if y
Thomas Greiner
2014/03/28 18:23:17
For completeness' sake, what I meant for (2) was:
| |
| 372 return; | |
| 373 | |
| 374 chrome.notifications.clear(notificationId, function(wasCleared) | |
| 369 { | 375 { |
| 370 if (wasCleared) | 376 if (wasCleared) |
| 371 notificationClosed(); | 377 notificationClosed(); |
| 372 }); | 378 }); |
| 379 } | |
| 380 | |
| 381 chrome.notifications.onButtonClicked.addListener(function(notificationId, butt onIndex) | |
| 382 { | |
| 383 notificationButtonClick(buttonIndex); | |
| 384 clearActiveNotification(notificationId); | |
|
Thomas Greiner
2014/03/28 15:57:08
I noticed that even notifications that were dismis
| |
| 373 }); | 385 }); |
| 386 chrome.notifications.onClicked.addListener(clearActiveNotification); | |
| 387 chrome.notifications.onClosed.addListener(notificationClosed); | |
| 374 } | 388 } |
| 375 | 389 |
| 376 function showNotification(notification) | 390 function showNotification(notification) |
| 377 { | 391 { |
| 378 if (activeNotification && activeNotification.id === notification.id) | 392 if (activeNotification && activeNotification.id === notification.id) |
| 379 return; | 393 return; |
| 380 | 394 |
| 381 activeNotification = notification; | 395 activeNotification = notification; |
| 382 if (activeNotification.type === "critical" || activeNotification.type === "que stion") | 396 if (activeNotification.type === "critical" || activeNotification.type === "que stion") |
| 383 { | 397 { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 tab.sendMessage({type: "clickhide-deactivate"}); | 562 tab.sendMessage({type: "clickhide-deactivate"}); |
| 549 refreshIconAndContextMenu(tab); | 563 refreshIconAndContextMenu(tab); |
| 550 }); | 564 }); |
| 551 | 565 |
| 552 setTimeout(function() | 566 setTimeout(function() |
| 553 { | 567 { |
| 554 var notificationToShow = Notification.getNextToShow(); | 568 var notificationToShow = Notification.getNextToShow(); |
| 555 if (notificationToShow) | 569 if (notificationToShow) |
| 556 showNotification(notificationToShow); | 570 showNotification(notificationToShow); |
| 557 }, 3 * 60 * 1000); | 571 }, 3 * 60 * 1000); |
| LEFT | RIGHT |