1

I tried to write a program with load a SWF file directly, and I am going to use NPAPI to implement that program.

But, I don't know how to start it. I mean how to communication between cocoa and NPAPI? And how to build the architecture of program?

I searched Google in many times, there is no many useful information for this topic.

I hope anyone can help me.

Any suggestion will be appreciated.

Ryan Liang
  • 51
  • 5
  • Also worth looking at is [this question on stackoverflow dealing with the same issue](http://stackoverflow.com/questions/643177/embedding-flash-within-a-custom-desktop-application-using-npapi). – taxilian Feb 17 '11 at 07:50
  • Thanks a lot. I am going to try use FireBreath to make a Flash Plug-in, and load plug-in on mac, maybe it is working. – Ryan Liang Feb 22 '11 at 04:11

2 Answers2

1

Building an NPAPI host is non-trivial; if you really want to do it yourself from scratch your best bet would be to look at the source for Gecko, WebKit, and/or Chromium, and re-use whatever you can from there (assuming your app's source license makes that possible).

Other than that, Mozilla's NPAPI documentation is the best source, along with the list of accepted NPAPI extensions for more recent changes (since you mentioned the Mac, you'll need to read and understand at least the Cocoa, Core Graphics, Core Animation, and negotiation proposals). Just keep in mind that a lot of how NPAPI works is de-facto standard based on what other browsers do, so just the documentation won't be enough.

You mentioned in a comment that you don't want to use WebKit because of a "security issue"—if you know of a security issue in WebKit, why not fix it instead of building a really complicated system from scratch? It's very, very unlikely that if you make a from-scratch implementation of an NPAPI host you will end up making fewer security mistakes than exist in a mature implementation that's been tested, debugged, and improved over the course of a number of years.

smorgan
  • 20,228
  • 3
  • 47
  • 55
  • Actually, I want to implement that program use WebKik(cause the internet have more resource), and I never touch that kind of development ever. But my leader told me use WebKit will cause performance down and has security issue about cross domain problem. So he ask me to study and build a program using NPAPI. More precisely, I need to load a _Flash plug-in_ and send a request to plug-in ask for load a _SWF_, or to control the internal behavior of SWF. Thanks for help. – Ryan Liang Feb 17 '11 at 04:41
  • 1
    Then I hope for your sake that your project has a source license that allows you to start from an existing open-source browser's implementation. If not, then your job comes down to single-handedly writing a from-scratch implementation of a complex, under-spec'd API that's full of subtle issues, without any prior knowledge, and somehow ending up with something that's better in essentially every way than the product of years of work by the WebKit team. As someone with a lot of experience here (you'll see my name on some of those NPAPI extensions) I strongly recommend you not go down that path. – smorgan Feb 17 '11 at 07:44
0

Particularly given the amount of plugin background you seem to have so far, I would strongly recommend that you use FireBreath. It will at least get you through the plugin part. The rest is up to you, and it won't be simple.

One thing to know is that different browsers on Mac OS X use different drawing models and different event models. For event models, the general rule of thumb is that 32 bit browsers support Carbon and 64 bit support Cocoa, though some 32 bit browser support Cocoa. Depending on 32/64 bit and the browser (and version) you may need to draw with QuickDraw, Cocoa, CoreAnimation, or CoreGraphics.

There is more information about this on the FireBreath wiki (main website).

taxilian
  • 14,229
  • 4
  • 34
  • 73
  • Thanks your advice! But, I am not going to do a plug-in. I want to build a Mac window application with only one button, just click button, then application will pop-up a SWF animation. I am not try to use WebKit and Flash'in'App to implement my program, because Webkit has security issue and Flash'in'App cost to much money. Since that I decide to use NPAPI. I appreciated your advice, hope you can give me more suggestion. Thank you. – Ryan Liang Feb 16 '11 at 09:54
  • Okay; I would look at the NPAPIHost project in FireBreath which is the core of a plugin host. As smorgan said, though, what you're doing is very nontrivial. I would look at using WebKit instead; what you're trying to do is not a simple thing. The links I gave you are still useful, though, because if you don't know how to implement your own you aren't going to be able to host someone else's. As smorgan said, if you know there is a security issue then fix it -- or at least report it. – taxilian Feb 16 '11 at 16:36
  • Thanks a lot. The security issue is about cross domain problem. I don't know specific detail, because that test program was not built by me, so I just know that much. – Ryan Liang Feb 17 '11 at 06:25