Search code examples
visual-studio-2010firefoxwindows-7-x64npapi

NPAPI plugin not detected by Firefox


I'm trying to make Firefox (16.0.2 under Windows 7 x64 Professional) detect a blank NPAPI plugin. Here's my code.

nplithium.def

LIBRARY    nplithium

EXPORTS
    NP_GetEntryPoints     @1
    NP_Initialize         @2
    NP_Shutdown           @3

nplithium.rc

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (United States) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US

/////////////////////////////////////////////////////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 1,0,0,1
 PRODUCTVERSION 1,0,0,1
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x40004L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "CompanyName", "Antek SRL"
            VALUE "FileDescription", "Example Lithium"
            VALUE "FileVersion", "1.0.0.2"
            VALUE "InternalName", "nplithium"
            VALUE "LegalCopyright", "Copyright (C) Marco Buzzanca 2012"
            VALUE "MIMEType", "application/x-lithium"
            VALUE "OriginalFilename", "nplithium.dll"
            VALUE "ProductName", "lithium"
            VALUE "ProductVersion", "1.0.0.1"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END

#endif    // English (United States) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//

dll_entry.cpp

#include "npapi.h"
#include "npfunctions.h"

extern "C" 
{
    NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* functions) 
    {
        if(functions == NULL)
            return NPERR_INVALID_FUNCTABLE_ERROR;

        if(functions->size < sizeof(NPPluginFuncs))
            return NPERR_INVALID_FUNCTABLE_ERROR;

        functions->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
        functions->newp          = NULL;
        functions->destroy       = NULL;
        functions->setwindow     = NULL;
        functions->newstream     = NULL;
        functions->destroystream = NULL;
        functions->asfile        = NULL;
        functions->writeready    = NULL;
        functions->write         = NULL;
        functions->print         = NULL;
        functions->event         = NULL;
        functions->urlnotify     = NULL;
        functions->getvalue      = NULL;
        functions->setvalue      = NULL;
        functions->javaClass     = NULL;

        return NPERR_NO_ERROR;
    }

    NPError OSCALL NP_Initialize(NPNetscapeFuncs* functions)
    {
        return NPERR_NO_ERROR;
    }

    NPError OSCALL NP_Shutdown() 
    {
        return NPERR_NO_ERROR;
    }
}

Unfortunately, all of the sample plugins and tutorials I've found on the web are either obsolete or incomplete. The MDN doesn't help either, as it provides little to no information about what the browser expects these functions to do (NP_GetEntryPoints is completely undocumented).

Is there something I'm missing? I am not trying to make the plugin do anything, I just want firefox to detect it.


Solution

  • I managed to make Firefox detect my plugin.

    As specified in plug-in developement overview:

    For this the version stamp of the embedded resource of the plug-in DLL should contain the following set of string/value pairs:

    • MIMEType: for MIME types
    • FileExtents: for file extensions
    • FileOpenName: for file open template
    • ProductName: for plug-in name
    • FileDescription: for description
    • Language: for language in use

    I was missing a few of these pairs in my .rc file.