Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/filterStorage.js

Issue 9043026: Adapted private browsing handling to per-window private browsing in Firefox 20 (Closed)
Patch Set: Created Dec. 18, 2012, 2:57 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/contentPolicy.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of the Adblock Plus, 2 * This file is part of the Adblock Plus,
3 * Copyright (C) 2006-2012 Eyeo GmbH 3 * Copyright (C) 2006-2012 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 return; 306 return;
307 307
308 subscription.filters.splice(oldPosition, 1); 308 subscription.filters.splice(oldPosition, 1);
309 subscription.filters.splice(newPosition, 0, filter); 309 subscription.filters.splice(newPosition, 0, filter);
310 FilterNotifier.triggerListeners("filter.moved", filter, subscription, oldPos ition, newPosition); 310 FilterNotifier.triggerListeners("filter.moved", filter, subscription, oldPos ition, newPosition);
311 }, 311 },
312 312
313 /** 313 /**
314 * Increases the hit count for a filter by one 314 * Increases the hit count for a filter by one
315 * @param {Filter} filter 315 * @param {Filter} filter
316 * @param {Window} window Window that the match originated in (required
317 * to recognize private browsing mode)
316 */ 318 */
317 increaseHitCount: function(filter) 319 increaseHitCount: function(filter, wnd)
318 { 320 {
319 if (!Prefs.savestats || PrivateBrowsing.enabled || !(filter instanceof Activ eFilter)) 321 if (!Prefs.savestats || PrivateBrowsing.enabledForWindow(wnd) ||
322 PrivateBrowsing.enabled || !(filter instanceof ActiveFilter))
323 {
320 return; 324 return;
325 }
321 326
322 filter.hitCount++; 327 filter.hitCount++;
323 filter.lastHit = Date.now(); 328 filter.lastHit = Date.now();
324 }, 329 },
325 330
326 /** 331 /**
327 * Resets hit count for some filters 332 * Resets hit count for some filters
328 * @param {Array of Filter} filters filters to be reset, if null all filters will be reset 333 * @param {Array of Filter} filters filters to be reset, if null all filters will be reset
329 */ 334 */
330 resetHitCounts: function(filters) 335 resetHitCounts: function(filters)
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 } 710 }
706 } 711 }
707 712
708 /** 713 /**
709 * Observer listening to private browsing mode changes. 714 * Observer listening to private browsing mode changes.
710 * @class 715 * @class
711 */ 716 */
712 let PrivateBrowsing = exports.PrivateBrowsing = 717 let PrivateBrowsing = exports.PrivateBrowsing =
713 { 718 {
714 /** 719 /**
715 * Will be set to true when the private browsing mode is switched on. 720 * Will be set to true when the private browsing mode is switched on globally.
716 * @type Boolean 721 * @type Boolean
717 */ 722 */
718 enabled: false, 723 enabled: false,
719 724
725 /**
726 * Checks whether private browsing is enabled for a particular window.
727 */
728 enabledForWindow: function(/**Window*/ wnd) /**Boolean*/
729 {
730 try
731 {
732 return wnd.QueryInterface(Ci.nsIInterfaceRequestor)
733 .getInterface(Ci.nsILoadContext)
734 .usePrivateBrowsing;
735 }
736 catch(e)
737 {
738 // Gecko 19 and below will throw NO_INTERFACE, this is expected
Thomas Greiner 2012/12/19 14:21:39 in that case we can check if we actually got a NO_
739 return false;
740 }
741 },
742
720 init: function() 743 init: function()
721 { 744 {
722 if ("@mozilla.org/privatebrowsing;1" in Cc) 745 if ("@mozilla.org/privatebrowsing;1" in Cc)
723 { 746 {
724 try 747 try
725 { 748 {
726 this.enabled = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPri vateBrowsingService).privateBrowsingEnabled; 749 this.enabled = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPri vateBrowsingService).privateBrowsingEnabled;
727 Services.obs.addObserver(this, "private-browsing", true); 750 Services.obs.addObserver(this, "private-browsing", true);
728 onShutdown.add(function() 751 onShutdown.add(function()
729 { 752 {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 else if (this.wantObj === false && val) 870 else if (this.wantObj === false && val)
848 this.curObj.push(val.replace(/\\\[/g, "[")); 871 this.curObj.push(val.replace(/\\\[/g, "["));
849 } 872 }
850 finally 873 finally
851 { 874 {
852 Filter.knownFilters = origKnownFilters; 875 Filter.knownFilters = origKnownFilters;
853 Subscription.knownSubscriptions = origKnownSubscriptions; 876 Subscription.knownSubscriptions = origKnownSubscriptions;
854 } 877 }
855 } 878 }
856 }; 879 };
OLDNEW
« no previous file with comments | « lib/contentPolicy.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld