0

I have created a safari plugin using NPAPI and I want to add a NSView in my plug-in.

When I try to get NPWindow throw function NPP_SetWindow(NPP instance, NPWindow* window), the second parameter is nil.

I think my plug-in is windowless, but i don't know how to create a windowed.

Magical
  • 263
  • 3
  • 10

1 Answers1

0

NPAPI on Mac does not support NSView as a windowing mode. There are two supported modes:

There used to be a QuickDraw mode, but that's deprecated.

For more information, see Stuart Morgan's excellent blog post on the subject.

It is possible to make a NSView render to a CoreGraphics context but you'd have to proxy all of the events and it is far from perfect.

EDIT: To further explain the answer to your question, the reason that the window parameter is NULL (it's a C api, not Obj C, so it's NULL, not nil... despite them being the same thing =]) is because in the Cocoa Event Model you get a CGContextRef as part of the draw event which is only valid during the context of that event.

taxilian
  • 14,229
  • 4
  • 34
  • 73
  • Hello @taxilian! I want to konw why the second parameter "window" is nil? I find below code from apple developer document,but now it can't work.Did i miss something ? NPError setwindow_cb(NPP instance, NPWindow* npw) { ... NP_CGContext *npcontext = npw.window; CGContextRef context = npcontext.context; CGRect boundingBox = CGContextGetClipBoundingBox(context); – Magical Sep 21 '12 at 06:13
  • You missed the update to cocoa where the window is now NULL and you get the CGContextRef as part of the event. See https://wiki.mozilla.org/NPAPI:CocoaEventModel – taxilian Sep 21 '12 at 20:46
  • Thank you very much, taxilian.**NPWindow** is very important for me,because my player is created by export function `void SetHwnd(void *hWnd, CGRect rect)` in my plug-in.if CGContextRef is only can used,I should rewrite a new function? – Magical Sep 24 '12 at 02:38
  • If your current code requires that the CGContextRef come from the NPWindow instead of as part of the Cocoa NPEvent then yes, you will have to rewrite some code. – taxilian Sep 24 '12 at 05:33