How to create a window in browser which has a NSWindow handle?

157 Views Asked by At

I am making a plugin for safari on mac. I am stuck at how to create a window over browser's window upon which a video can be displayed.

Earlier, we were using Cocoa Event model under which window pointer received in NPWindow in NPP_SetWindow function is null. Then we switched to Carbon Event model and we got pointer to NP_CGContext via window pointer present in NPWindow struct, using which we got pointer to WindowRef and got a pointer to NSWindow as following:

NP_CGContext* npContext = (NP_CGContext*)npWindow->window;
WindowRef window = npContext->window;
NSWindow* browserWindow = [[[NSWindow alloc] initWithWindowRef:window] autorelease];

Our streaming engine accepts the pointer to NSWindow. We don't know how to create a window in our browser space.

So any help regarding the window creation would be appreciated.

1

There are 1 best solutions below

1
smorgan On

Our streaming engine accepts the pointer to NSWindow. We don't know how to create a window in our browser space.

You should not do this, as explained in previous answers.

A streaming engine that requires an NSWindow pointer is very poorly suited to making an NPAPI plugin. You should if at all possible look for something that takes or vends a CALayer, or failing that, which can draw frames into CGContextRef (but this will be much slower in out-of-process plugins).

If you absolutely must use an NSWindow, then you'll need to make a new one in your plugin process that is completely unrelated to the browser's window, and display it somewhere on screen. The user experience will be relatively poor, because it won't move with the window, can end up behind the browser window, etc. This is explicitly discouraged by browser vendors. But if you have no choice but to use an NSWindow, then this is your only option with modern browsers.