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-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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); | 18 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
19 Cu.import("resource://gre/modules/Services.jsm"); | 19 Cu.import("resource://gre/modules/Services.jsm"); |
20 | 20 |
21 let {Utils} = require("utils"); | 21 let {Utils} = require("utils"); |
22 let {Prefs} = require("prefs"); | 22 let {Prefs} = require("prefs"); |
23 let {Policy} = require("contentPolicy"); | 23 let {Policy} = require("contentPolicy"); |
24 let {FilterListener} = require("filterListener"); | 24 let {FilterListener} = require("filterListener"); |
25 let {FilterStorage} = require("filterStorage"); | 25 let {FilterStorage} = require("filterStorage"); |
26 let {FilterNotifier} = require("filterNotifier"); | 26 let {FilterNotifier} = require("filterNotifier"); |
27 let {RequestNotifier} = require("requestNotifier"); | 27 let {RequestNotifier} = require("requestNotifier"); |
28 let {Filter, ActiveFilter} = require("filterClasses"); | 28 let {Filter} = require("filterClasses"); |
29 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub
scriptionClasses"); | 29 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub
scriptionClasses"); |
30 let {Synchronizer} = require("synchronizer"); | 30 let {Synchronizer} = require("synchronizer"); |
31 let {KeySelector} = require("keySelector"); | 31 let {KeySelector} = require("keySelector"); |
32 let {Notification} = require("notification"); | 32 let {Notification} = require("notification"); |
| 33 let {initAntiAdblockNotification} = require("antiadblockInit"); |
33 | 34 |
34 let CustomizableUI; | 35 let CustomizableUI; |
35 try | 36 try |
36 { | 37 { |
37 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null)
; | 38 ({CustomizableUI}) = Cu.import("resource:///modules/CustomizableUI.jsm", null)
; |
38 } | 39 } |
39 catch (e) | 40 catch (e) |
40 { | 41 { |
41 // No built-in CustomizableUI API, use our own implementation. | 42 // No built-in CustomizableUI API, use our own implementation. |
42 ({CustomizableUI}) = require("customizableUI"); | 43 ({CustomizableUI}) = require("customizableUI"); |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 392 |
392 if (this.overlay.all.length) | 393 if (this.overlay.all.length) |
393 this.overlay.all[0].appendChild(menuSource); | 394 this.overlay.all[0].appendChild(menuSource); |
394 if ("abp-toolbarbutton" in this.overlay) | 395 if ("abp-toolbarbutton" in this.overlay) |
395 this.overlay["abp-toolbarbutton"].appendChild(fixId(menuSource.cloneNode
(true), "abp-toolbar")); | 396 this.overlay["abp-toolbarbutton"].appendChild(fixId(menuSource.cloneNode
(true), "abp-toolbar")); |
396 if ("abp-menuitem" in this.overlay) | 397 if ("abp-menuitem" in this.overlay) |
397 this.overlay["abp-menuitem"].appendChild(fixId(menuSource.cloneNode(true
), "abp-menuitem")); | 398 this.overlay["abp-menuitem"].appendChild(fixId(menuSource.cloneNode(true
), "abp-menuitem")); |
398 } | 399 } |
399 }, | 400 }, |
400 | 401 |
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 }); | |
466 }, | |
467 | |
468 /** | 402 /** |
469 * Gets called once the initialization is finished and Adblock Plus elements | 403 * Gets called once the initialization is finished and Adblock Plus elements |
470 * can be added to the UI. | 404 * can be added to the UI. |
471 */ | 405 */ |
472 initDone: function() | 406 initDone: function() |
473 { | 407 { |
474 let {WindowObserver} = require("windowObserver"); | 408 let {WindowObserver} = require("windowObserver"); |
475 new WindowObserver(this); | 409 new WindowObserver(this); |
476 | 410 |
477 // Add toolbar icon | 411 // Add toolbar icon |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 this.updateStatusbarIcon(window); | 449 this.updateStatusbarIcon(window); |
516 } | 450 } |
517 }.bind(this)); | 451 }.bind(this)); |
518 FilterNotifier.addListener(function(action) | 452 FilterNotifier.addListener(function(action) |
519 { | 453 { |
520 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio
n) || action == "load") | 454 if (/^(filter|subscription)\.(added|removed|disabled|updated)$/.test(actio
n) || action == "load") |
521 this.updateState(); | 455 this.updateState(); |
522 }.bind(this)); | 456 }.bind(this)); |
523 | 457 |
524 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); | 458 notificationTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
525 notificationTimer.initWithCallback(this._showNextNotification.bind(this), | 459 notificationTimer.initWithCallback(this.showNextNotification.bind(this), |
526 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT)
; | 460 3 * 60 * 1000, Ci.nsITimer.TYPE_ONE_SHOT)
; |
527 onShutdown.add(function() notificationTimer.cancel()); | 461 onShutdown.add(function() notificationTimer.cancel()); |
528 }, | 462 }, |
529 | 463 |
530 /** | 464 /** |
531 * Will be set to true after the check whether first-run actions should run | 465 * Will be set to true after the check whether first-run actions should run |
532 * has been performed. | 466 * has been performed. |
533 * @type Boolean | 467 * @type Boolean |
534 */ | 468 */ |
535 firstRunDone: false, | 469 firstRunDone: false, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 this.updateIconState(window, window.document.getElementById("abp-toolbarbu
tton")); | 525 this.updateIconState(window, window.document.getElementById("abp-toolbarbu
tton")); |
592 }.bind(this)); | 526 }.bind(this)); |
593 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); | 527 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); |
594 | 528 |
595 window.document.getElementById("abp-notification-close").addEventListener("c
ommand", function(event) | 529 window.document.getElementById("abp-notification-close").addEventListener("c
ommand", function(event) |
596 { | 530 { |
597 window.document.getElementById("abp-notification").hidePopup(); | 531 window.document.getElementById("abp-notification").hidePopup(); |
598 }, false); | 532 }, false); |
599 | 533 |
600 // Add "anti-adblock messages" notification | 534 // Add "anti-adblock messages" notification |
601 this._initAntiAdblockNotification(); | 535 initAntiAdblockNotification(); |
| 536 |
| 537 let documentCreationObserver = { |
| 538 observe: function(subject, topic, data) |
| 539 { |
| 540 if (!(subject instanceof Ci.nsIDOMWindow)) |
| 541 return; |
| 542 |
| 543 this.showNextNotification(subject.location.href); |
| 544 }.bind(UI) |
| 545 }; |
| 546 Services.obs.addObserver(documentCreationObserver, "content-document-global-
created", false); |
| 547 onShutdown.add(function() |
| 548 { |
| 549 Services.obs.removeObserver(documentCreationObserver, "content-document-gl
obal-created", false); |
| 550 }); |
602 | 551 |
603 // First-run actions? | 552 // First-run actions? |
604 if (!this.firstRunDone) | 553 if (!this.firstRunDone) |
605 { | 554 { |
606 this.firstRunDone = true; | 555 this.firstRunDone = true; |
607 | 556 |
608 let {addonVersion} = require("info"); | 557 let {addonVersion} = require("info"); |
609 let prevVersion = Prefs.currentVersion; | 558 let prevVersion = Prefs.currentVersion; |
610 if (prevVersion != addonVersion) | 559 if (prevVersion != addonVersion) |
611 { | 560 { |
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1843 Prefs.hideContributeButton = true; | 1792 Prefs.hideContributeButton = true; |
1844 | 1793 |
1845 for each (let id in ["abp-status-contributebutton", "abp-toolbar-contributeb
utton", "abp-menuitem-contributebutton"]) | 1794 for each (let id in ["abp-status-contributebutton", "abp-toolbar-contributeb
utton", "abp-menuitem-contributebutton"]) |
1846 { | 1795 { |
1847 let button = window.document.getElementById(id); | 1796 let button = window.document.getElementById(id); |
1848 if (button) | 1797 if (button) |
1849 button.hidden = true; | 1798 button.hidden = true; |
1850 } | 1799 } |
1851 }, | 1800 }, |
1852 | 1801 |
1853 _showNextNotification: function(url) | 1802 showNextNotification: function(url) |
1854 { | 1803 { |
1855 let window = this.currentWindow; | 1804 let window = this.currentWindow; |
1856 if (!window) | 1805 if (!window) |
1857 return; | 1806 return; |
1858 | 1807 |
1859 let button = window.document.getElementById("abp-toolbarbutton") | 1808 let button = window.document.getElementById("abp-toolbarbutton") |
1860 || window.document.getElementById("abp-status"); | 1809 || window.document.getElementById("abp-status"); |
1861 if (!button) | 1810 if (!button) |
1862 return; | 1811 return; |
1863 | 1812 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1963 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], | 1912 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], |
1964 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] | 1913 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] |
1965 ]; | 1914 ]; |
1966 | 1915 |
1967 onShutdown.add(function() | 1916 onShutdown.add(function() |
1968 { | 1917 { |
1969 for (let window in UI.applicationWindows) | 1918 for (let window in UI.applicationWindows) |
1970 if (UI.isBottombarOpen(window)) | 1919 if (UI.isBottombarOpen(window)) |
1971 UI.toggleBottombar(window); | 1920 UI.toggleBottombar(window); |
1972 }); | 1921 }); |
OLD | NEW |