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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 let menuSource = this.overlay["abp-status-popup"]; | 389 let menuSource = this.overlay["abp-status-popup"]; |
390 delete this.overlay["abp-status-popup"]; | 390 delete this.overlay["abp-status-popup"]; |
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 }, | |
400 | |
401 _initAntiAdblockNotification: function() | |
402 { | |
403 let notification = { | |
404 id: "antiadblock", | |
405 type: "question", | |
406 title: Utils.getString("notification_antiadblock_title"), | |
407 message: Utils.getString("notification_antiadblock_message"), | |
408 urlFilters: [] | |
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 } | |
417 | |
418 function addAntiAdblockNotification(subscription) | |
419 { | |
420 let urlFilters = []; | |
421 for each (let filter in subscription.filters) | |
422 if (filter instanceof ActiveFilter) | |
423 for (let domain in filter.domains) | |
424 if (domain && urlFilters.indexOf(domain) == -1) | |
425 urlFilters.push(domain); | |
426 notification.urlFilters = urlFilters; | |
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) ; | |
435 } | |
436 | |
437 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); | |
438 if (subscription.lastDownload && subscription.disabled) | |
439 addAntiAdblockNotification(subscription); | |
440 | |
441 FilterNotifier.addListener(function(action, value, newItem, oldItem) | |
442 { | |
443 if (!/^subscription\.(updated|removed|disabled)$/.test(action) || value.ur l != Prefs.subscriptions_antiadblockurl) | |
444 return; | |
445 | |
446 if (action == "subscription.updated") | |
447 addAntiAdblockNotification(value); | |
448 else if (action == "subscription.removed" || (action == "subscription.disa bled" && !value.disabled)) | |
449 removeAntiAdblockNotification(); | |
450 }); | |
451 | |
452 var documentCreationObserver = { | |
453 observe: function(subject, topic, data) | |
454 { | |
455 if (!(subject instanceof Ci.nsIDOMWindow)) | |
456 return; | |
457 | |
458 this._showNextNotification(subject.location.href); | |
459 }.bind(this) | |
460 }; | |
461 Services.obs.addObserver(documentCreationObserver, "content-document-global- created", false); | |
462 onShutdown.add(function() | |
463 { | |
464 Services.obs.removeObserver(documentCreationObserver, "content-document-gl obal-created", false); | |
465 }); | |
399 }, | 466 }, |
400 | 467 |
401 /** | 468 /** |
402 * Gets called once the initialization is finished and Adblock Plus elements | 469 * Gets called once the initialization is finished and Adblock Plus elements |
403 * can be added to the UI. | 470 * can be added to the UI. |
404 */ | 471 */ |
405 initDone: function() | 472 initDone: function() |
406 { | 473 { |
407 let {WindowObserver} = require("windowObserver"); | 474 let {WindowObserver} = require("windowObserver"); |
408 new WindowObserver(this); | 475 new WindowObserver(this); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton")); | 591 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton")); |
525 }.bind(this)); | 592 }.bind(this)); |
526 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); | 593 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); |
527 | 594 |
528 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event) | 595 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event) |
529 { | 596 { |
530 window.document.getElementById("abp-notification").hidePopup(); | 597 window.document.getElementById("abp-notification").hidePopup(); |
531 }, false); | 598 }, false); |
532 | 599 |
533 // Add "anti-adblock messages" notification | 600 // Add "anti-adblock messages" notification |
534 function getDomainsFromSubscription(subscription) | 601 this._initAntiAdblockNotification(); |
535 { | |
536 let domains = []; | |
537 for each (let filter in subscription.filters) | |
538 if (filter instanceof ActiveFilter) | |
539 for (let domain in filter.domains) | |
540 if (domain && domains.indexOf(domain) == -1) | |
541 domains.push(domain); | |
542 return domains; | |
543 } | |
544 | |
545 let antiadblockNotification = { | |
546 id: "antiadblock", | |
547 type: "question", | |
548 title: Utils.getString("notification_antiadblock_title"), | |
549 message: Utils.getString("notification_antiadblock_message"), | |
550 domains: [], | |
551 onApproved: function() | |
552 { | |
553 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblocku rl); | |
554 if (subscription.url in FilterStorage.knownSubscriptions) | |
Felix Dahlke
2014/02/11 17:19:44
Shouldn't we add it here if it's not in the knownS
Felix Dahlke
2014/02/11 17:57:17
Actually not, it's fine :)
| |
555 subscription.disabled = false; | |
556 }, | |
557 onDeclined: function() | |
558 { | |
559 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblocku rl); | |
560 if (subscription.url in FilterStorage.knownSubscriptions) | |
561 subscription.disabled = true; | |
562 } | |
563 }; | |
564 let antiadblockSubscription = Subscription.fromURL(Prefs.subscriptions_antia dblockurl); | |
565 if (antiadblockSubscription.lastDownload && antiadblockSubscription.disabled ) | |
566 { | |
567 antiadblockNotification.domains = getDomainsFromSubscription(antiadblockSu bscription); | |
568 Notification.addNotification(antiadblockNotification); | |
569 } | |
570 FilterNotifier.addListener(function(action, value, newItem, oldItem) | |
571 { | |
572 if (!/^subscription\.(updated|removed|disabled)$/.test(action) || value.ur l != Prefs.subscriptions_antiadblockurl) | |
573 return; | |
574 | |
575 if (action == "subscription.updated") | |
576 { | |
577 antiadblockNotification.domains = getDomainsFromSubscription(value); | |
578 Notification.addNotification(antiadblockNotification); | |
579 } | |
580 else if (action == "subscription.removed" || (action == "subscription.disa bled" && !value.disabled)) | |
581 { | |
582 Notification.removeNotification(antiadblockNotification); | |
583 } | |
584 }); | |
585 | |
586 var httpRequestObserver = { | |
587 observe: function(subject, topic, data) | |
588 { | |
589 if (!(subject instanceof Ci.nsIDOMWindow)) | |
590 return; | |
591 | |
592 this._showNextNotification(subject.location.href); | |
593 }.bind(this) | |
594 }; | |
595 Services.obs.addObserver(httpRequestObserver, "content-document-global-creat ed", false); | |
596 onShutdown.add(function() | |
597 { | |
598 Services.obs.removeObserver(httpRequestObserver, "content-document-global- created", false); | |
599 }); | |
600 | 602 |
601 // First-run actions? | 603 // First-run actions? |
602 if (!this.firstRunDone) | 604 if (!this.firstRunDone) |
603 { | 605 { |
604 this.firstRunDone = true; | 606 this.firstRunDone = true; |
605 | 607 |
606 let {addonVersion} = require("info"); | 608 let {addonVersion} = require("info"); |
607 let prevVersion = Prefs.currentVersion; | 609 let prevVersion = Prefs.currentVersion; |
608 if (prevVersion != addonVersion) | 610 if (prevVersion != addonVersion) |
609 { | 611 { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 { | 838 { |
837 subscription.title = "Allow non-intrusive advertising"; | 839 subscription.title = "Allow non-intrusive advertising"; |
838 FilterStorage.addSubscription(subscription); | 840 FilterStorage.addSubscription(subscription); |
839 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) | 841 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) |
840 Synchronizer.execute(subscription); | 842 Synchronizer.execute(subscription); |
841 } | 843 } |
842 else | 844 else |
843 addAcceptable = false; | 845 addAcceptable = false; |
844 } | 846 } |
845 | 847 |
846 // Add "anti-adblock messages" subscription for new users and users updating from old ABP versions. | 848 // Add "anti-adblock messages" subscription |
847 if (Services.vc.compare(prevVersion, "2.5") < 0) | 849 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl); |
Felix Dahlke
2014/02/11 10:35:27
I think we should show them to every user once act
Thomas Greiner
2014/02/11 16:53:31
This is just the initial download of the filterlis
| |
848 { | 850 if (subscription) |
849 let subscription = Subscription.fromURL(Prefs.subscriptions_antiadblockurl ); | 851 { |
850 if (subscription) | 852 subscription.disabled = true; |
851 { | 853 FilterStorage.addSubscription(subscription); |
852 subscription.disabled = true; | 854 if (subscription instanceof DownloadableSubscription && !subscription.last Download) |
853 FilterStorage.addSubscription(subscription); | 855 Synchronizer.execute(subscription); |
854 if (subscription instanceof DownloadableSubscription && !subscription.la stDownload) | |
855 Synchronizer.execute(subscription); | |
856 } | |
857 } | 856 } |
858 | 857 |
859 if (!addSubscription && !addAcceptable) | 858 if (!addSubscription && !addAcceptable) |
860 return; | 859 return; |
861 | 860 |
862 function notifyUser() | 861 function notifyUser() |
863 { | 862 { |
864 let {addTab} = require("appSupport"); | 863 let {addTab} = require("appSupport"); |
865 if (addTab) | 864 if (addTab) |
866 { | 865 { |
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1903 let messageElement = window.document.getElementById("abp-notification-messag e"); | 1902 let messageElement = window.document.getElementById("abp-notification-messag e"); |
1904 messageElement.innerHTML = ""; | 1903 messageElement.innerHTML = ""; |
1905 let docLinks = []; | 1904 let docLinks = []; |
1906 for each (let link in notification.links) | 1905 for each (let link in notification.links) |
1907 docLinks.push(Utils.getDocLink(link)); | 1906 docLinks.push(Utils.getDocLink(link)); |
1908 insertMessage(messageElement, texts.message, docLinks); | 1907 insertMessage(messageElement, texts.message, docLinks); |
1909 | 1908 |
1910 messageElement.addEventListener("click", function(event) | 1909 messageElement.addEventListener("click", function(event) |
1911 { | 1910 { |
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") |
1913 link = link.parentNode; | |
1914 if (!link || link.localName !== "a") | |
1914 return; | 1915 return; |
1915 event.preventDefault(); | 1916 event.preventDefault(); |
1916 event.stopPropagation(); | 1917 event.stopPropagation(); |
1917 this.loadInBrowser(link.href, window); | 1918 this.loadInBrowser(link.href, window); |
1918 }.bind(this)); | 1919 }.bind(this)); |
1919 | 1920 |
1920 if (notification.type === "question") | 1921 if (notification.type === "question") |
1921 { | 1922 { |
1922 function buttonHandler(event) | 1923 function buttonHandler(approved, event) |
1923 { | 1924 { |
1924 event.preventDefault(); | 1925 event.preventDefault(); |
1925 event.stopPropagation(); | 1926 event.stopPropagation(); |
1926 panel.hidePopup(); | 1927 panel.hidePopup(); |
1927 | 1928 Notification.triggerQuestionListeners(notification.id, approved) |
1928 let action = notification[event.target.getAttribute("action")]; | |
1929 if (typeof action === "function") | |
1930 action(); | |
1931 Notification.markAsShown(notification.id); | 1929 Notification.markAsShown(notification.id); |
1932 } | 1930 } |
1933 window.document.getElementById("abp-notification-yes").oncommand = buttonH andler; | 1931 window.document.getElementById("abp-notification-yes").onclick = buttonHan dler.bind(null, true); |
1934 window.document.getElementById("abp-notification-no").oncommand = buttonHa ndler; | 1932 window.document.getElementById("abp-notification-no").onclick = buttonHand ler.bind(null, false); |
1935 } | 1933 } |
1936 | 1934 |
1937 panel.setAttribute("class", "abp-" + notification.type); | 1935 panel.setAttribute("class", "abp-" + notification.type); |
1938 panel.setAttribute("noautohide", notification.type === "question"); | 1936 panel.setAttribute("noautohide", notification.type === "question"); |
1939 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); | 1937 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); |
1940 } | 1938 } |
1941 }; | 1939 }; |
1942 UI.onPopupShowing = UI.onPopupShowing.bind(UI); | 1940 UI.onPopupShowing = UI.onPopupShowing.bind(UI); |
1943 UI.onKeyPress = UI.onKeyPress.bind(UI); | 1941 UI.onKeyPress = UI.onKeyPress.bind(UI); |
1944 UI.onIconClick = UI.onIconClick.bind(UI); | 1942 UI.onIconClick = UI.onIconClick.bind(UI); |
(...skipping 20 matching lines...) Expand all Loading... | |
1965 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], | 1963 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], |
1966 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] | 1964 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] |
1967 ]; | 1965 ]; |
1968 | 1966 |
1969 onShutdown.add(function() | 1967 onShutdown.add(function() |
1970 { | 1968 { |
1971 for (let window in UI.applicationWindows) | 1969 for (let window in UI.applicationWindows) |
1972 if (UI.isBottombarOpen(window)) | 1970 if (UI.isBottombarOpen(window)) |
1973 UI.toggleBottombar(window); | 1971 UI.toggleBottombar(window); |
1974 }); | 1972 }); |
LEFT | RIGHT |