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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 | 391 |
392 if (this.overlay.all.length) | 392 if (this.overlay.all.length) |
393 this.overlay.all[0].appendChild(menuSource); | 393 this.overlay.all[0].appendChild(menuSource); |
394 if ("abp-toolbarbutton" in this.overlay) | 394 if ("abp-toolbarbutton" in this.overlay) |
395 this.overlay["abp-toolbarbutton"].appendChild(fixId(menuSource.cloneNode (true), "abp-toolbar")); | 395 this.overlay["abp-toolbarbutton"].appendChild(fixId(menuSource.cloneNode (true), "abp-toolbar")); |
396 if ("abp-menuitem" in this.overlay) | 396 if ("abp-menuitem" in this.overlay) |
397 this.overlay["abp-menuitem"].appendChild(fixId(menuSource.cloneNode(true ), "abp-menuitem")); | 397 this.overlay["abp-menuitem"].appendChild(fixId(menuSource.cloneNode(true ), "abp-menuitem")); |
398 } | 398 } |
399 }, | 399 }, |
400 | 400 |
401 initAntiAdblockNotification: function() | 401 _initAntiAdblockNotification: function() |
Felix Dahlke
2014/02/12 15:09:27
Shouldn't this be "private"?
Thomas Greiner
2014/02/12 18:28:02
Done.
| |
402 { | 402 { |
403 let notification = { | 403 let notification = { |
Felix Dahlke
2014/02/12 15:09:27
I think we should move this into addAntiAdblockNot
Thomas Greiner
2014/02/12 18:28:02
No, it's also used to remove the notification (see
Felix Dahlke
2014/02/13 10:22:04
Oh, right.
| |
404 id: "antiadblock", | 404 id: "antiadblock", |
405 severity: "question", | 405 type: "question", |
406 title: Utils.getString("notification_antiadblock_title"), | 406 title: Utils.getString("notification_antiadblock_title"), |
407 message: Utils.getString("notification_antiadblock_message"), | 407 message: Utils.getString("notification_antiadblock_message"), |
408 urlFilters: [] | 408 urlFilters: [] |
409 }; | 409 }; |
410 | |
411 function notificationListener(approved) | |
412 { | |
413 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl ); | |
414 if (subscription.url in FilterStorage.knownSubscriptions) | |
415 subscription.disabled = !approved; | |
416 } | |
410 | 417 |
411 function addAntiAdblockNotification(subscription) | 418 function addAntiAdblockNotification(subscription) |
412 { | 419 { |
413 let urlFilters = []; | 420 let urlFilters = []; |
414 for each (let filter in subscription.filters) | 421 for each (let filter in subscription.filters) |
415 if (filter instanceof ActiveFilter) | 422 if (filter instanceof ActiveFilter) |
416 for (let domain in filter.domains) | 423 for (let domain in filter.domains) |
417 if (domain && urlFilters.indexOf(domain) == -1) | 424 if (domain && urlFilters.indexOf(domain) == -1) |
418 urlFilters.push(domain); | 425 urlFilters.push(domain); |
419 notification.urlFilters = urlFilters; | 426 notification.urlFilters = urlFilters; |
420 Notification.addNotification(notification); | 427 Notification.addNotification(notification); |
428 Notification.addQuestionListener(notification.id, notificationListener); | |
429 } | |
430 | |
431 function removeAntiAdblockNotification() | |
432 { | |
433 Notification.removeNotification(notification); | |
434 Notification.removeQuestionListener(notification.id, notificationListener) ; | |
421 } | 435 } |
422 | 436 |
423 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); | 437 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); |
424 if (subscription.lastDownload && subscription.disabled) | 438 if (subscription.lastDownload && subscription.disabled) |
425 { | |
426 addAntiAdblockNotification(subscription); | 439 addAntiAdblockNotification(subscription); |
427 } | |
428 | |
429 function notificationListener(id, approved) | |
430 { | |
431 if (id !== notification.id) | |
432 return; | |
433 | |
434 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl ); | |
435 if (subscription.url in FilterStorage.knownSubscriptions) | |
436 subscription.disabled = !approved; | |
437 } | |
438 Notification.addListener(notificationListener); | |
439 | 440 |
440 FilterNotifier.addListener(function(action, value, newItem, oldItem) | 441 FilterNotifier.addListener(function(action, value, newItem, oldItem) |
441 { | 442 { |
442 if (!/^subscription\.(updated|removed|disabled)$/.test(action) || value.ur l != Prefs.subscriptions_antiadblockurl) | 443 if (!/^subscription\.(updated|removed|disabled)$/.test(action) || value.ur l != Prefs.subscriptions_antiadblockurl) |
443 return; | 444 return; |
444 | 445 |
445 if (action == "subscription.updated") | 446 if (action == "subscription.updated") |
446 addAntiAdblockNotification(value); | 447 addAntiAdblockNotification(value); |
447 else if (action == "subscription.removed" || (action == "subscription.disa bled" && !value.disabled)) | 448 else if (action == "subscription.removed" || (action == "subscription.disa bled" && !value.disabled)) |
448 { | 449 removeAntiAdblockNotification(); |
449 Notification.removeNotification(notification); | |
450 } | |
451 }); | 450 }); |
452 | 451 |
453 var documentCreationObserver = { | 452 var documentCreationObserver = { |
454 observe: function(subject, topic, data) | 453 observe: function(subject, topic, data) |
455 { | 454 { |
456 if (!(subject instanceof Ci.nsIDOMWindow)) | 455 if (!(subject instanceof Ci.nsIDOMWindow)) |
457 return; | 456 return; |
458 | 457 |
459 this._showNextNotification(subject.location.href); | 458 this._showNextNotification(subject.location.href); |
460 }.bind(this) | 459 }.bind(this) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton")); | 591 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton")); |
593 }.bind(this)); | 592 }.bind(this)); |
594 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); | 593 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); |
595 | 594 |
596 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event) | 595 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event) |
597 { | 596 { |
598 window.document.getElementById("abp-notification").hidePopup(); | 597 window.document.getElementById("abp-notification").hidePopup(); |
599 }, false); | 598 }, false); |
600 | 599 |
601 // Add "anti-adblock messages" notification | 600 // Add "anti-adblock messages" notification |
602 this.initAntiAdblockNotification(); | 601 this._initAntiAdblockNotification(); |
603 | 602 |
604 // First-run actions? | 603 // First-run actions? |
605 if (!this.firstRunDone) | 604 if (!this.firstRunDone) |
606 { | 605 { |
607 this.firstRunDone = true; | 606 this.firstRunDone = true; |
608 | 607 |
609 let {addonVersion} = require("info"); | 608 let {addonVersion} = require("info"); |
610 let prevVersion = Prefs.currentVersion; | 609 let prevVersion = Prefs.currentVersion; |
611 if (prevVersion != addonVersion) | 610 if (prevVersion != addonVersion) |
612 { | 611 { |
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1912 let link = event.target; | 1911 let link = event.target; |
1913 while (link && link !== messageElement && link.localName !== "a") | 1912 while (link && link !== messageElement && link.localName !== "a") |
1914 link = link.parentNode; | 1913 link = link.parentNode; |
1915 if (!link || link.localName !== "a") | 1914 if (!link || link.localName !== "a") |
1916 return; | 1915 return; |
1917 event.preventDefault(); | 1916 event.preventDefault(); |
1918 event.stopPropagation(); | 1917 event.stopPropagation(); |
1919 this.loadInBrowser(link.href, window); | 1918 this.loadInBrowser(link.href, window); |
1920 }.bind(this)); | 1919 }.bind(this)); |
1921 | 1920 |
1922 if (notification.severity === "question") | 1921 if (notification.type === "question") |
1923 { | 1922 { |
1924 function buttonHandler(approved, event) | 1923 function buttonHandler(approved, event) |
1925 { | 1924 { |
1926 event.preventDefault(); | 1925 event.preventDefault(); |
1927 event.stopPropagation(); | 1926 event.stopPropagation(); |
1928 panel.hidePopup(); | 1927 panel.hidePopup(); |
1929 Notification.triggerListeners(notification.id, approved) | 1928 Notification.triggerQuestionListeners(notification.id, approved) |
1930 Notification.markAsShown(notification.id); | 1929 Notification.markAsShown(notification.id); |
1931 } | 1930 } |
1932 window.document.getElementById("abp-notification-yes").onclick = buttonHan dler.bind(null, true); | 1931 window.document.getElementById("abp-notification-yes").onclick = buttonHan dler.bind(null, true); |
1933 window.document.getElementById("abp-notification-no").onclick = buttonHand ler.bind(null, false); | 1932 window.document.getElementById("abp-notification-no").onclick = buttonHand ler.bind(null, false); |
1934 } | 1933 } |
1935 | 1934 |
1936 panel.setAttribute("class", "abp-" + notification.severity); | 1935 panel.setAttribute("class", "abp-" + notification.type); |
1937 panel.setAttribute("noautohide", notification.severity === "question"); | 1936 panel.setAttribute("noautohide", notification.type === "question"); |
1938 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); | 1937 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); |
1939 } | 1938 } |
1940 }; | 1939 }; |
1941 UI.onPopupShowing = UI.onPopupShowing.bind(UI); | 1940 UI.onPopupShowing = UI.onPopupShowing.bind(UI); |
1942 UI.onKeyPress = UI.onKeyPress.bind(UI); | 1941 UI.onKeyPress = UI.onKeyPress.bind(UI); |
1943 UI.onIconClick = UI.onIconClick.bind(UI); | 1942 UI.onIconClick = UI.onIconClick.bind(UI); |
1944 UI.init(); | 1943 UI.init(); |
1945 | 1944 |
1946 /** | 1945 /** |
1947 * List of event handers to be registered for each window. For each event | 1946 * List of event handers to be registered for each window. For each event |
(...skipping 16 matching lines...) Expand all Loading... | |
1964 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], | 1963 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], |
1965 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] | 1964 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] |
1966 ]; | 1965 ]; |
1967 | 1966 |
1968 onShutdown.add(function() | 1967 onShutdown.add(function() |
1969 { | 1968 { |
1970 for (let window in UI.applicationWindows) | 1969 for (let window in UI.applicationWindows) |
1971 if (UI.isBottombarOpen(window)) | 1970 if (UI.isBottombarOpen(window)) |
1972 UI.toggleBottombar(window); | 1971 UI.toggleBottombar(window); |
1973 }); | 1972 }); |
LEFT | RIGHT |