npp_destroy gets called immediately after npp_new - macos

I am trying to make a NPAPI plugin for chrome on Mac. I have written a basic npapi plugin and a basic manifest.json and background.html to load it. My background.html has a embed tag to fetch the plugin by Mimetype.
Now when I load my unpackaged extension from Chrome and try to debug the c++ code (in xcode4), I found that the functions are getting called in following order:
NP_Initialize
NP_GetEntryPoints
NPP_New
NPP_Destroy
After this when I click on the extension icon, the popup.html should get executed. My popup.html has these lines:
line 1:
var pluginObj = document.getElementById("pluginId");
line 2:
pluginObj.Myfunction();
But on line 1, NP_Getvalue() function doesnt get called and so a "scriptable NPObject" is not instantiated. On line 2, the Chrome JavaScript console says:
Error in event handler for 'undefined': Object #<HTMLEmbedElement> has no method 'Myfunction' TypeError: Object #<HTMLEmbedElement> has no method 'Myfunction'
Why does the NPP_Destroy functions gets called immediately after the NPP_New function?

Have you done drawing and event model negotiation in your plugin? Starting with Chrome 22 for Mac, the long-deprecated QuickDraw and Carbon models are no longer supported, and if your plugin doesn't negotiate modern models, it will be destroyed just after init. See here for example code that does this.
(Yes, it's unfortunate that the default models for 32-bit plugins are the old, deprecated models, but there's no way to change that in the spec due to all the existing plugins that expect the old behavior.)

Related

How to call a Javascript function inside an webview on nativescript?

How to call a Javascript function (and register a callback function to be executed after the method execution from web view is done) inside an webview on nativescript?
First the bad new, nothing is "built" in to do this. This requires you to add some code to communicate back from the webview. In the nativescript-webworkers plugins that I wrote; the way I did it was I used the onJsConfirm function on Android. On iOS I used the userContentControllerDidReceiveScriptMessage callback to communicate back. If you want to develop your own code; just grab a copy of my webworkers plugin and you can see the way to do it.
Now to the good news, is that it appears there is already a plugin called "nativescript-webview-interface" which gives you this facility so you don't have to build all that binding code yourself. It looks like all you need to do is include it and you will have bi-directional communications with your webview on both iOS and Android.
Note; to see if a plugin exists in the NativeScript community; your best bet is to look on http://plugins.nativescript.rocks, that is how I found out about the above listed plugin.

Modify webpage on Share Extension iOS8

I try to run js pre/post processor to modify webpage after finish share extension, but finalize method failed to run.
In Apple document it said that both Share extensions and Action extensions can benefit from this js processor, but my finalize method not get called. Only run method get called. Anyone know how to make this work ?
Accessing a Webpage
In Share extensions (on both platforms) and Action extensions (iOS
only), you can give users access to web content by asking Safari to
run a JavaScript file and return the results to the extension ...
https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html
Here is sample project: https://app.box.com/s/9ild73l9gbmfazrmjerk
In your code you have a typo in function type, should be "finalize" instead of "finalizea".

Handling CGEventTaps in an NPAPI plugin

I'm trying to create an NPAPI plugin to listen to the Media Keys on a macbook and pass that to javascript to control things like pandora or soundcloud. I'm using Spotify's SPMediaKeyTap library, which just wraps CGEventTap running on a separate thread.
My problem is that I use npn_invoke to call back to javascript. This works normally, but when it's triggered from the CGEventTap callback, it crashes the plugin. I realize this needs to be run from the plugin thread, and I've tried to pass it back to the main thread both by using [NSObject performSelectorOnMainThread] and [NSObject performSelector:onThread] with the thread i've stored away in the main plugin threads create method. Both of these solutions still crash on any npn call. Is there anything else that goes on when handling a CGEventTap event that causes state to be invalid for NPN browser interaction calls?
Don't try to second guess the threading model by saving the thread like you are; just use performSelectorOnMainThread to call NPN methods. I do this all the time and it works fine, so I'm guessing that something with your method of cross-thread marshalling isn't working the way it needs to.

Firefox Tab Tearing kills my NPPlugin

I have an NPAPI Plugin that runs in Firefox, but any time that the tab is "torn off" (by dragging the tab into space so a new window is formed), the plugin is destroyed and recreated. The problem is that the plugin needs to be initialized with information from an Ajax call, and I cannot find any way in Javascript to detect this, so the plugin is not getting the necessary initialization information.
So, any ideas as to how to detect this event and/or make the plugin not be destroyed/recreated when the tab is torn off?
What operating system are you dealing with? If it is actually destroying your plugin and recreating it, you could always have the plugin attempt to call a javascript method on startup.
Specify the name of the function in a param tag and then on plugin startup, attempt to get a reference to that method by calling NPN_GetProperty on the window NPObject (which you can get by calling NPN_GetValue(NPNVWindowNPObject, &npobjectptr) and then calling NPN_GetProperty(npp, npobjectptr, NPN_GetStringIdentifier(functionname), &destObj)
Then you can invoke that method with a reference to your plugin (which you can get again with NPN_GetValue) and the js function will know that it's time to initialize your plugin (again?).
You could do other things as well, such as store initialization data in global space and try to figure out a way to detect that it should be the same plugin instance... not sure how to be sure it's supposed to be the same one, though.

Is there a way to add global error handler in a visual basic 6.0 application?

VB 6.0 does not have any global handler.To catch runtime errors,we need to add a handler in each method where we feel an error can occur.But, still some places might be left out.So,we end up getting runtime errors.Adding error handler in all the methods of an application,the only way?
No there is no way to add a global error handler in VB6. However, you do not need to add an error handler in every method. You only really need to add an error handler in every event handler. E.g. Every click event,load event, etc
While errors do propogate upwards, VB6 has no way to do a stack trace, so you never know which method raised the error. Unfortunately, if you need this information, you have to add a handler to each method just to log where you were.
Also: errors do propagate upwards: if method X calls methods Y and Z, a single error handler in method X will cover all three methods.
I discovered this tool yesterday:
http://www.everythingaccess.com/simplyvba-global-error-handler.htm
It is a commercial product that enables global error handling in VB6 and VBA applications.
It has its cost but does its job perfectly. I have seen other tools (free though) helping in this VB6 mangle, but none can cover a true real global error handling like "SimplyVB6 Global Error Handler for VB6" does.
With "SimplyVB6 Global Error Handler for VB6", there is no need to change any line of existing code, and no need to number the lines of code (via a plug-in or something).
Just enable Global error handling (one line of code in the main module) and you are all set.
"SimplyVB6 Global Error Handler for VB6":
can show the call stack with real module and function names, as well as display the source code line.
Works only with P-Code compiled VB6 programs.
can work via early or late binding (no DLL Hell).
I am not in any way affiliated to www.everythingaccess.com, just happy to have found it yesterday afternoon, was kind of looking at this problem again as one of my customers was having bugs in our VB6 application. I was able to test the tool yesterday afternoon, exchanging emails with the www.everythingaccess.com support and getting the evaluation product per mail.
Their web side does not allow yet to download the evaluation version of the VB6 product, you have to email them but they are answering in less than an hour.
on error resume next - is kinda close but its been a while.
you might want to look up any caveats

Resources