mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
b=338039, p=zeniko, r=enndeakin. Provide easy, right way to restart an application.
This commit is contained in:
parent
4ed43f101a
commit
49182a7674
@ -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 \
|
||||
|
21
browser/fuel/test/browser_ApplicationQuitting.js
Normal file
21
browser/fuel/test/browser_ApplicationQuitting.js
Normal 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);
|
||||
}
|
@ -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])
|
||||
};
|
||||
|
@ -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();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user