LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // Load subscriptions data | 160 // Load subscriptions data |
161 let request = new XMLHttpRequest(); | 161 let request = new XMLHttpRequest(); |
162 request.mozBackgroundRequest = true; | 162 request.mozBackgroundRequest = true; |
163 request.open("GET", "chrome://adblockplus/content/ui/subscriptions.xml")
; | 163 request.open("GET", "chrome://adblockplus/content/ui/subscriptions.xml")
; |
164 request.addEventListener("load", function() | 164 request.addEventListener("load", function() |
165 { | 165 { |
166 if (onShutdown.done) | 166 if (onShutdown.done) |
167 return; | 167 return; |
168 | 168 |
169 let currentSubscription = FilterStorage.subscriptions.filter((subscrip
tion) => subscription instanceof DownloadableSubscription && | 169 let currentSubscription = FilterStorage.subscriptions.filter((subscrip
tion) => subscription instanceof DownloadableSubscription && |
170 subscription.url != Prefs.subscriptions_exceptionsurl && | 170 subscription.url != Prefs.subscriptions_exceptionsurl && |
171 subscription.url != Prefs.subscriptions_antiadblockurl); | 171 subscription.url != Prefs.subscriptions_antiadblockurl); |
172 currentSubscription = (currentSubscription.length ? currentSubscriptio
n[0] : null); | 172 currentSubscription = (currentSubscription.length ? currentSubscriptio
n[0] : null); |
173 | 173 |
174 let subscriptions =request.responseXML.getElementsByTagName("subscript
ion"); | 174 let subscriptions =request.responseXML.getElementsByTagName("subscript
ion"); |
175 for (let i = 0; i < subscriptions.length; i++) | 175 for (let i = 0; i < subscriptions.length; i++) |
176 { | 176 { |
177 let item = subscriptions[i]; | 177 let item = subscriptions[i]; |
178 let url = item.getAttribute("url"); | 178 let url = item.getAttribute("url"); |
179 if (!url) | 179 if (!url) |
180 continue; | 180 continue; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 for (let window of this.applicationWindows) | 420 for (let window of this.applicationWindows) |
421 this.updateStatusbarIcon(window); | 421 this.updateStatusbarIcon(window); |
422 } | 422 } |
423 }.bind(this)); | 423 }.bind(this)); |
424 FilterNotifier.addListener(function(action) | 424 FilterNotifier.addListener(function(action) |
425 { | 425 { |
426 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio
n) || action == "load") | 426 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio
n) || action == "load") |
427 this.updateState(); | 427 this.updateState(); |
428 }.bind(this)); | 428 }.bind(this)); |
429 | 429 |
430 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); | 430 Notification.addShowListener(notification => |
431 notificationTimer.initWithCallback(this.showNextNotification.bind(this), | 431 { |
432 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT)
; | 432 let window = this.currentWindow; |
433 onShutdown.add(() => notificationTimer.cancel()); | 433 if (!window) |
| 434 return; |
| 435 |
| 436 let button = window.document.getElementById("abp-toolbarbutton") |
| 437 || window.document.getElementById("abp-status"); |
| 438 if (!button) |
| 439 return; |
| 440 |
| 441 this._showNotification(window, button, notification); |
| 442 }); |
434 | 443 |
435 // Add "anti-adblock messages" notification | 444 // Add "anti-adblock messages" notification |
436 initAntiAdblockNotification(); | 445 initAntiAdblockNotification(); |
437 | 446 |
438 let documentCreationObserver = { | 447 let documentCreationObserver = { |
439 observe: function(subject, topic, data) | 448 observe: function(subject, topic, data) |
440 { | 449 { |
441 if (!(subject instanceof Ci.nsIDOMWindow)) | 450 if (!(subject instanceof Ci.nsIDOMWindow)) |
442 return; | 451 return; |
443 | 452 |
444 this.showNextNotification(subject.location.href); | 453 Notification.showNext(subject.location.href); |
445 }.bind(UI) | 454 }.bind(UI) |
446 }; | 455 }; |
447 Services.obs.addObserver(documentCreationObserver, "content-document-global-
created", false); | 456 Services.obs.addObserver(documentCreationObserver, "content-document-global-
created", false); |
448 onShutdown.add(function() | 457 onShutdown.add(function() |
449 { | 458 { |
450 Services.obs.removeObserver(documentCreationObserver, "content-document-gl
obal-created", false); | 459 Services.obs.removeObserver(documentCreationObserver, "content-document-gl
obal-created", false); |
451 }); | 460 }); |
452 | 461 |
453 // Execute first-run actions if a window is open already, otherwise it | 462 // Execute first-run actions if a window is open already, otherwise it |
454 // will happen in applyToWindow() when a window is opened. | 463 // will happen in applyToWindow() when a window is opened. |
455 this.firstRunActions(this.currentWindow); | 464 this.firstRunActions(this.currentWindow); |
456 }, | 465 }, |
457 | 466 |
458 addToolbarButton: function() | 467 addToolbarButton: function() |
459 { | 468 { |
460 let {WindowObserver} = require("windowObserver"); | 469 let {WindowObserver} = require("windowObserver"); |
461 new WindowObserver(this); | 470 new WindowObserver(this); |
462 | 471 |
463 let {defaultToolbarPosition} = require("appSupport"); | 472 let {defaultToolbarPosition} = require("appSupport"); |
464 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) | 473 if ("abp-toolbarbutton" in this.overlay && defaultToolbarPosition) |
465 { | 474 { |
466 try | 475 try |
467 { | 476 { |
468 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm",
null); | 477 ({CustomizableUI} = Cu.import("resource:///modules/CustomizableUI.jsm",
null)); |
469 } | 478 } |
470 catch (e) | 479 catch (e) |
471 { | 480 { |
472 // No built-in CustomizableUI API, use our own implementation. | 481 // No built-in CustomizableUI API, use our own implementation. |
473 ({CustomizableUI}) = require("customizableUI"); | 482 ({CustomizableUI} = require("customizableUI")); |
474 } | 483 } |
475 | 484 |
476 CustomizableUI.createWidget({ | 485 CustomizableUI.createWidget({ |
477 id: "abp-toolbarbutton", | 486 id: "abp-toolbarbutton", |
478 type: "custom", | 487 type: "custom", |
479 positionAttribute: "abp-iconposition", // For emulation only | 488 positionAttribute: "abp-iconposition", // For emulation only |
480 defaultArea: defaultToolbarPosition.parent, | 489 defaultArea: defaultToolbarPosition.parent, |
481 defaultBefore: defaultToolbarPosition.before, // For emulation only | 490 defaultBefore: defaultToolbarPosition.before, // For emulation only |
482 defaultAfter: defaultToolbarPosition.after, // For emulation only | 491 defaultAfter: defaultToolbarPosition.after, // For emulation only |
483 removable: true, | 492 removable: true, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 let notificationPanel = window.document.getElementById("abp-notification"); | 598 let notificationPanel = window.document.getElementById("abp-notification"); |
590 notificationPanel.addEventListener("command", function(event) | 599 notificationPanel.addEventListener("command", function(event) |
591 { | 600 { |
592 switch (event.target.id) | 601 switch (event.target.id) |
593 { | 602 { |
594 case "abp-notification-close": | 603 case "abp-notification-close": |
595 notificationPanel.classList.add("abp-closing"); | 604 notificationPanel.classList.add("abp-closing"); |
596 break; | 605 break; |
597 case "abp-notification-optout": | 606 case "abp-notification-optout": |
598 Notification.toggleIgnoreCategory("*", true); | 607 Notification.toggleIgnoreCategory("*", true); |
| 608 /* FALL THROUGH */ |
599 case "abp-notification-hide": | 609 case "abp-notification-hide": |
600 notificationPanel.hidePopup(); | 610 notificationPanel.hidePopup(); |
601 break; | 611 break; |
602 } | 612 } |
603 }, true); | 613 }, false); |
604 | 614 |
605 // First-run actions? | 615 // First-run actions? |
606 this.firstRunActions(window); | 616 this.firstRunActions(window); |
607 | 617 |
608 // Some people actually switch off browser.frames.enabled and are surprised | 618 // Some people actually switch off browser.frames.enabled and are surprised |
609 // that things stop working... | 619 // that things stop working... |
610 window.QueryInterface(Ci.nsIInterfaceRequestor) | 620 window.QueryInterface(Ci.nsIInterfaceRequestor) |
611 .getInterface(Ci.nsIWebNavigation) | 621 .getInterface(Ci.nsIWebNavigation) |
612 .QueryInterface(Ci.nsIDocShell) | 622 .QueryInterface(Ci.nsIDocShell) |
613 .allowSubframes = true; | 623 .allowSubframes = true; |
(...skipping 1249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 Prefs.hideContributeButton = true; | 1873 Prefs.hideContributeButton = true; |
1864 | 1874 |
1865 for (let id of ["abp-status-contributebutton", "abp-toolbar-contributebutton
", "abp-menuitem-contributebutton"]) | 1875 for (let id of ["abp-status-contributebutton", "abp-toolbar-contributebutton
", "abp-menuitem-contributebutton"]) |
1866 { | 1876 { |
1867 let button = window.document.getElementById(id); | 1877 let button = window.document.getElementById(id); |
1868 if (button) | 1878 if (button) |
1869 button.hidden = true; | 1879 button.hidden = true; |
1870 } | 1880 } |
1871 }, | 1881 }, |
1872 | 1882 |
1873 showNextNotification: function(url) | |
1874 { | |
1875 let window = this.currentWindow; | |
1876 if (!window) | |
1877 return; | |
1878 | |
1879 let button = window.document.getElementById("abp-toolbarbutton") | |
1880 || window.document.getElementById("abp-status"); | |
1881 if (!button) | |
1882 return; | |
1883 | |
1884 let notification = Notification.getNextToShow(url); | |
1885 if (!notification) | |
1886 return; | |
1887 | |
1888 this._showNotification(window, button, notification); | |
1889 }, | |
1890 | |
1891 _showNotification: function(window, button, notification) | 1883 _showNotification: function(window, button, notification) |
1892 { | 1884 { |
1893 let panel = window.document.getElementById("abp-notification"); | 1885 let panel = window.document.getElementById("abp-notification"); |
1894 if (panel.state !== "closed") | 1886 if (panel.state !== "closed") |
1895 return; | 1887 return; |
1896 | 1888 |
1897 function insertMessage(element, text, links) | 1889 function insertMessage(element, text, links) |
1898 { | 1890 { |
1899 let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(text); | 1891 let match = /^(.*?)<(a|strong)>(.*?)<\/\2>(.*)$/.exec(text); |
1900 if (!match) | 1892 if (!match) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 { | 1938 { |
1947 event.preventDefault(); | 1939 event.preventDefault(); |
1948 event.stopPropagation(); | 1940 event.stopPropagation(); |
1949 panel.hidePopup(); | 1941 panel.hidePopup(); |
1950 Notification.triggerQuestionListeners(notification.id, approved) | 1942 Notification.triggerQuestionListeners(notification.id, approved) |
1951 Notification.markAsShown(notification.id); | 1943 Notification.markAsShown(notification.id); |
1952 } | 1944 } |
1953 window.document.getElementById("abp-notification-yes").onclick = buttonHan
dler.bind(null, true); | 1945 window.document.getElementById("abp-notification-yes").onclick = buttonHan
dler.bind(null, true); |
1954 window.document.getElementById("abp-notification-no").onclick = buttonHand
ler.bind(null, false); | 1946 window.document.getElementById("abp-notification-no").onclick = buttonHand
ler.bind(null, false); |
1955 } | 1947 } |
| 1948 else |
| 1949 Notification.markAsShown(notification.id); |
1956 | 1950 |
1957 panel.setAttribute("class", "abp-" + notification.type); | 1951 panel.setAttribute("class", "abp-" + notification.type); |
1958 panel.setAttribute("noautohide", notification.type === "question"); | 1952 panel.setAttribute("noautohide", notification.type === "question"); |
1959 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); | 1953 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); |
1960 } | 1954 } |
1961 }; | 1955 }; |
1962 UI.onPopupShowing = UI.onPopupShowing.bind(UI); | 1956 UI.onPopupShowing = UI.onPopupShowing.bind(UI); |
1963 UI.onKeyPress = UI.onKeyPress.bind(UI); | 1957 UI.onKeyPress = UI.onKeyPress.bind(UI); |
1964 UI.onIconClick = UI.onIconClick.bind(UI); | 1958 UI.onIconClick = UI.onIconClick.bind(UI); |
1965 UI.init(); | 1959 UI.init(); |
(...skipping 19 matching lines...) Expand all Loading... |
1985 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)], | 1979 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)], |
1986 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa
tegory.bind(Notification, "*", null)] | 1980 ["abp-command-toggleshownotifications", "command", Notification.toggleIgnoreCa
tegory.bind(Notification, "*", null)] |
1987 ]; | 1981 ]; |
1988 | 1982 |
1989 onShutdown.add(function() | 1983 onShutdown.add(function() |
1990 { | 1984 { |
1991 for (let window of UI.applicationWindows) | 1985 for (let window of UI.applicationWindows) |
1992 if (UI.isBottombarOpen(window)) | 1986 if (UI.isBottombarOpen(window)) |
1993 UI.toggleBottombar(window); | 1987 UI.toggleBottombar(window); |
1994 }); | 1988 }); |
LEFT | RIGHT |