Bug 998863: Asynchronous Plugin Initialization, Part 11: IPC browser stream changes; r=jimm

This commit is contained in:
Aaron Klotz 2014-12-29 16:14:11 -07:00
parent fd3550c519
commit 89a1f85b44
4 changed files with 87 additions and 20 deletions

View File

@ -17,11 +17,7 @@ BrowserStreamChild::BrowserStreamChild(PluginInstanceChild* instance,
const uint32_t& length,
const uint32_t& lastmodified,
StreamNotifyChild* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t* stype)
const nsCString& headers)
: mInstance(instance)
, mStreamStatus(kStreamOpen)
, mDestroyPending(NOT_DESTROYED)
@ -34,9 +30,9 @@ BrowserStreamChild::BrowserStreamChild(PluginInstanceChild* instance,
, mStreamNotify(notifyData)
, mDeliveryTracker(MOZ_THIS_IN_INITIALIZER_LIST())
{
PLUGIN_LOG_DEBUG(("%s (%s, %i, %i, %p, %s, %s)", FULLFUNCTION,
PLUGIN_LOG_DEBUG(("%s (%s, %i, %i, %p, %s)", FULLFUNCTION,
url.get(), length, lastmodified, (void*) notifyData,
headers.get(), mimeType.get()));
headers.get()));
AssertPluginThread();
@ -46,8 +42,10 @@ BrowserStreamChild::BrowserStreamChild(PluginInstanceChild* instance,
mStream.end = length;
mStream.lastmodified = lastmodified;
mStream.headers = NullableStringGet(mHeaders);
if (notifyData)
if (notifyData) {
mStream.notifyData = notifyData->mClosure;
notifyData->SetAssociatedStream(this);
}
}
NPError
@ -68,9 +66,6 @@ BrowserStreamChild::StreamConstructed(
}
else {
mState = ALIVE;
if (mStreamNotify)
mStreamNotify->SetAssociatedStream(this);
}
return rv;

View File

@ -23,11 +23,7 @@ public:
const uint32_t& length,
const uint32_t& lastmodified,
StreamNotifyChild* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t* stype);
const nsCString& headers);
virtual ~BrowserStreamChild();
virtual bool IsBrowserStream() MOZ_OVERRIDE { return true; }

View File

@ -5,6 +5,7 @@
#include "BrowserStreamParent.h"
#include "PluginAsyncSurrogate.h"
#include "PluginInstanceParent.h"
#include "nsNPAPIPlugin.h"
@ -21,9 +22,15 @@ BrowserStreamParent::BrowserStreamParent(PluginInstanceParent* npp,
NPStream* stream)
: mNPP(npp)
, mStream(stream)
, mState(ALIVE)
, mDeferredDestroyReason(NPRES_DONE)
, mState(INITIALIZING)
{
mStream->pdata = static_cast<AStream*>(this);
nsNPAPIStreamWrapper* wrapper =
reinterpret_cast<nsNPAPIStreamWrapper*>(mStream->ndata);
if (wrapper) {
mStreamListener = wrapper->GetStreamListener();
}
}
BrowserStreamParent::~BrowserStreamParent()
@ -36,6 +43,43 @@ BrowserStreamParent::ActorDestroy(ActorDestroyReason aWhy)
// Implement me! Bug 1005159
}
bool
BrowserStreamParent::RecvAsyncNPP_NewStreamResult(const NPError& rv,
const uint16_t& stype)
{
PLUGIN_LOG_DEBUG_FUNCTION;
PluginAsyncSurrogate* surrogate = mNPP->GetAsyncSurrogate();
MOZ_ASSERT(surrogate);
surrogate->AsyncCallArriving();
nsRefPtr<nsNPAPIPluginStreamListener> streamListener = mStreamListener.forget();
if (mState == DEFERRING_DESTROY) {
// We've been asked to destroy ourselves before init was complete.
mState = DYING;
unused << SendNPP_DestroyStream(mDeferredDestroyReason);
return true;
}
NPError error = rv;
if (error == NPERR_NO_ERROR) {
if (!streamListener) {
return false;
}
if (streamListener->SetStreamType(stype)) {
mState = ALIVE;
} else {
error = NPERR_GENERIC_ERROR;
}
}
if (error != NPERR_NO_ERROR) {
// We need to clean up the stream
parent::_destroystream(mNPP->GetNPP(), mStream, NPRES_DONE);
unused << PBrowserStreamParent::Send__delete__(this);
}
return true;
}
bool
BrowserStreamParent::AnswerNPN_RequestRead(const IPCByteRanges& ranges,
NPError* result)
@ -43,6 +87,11 @@ BrowserStreamParent::AnswerNPN_RequestRead(const IPCByteRanges& ranges,
PLUGIN_LOG_DEBUG_FUNCTION;
switch (mState) {
case INITIALIZING:
NS_ERROR("Requesting a read before initialization has completed");
*result = NPERR_GENERIC_ERROR;
return false;
case ALIVE:
break;
@ -95,9 +144,16 @@ BrowserStreamParent::RecvNPN_DestroyStream(const NPReason& reason)
void
BrowserStreamParent::NPP_DestroyStream(NPReason reason)
{
NS_ASSERTION(ALIVE == mState, "NPP_DestroyStream called twice?");
mState = DYING;
unused << SendNPP_DestroyStream(reason);
NS_ASSERTION(ALIVE == mState || INITIALIZING == mState,
"NPP_DestroyStream called twice?");
bool stillInitializing = INITIALIZING == mState;
if (stillInitializing) {
mState = DEFERRING_DESTROY;
mDeferredDestroyReason = reason;
} else {
mState = DYING;
unused << SendNPP_DestroyStream(reason);
}
}
bool
@ -117,6 +173,9 @@ BrowserStreamParent::RecvStreamDestroyed()
int32_t
BrowserStreamParent::WriteReady()
{
if (mState == INITIALIZING) {
return 0;
}
return kSendDataChunk;
}

View File

@ -8,6 +8,8 @@
#include "mozilla/plugins/PBrowserStreamParent.h"
#include "mozilla/plugins/AStream.h"
#include "nsNPAPIPluginStreamListener.h"
#include "nsPluginStreamListenerPeer.h"
namespace mozilla {
namespace plugins {
@ -28,6 +30,10 @@ public:
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
virtual bool RecvAsyncNPP_NewStreamResult(
const NPError& rv,
const uint16_t& stype) MOZ_OVERRIDE;
virtual bool AnswerNPN_RequestRead(const IPCByteRanges& ranges,
NPError* result) MOZ_OVERRIDE;
@ -41,14 +47,25 @@ public:
void NPP_DestroyStream(NPReason reason);
void SetAlive()
{
if (mState == INITIALIZING) {
mState = ALIVE;
}
}
private:
using PBrowserStreamParent::SendNPP_DestroyStream;
PluginInstanceParent* mNPP;
NPStream* mStream;
nsCOMPtr<nsISupports> mStreamPeer;
nsRefPtr<nsNPAPIPluginStreamListener> mStreamListener;
NPReason mDeferredDestroyReason;
enum {
INITIALIZING,
DEFERRING_DESTROY,
ALIVE,
DYING,
DELETING