Netscape Plug-In Development on Mac OS

Why such a page ?

There are various reasons to the existence of this page :

Which Browser supports Plug-In ?

I didn't check the Hot-Java and Opera Browsers. The first one is a piece of sh.. on Mac OS, the later is not available yet.

Where can I find the Software Development Kit (SDK) and the Documentation ?

First, you must know that there are two versions of the SDK : To sum-up :

 Download the 4.01a SDK.

Now, the documentation. Here again, we have two versions :

I strongly recommend reading the documentation, it sheds light on some completely dark points in the SDK and sample codes.

For my part, I prefer the PDF version that doesn't kill my eyes when I'm reading it.

To sum-up :

 Download the PDF documentation.

Where do I start from, now ?

The easiest and nicest way is to first compile a sample project included in the SDK.

If you already have downloaded the 4.01a SDK, just open the Macintosh Simple Project. Compile it and put an alias of the Plug-In in the Netscape Communicator Plug-In folder.

Do not try to put it in Internet Explorer Plug-In folder ! If you try to use that Plug-In in Internet Explorer, Internet Explorer will crash. You do not want that to happen, do you ?

After playing for a while with this Plug-In, it's high time for you to face the bad reality of life.

To develop a Plug-In, it's a good idea to start with the MacTemplate project sources ; for two good reasons :

Some little modifications are needed to make the project compile but, well, you're a true developer, aren't you ?

Where do I put my Plug-In ?

In the Browser Plug-In folder, of course... DON'T DO THAT !

Instead, put an alias of your Plug-In the the Browser Plug-In folder. This will allow you to have only one real Plug-In for every Browsers: good bye Version Management. Evenmore, this will allow you to compile a new version of the Plug-In and not have to put it every time at the good location.

How do I draw in a Plug-In ?

If you want to create a Plug-In, it's usually to draw somthing inside the Browser Window (except for Audio Plug-In, I don't see what kind of Plug-In would draw nothing. Hum, Virus may be ?).

When it comes to drawing, you can have a look at the code in the MacShell.cpp file. Indeed, when you're drawing, you must set your drawing context and later restore the former drawing context.

If you're like me, a curious guy or a first-class life sucker, you will wonder what is inside the NP_Port and NPWindow structure.

Some hours of debugging at candles light gave me some answers that you can't find in the documentation. They are not obvious to remember (while I'm writing these lines, I have to read the code to check).

First, all drawings are clipped. This is done with the clipRect parameter of the NPWindow structure and the portx and porty parameters of the NP_Port structure.

The portx and porty datas are also used to define the new QuickDraw origin for the Plug-In.

The width and height parameters of the NPWindow structure indicate the Plug-In dimension.

What is the exact puprose of the x and y coordinates of the NPWindow structure ? They are the actual corrdinates of the top-left corner of the Plug-In.

If you want to manage an OpenGL view inside a Plug-In, be aware that it's a nightmare the first time you code it.

Another important point concerns resizing and scrolling.

You get aware of a resizement with a new call to the NPP_SetWindow function.

For scrolling, you're never informed. You will just notice that the NPWindow and NP_Por values have changed when you receive an update Event. So beware.

How do I manage Keyboard Events and the cursor ?

If you're using the SDK sample code to write your plug-in and you implement keyboard management on keydown events, surprise ! No keyboard input is taken into account. You can debug your code and you will quickly come to the point, that you're not receiving the keyDown and keyUp Events.

In fact, if you read the documentation (it's quite hard to find this part of the documentation), you will learn the following things :

On Mac OS, Mouse, Keyboard, Update Events are managed with the NPP_HandleEvent function. This function supports the majority of traditional Mac OS Events and 3 more ones :

On the getFocusEvent Event, you must set the return value of NPP_HandleEvent to true to tell the Browser that your Plug-In support Keyboard focus and will manage keystrokes when it has the Focus.

For the cursor, it's a bad idea to use the qd global. Use the gQDPtr that is obtained during the Plug-In initialization.

Once your code supports these 3 events, you will be able to manage Keyboard Events and Cursor Modification.

How do I read my Plug-In resources ?

With the gResFile value, you have a local File Reference on your Plug-In Resource Fork. This data is defined in the npmac.cpp file.

Just call UseResFile with this value and here you are.

How do I debug a Plug-In ?

If you're only developing perfect code, jump to the next section. But you must know that I hate you.

With CodeWarrior, it's quite easy to debug a Plug-In (which is actually just a Shared Library). In the Project Preferences Panel, section Target, select the Runtime Settings option.

With the Choose... button, you can set-up the binary that will launch your Plug-In. So select Internet Explorer or Netscape Communicator.

What you have to do next, is to launch the debugger, and drag and drop the HTML page that calls your Plug-In in the Browser window.

Personal note : During my various attempts with iCab, I never succeeded in making this work.

Internet Explorer Incompatibilities (or every thing you wanted to know about Plug-In developement and didn't dare to ask)

You've just succeeded in compiling your insanely great Plug-In and tested it with Netscape Communicator. You are the Best, you're going to meet your manager and ask for a bonus or even become the CEO of your firm.


Before comitting a Professional suicide, check that your plug-in works with Internet Explorer.

I'm sorry my lady, but we're living in a nasty world (I don't even speak of those satellites all around Earth disturbing the weather), Internet Explorer doesn't support all the functionalities of the SDK.

The various incompatibilites I have listed with Internet Explorer 4.5 and later :

To sum-up :

 Beware Internet Explorer and other Browsers. The fact that your plug-in is working with Netscape Communicator doesn't mean that it will work with other Borwsers.

Other informations

Sample Source code

The source code MacTemplate is amodified version of the sampleCode MacTemplate.

It's a CodeWarrior Pro 5 Project.