Revision 55537 of Custom about: URLs

  • Revision slug: Custom_about:_URLs
  • Revision title: Custom about: URLs
  • Revision id: 55537
  • Created:
  • Creator: Wikiwide
  • Is current revision? No
  • Comment Added description for Firefox 4; 367 words added
Tags: 

Revision Content

For creating an own about: URL, you have to use the following template . You have to replace SITENAME with your chosen name for the URL. You're URL will be "about:SITENAME". Also you'll have to generate an own UUID for your page and replace YOUR-UUID with it. CHROMEDIR is the path to the file you want to display with your about: URL.

const Cc = Components.classes;
const Ci = Components.interfaces;

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function AboutSITENAME() { }
AboutSITENAME.prototype = {
  classDescription: "about:SITENAME",
  contractID: "@mozilla.org/network/protocol/about;1?what=SITENAME",
  classID: Components.ID("{YOUR-UUID}"),
  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
  
  getURIFlags: function(aURI) {
    return Ci.nsIAboutModule.ALLOW_SCRIPT;
  },
  
  newChannel: function(aURI) {
    let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    let channel = ios.newChannel("chrome://CHROMEDIR",
                                 null, null);
    channel.originalURI = aURI;
    return channel;
  }
};

function NSGetModule(compMgr, fileSpec)
  XPCOMUtils.generateModule([AboutSITENAME]);

After that, you should edit the Manifest file and add:

EXTRA_PP_COMPONENTS = \
      aboutSITENAME.js \
    $(NULL)

 This makes sure that your file will be pre-processed and copied into browser/components/ .

For Firefox 4

In chrome.manifest of the extension, write:

component CID relative/file/location/of/file.js/whereever/you/put/it

contract @mozilla.org/network/protocol/about;1?what=sitename CID

Example:

component {00000000-0000-0000-0000-000000000000} components/aboutSitename.js

contract @mozilla.org/network/protocol/about;1?what=sitename {00000000-0000-0000-0000-000000000000}

CID can be received from firebot (https://developer.mozilla.org/en/Creating_a_Skin_for_Firefox/UUID); making up your own will most likely give you error "Malformed CID" in Error Console

 

Then, the Javascript file (probably components/aboutSitename.js)

const Cc = Components.classes;
const Ci = Components.interfaces;

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function AboutSitename() { }
AboutSITENAME.prototype = {
  classDescription: "about:sitename",
  contractID: "@mozilla.org/network/protocol/about;1?what=sitename",
  classID: Components.ID("{YOUR-UUID}"),
//Note: classID here should be exactly the same as CID in chrome.manifest
  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
  
  getURIFlags: function(aURI) {
    return Ci.nsIAboutModule.ALLOW_SCRIPT;
  },
  
  newChannel: function(aURI) {
    let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    let channel = ios.newChannel("chrome://CHROMEDIR",
                                 null, null);
//Note:"chrome://CHROMEDIR" is like chrome://extension/content/aboutSitename.html Read more about chrome registration: https://developer.mozilla.org/en/Chrome_Registration
  channel.originalURI = aURI;
    return channel;
  }
};
const NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutSITENAME]);

Revision Source

<p>For creating an own about: URL, you have to use the following template . You have to replace SITENAME with your chosen name for the URL. You're URL will be "about:SITENAME". Also you'll have to generate an own UUID for your page and replace YOUR-UUID with it. CHROMEDIR is the path to the file you want to display with your about: URL.</p>
<pre>const Cc = Components.classes;
const Ci = Components.interfaces;

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function AboutSITENAME() { }
AboutSITENAME.prototype = {
  classDescription: "about:SITENAME",
  contractID: "@mozilla.org/network/protocol/about;1?what=SITENAME",
  classID: Components.ID("{YOUR-UUID}"),
  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
  
  getURIFlags: function(aURI) {
    return Ci.nsIAboutModule.ALLOW_SCRIPT;
  },
  
  newChannel: function(aURI) {
    let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    let channel = ios.newChannel("chrome://CHROMEDIR",
                                 null, null);
    channel.originalURI = aURI;
    return channel;
  }
};

function NSGetModule(compMgr, fileSpec)
  XPCOMUtils.generateModule([AboutSITENAME]);
</pre>
<p>After that, you should edit the Manifest file and add:</p>
<pre>EXTRA_PP_COMPONENTS = \
      aboutSITENAME.js \
    $(NULL)
</pre>
<p> This makes sure that your file will be pre-processed and copied into browser/components/ .</p>
<h3>For Firefox 4</h3>
<p>In chrome.manifest of the extension, write:</p>
<p>component CID relative/file/location/of/file.js/whereever/you/put/it</p>
<p>contract <span class="Apple-style-span" style="font-family: 'Courier New', 'Andale Mono', monospace; white-space: pre; line-height: normal; ">@mozilla.org/network/protocol/about;1?what=sitename CID</span></p>
<p>Example:</p>
<p><span class="Apple-style-span" style="font-family: 'Courier New', 'Andale Mono', monospace; white-space: pre; line-height: normal; ">component <em style="font-family: Georgia, Times, 'Times New Roman', serif; ">{00000000-0000-0000-0000-000000000000} components/</em></span><em>aboutSitename</em><span class="Apple-style-span" style="font-family: 'Courier New', 'Andale Mono', monospace; white-space: pre; line-height: normal; "><em style="font-family: Georgia, Times, 'Times New Roman', serif; ">.js</em></span></p>
<p>contract <span class="Apple-style-span" style="font-family: 'Courier New', 'Andale Mono', monospace; white-space: pre; line-height: normal; ">@mozilla.org/network/protocol/about;1?what=sitename </span><span class="Apple-style-span" style="font-family: 'Courier New', 'Andale Mono', monospace; white-space: pre; line-height: normal; "><em style="font-family: Georgia, Times, 'Times New Roman', serif; ">{00000000-0000-0000-0000-000000000000}</em></span></p>
<p>CID can be received from firebot (<a href="/en/Creating_a_Skin_for_Firefox/UUID" title="https://developer.mozilla.org/en/Creating_a_Skin_for_Firefox/UUID">https://developer.mozilla.org/en/Creating_a_Skin_for_Firefox/UUID</a>); making up your own will most likely give you error "Malformed CID" in Error Console</p>
<p> </p>
<p>Then, the Javascript file (probably <span class="Apple-style-span" style="font-family: 'Courier New', 'Andale Mono', monospace; white-space: pre; line-height: normal; "><em style="font-family: Georgia, Times, 'Times New Roman', serif; ">components/</em></span><em style="font-family: Georgia, Times, 'Times New Roman', serif; ">aboutSitename</em><span class="Apple-style-span" style="font-family: 'Courier New', 'Andale Mono', monospace; white-space: pre; line-height: normal; "><em style="font-family: Georgia, Times, 'Times New Roman', serif; ">.js</em></span>)</p>
<pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.286em; margin-left: 0px; padding-top: 10px; padding-right: 20px; padding-bottom: 10px; padding-left: 20px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(213, 205, 187); border-right-color: rgb(213, 205, 187); border-bottom-color: rgb(213, 205, 187); border-left-color: rgb(213, 205, 187); overflow-x: auto; overflow-y: auto; font: normal normal normal 100%/normal 'Courier New', 'Andale Mono', monospace; ">const Cc = Components.classes;
const Ci = Components.interfaces;

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function AboutSitename() { }
AboutSITENAME.prototype = {
  classDescription: "about:sitename",
  contractID: "@mozilla.org/network/protocol/about;1?what=sitename",
  classID: Components.ID("{YOUR-UUID}"),
//Note: classID here should be exactly the same as CID in chrome.manifest
  QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
  
  getURIFlags: function(aURI) {
    return Ci.nsIAboutModule.ALLOW_SCRIPT;
  },
  
  newChannel: function(aURI) {
    let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    let channel = ios.newChannel("chrome://CHROMEDIR",
                                 null, null);
//Note:"chrome://CHROMEDIR" is like chrome://extension/content/aboutSitename.html Read more about chrome registration: https://developer.mozilla.org/en/Chrome_Registration
  channel.originalURI = aURI;
    return channel;
  }
};
const NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutSITENAME]);</pre>
Revert to this revision