Search code examples
cocoapluginswebkitnpapifirebreath

Converting a cocoa application to a NPAPI plugin with the Firebreath framework


I found recently that webkit model will be unsupported by Apple in Lion and Safari last release and that everybody is migrating to Firebreath project in order to use NPAPI.

I have a basic Cocoa Application which links with the following native frameworks:

  1. CoreGraphics
  2. CoreData
  3. IOKit
  4. PFEventTaps ( this is a 3 party framework by: Pfiddlesoft.com)

I've never used PlugIns so this is a little new for me, I started with the MAC tutorial written by Richard bateman and after following the guidelines I ends up with a firebreath project template for my personal project. the next step I made was just puting all my Objective-C classes into the Source Files folder adding the linking with the 4 frameworks, finally I added the new public methods I need to expose in the plug-In into the MyProjectPluinApi.h e.g.( registerMethod("MyMethod", make_method(this, &WilmerPlugInAPI::MyMethod ));

When I build the firebreath project I get a lot of compile errors, one of them very repetitive is: NSString was not declared in this scope. The error points to NSObjCRuntime.h

Until now I can't get this build succesfully with XCODE 3.2.6

what is wrong here? I need to change all my code to accomplish the CPP style in this template project? Or I can link my frameworks in some way? Is there some sample I can see?

MORE DETAILS: Nov 7 2011: I was trying to test with a simple project:

  • First I create the project testOfFB
    • it is generated in /users/Me/Firebreath-dev/build/projects/testofFB
  • then I modify the class testFBApi.cpp and rename it to testFBApi.mm.
  • I wrote an Objective-c class named testMath.m and rename it to testMath.mm
  • I add a method Add with the signature:

    -(long) Add:(long)a:(long)b:(long)c;
    
  • Finally I modify the file testFBApi.mm with this:

    registerMethod("add", make_method(this, &testFBAPI::add ));
    
  • In the implementation of add method I create an instance of the objective-c class method "add" to test the calling to my objective-c method. I did the includes and I changed the file /Mac/projectDef.cmake in this way:

    target_link_libraries(${PROJECT_NAME}
        ${PLUGIN_INTERNAL_DEPS}
        ${Cocoa.framework} // added line
        ${Foundation.framework} //added line
    )
    

I run the prepmac.sh script and then build the xcode solution and same errors appear plus some others like testFBApi has not been declared.


Solution

  • It's hard to say without a bit more information, but you may need to update your cmake files to import the frameworks you need; if you're doing that by hand in xcode it should probably work as well, but I haven't tried that way. You should know that adding it with cmake will not add it to the framework list in xcode, though it should be there.

    If you need to use objective-c code and c++ code in the same file you'll need to use the .mm file extension (objective-c++) rather than the more common .m (objective-c) extension.

    Other than this, I'd need to see more of your code to guess what might be wrong for sure; I would guess perhaps you have missing includes, for example. Note that if you had a PCH in your old project it is most likely not being used in the new project.

    For more info on adding the frameworks with cmake see http://www.firebreath.org/display/documentation/Using+Libraries