Search code examples
pluginsnpapiqtwebkit

Npapi Plugin not detected in demobrowser of QtWebkit


I am a newbie to StackOverflow and QtWebkit as well.

I have written a very basic Npapi plugin which has functions like NP_GetMimeTypeDescription and Np_Initialise etc for Mimetype application/basic-plugin and Mimetype description application/basic-plugin:bsc:Plug-ins SDK sample.

But I am facing a problem while loading it on the demobrowser of QtWebKit and also on Mozilla Firefox. I have placed the generated .so file in the paths where ever browser finds plugins like /usr/lib/mozilla/plugins/ and Qt Lib path.

I have a test.html file which contains the Mimetype application/basic-plugin. I am trying to launch this plugin in both the Mozilla browser and QtWebKit Demo Browser But in both the cases its not launching the plugin.

I am not able to find out why. Any suggestions are Welcome...


Solution

  • Thanks for help and suggestions.
    I was able to find out the problem why my plugin was not getting invoked, even if I placed the .so file in the correct folders /usr/lib/mozilla/plugins/ and Qt Lib path.

    There were 2 reasons...

    1. Had to enable the Define XP_UNIX (-DXP_UNIX) during compilation as a compiler directive. This will consider different prototypes of the functions and also implementation

      extern "C"
      NPError OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs
      #ifdef XP_UNIX
                                , NPPluginFuncs *pluginFuncs
      #endif
                                )
      {
              // keep a pointer to the browser functions
              g_browser = browserFuncs;
      
              // any memory that is to be shared by all instances of 
              the browser plugin should be initialized here.
              ;
      
      #ifdef XP_UNIX
             // under Linux, as the browser won't call NP_GetEntryPoints() 
              explicitly, do it now to fill in <pluginFuncs>
      
              return NP_GetEntryPoints(pluginFuncs);
      #else
      
              return NPERR_NO_ERROR;
      #endif
      }
      

    and

        extern "C"
        #ifdef XP_UNIX
        NPError NP_GetValue(void* instance, NPPVariable variable, void *value)
        #else
        NPError NP_GetValue(NPP instance, NPPVariable variable, void *value)
        #endif
    

    2.. There were 2 functions NP_GetValue and NPP_GetValue.

    extern "C"
    NPError NP_GetValue(void* instance, NPPVariable variable, void *value); 
    

    and

    NPError NPP_GetValue(NPP instance, NPPVariable variable, void *ret_value);
    

    NPP_GetValue is a plugin function whose registration should be made in NP_GetEntryPoints

        extern "C"
        NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* NPPluginFuncsptr)
        {
                ......
                NPPluginFuncsptr->newp = NPP_New;
                NPPluginFuncsptr->getvalue = NPP_GetValue;
                NPPluginFuncsptr->setvalue = NPP_SetValue;
                return NPERR_NO_ERROR;
        }
    

    In my code only NP_GetValue was implemented and NPP_GetValue was not implemented. So NPP_GetValue was undefined in .so and due to it the .so was not loading.

    On implementing the function NPP_GetValue this function was defined and exported in the .so file and was able to load it successfully.

    The sequence of calling of the functions from the browser to plugin is as follows...

    1. NP_Initialize - > Browser calls the initialization function first. (In case of Linux the set of plugin function should be exported by calling NP_GetEntryPoints explicity As browser will not call GetEntryPoints)

    2. NP_GetEntryPoints -> Called explicitly from NP_Initialize for Linux to expose/export plugin functions.

    3. NP_GetValue variable : 1 -> Called from Browser to get the Plugin Name (NPPVpluginNameString)

    4. NP_GetValue variable : 2 -> Called from Browser to get the Plugin Description (NPPVpluginDescriptionString)

    5. NP_GetMimeDescription -> Called from browser to get MimeType Description (This function should return Mime Type description e.g. : return("application/basic-plugin:bsc:Plug-ins SDK sample");)

    6. NPP_New -> Called from browser to create plugin instance.

    7. NPP_GetValue PLUGIN:main.cpp,NPP_GetValue,446ENTRY - > Called from browser to get plugin specific data...

    8. ......

    Please note that the next function in the above sequence will be called IF and ONLY IF the previous function call returns a success.:-)