mozilla

Revision 55539 of Custom about: URLs

  • Revision slug: Custom_about:_URLs
  • Revision title: Custom about: URLs
  • Revision id: 55539
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment clean up; 28 words added, 33 words removed

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 the extension's chrome.manifest file, write:

component CID relative/file/location/of/file.js/whereever/you/put/it
contract @mozilla.org/network/protocol/about;1?what=sitename CID

For example:

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

See this article for information on how to create a valid UUID; making up your own will most likely result in a "Malformed CID" error.

Then, in your 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 the extension's <a href="/en/chrome_registration" title="en/chrome registration"><code>chrome.manifest</code></a> file, write:</p>
<pre>component CID relative/file/location/of/file.js/whereever/you/put/it
contract @mozilla.org/network/protocol/about;1?what=sitename CID</pre>
<p>For example:</p>
<pre>component {00000000-0000-0000-0000-000000000000} components/aboutSitename.js
contract @mozilla.org/network/protocol/about;1?what=sitename {00000000-0000-0000-0000-000000000000}
</pre>
<p>See <a href="/en/Creating_a_Skin_for_Firefox/UUID" title="en/Creating a Skin for Firefox/UUID">this article</a> for information on how to create a valid UUID; making up your own will most likely result in a "Malformed CID" error.</p>
<p>Then, in your JavaScript file (probably <code>components/aboutSitename.js</code>):</p>
<pre class="brush: 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]);</pre>
Revert to this revision