gecko/dom/plugins/BrowserStreamParent.cpp

100 lines
2.1 KiB
C++
Raw Normal View History

/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
#include "BrowserStreamParent.h"
Rename plugin protocols and fix up usage --HG-- rename : dom/plugins/NPP.ipdl => dom/plugins/PPluginInstance.ipdl rename : dom/plugins/NPAPI.ipdl => dom/plugins/PPluginModule.ipdl rename : dom/plugins/NPObject.ipdl => dom/plugins/PPluginScriptableObject.ipdl rename : dom/plugins/NPBrowserStream.ipdl => dom/plugins/PPluginStream.ipdl rename : dom/plugins/NPPInstanceChild.cpp => dom/plugins/PluginInstanceChild.cpp rename : dom/plugins/NPPInstanceChild.h => dom/plugins/PluginInstanceChild.h rename : dom/plugins/NPPInstanceParent.cpp => dom/plugins/PluginInstanceParent.cpp rename : dom/plugins/NPPInstanceParent.h => dom/plugins/PluginInstanceParent.h rename : dom/plugins/NPAPIPluginChild.cpp => dom/plugins/PluginModuleChild.cpp rename : dom/plugins/NPAPIPluginChild.h => dom/plugins/PluginModuleChild.h rename : dom/plugins/NPAPIPluginParent.cpp => dom/plugins/PluginModuleParent.cpp rename : dom/plugins/NPAPIPluginParent.h => dom/plugins/PluginModuleParent.h rename : dom/plugins/NPObjectChild.cpp => dom/plugins/PluginScriptableObjectChild.cpp rename : dom/plugins/NPObjectChild.h => dom/plugins/PluginScriptableObjectChild.h rename : dom/plugins/NPObjectParent.cpp => dom/plugins/PluginScriptableObjectParent.cpp rename : dom/plugins/NPObjectParent.h => dom/plugins/PluginScriptableObjectParent.h rename : dom/plugins/NPBrowserStreamChild.cpp => dom/plugins/PluginStreamChild.cpp rename : dom/plugins/NPBrowserStreamChild.h => dom/plugins/PluginStreamChild.h rename : dom/plugins/NPBrowserStreamParent.cpp => dom/plugins/PluginStreamParent.cpp rename : dom/plugins/NPBrowserStreamParent.h => dom/plugins/PluginStreamParent.h
2009-09-08 23:31:35 -07:00
#include "PluginInstanceParent.h"
namespace mozilla {
namespace plugins {
BrowserStreamParent::BrowserStreamParent(PluginInstanceParent* npp,
NPStream* stream)
: mNPP(npp)
, mStream(stream)
{
mStream->pdata = static_cast<AStream*>(this);
}
BrowserStreamParent::~BrowserStreamParent()
{
}
bool
BrowserStreamParent::AnswerNPN_RequestRead(const IPCByteRanges& ranges,
NPError* result)
{
PLUGIN_LOG_DEBUG_FUNCTION;
if (!mStream)
return false;
if (ranges.size() > PR_INT32_MAX)
return false;
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];
}
rp[ranges.size() - 1].next = NULL;
*result = mNPP->mNPNIface->requestread(mStream, rp);
return true;
}
bool
BrowserStreamParent::Answer__delete__(const NPError& reason,
const bool& artificial)
{
if (!artificial)
NPN_DestroyStream(reason);
return true;
}
int32_t
BrowserStreamParent::WriteReady()
{
PLUGIN_LOG_DEBUG_FUNCTION;
int32_t result;
if (!CallNPP_WriteReady(mStream->end, &result))
return -1;
return result;
}
int32_t
BrowserStreamParent::Write(int32_t offset,
int32_t len,
void* buffer)
{
PLUGIN_LOG_DEBUG_FUNCTION;
int32_t result;
if (!CallNPP_Write(offset,
nsCString(static_cast<char*>(buffer), len),
&result))
return -1;
return result;
}
void
BrowserStreamParent::StreamAsFile(const char* fname)
{
PLUGIN_LOG_DEBUG_FUNCTION;
CallNPP_StreamAsFile(nsCString(fname));
}
NPError
BrowserStreamParent::NPN_DestroyStream(NPReason reason)
{
PLUGIN_LOG_DEBUG_FUNCTION;
return mNPP->mNPNIface->destroystream(mNPP->mNPP, mStream, reason);
}
} // namespace plugins
} // namespace mozilla