Bug 1579935 - WebExt API: Add browser.experiments.urlbar.restartBrowser. r=adw,mixedpuppy
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 15 Nov 2019 09:17:30 +0000
changeset 502124 94f7a68264785b8866adf35061a3c19804ca2ab2
parent 502123 58992c594ec72fb65591fe9088e207ef9e6e8cb1
child 502125 f6bcd354c056b2a8cabae55a656fb0f38eb01664
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, mixedpuppy
bugs1579935
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1579935 - WebExt API: Add browser.experiments.urlbar.restartBrowser. r=adw,mixedpuppy Differential Revision: https://phabricator.services.mozilla.com/D53051
browser/components/urlbar/tests/ext/api.js
browser/components/urlbar/tests/ext/schema.json
--- a/browser/components/urlbar/tests/ext/api.js
+++ b/browser/components/urlbar/tests/ext/api.js
@@ -116,13 +116,37 @@ this.experiments_urlbar = class extends 
             if (updateManager.updateCount) {
               let update = updateManager.getUpdateAt(0);
               return update.installDate;
             }
             // Fall back to the profile age.
             let age = await ProfileAge();
             return (await age.firstUse) || age.created;
           },
+
+          restartBrowser() {
+            // Notify all windows that an application quit has been requested.
+            let cancelQuit = Cc[
+              "@mozilla.org/supports-PRBool;1"
+            ].createInstance(Ci.nsISupportsPRBool);
+            Services.obs.notifyObservers(
+              cancelQuit,
+              "quit-application-requested",
+              "restart"
+            );
+            // Something aborted the quit process.
+            if (cancelQuit.data) {
+              return;
+            }
+            // If already in safe mode restart in safe mode.
+            if (Services.appinfo.inSafeMode) {
+              Services.startup.restartInSafeMode(Ci.nsIAppStartup.eAttemptQuit);
+            } else {
+              Services.startup.quit(
+                Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart
+              );
+            }
+          },
         },
       },
     };
   }
 };
--- a/browser/components/urlbar/tests/ext/schema.json
+++ b/browser/components/urlbar/tests/ext/schema.json
@@ -18,12 +18,20 @@
         "parameters": []
       },
       {
         "name": "lastBrowserUpdateDate",
         "type": "function",
         "async": true,
         "description": "Returns the date of the last browser update. If there's no update history, then the date the profile was first used is returned instead. The return value is milliseconds since 1 January 1970 UTC (i.e., suitable for passing to <code>new Date()</code>).",
         "parameters": []
+      },
+      {
+        "name": "restartBrowser",
+        "type": "function",
+        "async": true,
+        "description": "Restarts the application.",
+        "requireUserInput": true,
+        "parameters": []
       }
     ]
   }
 ]