1

I need to create an about: page, to display addon options. I have seen ti done before, but there seems to be no option in the SDK that allows you to do that.

Is there another way I could let users type about:pagename and get to my page?

I would prefer not to redirect all tabs with a URL of about:pagename to another options page.

Thanks in advance

Kaspar Lee
  • 5,446
  • 4
  • 31
  • 54
  • Check out these add-ons, its source code is open source: https://github.com/nmaier/about-addons-memory and https://github.com/leibovic/about-me – matagus Dec 06 '15 at 19:33
  • Thanks! Though both these addons are bootstrap addons, not using the SDK, so how can it be done using the SDK? – Kaspar Lee Dec 06 '15 at 20:56
  • The sdk doesn't have support for that. The fact that those addons are bootstrapped only affects how they're structured: the code for making work an ´about:page´ will work in you sdk-based addon. – matagus Dec 06 '15 at 21:08
  • It would be nice if you showed some of the code that you have tried... – bgmCoder Jan 14 '16 at 03:11
  • @bgmCoder I hadn't tried any code, since I could not work out if this is possible in the SDK. I did not know what code to write. – Kaspar Lee Jan 14 '16 at 09:05

2 Answers2

1

This is the index.js file for a restartless add-on developed using jpm:

const { Cc, Ci, Cr, Cu, Cm, components } = require("chrome");

Cm.QueryInterface(Ci.nsIComponentRegistrar);
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");

// globals
var factory;
const aboutPage_description = 'This is my custom about page';
const aboutPage_id = '6c098a80-9e13-11e5-a837-0800200c9a66'; // make sure you generate a unique id from https://www.famkruithof.net/uuid/uuidgen
const aboutPage_word = 'foobar';
const aboutPage_page = Services.io.newChannel('data:text/html,hi this is the page that is shown when navigate to about:foobar', null, null);

function AboutCustom() {};

AboutCustom.prototype = Object.freeze({
    classDescription: aboutPage_description,
    contractID: '@mozilla.org/network/protocol/about;1?what=' + aboutPage_word,
    classID: components.ID('{' + aboutPage_id + '}'),
    QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),

    getURIFlags: function(aURI) {
        return Ci.nsIAboutModule.ALLOW_SCRIPT;
    },

    newChannel: function(aURI) {
        let channel = aboutPage_page;
        channel.originalURI = aURI;
        return channel;
    }
});

function Factory(component) {
    this.createInstance = function(outer, iid) {
        if (outer) {
            throw Cr.NS_ERROR_NO_AGGREGATION;
        }
        return new component();
    };
    this.register = function() {
        Cm.registerFactory(component.prototype.classID, component.prototype.classDescription, component.prototype.contractID, this);
    };
    this.unregister = function() {
        Cm.unregisterFactory(component.prototype.classID, this);
    }
    Object.freeze(this);
    this.register();
}

exports.main = function() {
  factory = new Factory(AboutCustom);
};

exports.onUnload = function(reason) {
  factory.unregister();
};

Basically it registers a custom about page that will be loaded when you access about:foobar. The loaded page is just a line of text.

This is how it looks like:

about:foobar page

You can see a working example here: https://github.com/matagus/about-foobar-addon

matagus
  • 6,136
  • 2
  • 26
  • 39
0

I think this is a better solution if you are using the addons-sdk:

Credit goes here: https://stackoverflow.com/a/9196046/1038866

var pageMod = require("page-mod");
pageMod.PageMod({
  include: data.url("options.html"),
  ...
});    
var tabs = require("tabs");
tabs.open(data.url("options.html"));

But there are other ways. You could take a look at the Scroll to Top addon which implements this: https://addons.mozilla.org/firefox/addon/402816

Community
  • 1
  • 1
bgmCoder
  • 6,205
  • 8
  • 58
  • 105
  • Can you use `pageMod` to include a script on `about:mypage`? – Kaspar Lee Jan 14 '16 at 09:04
  • Also, the addon "Scroll to Top" doesn't exactly create an about page, it just attaches a script to local HTML page – Kaspar Lee Jan 14 '16 at 09:08
  • @Druzion Isn't a local html page the same as an "about" page? All you do is talk "about" your addon in it. And yes, you can use pageMod to include a script on a local html page. – bgmCoder Jan 14 '16 at 15:17
  • Okay, thank you. I'll change this to the accepted answer after I test it out – Kaspar Lee Jan 15 '16 at 11:53
  • I am actually about (haha) ready to do this exact thing for my addon. I am going to combine "about" and "options" into one page and include it in the data directory for the addon. I don't want to use a website to host the page because I want it available offline. – bgmCoder Jan 15 '16 at 15:01