michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const { Cc, Ci, Cu } = require("chrome"); michael@0: const gcli = require("gcli/index"); michael@0: const Services = require("Services"); michael@0: michael@0: const BRAND_SHORT_NAME = Cc["@mozilla.org/intl/stringbundle;1"] michael@0: .getService(Ci.nsIStringBundleService) michael@0: .createBundle("chrome://branding/locale/brand.properties") michael@0: .GetStringFromName("brandShortName"); michael@0: michael@0: /** michael@0: * Restart command michael@0: * michael@0: * @param boolean nocache michael@0: * Disables loading content from cache upon restart. michael@0: * michael@0: * Examples : michael@0: * >> restart michael@0: * - restarts browser immediately michael@0: * >> restart --nocache michael@0: * - restarts immediately and starts Firefox without using cache michael@0: */ michael@0: exports.items = [ michael@0: { michael@0: name: "restart", michael@0: description: gcli.lookupFormat("restartBrowserDesc", [ BRAND_SHORT_NAME ]), michael@0: params: [ michael@0: { michael@0: name: "nocache", michael@0: type: "boolean", michael@0: description: gcli.lookup("restartBrowserNocacheDesc") michael@0: } michael@0: ], michael@0: returnType: "string", michael@0: exec: function Restart(args, context) { michael@0: let canceled = Cc["@mozilla.org/supports-PRBool;1"] michael@0: .createInstance(Ci.nsISupportsPRBool); michael@0: Services.obs.notifyObservers(canceled, "quit-application-requested", "restart"); michael@0: if (canceled.data) { michael@0: return gcli.lookup("restartBrowserRequestCancelled"); michael@0: } michael@0: michael@0: // disable loading content from cache. michael@0: if (args.nocache) { michael@0: Services.appinfo.invalidateCachesOnRestart(); michael@0: } michael@0: michael@0: // restart michael@0: Cc["@mozilla.org/toolkit/app-startup;1"] michael@0: .getService(Ci.nsIAppStartup) michael@0: .quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart); michael@0: return gcli.lookupFormat("restartBrowserRestarting", [ BRAND_SHORT_NAME ]); michael@0: } michael@0: } michael@0: ];