summaryrefslogtreecommitdiffstats
path: root/tools/quitter
diff options
context:
space:
mode:
Diffstat (limited to 'tools/quitter')
-rw-r--r--tools/quitter/.eslintrc.js11
-rw-r--r--tools/quitter/Makefile.in6
-rw-r--r--tools/quitter/background.js13
-rw-r--r--tools/quitter/contentscript.js21
-rw-r--r--tools/quitter/manifest.json34
-rw-r--r--tools/quitter/moz.build17
-rw-r--r--tools/quitter/parent.js27
-rw-r--r--tools/quitter/quitter@mozilla.org.xpibin0 -> 7388 bytes
-rw-r--r--tools/quitter/schema.json13
9 files changed, 142 insertions, 0 deletions
diff --git a/tools/quitter/.eslintrc.js b/tools/quitter/.eslintrc.js
new file mode 100644
index 0000000000..ca92008960
--- /dev/null
+++ b/tools/quitter/.eslintrc.js
@@ -0,0 +1,11 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+module.exports = {
+ globals: {
+ cloneInto: true,
+ },
+};
diff --git a/tools/quitter/Makefile.in b/tools/quitter/Makefile.in
new file mode 100644
index 0000000000..bc0c0852cf
--- /dev/null
+++ b/tools/quitter/Makefile.in
@@ -0,0 +1,6 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+XPI_PKGNAME = quitter@mozilla.org
diff --git a/tools/quitter/background.js b/tools/quitter/background.js
new file mode 100644
index 0000000000..a915d953f9
--- /dev/null
+++ b/tools/quitter/background.js
@@ -0,0 +1,13 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/* eslint-env webextensions */
+
+browser.runtime.onMessage.addListener(msg => {
+ if (msg === "quit") {
+ browser.quitter.quit();
+ }
+});
diff --git a/tools/quitter/contentscript.js b/tools/quitter/contentscript.js
new file mode 100644
index 0000000000..b0cfc70313
--- /dev/null
+++ b/tools/quitter/contentscript.js
@@ -0,0 +1,21 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/* eslint-env webextensions */
+
+const Quitter = {
+ async quit() {
+ // This can be called before the background page has loaded,
+ // so we need to wait for it.
+ browser.runtime.sendMessage("quit").catch(() => {
+ setTimeout(Quitter.quit, 100);
+ });
+ },
+};
+
+window.wrappedJSObject.Quitter = cloneInto(Quitter, window, {
+ cloneFunctions: true,
+});
diff --git a/tools/quitter/manifest.json b/tools/quitter/manifest.json
new file mode 100644
index 0000000000..de7f5a6732
--- /dev/null
+++ b/tools/quitter/manifest.json
@@ -0,0 +1,34 @@
+{
+ "manifest_version": 2,
+
+ "applications": {
+ "gecko": {"id": "quitter@mozilla.org"}
+ },
+
+ "name": "Quitter",
+ "description": "Quit",
+ "version": "2019.12.03",
+ "author": "Mozilla",
+
+ "background": {
+ "scripts": ["background.js"]
+ },
+
+ "content_scripts": [{
+ "js": ["contentscript.js"],
+ "run_at": "document_start",
+ "match_about_blank": true,
+ "matches": ["<all_urls>"]
+ }],
+
+ "experiment_apis": {
+ "quitter": {
+ "schema": "schema.json",
+ "parent": {
+ "scopes": ["addon_parent"],
+ "script": "parent.js",
+ "paths": [["quitter", "quit"]]
+ }
+ }
+ }
+}
diff --git a/tools/quitter/moz.build b/tools/quitter/moz.build
new file mode 100644
index 0000000000..d782493355
--- /dev/null
+++ b/tools/quitter/moz.build
@@ -0,0 +1,17 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+XPI_NAME = "quitter"
+
+USE_EXTENSION_MANIFEST = True
+
+FINAL_TARGET_FILES += [
+ "background.js",
+ "contentscript.js",
+ "manifest.json",
+ "parent.js",
+ "schema.json",
+]
diff --git a/tools/quitter/parent.js b/tools/quitter/parent.js
new file mode 100644
index 0000000000..a79583c3d4
--- /dev/null
+++ b/tools/quitter/parent.js
@@ -0,0 +1,27 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/* globals ExtensionAPI */
+
+const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+this.quitter = class extends ExtensionAPI {
+ getAPI(context) {
+ return {
+ quitter: {
+ async quit() {
+ let browserWindow = Services.wm.getMostRecentWindow(
+ "navigator:browser"
+ );
+ if (browserWindow && browserWindow.gBrowserInit) {
+ await browserWindow.gBrowserInit.idleTasksFinishedPromise;
+ }
+ Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
+ },
+ },
+ };
+ }
+};
diff --git a/tools/quitter/quitter@mozilla.org.xpi b/tools/quitter/quitter@mozilla.org.xpi
new file mode 100644
index 0000000000..abf86b7914
--- /dev/null
+++ b/tools/quitter/quitter@mozilla.org.xpi
Binary files differ
diff --git a/tools/quitter/schema.json b/tools/quitter/schema.json
new file mode 100644
index 0000000000..4c2e6fc86d
--- /dev/null
+++ b/tools/quitter/schema.json
@@ -0,0 +1,13 @@
+[
+ {
+ "namespace": "quitter",
+ "functions": [
+ {
+ "name": "quit",
+ "type": "function",
+ "async": true,
+ "parameters": []
+ }
+ ]
+ }
+]