MozillaZine

Learning to write extensions: the epic journey

Talk about add-ons and extension development.
Ted Mielczarek
 
Posts: 1269
Joined: November 5th, 2002, 7:32 am
Location: PA

Post Posted June 21st, 2006, 4:41 am

Well, extension development is certainly getting better. It's a lot easier now than it was back when Phoenix 0.3 (or whatever the first version that officially supported extensions was) was out. The tools and documentation have improved greatly. That being said, they're still not perfect, and there are still a lot of things you need to know to be able to write an extension. I think extensiondev serves pretty well, although it could use an overhaul (I just haven't had time), and there's also my Extension Wizard which is pretty handy for starting a new extension. It's also probably a bit tough that you started out on Thunderbird, which doesn't get quite as much love as Firefox does. Anyway, I hope you can accomplish what you set out to, and please do update the wikis if you find them lacking. Good luck!

-Ted

sdwilsh
 
Posts: 563
Joined: November 6th, 2005, 9:46 pm
Location: California

Post Posted June 21st, 2006, 6:54 am

Ted - have you thought about opening up the source code for that wizard? I know I would personally like to see at least one other license with that.

EDIT: That, and Flock support should be added. As far as I know, you don't have to do anything different other than <a href="http://wiki.flock.com/index.php?title=Modify_Firefox_Extensions">support the target application.</a>

ericjung
 
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post Posted June 21st, 2006, 10:29 am

Dewi Morgan wrote:It is trivial to write a program to run in an operating system. The typical "hello world" program is one to four lines long and requires you to merely create a new text file, type in those lines, and possibly to compile it. Knowing the OS kernel is not required.
Not necessarily true.

If you don't want to use an API to write "Hello World" (such as the C runtime API, MFC, .NET, Java, or any 4GL such as Visual BASIC), then you must learn how to interface with the kernel in order to write to a resource (file, stdout, socket, etc). Even to write a file, if you don't want to use a high-level API or platform, requires learning how to interface with the kernel. In Windows, this kernel interface is called the Win32 API (now called Windows API to show it can work with 16-bit and 64-bit systems).

If you picture Mozilla as a world without one of these high-level APIs/4GL language/VM systems that you're accustomed to, I think you'll start to get the idea.

Au contraire. I did not use the phrase "kernel extension", I used the word "program"
Yep. I know. And without the abstractions you're used to (higher-level API, 4GL, or VM), you must learn to interface with the kernel to write a program. In Windows and Unix, this is done by learning kernel APIs.

Programs (generally speaking) do stuff that the OS does not do by default. Clearly, it was not necessary for every author of every program on your system to know the inner workings of the kernel in order to write their program.
Only because someone wrote a higher-level API, 4GL, or VM for them to leverage. If no such tools exist (as with mozilla), those programmers must learn to interface with the kernel to do I/O, network communications, thread and task scheduling, etc.

Why is there no high-level API or 4GL language for Mozilla? My guess is it has to do with limited resources.

That is my point: An "operating system" is a "system". So to excuse Mozilla for being hard to modify, merely on the basis that it is a "system", is not a valid argument, since we have an example of a far more complex system that is trivial enough to modofy that a sixyearold can do it.

As I wrote before, this is only because someone else came along and wrote abstractions on top of the kernel interfaces which the 6-year old can use. Under the hood, those abstractions still resolve to the kernel APIs.

But Mozilla/ThunderBird/FireFox are hyped as being easy to extend and modify: and it is clear that this is a lie.
Clearly this is a subjective statement. I know high-school students who've written wonderful firefox extensions and they have no formal computer science training.

max1million
 
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Post Posted June 22nd, 2006, 1:18 am

I have never writtten (or rewritten) an executable for Windows. Counldn't understand what all them funky symbols supposed to do. I guess I need one of them "high-level APIs/4GL language/VM systems" that grimholtz has mentioned. Did use some VBScript (in Windows) though, which it would have been a bit better if I was using JScript cause that would have been more similar to what's used in the Mozilla based programs (Firefox, Thunderbird, etc). As for the Mozilla based programs, much of the interface (and extensions) is written in plain text (js, xul, css, xml) which I was able to read and rewrite to get it to do something different. Of course it takes some understanding of the basics which takes time, to get started. For development (Firefox extension) I just work on the extension right in the profile folder where it's installed, using folders instead of jar. Using a similar or basic sample extension to sart with, if it used a jar I replace the jar with a folder and edit install files for folder instead of jar, and zip it all back into xpi and install. I use the short name for extension as part of function (or class) names, ids and such, makes using replace an easy way to reuse code for something different.

These may be of some use.
http://kb.mozillazine.org/Profile_folder
http://www.xulplanet.com/tutorials/mozsdk/
http://www.xulplanet.com/tutorials/
http://www.xulplanet.com/references/
http://developer.mozilla.org/en/docs/XUL_Tutorial
http://developer.mozilla.org/
http://kb.mozillazine.org/Knowledge_Base
http://ted.mielczarek.org/code/mozilla/ ... uledit.xul

Ted Mielczarek
 
Posts: 1269
Joined: November 5th, 2002, 7:32 am
Location: PA

Post Posted June 22nd, 2006, 4:50 am

comrade693 wrote:Ted - have you thought about opening up the source code for that wizard? I know I would personally like to see at least one other license with that.

EDIT: That, and Flock support should be added. As far as I know, you don't have to do anything different other than <a href="http://wiki.flock.com/index.php?title=Modify_Firefox_Extensions">support the target application.</a>


comrade: I don't think open sourcing the wizard would be much help, it's very much tied up with being a CGI, so you'd have to host your own webserver to get any benefit out of it. If there's anything you'd like to see added (even just alternate licenses) please let me know and I'll add it!

I will add Flock support. It's not quite as simple as just adding the target app, since the code currently branches in a few places based on Firefox/Thunderbird being the target apps. I just need to clean that up a bit and it should be ok.

-Ted

Old Ausdilecce
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted June 22nd, 2006, 7:08 pm

Dewi,

Just a couple of random thots..

Do you really think that ranting will get you any closer to your goal? Do you think ranting will make it any easier for the next guy/gal ?

Now, I will agree that creating (your first) extension for mozilla apps isn't the most straightforward process in the world, BUT, once you know how - each one after that is a breeze..

The issue you are facing is that there is no IDE for extensions at the moment, as there is for creating 'programs' for Windows.. There are not hundreds of books on creating extensions either (but they will come).. You just need to get over the hurdle of your first working extension..

I will relate how *I* did it.. I did NOT go looking for a tutorial, because that would be misery +. ( I have never has much luck with 'tutorials' - they never seem to explain what I need to know).

I went looking for an very *very basic* extension that did *kinda* what I wanted to do and made *small* changes to it and tried that out.. If I was satified that I understood what that change did and what the reprocussions were, I made more changes, and more and more. Obviously, it was much harder than just typing in code from some tutorial, but *I* learned faster...

Even now that I have a couple extensions under my belt - if I come across a problem that I cannot solve, I just download an extension that has solved a similar problem and see how that person did it... I work it out and move on... Its not bloody rocket science here mate. Its *really* helpful that every extension's code is in plaintext.. Use that to your advantage.

There was a lot of cursing, I must admit. But, the end result ( a working extension) was MUCH more satisfying.



Good luck

Old Michael Buckley
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted June 23rd, 2006, 3:04 pm

Your very confused, I don't have to look any further than you saying that chrome://messenger/content/messengercompose/messengercompose.xul was not the folder that the DOMi said it was in. You went to the chrome folder in ThunderBird, extracted a jar file, which dose not count in the path name.

You don't really have to understand all the files in the extension to start, they can be sorted out later, they are faily self explantray in a way.

Bad guess about the 8th line saying what it overlays that line must be
<overlay>
other wise it dose not work right. You set what it overlays in the contents.rdf, chrome.manifest and install.rdf

When you follow a Hello World extension you end up with and extension were you press a menu item that runs a script, that is what you want to do from what you have said.

There is a differance between writing and extension and a program. With an extension you are modifying something, to modify anything you must know what you are modifying before you can do so.
New [url=http://forums.mozillazine.org/profile.php?mode=viewprofile&u=299802:3o1quhg8]Michael Buckley[/url:3o1quhg8] account as old one was lost.

Dewi Morgan
 
Posts: 8
Joined: October 1st, 2005, 8:35 am
Location: London, UK

Post Posted July 15th, 2006, 10:07 am

[replying in reverse chronological order, just because]
Still not found any time to work on this, I'm beginning to rather dislilke having two jobs.

Michael Buckley wrote:You went to the chrome folder in ThunderBird, extracted a jar file, which dose not count in the path name.

Good call, I was assuming that the name of the jar file would be part of the path, on the assumption that it should know where to find the file. If it's storing a table of what's in which jarfile somewhere else, then yeah, I guess the filename's not relevant.

There is a differance between writing and extension and a program. With an extension you are modifying something, to modify anything you must know what you are modifying before you can do so.


Yes, I've come to the conclusion that these are not extensions but mods, like the mods you get for games like Morrowind, Oblivion, etc. I'd like to call them "mods" since it's shorter, and what they are, but I suspect I'd get shouted at for it because it's not the recognised name.

This suggests that:
1) conflicts are possible and likely. Are there any tools for detecting etensions that affect the same XML nodes, scripts, files or objects? Or is there a standard way to report what elements you've modded/extended so that others will be able to see if their extensions conflict? How do users detect and resolve conflicts? I've rarely seen extensions announce probable conflicts, while with game mods it's one of the standard parts of the readme.

2) load-order is important. Say the list contains "To:", "Cc:" and "Bcc:"; my extension appends "FaxTo:"; and another appends "PrintTo:", then if the other extension relies for some silly reason on having the fourth position, then my extension must, in order not to conflict, load after it - is this correct or am I just being wrongheaded? If it's correct, how does the extension author or user manage the load-order?


ausdilecce wrote:Do you really think that ranting will get you any closer to your goal? Do you think ranting will make it any easier for the next guy/gal?


Not really, no. But I made a record of my thoughts and feelings when learning, so's I could remember it and hopefully write a tutorial afterwards that addresses the problems I had, and lays it out in the order I wanted the information and avoids the annoyances I had. If I don't record them then I'll forget how I felt, and I'll explain it from the point of view of someone who already understands the stuff, and will forget to explain stuff that's "obvious" to me.

I posted it here with the thought that it may be useful, interesting or just plain amusing to some. I was very surprised and impressed to actually have a significant, positive response: it wasn't expected :)

max1million wrote:These may be of some use.

Thanks, I'll check them out.

grimholtz wrote:If you don't want to use an API to write "Hello World"...

That's my point, yes: that for many decades, we have been trying to make people follow correct programming practice. The argument "what if you don't want to follow correct programming practice?" is not relevant: if you want to do something incorrect, then it is incorrect by definition.

I suspect that as a programmer, you'd agree that the following are Bad Things to write in programs, if they can be avoided:
  • unavoidabe and/or undetectable conflicts
  • reliance on undocumented internal workings of unrelated components maintained by other people.

Where they cannot be avoided (game mods, and, it seems, Mozilla extensions) they are still bad, but are a necessary evil.

Voluntary steps are then taken by the programmers to reduce the "profile" of potential conflicts, to notify users and other mods of changed elements, and to write documented shared libraries to accomplish common tasks.

For example, for Oblivion, there are "modder's resources" like Reznod's "easy companion share" (companions are not an inbuilt part of the game: an NPC following you and sharing their inventory is an alien concept, but has been programmed in with this mod, which is extended by various "companion" mods to create characters that can accompany you in your quests, and even have quests and story arcs of their own).

There are also third party fan utilities like the Oblivion Mod Manager, which packages your mods (along with installation scripts so that you can ask the user how they ant it installed), checks for conflicting files and conflicting objects modified, lets you manage the load order, and so forth.

I suspect equivalent utilities and helper libraries are available for Moz extensions too, and I just didn't look in the right places. I'll check the links I've been given :)


Ted Mielczarek wrote:extensiondev serves pretty well... also my Extension Wizard

Thanks, I'll check those out :)

a bit tough that you started out on Thunderbird, which doesn't get quite as much love as Firefox


Yeah, I could tell from the docs I read that was the case, and I kindof shot myself in the foot by choosing it. Ah, well, adds to the challenge, and I'm sure it'll catch up eventually :)
Yet another Firefox user.

ericjung
 
Posts: 846
Joined: August 4th, 2003, 9:32 am

Post Posted July 15th, 2006, 1:21 pm

Best of luck to you. Let us know how your learning progresses. Contrary to some of the negatively in this thread (from myself included), I'm sure we all want to see you succeed.

-grimholtz

Old Michael Buckley
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted July 15th, 2006, 7:56 pm

If it's storing a table of what's in which jarfile somewhere else, then yeah, I guess the filename's not relevant.

The chrome.manifest, and in pre 1.5 FireFox/ThunderBird the contents.rdf, after 1.5 according to XUL planet the contents.rdf is not needed.

The move time you spend at XULplanet.com the better when you are starting off.

I'm beginning to rather dislilke having two jobs.

It ends up a bit like that :P

Conflicts can be avoided to some degree. But with any two extentions that do the same thing you will have problems. I once installed both adblock and adblock plus, FireFox took 4 minutes to start up, more then 8 times a long as the 28 seconds my computer take to load windows.

A lot of extentions that modify tab behavor conflict with tab mix plus, you see the quite often.

No extention will ever break because of position of something like that is wrong. It happen when both try to over ride the same function, or use the same id tags. You just have to make sure you prefex all ids with something like yourExtention_ and for JavaScript were you are not over rideing the default function(which is what causes most clashes) something like this.

Code: Select all
var extension_name = {

 doSomeThing: function() {
  Some function
 },
 doSomeThingElse: function()
  another function
 }
}


Were something apears can be controled to some extent but most of the time it is first in get first position. I added a item to the Tools menu in FireFox and to apear below the JavaScript console. It was the fith item after it because four other extension had got in first.

Some extensions are extentions, chatzilla would be an example it allows you to open a new window that was not there before.
Other extentions are outright mods, Mr tech local install would be the best example.
Others fall some were in between.

Michael

jenzed
 
Posts: 1
Joined: March 26th, 2009, 11:26 am

Post Posted September 1st, 2009, 1:58 pm

Ouch. Hopefully writing Thunderbird extensions is less difficult now and there are better resources. However, this thread still comes up when people are searching for help with creating Thunderbird extensions. So, for recent visitors, please check out the Mozilla Developer Center (http://developer.mozilla.org/), especially the area on Thunderbird extensions (http://developer.mozilla.org/en/Extensions/Thunderbird) and the Thunderbird extension tutorial (http://developer.mozilla.org/en/Buildin ... _extension).

LoudNoise
Moderator

User avatar
 
Posts: 40048
Joined: October 18th, 2007, 1:45 pm
Location: Next door to the west

Post Posted September 1st, 2009, 2:08 pm

Locking since this is from 2006. See note above.
Post wrangler
"Choose between the Food Select Feature or other Functions. If no food or function is chosen, Toast is the default."

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest