1998-07-11 05:39:51 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Backward Adapter
|
|
|
|
// This acts as a adapter layer to allow 5.0 plugins work with the 4.0/3.0
|
|
|
|
// browser.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SECTION 1 - Includes
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-09 05:55:13 +04:00
|
|
|
// extern "C" {
|
1998-07-11 05:39:51 +04:00
|
|
|
#include "npapi.h"
|
1998-08-09 05:55:13 +04:00
|
|
|
// }
|
1999-03-01 01:10:26 +03:00
|
|
|
#include "nsIPluginManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIAllocator.h"
|
1999-03-14 07:41:51 +03:00
|
|
|
#include "nsLiveConnect.h"
|
1998-07-11 05:39:51 +04:00
|
|
|
#include "nsplugin.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SECTION 3 - Classes
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CPluginManager
|
|
|
|
//
|
|
|
|
// This is the dummy plugin manager that interacts with the 5.0 plugin.
|
|
|
|
//
|
1999-03-01 01:10:26 +03:00
|
|
|
class CPluginManager : public nsIPluginManager, public nsIServiceManager, public nsIAllocator {
|
1998-07-11 05:39:51 +04:00
|
|
|
public:
|
1999-03-01 01:10:26 +03:00
|
|
|
// Need an operator new for this.
|
|
|
|
void* operator new(size_t size) { return ::NPN_MemAlloc(size); }
|
|
|
|
void operator delete(void* ptr) { ::NPN_MemFree(ptr); }
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
CPluginManager(void);
|
|
|
|
virtual ~CPluginManager(void);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsIPluginManager:
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// (Corresponds to NPN_GetValue.)
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
GetValue(nsPluginManagerVariable variable, void *value);
|
|
|
|
|
|
|
|
// (Corresponds to NPN_SetValue.)
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
SetValue(nsPluginManagerVariable variable, void *value);
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
ReloadPlugins(PRBool reloadPages);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// (Corresponds to NPN_UserAgent.)
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
UserAgent(const char* *result);
|
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetURL(nsISupports* pluginInst,
|
|
|
|
const char* url,
|
|
|
|
const char* target = NULL,
|
|
|
|
nsIPluginStreamListener* streamListener = NULL,
|
|
|
|
const char* altHost = NULL,
|
|
|
|
const char* referrer = NULL,
|
|
|
|
PRBool forceJSEnabled = PR_FALSE);
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
PostURL(nsISupports* pluginInst,
|
|
|
|
const char* url,
|
|
|
|
PRUint32 postDataLen,
|
|
|
|
const char* postData,
|
|
|
|
PRBool isFile = PR_FALSE,
|
|
|
|
const char* target = NULL,
|
|
|
|
nsIPluginStreamListener* streamListener = NULL,
|
|
|
|
const char* altHost = NULL,
|
|
|
|
const char* referrer = NULL,
|
|
|
|
PRBool forceJSEnabled = PR_FALSE,
|
|
|
|
PRUint32 postHeadersLength = 0,
|
|
|
|
const char* postHeaders = NULL);
|
|
|
|
|
1999-03-12 07:48:04 +03:00
|
|
|
/**
|
|
|
|
* RegisterService may be called explicitly to register a service
|
|
|
|
* with the service manager. If a service is not registered explicitly,
|
|
|
|
* the component manager will be used to create an instance according
|
|
|
|
* to the class ID specified.
|
|
|
|
*/
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
1999-03-12 07:48:04 +03:00
|
|
|
RegisterService(const nsCID& aClass, nsISupports* aService)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1999-03-12 07:48:04 +03:00
|
|
|
/**
|
|
|
|
* Requests a service to be shut down, possibly unloading its DLL.
|
|
|
|
*
|
|
|
|
* @returns NS_OK - if shutdown was successful and service was unloaded,
|
|
|
|
* @returns NS_ERROR_SERVICE_NOT_FOUND - if shutdown failed because
|
|
|
|
* the service was not currently loaded
|
|
|
|
* @returns NS_ERROR_SERVICE_IN_USE - if shutdown failed because some
|
|
|
|
* user of the service wouldn't voluntarily release it by using
|
|
|
|
* a shutdown listener.
|
|
|
|
*/
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
1999-03-12 07:48:04 +03:00
|
|
|
UnregisterService(const nsCID& aClass)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1998-09-01 04:17:25 +04:00
|
|
|
|
1999-03-01 01:10:26 +03:00
|
|
|
NS_IMETHOD
|
|
|
|
GetService(const nsCID& aClass, const nsIID& aIID,
|
|
|
|
nsISupports* *result,
|
|
|
|
nsIShutdownListener* shutdownListener = NULL);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
ReleaseService(const nsCID& aClass, nsISupports* service,
|
|
|
|
nsIShutdownListener* shutdownListener = NULL);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
1999-03-12 07:48:04 +03:00
|
|
|
GetService(const char* aProgID, const nsIID& aIID,
|
|
|
|
nsISupports* *result,
|
|
|
|
nsIShutdownListener* shutdownListener = NULL)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
ReleaseService(const char* aProgID, nsISupports* service,
|
|
|
|
nsIShutdownListener* shutdownListener = NULL)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1999-03-01 01:10:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a block of memory of a particular size.
|
|
|
|
*
|
|
|
|
* @param size - the size of the block to allocate
|
|
|
|
* @result the block of memory
|
|
|
|
*/
|
|
|
|
NS_IMETHOD_(void*)
|
|
|
|
Alloc(PRUint32 size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reallocates a block of memory to a new size.
|
|
|
|
*
|
|
|
|
* @param ptr - the block of memory to reallocate
|
|
|
|
* @param size - the new size
|
|
|
|
* @result the rellocated block of memory
|
|
|
|
*/
|
|
|
|
NS_IMETHOD_(void*)
|
|
|
|
Realloc(void* ptr, PRUint32 size);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Frees a block of memory.
|
|
|
|
*
|
|
|
|
* @param ptr - the block of memory to free
|
|
|
|
*/
|
|
|
|
NS_IMETHOD
|
|
|
|
Free(void* ptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to shrink the heap.
|
|
|
|
*/
|
|
|
|
NS_IMETHOD
|
|
|
|
HeapMinimize(void);
|
1999-03-14 07:41:51 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsILiveconnect* mLiveconnect;
|
1998-07-11 05:39:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CPluginManagerStream
|
|
|
|
//
|
|
|
|
// This is the dummy plugin manager stream that interacts with the 5.0 plugin.
|
|
|
|
//
|
|
|
|
class CPluginManagerStream : public nsIOutputStream {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
CPluginManagerStream(NPP npp, NPStream* pstr);
|
|
|
|
virtual ~CPluginManagerStream(void);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Taken from nsIStream
|
|
|
|
//
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
/** Write data into the stream.
|
|
|
|
* @param aBuf the buffer into which the data is read
|
|
|
|
* @param aCount the maximum number of bytes to read
|
|
|
|
* @param errorResult the error code if an error occurs
|
|
|
|
* @return number of bytes read or -1 if error
|
|
|
|
*/
|
|
|
|
NS_IMETHOD
|
1999-03-08 03:07:24 +03:00
|
|
|
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1999-04-22 11:31:03 +04:00
|
|
|
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Flush() {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Specific methods to nsIPluginManagerStream.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Corresponds to NPStream's url field.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetURL(const char* *result);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Corresponds to NPStream's end field.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetEnd(PRUint32 *result);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Corresponds to NPStream's lastmodfied field.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetLastModified(PRUint32 *result);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Corresponds to NPStream's notifyData field.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetNotifyData(void* *result);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Corresponds to NPStream's url field.
|
|
|
|
NS_IMETHOD Close(void);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// npp
|
|
|
|
// The plugin instance that the manager stream belongs to.
|
|
|
|
NPP npp;
|
|
|
|
|
|
|
|
// pstream
|
|
|
|
// The stream the class is using.
|
|
|
|
NPStream* pstream;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CPluginInstancePeer
|
|
|
|
//
|
|
|
|
// This is the dummy instance peer that interacts with the 5.0 plugin.
|
|
|
|
// In order to do LiveConnect, the class subclasses nsILiveConnectPluginInstancePeer.
|
|
|
|
//
|
|
|
|
class CPluginInstancePeer : public nsIPluginInstancePeer, public nsIPluginTagInfo {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// XXX - I add parameters to the constructor because I wasn't sure if
|
|
|
|
// XXX - the 4.0 browser had the npp_instance struct implemented.
|
|
|
|
// XXX - If so, then I can access npp_instance through npp->ndata.
|
1998-08-09 07:17:39 +04:00
|
|
|
CPluginInstancePeer(nsIPluginInstance* pluginInstance, NPP npp, nsMIMEType typeString, nsPluginMode type,
|
1998-07-11 05:39:51 +04:00
|
|
|
PRUint16 attribute_cnt, const char** attribute_list, const char** values_list);
|
1998-08-09 07:17:39 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
virtual ~CPluginInstancePeer(void);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
// (Corresponds to NPN_GetValue.)
|
|
|
|
NS_IMETHOD
|
|
|
|
GetValue(nsPluginInstancePeerVariable variable, void *value);
|
|
|
|
|
|
|
|
// (Corresponds to NPN_SetValue.)
|
|
|
|
NS_IMETHOD
|
|
|
|
SetValue(nsPluginInstancePeerVariable variable, void *value);
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
// Corresponds to NPP_New's MIMEType argument.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetMIMEType(nsMIMEType *result);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Corresponds to NPP_New's mode argument.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetMode(nsPluginMode *result);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Get a ptr to the paired list of attribute names and values,
|
|
|
|
// returns the length of the array.
|
|
|
|
//
|
|
|
|
// Each name or value is a null-terminated string.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
GetAttributes(PRUint16& n, const char* const*& names, const char* const*& values);
|
|
|
|
|
|
|
|
// Get the value for the named attribute. Returns null
|
|
|
|
// if the attribute was not set.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
|
|
|
GetAttribute(const char* name, const char* *result);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Corresponds to NPN_NewStream.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result);
|
|
|
|
|
|
|
|
// Corresponds to NPN_ShowStatus.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
ShowStatus(const char* message);
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMETHOD
|
1998-09-15 07:45:38 +04:00
|
|
|
SetWindowSize(PRUint32 width, PRUint32 height);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-08-09 07:17:39 +04:00
|
|
|
nsIPluginInstance* GetInstance(void) { return mInstance; }
|
|
|
|
NPP GetNPPInstance(void) { return npp; }
|
|
|
|
|
|
|
|
void SetWindow(NPWindow* window) { mWindow = window; }
|
|
|
|
NPWindow* GetWindow() { return mWindow; }
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
NPP npp;
|
|
|
|
// XXX - The next five variables may need to be here since I
|
|
|
|
// XXX - don't think np_instance is available in 4.0X.
|
1998-08-09 07:17:39 +04:00
|
|
|
nsIPluginInstance* mInstance;
|
|
|
|
NPWindow* mWindow;
|
1998-07-11 05:39:51 +04:00
|
|
|
nsMIMEType typeString;
|
1998-08-01 00:19:50 +04:00
|
|
|
nsPluginMode type;
|
1998-07-11 05:39:51 +04:00
|
|
|
PRUint16 attribute_cnt;
|
|
|
|
char** attribute_list;
|
|
|
|
char** values_list;
|
|
|
|
};
|
|
|
|
|
1999-02-15 21:29:06 +03:00
|
|
|
class CPluginStreamInfo : public nsIPluginStreamInfo {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
1999-03-12 07:48:04 +03:00
|
|
|
CPluginStreamInfo(const char* URL, nsIPluginInputStream* inStr, nsMIMEType type, PRBool seekable)
|
|
|
|
: mURL(URL), mInputStream(inStr), mMimeType(type), mIsSeekable(seekable) {}
|
1999-02-15 21:29:06 +03:00
|
|
|
|
|
|
|
virtual ~CPluginStreamInfo() {}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
GetContentType(nsMIMEType* result)
|
|
|
|
{
|
|
|
|
*result = mMimeType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
IsSeekable(PRBool* result)
|
|
|
|
{
|
|
|
|
*result = mIsSeekable;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
GetLength(PRUint32* result)
|
|
|
|
{
|
|
|
|
return mInputStream->GetLength(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
GetLastModified(PRUint32* result)
|
|
|
|
{
|
|
|
|
return mInputStream->GetLastModified(result);
|
|
|
|
}
|
|
|
|
|
1999-03-12 07:48:04 +03:00
|
|
|
NS_METHOD
|
|
|
|
GetURL(const char** result)
|
|
|
|
{
|
|
|
|
*result = mURL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-15 21:29:06 +03:00
|
|
|
NS_METHOD
|
|
|
|
RequestRead(nsByteRange* rangeList)
|
|
|
|
{
|
|
|
|
return mInputStream->RequestRead(rangeList);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
1999-03-12 07:48:04 +03:00
|
|
|
const char* mURL;
|
1999-02-15 21:29:06 +03:00
|
|
|
nsIPluginInputStream* mInputStream;
|
|
|
|
nsMIMEType mMimeType;
|
|
|
|
PRBool mIsSeekable;
|
|
|
|
};
|
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
class CPluginInputStream : public nsIPluginInputStream {
|
|
|
|
public:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsIBaseStream:
|
|
|
|
|
|
|
|
/** Close the stream. */
|
|
|
|
NS_IMETHOD
|
|
|
|
Close(void);
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsIInputStream:
|
|
|
|
|
|
|
|
/** Return the number of bytes in the stream
|
|
|
|
* @param aLength out parameter to hold the length
|
|
|
|
* of the stream. if an error occurs, the length
|
|
|
|
* will be undefined
|
|
|
|
* @return error status
|
|
|
|
*/
|
|
|
|
NS_IMETHOD
|
1999-02-15 21:29:06 +03:00
|
|
|
GetLength(PRUint32 *aLength);
|
1998-10-01 06:59:16 +04:00
|
|
|
|
|
|
|
/** Read data from the stream.
|
|
|
|
* @param aErrorCode the error code if an error occurs
|
|
|
|
* @param aBuf the buffer into which the data is read
|
|
|
|
* @param aCount the maximum number of bytes to read
|
|
|
|
* @param aReadCount out parameter to hold the number of
|
|
|
|
* bytes read, eof if 0. if an error occurs, the
|
|
|
|
* read count will be undefined
|
|
|
|
* @return error status
|
|
|
|
*/
|
|
|
|
NS_IMETHOD
|
1999-03-08 03:07:24 +03:00
|
|
|
Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount);
|
1998-10-01 06:59:16 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsIPluginInputStream:
|
|
|
|
|
|
|
|
// (Corresponds to NPStream's lastmodified field.)
|
|
|
|
NS_IMETHOD
|
|
|
|
GetLastModified(PRUint32 *result);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
RequestRead(nsByteRange* rangeList);
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPluginInputStream specific methods:
|
|
|
|
|
1999-02-15 21:29:06 +03:00
|
|
|
CPluginInputStream(nsIPluginStreamListener* listener);
|
1998-10-01 06:59:16 +04:00
|
|
|
virtual ~CPluginInputStream(void);
|
|
|
|
|
|
|
|
void SetStreamInfo(NPP npp, NPStream* stream) {
|
|
|
|
mNPP = npp;
|
|
|
|
mStream = stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPluginStreamListener* GetListener(void) { return mListener; }
|
|
|
|
nsPluginStreamType GetStreamType(void) { return mStreamType; }
|
|
|
|
|
|
|
|
nsresult SetReadBuffer(PRUint32 len, const char* buffer) {
|
|
|
|
// XXX this has to be way more sophisticated
|
1999-02-15 21:29:06 +03:00
|
|
|
mBuffer = dup(len, buffer);
|
1998-10-01 06:59:16 +04:00
|
|
|
mBufferLength = len;
|
|
|
|
mAmountRead = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-15 21:29:06 +03:00
|
|
|
|
|
|
|
char* dup(PRUint32 len, const char* buffer) {
|
|
|
|
char* result = new char[len];
|
|
|
|
if (result != NULL) {
|
|
|
|
const char *src = buffer;
|
|
|
|
char *dest = result;
|
|
|
|
while (len-- > 0)
|
|
|
|
*dest++ = *src++;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-03-12 07:48:04 +03:00
|
|
|
nsIPluginStreamInfo* CreatePluginStreamInfo(const char* url, nsMIMEType type, PRBool seekable) {
|
1999-02-15 21:29:06 +03:00
|
|
|
if (mStreamInfo == NULL) {
|
1999-03-12 07:48:04 +03:00
|
|
|
mStreamInfo = new CPluginStreamInfo(url, this, type, seekable);
|
1999-02-15 21:29:06 +03:00
|
|
|
mStreamInfo->AddRef();
|
|
|
|
}
|
|
|
|
return mStreamInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPluginStreamInfo* GetPluginStreamInfo() {
|
|
|
|
return mStreamInfo;
|
|
|
|
}
|
1998-10-01 06:59:16 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const char* mURL;
|
|
|
|
nsIPluginStreamListener* mListener;
|
|
|
|
nsPluginStreamType mStreamType;
|
|
|
|
NPP mNPP;
|
|
|
|
NPStream* mStream;
|
|
|
|
char* mBuffer;
|
|
|
|
PRUint32 mBufferLength;
|
|
|
|
PRUint32 mAmountRead;
|
1999-02-15 21:29:06 +03:00
|
|
|
nsIPluginStreamInfo* mStreamInfo;
|
1998-10-01 06:59:16 +04:00
|
|
|
};
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
#define TRACE(foo) trace(foo)
|
|
|
|
#endif
|
|
|
|
|
1998-08-09 05:55:13 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#undef assert
|
|
|
|
#define assert(cond)
|
|
|
|
#endif
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SECTION 1 - Includes
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-09 05:55:13 +04:00
|
|
|
#if defined(XP_UNIX) || defined(XP_MAC)
|
1998-07-11 05:39:51 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#else
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
1998-08-09 05:55:13 +04:00
|
|
|
// SECTION 2 - Global Variables
|
1998-07-11 05:39:51 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//
|
|
|
|
// thePlugin and thePluginManager are used in the life of the plugin.
|
|
|
|
//
|
|
|
|
// These two will be created on NPP_Initialize and destroyed on NPP_Shutdown.
|
|
|
|
//
|
|
|
|
nsIPluginManager* thePluginManager = NULL;
|
|
|
|
nsIPlugin* thePlugin = NULL;
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsISupports IDs
|
|
|
|
//
|
|
|
|
// Interface IDs for nsISupports
|
|
|
|
//
|
1999-03-01 01:10:26 +03:00
|
|
|
NS_DEFINE_IID(kPluginCID, NS_PLUGIN_CID);
|
1999-03-12 07:48:04 +03:00
|
|
|
static NS_DEFINE_IID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
|
|
|
|
static NS_DEFINE_IID(kAllocatorCID, NS_ALLOCATOR_CID);
|
1998-10-01 06:59:16 +04:00
|
|
|
|
1999-02-15 21:29:06 +03:00
|
|
|
NS_DEFINE_IID(kIPluginStreamInfoIID, NS_IPLUGINSTREAMINFO_IID);
|
1998-10-01 06:59:16 +04:00
|
|
|
NS_DEFINE_IID(kIPluginInputStreamIID, NS_IPLUGININPUTSTREAM_IID);
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
// mapping from NPError to nsresult
|
|
|
|
nsresult fromNPError[] = {
|
|
|
|
NS_OK, // NPERR_NO_ERROR,
|
|
|
|
NS_ERROR_FAILURE, // NPERR_GENERIC_ERROR,
|
|
|
|
NS_ERROR_FAILURE, // NPERR_INVALID_INSTANCE_ERROR,
|
|
|
|
NS_ERROR_NOT_INITIALIZED, // NPERR_INVALID_FUNCTABLE_ERROR,
|
|
|
|
NS_ERROR_FACTORY_NOT_LOADED, // NPERR_MODULE_LOAD_FAILED_ERROR,
|
|
|
|
NS_ERROR_OUT_OF_MEMORY, // NPERR_OUT_OF_MEMORY_ERROR,
|
|
|
|
NS_NOINTERFACE, // NPERR_INVALID_PLUGIN_ERROR,
|
|
|
|
NS_ERROR_ILLEGAL_VALUE, // NPERR_INVALID_PLUGIN_DIR_ERROR,
|
|
|
|
NS_NOINTERFACE, // NPERR_INCOMPATIBLE_VERSION_ERROR,
|
|
|
|
NS_ERROR_ILLEGAL_VALUE, // NPERR_INVALID_PARAM,
|
|
|
|
NS_ERROR_ILLEGAL_VALUE, // NPERR_INVALID_URL,
|
|
|
|
NS_ERROR_ILLEGAL_VALUE, // NPERR_FILE_NOT_FOUND,
|
|
|
|
NS_ERROR_FAILURE, // NPERR_NO_DATA,
|
|
|
|
NS_ERROR_FAILURE // NPERR_STREAM_NOT_SEEKABLE,
|
|
|
|
};
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SECTION 4 - API Shim Plugin Implementations
|
|
|
|
// Glue code to the 5.0x Plugin.
|
|
|
|
//
|
|
|
|
// Most of the NPP_* functions that interact with the plug-in will need to get
|
|
|
|
// the instance peer from npp->pdata so it can get the plugin instance from the
|
|
|
|
// peer. Once the plugin instance is available, the appropriate 5.0 plug-in
|
|
|
|
// function can be called:
|
|
|
|
//
|
|
|
|
// CPluginInstancePeer* peer = (CPluginInstancePeer* )instance->pdata;
|
|
|
|
// nsIPluginInstance* inst = peer->GetUserInstance();
|
|
|
|
// inst->NewPluginAPIFunction();
|
|
|
|
//
|
|
|
|
// Similar steps takes place with streams. The stream peer is stored in NPStream's
|
|
|
|
// pdata. Get the peer, get the stream, call the function.
|
|
|
|
//
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// UNIX-only API calls
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
char* NPP_GetMIMEDescription(void)
|
|
|
|
{
|
|
|
|
int freeFac = 0;
|
1998-08-01 00:19:50 +04:00
|
|
|
//fprintf(stderr, "MIME description\n");
|
1998-07-11 05:39:51 +04:00
|
|
|
if (thePlugin == NULL) {
|
1998-08-01 00:19:50 +04:00
|
|
|
freeFac = 1;
|
1999-03-01 01:10:26 +03:00
|
|
|
NSGetFactory(thePluginManager, kPluginCID, NULL, NULL, (nsIFactory** )&thePlugin);
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
1998-08-01 00:19:50 +04:00
|
|
|
//fprintf(stderr, "Allocated Plugin 0x%08x\n", thePlugin);
|
|
|
|
const char * ret;
|
|
|
|
nsresult err = thePlugin->GetMIMEDescription(&ret);
|
|
|
|
if (err) return NULL;
|
|
|
|
//fprintf(stderr, "Get response %s\n", ret);
|
1998-07-11 05:39:51 +04:00
|
|
|
if (freeFac) {
|
1998-08-01 00:19:50 +04:00
|
|
|
//fprintf(stderr, "Freeing plugin...");
|
|
|
|
thePlugin->Release();
|
|
|
|
thePlugin = NULL;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
1998-08-01 00:19:50 +04:00
|
|
|
//fprintf(stderr, "Done\n");
|
|
|
|
return (char*)ret;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Cross-Platform Plug-in API Calls
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_SetValue:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NPError
|
|
|
|
NPP_SetValue(NPP instance, NPNVariable variable, void *value)
|
|
|
|
{
|
1998-08-01 00:19:50 +04:00
|
|
|
return NPERR_GENERIC_ERROR; // nothing to set
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_GetValue:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NPError
|
|
|
|
NPP_GetValue(NPP instance, NPPVariable variable, void *value) {
|
|
|
|
int freeFac = 0;
|
1998-08-01 00:19:50 +04:00
|
|
|
//fprintf(stderr, "MIME description\n");
|
1998-07-11 05:39:51 +04:00
|
|
|
if (thePlugin == NULL) {
|
1998-08-01 00:19:50 +04:00
|
|
|
freeFac = 1;
|
1999-03-01 01:10:26 +03:00
|
|
|
if (NSGetFactory(thePluginManager, kPluginCID, NULL, NULL, (nsIFactory** )&thePlugin) != NS_OK)
|
1998-08-01 00:19:50 +04:00
|
|
|
return NPERR_GENERIC_ERROR;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
1998-08-01 00:19:50 +04:00
|
|
|
//fprintf(stderr, "Allocated Plugin 0x%08x\n", thePlugin);
|
|
|
|
nsresult err = thePlugin->GetValue((nsPluginVariable)variable, value);
|
|
|
|
if (err) return NPERR_GENERIC_ERROR;
|
|
|
|
//fprintf(stderr, "Get response %08x\n", ret);
|
1998-07-11 05:39:51 +04:00
|
|
|
if (freeFac) {
|
1998-08-01 00:19:50 +04:00
|
|
|
//fprintf(stderr, "Freeing plugin...");
|
|
|
|
thePlugin->Release();
|
|
|
|
thePlugin = NULL;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
1998-08-01 00:19:50 +04:00
|
|
|
//fprintf(stderr, "Done\n");
|
|
|
|
return NPERR_NO_ERROR;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
1998-08-01 00:19:50 +04:00
|
|
|
#endif // XP_UNIX
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_Initialize:
|
|
|
|
// Provides global initialization for a plug-in, and returns an error value.
|
|
|
|
//
|
|
|
|
// This function is called once when a plug-in is loaded, before the first instance
|
|
|
|
// is created. thePluginManager and thePlugin are both initialized.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NPError
|
|
|
|
NPP_Initialize(void)
|
|
|
|
{
|
|
|
|
// 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) {
|
1998-08-01 00:19:50 +04:00
|
|
|
// Create the plugin manager and plugin classes.
|
|
|
|
thePluginManager = new CPluginManager();
|
|
|
|
if ( thePluginManager == NULL )
|
|
|
|
return NPERR_OUT_OF_MEMORY_ERROR;
|
|
|
|
thePluginManager->AddRef();
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
nsresult error = NS_OK;
|
|
|
|
// On UNIX the plugin might have been created when calling NPP_GetMIMEType.
|
1998-08-09 07:17:39 +04:00
|
|
|
if (thePlugin == NULL) {
|
1998-08-01 00:19:50 +04:00
|
|
|
// create nsIPlugin factory
|
1999-03-01 01:10:26 +03:00
|
|
|
error = (NPError)NSGetFactory(thePluginManager, kPluginCID, NULL, NULL, (nsIFactory** )&thePlugin);
|
|
|
|
#if 0
|
|
|
|
// beard: this will leak reference counts.
|
1998-08-09 07:17:39 +04:00
|
|
|
if (error == NS_OK) {
|
|
|
|
thePlugin->AddRef();
|
|
|
|
}
|
1999-03-01 01:10:26 +03:00
|
|
|
#endif
|
1998-08-09 07:17:39 +04:00
|
|
|
}
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
return (NPError) error;
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_GetJavaClass:
|
|
|
|
// New in Netscape Navigator 3.0.
|
|
|
|
//
|
|
|
|
// NPP_GetJavaClass is called during initialization to ask your plugin
|
|
|
|
// what its associated Java class is. If you don't have one, just return
|
|
|
|
// NULL. Otherwise, use the javah-generated "use_" function to both
|
|
|
|
// initialize your class and return it. If you can't find your class, an
|
|
|
|
// error will be signalled by "use_" and will cause the Navigator to
|
|
|
|
// complain to the user.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
jref
|
|
|
|
NPP_GetJavaClass(void)
|
|
|
|
{
|
|
|
|
// Only call initialize the plugin if it hasn't been `d.
|
1998-10-01 06:59:16 +04:00
|
|
|
#if 0
|
|
|
|
if (thePluginManager == NULL) {
|
1998-07-11 05:39:51 +04:00
|
|
|
// Create the plugin manager and plugin objects.
|
|
|
|
NPError result = CPluginManager::Create();
|
|
|
|
if (result) return NULL;
|
1998-10-01 06:59:16 +04:00
|
|
|
assert( thePluginManager != NULL );
|
1998-07-11 05:39:51 +04:00
|
|
|
thePluginManager->AddRef();
|
|
|
|
NP_CreatePlugin(thePluginManager, (nsIPlugin** )(&thePlugin));
|
|
|
|
assert( thePlugin != NULL );
|
1998-10-01 06:59:16 +04:00
|
|
|
}
|
|
|
|
return thePlugin->GetJavaClass();
|
|
|
|
#endif
|
|
|
|
return NULL;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_Shutdown:
|
|
|
|
// Provides global deinitialization for a plug-in.
|
|
|
|
//
|
|
|
|
// This function is called once after the last instance of your plug-in
|
|
|
|
// is destroyed. thePluginManager and thePlugin are delete at this time.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
void
|
|
|
|
NPP_Shutdown(void)
|
|
|
|
{
|
1998-10-01 06:59:16 +04:00
|
|
|
// TRACE("NPP_Shutdown\n");
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
if (thePlugin)
|
|
|
|
{
|
|
|
|
thePlugin->Shutdown();
|
|
|
|
thePlugin->Release();
|
|
|
|
thePlugin = NULL;
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
if (thePluginManager) {
|
|
|
|
thePluginManager->Release();
|
|
|
|
thePluginManager = NULL;
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_New:
|
|
|
|
// Creates a new instance of a plug-in and returns an error value.
|
|
|
|
//
|
|
|
|
// A plugin instance peer and instance peer is created. After
|
|
|
|
// a successful instansiation, the peer is stored in the plugin
|
|
|
|
// instance's pdata.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NPError
|
|
|
|
NPP_New(NPMIMEType pluginType,
|
|
|
|
NPP instance,
|
|
|
|
PRUint16 mode,
|
|
|
|
int16 argc,
|
|
|
|
char* argn[],
|
|
|
|
char* argv[],
|
|
|
|
NPSavedData* saved)
|
|
|
|
{
|
|
|
|
// TRACE("NPP_New\n");
|
|
|
|
|
|
|
|
if (instance == NULL)
|
1998-08-01 00:19:50 +04:00
|
|
|
return NPERR_INVALID_INSTANCE_ERROR;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Create a new plugin instance and start it.
|
|
|
|
nsIPluginInstance* pluginInstance = NULL;
|
1999-03-14 23:09:57 +03:00
|
|
|
thePlugin->CreatePluginInstance(thePluginManager, nsIPluginInstance::GetIID(), pluginType, (void**)&pluginInstance);
|
1998-07-11 05:39:51 +04:00
|
|
|
if (pluginInstance == NULL) {
|
1998-08-01 00:19:50 +04:00
|
|
|
return NPERR_OUT_OF_MEMORY_ERROR;
|
1999-03-01 01:10:26 +03:00
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// 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.
|
1998-08-09 07:17:39 +04:00
|
|
|
CPluginInstancePeer* peer = new CPluginInstancePeer(pluginInstance, instance, (nsMIMEType)pluginType,
|
|
|
|
(nsPluginMode)mode, (PRUint16)argc, (const char** )argn, (const char** )argv);
|
1998-07-11 05:39:51 +04:00
|
|
|
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.
|
1998-08-09 07:17:39 +04:00
|
|
|
instance->pdata = peer;
|
1998-07-11 05:39:51 +04:00
|
|
|
peer->Release();
|
|
|
|
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_Destroy:
|
|
|
|
// Deletes a specific instance of a plug-in and returns an error value.
|
|
|
|
//
|
|
|
|
// The plugin instance peer and plugin instance are destroyed.
|
|
|
|
// The instance's pdata is set to NULL.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NPError
|
|
|
|
NPP_Destroy(NPP instance, NPSavedData** save)
|
|
|
|
{
|
|
|
|
// TRACE("NPP_Destroy\n");
|
|
|
|
|
|
|
|
if (instance == NULL)
|
1998-08-01 00:19:50 +04:00
|
|
|
return NPERR_INVALID_INSTANCE_ERROR;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-08-09 07:17:39 +04:00
|
|
|
CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata;
|
|
|
|
nsIPluginInstance* pluginInstance = peer->GetInstance();
|
1998-07-11 05:39:51 +04:00
|
|
|
pluginInstance->Stop();
|
|
|
|
pluginInstance->Destroy();
|
|
|
|
pluginInstance->Release();
|
1998-08-09 07:17:39 +04:00
|
|
|
// peer->Release();
|
1998-07-11 05:39:51 +04:00
|
|
|
instance->pdata = NULL;
|
|
|
|
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_SetWindow:
|
|
|
|
// Sets the window in which a plug-in draws, and returns an error value.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NPError
|
|
|
|
NPP_SetWindow(NPP instance, NPWindow* window)
|
|
|
|
{
|
|
|
|
// TRACE("NPP_SetWindow\n");
|
|
|
|
|
|
|
|
if (instance == NULL)
|
1998-08-01 00:19:50 +04:00
|
|
|
return NPERR_INVALID_INSTANCE_ERROR;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-08-09 07:17:39 +04:00
|
|
|
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();
|
1998-07-11 05:39:51 +04:00
|
|
|
if( pluginInstance == 0 )
|
1998-08-01 00:19:50 +04:00
|
|
|
return NPERR_INVALID_PLUGIN_ERROR;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
return (NPError)pluginInstance->SetWindow((nsPluginWindow* ) window );
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_NewStream:
|
|
|
|
// Notifies an instance of a new data stream and returns an error value.
|
|
|
|
//
|
|
|
|
// Create a stream peer and stream. If succesful, save
|
|
|
|
// the stream peer in NPStream's pdata.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NPError
|
|
|
|
NPP_NewStream(NPP instance,
|
1998-10-01 06:59:16 +04:00
|
|
|
NPMIMEType type,
|
|
|
|
NPStream *stream,
|
|
|
|
NPBool seekable,
|
|
|
|
PRUint16 *stype)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
|
|
|
// 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)
|
1998-08-01 00:19:50 +04:00
|
|
|
return NPERR_INVALID_INSTANCE_ERROR;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
CPluginInputStream* inStr = (CPluginInputStream*)stream->notifyData;
|
|
|
|
if (inStr == NULL)
|
|
|
|
return NPERR_GENERIC_ERROR;
|
1999-02-15 21:29:06 +03:00
|
|
|
|
1999-03-12 07:48:04 +03:00
|
|
|
nsIPluginStreamInfo* info = inStr->CreatePluginStreamInfo(stream->url, type, seekable);
|
|
|
|
nsresult err = inStr->GetListener()->OnStartBinding(info);
|
1998-10-01 06:59:16 +04:00
|
|
|
if (err) return err;
|
|
|
|
|
|
|
|
inStr->SetStreamInfo(instance, stream);
|
|
|
|
stream->pdata = inStr;
|
|
|
|
*stype = inStr->GetStreamType();
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_WriteReady:
|
|
|
|
// Returns the maximum number of bytes that an instance is prepared to accept
|
|
|
|
// from the stream.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
int32
|
|
|
|
NPP_WriteReady(NPP instance, NPStream *stream)
|
|
|
|
{
|
|
|
|
// TRACE("NPP_WriteReady\n");
|
|
|
|
|
|
|
|
if (instance == NULL)
|
1998-08-01 00:19:50 +04:00
|
|
|
return -1;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata;
|
|
|
|
if (inStr == NULL)
|
|
|
|
return -1;
|
|
|
|
return NP_MAXREADY;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_Write:
|
|
|
|
// Delivers data from a stream and returns the number of bytes written.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
int32
|
|
|
|
NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
|
|
|
|
{
|
|
|
|
// TRACE("NPP_Write\n");
|
|
|
|
|
|
|
|
if (instance == NULL)
|
1998-08-01 00:19:50 +04:00
|
|
|
return -1;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
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;
|
1999-03-12 07:48:04 +03:00
|
|
|
err = inStr->GetListener()->OnDataAvailable(inStr->GetPluginStreamInfo(), inStr, len);
|
1998-10-01 06:59:16 +04:00
|
|
|
if (err != NS_OK) return -1;
|
|
|
|
return len;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_DestroyStream:
|
|
|
|
// Indicates the closure and deletion of a stream, and returns an error value.
|
|
|
|
//
|
|
|
|
// The stream peer and stream are destroyed. NPStream's
|
|
|
|
// pdata is set to NULL.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NPError
|
|
|
|
NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
|
|
|
|
{
|
|
|
|
// TRACE("NPP_DestroyStream\n");
|
|
|
|
|
|
|
|
if (instance == NULL)
|
1998-08-01 00:19:50 +04:00
|
|
|
return NPERR_INVALID_INSTANCE_ERROR;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata;
|
|
|
|
if (inStr == NULL)
|
|
|
|
return NPERR_GENERIC_ERROR;
|
1999-03-12 07:48:04 +03:00
|
|
|
inStr->GetListener()->OnStopBinding(inStr->GetPluginStreamInfo(), (nsPluginReason)reason);
|
1999-03-02 07:46:05 +03:00
|
|
|
// inStr->Release();
|
1998-10-01 06:59:16 +04:00
|
|
|
stream->pdata = NULL;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
return NPERR_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_StreamAsFile:
|
|
|
|
// Provides a local file name for the data from a stream.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
void
|
|
|
|
NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
|
|
|
|
{
|
1998-10-01 06:59:16 +04:00
|
|
|
// TRACE("NPP_StreamAsFile\n");
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
if (instance == NULL)
|
|
|
|
return;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
CPluginInputStream* inStr = (CPluginInputStream*)stream->pdata;
|
|
|
|
if (inStr == NULL)
|
|
|
|
return;
|
1999-03-12 07:48:04 +03:00
|
|
|
(void)inStr->GetListener()->OnFileAvailable(inStr->GetPluginStreamInfo(), fname);
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_Print:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
void
|
|
|
|
NPP_Print(NPP instance, NPPrint* printInfo)
|
|
|
|
{
|
|
|
|
// TRACE("NPP_Print\n");
|
|
|
|
|
|
|
|
if(printInfo == NULL) // trap invalid parm
|
|
|
|
return;
|
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
if (instance != NULL)
|
|
|
|
{
|
|
|
|
CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata;
|
|
|
|
nsIPluginInstance* pluginInstance = peer->GetInstance();
|
|
|
|
pluginInstance->Print((nsPluginPrint* ) printInfo );
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_URLNotify:
|
|
|
|
// Notifies the instance of the completion of a URL request.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
void
|
|
|
|
NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
|
|
|
|
{
|
1998-10-01 06:59:16 +04:00
|
|
|
// TRACE("NPP_URLNotify\n");
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
if (instance != NULL) {
|
|
|
|
CPluginInputStream* inStr = (CPluginInputStream*)notifyData;
|
1999-03-12 07:48:04 +03:00
|
|
|
(void)inStr->GetListener()->OnStopBinding(inStr->GetPluginStreamInfo(), (nsPluginReason)reason);
|
1999-03-02 07:46:05 +03:00
|
|
|
inStr->Release();
|
1998-10-01 06:59:16 +04:00
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NPP_HandleEvent:
|
|
|
|
// Mac-only, but stub must be present for Windows
|
|
|
|
// Delivers a platform-specific event to the instance.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
#ifndef XP_UNIX
|
|
|
|
int16
|
|
|
|
NPP_HandleEvent(NPP instance, void* event)
|
|
|
|
{
|
|
|
|
// TRACE("NPP_HandleEvent\n");
|
1998-10-01 06:59:16 +04:00
|
|
|
int16 eventHandled = FALSE;
|
|
|
|
if (instance == NULL)
|
|
|
|
return eventHandled;
|
1998-08-09 07:17:39 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
NPEvent* npEvent = (NPEvent*) event;
|
|
|
|
nsPluginEvent pluginEvent = {
|
1998-08-09 07:17:39 +04:00
|
|
|
#ifdef XP_MAC
|
1998-10-01 06:59:16 +04:00
|
|
|
npEvent, NULL
|
1998-08-09 07:17:39 +04:00
|
|
|
#else
|
1998-10-01 06:59:16 +04:00
|
|
|
npEvent->event, npEvent->wParam, npEvent->lParam
|
1998-08-09 07:17:39 +04:00
|
|
|
#endif
|
1998-10-01 06:59:16 +04:00
|
|
|
};
|
1998-08-09 07:17:39 +04:00
|
|
|
|
|
|
|
CPluginInstancePeer* peer = (CPluginInstancePeer*) instance->pdata;
|
|
|
|
nsIPluginInstance* pluginInstance = peer->GetInstance();
|
1998-10-01 06:59:16 +04:00
|
|
|
if (pluginInstance) {
|
1998-08-01 00:19:50 +04:00
|
|
|
PRBool handled;
|
1998-10-01 06:59:16 +04:00
|
|
|
nsresult err = pluginInstance->HandleEvent(&pluginEvent, &handled);
|
1998-08-01 00:19:50 +04:00
|
|
|
if (err) return FALSE;
|
|
|
|
eventHandled = (handled == PR_TRUE);
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
return eventHandled;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
#endif // ndef XP_UNIX
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SECTION 5 - API Browser Implementations
|
|
|
|
//
|
|
|
|
// Glue code to the 4.0x Browser.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CPluginManager
|
|
|
|
//
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
//
|
|
|
|
// Once we moved to the new APIs, we need to implement fJVMMgr.
|
|
|
|
//
|
|
|
|
//******************************************************************************
|
|
|
|
|
1999-03-14 07:41:51 +03:00
|
|
|
CPluginManager::CPluginManager(void)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
|
|
|
// Set reference count to 0.
|
|
|
|
NS_INIT_REFCNT();
|
1999-03-14 07:41:51 +03:00
|
|
|
|
|
|
|
mLiveconnect = NULL;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CPluginManager::~CPluginManager(void)
|
|
|
|
{
|
1999-03-14 07:41:51 +03:00
|
|
|
NS_IF_RELEASE(mLiveconnect);
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// ReloadPlugins:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
CPluginManager::ReloadPlugins(PRBool reloadPages)
|
|
|
|
{
|
1998-10-01 06:59:16 +04:00
|
|
|
NPN_ReloadPlugins(reloadPages);
|
1998-08-01 00:19:50 +04:00
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
NS_METHOD
|
|
|
|
CPluginManager::GetURL(nsISupports* pluginInst,
|
|
|
|
const char* url,
|
|
|
|
const char* target,
|
|
|
|
nsIPluginStreamListener* streamListener,
|
|
|
|
const char* altHost,
|
|
|
|
const char* referrer,
|
|
|
|
PRBool forceJSEnabled)
|
|
|
|
{
|
|
|
|
if (altHost != NULL || referrer != NULL || forceJSEnabled != PR_FALSE) {
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPluginInstance* inst = NULL;
|
1999-03-03 22:48:57 +03:00
|
|
|
nsresult rslt = pluginInst->QueryInterface(nsIPluginInstance::GetIID(), (void**)&inst);
|
1998-10-01 06:59:16 +04:00
|
|
|
if (rslt != NS_OK) return rslt;
|
|
|
|
CPluginInstancePeer* instancePeer = NULL;
|
|
|
|
rslt = inst->GetPeer((nsIPluginInstancePeer**)&instancePeer);
|
|
|
|
if (rslt != NS_OK) {
|
|
|
|
inst->Release();
|
|
|
|
return rslt;
|
|
|
|
}
|
|
|
|
NPP npp = instancePeer->GetNPPInstance();
|
|
|
|
|
|
|
|
NPError err;
|
|
|
|
if (streamListener) {
|
1999-02-15 21:29:06 +03:00
|
|
|
CPluginInputStream* inStr = new CPluginInputStream(streamListener);
|
1998-10-01 06:59:16 +04:00
|
|
|
if (inStr == NULL) {
|
|
|
|
instancePeer->Release();
|
|
|
|
inst->Release();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
inStr->AddRef();
|
|
|
|
|
|
|
|
err = NPN_GetURLNotify(npp, url, target, inStr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
err = NPN_GetURL(npp, url, target);
|
|
|
|
}
|
|
|
|
instancePeer->Release();
|
|
|
|
inst->Release();
|
|
|
|
return fromNPError[err];
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManager::PostURL(nsISupports* pluginInst,
|
|
|
|
const char* url,
|
|
|
|
PRUint32 postDataLen,
|
|
|
|
const char* postData,
|
|
|
|
PRBool isFile,
|
|
|
|
const char* target,
|
|
|
|
nsIPluginStreamListener* streamListener,
|
|
|
|
const char* altHost,
|
|
|
|
const char* referrer,
|
|
|
|
PRBool forceJSEnabled,
|
|
|
|
PRUint32 postHeadersLength,
|
|
|
|
const char* postHeaders)
|
|
|
|
{
|
|
|
|
if (altHost != NULL || referrer != NULL || forceJSEnabled != PR_FALSE
|
|
|
|
|| postHeadersLength != 0 || postHeaders != NULL) {
|
|
|
|
return NPERR_INVALID_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPluginInstance* inst = NULL;
|
1999-03-03 22:48:57 +03:00
|
|
|
nsresult rslt = pluginInst->QueryInterface(nsIPluginInstance::GetIID(), (void**)&inst);
|
1998-10-01 06:59:16 +04:00
|
|
|
if (rslt != NS_OK) return rslt;
|
|
|
|
CPluginInstancePeer* instancePeer = NULL;
|
|
|
|
rslt = inst->GetPeer((nsIPluginInstancePeer**)&instancePeer);
|
|
|
|
if (rslt != NS_OK) {
|
|
|
|
inst->Release();
|
|
|
|
return rslt;
|
|
|
|
}
|
|
|
|
NPP npp = instancePeer->GetNPPInstance();
|
|
|
|
|
|
|
|
NPError err;
|
|
|
|
if (streamListener) {
|
1999-02-15 21:29:06 +03:00
|
|
|
CPluginInputStream* inStr = new CPluginInputStream(streamListener);
|
1998-10-01 06:59:16 +04:00
|
|
|
if (inStr == NULL) {
|
|
|
|
instancePeer->Release();
|
|
|
|
inst->Release();
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
inStr->AddRef();
|
|
|
|
|
|
|
|
err = NPN_PostURLNotify(npp, url, target, postDataLen, postData, isFile, inStr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
err = NPN_PostURL(npp, url, target, postDataLen, postData, isFile);
|
|
|
|
}
|
|
|
|
instancePeer->Release();
|
|
|
|
inst->Release();
|
|
|
|
return fromNPError[err];
|
|
|
|
}
|
|
|
|
|
1999-03-01 01:10:26 +03:00
|
|
|
NS_METHOD
|
|
|
|
CPluginManager::GetService(const nsCID& aClass, const nsIID& aIID,
|
|
|
|
nsISupports* *result,
|
|
|
|
nsIShutdownListener* shutdownListener)
|
|
|
|
{
|
|
|
|
// the only service we support currently is nsIAllocator.
|
1999-03-12 07:48:04 +03:00
|
|
|
if (aClass.Equals(kPluginManagerCID) || aClass.Equals(kAllocatorCID)) {
|
1999-03-01 01:10:26 +03:00
|
|
|
return QueryInterface(aIID, (void**) result);
|
|
|
|
}
|
1999-03-14 07:41:51 +03:00
|
|
|
if (aClass.Equals(nsILiveconnect::GetCID())) {
|
|
|
|
if (mLiveconnect == NULL) {
|
|
|
|
mLiveconnect = new nsLiveconnect;
|
|
|
|
NS_IF_ADDREF(mLiveconnect);
|
|
|
|
}
|
|
|
|
return mLiveconnect->QueryInterface(aIID, result);
|
|
|
|
}
|
1999-03-01 01:10:26 +03:00
|
|
|
return NS_ERROR_SERVICE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManager::ReleaseService(const nsCID& aClass, nsISupports* service,
|
|
|
|
nsIShutdownListener* shutdownListener)
|
|
|
|
{
|
|
|
|
NS_RELEASE(service);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD_(void*)
|
|
|
|
CPluginManager::Alloc(PRUint32 size)
|
|
|
|
{
|
|
|
|
return ::NPN_MemAlloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD_(void*)
|
|
|
|
CPluginManager::Realloc(void* ptr, PRUint32 size)
|
|
|
|
{
|
|
|
|
if (ptr != NULL) {
|
|
|
|
void* new_ptr = Alloc(size);
|
|
|
|
if (new_ptr != NULL) {
|
|
|
|
::memcpy(new_ptr, ptr, size);
|
|
|
|
Free(ptr);
|
|
|
|
}
|
|
|
|
ptr = new_ptr;
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManager::Free(void* ptr)
|
|
|
|
{
|
|
|
|
if (ptr != NULL) {
|
|
|
|
::NPN_MemFree(ptr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManager::HeapMinimize()
|
|
|
|
{
|
|
|
|
#ifdef XP_MAC
|
|
|
|
::NPN_MemFlush(1024);
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// UserAgent:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManager::UserAgent(const char* *result)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
1998-08-01 00:19:50 +04:00
|
|
|
*result = NPN_UserAgent(NULL);
|
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
int varMap[] = {
|
|
|
|
(int)NPNVxDisplay, // nsPluginManagerVariable_XDisplay = 1,
|
|
|
|
(int)NPNVxtAppContext, // nsPluginManagerVariable_XtAppContext,
|
|
|
|
(int)NPNVnetscapeWindow, // nsPluginManagerVariable_NetscapeWindow,
|
|
|
|
(int)NPPVpluginWindowBool, // nsPluginInstancePeerVariable_WindowBool,
|
|
|
|
(int)NPPVpluginTransparentBool, // nsPluginInstancePeerVariable_TransparentBool,
|
|
|
|
(int)NPPVjavaClass, // nsPluginInstancePeerVariable_JavaClass,
|
|
|
|
(int)NPPVpluginWindowSize, // nsPluginInstancePeerVariable_WindowSize,
|
|
|
|
(int)NPPVpluginTimerInterval, // nsPluginInstancePeerVariable_TimerInterval
|
|
|
|
};
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// GetValue:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
CPluginManager::GetValue(nsPluginManagerVariable variable, void *value)
|
|
|
|
{
|
|
|
|
#ifdef XP_UNIX
|
1998-08-01 00:19:50 +04:00
|
|
|
return fromNPError[NPN_GetValue(NULL, (NPNVariable)varMap[(int)variable], value)];
|
1998-07-11 05:39:51 +04:00
|
|
|
#else
|
1998-08-01 00:19:50 +04:00
|
|
|
return fromNPError[NPERR_GENERIC_ERROR];
|
1998-07-11 05:39:51 +04:00
|
|
|
#endif // XP_UNIX
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// SetValue:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
CPluginManager::SetValue(nsPluginManagerVariable variable, void *value)
|
|
|
|
{
|
1998-08-01 00:19:50 +04:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
return fromNPError[NPN_SetValue(NULL, (NPPVariable)varMap[(int)variable], value)];
|
|
|
|
#else
|
|
|
|
return fromNPError[NPERR_GENERIC_ERROR];
|
|
|
|
#endif // XP_UNIX
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// nsISupports functions
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NS_IMPL_ADDREF(CPluginManager);
|
|
|
|
NS_IMPL_RELEASE(CPluginManager);
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManager::QueryInterface(const nsIID& iid, void** ptr)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
1998-08-01 00:19:50 +04:00
|
|
|
if (NULL == ptr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1999-03-03 22:48:57 +03:00
|
|
|
if (iid.Equals(nsIServiceManager::GetIID())) {
|
1999-03-01 01:10:26 +03:00
|
|
|
*ptr = (void*) (nsIServiceManager*)this;
|
1998-08-01 00:19:50 +04:00
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
1999-03-01 01:10:26 +03:00
|
|
|
}
|
1999-03-03 22:48:57 +03:00
|
|
|
if (iid.Equals(nsIAllocator::GetIID())) {
|
1999-03-01 01:10:26 +03:00
|
|
|
*ptr = (void*) (nsIAllocator*)this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-03 22:48:57 +03:00
|
|
|
if (iid.Equals(nsIPluginManager::GetIID()) || iid.Equals(nsISupports::GetIID())) {
|
1998-08-01 00:19:50 +04:00
|
|
|
*ptr = (void*) ((nsIPluginManager*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CPluginInstancePeer
|
|
|
|
//
|
|
|
|
|
1998-08-09 07:17:39 +04:00
|
|
|
CPluginInstancePeer::CPluginInstancePeer(nsIPluginInstance* pluginInstance,
|
|
|
|
NPP npp,
|
1998-07-11 05:39:51 +04:00
|
|
|
nsMIMEType typeString,
|
1998-08-01 00:19:50 +04:00
|
|
|
nsPluginMode type,
|
1998-07-11 05:39:51 +04:00
|
|
|
PRUint16 attr_cnt,
|
1998-08-09 05:55:13 +04:00
|
|
|
const char** attr_list,
|
1998-07-11 05:39:51 +04:00
|
|
|
const char** val_list)
|
1998-08-09 07:17:39 +04:00
|
|
|
: mInstance(pluginInstance), mWindow(NULL),
|
|
|
|
npp(npp), typeString(typeString), type(type), attribute_cnt(attr_cnt),
|
|
|
|
attribute_list(NULL), values_list(NULL)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
|
|
|
// Set the reference count to 0.
|
|
|
|
NS_INIT_REFCNT();
|
1998-08-09 07:17:39 +04:00
|
|
|
|
1999-03-02 07:46:05 +03:00
|
|
|
NS_IF_ADDREF(mInstance);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
attribute_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*));
|
|
|
|
values_list = (char**) NPN_MemAlloc(attr_cnt * sizeof(const char*));
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
if (attribute_list != NULL && values_list != NULL) {
|
|
|
|
for (int i = 0; i < attribute_cnt; i++) {
|
|
|
|
attribute_list[i] = (char*) NPN_MemAlloc(strlen(attr_list[i]) + 1);
|
|
|
|
if (attribute_list[i] != NULL)
|
|
|
|
strcpy(attribute_list[i], attr_list[i]);
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
values_list[i] = (char*) NPN_MemAlloc(strlen(val_list[i]) + 1);
|
|
|
|
if (values_list[i] != NULL)
|
|
|
|
strcpy(values_list[i], val_list[i]);
|
|
|
|
}
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CPluginInstancePeer::~CPluginInstancePeer(void)
|
|
|
|
{
|
1998-10-01 06:59:16 +04:00
|
|
|
if (attribute_list != NULL && values_list != NULL) {
|
|
|
|
for (int i = 0; i < attribute_cnt; i++) {
|
|
|
|
NPN_MemFree(attribute_list[i]);
|
|
|
|
NPN_MemFree(values_list[i]);
|
|
|
|
}
|
1998-08-09 05:55:13 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
NPN_MemFree(attribute_list);
|
|
|
|
NPN_MemFree(values_list);
|
|
|
|
}
|
1999-03-02 07:46:05 +03:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mInstance);
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// GetValue:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginInstancePeer::GetValue(nsPluginInstancePeerVariable variable, void *value)
|
|
|
|
{
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
return fromNPError[NPN_GetValue(NULL, (NPNVariable)varMap[(int)variable], value)];
|
|
|
|
#else
|
|
|
|
return fromNPError[NPERR_GENERIC_ERROR];
|
|
|
|
#endif // XP_UNIX
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// SetValue:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginInstancePeer::SetValue(nsPluginInstancePeerVariable variable, void *value)
|
|
|
|
{
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
return fromNPError[NPN_SetValue(NULL, (NPPVariable)varMap[(int)variable], value)];
|
|
|
|
#else
|
|
|
|
return fromNPError[NPERR_GENERIC_ERROR];
|
|
|
|
#endif // XP_UNIX
|
|
|
|
}
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// GetMIMEType:
|
|
|
|
// Corresponds to NPP_New's MIMEType argument.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginInstancePeer::GetMIMEType(nsMIMEType *result)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
1998-08-01 00:19:50 +04:00
|
|
|
*result = typeString;
|
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// GetMode:
|
|
|
|
// Corresponds to NPP_New's mode argument.
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginInstancePeer::GetMode(nsPluginMode *result)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
1998-08-01 00:19:50 +04:00
|
|
|
*result = type;
|
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get a ptr to the paired list of attribute names and values,
|
|
|
|
// returns the length of the array.
|
|
|
|
//
|
|
|
|
// Each name or value is a null-terminated string.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_METHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
CPluginInstancePeer::GetAttributes(PRUint16& n, const char* const*& names, const char* const*& values)
|
|
|
|
{
|
1998-10-01 06:59:16 +04:00
|
|
|
n = attribute_cnt;
|
|
|
|
names = attribute_list;
|
|
|
|
values = values_list;
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
1998-08-09 05:55:13 +04:00
|
|
|
#if defined(XP_MAC)
|
|
|
|
|
|
|
|
inline unsigned char toupper(unsigned char c)
|
|
|
|
{
|
1998-10-01 06:59:16 +04:00
|
|
|
return (c >= 'a' && c <= 'z') ? (c - ('a' - 'A')) : c;
|
1998-08-09 05:55:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int strcasecmp(const char * str1, const char * str2)
|
|
|
|
{
|
|
|
|
#if __POWERPC__
|
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
const unsigned char * p1 = (unsigned char *) str1 - 1;
|
|
|
|
const unsigned char * p2 = (unsigned char *) str2 - 1;
|
|
|
|
unsigned long c1, c2;
|
1998-08-09 05:55:13 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
while (toupper(c1 = *++p1) == toupper(c2 = *++p2))
|
|
|
|
if (!c1)
|
|
|
|
return(0);
|
1998-08-09 05:55:13 +04:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
const unsigned char * p1 = (unsigned char *) str1;
|
|
|
|
const unsigned char * p2 = (unsigned char *) str2;
|
|
|
|
unsigned char c1, c2;
|
1998-08-09 05:55:13 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
while (toupper(c1 = *p1++) == toupper(c2 = *p2++))
|
|
|
|
if (!c1)
|
|
|
|
return(0);
|
1998-08-09 05:55:13 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
return(toupper(c1) - toupper(c2));
|
1998-08-09 05:55:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* XP_MAC */
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Get the value for the named attribute. Returns null
|
|
|
|
// if the attribute was not set.
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_METHOD
|
|
|
|
CPluginInstancePeer::GetAttribute(const char* name, const char* *result)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
1998-10-01 06:59:16 +04:00
|
|
|
for (int i=0; i < attribute_cnt; i++) {
|
1998-08-09 05:55:13 +04:00
|
|
|
#if defined(XP_UNIX) || defined(XP_MAC)
|
1998-10-01 06:59:16 +04:00
|
|
|
if (strcasecmp(name, attribute_list[i]) == 0)
|
1998-07-11 05:39:51 +04:00
|
|
|
#else
|
1998-10-01 06:59:16 +04:00
|
|
|
if (stricmp(name, attribute_list[i]) == 0)
|
1998-07-11 05:39:51 +04:00
|
|
|
#endif
|
1998-10-01 06:59:16 +04:00
|
|
|
{
|
|
|
|
*result = values_list[i];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1998-10-01 06:59:16 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// NewStream:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_METHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
CPluginInstancePeer::NewStream(nsMIMEType type, const char* target,
|
1998-10-01 06:59:16 +04:00
|
|
|
nsIOutputStream* *result)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
|
|
|
assert( npp != NULL );
|
|
|
|
|
|
|
|
// Create a new NPStream.
|
1999-03-21 02:12:43 +03:00
|
|
|
NPStream* stream = NULL;
|
|
|
|
NPError error = NPN_NewStream(npp, (NPMIMEType)type, target, &stream);
|
|
|
|
if (error != NPERR_NO_ERROR)
|
1998-08-01 00:19:50 +04:00
|
|
|
return fromNPError[error];
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
// Create a new Plugin Manager Stream.
|
|
|
|
// XXX - Do we have to Release() the manager stream before doing this?
|
|
|
|
// XXX - See the BAM doc for more info.
|
1999-03-21 02:12:43 +03:00
|
|
|
CPluginManagerStream* mstream = new CPluginManagerStream(npp, stream);
|
|
|
|
if (mstream == NULL)
|
1998-08-01 00:19:50 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-07-11 05:39:51 +04:00
|
|
|
mstream->AddRef();
|
|
|
|
*result = (nsIOutputStream* )mstream;
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// ShowStatus:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
CPluginInstancePeer::ShowStatus(const char* message)
|
|
|
|
{
|
|
|
|
assert( message != NULL );
|
|
|
|
|
|
|
|
NPN_Status(npp, message);
|
1998-08-01 00:19:50 +04:00
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
1998-09-15 07:45:38 +04:00
|
|
|
NS_METHOD
|
|
|
|
CPluginInstancePeer::SetWindowSize(PRUint32 width, PRUint32 height)
|
|
|
|
{
|
|
|
|
NPError err;
|
|
|
|
NPSize size;
|
|
|
|
size.width = width;
|
|
|
|
size.height = height;
|
|
|
|
err = NPN_SetValue(npp, NPPVpluginWindowSize, &size);
|
|
|
|
return fromNPError[err];
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// nsISupports functions
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NS_IMPL_ADDREF(CPluginInstancePeer);
|
|
|
|
NS_IMPL_RELEASE(CPluginInstancePeer);
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_METHOD
|
|
|
|
CPluginInstancePeer::QueryInterface(const nsIID& iid, void** ptr)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
1998-08-01 00:19:50 +04:00
|
|
|
if (NULL == ptr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-07-11 05:39:51 +04:00
|
|
|
|
1999-03-03 22:48:57 +03:00
|
|
|
if (iid.Equals(nsIPluginInstancePeer::GetIID())) {
|
1998-08-01 00:19:50 +04:00
|
|
|
*ptr = (void*) this;
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-03-03 22:48:57 +03:00
|
|
|
if (iid.Equals(nsIPluginTagInfo::GetIID()) || iid.Equals(nsISupports::GetIID())) {
|
1998-08-01 00:19:50 +04:00
|
|
|
*ptr = (void*) ((nsIPluginTagInfo*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CPluginManagerStream
|
|
|
|
//
|
|
|
|
|
|
|
|
CPluginManagerStream::CPluginManagerStream(NPP npp, NPStream* pstr)
|
|
|
|
: npp(npp), pstream(pstr)
|
|
|
|
{
|
|
|
|
// Set the reference count to 0.
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
CPluginManagerStream::~CPluginManagerStream(void)
|
|
|
|
{
|
|
|
|
//pstream = NULL;
|
|
|
|
NPN_DestroyStream(npp, pstream, NPRES_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// Write:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
1999-03-08 03:07:24 +03:00
|
|
|
CPluginManagerStream::Write(const char* buffer, PRUint32 len, PRUint32 *aWriteCount)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
|
|
|
assert( npp != NULL );
|
|
|
|
assert( pstream != NULL );
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
*aWriteCount = NPN_Write(npp, pstream, len, (void* )buffer);
|
|
|
|
return *aWriteCount >= 0 ? NS_OK : NS_ERROR_FAILURE;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// GetURL:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManagerStream::GetURL(const char* *result)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
|
|
|
assert( pstream != NULL );
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
*result = pstream->url;
|
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// GetEnd:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManagerStream::GetEnd(PRUint32 *result)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
|
|
|
assert( pstream != NULL );
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
*result = pstream->end;
|
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// GetLastModified:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManagerStream::GetLastModified(PRUint32 *result)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
|
|
|
assert( pstream != NULL );
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
*result = pstream->lastmodified;
|
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// GetNotifyData:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginManagerStream::GetNotifyData(void* *result)
|
1998-07-11 05:39:51 +04:00
|
|
|
{
|
|
|
|
assert( pstream != NULL );
|
|
|
|
|
1998-08-01 00:19:50 +04:00
|
|
|
*result = pstream->notifyData;
|
|
|
|
return NS_OK;
|
1998-07-11 05:39:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// GetNotifyData:
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
|
|
|
NS_METHOD
|
1998-07-11 05:39:51 +04:00
|
|
|
CPluginManagerStream::Close(void)
|
|
|
|
{
|
|
|
|
assert( pstream != NULL );
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// nsISupports functions
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++
|
1998-08-01 00:19:50 +04:00
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
NS_IMPL_ADDREF(CPluginManagerStream);
|
1998-08-01 00:19:50 +04:00
|
|
|
NS_IMPL_RELEASE(CPluginManagerStream);
|
|
|
|
|
1999-03-03 22:48:57 +03:00
|
|
|
NS_IMPL_QUERY_INTERFACE(CPluginManagerStream, nsIOutputStream::GetIID());
|
1998-07-11 05:39:51 +04:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-02-15 21:29:06 +03:00
|
|
|
NS_IMPL_ISUPPORTS(CPluginStreamInfo, kIPluginStreamInfoIID);
|
|
|
|
|
|
|
|
CPluginInputStream::CPluginInputStream(nsIPluginStreamListener* listener)
|
|
|
|
: mListener(listener), mStreamType(nsPluginStreamType_Normal),
|
1998-10-01 06:59:16 +04:00
|
|
|
mNPP(NULL), mStream(NULL),
|
1999-02-15 21:29:06 +03:00
|
|
|
mBuffer(NULL), mBufferLength(0), mAmountRead(0),
|
|
|
|
mStreamInfo(NULL)
|
1998-10-01 06:59:16 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
1999-02-15 21:29:06 +03:00
|
|
|
|
|
|
|
if (mListener != NULL) {
|
|
|
|
mListener->AddRef();
|
|
|
|
mListener->GetStreamType(&mStreamType);
|
|
|
|
}
|
1998-10-01 06:59:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CPluginInputStream::~CPluginInputStream(void)
|
|
|
|
{
|
1999-02-15 21:29:06 +03:00
|
|
|
NS_IF_RELEASE(mListener);
|
|
|
|
|
|
|
|
delete mBuffer;
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mStreamInfo);
|
1998-10-01 06:59:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(CPluginInputStream, kIPluginInputStreamIID);
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginInputStream::Close(void)
|
|
|
|
{
|
|
|
|
if (mNPP == NULL || mStream == NULL)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
NPError err = NPN_DestroyStream(mNPP, mStream, NPRES_USER_BREAK);
|
|
|
|
return fromNPError[err];
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
1999-02-15 21:29:06 +03:00
|
|
|
CPluginInputStream::GetLength(PRUint32 *aLength)
|
1998-10-01 06:59:16 +04:00
|
|
|
{
|
|
|
|
*aLength = mStream->end;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
1999-03-08 03:07:24 +03:00
|
|
|
CPluginInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount)
|
1998-10-01 06:59:16 +04:00
|
|
|
{
|
1999-03-08 03:07:24 +03:00
|
|
|
PRUint32 cnt = PR_MIN(aCount, mBufferLength);
|
|
|
|
memcpy(aBuf, mBuffer + mAmountRead, cnt);
|
1998-10-01 06:59:16 +04:00
|
|
|
*aReadCount = cnt;
|
1999-03-08 03:07:24 +03:00
|
|
|
mAmountRead += cnt;
|
|
|
|
mBufferLength -= cnt;
|
1998-10-01 06:59:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginInputStream::GetLastModified(PRUint32 *result)
|
|
|
|
{
|
|
|
|
*result = mStream->lastmodified;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
CPluginInputStream::RequestRead(nsByteRange* rangeList)
|
|
|
|
{
|
|
|
|
NPError err = NPN_RequestRead(mStream, (NPByteRange*)rangeList);
|
|
|
|
return fromNPError[err];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-11 05:39:51 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|