contentscript.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. var Ci = Components.interfaces;
  5. var Cc = Components.classes;
  6. var Cu = Components.utils;
  7. function Quitter() {
  8. }
  9. Quitter.prototype = {
  10. toString: function() { return "[Quitter]"; },
  11. quit: function() { sendSyncMessage('Quitter.Quit', {}); }
  12. };
  13. // This is a frame script, so it may be running in a content process.
  14. // In any event, it is targeted at a specific "tab", so we listen for
  15. // the DOMWindowCreated event to be notified about content windows
  16. // being created in this context.
  17. function QuitterManager() {
  18. addEventListener("DOMWindowCreated", this, false);
  19. }
  20. QuitterManager.prototype = {
  21. handleEvent: function handleEvent(aEvent) {
  22. var quitter = new Quitter(window);
  23. var window = aEvent.target.defaultView;
  24. window.wrappedJSObject.Quitter = Cu.cloneInto({
  25. toString: quitter.toString.bind(quitter),
  26. quit: quitter.quit.bind(quitter)
  27. }, window, {cloneFunctions: true});
  28. }
  29. };
  30. var quittermanager = new QuitterManager();