| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 with(require("filterClasses")) | 18 with(require("filterClasses")) |
| 19 { | 19 { |
| 20 this.Filter = Filter; | 20 this.Filter = Filter; |
| 21 this.ActiveFilter = ActiveFilter; | |
| 22 this.RegExpFilter = RegExpFilter; | 21 this.RegExpFilter = RegExpFilter; |
| 23 this.BlockingFilter = BlockingFilter; | 22 this.BlockingFilter = BlockingFilter; |
| 24 this.WhitelistFilter = WhitelistFilter; | 23 this.WhitelistFilter = WhitelistFilter; |
| 25 } | 24 } |
| 26 with(require("subscriptionClasses")) | 25 with(require("subscriptionClasses")) |
| 27 { | 26 { |
| 28 this.Subscription = Subscription; | 27 this.Subscription = Subscription; |
| 29 this.DownloadableSubscription = DownloadableSubscription; | 28 this.DownloadableSubscription = DownloadableSubscription; |
| 30 } | 29 } |
| 31 with(require("whitelisting")) | 30 with(require("whitelisting")) |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 } | 343 } |
| 345 else if (activeNotification.links && activeNotification.links[index]) | 344 else if (activeNotification.links && activeNotification.links[index]) |
| 346 { | 345 { |
| 347 ext.windows.getLastFocused(function(win) | 346 ext.windows.getLastFocused(function(win) |
| 348 { | 347 { |
| 349 win.openTab(Utils.getDocLink(activeNotification.links[index])); | 348 win.openTab(Utils.getDocLink(activeNotification.links[index])); |
| 350 }); | 349 }); |
| 351 } | 350 } |
| 352 } | 351 } |
| 353 | 352 |
| 353 function notificationClosed() | |
| 354 { | |
| 355 activeNotification = null; | |
| 356 } | |
| 357 | |
| 358 // Chrome on Linux does not fully support chrome.notifications until version 35 | |
|
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 | |
| 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 | |
| 366 chrome.notifications.onClicked.addListener(function(id, callback) | |
| 367 { | |
| 368 chrome.notifications.clear(id, function(wasCleared) | |
| 369 { | |
| 370 if (wasCleared) | |
| 371 notificationClosed(); | |
| 372 }); | |
| 373 }); | |
| 374 } | |
| 375 | |
| 354 function showNotification(notification) | 376 function showNotification(notification) |
| 355 { | 377 { |
| 356 if (activeNotification && activeNotification.id === notification.id) | 378 if (activeNotification && activeNotification.id === notification.id) |
| 357 return; | 379 return; |
| 358 | 380 |
| 359 activeNotification = notification; | 381 activeNotification = notification; |
| 360 if (activeNotification.type === "critical" || activeNotification.type === "que stion") | 382 if (activeNotification.type === "critical" || activeNotification.type === "que stion") |
| 361 { | 383 { |
| 362 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; | 384 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; |
| 363 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) | 385 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) |
| 364 { | 386 { |
| 365 var notification = webkitNotifications.createHTMLNotification("notificatio n.html"); | 387 var notification = webkitNotifications.createHTMLNotification("notificatio n.html"); |
| 366 notification.show(); | 388 notification.show(); |
| 367 prepareNotificationIconAndPopup(); | 389 prepareNotificationIconAndPopup(); |
| 368 return; | 390 return; |
| 369 } | 391 } |
| 370 | 392 |
| 371 var texts = Notification.getLocalizedTexts(notification); | 393 var texts = Notification.getLocalizedTexts(notification); |
| 372 var title = texts.title || ""; | 394 var title = texts.title || ""; |
| 373 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; | 395 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
| 374 var iconUrl = ext.getURL("icons/abp-128.png"); | 396 var iconUrl = ext.getURL("icons/abp-128.png"); |
| 375 var hasLinks = activeNotification.links && activeNotification.links.length > 0; | 397 var hasLinks = activeNotification.links && activeNotification.links.length > 0; |
| 376 | 398 |
| 377 // Chrome on Linux does not fully support chrome.notifications yet | 399 if (canUseChromeNotifications) |
| 378 // https://code.google.com/p/chromium/issues/detail?id=291485 | |
| 379 if (require("info").platform == "chromium" && "notifications" in chrome && n avigator.platform.indexOf("Linux") == -1) | |
| 380 { | 400 { |
| 381 var opts = { | 401 var opts = { |
| 382 type: "basic", | 402 type: "basic", |
| 383 title: title, | 403 title: title, |
| 384 message: message, | 404 message: message, |
| 385 iconUrl: iconUrl, | 405 iconUrl: iconUrl, |
| 386 buttons: [], | 406 buttons: [], |
| 387 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically | 407 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically |
| 388 }; | 408 }; |
| 389 if (activeNotification.type === "question") | 409 if (activeNotification.type === "question") |
| 390 { | 410 { |
| 391 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_yes")}); | 411 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_yes")}); |
| 392 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_no")}); | 412 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_no")}); |
| 393 } | 413 } |
| 394 else | 414 else |
| 395 { | 415 { |
| 396 var regex = /<a>(.*?)<\/a>/g; | 416 var regex = /<a>(.*?)<\/a>/g; |
| 397 var plainMessage = texts.message || ""; | 417 var plainMessage = texts.message || ""; |
| 398 var match; | 418 var match; |
| 399 while (match = regex.exec(plainMessage)) | 419 while (match = regex.exec(plainMessage)) |
| 400 opts.buttons.push({title: match[1]}); | 420 opts.buttons.push({title: match[1]}); |
| 401 } | 421 } |
| 402 | 422 |
| 403 chrome.notifications.create("", opts, function() {}); | 423 chrome.notifications.create("", opts, function() {}); |
| 404 chrome.notifications.onButtonClicked.addListener(notificationButtonClick); | |
| 405 } | 424 } |
| 406 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns && activeNotification.type !== "question") | 425 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns && activeNotification.type !== "question") |
| 407 { | 426 { |
| 408 if (hasLinks) | 427 if (hasLinks) |
| 409 message += " " + ext.i18n.getMessage("notification_without_buttons"); | 428 message += " " + ext.i18n.getMessage("notification_without_buttons"); |
| 410 | 429 |
| 411 var notification = webkitNotifications.createNotification(iconUrl, title, message); | 430 var notification = webkitNotifications.createNotification(iconUrl, title, message); |
| 412 notification.show(); | 431 notification.show(); |
| 413 notification.addEventListener("click", openNotificationLinks, false); | 432 notification.addEventListener("click", openNotificationLinks, false); |
| 433 notification.addEventListener("close", notificationClosed, false); | |
| 414 } | 434 } |
| 415 else | 435 else |
| 416 { | 436 { |
| 417 var message = title + "\n" + message; | 437 var message = title + "\n" + message; |
| 418 if (hasLinks) | 438 if (hasLinks) |
| 419 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); | 439 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); |
| 420 | 440 |
| 421 var approved = confirm(message); | 441 var approved = confirm(message); |
| 422 if (activeNotification.type === "question") | 442 if (activeNotification.type === "question") |
| 423 notificationButtonClick(null, approved ? 0 : 1); | 443 notificationButtonClick(null, approved ? 0 : 1); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 tab.sendMessage({type: "clickhide-deactivate"}); | 548 tab.sendMessage({type: "clickhide-deactivate"}); |
| 529 refreshIconAndContextMenu(tab); | 549 refreshIconAndContextMenu(tab); |
| 530 }); | 550 }); |
| 531 | 551 |
| 532 setTimeout(function() | 552 setTimeout(function() |
| 533 { | 553 { |
| 534 var notificationToShow = Notification.getNextToShow(); | 554 var notificationToShow = Notification.getNextToShow(); |
| 535 if (notificationToShow) | 555 if (notificationToShow) |
| 536 showNotification(notificationToShow); | 556 showNotification(notificationToShow); |
| 537 }, 3 * 60 * 1000); | 557 }, 3 * 60 * 1000); |
| OLD | NEW |