Search code examples
macosnswindownpapi

NPAPI plugin + NSWindow hierarchy in OS X - Can I find the parent and bring it to front?


I have a NPAPI (windowed-mode) plugin, running in a popup window. Unfortunately, there is a bug in Chrome where it grabs the focus unexpectedly and the popup is occluded. My goal is to work around this bug while it gets fixed.

SetWindow passes me NPWindow*. Using this, on Windows I get a valid HWND and can navigate to the parent HWND. On Mac (using the Cocoa model) I can get an NSWindow but it doesn't seem valid and doesn't seem to do anything constructive when I send makeKeyAndOrderFront or any other msg.

Should I expect to get a valid NSWindow? Is this NSWindow a child window somehow connected with the top level window of the popup? If so, is there an appropriate way of obtaining that window?


Solution

  • Short answer: No

    Longer answer: Not in a way that will work on all browsers and be guaranteed not to break on the next version.

    On current browsers your plugin is running in a different process and the browser is actually marshalling the drawing across processes anyway; there is no link between the NPWindow* and the NSWindow that is being used on any drawing model that is available. In Carbon (32 bit browsers only) there was a hack that you could use to make this work anyway, but it was just that -- a hack. It no longer works on newer browsers.