From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- tools/quitter/Makefile.in | 6 +++ tools/quitter/QuitterObserver.js | 70 ++++++++++++++++++++++++++++++++++ tools/quitter/chrome.manifest | 4 ++ tools/quitter/contentscript.js | 37 ++++++++++++++++++ tools/quitter/install.rdf | 35 +++++++++++++++++ tools/quitter/jar.mn | 3 ++ tools/quitter/moz.build | 21 ++++++++++ tools/quitter/quitter@mozilla.org.xpi | Bin 0 -> 6864 bytes 8 files changed, 176 insertions(+) create mode 100644 tools/quitter/Makefile.in create mode 100644 tools/quitter/QuitterObserver.js create mode 100644 tools/quitter/chrome.manifest create mode 100644 tools/quitter/contentscript.js create mode 100644 tools/quitter/install.rdf create mode 100644 tools/quitter/jar.mn create mode 100644 tools/quitter/moz.build create mode 100644 tools/quitter/quitter@mozilla.org.xpi (limited to 'tools/quitter') diff --git a/tools/quitter/Makefile.in b/tools/quitter/Makefile.in new file mode 100644 index 000000000..bc0c0852c --- /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/QuitterObserver.js b/tools/quitter/QuitterObserver.js new file mode 100644 index 000000000..fe2a810c9 --- /dev/null +++ b/tools/quitter/QuitterObserver.js @@ -0,0 +1,70 @@ +/* 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/. */ + +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); +Components.utils.import("resource://gre/modules/Services.jsm"); + +const Cc = Components.classes; +const Ci = Components.interfaces; + +const CHILD_SCRIPT = "chrome://quitter/content/contentscript.js"; + +/* XPCOM gunk */ +function QuitterObserver() {} + +QuitterObserver.prototype = { + classDescription: "Quitter Observer for use in testing.", + classID: Components.ID("{c235a986-5ac1-4f28-ad73-825dae9bad90}"), + contractID: "@mozilla.org/quitter-observer;1", + QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver]), + _xpcom_categories: [{category: "profile-after-change", service: true }], + isFrameScriptLoaded: false, + + observe: function(aSubject, aTopic, aData) + { + if (aTopic == "profile-after-change") { + this.init(); + } else if (!this.isFrameScriptLoaded && + aTopic == "chrome-document-global-created") { + + var messageManager = Cc["@mozilla.org/globalmessagemanager;1"]. + getService(Ci.nsIMessageBroadcaster); + // Register for any messages our API needs us to handle + messageManager.addMessageListener("Quitter.Quit", this); + + messageManager.loadFrameScript(CHILD_SCRIPT, true); + this.isFrameScriptLoaded = true; + } else if (aTopic == "xpcom-shutdown") { + this.uninit(); + } + }, + + init: function() + { + var obs = Services.obs; + obs.addObserver(this, "xpcom-shutdown", false); + obs.addObserver(this, "chrome-document-global-created", false); + }, + + uninit: function() + { + var obs = Services.obs; + obs.removeObserver(this, "chrome-document-global-created", false); + }, + + /** + * messageManager callback function + * This will get requests from our API in the window and process them in chrome for it + **/ + receiveMessage: function(aMessage) { + switch(aMessage.name) { + case "Quitter.Quit": + let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup); + appStartup.quit(Ci.nsIAppStartup.eForceQuit); + break; + } + } +}; + +const NSGetFactory = XPCOMUtils.generateNSGetFactory([QuitterObserver]); diff --git a/tools/quitter/chrome.manifest b/tools/quitter/chrome.manifest new file mode 100644 index 000000000..b01f04655 --- /dev/null +++ b/tools/quitter/chrome.manifest @@ -0,0 +1,4 @@ +category profile-after-change @mozilla.org/quitter-observer;1 @mozilla.org/quitter-observer;1 +component {c235a986-5ac1-4f28-ad73-825dae9bad90} components/QuitterObserver.js +content quitter chrome/quitter/content/ +contract @mozilla.org/quitter-observer;1 {c235a986-5ac1-4f28-ad73-825dae9bad90} diff --git a/tools/quitter/contentscript.js b/tools/quitter/contentscript.js new file mode 100644 index 000000000..e25f5dbc8 --- /dev/null +++ b/tools/quitter/contentscript.js @@ -0,0 +1,37 @@ +/* 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/. */ + +var Ci = Components.interfaces; +var Cc = Components.classes; +var Cu = Components.utils; + +function Quitter() { +} + +Quitter.prototype = { + toString: function() { return "[Quitter]"; }, + quit: function() { sendSyncMessage('Quitter.Quit', {}); } +}; + +// This is a frame script, so it may be running in a content process. +// In any event, it is targeted at a specific "tab", so we listen for +// the DOMWindowCreated event to be notified about content windows +// being created in this context. + +function QuitterManager() { + addEventListener("DOMWindowCreated", this, false); +} + +QuitterManager.prototype = { + handleEvent: function handleEvent(aEvent) { + var quitter = new Quitter(window); + var window = aEvent.target.defaultView; + window.wrappedJSObject.Quitter = Cu.cloneInto({ + toString: quitter.toString.bind(quitter), + quit: quitter.quit.bind(quitter) + }, window, {cloneFunctions: true}); + } +}; + +var quittermanager = new QuitterManager(); diff --git a/tools/quitter/install.rdf b/tools/quitter/install.rdf new file mode 100644 index 000000000..184edfd2c --- /dev/null +++ b/tools/quitter/install.rdf @@ -0,0 +1,35 @@ + + + + + + quitter@mozilla.org + 2016.03.10 + 2 + + + + + + {ec8030f7-c20a-464f-9b0e-13a3a9e97384} + 45.0 + * + + + + + + {aa3c5121-dab2-40e2-81ca-7ea25febc110} + 45.0 + * + + + + + Quitter + Adds a quit method that content pages can use to quit the application. + Mozilla + + diff --git a/tools/quitter/jar.mn b/tools/quitter/jar.mn new file mode 100644 index 000000000..4467f923b --- /dev/null +++ b/tools/quitter/jar.mn @@ -0,0 +1,3 @@ +quitter.jar: +% content quitter %content/ + content/contentscript.js (contentscript.js) diff --git a/tools/quitter/moz.build b/tools/quitter/moz.build new file mode 100644 index 000000000..d58c0d7b4 --- /dev/null +++ b/tools/quitter/moz.build @@ -0,0 +1,21 @@ +# -*- 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/. + +EXTRA_COMPONENTS += [ + 'QuitterObserver.js', +] + +XPI_NAME = 'quitter' + +JAR_MANIFESTS += ['jar.mn'] + +USE_EXTENSION_MANIFEST = True +NO_JS_MANIFEST = True + +FINAL_TARGET_FILES += [ + 'chrome.manifest', + 'install.rdf', +] diff --git a/tools/quitter/quitter@mozilla.org.xpi b/tools/quitter/quitter@mozilla.org.xpi new file mode 100644 index 000000000..a8a6b8ad0 Binary files /dev/null and b/tools/quitter/quitter@mozilla.org.xpi differ -- cgit v1.2.3