Bug 722977 - Tabs engine uses global Svc.Private to make decisions based on private browsing state; r=ehsan,gps,rnewman

This commit is contained in:
Andres Hernandez 2012-11-19 14:44:07 -06:00
Родитель 2fcc0a1c8b
Коммит 0478694ccb
2 изменённых файлов: 42 добавлений и 20 удалений

Просмотреть файл

@ -54,9 +54,13 @@ sync_engine_modules := \
history.js \ history.js \
passwords.js \ passwords.js \
prefs.js \ prefs.js \
tabs.js \
$(NULL) $(NULL)
# Preprocess engine files.
SYNC_PP_ENGINE := modules/engines/tabs.js
SYNC_PP_ENGINE_PATH = $(FINAL_TARGET)/modules/services-sync/engines
PP_TARGETS += SYNC_PP_ENGINE
sync_stage_modules := \ sync_stage_modules := \
cluster.js \ cluster.js \
enginesync.js \ enginesync.js \

Просмотреть файл

@ -18,13 +18,8 @@ Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/constants.js"); Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-common/preferences.js"); Cu.import("resource://services-common/preferences.js");
// It is safer to inspect the private browsing preferences rather than XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
// the flags of nsIPrivateBrowsingService. The user may have turned on "resource://gre/modules/PrivateBrowsingUtils.jsm");
// "Never remember history" in the same session, or Firefox was started
// with the -private command line argument. In both cases, the
// "autoStarted" flag of nsIPrivateBrowsingService will be wrong.
const PBPrefs = new Preferences("browser.privatebrowsing.");
this.TabSetRecord = function TabSetRecord(collection, id) { this.TabSetRecord = function TabSetRecord(collection, id) {
CryptoWrapper.call(this, collection, id); CryptoWrapper.call(this, collection, id);
@ -128,6 +123,9 @@ TabStore.prototype = {
let currentState = JSON.parse(Svc.Session.getBrowserState()); let currentState = JSON.parse(Svc.Session.getBrowserState());
let tabLastUsed = this.tabLastUsed; let tabLastUsed = this.tabLastUsed;
currentState.windows.forEach(function(window) { currentState.windows.forEach(function(window) {
if (window.isPrivate) {
return;
}
window.tabs.forEach(function(tab) { window.tabs.forEach(function(tab) {
// Make sure there are history entries to look at. // Make sure there are history entries to look at.
if (!tab.entries.length) if (!tab.entries.length)
@ -159,12 +157,6 @@ TabStore.prototype = {
let record = new TabSetRecord(collection, id); let record = new TabSetRecord(collection, id);
record.clientName = this.engine.service.clientsEngine.localName; record.clientName = this.engine.service.clientsEngine.localName;
// Don't provide any tabs to compare against and ignore the update later.
if (Svc.Private && Svc.Private.privateBrowsingEnabled && !PBPrefs.get("autostart")) {
record.tabs = [];
return record;
}
// Sort tabs in descending-used order to grab the most recently used // Sort tabs in descending-used order to grab the most recently used
let tabs = this.getAllTabs(true).sort(function(a, b) { let tabs = this.getAllTabs(true).sort(function(a, b) {
return b.lastUsed - a.lastUsed; return b.lastUsed - a.lastUsed;
@ -195,10 +187,26 @@ TabStore.prototype = {
}, },
getAllIDs: function TabStore_getAllIds() { getAllIDs: function TabStore_getAllIds() {
// Don't report any tabs if we're in private browsing for first syncs. // Don't report any tabs if all windows are in private browsing for
// first syncs.
let ids = {}; let ids = {};
if (Svc.Private && Svc.Private.privateBrowsingEnabled && !PBPrefs.get("autostart")) let allWindowsArePrivate = false;
let wins = Services.wm.getEnumerator("navigator:browser");
while (wins.hasMoreElements()) {
if (PrivateBrowsingUtils.isWindowPrivate(wins.getNext())) {
// Ensure that at least there is a private window.
allWindowsArePrivate = true;
} else {
// If there is a not private windown then finish and continue.
allWindowsArePrivate = false;
break;
}
}
if (allWindowsArePrivate &&
!PrivateBrowsingUtils.permanentPrivateBrowsing) {
return ids; return ids;
}
ids[this.engine.service.clientsEngine.localID] = true; ids[this.engine.service.clientsEngine.localID] = true;
return ids; return ids;
@ -280,7 +288,9 @@ TabTracker.prototype = {
switch (aTopic) { switch (aTopic) {
case "weave:engine:start-tracking": case "weave:engine:start-tracking":
if (!this._enabled) { if (!this._enabled) {
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
Svc.Obs.add("private-browsing", this); Svc.Obs.add("private-browsing", this);
#endif
Svc.Obs.add("domwindowopened", this); Svc.Obs.add("domwindowopened", this);
let wins = Services.wm.getEnumerator("navigator:browser"); let wins = Services.wm.getEnumerator("navigator:browser");
while (wins.hasMoreElements()) while (wins.hasMoreElements())
@ -290,7 +300,9 @@ TabTracker.prototype = {
break; break;
case "weave:engine:stop-tracking": case "weave:engine:stop-tracking":
if (this._enabled) { if (this._enabled) {
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
Svc.Obs.remove("private-browsing", this); Svc.Obs.remove("private-browsing", this);
#endif
Svc.Obs.remove("domwindowopened", this); Svc.Obs.remove("domwindowopened", this);
let wins = Services.wm.getEnumerator("navigator:browser"); let wins = Services.wm.getEnumerator("navigator:browser");
while (wins.hasMoreElements()) while (wins.hasMoreElements())
@ -307,16 +319,22 @@ TabTracker.prototype = {
self._registerListenersForWindow(aSubject); self._registerListenersForWindow(aSubject);
}, false); }, false);
break; break;
#ifndef MOZ_PER_WINDOW_PRIVATE_BROWSING
case "private-browsing": case "private-browsing":
if (aData == "enter" && !PBPrefs.get("autostart")) if (aData == "enter" && !PrivateBrowsingUtils.permanentPrivateBrowsing)
this.modified = false; this.modified = false;
#endif
} }
}, },
onTab: function onTab(event) { onTab: function onTab(event) {
if (Svc.Private && Svc.Private.privateBrowsingEnabled && !PBPrefs.get("autostart")) { if (event.originalTarget.linkedBrowser) {
this._log.trace("Ignoring tab event from private browsing."); let win = event.originalTarget.linkedBrowser.contentWindow;
return; if (PrivateBrowsingUtils.isWindowPrivate(win) &&
!PrivateBrowsingUtils.permanentPrivateBrowsing) {
this._log.trace("Ignoring tab event from private browsing.");
return;
}
} }
this._log.trace("onTab event: " + event.type); this._log.trace("onTab event: " + event.type);