Search code examples
cocoasafarinpapi

Safari 5.1 npapi issue


Since several days I am trying to resolve the folowing issue, reading all I found around the web about npapi on mac.

The goal is to have a npapi plugin which works for safari and firefox(mac). My software (that I can not rewrite specialy for this purpose hase about 45000 lines of C code) is based on a NSView attached to a NSDocument....

I have a webkit version based plugin that I must trash (thanks to Apple!) based to the same NSView.

I have a npapi version plugin which works fine on firefox. In this npapi plugin, I take the carbon window ref, I make a NSWindow based on that: NSWindow *browserWindow = [[[NSWindow alloc] initWithWindowRef:wind]autorelease];

and I put my NSView on this window and that works.

Now the pb is that I can not do the same thing on safari.

Look at attached picture, the window is not in the safari's window! the firefox window is between safari's window and my plugin window

I tryed several ways... it dose not work. Can a cocoa's gourou says where I am making something wrong? or is this a known issue?

NPError NPP_SetWindow(NPP instance, NPWindow* window){

NP_CGContext *ctx = window->window; void *wind = ctx->window;

... in the NSView init function:

NSWindow *browserWindow = [[NSWindow alloc] initWithWindowRef:wind];
self = [super initWithFrame:frame];
if( self )
{
    [browserWindow makeFirstResponder: self];
    [self  setNextResponder: nil];
    [browserWindow setContentView:self];
    [self webPlugInInitialize];// my own initializing
}
return self;

Solution

  • In Safari 5.1, the web rendering is not done by Safari itself, but on a different process to enhance security. Open up the Activity Monitor, and you see that background process called "Safari Web Process" or something like that.

    So, you can't and shouldn't create NSWindow based on the Carbon window ref which can be obtained within NPAPI plugin. Read Apple's own documentation on this point. You should request the core graphics drawing method, and then the WindowRef field of NP_CGContext should have a NSWindow*, not the Carbon window ref.