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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 // Some types cannot be distinguished | 52 // Some types cannot be distinguished |
53 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; | 53 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; |
54 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; | 54 RegExpFilter.typeMap.MEDIA = RegExpFilter.typeMap.FONT = RegExpFilter.typeMap.OT HER; |
55 | 55 |
56 // Chrome on Linux does not fully support chrome.notifications until version 35 | 56 // Chrome on Linux does not fully support chrome.notifications until version 35 |
57 // https://code.google.com/p/chromium/issues/detail?id=291485 | 57 // https://code.google.com/p/chromium/issues/detail?id=291485 |
58 var canUseChromeNotifications = require("info").platform == "chromium" | 58 var canUseChromeNotifications = require("info").platform == "chromium" |
59 && "notifications" in chrome | 59 && "notifications" in chrome |
60 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion) > 34); | 60 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion) > 34); |
61 | 61 |
62 var isFirstRun = false; | |
63 var seenDataCorruption = false; | 62 var seenDataCorruption = false; |
64 require("filterNotifier").FilterNotifier.addListener(function(action) | 63 require("filterNotifier").FilterNotifier.addListener(function(action) |
65 { | 64 { |
66 if (action == "load") | 65 if (action == "load") |
67 { | 66 { |
68 var importingOldData = importOldData(); | 67 var importingOldData = importOldData(); |
Thomas Greiner
2014/04/15 12:53:07
Since we can now distinguish first-run from update
Wladimir Palant
2014/04/15 13:31:53
I'd rather not polish this code, it isn't worth th
| |
69 | 68 |
70 var addonVersion = require("info").addonVersion; | 69 var addonVersion = require("info").addonVersion; |
71 var prevVersion = ext.storage.currentVersion; | 70 var prevVersion = ext.storage.currentVersion; |
72 if (prevVersion != addonVersion) | 71 if (prevVersion != addonVersion || FilterStorage.firstRun) |
73 { | 72 { |
74 isFirstRun = !prevVersion; | 73 seenDataCorruption = prevVersion && FilterStorage.firstRun; |
75 ext.storage.currentVersion = addonVersion; | 74 ext.storage.currentVersion = addonVersion; |
76 if (!importingOldData) | 75 if (!importingOldData) |
77 addSubscription(prevVersion); | 76 addSubscription(prevVersion); |
78 } | 77 } |
79 | 78 |
80 if (canUseChromeNotifications) | 79 if (canUseChromeNotifications) |
81 initChromeNotifications(); | 80 initChromeNotifications(); |
82 initAntiAdblockNotification(); | 81 initAntiAdblockNotification(); |
83 } | 82 } |
84 | 83 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 activeNotification.onClicked = function() | 313 activeNotification.onClicked = function() |
315 { | 314 { |
316 if (animateIcon) | 315 if (animateIcon) |
317 iconAnimation.stop(); | 316 iconAnimation.stop(); |
318 notificationClosed(); | 317 notificationClosed(); |
319 }; | 318 }; |
320 if (animateIcon) | 319 if (animateIcon) |
321 iconAnimation.update(activeNotification.type); | 320 iconAnimation.update(activeNotification.type); |
322 } | 321 } |
323 | 322 |
324 function openNotificationLinks() | 323 function openNotificationLinks() |
325 { | 324 { |
326 if (activeNotification.links) | 325 if (activeNotification.links) |
327 { | 326 { |
328 activeNotification.links.forEach(function(link) | 327 activeNotification.links.forEach(function(link) |
329 { | 328 { |
330 ext.windows.getLastFocused(function(win) | 329 ext.windows.getLastFocused(function(win) |
331 { | 330 { |
332 win.openTab(Utils.getDocLink(link)); | 331 win.openTab(Utils.getDocLink(link)); |
333 }); | 332 }); |
334 }); | 333 }); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 clearActiveNotification(notificationId); | 393 clearActiveNotification(notificationId); |
395 }); | 394 }); |
396 chrome.notifications.onClicked.addListener(clearActiveNotification); | 395 chrome.notifications.onClicked.addListener(clearActiveNotification); |
397 chrome.notifications.onClosed.addListener(notificationClosed); | 396 chrome.notifications.onClosed.addListener(notificationClosed); |
398 } | 397 } |
399 | 398 |
400 function showNotification(notification) | 399 function showNotification(notification) |
401 { | 400 { |
402 if (activeNotification && activeNotification.id === notification.id) | 401 if (activeNotification && activeNotification.id === notification.id) |
403 return; | 402 return; |
404 | 403 |
405 activeNotification = notification; | 404 activeNotification = notification; |
406 if (activeNotification.type === "critical" || activeNotification.type === "que stion") | 405 if (activeNotification.type === "critical" || activeNotification.type === "que stion") |
407 { | 406 { |
408 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; | 407 var hasWebkitNotifications = typeof webkitNotifications !== "undefined"; |
409 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) | 408 if (hasWebkitNotifications && "createHTMLNotification" in webkitNotification s) |
410 { | 409 { |
411 var notification = webkitNotifications.createHTMLNotification("notificatio n.html"); | 410 var notification = webkitNotifications.createHTMLNotification("notificatio n.html"); |
412 notification.show(); | 411 notification.show(); |
413 prepareNotificationIconAndPopup(); | 412 prepareNotificationIconAndPopup(); |
414 return; | 413 return; |
415 } | 414 } |
416 | 415 |
417 var texts = Notification.getLocalizedTexts(notification); | 416 var texts = Notification.getLocalizedTexts(notification); |
418 var title = texts.title || ""; | 417 var title = texts.title || ""; |
419 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; | 418 var message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
420 var iconUrl = ext.getURL("icons/abp-128.png"); | 419 var iconUrl = ext.getURL("icons/abp-128.png"); |
421 var hasLinks = activeNotification.links && activeNotification.links.length > 0; | 420 var hasLinks = activeNotification.links && activeNotification.links.length > 0; |
422 | 421 |
423 if (canUseChromeNotifications) | 422 if (canUseChromeNotifications) |
424 { | 423 { |
425 var opts = { | 424 var opts = { |
426 type: "basic", | 425 type: "basic", |
427 title: title, | 426 title: title, |
428 message: message, | 427 message: message, |
429 buttons: [], | 428 buttons: [], |
430 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically | 429 priority: 2 // We use the highest priority to prevent the notification f rom closing automatically |
431 }; | 430 }; |
432 if (activeNotification.type === "question") | 431 if (activeNotification.type === "question") |
433 { | 432 { |
434 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_yes")}); | 433 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_yes")}); |
435 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_no")}); | 434 opts.buttons.push({title: ext.i18n.getMessage("overlay_notification_butt on_no")}); |
436 } | 435 } |
437 else | 436 else |
438 { | 437 { |
439 var regex = /<a>(.*?)<\/a>/g; | 438 var regex = /<a>(.*?)<\/a>/g; |
440 var plainMessage = texts.message || ""; | 439 var plainMessage = texts.message || ""; |
441 var match; | 440 var match; |
442 while (match = regex.exec(plainMessage)) | 441 while (match = regex.exec(plainMessage)) |
443 opts.buttons.push({title: match[1]}); | 442 opts.buttons.push({title: match[1]}); |
444 } | 443 } |
445 | 444 |
446 imgToBase64(iconUrl, function(iconData) | 445 imgToBase64(iconUrl, function(iconData) |
447 { | 446 { |
448 opts["iconUrl"] = iconData; | 447 opts["iconUrl"] = iconData; |
449 chrome.notifications.create("", opts, function() {}); | 448 chrome.notifications.create("", opts, function() {}); |
450 }); | 449 }); |
451 } | 450 } |
452 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns && activeNotification.type !== "question") | 451 else if (hasWebkitNotifications && "createNotification" in webkitNotificatio ns && activeNotification.type !== "question") |
453 { | 452 { |
454 if (hasLinks) | 453 if (hasLinks) |
455 message += " " + ext.i18n.getMessage("notification_without_buttons"); | 454 message += " " + ext.i18n.getMessage("notification_without_buttons"); |
456 | 455 |
457 imgToBase64(iconUrl, function(iconData) | 456 imgToBase64(iconUrl, function(iconData) |
458 { | 457 { |
459 var notification = webkitNotifications.createNotification(iconData, titl e, message); | 458 var notification = webkitNotifications.createNotification(iconData, titl e, message); |
460 notification.show(); | 459 notification.show(); |
461 notification.addEventListener("click", openNotificationLinks, false); | 460 notification.addEventListener("click", openNotificationLinks, false); |
462 notification.addEventListener("close", notificationClosed, false); | 461 notification.addEventListener("close", notificationClosed, false); |
463 }); | 462 }); |
464 } | 463 } |
465 else | 464 else |
466 { | 465 { |
467 var message = title + "\n" + message; | 466 var message = title + "\n" + message; |
468 if (hasLinks) | 467 if (hasLinks) |
469 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); | 468 message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); |
470 | 469 |
471 var approved = confirm(message); | 470 var approved = confirm(message); |
472 if (activeNotification.type === "question") | 471 if (activeNotification.type === "question") |
473 notificationButtonClick(approved ? 0 : 1); | 472 notificationButtonClick(approved ? 0 : 1); |
474 else if (approved) | 473 else if (approved) |
475 openNotificationLinks(); | 474 openNotificationLinks(); |
476 } | 475 } |
477 } | 476 } |
478 prepareNotificationIconAndPopup(); | 477 prepareNotificationIconAndPopup(); |
479 } | 478 } |
480 | 479 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 page.sendMessage({type: "clickhide-deactivate"}); | 577 page.sendMessage({type: "clickhide-deactivate"}); |
579 refreshIconAndContextMenu(page); | 578 refreshIconAndContextMenu(page); |
580 }); | 579 }); |
581 | 580 |
582 setTimeout(function() | 581 setTimeout(function() |
583 { | 582 { |
584 var notificationToShow = Notification.getNextToShow(); | 583 var notificationToShow = Notification.getNextToShow(); |
585 if (notificationToShow) | 584 if (notificationToShow) |
586 showNotification(notificationToShow); | 585 showNotification(notificationToShow); |
587 }, 3 * 60 * 1000); | 586 }, 3 * 60 * 1000); |
OLD | NEW |