Is it possible to create two different plugins in the same dll, one for communication and the other as a canvas?
I know that i can do it in the same class but I want the first to be windowless (I need only one per browser) and the other one is windowed (I may create up to 4 of them in the same browser).
I want to be able to select between them, some thing like this.
<object id="plugin0" type="application/x-communication" width="0" height="0">
<param name="onload1" value="pluginLoaded" />
<object id="plugin1" type="application/x-canvas" width="320" height="240">
<param name="onload2" value="pluginLoaded" />
Can I create the canvas object dynamically from the communication object using FB::DOM and get the JSAPIAUTO pointer to pass the binary data between them directly?
NpAPI does not support byte array and I tried to use base64 string but it is very slow.
Yes you can have a single DLL with multiple “plugins”. Actually it is just one plugin, but it can handle multiple mimetypes. If you look at the FBTestPlugin example you’ll see that it actually handles three different mimetypes. Those plugins can optionally share the same JSAPI interface, but they all are in the same memory space so you can (carefully!) use globals to share information.
Assuming your “canvas” object is an instance of your own plugin you could use some sort of identifier and a global map to pass a value to the other plugin instance to tell it which block of memory to use, etc. You can’t pass a JSAPI object from one to the other through javascript and get the raw C++ object back (at least not in all cases) but you can pass identifiers around that let you find the things you’re looking for.
You can find the notes on how to do multiple mimetype support in the firebreath repo in the FBTestPlugin project. I’ll post them here as well, though it’s possible some of these details may change later.
Modified original FBTestPlugin as follows to support multiple mimetypes
in a single codebase:
Edit PluginConfig.cmake, add multiple entries for the following
entries: FBSTRING_MIMEType, ACTIVEX_PROGID, FBControl_GUID, and
FBSTRING_PluginDescription. Make sure that you provide unique values for
all entries, including the GUIDs in FBControl_GUID.
Edit Factory.cpp, modify PluginFactory::createPlugin() and add code
to check mimetype and create the appropriate object. Also add
“mimetype” as a parameter to
“boost::make_shared(mimetype)”. The new code can construct
the “standard” FBTestPlugin plugin, or a new “SimpleMath” plugin from
either the FBTestPlugin or FBTestMathPlugin C++ objects.
In FBTestPlugin.h, modify the FBTestPlugin constructor to take
“const std::string& mimetype” as an argument. Add “std::string
m_mimetype;” as a private variable to FBTestPlugin.
In FBTestPlugin.cpp, modify the FBTestPlugin constructor to take
“const std::string& mimetype” as an argument and to set m_mimetype from
the mimetype parameter. Modify createJSAPI() to return
“boost::make_shared(m_host)”
instead of
“boost::make_shared(FB::ptr_cast(shared_from_this()), m_host)”
depending on the mimetype. Include “SimpleMath.h”.
Modify the plugin text in the drawing code depending on the mimetype for visual feedback to user.
Modify SimpleMathAPI.h and SimpleMathAPI.cpp to add “self” property
and “GetSelf()” method, both of which return shared_from_this().
Copy FBTestPlugin.* to FBTestMathPlugin.* and change object name.
Simplify FBTestMathPlugin by removing the LeakFinder. Modify
createJSAPI() to return only the SimpleMathAPI object. Modify the
plugin text in the drawing code for visual feedback to user.
Modified test code in test.html to test multiple mimetypes. Create
three plugins, and test math functions using all three.