> David, can you do a brain dump of what would be the technology challenges of implementing something like that?
>
> Adam
I've identified the following components of the plugin system:
- Navigating and searching for extensions
- Extension format
- Extension metadata
- Downloading extensions
- Storing extensions
- Loading extensions
- Uninstalling extensions
- Referring to images / loading resources
Going through them one by one, looking at technology needed:
Navigating and searching for extensions:
This is pretty easy. We want to store the list of extensions on a server somewhere, and we want to make sure that each extension entry can point to multiple downloads for different browsers.
Extension format:
I think each extension should be a zip file with a very simple internal structure: there is a JSON header file at the top level. This contains the metadata and a list of relative paths within the zip to JS files that Builder should load in. (see
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIZipReader )
Extension metadata:
Each extension should store its name, icon, description and version compatibility information.
Downloading extensions:
As you suggested, this can be done using XHR.
https://developer.mozilla.org/en/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data describes how to cleanly read binary data. One issue is that we can't provide a progress bar for the download, but hopefully the downloads should generally be small.
Storing extensions:
In Firefox, the Correct Way of storing extra files for an extension is to put them in an appropriately-named folder directly in the profile folder. This is how major extensions like Adblock Plus and Greasemonkey do it. (see
https://developer.mozilla.org/en/XUL_School/Local_Storage )
Given that we'll want to be able to refer to files inside the extensions in HTML (see "Referring to images / loading resources"), extensions will need to be unzipped into folders.
Loading extensions:
After Se Builder itself has loaded, but (probably) before the hooks trigger that cause the UI to be displayed, Builder goes through each installed extension and loads and executes the JS files referenced in the header.js file. These files can then install listeners (as discussed in the earlier email) to extend Builder. (There used to be code in Builder for reading in and executing files, and this code can be resurrected.)
One potential issue is that the code may behave differently depending on which order the extensions are loaded in. Extensions should at least be sorted by identifier to produce a consistent loading order. (Otherwise there'll be lots of hard to reproduce bugs where extensions conflict only if loaded in a specific order.)
Uninstalling extensions:
The simple way to do this is to just remove the extension from the list, and then require a restart of Builder. Will have to make sure that Builder can be restarted cleanly with no old state "hanging over" from its previous incarnation. (Firefox gets very enthusiastic about caching at times.)
Referring to images / loading resources:
The big issue is how to refer to other resources. For example, if an extension wants to add a GUI element that includes an image, what should the HREF path for it be? With a Firefox extension, this can be a chrome:// URL, and that will get resolved correctly. But I don't think it's possible to construct chrome URLs that will point to the right location inside the profile folder.
So instead, we need to use file:// URLs. How do we get these? There can be a getURLForFile function in the extension API that turns a relative file path into a valid file:// URL. This does mean that you have to go via this function each time you want to include an image, but I don't see a way around that.
The API can also have related functions for getting nsIFiles / input streams from a relative path.
Summary of main issues:
- Cleanly downloading extensions
- Unzipping extensions
- Reading extension JS via input stream and executing it
- Minimising chance of extension conflicts
- Cleanly restarting Builder when installing/uninstalling
- URLs for images inside Builder extensions/input streams for resource files
In conclusion, I don't see any huge obstacles, though getting the whole download-unzip-load-reboot cycle to work cleanly may take some time, and we'll definitely have to clearly document how you get at those file URLs.
---
- David