about-devtools-toolbox.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. "use strict";
  5. // Register about:devtools-toolbox which allows to open a devtools toolbox
  6. // in a Firefox tab or a custom html iframe in browser.html
  7. const { Ci, Cu, Cm, components } = require("chrome");
  8. const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
  9. const Services = require("Services");
  10. const { XPCOMUtils } = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
  11. const { nsIAboutModule } = Ci;
  12. function AboutURL() {}
  13. AboutURL.prototype = {
  14. uri: Services.io.newURI("chrome://devtools/content/framework/toolbox.xul",
  15. null, null),
  16. classDescription: "about:devtools-toolbox",
  17. classID: components.ID("11342911-3135-45a8-8d71-737a2b0ad469"),
  18. contractID: "@mozilla.org/network/protocol/about;1?what=devtools-toolbox",
  19. QueryInterface: XPCOMUtils.generateQI([nsIAboutModule]),
  20. newChannel: function (aURI, aLoadInfo) {
  21. let chan = Services.io.newChannelFromURIWithLoadInfo(this.uri, aLoadInfo);
  22. chan.owner = Services.scriptSecurityManager.getSystemPrincipal();
  23. return chan;
  24. },
  25. getURIFlags: function (aURI) {
  26. return nsIAboutModule.ALLOW_SCRIPT || nsIAboutModule.ENABLE_INDEXED_DB;
  27. }
  28. };
  29. AboutURL.createInstance = function (outer, iid) {
  30. if (outer) {
  31. throw Cr.NS_ERROR_NO_AGGREGATION;
  32. }
  33. return new AboutURL();
  34. };
  35. exports.register = function () {
  36. if (registrar.isCIDRegistered(AboutURL.prototype.classID)) {
  37. console.error("Trying to register " + AboutURL.prototype.classDescription +
  38. " more than once.");
  39. } else {
  40. registrar.registerFactory(AboutURL.prototype.classID,
  41. AboutURL.prototype.classDescription,
  42. AboutURL.prototype.contractID,
  43. AboutURL);
  44. }
  45. };
  46. exports.unregister = function () {
  47. if (registrar.isCIDRegistered(AboutURL.prototype.classID)) {
  48. registrar.unregisterFactory(AboutURL.prototype.classID, AboutURL);
  49. }
  50. };