Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
badapter.cpp File Reference
#include "npapi.h"
#include "nsIPluginManager.h"
#include "nsIServiceManager.h"
#include "nsIAllocator.h"
#include "nsLiveConnect.h"
#include "nsplugin.h"
#include "nsDebug.h"
#include <windows.h>

Go to the source code of this file.

Classes

class  CPluginManager
class  CPluginManagerStream
class  CPluginInstancePeer
class  CPluginStreamInfo
class  CPluginInputStream

Functions

 NS_DEFINE_IID (kPluginCID, NS_PLUGIN_CID)
static NS_DEFINE_IID (kPluginManagerCID, NS_PLUGINMANAGER_CID)
static NS_DEFINE_IID (kAllocatorCID, NS_ALLOCATOR_CID)
NPError NPP_Initialize (void)
jref NPP_GetJavaClass (void)
void NPP_Shutdown (void)
NPError NPP_New (NPMIMEType pluginType, NPP instance, PRUint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved)
NPError NPP_Destroy (NPP instance, NPSavedData **save)
NPError NPP_SetWindow (NPP instance, NPWindow *window)
NPError NPP_NewStream (NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, PRUint16 *stype)
int32 NPP_WriteReady (NPP instance, NPStream *stream)
int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPReason reason)
void NPP_StreamAsFile (NPP instance, NPStream *stream, const char *fname)
void NPP_Print (NPP instance, NPPrint *printInfo)
void NPP_URLNotify (NPP instance, const char *url, NPReason reason, void *notifyData)
int16 NPP_HandleEvent (NPP instance, void *event)

Variables

nsIPluginManagerthePluginManager = NULL
nsIPluginthePlugin = NULL
nsresult fromNPError []
int varMap []

Function Documentation

NPError NPP_Destroy ( NPP  instance,
NPSavedData **  save 
)

Definition at line 809 of file badapter.cpp.

{
//    TRACE("NPP_Destroy\n");
    
    if (instance == NULL)
        return NPERR_INVALID_INSTANCE_ERROR;
    
    CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata;
    nsIPluginInstance* pluginInstance = peer->GetInstance();
    pluginInstance->Stop();
    pluginInstance->Destroy();
    pluginInstance->Release();
       // peer->Release();
    instance->pdata = NULL;
    
    return NPERR_NO_ERROR;
}

Here is the call graph for this function:

NPError NPP_DestroyStream ( NPP  instance,
NPStream stream,
NPReason  reason 
)

Definition at line 946 of file badapter.cpp.

{
//    TRACE("NPP_DestroyStream\n");

    if (instance == NULL)
        return NPERR_INVALID_INSTANCE_ERROR;
              
    CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata;
    if (inStr == NULL)
        return NPERR_GENERIC_ERROR;
    inStr->GetListener()->OnStopBinding(inStr->GetPluginStreamInfo(), (nsPluginReason)reason);
    // inStr->Release();
    stream->pdata = NULL;
       
    return NPERR_NO_ERROR;
}

Here is the call graph for this function:

Definition at line 706 of file badapter.cpp.

{
    // Only call initialize the plugin if it hasn't been `d.
#if 0
    if (thePluginManager == NULL) {
        // Create the plugin manager and plugin objects.
        NPError result = CPluginManager::Create();      
        if (result) return NULL;
        assert( thePluginManager != NULL );
        thePluginManager->AddRef();
        NP_CreatePlugin(thePluginManager, (nsIPlugin** )(&thePlugin));
        assert( thePlugin != NULL );
    }
    return thePlugin->GetJavaClass();
#endif
    return NULL;
}

Here is the call graph for this function:

int16 NPP_HandleEvent ( NPP  instance,
void event 
)

Definition at line 1027 of file badapter.cpp.

{
//    TRACE("NPP_HandleEvent\n");
    int16 eventHandled = FALSE;
    if (instance == NULL)
        return eventHandled;
       
    NPEvent* npEvent = (NPEvent*) event;
    nsPluginEvent pluginEvent = {
#ifdef XP_MAC
        npEvent, NULL
#else
        npEvent->event, npEvent->wParam, npEvent->lParam
#endif
    };
       
    CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata;
    nsIPluginInstance* pluginInstance = peer->GetInstance();
    if (pluginInstance) {
        PRBool handled;
        nsresult err = pluginInstance->HandleEvent(&pluginEvent, &handled);
        if (err) return FALSE;
        eventHandled = (handled == PR_TRUE);
    }
       
    return eventHandled;
}

Here is the call graph for this function:

Definition at line 663 of file badapter.cpp.

{
//    TRACE("NPP_Initialize\n");

    // Only call initialize the plugin if it hasn't been created.
    // This could happen if GetJavaClass() is called before
    // NPP Initialize.  
    if (thePluginManager == NULL) {
        // Create the plugin manager and plugin classes.
        thePluginManager = new CPluginManager(); 
        if ( thePluginManager == NULL ) 
            return NPERR_OUT_OF_MEMORY_ERROR;  
        thePluginManager->AddRef();
    }
    nsresult error = NS_OK;  
    // On UNIX the plugin might have been created when calling NPP_GetMIMEType.
    if (thePlugin == NULL) {
        // create nsIPlugin factory
        error = (NPError)NSGetFactory(thePluginManager, kPluginCID, NULL, NULL, (nsIFactory** )&thePlugin);
#if 0
              // beard: this will leak reference counts.       
           if (error == NS_OK) {
              thePlugin->AddRef();
           }
#endif
       }
       
    return (NPError) error; 
}

Here is the call graph for this function:

NPError NPP_New ( NPMIMEType  pluginType,
NPP  instance,
PRUint16  mode,
int16  argc,
char *  argn[],
char *  argv[],
NPSavedData saved 
)

Definition at line 762 of file badapter.cpp.

{
//    TRACE("NPP_New\n");
    
    if (instance == NULL)
        return NPERR_INVALID_INSTANCE_ERROR;

    // Create a new plugin instance and start it.
    nsIPluginInstance* pluginInstance = NULL;
    thePlugin->CreatePluginInstance(thePluginManager, NS_GET_IID(nsIPluginInstance), pluginType, (void**)&pluginInstance);
    if (pluginInstance == NULL) {
        return NPERR_OUT_OF_MEMORY_ERROR;
    }
    
    // Create a new plugin instance peer,
    // XXX - Since np_instance is not implemented in the 4.0x browser, I
    // XXX - had to save the plugin parameter in the peer class.
    // XXX - Ask Warren about np_instance.
    CPluginInstancePeer* peer = new CPluginInstancePeer(pluginInstance, instance, (nsMIMEType)pluginType, 
                                                                          (nsPluginMode)mode, (PRUint16)argc, (const char** )argn, (const char** )argv);
    assert( peer != NULL );
    if (!peer) return NPERR_OUT_OF_MEMORY_ERROR;
    peer->AddRef();
    pluginInstance->Initialize(peer);
    pluginInstance->Start();
    // Set the user instance and store the peer in npp->pdata.
    instance->pdata = peer;
    peer->Release();

    return NPERR_NO_ERROR;
}
NPError NPP_NewStream ( NPP  instance,
NPMIMEType  type,
NPStream stream,
NPBool  seekable,
PRUint16 stype 
)

Definition at line 863 of file badapter.cpp.

{
    // XXX - How do you set the fields of the peer stream and stream?
    // XXX - Looks like these field will have to be created since
    // XXX - We are not using np_stream.
   
//    TRACE("NPP_NewStream\n");

    if (instance == NULL)
        return NPERR_INVALID_INSTANCE_ERROR;
                            
    CPluginInputStream* inStr = (CPluginInputStream*)stream->notifyData;
    if (inStr == NULL)
        return NPERR_GENERIC_ERROR;
    
    nsIPluginStreamInfo* info = inStr->CreatePluginStreamInfo(stream->url, type, seekable);
    nsresult err = inStr->GetListener()->OnStartBinding(info);
    if (err) return err;

    inStr->SetStreamInfo(instance, stream);
    stream->pdata = inStr;
    *stype = inStr->GetStreamType();

    return NPERR_NO_ERROR;
}

Here is the call graph for this function:

void NPP_Print ( NPP  instance,
NPPrint printInfo 
)

Definition at line 987 of file badapter.cpp.

{
//    TRACE("NPP_Print\n");

    if(printInfo == NULL)   // trap invalid parm
        return;

    if (instance != NULL)
    {
        CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata;
        nsIPluginInstance* pluginInstance = peer->GetInstance();
        pluginInstance->Print((nsPluginPrint* ) printInfo );
    }
}

Here is the call graph for this function:

NPError NPP_SetWindow ( NPP  instance,
NPWindow window 
)

Definition at line 833 of file badapter.cpp.

{
//    TRACE("NPP_SetWindow\n");
    
    if (instance == NULL)
        return NPERR_INVALID_INSTANCE_ERROR;

    CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata;
    if ( peer == NULL)
        return NPERR_INVALID_PLUGIN_ERROR;

       // record the window in the peer, so we can deliver proper events.
       peer->SetWindow(window);

    nsIPluginInstance* pluginInstance = peer->GetInstance();
    if( pluginInstance == 0 )
        return NPERR_INVALID_PLUGIN_ERROR;

    return (NPError)pluginInstance->SetWindow((nsPluginWindow* ) window );
}

Here is the call graph for this function:

Definition at line 733 of file badapter.cpp.

{
//    TRACE("NPP_Shutdown\n");

    if (thePlugin)
    {
        thePlugin->Shutdown();
        thePlugin->Release();
        thePlugin = NULL;
    }

    if (thePluginManager)  {
        thePluginManager->Release();
        thePluginManager = NULL;
    }
    
    return;
}
void NPP_StreamAsFile ( NPP  instance,
NPStream stream,
const char *  fname 
)

Definition at line 969 of file badapter.cpp.

{
//    TRACE("NPP_StreamAsFile\n");

    if (instance == NULL)
        return;
              
    CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata;
    if (inStr == NULL)
        return;
    (void)inStr->GetListener()->OnFileAvailable(inStr->GetPluginStreamInfo(), fname);
}

Here is the call graph for this function:

void NPP_URLNotify ( NPP  instance,
const char *  url,
NPReason  reason,
void notifyData 
)

Definition at line 1008 of file badapter.cpp.

{
//    TRACE("NPP_URLNotify\n");

    if (instance != NULL) {
        CPluginInputStream* inStr = (CPluginInputStream*)notifyData;
        (void)inStr->GetListener()->OnStopBinding(inStr->GetPluginStreamInfo(), (nsPluginReason)reason);
        inStr->Release();
    }
}

Here is the call graph for this function:

int32 NPP_Write ( NPP  instance,
NPStream stream,
int32  offset,
int32  len,
void buffer 
)

Definition at line 920 of file badapter.cpp.

{
//    TRACE("NPP_Write\n");

    if (instance == NULL)
        return -1;
       
    CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata;
    if (inStr == NULL)
        return -1;
    nsresult err = inStr->SetReadBuffer((PRUint32)len, (const char*)buffer);
    if (err != NS_OK) return -1;
    err = inStr->GetListener()->OnDataAvailable(inStr->GetPluginStreamInfo(), inStr, len);
    if (err != NS_OK) return -1;
    return len;
}

Here is the call graph for this function:

int32 NPP_WriteReady ( NPP  instance,
NPStream stream 
)

Definition at line 900 of file badapter.cpp.

{
//    TRACE("NPP_WriteReady\n");

    if (instance == NULL)
        return -1;

    CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata;
    if (inStr == NULL)
        return -1;
    return NP_MAXREADY;
}

Here is the call graph for this function:

NS_DEFINE_IID ( kPluginCID  ,
NS_PLUGIN_CID   
)
static NS_DEFINE_IID ( kPluginManagerCID  ,
NS_PLUGINMANAGER_CID   
) [static]
static NS_DEFINE_IID ( kAllocatorCID  ,
NS_ALLOCATOR_CID   
) [static]

Variable Documentation

Definition at line 539 of file badapter.cpp.

Definition at line 538 of file badapter.cpp.