| 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 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 } | 344 } |
| 345 else if (activeNotification.links && activeNotification.links[index]) | 345 else if (activeNotification.links && activeNotification.links[index]) |
| 346 { | 346 { |
| 347 ext.windows.getLastFocused(function(win) | 347 ext.windows.getLastFocused(function(win) |
| 348 { | 348 { |
| 349 win.openTab(Utils.getDocLink(activeNotification.links[index])); | 349 win.openTab(Utils.getDocLink(activeNotification.links[index])); |
| 350 }); | 350 }); |
| 351 } | 351 } |
| 352 } | 352 } |
| 353 | 353 |
| 354 function imgToBase64(url, callback) | |
| 355 { | |
| 356 var canvas = document.createElement("CANVAS"), | |
|
Wladimir Palant
2014/03/28 14:18:29
Nit: document.createElement("canvas") please (lowe
saroyanm
2014/03/28 15:16:02
Done.
| |
| 357 ctx = canvas.getContext("2d"), | |
| 358 img = new Image; | |
| 359 img.src = url; | |
| 360 img.onload = function() | |
| 361 { | |
| 362 canvas.height = img.height; | |
| 363 canvas.width = img.width; | |
| 364 ctx.drawImage(img, 0, 0); | |
| 365 callback(canvas.toDataURL("image/png")); | |
| 366 canvas = null; | |
| 367 }; | |
| 368 } | |
| 369 | |
| 354 function showNotification(notification) | 370 function showNotification(notification) |
| 355 { | 371 { |
| 356 if (activeNotification && activeNotification.id === notification.id) | 372 if (activeNotification && activeNotification.id === notification.id) |
| 357 return; | 373 return; |
| 358 | 374 |
| 359 activeNotification = notification; | 375 activeNotification = notification; |
| 360 if (activeNotification.type === "critical" || activeNotification.type === "que stion") | 376 if (activeNotification.type === "critical" || activeNotification.type === "que stion") |
| 361 { | 377 { |
| 362 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; | 378 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; |
| 363 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) | 379 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 375 var hasLinks = activeNotification.links && activeNotification.links.length > 0; | 391 var hasLinks = activeNotification.links && activeNotification.links.length > 0; |
| 376 | 392 |
| 377 // Chrome on Linux does not fully support chrome.notifications yet | 393 // Chrome on Linux does not fully support chrome.notifications yet |
| 378 // https://code.google.com/p/chromium/issues/detail?id=291485 | 394 // 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) | 395 if (require("info").platform == "chromium" && "notifications" in chrome && n avigator.platform.indexOf("Linux") == -1) |
| 380 { | 396 { |
| 381 var opts = { | 397 var opts = { |
| 382 type: "basic", | 398 type: "basic", |
| 383 title: title, | 399 title: title, |
| 384 message: message, | 400 message: message, |
| 385 iconUrl: iconUrl, | |
| 386 buttons: [], | 401 buttons: [], |
| 387 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically | 402 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically |
| 388 }; | 403 }; |
| 389 if (activeNotification.type === "question") | 404 if (activeNotification.type === "question") |
| 390 { | 405 { |
| 391 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_yes")}); | 406 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")}); | 407 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_no")}); |
| 393 } | 408 } |
| 394 else | 409 else |
| 395 { | 410 { |
| 396 var regex = /<a>(.*?)<\/a>/g; | 411 var regex = /<a>(.*?)<\/a>/g; |
| 397 var plainMessage = texts.message || ""; | 412 var plainMessage = texts.message || ""; |
| 398 var match; | 413 var match; |
| 399 while (match = regex.exec(plainMessage)) | 414 while (match = regex.exec(plainMessage)) |
| 400 opts.buttons.push({title: match[1]}); | 415 opts.buttons.push({title: match[1]}); |
| 401 } | 416 } |
| 402 | 417 |
| 403 chrome.notifications.create("", opts, function() {}); | 418 imgToBase64(iconUrl, function(iconData) |
| 404 chrome.notifications.onButtonClicked.addListener(notificationButtonClick); | 419 { |
| 420 opts["iconUrl"] = iconData; | |
| 421 chrome.notifications.create("", opts, function() {}); | |
| 422 chrome.notifications.onButtonClicked.addListener(notificationButtonClick ); | |
| 423 }); | |
| 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 imgToBase64(iconUrl, function(iconData) |
| 412 notification.show(); | 431 { |
| 413 notification.addEventListener("click", openNotificationLinks, false); | 432 var notification = webkitNotifications.createNotification(iconData, titl e, message); |
| 433 notification.show(); | |
| 434 notification.addEventListener("click", openNotificationLinks, false); | |
| 435 }); | |
| 414 } | 436 } |
| 415 else | 437 else |
| 416 { | 438 { |
| 417 var message = title + "\n" + message; | 439 var message = title + "\n" + message; |
| 418 if (hasLinks) | 440 if (hasLinks) |
| 419 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); | 441 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); |
| 420 | 442 |
| 421 var approved = confirm(message); | 443 var approved = confirm(message); |
| 422 if (activeNotification.type === "question") | 444 if (activeNotification.type === "question") |
| 423 notificationButtonClick(null, approved ? 0 : 1); | 445 notificationButtonClick(null, approved ? 0 : 1); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 tab.sendMessage({type: "clickhide-deactivate"}); | 550 tab.sendMessage({type: "clickhide-deactivate"}); |
| 529 refreshIconAndContextMenu(tab); | 551 refreshIconAndContextMenu(tab); |
| 530 }); | 552 }); |
| 531 | 553 |
| 532 setTimeout(function() | 554 setTimeout(function() |
| 533 { | 555 { |
| 534 var notificationToShow = Notification.getNextToShow(); | 556 var notificationToShow = Notification.getNextToShow(); |
| 535 if (notificationToShow) | 557 if (notificationToShow) |
| 536 showNotification(notificationToShow); | 558 showNotification(notificationToShow); |
| 537 }, 3 * 60 * 1000); | 559 }, 3 * 60 * 1000); |
| OLD | NEW |