1 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
3 #include "BrowserStreamParent.h"
4 #include "PluginInstanceParent.h"
6 #include "mozilla/unused.h"
8 // How much data are we willing to send across the wire
10 static const int32_t kSendDataChunk
= 0x4000;
15 BrowserStreamParent::BrowserStreamParent(PluginInstanceParent
* npp
,
21 mStream
->pdata
= static_cast<AStream
*>(this);
24 BrowserStreamParent::~BrowserStreamParent()
29 BrowserStreamParent::AnswerNPN_RequestRead(const IPCByteRanges
& ranges
,
32 PLUGIN_LOG_DEBUG_FUNCTION
;
39 *result
= NPERR_GENERIC_ERROR
;
43 NS_ERROR("Unexpected state");
50 if (ranges
.size() > PR_INT32_MAX
)
53 nsAutoArrayPtr
<NPByteRange
> rp(new NPByteRange
[ranges
.size()]);
54 for (PRUint32 i
= 0; i
< ranges
.size(); ++i
) {
55 rp
[i
].offset
= ranges
[i
].offset
;
56 rp
[i
].length
= ranges
[i
].length
;
57 rp
[i
].next
= &rp
[i
+ 1];
59 rp
[ranges
.size() - 1].next
= NULL
;
61 *result
= mNPP
->mNPNIface
->requestread(mStream
, rp
);
66 BrowserStreamParent::RecvNPN_DestroyStream(const NPReason
& reason
)
76 NS_ERROR("Unexpected state");
80 mNPP
->mNPNIface
->destroystream(mNPP
->mNPP
, mStream
, reason
);
85 BrowserStreamParent::NPP_DestroyStream(NPReason reason
)
87 NS_ASSERTION(ALIVE
== mState
, "NPP_DestroyStream called twice?");
89 unused
<< SendNPP_DestroyStream(reason
);
93 BrowserStreamParent::RecvStreamDestroyed()
95 if (DYING
!= mState
) {
96 NS_ERROR("Unexpected state");
101 return Send__delete__(this);
105 BrowserStreamParent::WriteReady()
107 return kSendDataChunk
;
111 BrowserStreamParent::Write(int32_t offset
,
115 PLUGIN_LOG_DEBUG_FUNCTION
;
117 NS_ASSERTION(ALIVE
== mState
, "Sending data after NPP_DestroyStream?");
118 NS_ASSERTION(len
> 0, "Non-positive length to NPP_Write");
120 if (len
> kSendDataChunk
)
121 len
= kSendDataChunk
;
123 return SendWrite(offset
,
124 nsCString(static_cast<char*>(buffer
), len
),
130 BrowserStreamParent::StreamAsFile(const char* fname
)
132 PLUGIN_LOG_DEBUG_FUNCTION
;
134 NS_ASSERTION(ALIVE
== mState
,
135 "Calling streamasfile after NPP_DestroyStream?");
137 unused
<< CallNPP_StreamAsFile(nsCString(fname
));
141 } // namespace plugins
142 } // namespace mozilla