tools/quitter/contentscript.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/quitter/contentscript.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,38 @@
     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 +var Ci = Components.interfaces;
     1.9 +var Cc = Components.classes;
    1.10 +
    1.11 +function Quitter() {
    1.12 +}
    1.13 +
    1.14 +Quitter.prototype = {
    1.15 +  toString: function() { return "[Quitter]"; },
    1.16 +  quit: function() {
    1.17 +    sendSyncMessage('Quitter.Quit', {});
    1.18 +  },
    1.19 +  __exposedProps__: {
    1.20 +    'toString': 'r',
    1.21 +    'quit': 'r'
    1.22 +  }
    1.23 +};
    1.24 +
    1.25 +// This is a frame script, so it may be running in a content process.
    1.26 +// In any event, it is targeted at a specific "tab", so we listen for
    1.27 +// the DOMWindowCreated event to be notified about content windows
    1.28 +// being created in this context.
    1.29 +
    1.30 +function QuitterManager() {
    1.31 +  addEventListener("DOMWindowCreated", this, false);
    1.32 +}
    1.33 +
    1.34 +QuitterManager.prototype = {
    1.35 +  handleEvent: function handleEvent(aEvent) {
    1.36 +    var window = aEvent.target.defaultView;
    1.37 +    window.wrappedJSObject.Quitter = new Quitter(window);
    1.38 +  }
    1.39 +};
    1.40 +
    1.41 +var quittermanager = new QuitterManager();

mercurial