2009-08-18 13:20:03 -07:00
|
|
|
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
|
|
|
|
|
2009-09-09 07:04:09 -07:00
|
|
|
#include "BrowserStreamParent.h"
|
2009-09-08 23:31:35 -07:00
|
|
|
#include "PluginInstanceParent.h"
|
2009-08-18 13:20:03 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace plugins {
|
|
|
|
|
2009-09-09 07:04:09 -07:00
|
|
|
BrowserStreamParent::BrowserStreamParent(PluginInstanceParent* npp,
|
|
|
|
NPStream* stream)
|
2009-08-18 13:20:03 -07:00
|
|
|
: mNPP(npp)
|
|
|
|
, mStream(stream)
|
|
|
|
{
|
2009-09-21 07:51:35 -07:00
|
|
|
mStream->pdata = static_cast<AStream*>(this);
|
2009-08-18 13:20:03 -07:00
|
|
|
}
|
|
|
|
|
2009-09-23 16:00:23 -07:00
|
|
|
BrowserStreamParent::~BrowserStreamParent()
|
|
|
|
{
|
2009-11-02 08:48:52 -08:00
|
|
|
}
|
2009-09-23 16:00:23 -07:00
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2009-09-09 07:04:09 -07:00
|
|
|
BrowserStreamParent::AnswerNPN_RequestRead(const IPCByteRanges& ranges,
|
|
|
|
NPError* result)
|
2009-08-18 13:20:03 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_FUNCTION;
|
2009-09-22 14:06:00 -07:00
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
if (!mStream)
|
2009-09-17 16:09:20 -07:00
|
|
|
return false;
|
2009-08-18 13:20:03 -07:00
|
|
|
|
2009-11-02 08:48:52 -08:00
|
|
|
if (ranges.size() > PR_INT32_MAX)
|
2009-09-19 12:24:24 -07:00
|
|
|
return false;
|
2009-08-18 13:20:03 -07:00
|
|
|
|
|
|
|
nsAutoArrayPtr<NPByteRange> rp(new NPByteRange[ranges.size()]);
|
|
|
|
for (PRUint32 i = 0; i < ranges.size(); ++i) {
|
|
|
|
rp[i].offset = ranges[i].offset;
|
|
|
|
rp[i].length = ranges[i].length;
|
|
|
|
rp[i].next = &rp[i + 1];
|
|
|
|
}
|
2009-09-22 14:06:00 -07:00
|
|
|
rp[ranges.size() - 1].next = NULL;
|
2009-08-18 13:20:03 -07:00
|
|
|
|
2009-09-22 14:06:00 -07:00
|
|
|
*result = mNPP->mNPNIface->requestread(mStream, rp);
|
|
|
|
return true;
|
2009-08-18 13:20:03 -07:00
|
|
|
}
|
|
|
|
|
2009-12-03 00:16:14 -08:00
|
|
|
bool
|
|
|
|
BrowserStreamParent::Answer__delete__(const NPError& reason,
|
|
|
|
const bool& artificial)
|
|
|
|
{
|
|
|
|
if (!artificial)
|
|
|
|
NPN_DestroyStream(reason);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
int32_t
|
2009-09-09 07:04:09 -07:00
|
|
|
BrowserStreamParent::WriteReady()
|
2009-08-18 13:20:03 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_FUNCTION;
|
2009-09-22 14:06:00 -07:00
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
int32_t result;
|
2009-11-25 12:34:49 -08:00
|
|
|
if (!CallNPP_WriteReady(mStream->end, &result))
|
2009-09-19 12:24:24 -07:00
|
|
|
return -1;
|
2009-11-25 12:34:49 -08:00
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
2009-09-09 07:04:09 -07:00
|
|
|
BrowserStreamParent::Write(int32_t offset,
|
|
|
|
int32_t len,
|
|
|
|
void* buffer)
|
2009-08-18 13:20:03 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_FUNCTION;
|
2009-09-22 14:06:00 -07:00
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
int32_t result;
|
2009-09-19 12:24:24 -07:00
|
|
|
if (!CallNPP_Write(offset,
|
2009-09-21 07:51:35 -07:00
|
|
|
nsCString(static_cast<char*>(buffer), len),
|
2009-09-23 16:00:23 -07:00
|
|
|
&result))
|
2009-08-18 13:20:03 -07:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-09 07:04:09 -07:00
|
|
|
BrowserStreamParent::StreamAsFile(const char* fname)
|
2009-08-18 13:20:03 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_FUNCTION;
|
2009-09-22 14:06:00 -07:00
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
CallNPP_StreamAsFile(nsCString(fname));
|
|
|
|
}
|
|
|
|
|
|
|
|
NPError
|
2009-09-09 07:04:09 -07:00
|
|
|
BrowserStreamParent::NPN_DestroyStream(NPReason reason)
|
2009-08-18 13:20:03 -07:00
|
|
|
{
|
2009-12-18 14:22:51 -08:00
|
|
|
PLUGIN_LOG_DEBUG_FUNCTION;
|
2009-09-22 14:06:00 -07:00
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
return mNPP->mNPNIface->destroystream(mNPP->mNPP, mStream, reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace plugins
|
|
|
|
} // namespace mozilla
|