Accessing NPN_ methods from NPAPI plugin - google-chrome

I have a NPAPI plugin developed for Chrome. It works ok. But now I need to call NPN_GetValue from the plugin. The question is, how can I link (either statically, or dynamically) my code and what library/binary should be used for imports? I searched through all Chrome binaries and I did not find a single one, which contains NPN_ exports. Surely NPN_ methods must be provided by hosting browser.
Thanks in advance.

The function pointers are provided to you as an argument to NP_Initialize; it's your job to keep them around so that you can call them later. The functions aren't exported for you to link to.

Related

NPAPI mozilla plugin loading issue

I have successfully compiled and created npapi dll in MS based on mozilla npruntime project. Reference from: https://developer.mozilla.org/en-US/docs/Compiling_The_npruntime_Sample_Plugin_in_Visual_Studio.
Starting mozilla and open about:plugins shows the plugin. But when I open "test.html" the plugin does'nt come up.
I have tested the dll by making a separate test app, where i can access the entry point functions through
NP_INIT l_pInit= (NP_INIT)GetProcAddress(hModule, "NP_Initialize");
and i am able to step into my plugin dll function.
But with mozilla it doesn't work. Please suggest.
You can debug directly the mozilla process. Just attach to the process. However, modern browsers uses separate process for loading the third party plugins, so you will have to attach to that process. Than you can set breakpoints to loading routine (NP_GetEntryPoints, NP_Initialize) and see what is happening in there.
Also, if you have trouble with attaching to the process, you can simply show debug dialogs from your code and narrow the problem area.
UPDATE 1:
It seems like the browser does nto know that it should use the plugin. Did you specify the MIME type of hwat your plugin is for? If so, run the following script in an HTML page:
<embed type="application/x-my-extension" id="pluginId">
<script>
var plugin = document.getElementById("pluginId");
var result = plugin.myPluginMethod(); // call a method in your plugin
console.log("my plugin returned: " + result);
</script>
x-my-extensionreplace with your extension which you used in NP_GetMimeDescription. You shoudl check in about:plugins if the browser registered your plugin correctly for correct MIME type.
Sounds like there is most likely something wrong in your plugin initialization; you might try using FireBreath to create a npapi plugin, as it will be a lot less work and work on IE as well. If you don't like that idea, you could look at other npapi plugins (including FireBreath) to make sure you're doing things correctly. Add logging (of whichever type you like) to the main entrypoints and see which point it fails at.
Another trick is to go to about:config and find the plugins ipc settings and disable them; then you can attach to the main firefox process and it should hit your breakpoints if they are being called.
See the FireBreath Debugging Plugins page for other ideas.
Thanks guyz. Finally i am able to load and access the functionality of my plugin in the browser. Following are the findings:-
1. Even though my plugin's MIME type in resource file was 'application/mozilla-npruntime-scriptable-plugin'. But i need to access it from javascript embed element through 'application/x-npruntime-scriptable-plugin'. After this step the debugger started breaking on my plugin's break points.
2. The check of size of NPPluginFuncs and NPNetscapeFuncs was failing, may be because of different version of NPAPI implemented in my firefox.
At the end i got startup and thank you all for your support.

NPAPI load third-party DLL

I am developing an NPAPI Firefox plugin and I have a question.
I need to load a third-party DLL (such as D:\mydll.dll), but on some computers mydll.dll is not in the system path or in c:\windows\system32 and I get loading errors.
Here is the code:
SetCurrentDirectory ("d:\");
m_hModule = LoadLibrary ("mydll.dll");
LoadLibrary returns 126. I checked with DEPENDS.EXE to view the dependent modules and everything looks fine. I do not know what the problem is.
Another problem is that I want the plug-in to work in Safari (my safari is version 5.17). I copy it into Safari's Plugins directory and it tells me it cannot find the plug-in. I want to know how to solve this.
Thank you, and please excuse my poor English.
Setting the current directory will not always work when in a plugin because you don't own the process. The command that you want is SetDllDirectory.
SetDllDirectory("D:\");
m_hModule = LoadLibrary("mydll.dll");
Of course, I don't recommend that you ever assume a DLL is in the root of the drive =] What I would do is put the DLL you need in the same directory as the plugin DLL and then you can get the path of the DLL using GetModuleFilename.
For installing, rather than putting the plugin in the plugins/ directory in the firefox (or safari) directory you should install it through the windows registry. This will make it visible for firefox, chrome, and safari.
You may want to consider using FireBreath instead of implementing the NPAPI interfaces yourself; it takes care of most of the tricky parts and leaves you free to focus on the important parts of your plugin.

Call A Method In Dll Using HTML5

I have a dll file and i need to call a method in the dll and return some value.
Before i have used a VB script and called it from a html file that runs only on IE.
Now i need to call the dll directly from HTML5 without using any VBScript or Javascript.
Which tag can achieve this and that can be run in almost all browsers.
Please help me.
Thanks in advance.
There is an <embed> Tag, but it's not for DLLs. In fact there is no tag which allows you to call DLLs at all.
So you should step away from the idea to do your processing on the client-side and just move it to the backend. Create a ASP.NET-Service if you have to use your DLL. You can even use PHP5 (using COM functions) if it's running on a Windows server.

Chrome Extension Internals

I am trying to understand the internals of Chrome Extension. It will be great if you can provide more details regarding this.
My understandings are as follows:
Extensions run in its own process.
Extensions interact with Browser process through IPC.
My question:
1. Whenever we call a extension api such as chrome.module.function() from extension user script, I would expect the function to go to the renderer process first and then send a IPC such as ExtensionHostMsg_ABC to the browser process to do the required operation.
Extension Process Browser Process
ExtensionHostMsg_Req
chrome.module.function() ----------------> Handle the msg
ExtensionMsg_Response
Send the result back to js <-----------------
But to my surprise, I see that all the extension api functions are declared and defined in chrome/browser/extensions/xyz_api.h & .cc files. So it looks like when a api is called from js, we come directly to the browser process. Where and how does this magic happens?
I also see some extensions bindings c++ code in chrome/renderer/extensions/abc_bindings.cc and the corresponding js code in chrome/renderer/extensions/resources/abc.js. I think we have this code to share some information between the extension renderer and js code. Is it right? Can you provide me a example scenario for this?
Sorry for asking these basic questions. I really appreciate your help.
Regarding your question on how the bindings are made. You define your extension API in chrome/common/extensions/api/extension_api.json which is how V8 sets up the C++ JavaScript bindings. That is where all the magic happens :)
If you want to call privileged APIs from the content script you would need to add the namespace to chrome/renderer/resources/extensions/renderer_extension_bindings.js
For more information regarding the design of the Extension System in Chromium, there are good docs that explain the whole process model and interactions:
http://www.chromium.org/developers/design-documents/extensions

Can an AIR app be programmed to handle a URL protocol?

I'm writing what is essentially a browser in Adobe AIR (ActionScript, not AJAX). A great bit of functionality to implement would be protocol handling. iTunes, for instance, handles itms protocols; when your friend sends you a link beginning with "itms://", it's going to launch iTunes as long as it's installed. Is there a way to write an AIR app (requiring AIR 2 would be fine) that can be the "handler" for a protocol in this way?
There is no way, programatically speaking, to specifically handle a particular protocol. However, there is InvokeEvent. InvokeEvent will be fired when the application is "invoked", either when it's explictly launched or if an associated file or URL is activated.
The process of associating your app with a particular file type or protocol scheme is separate and application-dependant. In iOS, for example, you would need to specify the protocol in Info.plist under CFBundleURLTypes/CFBundleURLSchemes.
Yes. You can use the URLLoader class to download data in binary form (URLLoader.BINARY) and then parse this as appropriate. See this CS3 documentation on working with external data.
http://www.patrick-heinzelmann.de/labs/lastfm/
I'm not sure exactly how it works and I don't see a way to download the app, so I can't even test it, but maybe it will help...
Check out this page. I am trying to find out the same thing, but I haven't found any solution to do it with just Air yet. Seems like you might need a custom installer to setup the correct registry entries, and a proxy application to "wash" the input to a correct format that then can start your application with the correct command line parameters. Hope this can be of any assistance.