1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/gcli/commands/restart.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,60 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +const { Cc, Ci, Cu } = require("chrome"); 1.11 +const gcli = require("gcli/index"); 1.12 +const Services = require("Services"); 1.13 + 1.14 +const BRAND_SHORT_NAME = Cc["@mozilla.org/intl/stringbundle;1"] 1.15 + .getService(Ci.nsIStringBundleService) 1.16 + .createBundle("chrome://branding/locale/brand.properties") 1.17 + .GetStringFromName("brandShortName"); 1.18 + 1.19 +/** 1.20 + * Restart command 1.21 + * 1.22 + * @param boolean nocache 1.23 + * Disables loading content from cache upon restart. 1.24 + * 1.25 + * Examples : 1.26 + * >> restart 1.27 + * - restarts browser immediately 1.28 + * >> restart --nocache 1.29 + * - restarts immediately and starts Firefox without using cache 1.30 + */ 1.31 +exports.items = [ 1.32 + { 1.33 + name: "restart", 1.34 + description: gcli.lookupFormat("restartBrowserDesc", [ BRAND_SHORT_NAME ]), 1.35 + params: [ 1.36 + { 1.37 + name: "nocache", 1.38 + type: "boolean", 1.39 + description: gcli.lookup("restartBrowserNocacheDesc") 1.40 + } 1.41 + ], 1.42 + returnType: "string", 1.43 + exec: function Restart(args, context) { 1.44 + let canceled = Cc["@mozilla.org/supports-PRBool;1"] 1.45 + .createInstance(Ci.nsISupportsPRBool); 1.46 + Services.obs.notifyObservers(canceled, "quit-application-requested", "restart"); 1.47 + if (canceled.data) { 1.48 + return gcli.lookup("restartBrowserRequestCancelled"); 1.49 + } 1.50 + 1.51 + // disable loading content from cache. 1.52 + if (args.nocache) { 1.53 + Services.appinfo.invalidateCachesOnRestart(); 1.54 + } 1.55 + 1.56 + // restart 1.57 + Cc["@mozilla.org/toolkit/app-startup;1"] 1.58 + .getService(Ci.nsIAppStartup) 1.59 + .quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart); 1.60 + return gcli.lookupFormat("restartBrowserRestarting", [ BRAND_SHORT_NAME ]); 1.61 + } 1.62 + } 1.63 +];