b=338039, p=zeniko, r=enndeakin. Provide easy, right way to restart an application.

This commit is contained in:
Simon Bunzli 2008-09-06 23:30:13 -05:00
parent 4ed43f101a
commit 49182a7674
4 changed files with 60 additions and 1 deletions

View File

@ -47,6 +47,7 @@ include $(topsrcdir)/config/rules.mk
_BROWSER_FILES =browser_Application.js \
browser_ApplicationPrefs.js \
browser_ApplicationStorage.js \
browser_ApplicationQuitting.js \
browser_Browser.js \
browser_Bookmarks.js \
ContentA.html \

View File

@ -0,0 +1,21 @@
function test() {
let quitRequestObserver = {
observe: function(aSubject, aTopic, aData) {
ok(aTopic == "quit-application-requested" &&
aSubject instanceof Components.interfaces.nsISupportsPRBool,
"Received a quit request we're going to deny");
aSubject.data = true;
}
};
// ensure that we don't accidentally quit
let os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.addObserver(quitRequestObserver, "quit-application-requested", false);
ok(!Application.quit(), "Tried to quit - and didn't succeed");
ok(!Application.restart(), "Tried to restart - and didn't succeed");
// clean up
os.removeObserver(quitRequestObserver, "quit-application-requested", false);
}

View File

@ -685,5 +685,30 @@ extApplication.prototype = {
return this._events;
},
// helper method for correct quitting/restarting
_quitWithFlags: function app__quitWithFlags(aFlags) {
let os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
let cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
.createInstance(Components.interfaces.nsISupportsPRBool);
os.notifyObservers(cancelQuit, "quit-application-requested", null);
if (cancelQuit.data)
return false; // somebody canceled our quit request
let appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1']
.getService(Components.interfaces.nsIAppStartup);
appStartup.quit(aFlags);
return true;
},
quit: function app_quit() {
return this._quitWithFlags(Components.interfaces.nsIAppStartup.eAttemptQuit);
},
restart: function app_restart() {
return this._quitWithFlags(Components.interfaces.nsIAppStartup.eAttemptQuit |
Components.interfaces.nsIAppStartup.eRestart);
},
QueryInterface : XPCOMUtils.generateQI([Ci.extIApplication, Ci.nsISupportsWeakReference])
};

View File

@ -382,7 +382,7 @@ interface extISessionStorage : nsISupports
nsIVariant get(in AString aName, in nsIVariant aDefaultValue);
};
[scriptable, uuid(ba9442ee-7070-44fb-8157-c111e1fa70b6)]
[scriptable, uuid(e53d6610-7468-11dd-ad8b-0800200c9a66)]
interface extIApplication : nsISupports
{
/**
@ -427,4 +427,16 @@ interface extIApplication : nsISupports
* supports: "load", "ready", "quit", "unload"
*/
readonly attribute extIEvents events;
/**
* Quits the application (if nobody objects to quit-application-requested).
* @returns whether quitting will proceed
*/
boolean quit();
/**
* Restarts the application (if nobody objects to quit-application-requested).
* @returns whether restarting will proceed
*/
boolean restart();
};