зеркало из https://github.com/mozilla/gecko-dev.git
Bug 587031 - Entering/Exiting Private Browsing mode from within Tab Candy (Panorama) is presently ambiguous r=dietrich, a=blocking
--HG-- extra : rebase_source : 2ad0935dc80b84961314750f04d08e1309f968b6
This commit is contained in:
Родитель
7f88957325
Коммит
c4b4d99b8a
|
@ -145,13 +145,14 @@ let Storage = {
|
|||
// Returns the data for all groupItems associated with the given window.
|
||||
readGroupItemData: function Storage_readGroupItemData(win) {
|
||||
var existingData = {};
|
||||
let data;
|
||||
try {
|
||||
existingData = JSON.parse(
|
||||
this._sessionStore.getWindowValue(win, this.GROUP_DATA_IDENTIFIER)
|
||||
);
|
||||
data = this._sessionStore.getWindowValue(win, this.GROUP_DATA_IDENTIFIER);
|
||||
if (data)
|
||||
existingData = JSON.parse(data);
|
||||
} catch (e) {
|
||||
// getWindowValue will fail if the property doesn't exist
|
||||
Utils.log("Error in readGroupItemData: "+e);
|
||||
Utils.log("Error in readGroupItemData: "+e, data);
|
||||
}
|
||||
return existingData;
|
||||
},
|
||||
|
|
|
@ -38,6 +38,11 @@ XPCOMUtils.defineLazyGetter(this, "gPrefBranch", function() {
|
|||
getBranch("browser.panorama.");
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gPrivateBrowsing", function() {
|
||||
return Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
});
|
||||
|
||||
# NB: Certain files need to evaluate before others
|
||||
|
||||
#include iq.js
|
||||
|
|
|
@ -88,6 +88,17 @@ let UI = {
|
|||
// An array of functions to be called at uninit time
|
||||
_cleanupFunctions: [],
|
||||
|
||||
// Variable: _privateBrowsing
|
||||
// Keeps track of info related to private browsing, including:
|
||||
// transitionStage - what step we're on in entering/exiting PB
|
||||
// transitionMode - whether we're entering or exiting PB
|
||||
// wasInTabView - whether TabView was visible before we went into PB
|
||||
_privateBrowsing: {
|
||||
transitionStage: 0,
|
||||
transitionMode: "",
|
||||
wasInTabView: false
|
||||
},
|
||||
|
||||
// ----------
|
||||
// Function: init
|
||||
// Must be called after the object is created.
|
||||
|
@ -461,6 +472,67 @@ let UI = {
|
|||
_addTabActionHandlers: function UI__addTabActionHandlers() {
|
||||
var self = this;
|
||||
|
||||
// session restore
|
||||
function srObserver(aSubject, aTopic, aData) {
|
||||
if (aTopic != "sessionstore-browser-state-restored")
|
||||
return;
|
||||
|
||||
// if we're transitioning into/out of private browsing, update appropriately
|
||||
if (self._privateBrowsing.transitionStage == 1)
|
||||
self._privateBrowsing.transitionStage = 2;
|
||||
else if (self._privateBrowsing.transitionStage == 3) {
|
||||
if (self._privateBrowsing.transitionMode == "exit" &&
|
||||
self._privateBrowsing.wasInTabView)
|
||||
self.showTabView(false);
|
||||
|
||||
self._privateBrowsing.transitionStage = 0;
|
||||
self._privateBrowsing.transitionMode = "";
|
||||
}
|
||||
}
|
||||
|
||||
Services.obs.addObserver(srObserver, "sessionstore-browser-state-restored", false);
|
||||
|
||||
this._cleanupFunctions.push(function() {
|
||||
Services.obs.removeObserver(srObserver, "sessionstore-browser-state-restored");
|
||||
});
|
||||
|
||||
// Private Browsing:
|
||||
// We keep track of the transition to/from PB with the transitionStage
|
||||
// and transitionMode properties of _privateBrowsing. The stage is 0 if
|
||||
// not transitioning, 1 if just started ("change-granted"), 2 after the
|
||||
// first sessionrestore, 3 after the "private-browsing" notification, and
|
||||
// then back to 0 after the second sessionrestore. The mode is "" if not
|
||||
// transitioning, otherwise it's "enter" or "exit" as appropriate. When
|
||||
// transitioning to PB, we exit Panorama if necessary (making note of the
|
||||
// fact that we were there so we can return after PB) and make sure we
|
||||
// don't reenter Panorama due to all of the session restore tab
|
||||
// manipulation (which otherwise we might). When transitioning away from
|
||||
// PB, we reenter Panorama if we had been there directly before PB.
|
||||
function pbObserver(aSubject, aTopic, aData) {
|
||||
if (aTopic == "private-browsing") {
|
||||
self._privateBrowsing.transitionStage = 3;
|
||||
if (aData == "enter") {
|
||||
// If we are in Tab View, exit.
|
||||
self._privateBrowsing.wasInTabView = self._isTabViewVisible();
|
||||
if (self._isTabViewVisible())
|
||||
self.goToTab(gBrowser.selectedTab);
|
||||
}
|
||||
} else if (aTopic == "private-browsing-change-granted") {
|
||||
if (aData == "enter" || aData == "exit") {
|
||||
self._privateBrowsing.transitionStage = 1;
|
||||
self._privateBrowsing.transitionMode = aData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Services.obs.addObserver(pbObserver, "private-browsing", false);
|
||||
Services.obs.addObserver(pbObserver, "private-browsing-change-granted", false);
|
||||
|
||||
this._cleanupFunctions.push(function() {
|
||||
Services.obs.removeObserver(pbObserver, "private-browsing");
|
||||
Services.obs.removeObserver(pbObserver, "private-browsing-change-granted");
|
||||
});
|
||||
|
||||
// TabOpen
|
||||
this._eventListeners.open = function(tab) {
|
||||
if (tab.ownerDocument.defaultView != gWindow)
|
||||
|
@ -485,6 +557,11 @@ let UI = {
|
|||
if (self._currentTab == tab)
|
||||
self._closedSelectedTabInTabView = true;
|
||||
} else {
|
||||
// If we're currently in the process of entering private browsing,
|
||||
// we don't want to go to the Tab View UI.
|
||||
if (self._privateBrowsing.transitionStage > 0)
|
||||
return;
|
||||
|
||||
// if not closing the last tab
|
||||
if (gBrowser.tabs.length > 1) {
|
||||
// Don't return to TabView if there are any app tabs
|
||||
|
|
|
@ -61,6 +61,7 @@ _BROWSER_FILES = \
|
|||
browser_tabview_launch.js \
|
||||
browser_tabview_multiwindow_search.js \
|
||||
browser_tabview_orphaned_tabs.js \
|
||||
browser_tabview_privatebrowsing.js \
|
||||
browser_tabview_search.js \
|
||||
browser_tabview_snapping.js \
|
||||
browser_tabview_startup_transitions.js \
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is tabview private browsing test.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Raymond Lee <raymond@appcoast.com>
|
||||
* Ian Gilman <ian@iangilman.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
let normalURLs = [];
|
||||
let pbTabURL = "about:privatebrowsing";
|
||||
|
||||
let pb = Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
|
||||
// -----------
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
// Establish initial state
|
||||
is(gBrowser.tabs.length, 1, "we start with 1 tab");
|
||||
|
||||
// Create a second tab
|
||||
gBrowser.addTab("about:robots");
|
||||
is(gBrowser.tabs.length, 2, "we now have 2 tabs");
|
||||
|
||||
afterAllTabsLoaded(function() {
|
||||
// Get normal tab urls
|
||||
for (let a = 0; a < gBrowser.tabs.length; a++) {
|
||||
normalURLs.push(gBrowser.tabs[a].linkedBrowser.currentURI.spec);
|
||||
}
|
||||
|
||||
// Go into Tab View
|
||||
window.addEventListener("tabviewshown", onTabViewLoadedAndShown, false);
|
||||
TabView.toggle();
|
||||
});
|
||||
}
|
||||
|
||||
// -----------
|
||||
function onTabViewLoadedAndShown() {
|
||||
window.removeEventListener("tabviewshown", onTabViewLoadedAndShown, false);
|
||||
ok(TabView.isVisible(), "Tab View is visible");
|
||||
|
||||
// go into private browsing and make sure Tab View becomes hidden
|
||||
pb.privateBrowsingEnabled = true;
|
||||
ok(!TabView.isVisible(), "Tab View is no longer visible");
|
||||
afterAllTabsLoaded(function() {
|
||||
verifyPB();
|
||||
|
||||
// exit private browsing and make sure Tab View is shown again
|
||||
pb.privateBrowsingEnabled = false;
|
||||
ok(TabView.isVisible(), "Tab View is visible again");
|
||||
afterAllTabsLoaded(function() {
|
||||
verifyNormal();
|
||||
|
||||
// exit Tab View
|
||||
window.addEventListener("tabviewhidden", onTabViewHidden, false);
|
||||
TabView.toggle();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// -----------
|
||||
function onTabViewHidden() {
|
||||
window.removeEventListener("tabviewhidden", onTabViewHidden, false);
|
||||
ok(!TabView.isVisible(), "Tab View is not visible");
|
||||
|
||||
// go into private browsing and make sure Tab View remains hidden
|
||||
pb.privateBrowsingEnabled = true;
|
||||
ok(!TabView.isVisible(), "Tab View is still not visible");
|
||||
afterAllTabsLoaded(function() {
|
||||
verifyPB();
|
||||
|
||||
// turn private browsing back off
|
||||
pb.privateBrowsingEnabled = false;
|
||||
afterAllTabsLoaded(function() {
|
||||
verifyNormal();
|
||||
|
||||
// clean up
|
||||
gBrowser.removeTab(gBrowser.tabs[1]);
|
||||
|
||||
is(gBrowser.tabs.length, 1, "we finish with one tab");
|
||||
ok(!pb.privateBrowsingEnabled, "we finish with private browsing off");
|
||||
ok(!TabView.isVisible(), "we finish with Tab View not visible");
|
||||
|
||||
finish();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ----------
|
||||
function verifyPB() {
|
||||
ok(pb.privateBrowsingEnabled == true, "private browsing is on");
|
||||
is(gBrowser.tabs.length, 1, "we have 1 tab in private browsing");
|
||||
|
||||
let browser = gBrowser.tabs[0].linkedBrowser;
|
||||
is(browser.currentURI.spec, pbTabURL, "correct URL for private browsing");
|
||||
}
|
||||
|
||||
// ----------
|
||||
function verifyNormal() {
|
||||
ok(pb.privateBrowsingEnabled == false, "private browsing is off");
|
||||
|
||||
let count = gBrowser.tabs.length;
|
||||
is(count, 2, "we have 2 tabs in normal mode");
|
||||
|
||||
for (let a = 0; a < count; a++) {
|
||||
let browser = gBrowser.tabs[a].linkedBrowser;
|
||||
is(browser.currentURI.spec, normalURLs[a], "correct URL for normal mode");
|
||||
}
|
||||
}
|
||||
|
||||
// ----------
|
||||
function afterAllTabsLoaded(callback) {
|
||||
let stillToLoad = 0;
|
||||
function onLoad() {
|
||||
this.removeEventListener("load", onLoad, true);
|
||||
|
||||
stillToLoad--;
|
||||
if (!stillToLoad)
|
||||
callback();
|
||||
}
|
||||
|
||||
for (let a = 0; a < gBrowser.tabs.length; a++) {
|
||||
let browser = gBrowser.tabs[a].linkedBrowser;
|
||||
if (browser.webProgress.isLoadingDocument) {
|
||||
stillToLoad++;
|
||||
browser.addEventListener("load", onLoad, true);
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче