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:35 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 let loadContext = wnd.QueryInterface(Ci.nsIInterfaceRequestor)
733 .getInterface(Ci.nsILoadContext);
734 if ("usePrivateBrowsing" in loadContext)
735 return loadContext.usePrivateBrowsing;
736 else
737 return false; // Gecko 12 or below
738 }
739 catch(e)
740 {
741 Cu.reportError(e);
742 return false;
743 }
744 },
745
720 init: function() 746 init: function()
721 { 747 {
722 if ("@mozilla.org/privatebrowsing;1" in Cc) 748 if ("@mozilla.org/privatebrowsing;1" in Cc)
723 { 749 {
724 try 750 try
725 { 751 {
726 this.enabled = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPri vateBrowsingService).privateBrowsingEnabled; 752 this.enabled = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPri vateBrowsingService).privateBrowsingEnabled;
727 Services.obs.addObserver(this, "private-browsing", true); 753 Services.obs.addObserver(this, "private-browsing", true);
728 onShutdown.add(function() 754 onShutdown.add(function()
729 { 755 {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 else if (this.wantObj === false && val) 873 else if (this.wantObj === false && val)
848 this.curObj.push(val.replace(/\\\[/g, "[")); 874 this.curObj.push(val.replace(/\\\[/g, "["));
849 } 875 }
850 finally 876 finally
851 { 877 {
852 Filter.knownFilters = origKnownFilters; 878 Filter.knownFilters = origKnownFilters;
853 Subscription.knownSubscriptions = origKnownSubscriptions; 879 Subscription.knownSubscriptions = origKnownSubscriptions;
854 } 880 }
855 } 881 }
856 }; 882 };
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