aboutAbout.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 Cc = Components.classes;
  5. var Ci = Components.interfaces;
  6. var gProtocols = [];
  7. var gContainer;
  8. window.onload = function () {
  9. gContainer = document.getElementById("abouts");
  10. findAbouts();
  11. }
  12. function findAbouts() {
  13. var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
  14. for (var cid in Cc) {
  15. var result = cid.match(/@mozilla.org\/network\/protocol\/about;1\?what\=(.*)$/);
  16. if (result) {
  17. var aboutType = result[1];
  18. var contract = "@mozilla.org/network/protocol/about;1?what=" + aboutType;
  19. try {
  20. var am = Cc[contract].getService(Ci.nsIAboutModule);
  21. var uri = ios.newURI("about:"+aboutType, null, null);
  22. var flags = am.getURIFlags(uri);
  23. if (!(flags & Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT)) {
  24. gProtocols.push(aboutType);
  25. }
  26. } catch (e) {
  27. // getService might have thrown if the component doesn't actually
  28. // implement nsIAboutModule
  29. }
  30. }
  31. }
  32. gProtocols.sort().forEach(createProtocolListing);
  33. }
  34. function createProtocolListing(aProtocol) {
  35. var uri = "about:" + aProtocol;
  36. var li = document.createElement("li");
  37. var link = document.createElement("a");
  38. var text = document.createTextNode(uri);
  39. link.href = uri;
  40. link.appendChild(text);
  41. li.appendChild(link);
  42. gContainer.appendChild(li);
  43. }