Bug 998863: Asynchronous Plugin Initialization, Part 6: PluginInstanceChild changes; r=jimm

This commit is contained in:
Aaron Klotz 2014-12-24 17:56:32 -07:00
parent 1af67c79f3
commit e8149f866f
2 changed files with 169 additions and 34 deletions

View File

@ -119,8 +119,16 @@ CreateDrawTargetForSurface(gfxASurface *aSurface)
return drawTarget;
}
PluginInstanceChild::PluginInstanceChild(const NPPluginFuncs* aPluginIface)
PluginInstanceChild::PluginInstanceChild(const NPPluginFuncs* aPluginIface,
const nsCString& aMimeType,
const uint16_t& aMode,
const InfallibleTArray<nsCString>& aNames,
const InfallibleTArray<nsCString>& aValues)
: mPluginIface(aPluginIface)
, mMimeType(aMimeType)
, mMode(aMode)
, mNames(aNames)
, mValues(aValues)
#if defined(XP_MACOSX)
, mContentsScaleFactor(1.0)
#endif
@ -210,6 +218,54 @@ PluginInstanceChild::~PluginInstanceChild()
#endif
}
NPError
PluginInstanceChild::DoNPP_New()
{
// unpack the arguments into a C format
int argc = mNames.Length();
NS_ASSERTION(argc == (int) mValues.Length(),
"argn.length != argv.length");
nsAutoArrayPtr<char*> argn(new char*[1 + argc]);
nsAutoArrayPtr<char*> argv(new char*[1 + argc]);
argn[argc] = 0;
argv[argc] = 0;
for (int i = 0; i < argc; ++i) {
argn[i] = const_cast<char*>(NullableStringGet(mNames[i]));
argv[i] = const_cast<char*>(NullableStringGet(mValues[i]));
}
NPP npp = GetNPP();
NPError rv = mPluginIface->newp((char*)NullableStringGet(mMimeType), npp,
mMode, argc, argn, argv, 0);
if (NPERR_NO_ERROR != rv) {
return rv;
}
Initialize();
#if defined(XP_MACOSX) && defined(__i386__)
// If an i386 Mac OS X plugin has selected the Carbon event model then
// we have to fail. We do not support putting Carbon event model plugins
// out of process. Note that Carbon is the default model so out of process
// plugins need to actively negotiate something else in order to work
// out of process.
if (EventModel() == NPEventModelCarbon) {
// Send notification that a plugin tried to negotiate Carbon NPAPI so that
// users can be notified that restarting the browser in i386 mode may allow
// them to use the plugin.
SendNegotiatedCarbon();
// Fail to instantiate.
rv = NPERR_MODULE_LOAD_FAILED_ERROR;
}
#endif
return rv;
}
int
PluginInstanceChild::GetQuirks()
{
@ -2234,21 +2290,86 @@ PluginInstanceChild::RecvPPluginScriptableObjectConstructor(
}
bool
PluginInstanceChild::AnswerPBrowserStreamConstructor(
PluginInstanceChild::RecvPBrowserStreamConstructor(
PBrowserStreamChild* aActor,
const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
PStreamNotifyChild* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t* stype)
const nsCString& headers)
{
return true;
}
NPError
PluginInstanceChild::DoNPP_NewStream(BrowserStreamChild* actor,
const nsCString& mimeType,
const bool& seekable,
uint16_t* stype)
{
AssertPluginThread();
*rv = static_cast<BrowserStreamChild*>(aActor)
->StreamConstructed(mimeType, seekable, stype);
NPError rv = actor->StreamConstructed(mimeType, seekable, stype);
return rv;
}
bool
PluginInstanceChild::AnswerNPP_NewStream(PBrowserStreamChild* actor,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t* stype)
{
*rv = DoNPP_NewStream(static_cast<BrowserStreamChild*>(actor), mimeType,
seekable, stype);
return true;
}
class NewStreamAsyncCall : public ChildAsyncCall
{
public:
NewStreamAsyncCall(PluginInstanceChild* aInstance,
BrowserStreamChild* aBrowserStreamChild,
const nsCString& aMimeType,
const bool aSeekable)
: ChildAsyncCall(aInstance, nullptr, nullptr)
, mBrowserStreamChild(aBrowserStreamChild)
, mMimeType(aMimeType)
, mSeekable(aSeekable)
{
}
void Run() MOZ_OVERRIDE
{
RemoveFromAsyncList();
uint16_t stype = NP_NORMAL;
NPError rv = mInstance->DoNPP_NewStream(mBrowserStreamChild, mMimeType,
mSeekable, &stype);
DebugOnly<bool> sendOk =
mBrowserStreamChild->SendAsyncNPP_NewStreamResult(rv, stype);
MOZ_ASSERT(sendOk);
}
private:
BrowserStreamChild* mBrowserStreamChild;
const nsCString mMimeType;
const bool mSeekable;
};
bool
PluginInstanceChild::RecvAsyncNPP_NewStream(PBrowserStreamChild* actor,
const nsCString& mimeType,
const bool& seekable)
{
// Reusing ChildAsyncCall so that the task is cancelled properly on Destroy
BrowserStreamChild* child = static_cast<BrowserStreamChild*>(actor);
NewStreamAsyncCall* task = new NewStreamAsyncCall(this, child, mimeType,
seekable);
{
MutexAutoLock lock(mAsyncCallMutex);
mPendingAsyncCalls.AppendElement(task);
}
MessageLoop::current()->PostTask(FROM_HERE, task);
return true;
}
@ -2257,16 +2378,12 @@ PluginInstanceChild::AllocPBrowserStreamChild(const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
PStreamNotifyChild* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t *stype)
const nsCString& headers)
{
AssertPluginThread();
return new BrowserStreamChild(this, url, length, lastmodified,
static_cast<StreamNotifyChild*>(notifyData),
headers, mimeType, seekable, rv, stype);
headers);
}
bool

View File

@ -143,29 +143,31 @@ protected:
virtual bool
RecvPPluginScriptableObjectConstructor(PPluginScriptableObjectChild* aActor) MOZ_OVERRIDE;
virtual bool
RecvPBrowserStreamConstructor(PBrowserStreamChild* aActor, const nsCString& url,
const uint32_t& length, const uint32_t& lastmodified,
PStreamNotifyChild* notifyData, const nsCString& headers);
virtual bool
AnswerNPP_NewStream(
PBrowserStreamChild* actor,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t* stype) MOZ_OVERRIDE;
virtual bool
RecvAsyncNPP_NewStream(
PBrowserStreamChild* actor,
const nsCString& mimeType,
const bool& seekable) MOZ_OVERRIDE;
virtual PBrowserStreamChild*
AllocPBrowserStreamChild(const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
PStreamNotifyChild* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t *stype) MOZ_OVERRIDE;
virtual bool
AnswerPBrowserStreamConstructor(
PBrowserStreamChild* aActor,
const nsCString& url,
const uint32_t& length,
const uint32_t& lastmodified,
PStreamNotifyChild* notifyData,
const nsCString& headers,
const nsCString& mimeType,
const bool& seekable,
NPError* rv,
uint16_t* stype) MOZ_OVERRIDE;
const nsCString& headers) MOZ_OVERRIDE;
virtual bool
DeallocPBrowserStreamChild(PBrowserStreamChild* stream) MOZ_OVERRIDE;
@ -202,10 +204,22 @@ protected:
#endif
public:
explicit PluginInstanceChild(const NPPluginFuncs* aPluginIface);
PluginInstanceChild(const NPPluginFuncs* aPluginIface,
const nsCString& aMimeType,
const uint16_t& aMode,
const InfallibleTArray<nsCString>& aNames,
const InfallibleTArray<nsCString>& aValues);
virtual ~PluginInstanceChild();
NPError DoNPP_New();
// Common sync+async implementation of NPP_NewStream
NPError DoNPP_NewStream(BrowserStreamChild* actor,
const nsCString& mimeType,
const bool& seekable,
uint16_t* stype);
bool Initialize();
NPP GetNPP()
@ -352,6 +366,10 @@ private:
#endif
const NPPluginFuncs* mPluginIface;
nsCString mMimeType;
uint16_t mMode;
InfallibleTArray<nsCString> mNames;
InfallibleTArray<nsCString> mValues;
NPP_t mData;
NPWindow mWindow;
#if defined(XP_MACOSX)