зеркало из https://github.com/mozilla/pjs.git
Added NPN_NewStream() functionality. Currently uses a temp file between the plugin stream and the target.
I will remove this file in-between as soon as I get a little more stream help from netlib.
This commit is contained in:
Родитель
115471fe2a
Коммит
47e105d8fd
|
@ -406,7 +406,9 @@ ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
|
|||
{
|
||||
NS_ASSERTION(stream != NULL, "bad stream");
|
||||
|
||||
NS_ADDREF(fStream);
|
||||
fStream = stream;
|
||||
|
||||
NS_ADDREF(fStream);
|
||||
|
||||
memset(&fNPStream, 0, sizeof(fNPStream));
|
||||
fNPStream.ndata = (void*) this;
|
||||
|
@ -414,6 +416,8 @@ ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
|
|||
|
||||
ns4xStreamWrapper::~ns4xStreamWrapper(void)
|
||||
{
|
||||
fStream->Close();
|
||||
|
||||
NS_IF_RELEASE(fStream);
|
||||
}
|
||||
|
||||
|
@ -472,7 +476,7 @@ ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *
|
|||
int32 NP_EXPORT
|
||||
ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
|
||||
{
|
||||
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
|
||||
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
|
||||
|
||||
NS_ASSERTION(wrapper != NULL, "null wrapper");
|
||||
|
||||
|
@ -492,7 +496,7 @@ ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
|
|||
nsresult NP_EXPORT
|
||||
ns4xPlugin::_destroystream(NPP npp, NPStream *pstream, NPError reason)
|
||||
{
|
||||
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
|
||||
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
|
||||
|
||||
NS_ASSERTION(wrapper != NULL, "null wrapper");
|
||||
|
||||
|
|
|
@ -33,20 +33,14 @@
|
|||
* right calling conventions on Win16.
|
||||
*/
|
||||
|
||||
#ifdef XP_WIN16
|
||||
#define NP_EXPORT __export
|
||||
#elif defined(XP_OS2)
|
||||
#define NP_EXPORT _System
|
||||
#else
|
||||
#define NP_EXPORT
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// XXX These are defined in platform specific FE directories right now :-/
|
||||
|
||||
//BTW: this sucks rocks.
|
||||
#ifdef XP_WIN
|
||||
#ifdef XP_PC
|
||||
#define PLUGIN_ENTRYPOINT_CALL_TYPE __stdcall
|
||||
#else
|
||||
#define PLUGIN_ENTRYPOINT_CALL_TYPE
|
||||
|
|
|
@ -227,9 +227,12 @@ nsPluginStreamListener :: nsPluginStreamListener()
|
|||
nsPluginStreamListener :: ~nsPluginStreamListener()
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
const char* spec;
|
||||
(void)mURL->GetSpec(&spec);
|
||||
printf("killing stream for %s\n", mURL ? spec : "(unknown URL)");
|
||||
if(mURL != nsnull)
|
||||
{
|
||||
const char* spec;
|
||||
(void)mURL->GetSpec(&spec);
|
||||
printf("killing stream for %s\n", mURL ? spec : "(unknown URL)");
|
||||
}
|
||||
#endif
|
||||
NS_IF_RELEASE(mURL);
|
||||
NS_IF_RELEASE(mOwner);
|
||||
|
@ -499,7 +502,7 @@ NS_IMETHODIMP nsPluginStreamListener :: OnStopBinding(nsIURL* aURL, nsresult aSt
|
|||
mStreamFile = nsnull;
|
||||
|
||||
char buf[400], tpath[300];
|
||||
#ifdef XP_WIN
|
||||
#ifdef XP_PC
|
||||
::GetTempPath(sizeof(tpath), tpath);
|
||||
PRInt32 len = PL_strlen(tpath);
|
||||
|
||||
|
@ -512,7 +515,7 @@ NS_IMETHODIMP nsPluginStreamListener :: OnStopBinding(nsIURL* aURL, nsresult aSt
|
|||
PL_strcpy(tpath, "/tmp/");
|
||||
#else
|
||||
tpath[0] = 0;
|
||||
#endif // XP_WIN
|
||||
#endif // XP_PC
|
||||
PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, mStream);
|
||||
mStream->AsFile(buf);
|
||||
}
|
||||
|
@ -634,7 +637,7 @@ nsresult nsPluginStreamListener::SetUpStreamPeer(nsIURL* aURL, nsIPluginInstance
|
|||
diskCache->AddObject(mCachedFile);
|
||||
#else // USE_CACHE
|
||||
char buf[400], tpath[300];
|
||||
#ifdef XP_WIN
|
||||
#ifdef XP_PC
|
||||
::GetTempPath(sizeof(tpath), tpath);
|
||||
PRInt32 len = PL_strlen(tpath);
|
||||
|
||||
|
@ -647,7 +650,7 @@ nsresult nsPluginStreamListener::SetUpStreamPeer(nsIURL* aURL, nsIPluginInstance
|
|||
PL_strcpy(tpath, "/tmp/");
|
||||
#else
|
||||
tpath[0] = 0;
|
||||
#endif // XP_WIN
|
||||
#endif // XP_PC
|
||||
PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, mStream);
|
||||
mStreamFile = fopen(buf, "wb");
|
||||
#endif // USE_CACHE
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <stdio.h>
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
#include "prprf.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
nsPluginInstancePeerImpl :: nsPluginInstancePeerImpl()
|
||||
{
|
||||
|
@ -44,15 +46,15 @@ nsPluginInstancePeerImpl :: ~nsPluginInstancePeerImpl()
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsPluginInstancePeerImpl);
|
||||
NS_IMPL_RELEASE(nsPluginInstancePeerImpl);
|
||||
|
||||
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
|
||||
static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
|
||||
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
|
||||
static NS_DEFINE_IID(kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
NS_IMPL_ADDREF(nsPluginInstancePeerImpl);
|
||||
NS_IMPL_RELEASE(nsPluginInstancePeerImpl);
|
||||
|
||||
nsresult nsPluginInstancePeerImpl :: QueryInterface(const nsIID& iid, void** instance)
|
||||
{
|
||||
if (instance == NULL)
|
||||
|
@ -120,10 +122,158 @@ NS_IMETHODIMP nsPluginInstancePeerImpl :: GetMode(nsPluginMode *result)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// nsPluginStreamToFile
|
||||
// --------------------
|
||||
// Used to handle NPN_NewStream() - writes the stream as received by the plugin
|
||||
// to a file and at completion (NPN_DestroyStream), tells the browser to load it into
|
||||
// a plugin-specified target
|
||||
|
||||
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
|
||||
|
||||
class nsPluginStreamToFile : public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
|
||||
nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner);
|
||||
~nsPluginStreamToFile();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIOutputStream interface
|
||||
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
// nsIBaseStream interface
|
||||
|
||||
NS_IMETHOD
|
||||
Close(void);
|
||||
|
||||
protected:
|
||||
|
||||
char* mTarget;
|
||||
char* mFileURL;
|
||||
char* mFilename;
|
||||
FILE* mStreamFile;
|
||||
nsIPluginInstanceOwner* mOwner;
|
||||
};
|
||||
|
||||
nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner)
|
||||
{
|
||||
mTarget = PL_strdup(target);
|
||||
mOwner = owner;
|
||||
|
||||
// open the file and prepare it for writing
|
||||
char buf[400], tpath[300];
|
||||
#ifdef XP_PC
|
||||
::GetTempPath(sizeof(tpath), tpath);
|
||||
PRInt32 len = PL_strlen(tpath);
|
||||
|
||||
if((len > 0) && (tpath[len-1] != '\\'))
|
||||
{
|
||||
tpath[len] = '\\';
|
||||
tpath[len+1] = 0;
|
||||
}
|
||||
#elif defined (XP_UNIX)
|
||||
PL_strcpy(tpath, "/tmp/");
|
||||
#else
|
||||
tpath[0] = 0;
|
||||
#endif // XP_PC
|
||||
|
||||
// create the file
|
||||
PR_snprintf(buf, sizeof(buf), "%s%08X.html", tpath, this);
|
||||
mStreamFile = fopen(buf, "w");
|
||||
fclose(mStreamFile);
|
||||
|
||||
mFilename = PL_strdup(buf);
|
||||
|
||||
// construct the URL we'll use later in calls to GetURL()
|
||||
mFileURL = (char*)PR_Malloc((PL_strlen(buf)+PL_strlen("file://")+1) * sizeof(char));
|
||||
if(mFileURL == nsnull)
|
||||
return;
|
||||
|
||||
PL_strcpy(mFileURL, "file://");
|
||||
PL_strcat(mFileURL, buf);
|
||||
|
||||
// swap \ with / for the file URL
|
||||
PRInt32 i = 0;
|
||||
while(mFileURL[i] != 0)
|
||||
{
|
||||
if(mFileURL[i] == '\\')
|
||||
mFileURL[i] = '/';
|
||||
++i;
|
||||
}
|
||||
|
||||
printf("File URL = %s\n", mFileURL);
|
||||
}
|
||||
|
||||
nsPluginStreamToFile::~nsPluginStreamToFile()
|
||||
{
|
||||
if(nsnull != mTarget)
|
||||
PL_strfree(mTarget);
|
||||
|
||||
if(nsnull != mFileURL)
|
||||
PL_strfree(mFileURL);
|
||||
|
||||
if(nsnull != mFilename)
|
||||
PL_strfree(mFilename);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsPluginStreamToFile)
|
||||
NS_IMPL_RELEASE(nsPluginStreamToFile)
|
||||
|
||||
nsresult nsPluginStreamToFile::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
|
||||
if (nsnull == aInstancePtrResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(kIOutputStreamIID))
|
||||
{
|
||||
*aInstancePtrResult = (void *)((nsIOutputStream *)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
{
|
||||
// write the data to the file and update the target
|
||||
if(nsnull != mFilename)
|
||||
{
|
||||
mStreamFile = fopen(mFilename, "a");
|
||||
fwrite(aBuf, 1, aCount, mStreamFile);
|
||||
fclose(mStreamFile);
|
||||
mOwner->GetURL(mFileURL, mTarget, nsnull);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPluginStreamToFile::Close(void)
|
||||
{
|
||||
mOwner->GetURL(mFileURL, mTarget, nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// end of nsPluginStreamToFile
|
||||
|
||||
NS_IMETHODIMP nsPluginInstancePeerImpl :: NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result)
|
||||
{
|
||||
printf("instance peer newstream called\n");
|
||||
return NS_OK;
|
||||
nsresult rv;
|
||||
nsPluginStreamToFile* stream = new nsPluginStreamToFile(target, mOwner);
|
||||
|
||||
rv = stream->QueryInterface(kIOutputStreamIID, (void **)result);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPluginInstancePeerImpl :: ShowStatus(const char* message)
|
||||
|
@ -633,3 +783,4 @@ nsresult nsPluginInstancePeerImpl :: GetOwner(nsIPluginInstanceOwner *&aOwner)
|
|||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "nsIPluginInstanceOwner.h"
|
||||
#include "nsIJVMPluginTagInfo.h"
|
||||
|
||||
|
||||
class nsPluginInstancePeerImpl : public nsIPluginInstancePeer,
|
||||
public nsIPluginTagInfo2,
|
||||
public nsIJVMPluginTagInfo
|
||||
|
|
|
@ -406,7 +406,9 @@ ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
|
|||
{
|
||||
NS_ASSERTION(stream != NULL, "bad stream");
|
||||
|
||||
NS_ADDREF(fStream);
|
||||
fStream = stream;
|
||||
|
||||
NS_ADDREF(fStream);
|
||||
|
||||
memset(&fNPStream, 0, sizeof(fNPStream));
|
||||
fNPStream.ndata = (void*) this;
|
||||
|
@ -414,6 +416,8 @@ ns4xStreamWrapper::ns4xStreamWrapper(nsIOutputStream* stream)
|
|||
|
||||
ns4xStreamWrapper::~ns4xStreamWrapper(void)
|
||||
{
|
||||
fStream->Close();
|
||||
|
||||
NS_IF_RELEASE(fStream);
|
||||
}
|
||||
|
||||
|
@ -472,7 +476,7 @@ ns4xPlugin::_newstream(NPP npp, NPMIMEType type, const char* window, NPStream* *
|
|||
int32 NP_EXPORT
|
||||
ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
|
||||
{
|
||||
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
|
||||
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
|
||||
|
||||
NS_ASSERTION(wrapper != NULL, "null wrapper");
|
||||
|
||||
|
@ -492,7 +496,7 @@ ns4xPlugin::_write(NPP npp, NPStream *pstream, int32 len, void *buffer)
|
|||
nsresult NP_EXPORT
|
||||
ns4xPlugin::_destroystream(NPP npp, NPStream *pstream, NPError reason)
|
||||
{
|
||||
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) npp->ndata;
|
||||
ns4xStreamWrapper* wrapper = (ns4xStreamWrapper*) pstream->ndata;
|
||||
|
||||
NS_ASSERTION(wrapper != NULL, "null wrapper");
|
||||
|
||||
|
|
|
@ -33,20 +33,14 @@
|
|||
* right calling conventions on Win16.
|
||||
*/
|
||||
|
||||
#ifdef XP_WIN16
|
||||
#define NP_EXPORT __export
|
||||
#elif defined(XP_OS2)
|
||||
#define NP_EXPORT _System
|
||||
#else
|
||||
#define NP_EXPORT
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// XXX These are defined in platform specific FE directories right now :-/
|
||||
|
||||
//BTW: this sucks rocks.
|
||||
#ifdef XP_WIN
|
||||
#ifdef XP_PC
|
||||
#define PLUGIN_ENTRYPOINT_CALL_TYPE __stdcall
|
||||
#else
|
||||
#define PLUGIN_ENTRYPOINT_CALL_TYPE
|
||||
|
|
|
@ -227,9 +227,12 @@ nsPluginStreamListener :: nsPluginStreamListener()
|
|||
nsPluginStreamListener :: ~nsPluginStreamListener()
|
||||
{
|
||||
#ifdef NS_DEBUG
|
||||
const char* spec;
|
||||
(void)mURL->GetSpec(&spec);
|
||||
printf("killing stream for %s\n", mURL ? spec : "(unknown URL)");
|
||||
if(mURL != nsnull)
|
||||
{
|
||||
const char* spec;
|
||||
(void)mURL->GetSpec(&spec);
|
||||
printf("killing stream for %s\n", mURL ? spec : "(unknown URL)");
|
||||
}
|
||||
#endif
|
||||
NS_IF_RELEASE(mURL);
|
||||
NS_IF_RELEASE(mOwner);
|
||||
|
@ -499,7 +502,7 @@ NS_IMETHODIMP nsPluginStreamListener :: OnStopBinding(nsIURL* aURL, nsresult aSt
|
|||
mStreamFile = nsnull;
|
||||
|
||||
char buf[400], tpath[300];
|
||||
#ifdef XP_WIN
|
||||
#ifdef XP_PC
|
||||
::GetTempPath(sizeof(tpath), tpath);
|
||||
PRInt32 len = PL_strlen(tpath);
|
||||
|
||||
|
@ -512,7 +515,7 @@ NS_IMETHODIMP nsPluginStreamListener :: OnStopBinding(nsIURL* aURL, nsresult aSt
|
|||
PL_strcpy(tpath, "/tmp/");
|
||||
#else
|
||||
tpath[0] = 0;
|
||||
#endif // XP_WIN
|
||||
#endif // XP_PC
|
||||
PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, mStream);
|
||||
mStream->AsFile(buf);
|
||||
}
|
||||
|
@ -634,7 +637,7 @@ nsresult nsPluginStreamListener::SetUpStreamPeer(nsIURL* aURL, nsIPluginInstance
|
|||
diskCache->AddObject(mCachedFile);
|
||||
#else // USE_CACHE
|
||||
char buf[400], tpath[300];
|
||||
#ifdef XP_WIN
|
||||
#ifdef XP_PC
|
||||
::GetTempPath(sizeof(tpath), tpath);
|
||||
PRInt32 len = PL_strlen(tpath);
|
||||
|
||||
|
@ -647,7 +650,7 @@ nsresult nsPluginStreamListener::SetUpStreamPeer(nsIURL* aURL, nsIPluginInstance
|
|||
PL_strcpy(tpath, "/tmp/");
|
||||
#else
|
||||
tpath[0] = 0;
|
||||
#endif // XP_WIN
|
||||
#endif // XP_PC
|
||||
PR_snprintf(buf, sizeof(buf), "%s%08X.ngl", tpath, mStream);
|
||||
mStreamFile = fopen(buf, "wb");
|
||||
#endif // USE_CACHE
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <stdio.h>
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
#include "prprf.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
nsPluginInstancePeerImpl :: nsPluginInstancePeerImpl()
|
||||
{
|
||||
|
@ -44,15 +46,15 @@ nsPluginInstancePeerImpl :: ~nsPluginInstancePeerImpl()
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsPluginInstancePeerImpl);
|
||||
NS_IMPL_RELEASE(nsPluginInstancePeerImpl);
|
||||
|
||||
static NS_DEFINE_IID(kIPluginTagInfoIID, NS_IPLUGINTAGINFO_IID);
|
||||
static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID);
|
||||
static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID);
|
||||
static NS_DEFINE_IID(kIJVMPluginTagInfoIID, NS_IJVMPLUGINTAGINFO_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
NS_IMPL_ADDREF(nsPluginInstancePeerImpl);
|
||||
NS_IMPL_RELEASE(nsPluginInstancePeerImpl);
|
||||
|
||||
nsresult nsPluginInstancePeerImpl :: QueryInterface(const nsIID& iid, void** instance)
|
||||
{
|
||||
if (instance == NULL)
|
||||
|
@ -120,10 +122,158 @@ NS_IMETHODIMP nsPluginInstancePeerImpl :: GetMode(nsPluginMode *result)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// nsPluginStreamToFile
|
||||
// --------------------
|
||||
// Used to handle NPN_NewStream() - writes the stream as received by the plugin
|
||||
// to a file and at completion (NPN_DestroyStream), tells the browser to load it into
|
||||
// a plugin-specified target
|
||||
|
||||
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
|
||||
|
||||
class nsPluginStreamToFile : public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
|
||||
nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner);
|
||||
~nsPluginStreamToFile();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIOutputStream interface
|
||||
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
// nsIBaseStream interface
|
||||
|
||||
NS_IMETHOD
|
||||
Close(void);
|
||||
|
||||
protected:
|
||||
|
||||
char* mTarget;
|
||||
char* mFileURL;
|
||||
char* mFilename;
|
||||
FILE* mStreamFile;
|
||||
nsIPluginInstanceOwner* mOwner;
|
||||
};
|
||||
|
||||
nsPluginStreamToFile::nsPluginStreamToFile(const char* target, nsIPluginInstanceOwner* owner)
|
||||
{
|
||||
mTarget = PL_strdup(target);
|
||||
mOwner = owner;
|
||||
|
||||
// open the file and prepare it for writing
|
||||
char buf[400], tpath[300];
|
||||
#ifdef XP_PC
|
||||
::GetTempPath(sizeof(tpath), tpath);
|
||||
PRInt32 len = PL_strlen(tpath);
|
||||
|
||||
if((len > 0) && (tpath[len-1] != '\\'))
|
||||
{
|
||||
tpath[len] = '\\';
|
||||
tpath[len+1] = 0;
|
||||
}
|
||||
#elif defined (XP_UNIX)
|
||||
PL_strcpy(tpath, "/tmp/");
|
||||
#else
|
||||
tpath[0] = 0;
|
||||
#endif // XP_PC
|
||||
|
||||
// create the file
|
||||
PR_snprintf(buf, sizeof(buf), "%s%08X.html", tpath, this);
|
||||
mStreamFile = fopen(buf, "w");
|
||||
fclose(mStreamFile);
|
||||
|
||||
mFilename = PL_strdup(buf);
|
||||
|
||||
// construct the URL we'll use later in calls to GetURL()
|
||||
mFileURL = (char*)PR_Malloc((PL_strlen(buf)+PL_strlen("file://")+1) * sizeof(char));
|
||||
if(mFileURL == nsnull)
|
||||
return;
|
||||
|
||||
PL_strcpy(mFileURL, "file://");
|
||||
PL_strcat(mFileURL, buf);
|
||||
|
||||
// swap \ with / for the file URL
|
||||
PRInt32 i = 0;
|
||||
while(mFileURL[i] != 0)
|
||||
{
|
||||
if(mFileURL[i] == '\\')
|
||||
mFileURL[i] = '/';
|
||||
++i;
|
||||
}
|
||||
|
||||
printf("File URL = %s\n", mFileURL);
|
||||
}
|
||||
|
||||
nsPluginStreamToFile::~nsPluginStreamToFile()
|
||||
{
|
||||
if(nsnull != mTarget)
|
||||
PL_strfree(mTarget);
|
||||
|
||||
if(nsnull != mFileURL)
|
||||
PL_strfree(mFileURL);
|
||||
|
||||
if(nsnull != mFilename)
|
||||
PL_strfree(mFilename);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsPluginStreamToFile)
|
||||
NS_IMPL_RELEASE(nsPluginStreamToFile)
|
||||
|
||||
nsresult nsPluginStreamToFile::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
|
||||
if (nsnull == aInstancePtrResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(kIOutputStreamIID))
|
||||
{
|
||||
*aInstancePtrResult = (void *)((nsIOutputStream *)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aOffset, PRUint32 aCount, PRUint32 *aWriteCount)
|
||||
{
|
||||
// write the data to the file and update the target
|
||||
if(nsnull != mFilename)
|
||||
{
|
||||
mStreamFile = fopen(mFilename, "a");
|
||||
fwrite(aBuf, 1, aCount, mStreamFile);
|
||||
fclose(mStreamFile);
|
||||
mOwner->GetURL(mFileURL, mTarget, nsnull);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPluginStreamToFile::Close(void)
|
||||
{
|
||||
mOwner->GetURL(mFileURL, mTarget, nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// end of nsPluginStreamToFile
|
||||
|
||||
NS_IMETHODIMP nsPluginInstancePeerImpl :: NewStream(nsMIMEType type, const char* target, nsIOutputStream* *result)
|
||||
{
|
||||
printf("instance peer newstream called\n");
|
||||
return NS_OK;
|
||||
nsresult rv;
|
||||
nsPluginStreamToFile* stream = new nsPluginStreamToFile(target, mOwner);
|
||||
|
||||
rv = stream->QueryInterface(kIOutputStreamIID, (void **)result);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsPluginInstancePeerImpl :: ShowStatus(const char* message)
|
||||
|
@ -633,3 +783,4 @@ nsresult nsPluginInstancePeerImpl :: GetOwner(nsIPluginInstanceOwner *&aOwner)
|
|||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "nsIPluginInstanceOwner.h"
|
||||
#include "nsIJVMPluginTagInfo.h"
|
||||
|
||||
|
||||
class nsPluginInstancePeerImpl : public nsIPluginInstancePeer,
|
||||
public nsIPluginTagInfo2,
|
||||
public nsIJVMPluginTagInfo
|
||||
|
|
Загрузка…
Ссылка в новой задаче