зеркало из https://github.com/mozilla/gecko-dev.git
Bug 591801: Create a fake session history for the cases where the add-ons manager runs in its own window. r=Unfocused, a=blocks-betaN
This commit is contained in:
Родитель
03b8ae8fda
Коммит
3699ad3ed8
|
@ -98,16 +98,14 @@ XPCOMUtils.defineLazyGetter(gStrings, "appVersion", function() {
|
||||||
return Services.appinfo.version;
|
return Services.appinfo.version;
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("load", initialize, false);
|
document.addEventListener("load", initialize, true);
|
||||||
window.addEventListener("unload", shutdown, false);
|
window.addEventListener("unload", shutdown, false);
|
||||||
window.addEventListener("popstate", function(event) {
|
|
||||||
gViewController.statePopped(event);
|
|
||||||
}, false);
|
|
||||||
|
|
||||||
var gPendingInitializations = 1;
|
var gPendingInitializations = 1;
|
||||||
__defineGetter__("gIsInitializing", function() gPendingInitializations > 0);
|
__defineGetter__("gIsInitializing", function() gPendingInitializations > 0);
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
|
document.removeEventListener("load", initialize, true);
|
||||||
gCategories.initialize();
|
gCategories.initialize();
|
||||||
gHeader.initialize();
|
gHeader.initialize();
|
||||||
gViewController.initialize();
|
gViewController.initialize();
|
||||||
|
@ -144,6 +142,58 @@ function loadView(aViewId) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper around the HTML5 session history service that continues to work
|
||||||
|
* even if the window has session history disabled.
|
||||||
|
* Without session history it currently only tracks the previous state so
|
||||||
|
* the popState function works.
|
||||||
|
*/
|
||||||
|
var gHistory = {
|
||||||
|
states: [],
|
||||||
|
|
||||||
|
pushState: function(aState) {
|
||||||
|
try {
|
||||||
|
window.history.pushState(aState, document.title);
|
||||||
|
}
|
||||||
|
catch(e) {
|
||||||
|
while (this.states.length > 1)
|
||||||
|
this.states.shift();
|
||||||
|
this.states.push(aState);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
replaceState: function(aState) {
|
||||||
|
try {
|
||||||
|
window.history.replaceState(aState, document.title);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
this.states.pop();
|
||||||
|
this.states.push(aState);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
popState: function() {
|
||||||
|
// If there are no cached states then the session history must be working
|
||||||
|
if (this.states.length == 0) {
|
||||||
|
window.addEventListener("popstate", function(event) {
|
||||||
|
window.removeEventListener("popstate", arguments.callee, true);
|
||||||
|
// TODO To ensure we can't go forward again we put an additional entry
|
||||||
|
// for the current state into the history. Ideally we would just strip
|
||||||
|
// the history but there doesn't seem to be a way to do that. Bug 590661
|
||||||
|
window.history.pushState(event.state, document.title);
|
||||||
|
}, true);
|
||||||
|
window.history.back();
|
||||||
|
} else {
|
||||||
|
if (this.states.length < 2)
|
||||||
|
throw new Error("Cannot popState from this view");
|
||||||
|
|
||||||
|
this.states.pop();
|
||||||
|
let state = this.states[this.states.length - 1];
|
||||||
|
gViewController.statePopped({ state: state });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var gEventManager = {
|
var gEventManager = {
|
||||||
_listeners: {},
|
_listeners: {},
|
||||||
_installListeners: [],
|
_installListeners: [],
|
||||||
|
@ -348,6 +398,10 @@ var gViewController = {
|
||||||
view.initialize();
|
view.initialize();
|
||||||
|
|
||||||
window.controllers.appendController(this);
|
window.controllers.appendController(this);
|
||||||
|
|
||||||
|
window.addEventListener("popstate",
|
||||||
|
gViewController.statePopped.bind(gViewController),
|
||||||
|
false);
|
||||||
},
|
},
|
||||||
|
|
||||||
shutdown: function() {
|
shutdown: function() {
|
||||||
|
@ -407,7 +461,7 @@ var gViewController = {
|
||||||
if (aViewId == this.currentViewId)
|
if (aViewId == this.currentViewId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
window.history.pushState({
|
gHistory.pushState({
|
||||||
view: aViewId,
|
view: aViewId,
|
||||||
previousView: this.currentViewId
|
previousView: this.currentViewId
|
||||||
}, document.title);
|
}, document.title);
|
||||||
|
@ -415,7 +469,7 @@ var gViewController = {
|
||||||
},
|
},
|
||||||
|
|
||||||
loadInitialView: function(aViewId) {
|
loadInitialView: function(aViewId) {
|
||||||
window.history.replaceState({
|
gHistory.replaceState({
|
||||||
view: aViewId,
|
view: aViewId,
|
||||||
previousView: null
|
previousView: null
|
||||||
}, document.title);
|
}, document.title);
|
||||||
|
@ -459,20 +513,8 @@ var gViewController = {
|
||||||
|
|
||||||
// Moves back in the document history and removes the current history entry
|
// Moves back in the document history and removes the current history entry
|
||||||
popState: function(aCallback) {
|
popState: function(aCallback) {
|
||||||
this.viewChangeCallback = function() {
|
this.viewChangeCallback = aCallback;
|
||||||
// TODO To ensure we can't go forward again we put an additional entry for
|
gHistory.popState();
|
||||||
// the current page into the history. Ideally we would just strip the
|
|
||||||
// history but there doesn't seem to be a way to do that. Bug 590661
|
|
||||||
window.history.pushState({
|
|
||||||
view: gViewController.currentViewId,
|
|
||||||
previousView: gViewController.currentViewId
|
|
||||||
}, document.title);
|
|
||||||
this.updateCommands();
|
|
||||||
|
|
||||||
if (aCallback)
|
|
||||||
aCallback();
|
|
||||||
};
|
|
||||||
window.history.back();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
notifyViewChanged: function() {
|
notifyViewChanged: function() {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче