I’ve been working on a embedded widget(html,css,js) that receives some text every x seconds and interpret that text depending on what 3rd party add-ons are being installed. It is something similar with firefox add-ons system only much simplified.
Let me give you an example of what I’m trying to achieve.
I provide an embedded code for a widget, so that people can put it on their sites, similar with twitter updates widget. I also provide a small api(in javascript) so that people can create some extensions(add-ons). For example if in the text that is loaded every x seconds appears a youtube link , instead of showing the link, the addon can replace it with the embedded video. Another example are smileys: replace 🙂 for example with an image. The list can go on, but I think you got the picture.
The problem is that when 2 or more add-ons try to replace the same content.
For example let say the widget loads the following text: http://www.youtube.com/watch?v=video_id and one add-on tries to replace the text with the video and the other add-on tries to replace it with the related image thumb.
How can I solve the interference between 2 add-ons. I’m also interested how firefox deals with this situation on their add-ons system. I’ve read some of their documentation about XUL overlays but I didn’t find anything about this situation. On their documentation page: https://developer.mozilla.org/en/XUL_Overlays they said the XUL overlays can be used for:
- adding UI for additional components, as described in the example
- above overriding small pieces of a XUL file without having to
- resupply the whole UI reusing particular pieces of the UI
I’m interested more in the last 2, in the situation explained above, but without any luck. I’ve also searched on google, but didn’t find anything.
So far the only solution I can think of is to make a mechanism that can find if 2 or more add-ons overwrite the same UI and notify the user(the one that wants to install the widget on his site) to disable one of the add-ons. If this is the only solution, I’m also interested in your ideas on how to achieve this.
NOTE: The add-ons are not necessary done by the person who put the widget on his site. It will will a system similar to firefox add-ons where the user choose what addons to install and then just copy -paste the code into his site.
I’m not sure if this is what you’re looking for, but I can think of the solution like that:
1) Create some kind of identifiers for each type of contents that are being replaced. E.g.
2) When the application starts, add-ons register to each type of replacement. So there is globally available set/array/whatever collection type, having registered add-ons to handling different types of texts.
More specifically, there is a map (associative array), that maps, in Java notation:
InputText => Set<AddOn>For instance, basing on strings and arrays (this is after adding it dynamically by each addon; order doesn’t matter)
3) The addons either have IDs that mean their “priority” of handling the inputs, or it is somehow configurable (either per-application globally, or per-addon, the order in which they should run over different kinds of contents).
E.g.
Something in the configuration of the app:
which means, if addon7 is installed, then use it to process youtube links; if no, use addon3; if no addon3, use addon5 and so on…
The problem is that if you don’t know about all possible addons being developed, you can’t use it like that.
What you can do is, wait for all addons to load, and then display information to the user:
“addon1” and “addon7” want to process Youtube links, which one do you want to do this? (click something, and then store the setting, or make user write it down in the script).
The foolish way (but maybe not so much, if the behaviors of addons are strictly the same), that each addon can have some ID inside of it, and depending on which one has the highest ID, it performs the action.
About Firefox, if there are two competing addons trying to do similar jobs, it often ends up in incompatibility… Depending of course if the efforts of the addons can or can not be combined. But basically, you have to assure some way of the order of the things, otherwise it can end up random, which is definitely not the good way.