Skip to content

Instantly share code, notes, and snippets.

@Noitidart
Last active January 4, 2016 18:59
Show Gist options
  • Save Noitidart/8663868 to your computer and use it in GitHub Desktop.
Save Noitidart/8663868 to your computer and use it in GitHub Desktop.
This is the source to bootstrap addon "Custom About Page Demo". It demonstrates how to create an about:**** url for the MDN document located here: https://developer.mozilla.org/en-US/docs/Custom_about:_URLs#For_Firefox_4_%28Second_Approach%29
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr, manager: Cm} = Components;
var selfPath; //note: file system on windows uses \ (forward slash)) but firefox browser uses / (backward slash) //do not edit //the jar will have forward slashes but to navigate so if just want a file within the main folder its selfPath + fileName. but if want folder its selfPath + fileName + '\\'fileInFolder //so as u can see must use forward slashes to navigate folders
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://gre/modules/Services.jsm');
Cm.QueryInterface(Ci.nsIComponentRegistrar);
var AboutModuleUnloaders = [];
function AboutModule() {}
function registerAbout() {
AboutModule.prototype = {
uri: Services.io.newURI(selfPath + 'frontend module/index.txt', null, null), //EXAMPLE1: uri: Services.io.newURI('http://www.bing.com/', null, null), //EXAMPLE2: uri: Services.io.newURI('chrome://about-addons-memory/content/about.xhtml', null, null),
classDescription: 'This shows custom about page demo',
classID: Components.ID('9acb8b00-8616-11e3-baa7-0800200c9a66'), //EXAMPLE: classID: Components.ID('1704E6F0-8039-11E3-9CE1-C4766188709B'),
contractID: '@mozilla.org/network/protocol/about;1?what=demo', //EXAMPLE: contractID: '@mozilla.org/network/protocol/about;1?what=yabba'
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
newChannel: function (aURI) {
let chan = Services.io.newChannelFromURI(this.uri);
chan.originalURI = aURI;
return chan;
},
getURIFlags: function (aURI) 0
};
for (let[y, cls] in Iterator([AboutModule])) {
//Cu.reportError('y: ' + y);
//Cu.reportError('cls: ' + cls);
try {
var factory = {
_cls: cls,
createInstance: function (outer, iid) {
if (outer) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
return new cls();
}
};
Cm.registerFactory(cls.prototype.classID, cls.prototype.classDescription, cls.prototype.contractID, factory);
AboutModuleUnloaders.push(function(){
Cm.unregisterFactory(factory._cls.prototype.classID, factory);
});
} catch (ex) {
Cu.reportError('failed to register module: ' + cls.name + '\nexception thrown: ' + ex);
}
}
}
function unregisterAbout() {
for (var i=0; i<AboutModuleUnloaders.length; i++) {
AboutModuleUnloaders[i]();
}
}
function startup(aData, aReason) {
Cu.reportError('startup');
selfPath = aData.resourceURI.spec; //has final slash at end so for use use as: "aData.resourceURI.spec + 'bootstrap.js'" this gets the bootstrap file //note the final slash being a backward "/" is very important
Cu.reportError('selfPath = "' + selfPath + '"');
registerAbout();
Cu.reportError('about registered')
}
function shutdown(aData, aReason) {
if (aReason == APP_SHUTDOWN) return;
unregisterAbout();
}
function install() {}
function uninstall() {}
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>custom-about-page-demo@jetpack</em:id>
<em:version>initial</em:version>
<em:type>2</em:type>
<em:bootstrap>true</em:bootstrap>
<em:unpack>false</em:unpack>
<!-- Firefox -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>7.0</em:minVersion>
<em:maxVersion>10.0a1</em:maxVersion>
</Description>
</em:targetApplication>
<!-- Front End MetaData -->
<em:name>custom about page demo</em:name>
<em:description>This addon shows how to make a custom about page</em:description>
<em:creator>Noitidart</em:creator>
<em:iconURL/>
<em:icon64URL/>
<em:optionsType>2</em:optionsType>
</Description>
</RDF>
@Noitidart
Copy link
Author

Gists do not support folders it looks like. If you would like to try this addon, in the bootstrap.js directory, create a folder called "frontend module" and then inside it place index.txt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment