OLD | NEW |
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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 return; | 316 return; |
317 | 317 |
318 subscription.filters.splice(oldPosition, 1); | 318 subscription.filters.splice(oldPosition, 1); |
319 subscription.filters.splice(newPosition, 0, filter); | 319 subscription.filters.splice(newPosition, 0, filter); |
320 FilterNotifier.triggerListeners("filter.moved", filter, subscription, oldPos
ition, newPosition); | 320 FilterNotifier.triggerListeners("filter.moved", filter, subscription, oldPos
ition, newPosition); |
321 }, | 321 }, |
322 | 322 |
323 /** | 323 /** |
324 * Increases the hit count for a filter by one | 324 * Increases the hit count for a filter by one |
325 * @param {Filter} filter | 325 * @param {Filter} filter |
326 * @param {Window} window Window that the match originated in (required | |
327 * to recognize private browsing mode) | |
328 */ | 326 */ |
329 increaseHitCount: function(filter, wnd) | 327 increaseHitCount: function(filter) |
330 { | 328 { |
331 if (!Prefs.savestats || PrivateBrowsing.enabledForWindow(wnd) || | 329 if (!Prefs.savestats || !(filter instanceof ActiveFilter)) |
332 PrivateBrowsing.enabled || !(filter instanceof ActiveFilter)) | |
333 { | |
334 return; | 330 return; |
335 } | |
336 | 331 |
337 filter.hitCount++; | 332 filter.hitCount++; |
338 filter.lastHit = Date.now(); | 333 filter.lastHit = Date.now(); |
339 }, | 334 }, |
340 | 335 |
341 /** | 336 /** |
342 * Resets hit count for some filters | 337 * Resets hit count for some filters |
343 * @param {Filter[]} filters filters to be reset, if null all filters will be
reset | 338 * @param {Filter[]} filters filters to be reset, if null all filters will be
reset |
344 */ | 339 */ |
345 resetHitCounts: function(filters) | 340 resetHitCounts: function(filters) |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 | 683 |
689 for (let filter of subscription.filters) | 684 for (let filter of subscription.filters) |
690 { | 685 { |
691 let i = filter.subscriptions.indexOf(subscription); | 686 let i = filter.subscriptions.indexOf(subscription); |
692 if (i >= 0) | 687 if (i >= 0) |
693 filter.subscriptions.splice(i, 1); | 688 filter.subscriptions.splice(i, 1); |
694 } | 689 } |
695 } | 690 } |
696 | 691 |
697 /** | 692 /** |
698 * Observer listening to private browsing mode changes. | |
699 * @class | |
700 */ | |
701 let PrivateBrowsing = exports.PrivateBrowsing = | |
702 { | |
703 /** | |
704 * Will be set to true when the private browsing mode is switched on globally. | |
705 * @type Boolean | |
706 */ | |
707 enabled: false, | |
708 | |
709 /** | |
710 * Checks whether private browsing is enabled for a particular window. | |
711 */ | |
712 enabledForWindow: function(/**Window*/ wnd) /**Boolean*/ | |
713 { | |
714 try | |
715 { | |
716 return wnd.QueryInterface(Ci.nsIInterfaceRequestor) | |
717 .getInterface(Ci.nsILoadContext) | |
718 .usePrivateBrowsing; | |
719 } | |
720 catch (e) | |
721 { | |
722 // Gecko 19 and below will throw NS_NOINTERFACE, this is expected | |
723 if (e.result != Cr.NS_NOINTERFACE) | |
724 Cu.reportError(e); | |
725 return false; | |
726 } | |
727 }, | |
728 | |
729 init: function() | |
730 { | |
731 if ("@mozilla.org/privatebrowsing;1" in Cc) | |
732 { | |
733 try | |
734 { | |
735 this.enabled = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPri
vateBrowsingService).privateBrowsingEnabled; | |
736 Services.obs.addObserver(this, "private-browsing", true); | |
737 onShutdown.add(function() | |
738 { | |
739 Services.obs.removeObserver(this, "private-browsing"); | |
740 }.bind(this)); | |
741 } | |
742 catch(e) | |
743 { | |
744 Cu.reportError(e); | |
745 } | |
746 } | |
747 }, | |
748 | |
749 observe: function(subject, topic, data) | |
750 { | |
751 if (topic == "private-browsing") | |
752 { | |
753 if (data == "enter") | |
754 this.enabled = true; | |
755 else if (data == "exit") | |
756 this.enabled = false; | |
757 } | |
758 }, | |
759 | |
760 QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObse
rver]) | |
761 }; | |
762 PrivateBrowsing.init(); | |
763 | |
764 /** | |
765 * IO.readFromFile() listener to parse filter data. | 693 * IO.readFromFile() listener to parse filter data. |
766 * @constructor | 694 * @constructor |
767 */ | 695 */ |
768 function INIParser() | 696 function INIParser() |
769 { | 697 { |
770 this.fileProperties = this.curObj = {}; | 698 this.fileProperties = this.curObj = {}; |
771 this.subscriptions = []; | 699 this.subscriptions = []; |
772 this.knownFilters = Object.create(null); | 700 this.knownFilters = Object.create(null); |
773 this.knownSubscriptions = Object.create(null); | 701 this.knownSubscriptions = Object.create(null); |
774 } | 702 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 Subscription.knownSubscriptions = origKnownSubscriptions; | 791 Subscription.knownSubscriptions = origKnownSubscriptions; |
864 } | 792 } |
865 | 793 |
866 // Allow events to be processed every now and then. | 794 // Allow events to be processed every now and then. |
867 // Note: IO.readFromFile() will deal with the potential reentrance here. | 795 // Note: IO.readFromFile() will deal with the potential reentrance here. |
868 this.linesProcessed++; | 796 this.linesProcessed++; |
869 if (this.linesProcessed % 1000 == 0) | 797 if (this.linesProcessed % 1000 == 0) |
870 Utils.yield(); | 798 Utils.yield(); |
871 } | 799 } |
872 }; | 800 }; |
OLD | NEW |