Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Safari NPAPI plugin

I've written a NPAPI plugin for Windows and I'm now trying to get a Mac version going. I've gotten a project setup from the NetscapeMoviePlugin example. I'm trying to figure out what the preferred way of creating a plugin with decent user interface is (toolbar, buttons, several views objects).

I have two copies of the my project that I have been working on for weeks:

The first projects directly creates all of the HIView objects and places them into the root view of the WindowRef given to me by the plugin interface. The only problem I'm having with this is, on the update event where the repaint happens, the root view (I'm guessing) keeps painting the content window black before I get called to paint. This is causing a flicked every time the paint happens. Also because I'm using a Scroll view with an embedded image view, my scroll bars and un-used area of the scroll view are painted over black. None the less the black flicker is the problem I'm running into with this approach.

The second project creates all of the views on a separate window, and then I'm attempting to group the window together using window groups to get the parent child functionality. This is working ok; the windows move together and share activation, but I can't get the minimize/maximize functionality to work. I've tried both creating my own window group and placing my window along with the safari window in it, and getting the window group from the window from safari and placing my window into that. With both groups I'm using window group attributes of kWindowGroupAttrMoveTogether, kWindowGroupAttrLayerTogether, kWindowGroupAttrSharedActivation, and kWindowGroupAttrHideOnCollapse. I've tried several different combinations to see what happens as well. Either way, when I click the yellow collapse button on the safari window, the safari falls into the tray and then reappears behind my window and my window never goes anywhere. I've tried manually catching the collapse event and sending the event to my window, but this makes no difference.

Does anybody have any pointers as to which of the two ways are the better way of writing a plugin, or suggestions as to the functionality of both of the situations described above? Also I would like to note that I have tried the plugin on Safari on both tiger and leopard and have had the same results. I've been yanking my hair out for weeks trying to get this to work. I would really appreciate any help. Thanks for looking.

Mackbook, Mac OS X (10.4.11)

Posted on Nov 11, 2008 8:39 AM

Reply
1 reply

Nov 12, 2008 1:19 PM in response to joey12312312

I solved the issue. I found that Safari was a Cocoa application, so I got a NSWindow reference from the window handle given in the NPAPI NPP_SetWindow call, and then created a NSWindow reference for my carbon window and tied them together. I just thought I post this back, in case anyone else has the same problem.

NPError NPP_SetWindow(NPP instance, NPWindow* npWindow)
{
// Get a Cocoa window reference of the browser window
NP_CGContext* npContext = (NP_CGContext*)npWindow->window;
WindowRef window = npContext->window;
NSWindow* browserWindow = [[[NSWindow alloc] initWithWindowRef:window] autorelease];

// Get a Cocoa reference of my carbon window
// yourCarbonWindow should be replaced with the window handle of the carbon
// window that should be tied to the Safari window.
NSWindow* myWindow = [[[NSWindow alloc] initWithWindowRef:yourCarbonWindow] autorelease];

// Now create a parent child relationship
[browserWindow addChildWindow:myWindow ordered:NSWindowAbove];
}

The code formatting is messed up, but you get the picture.

Safari NPAPI plugin

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.