Bug 516524 - Support NPRuntime across processes. r=bsmedberg.

This commit is contained in:
Ben Turner 2009-10-07 16:50:48 -07:00
Родитель bef4a65dca
Коммит 423c5543dd
14 изменённых файлов: 1839 добавлений и 277 удалений

Просмотреть файл

@ -48,8 +48,7 @@ using mozilla::ipc::NPRemoteIdentifier;
using nsTArray<NPRemoteIdentifier>;
using mozilla::void_t;
using mozilla::null_t;
using mozilla::ipc::NPRemoteVariant;
using nsTArray<NPRemoteVariant>;
using nsTArray<Variant>;
namespace mozilla {
namespace plugins {
@ -68,7 +67,7 @@ rpc protocol PPluginScriptableObject
{
manager PPluginInstance;
child:
both:
// NPClass methods
rpc Invalidate();
@ -76,23 +75,23 @@ child:
returns (bool aHasMethod);
rpc Invoke(NPRemoteIdentifier aId,
nsTArray<NPRemoteVariant> aArgs)
returns (NPRemoteVariant aResult,
nsTArray<Variant> aArgs)
returns (Variant aResult,
bool aSuccess);
rpc InvokeDefault(nsTArray<NPRemoteVariant> aArgs)
returns (NPRemoteVariant aResult,
rpc InvokeDefault(nsTArray<Variant> aArgs)
returns (Variant aResult,
bool aSuccess);
rpc HasProperty(NPRemoteIdentifier aId)
returns (bool aHasProperty);
rpc GetProperty(NPRemoteIdentifier aId)
returns (NPRemoteVariant aResult,
returns (Variant aResult,
bool aSuccess);
rpc SetProperty(NPRemoteIdentifier aId,
NPRemoteVariant aValue)
Variant aValue)
returns (bool aSuccess);
rpc RemoveProperty(NPRemoteIdentifier aId)
@ -102,8 +101,8 @@ child:
returns (nsTArray<NPRemoteIdentifier> aProperties,
bool aSuccess);
rpc Construct(nsTArray<NPRemoteVariant> aArgs)
returns (NPRemoteVariant aResult,
rpc Construct(nsTArray<Variant> aArgs)
returns (Variant aResult,
bool aSuccess);
};

Просмотреть файл

@ -124,6 +124,48 @@ PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
return result;
}
case NPNVWindowNPObject: {
PPluginScriptableObjectChild* actor;
NPError result;
if (!CallNPN_GetValue_NPNVWindowNPObject(&actor, &result)) {
NS_WARNING("Failed to send message!");
return NPERR_GENERIC_ERROR;
}
if (result != NPERR_NO_ERROR) {
return result;
}
NPObject* object =
static_cast<PluginScriptableObjectChild*>(actor)->GetObject();
NS_ASSERTION(object, "Null object?!");
PluginModuleChild::sBrowserFuncs.retainobject(object);
*((NPObject**)aValue) = object;
return NPERR_NO_ERROR;
}
case NPNVPluginElementNPObject: {
PPluginScriptableObjectChild* actor;
NPError result;
if (!CallNPN_GetValue_NPNVPluginElementNPObject(&actor, &result)) {
NS_WARNING("Failed to send message!");
return NPERR_GENERIC_ERROR;
}
if (result != NPERR_NO_ERROR) {
return result;
}
NPObject* object =
static_cast<PluginScriptableObjectChild*>(actor)->GetObject();
NS_ASSERTION(object, "Null object?!");
PluginModuleChild::sBrowserFuncs.retainobject(object);
*((NPObject**)aValue) = object;
return NPERR_NO_ERROR;
}
default:
printf(" unhandled var %s\n", NPNVariableToString(aVar));
return NPERR_GENERIC_ERROR;
@ -222,13 +264,16 @@ PluginInstanceChild::AnswerNPP_GetValue_NPPVpluginScriptableNPObject(
}
PluginScriptableObjectChild* actor = GetActorForNPObject(object);
if (!actor) {
// If we get an actor then it has retained. Otherwise we don't need it any
// longer.
PluginModuleChild::sBrowserFuncs.releaseobject(object);
if (!actor) {
*result = NPERR_GENERIC_ERROR;
return true;
}
PluginModuleChild::sBrowserFuncs.releaseobject(object);
*value = actor;
return true;
}
@ -352,6 +397,26 @@ PluginInstanceChild::Initialize()
return true;
}
void
PluginInstanceChild::Destroy()
{
// Copy the actors here so we don't enumerate a mutating array.
nsAutoTArray<PluginScriptableObjectChild*, 10> objects;
PRUint32 count = mScriptableObjects.Length();
for (PRUint32 index = 0; index < count; index++) {
objects.AppendElement(mScriptableObjects[index]);
}
count = objects.Length();
for (PRUint32 index = 0; index < count; index++) {
PluginScriptableObjectChild*& actor = objects[index];
NPObject* object = actor->GetObject();
if (object->_class == PluginScriptableObjectChild::GetClass()) {
PluginScriptableObjectChild::ScriptableInvalidate(object);
}
}
}
#if defined(OS_WIN)
static const TCHAR kWindowClassName[] = TEXT("GeckoPluginWindow");
@ -509,11 +574,18 @@ PluginInstanceChild::AllocPPluginScriptableObject()
}
bool
PluginInstanceChild::DeallocPPluginScriptableObject(PPluginScriptableObjectChild* aObject)
PluginInstanceChild::DeallocPPluginScriptableObject(
PPluginScriptableObjectChild* aObject)
{
PluginScriptableObjectChild* object =
reinterpret_cast<PluginScriptableObjectChild*>(aObject);
NPObject* npobject = object->GetObject();
if (npobject &&
npobject->_class != PluginScriptableObjectChild::GetClass()) {
PluginModuleChild::current()->UnregisterNPObject(npobject);
}
PRUint32 count = mScriptableObjects.Length();
for (PRUint32 index = 0; index < count; index++) {
if (mScriptableObjects[index] == object) {
@ -525,6 +597,30 @@ PluginInstanceChild::DeallocPPluginScriptableObject(PPluginScriptableObjectChild
return false;
}
bool
PluginInstanceChild::AnswerPPluginScriptableObjectConstructor(
PPluginScriptableObjectChild* aActor)
{
// This is only called in response to the parent process requesting the
// creation of an actor. This actor will represent an NPObject that is
// created by the browser and returned to the plugin.
NPClass* npclass =
const_cast<NPClass*>(PluginScriptableObjectChild::GetClass());
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(
PluginModuleChild::sBrowserFuncs.createobject(GetNPP(), npclass));
if (!object) {
NS_WARNING("Failed to create NPObject!");
return false;
}
PluginScriptableObjectChild* actor =
static_cast<PluginScriptableObjectChild*>(aActor);
actor->Initialize(const_cast<PluginInstanceChild*>(this), object);
return true;
}
PBrowserStreamChild*
PluginInstanceChild::AllocPBrowserStream(const nsCString& url,
const uint32_t& length,
@ -616,11 +712,17 @@ PluginInstanceChild::GetActorForNPObject(NPObject* aObject)
{
NS_ASSERTION(aObject, "Null pointer!");
if (aObject->_class == PluginScriptableObjectChild::GetClass()) {
// One of ours! It's a browser-provided object.
ChildNPObject* object = static_cast<ChildNPObject*>(aObject);
NS_ASSERTION(object->parent, "Null actor!");
return object->parent;
}
PluginScriptableObjectChild* actor =
PluginModuleChild::current()->GetActorForNPObject(aObject);
if (actor) {
PluginModuleChild::sBrowserFuncs.retainobject(aObject);
// Plugin-provided object that we've previously wrapped.
return actor;
}

Просмотреть файл

@ -90,6 +90,9 @@ protected:
virtual bool
DeallocPPluginScriptableObject(PPluginScriptableObjectChild* aObject);
virtual bool
AnswerPPluginScriptableObjectConstructor(PPluginScriptableObjectChild* aActor);
virtual PBrowserStreamChild*
AllocPBrowserStream(const nsCString& url,
const uint32_t& length,
@ -158,6 +161,7 @@ public:
virtual ~PluginInstanceChild();
bool Initialize();
void Destroy();
NPP GetNPP()
{

Просмотреть файл

@ -61,6 +61,25 @@ PluginInstanceParent::~PluginInstanceParent()
{
}
void
PluginInstanceParent::Destroy()
{
// Copy the actors here so we don't enumerate a mutating array.
nsAutoTArray<PluginScriptableObjectParent*, 10> objects;
PRUint32 count = mScriptableObjects.Length();
for (PRUint32 index = 0; index < count; index++) {
objects.AppendElement(mScriptableObjects[index]);
}
count = objects.Length();
for (PRUint32 index = 0; index < count; index++) {
NPObject* object = objects[index]->GetObject();
if (object->_class == PluginScriptableObjectParent::GetClass()) {
PluginScriptableObjectParent::ScriptableInvalidate(object);
}
}
}
PBrowserStreamParent*
PluginInstanceParent::AllocPBrowserStream(const nsCString& url,
const uint32_t& length,
@ -138,25 +157,59 @@ PluginInstanceParent::AnswerNPN_GetValue_NPNVisOfflineBool(bool* value,
}
bool
PluginInstanceParent::AnswerNPN_GetValue_NPNVWindowNPObject(
PPluginScriptableObjectParent** value,
NPError* result)
PluginInstanceParent::InternalGetValueForNPObject(
NPNVariable aVariable,
PPluginScriptableObjectParent** aValue,
NPError* aResult)
{
// TODO NPRuntime
*value = NULL;
*result = NPERR_GENERIC_ERROR;
NPObject* npobject;
NPError result = mNPNIface->getvalue(mNPP, aVariable, (void*)&npobject);
if (result != NPERR_NO_ERROR || !npobject) {
*aValue = nsnull;
*aResult = result;
return true;
}
PluginScriptableObjectParent* actor =
static_cast<PluginScriptableObjectParent*>(
AllocPPluginScriptableObject());
if (!actor) {
mNPNIface->releaseobject(npobject);
*aValue = nsnull;
*aResult = NPERR_OUT_OF_MEMORY_ERROR;
return true;
}
if (!CallPPluginScriptableObjectConstructor(actor)) {
mNPNIface->releaseobject(npobject);
DeallocPPluginScriptableObject(actor);
*aValue = nsnull;
*aResult = NPERR_GENERIC_ERROR;
return true;
}
actor->Initialize(const_cast<PluginInstanceParent*>(this), npobject);
*aValue = actor;
*aResult = NPERR_NO_ERROR;
return true;
}
bool
PluginInstanceParent::AnswerNPN_GetValue_NPNVPluginElementNPObject(
PPluginScriptableObjectParent** value,
NPError* result)
PluginInstanceParent::AnswerNPN_GetValue_NPNVWindowNPObject(
PPluginScriptableObjectParent** aValue,
NPError* aResult)
{
// TODO NPRuntime
*value = NULL;
*result = NPERR_GENERIC_ERROR;
return true;
return InternalGetValueForNPObject(NPNVWindowNPObject, aValue, aResult);
}
bool
PluginInstanceParent::AnswerNPN_GetValue_NPNVPluginElementNPObject(
PPluginScriptableObjectParent** aValue,
NPError* aResult)
{
return InternalGetValueForNPObject(NPNVPluginElementNPObject, aValue,
aResult);
}
bool
@ -360,8 +413,7 @@ PluginInstanceParent::NPP_GetValue(NPPVariable aVariable,
}
NPObject* object =
reinterpret_cast<PluginScriptableObjectParent*>(actor)->
GetObject();
static_cast<PluginScriptableObjectParent*>(actor)->GetObject();
NS_ASSERTION(object, "This shouldn't ever be null!");
(*(NPObject**)_retval) = npn->retainobject(object);
@ -486,19 +538,26 @@ bool
PluginInstanceParent::AnswerPPluginScriptableObjectConstructor(
PPluginScriptableObjectParent* aActor)
{
// This is only called in response to the child process requesting the
// creation of an actor. This actor will represent an NPObject that is
// created by the plugin and returned to the browser.
const NPNetscapeFuncs* npn = mParent->GetNetscapeFuncs();
if (!npn) {
NS_WARNING("No netscape function pointers?!");
return false;
}
NPClass* npclass =
const_cast<NPClass*>(PluginScriptableObjectParent::GetClass());
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(
npn->createobject(mNPP, PluginScriptableObjectParent::GetClass()));
npn->createobject(mNPP, npclass));
if (!object) {
NS_WARNING("Failed to create NPObject!");
return false;
}
reinterpret_cast<PluginScriptableObjectParent*>(aActor)->Initialize(
static_cast<PluginScriptableObjectParent*>(aActor)->Initialize(
const_cast<PluginInstanceParent*>(this), object);
return true;
}
@ -513,3 +572,33 @@ PluginInstanceParent::NPP_URLNotify(const char* url, NPReason reason,
static_cast<PStreamNotifyParent*>(notifyData);
CallPStreamNotifyDestructor(streamNotify, reason);
}
PluginScriptableObjectParent*
PluginInstanceParent::GetActorForNPObject(NPObject* aObject)
{
NS_ASSERTION(aObject, "Null pointer!");
if (aObject->_class == PluginScriptableObjectParent::GetClass()) {
// One of ours!
ParentNPObject* object = static_cast<ParentNPObject*>(aObject);
NS_ASSERTION(object->parent, "Null actor!");
return object->parent;
}
PRUint32 count = mScriptableObjects.Length();
for (PRUint32 index = 0; index < count; index++) {
nsAutoPtr<PluginScriptableObjectParent>& actor =
mScriptableObjects[index];
if (actor->GetObject() == aObject) {
return actor;
}
}
PluginScriptableObjectParent* actor =
static_cast<PluginScriptableObjectParent*>(
CallPPluginScriptableObjectConstructor());
NS_ENSURE_TRUE(actor, nsnull);
actor->Initialize(const_cast<PluginInstanceParent*>(this), aObject);
return actor;
}

Просмотреть файл

@ -69,6 +69,8 @@ public:
virtual ~PluginInstanceParent();
void Destroy();
virtual PPluginScriptableObjectParent*
AllocPPluginScriptableObject();
@ -178,6 +180,25 @@ public:
return mParent;
}
const NPNetscapeFuncs* GetNPNIface()
{
return mNPNIface;
}
PluginScriptableObjectParent*
GetActorForNPObject(NPObject* aObject);
NPP
GetNPP()
{
return mNPP;
}
private:
bool InternalGetValueForNPObject(NPNVariable aVariable,
PPluginScriptableObjectParent** aValue,
NPError* aResult);
private:
PluginModuleParent* mParent;
NPP mNPP;

Просмотреть файл

@ -53,15 +53,9 @@ namespace mozilla {
struct void_t { };
struct null_t { };
// XXX Uberhack, remove this typedef and forward decl.
namespace plugins {
class Variant;
}
namespace ipc {
typedef intptr_t NPRemoteIdentifier;
typedef mozilla::plugins::Variant NPRemoteVariant;
} /* namespace ipc */

Просмотреть файл

@ -839,7 +839,10 @@ _createobject(NPP aNPP,
NPObject* NP_CALLBACK
_retainobject(NPObject* aNPObj)
{
_MOZ_LOG(__FUNCTION__);
#ifdef DEBUG
printf("[PluginModuleChild] %s: object %p, refcnt %d\n", __FUNCTION__,
aNPObj, aNPObj->referenceCount + 1);
#endif
++aNPObj->referenceCount;
return aNPObj;
}
@ -847,8 +850,10 @@ _retainobject(NPObject* aNPObj)
void NP_CALLBACK
_releaseobject(NPObject* aNPObj)
{
_MOZ_LOG(__FUNCTION__);
#ifdef DEBUG
printf("[PluginModuleChild] %s: object %p, refcnt %d\n", __FUNCTION__,
aNPObj, aNPObj->referenceCount - 1);
#endif
if (--aNPObj->referenceCount == 0) {
if (aNPObj->_class && aNPObj->_class->deallocate) {
aNPObj->_class->deallocate(aNPObj);
@ -868,7 +873,11 @@ _invoke(NPP aNPP,
NPVariant* aResult)
{
_MOZ_LOG(__FUNCTION__);
if (!aNPP || !aNPObj || !aNPObj->_class || !aNPObj->_class->invoke)
return false;
return aNPObj->_class->invoke(aNPObj, aMethod, aArgs, aArgCount, aResult);
}
bool NP_CALLBACK
@ -879,7 +888,11 @@ _invokedefault(NPP aNPP,
NPVariant* aResult)
{
_MOZ_LOG(__FUNCTION__);
if (!aNPP || !aNPObj || !aNPObj->_class || !aNPObj->_class->invokeDefault)
return false;
return aNPObj->_class->invokeDefault(aNPObj, aArgs, aArgCount, aResult);
}
bool NP_CALLBACK
@ -889,6 +902,7 @@ _evaluate(NPP aNPP,
NPVariant* aResult)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
return false;
}
@ -899,7 +913,11 @@ _getproperty(NPP aNPP,
NPVariant* aResult)
{
_MOZ_LOG(__FUNCTION__);
if (!aNPP || !aNPObj || !aNPObj->_class || !aNPObj->_class->getProperty)
return false;
return aNPObj->_class->getProperty(aNPObj, aPropertyName, aResult);
}
bool NP_CALLBACK
@ -909,7 +927,11 @@ _setproperty(NPP aNPP,
const NPVariant* aValue)
{
_MOZ_LOG(__FUNCTION__);
if (!aNPP || !aNPObj || !aNPObj->_class || !aNPObj->_class->setProperty)
return false;
return aNPObj->_class->setProperty(aNPObj, aPropertyName, aValue);
}
bool NP_CALLBACK
@ -918,7 +940,11 @@ _removeproperty(NPP aNPP,
NPIdentifier aPropertyName)
{
_MOZ_LOG(__FUNCTION__);
if (!aNPP || !aNPObj || !aNPObj->_class || !aNPObj->_class->removeProperty)
return false;
return aNPObj->_class->removeProperty(aNPObj, aPropertyName);
}
bool NP_CALLBACK
@ -927,7 +953,11 @@ _hasproperty(NPP aNPP,
NPIdentifier aPropertyName)
{
_MOZ_LOG(__FUNCTION__);
if (!aNPP || !aNPObj || !aNPObj->_class || !aNPObj->_class->hasProperty)
return false;
return aNPObj->_class->hasProperty(aNPObj, aPropertyName);
}
bool NP_CALLBACK
@ -936,7 +966,11 @@ _hasmethod(NPP aNPP,
NPIdentifier aMethodName)
{
_MOZ_LOG(__FUNCTION__);
if (!aNPP || !aNPObj || !aNPObj->_class || !aNPObj->_class->hasMethod)
return false;
return aNPObj->_class->hasMethod(aNPObj, aMethodName);
}
bool NP_CALLBACK
@ -946,7 +980,18 @@ _enumerate(NPP aNPP,
uint32_t* aCount)
{
_MOZ_LOG(__FUNCTION__);
if (!aNPP || !aNPObj || !aNPObj->_class)
return false;
if (!NP_CLASS_STRUCT_VERSION_HAS_ENUM(aNPObj->_class) ||
!aNPObj->_class->enumerate) {
*aIdentifiers = 0;
*aCount = 0;
return true;
}
return aNPObj->_class->enumerate(aNPObj, aIdentifiers, aCount);
}
bool NP_CALLBACK
@ -957,13 +1002,31 @@ _construct(NPP aNPP,
NPVariant* aResult)
{
_MOZ_LOG(__FUNCTION__);
if (!aNPP || !aNPObj || !aNPObj->_class ||
!NP_CLASS_STRUCT_VERSION_HAS_CTOR(aNPObj->_class) ||
!aNPObj->_class->construct) {
return false;
}
return aNPObj->_class->construct(aNPObj, aArgs, aArgCount, aResult);
}
void NP_CALLBACK
_releasevariantvalue(NPVariant* aVariant)
{
_MOZ_LOG(__FUNCTION__);
if (NPVARIANT_IS_STRING(*aVariant)) {
NPString str = NPVARIANT_TO_STRING(*aVariant);
free(const_cast<NPUTF8*>(str.UTF8Characters));
}
else if (NPVARIANT_IS_OBJECT(*aVariant)) {
NPObject* object = NPVARIANT_TO_OBJECT(*aVariant);
if (object) {
_releaseobject(object);
}
}
VOID_TO_NPVARIANT(*aVariant);
}
void NP_CALLBACK
@ -971,6 +1034,7 @@ _setexception(NPObject* aNPObj,
const NPUTF8* aMessage)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
}
bool NP_CALLBACK
@ -978,6 +1042,7 @@ _pushpopupsenabledstate(NPP aNPP,
NPBool aEnabled)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
return false;
}
@ -985,6 +1050,7 @@ bool NP_CALLBACK
_poppopupsenabledstate(NPP aNPP)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
return false;
}
@ -994,6 +1060,7 @@ _pluginthreadasynccall(NPP aNPP,
void* aUserData)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
}
NPError NP_CALLBACK
@ -1001,6 +1068,7 @@ _getvalueforurl(NPP npp, NPNURLVariable variable, const char *url,
char **value, uint32_t *len)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
return NPERR_GENERIC_ERROR;
}
@ -1009,6 +1077,7 @@ _setvalueforurl(NPP npp, NPNURLVariable variable, const char *url,
const char *value, uint32_t len)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
return NPERR_GENERIC_ERROR;
}
@ -1020,6 +1089,7 @@ _getauthenticationinfo(NPP npp, const char *protocol,
char **password, uint32_t *plen)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
return NPERR_GENERIC_ERROR;
}
@ -1028,12 +1098,14 @@ _scheduletimer(NPP instance, uint32_t interval, NPBool repeat,
void (*timerFunc)(NPP npp, uint32_t timerID))
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
return 0;
}
void NP_CALLBACK
_unscheduletimer(NPP instance, uint32_t timerID)
{
NS_NOTYETIMPLEMENTED("Implement me!");
_MOZ_LOG(__FUNCTION__);
}
@ -1041,6 +1113,7 @@ NPError NP_CALLBACK
_popupcontextmenu(NPP instance, NPMenu* menu)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
return NPERR_GENERIC_ERROR;
}
@ -1050,6 +1123,7 @@ _convertpoint(NPP instance,
double *destX, double *destY, NPCoordinateSpace destSpace)
{
_MOZ_LOG(__FUNCTION__);
NS_NOTYETIMPLEMENTED("Implement me!");
return 0;
}
@ -1149,14 +1223,25 @@ PluginModuleChild::AnswerPPluginInstanceConstructor(PPluginInstanceChild* aActor
}
bool
PluginModuleChild::DeallocPPluginInstance(PPluginInstanceChild* actor,
PluginModuleChild::DeallocPPluginInstance(PPluginInstanceChild* aActor,
NPError* rv)
{
_MOZ_LOG(__FUNCTION__);
PluginInstanceChild* inst = static_cast<PluginInstanceChild*>(actor);
delete aActor;
return true;
}
bool
PluginModuleChild::AnswerPPluginInstanceDestructor(PPluginInstanceChild* aActor,
NPError* rv)
{
_MOZ_LOG(__FUNCTION__);
PluginInstanceChild* inst = static_cast<PluginInstanceChild*>(aActor);
*rv = mFunctions.destroy(inst->GetNPP(), 0);
delete actor;
inst->Destroy();
inst->GetNPP()->ndata = 0;
return true;

Просмотреть файл

@ -112,6 +112,10 @@ protected:
DeallocPPluginInstance(PPluginInstanceChild* aActor,
NPError* rv);
virtual bool
AnswerPPluginInstanceDestructor(PPluginInstanceChild* aActor,
NPError* rv);
virtual bool
AnswerPPluginInstanceConstructor(PPluginInstanceChild* aActor,
const nsCString& aMimeType,

Просмотреть файл

@ -102,6 +102,7 @@ PluginModuleParent::DeallocPPluginInstance(PPluginInstanceParent* aActor,
{
_MOZ_LOG(__FUNCTION__);
delete aActor;
*_retval = NPERR_NO_ERROR;
return true;
}
@ -225,6 +226,8 @@ PluginModuleParent::NPP_Destroy(NPP instance,
PluginInstanceParent* parentInstance =
static_cast<PluginInstanceParent*>(instance->pdata);
parentInstance->Destroy();
NPError prv;
if (!Shim::HACK_target->CallPPluginInstanceDestructor(parentInstance, &prv)) {
prv = NPERR_GENERIC_ERROR;

Просмотреть файл

@ -46,14 +46,15 @@
#include "PluginInstanceChild.h"
using namespace mozilla::plugins;
using mozilla::ipc::NPRemoteVariant;
using mozilla::ipc::NPRemoteIdentifier;
namespace {
inline NPObject*
NPObjectFromVariant(const NPRemoteVariant& aRemoteVariant) {
NPObjectFromVariant(const Variant& aRemoteVariant)
{
NS_ASSERTION(aRemoteVariant.type() ==
NPRemoteVariant::TPPluginScriptableObjectChild,
Variant::TPPluginScriptableObjectChild,
"Wrong variant type!");
PluginScriptableObjectChild* actor =
const_cast<PluginScriptableObjectChild*>(
@ -63,73 +64,66 @@ NPObjectFromVariant(const NPRemoteVariant& aRemoteVariant) {
}
inline NPObject*
NPObjectFromVariant(const NPVariant& aVariant) {
NPObjectFromVariant(const NPVariant& aVariant)
{
NS_ASSERTION(NPVARIANT_IS_OBJECT(aVariant), "Wrong variant type!");
return NPVARIANT_TO_OBJECT(aVariant);
}
bool
ConvertToVariant(const NPRemoteVariant& aRemoteVariant,
void
ConvertToVariant(const Variant& aRemoteVariant,
NPVariant& aVariant)
{
switch (aRemoteVariant.type()) {
case NPRemoteVariant::Tvoid_t: {
case Variant::Tvoid_t: {
VOID_TO_NPVARIANT(aVariant);
break;
}
case NPRemoteVariant::Tnull_t: {
case Variant::Tnull_t: {
NULL_TO_NPVARIANT(aVariant);
break;
}
case NPRemoteVariant::Tbool: {
case Variant::Tbool: {
BOOLEAN_TO_NPVARIANT(aRemoteVariant.get_bool(), aVariant);
break;
}
case NPRemoteVariant::Tint: {
case Variant::Tint: {
INT32_TO_NPVARIANT(aRemoteVariant.get_int(), aVariant);
break;
}
case NPRemoteVariant::Tdouble: {
case Variant::Tdouble: {
DOUBLE_TO_NPVARIANT(aRemoteVariant.get_double(), aVariant);
break;
}
case NPRemoteVariant::TnsCString: {
case Variant::TnsCString: {
const nsCString& string = aRemoteVariant.get_nsCString();
NPUTF8* buffer = reinterpret_cast<NPUTF8*>(strdup(string.get()));
if (!buffer) {
NS_ERROR("Out of memory!");
return false;
}
NS_ASSERTION(buffer, "Out of memory!");
STRINGN_TO_NPVARIANT(buffer, string.Length(), aVariant);
break;
}
case NPRemoteVariant::TPPluginScriptableObjectChild: {
case Variant::TPPluginScriptableObjectChild: {
NPObject* object = NPObjectFromVariant(aRemoteVariant);
if (!object) {
NS_ERROR("Er, this shouldn't fail!");
return false;
}
NS_ASSERTION(object, "Null object?!");
PluginModuleChild::sBrowserFuncs.retainobject(object);
OBJECT_TO_NPVARIANT(object, aVariant);
break;
}
default:
NS_NOTREACHED("Shouldn't get here!");
return false;
NS_RUNTIMEABORT("Shouldn't get here!");
}
return true;
}
bool
ConvertToRemoteVariant(const NPVariant& aVariant,
NPRemoteVariant& aRemoteVariant,
Variant& aRemoteVariant,
PluginInstanceChild* aInstance)
{
if (NPVARIANT_IS_VOID(aVariant)) {
@ -154,8 +148,11 @@ ConvertToRemoteVariant(const NPVariant& aVariant,
}
else if (NPVARIANT_IS_OBJECT(aVariant)) {
NS_ASSERTION(aInstance, "Must have an instance to wrap!");
PluginScriptableObjectChild* actor =
aInstance->GetActorForNPObject(NPVARIANT_TO_OBJECT(aVariant));
NPObject* object = NPVARIANT_TO_OBJECT(aVariant);
NS_ASSERTION(object, "Null object?!");
PluginScriptableObjectChild* actor = aInstance->GetActorForNPObject(object);
if (!actor) {
NS_ERROR("Failed to create actor!");
return false;
@ -172,6 +169,445 @@ ConvertToRemoteVariant(const NPVariant& aVariant,
} // anonymous namespace
// static
NPObject*
PluginScriptableObjectChild::ScriptableAllocate(NPP aInstance,
NPClass* aClass)
{
NS_ASSERTION(aClass == PluginScriptableObjectChild::GetClass(),
"Huh?! Wrong class!");
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(
PluginModuleChild::sBrowserFuncs.memalloc(sizeof(ChildNPObject)));
if (object) {
memset(object, 0, sizeof(ChildNPObject));
}
return object;
}
// static
void
PluginScriptableObjectChild::ScriptableInvalidate(NPObject* aObject)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
// This can happen more than once, and is just fine.
return;
}
PluginScriptableObjectChild* actor = object->parent;
PluginInstanceChild* instance = actor ? actor->GetInstance() : nsnull;
NS_WARN_IF_FALSE(instance, "No instance!");
if (actor && !actor->CallInvalidate()) {
NS_WARNING("Failed to send message!");
}
object->invalidated = true;
if (instance &&
!instance->CallPPluginScriptableObjectDestructor(object->parent)) {
NS_WARNING("Failed to send message!");
}
}
// static
void
PluginScriptableObjectChild::ScriptableDeallocate(NPObject* aObject)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (!object->invalidated) {
ScriptableInvalidate(aObject);
}
NS_ASSERTION(object->invalidated, "Should be invalidated!");
NS_Free(aObject);
}
// static
bool
PluginScriptableObjectChild::ScriptableHasMethod(NPObject* aObject,
NPIdentifier aName)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return false;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectChild* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
bool result;
if (!actor->CallHasMethod((NPRemoteIdentifier)aName, &result)) {
NS_WARNING("Failed to send message!");
return false;
}
return result;
}
// static
bool
PluginScriptableObjectChild::ScriptableInvoke(NPObject* aObject,
NPIdentifier aName,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return false;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectChild* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
nsAutoTArray<Variant, 10> args;
if (!args.SetLength(aArgCount)) {
NS_ERROR("Out of memory?!");
return false;
}
for (PRUint32 index = 0; index < aArgCount; index++) {
Variant& arg = args[index];
if (!ConvertToRemoteVariant(aArgs[index], arg, actor->GetInstance())) {
NS_WARNING("Failed to convert argument!");
return false;
}
}
Variant remoteResult;
bool success;
if (!actor->CallInvoke((NPRemoteIdentifier)aName, args, &remoteResult,
&success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
ConvertToVariant(remoteResult, *aResult);
return true;
}
// static
bool
PluginScriptableObjectChild::ScriptableInvokeDefault(NPObject* aObject,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return false;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectChild* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
nsAutoTArray<Variant, 10> args;
if (!args.SetLength(aArgCount)) {
NS_ERROR("Out of memory?!");
return false;
}
for (PRUint32 index = 0; index < aArgCount; index++) {
Variant& arg = args[index];
if (!ConvertToRemoteVariant(aArgs[index], arg, actor->GetInstance())) {
NS_WARNING("Failed to convert argument!");
return false;
}
}
Variant remoteResult;
bool success;
if (!actor->CallInvokeDefault(args, &remoteResult, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
ConvertToVariant(remoteResult, *aResult);
return true;
}
// static
bool
PluginScriptableObjectChild::ScriptableHasProperty(NPObject* aObject,
NPIdentifier aName)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return false;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectChild* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
bool result;
if (!actor->CallHasProperty((NPRemoteIdentifier)aName, &result)) {
NS_WARNING("Failed to send message!");
return false;
}
return result;
}
// static
bool
PluginScriptableObjectChild::ScriptableGetProperty(NPObject* aObject,
NPIdentifier aName,
NPVariant* aResult)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return false;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectChild* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
Variant result;
bool success;
if (!actor->CallGetProperty((NPRemoteIdentifier)aName, &result, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
ConvertToVariant(result, *aResult);
return true;
}
// static
bool
PluginScriptableObjectChild::ScriptableSetProperty(NPObject* aObject,
NPIdentifier aName,
const NPVariant* aValue)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return false;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectChild* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
Variant value;
if (!ConvertToRemoteVariant(*aValue, value, actor->GetInstance())) {
NS_WARNING("Failed to convert variant!");
return false;
}
bool success;
if (!actor->CallSetProperty((NPRemoteIdentifier)aName, value, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
return success;
}
// static
bool
PluginScriptableObjectChild::ScriptableRemoveProperty(NPObject* aObject,
NPIdentifier aName)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return false;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectChild* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
bool success;
if (!actor->CallRemoveProperty((NPRemoteIdentifier)aName, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
return success;
}
// static
bool
PluginScriptableObjectChild::ScriptableEnumerate(NPObject* aObject,
NPIdentifier** aIdentifiers,
uint32_t* aCount)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return false;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectChild* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
nsAutoTArray<NPRemoteIdentifier, 10> identifiers;
bool success;
if (!actor->CallEnumerate(&identifiers, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
*aCount = identifiers.Length();
if (!*aCount) {
*aIdentifiers = nsnull;
return true;
}
*aIdentifiers = reinterpret_cast<NPIdentifier*>(
PluginModuleChild::sBrowserFuncs.memalloc(*aCount * sizeof(NPIdentifier)));
if (!*aIdentifiers) {
NS_ERROR("Out of memory!");
return false;
}
for (PRUint32 index = 0; index < *aCount; index++) {
*aIdentifiers[index] = (NPIdentifier)identifiers[index];
}
return true;
}
// static
bool
PluginScriptableObjectChild::ScriptableConstruct(NPObject* aObject,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult)
{
if (aObject->_class != PluginScriptableObjectChild::GetClass()) {
NS_ERROR("Don't know what kind of object this is!");
return false;
}
ChildNPObject* object = reinterpret_cast<ChildNPObject*>(aObject);
if (object->invalidated) {
NS_WARNING("Calling method on an invalidated object!");
return false;
}
PluginScriptableObjectChild* actor = object->parent;
NS_ASSERTION(actor, "This shouldn't ever be null!");
nsAutoTArray<Variant, 10> args;
if (!args.SetLength(aArgCount)) {
NS_ERROR("Out of memory?!");
return false;
}
for (PRUint32 index = 0; index < aArgCount; index++) {
Variant& arg = args[index];
if (!ConvertToRemoteVariant(aArgs[index], arg, actor->GetInstance())) {
NS_WARNING("Failed to convert argument!");
return false;
}
}
Variant remoteResult;
bool success;
if (!actor->CallConstruct(args, &remoteResult, &success)) {
NS_WARNING("Failed to send message!");
return false;
}
if (!success) {
return false;
}
ConvertToVariant(remoteResult, *aResult);
return true;
}
const NPClass PluginScriptableObjectChild::sNPClass = {
NP_CLASS_STRUCT_VERSION,
PluginScriptableObjectChild::ScriptableAllocate,
PluginScriptableObjectChild::ScriptableDeallocate,
PluginScriptableObjectChild::ScriptableInvalidate,
PluginScriptableObjectChild::ScriptableHasMethod,
PluginScriptableObjectChild::ScriptableInvoke,
PluginScriptableObjectChild::ScriptableInvokeDefault,
PluginScriptableObjectChild::ScriptableHasProperty,
PluginScriptableObjectChild::ScriptableGetProperty,
PluginScriptableObjectChild::ScriptableSetProperty,
PluginScriptableObjectChild::ScriptableRemoveProperty,
PluginScriptableObjectChild::ScriptableEnumerate,
PluginScriptableObjectChild::ScriptableConstruct
};
PluginScriptableObjectChild::PluginScriptableObjectChild()
: mInstance(nsnull),
mObject(nsnull)
@ -181,8 +617,16 @@ PluginScriptableObjectChild::PluginScriptableObjectChild()
PluginScriptableObjectChild::~PluginScriptableObjectChild()
{
if (mObject) {
if (mObject->_class == GetClass()) {
if (!static_cast<ChildNPObject*>(mObject)->invalidated) {
NS_WARNING("This should have happened already!");
ScriptableInvalidate(mObject);
}
}
else {
PluginModuleChild::sBrowserFuncs.releaseobject(mObject);
}
}
}
void
@ -190,14 +634,37 @@ PluginScriptableObjectChild::Initialize(PluginInstanceChild* aInstance,
NPObject* aObject)
{
NS_ASSERTION(!(mInstance && mObject), "Calling Initialize class twice!");
if (aObject->_class == GetClass()) {
ChildNPObject* object = static_cast<ChildNPObject*>(aObject);
NS_ASSERTION(!object->parent, "Bad object!");
object->parent = const_cast<PluginScriptableObjectChild*>(this);
// We don't want to have the actor own this object but rather let the object
// own this actor. Set the reference count to 0 here so that when the object
// dies we will send the destructor message to the parent.
NS_ASSERTION(aObject->referenceCount == 1, "Some kind of live object!");
aObject->referenceCount = 0;
}
else {
// Plugin-provided object, retain here. This should be the only reference we
// ever need.
PluginModuleChild::sBrowserFuncs.retainobject(aObject);
}
mInstance = aInstance;
mObject = PluginModuleChild::sBrowserFuncs.retainobject(aObject);
mObject = aObject;
}
bool
PluginScriptableObjectChild::AnswerInvalidate()
{
if (mObject) {
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (mObject->_class && mObject->_class->invalidate) {
mObject->_class->invalidate(mObject);
}
PluginModuleChild::sBrowserFuncs.releaseobject(mObject);
mObject = nsnull;
}
@ -209,11 +676,13 @@ PluginScriptableObjectChild::AnswerHasMethod(const NPRemoteIdentifier& aId,
bool* aHasMethod)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerHasMethod with an invalidated object!");
NS_WARNING("Calling AnswerHasMethod with an invalidated object!");
*aHasMethod = false;
return true;
}
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (!(mObject->_class && mObject->_class->hasMethod)) {
*aHasMethod = false;
return true;
@ -225,16 +694,18 @@ PluginScriptableObjectChild::AnswerHasMethod(const NPRemoteIdentifier& aId,
bool
PluginScriptableObjectChild::AnswerInvoke(const NPRemoteIdentifier& aId,
const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
const nsTArray<Variant>& aArgs,
Variant* aResult,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerInvoke with an invalidated object!");
NS_WARNING("Calling AnswerInvoke with an invalidated object!");
*aSuccess = false;
return true;
}
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (!(mObject->_class && mObject->_class->invoke)) {
*aSuccess = false;
return true;
@ -249,23 +720,29 @@ PluginScriptableObjectChild::AnswerInvoke(const NPRemoteIdentifier& aId,
}
for (PRUint32 index = 0; index < argCount; index++) {
if (!ConvertToVariant(aArgs[index], convertedArgs[index])) {
*aSuccess = false;
return true;
}
ConvertToVariant(aArgs[index], convertedArgs[index]);
}
NPVariant result;
bool success = mObject->_class->invoke(mObject, (NPIdentifier)aId,
convertedArgs.Elements(), argCount,
&result);
for (PRUint32 index = 0; index < argCount; index++) {
PluginModuleChild::sBrowserFuncs.releasevariantvalue(&convertedArgs[index]);
}
if (!success) {
*aSuccess = false;
return true;
}
NPRemoteVariant convertedResult;
if (!ConvertToRemoteVariant(result, convertedResult, mInstance)) {
Variant convertedResult;
success = ConvertToRemoteVariant(result, convertedResult, GetInstance());
PluginModuleChild::sBrowserFuncs.releasevariantvalue(&result);
if (!success) {
*aSuccess = false;
return true;
}
@ -276,16 +753,18 @@ PluginScriptableObjectChild::AnswerInvoke(const NPRemoteIdentifier& aId,
}
bool
PluginScriptableObjectChild::AnswerInvokeDefault(const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
PluginScriptableObjectChild::AnswerInvokeDefault(const nsTArray<Variant>& aArgs,
Variant* aResult,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerInvokeDefault with an invalidated object!");
NS_WARNING("Calling AnswerInvokeDefault with an invalidated object!");
*aSuccess = false;
return true;
}
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (!(mObject->_class && mObject->_class->invokeDefault)) {
*aSuccess = false;
return true;
@ -300,23 +779,29 @@ PluginScriptableObjectChild::AnswerInvokeDefault(const nsTArray<NPRemoteVariant>
}
for (PRUint32 index = 0; index < argCount; index++) {
if (!ConvertToVariant(aArgs[index], convertedArgs[index])) {
*aSuccess = false;
return true;
}
ConvertToVariant(aArgs[index], convertedArgs[index]);
}
NPVariant result;
bool success = mObject->_class->invokeDefault(mObject,
convertedArgs.Elements(),
argCount, &result);
for (PRUint32 index = 0; index < argCount; index++) {
PluginModuleChild::sBrowserFuncs.releasevariantvalue(&convertedArgs[index]);
}
if (!success) {
*aSuccess = false;
return true;
}
NPRemoteVariant convertedResult;
if (!ConvertToRemoteVariant(result, convertedResult, mInstance)) {
Variant convertedResult;
success = ConvertToRemoteVariant(result, convertedResult, GetInstance());
PluginModuleChild::sBrowserFuncs.releasevariantvalue(&result);
if (!success) {
*aSuccess = false;
return true;
}
@ -331,11 +816,13 @@ PluginScriptableObjectChild::AnswerHasProperty(const NPRemoteIdentifier& aId,
bool* aHasProperty)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerHasProperty with an invalidated object!");
NS_WARNING("Calling AnswerHasProperty with an invalidated object!");
*aHasProperty = false;
return true;
}
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (!(mObject->_class && mObject->_class->hasProperty)) {
*aHasProperty = false;
return true;
@ -347,15 +834,17 @@ PluginScriptableObjectChild::AnswerHasProperty(const NPRemoteIdentifier& aId,
bool
PluginScriptableObjectChild::AnswerGetProperty(const NPRemoteIdentifier& aId,
NPRemoteVariant* aResult,
Variant* aResult,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerGetProperty with an invalidated object!");
NS_WARNING("Calling AnswerGetProperty with an invalidated object!");
*aSuccess = false;
return true;
}
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (!(mObject->_class && mObject->_class->getProperty)) {
*aSuccess = false;
return true;
@ -367,8 +856,9 @@ PluginScriptableObjectChild::AnswerGetProperty(const NPRemoteIdentifier& aId,
return true;
}
NPRemoteVariant converted;
if ((*aSuccess = ConvertToRemoteVariant(result, converted, mInstance))) {
Variant converted;
if ((*aSuccess = ConvertToRemoteVariant(result, converted, GetInstance()))) {
PluginModuleChild::sBrowserFuncs.releasevariantvalue(&result);
*aResult = converted;
}
return true;
@ -376,28 +866,29 @@ PluginScriptableObjectChild::AnswerGetProperty(const NPRemoteIdentifier& aId,
bool
PluginScriptableObjectChild::AnswerSetProperty(const NPRemoteIdentifier& aId,
const NPRemoteVariant& aValue,
const Variant& aValue,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerSetProperty with an invalidated object!");
NS_WARNING("Calling AnswerSetProperty with an invalidated object!");
*aSuccess = false;
return true;
}
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (!(mObject->_class && mObject->_class->setProperty)) {
*aSuccess = false;
return true;
}
NPVariant converted;
if (!ConvertToVariant(aValue, converted)) {
*aSuccess = false;
return true;
}
ConvertToVariant(aValue, converted);
*aSuccess = mObject->_class->setProperty(mObject, (NPIdentifier)aId,
&converted);
if ((*aSuccess = mObject->_class->setProperty(mObject, (NPIdentifier)aId,
&converted))) {
PluginModuleChild::sBrowserFuncs.releasevariantvalue(&converted);
}
return true;
}
@ -406,11 +897,13 @@ PluginScriptableObjectChild::AnswerRemoveProperty(const NPRemoteIdentifier& aId,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerRemoveProperty with an invalidated object!");
NS_WARNING("Calling AnswerRemoveProperty with an invalidated object!");
*aSuccess = false;
return true;
}
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (!(mObject->_class && mObject->_class->removeProperty)) {
*aSuccess = false;
return true;
@ -425,11 +918,13 @@ PluginScriptableObjectChild::AnswerEnumerate(nsTArray<NPRemoteIdentifier>* aProp
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerEnumerate with an invalidated object!");
NS_WARNING("Calling AnswerEnumerate with an invalidated object!");
*aSuccess = false;
return true;
}
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (!(mObject->_class && mObject->_class->enumerate)) {
*aSuccess = false;
return true;
@ -462,16 +957,18 @@ PluginScriptableObjectChild::AnswerEnumerate(nsTArray<NPRemoteIdentifier>* aProp
}
bool
PluginScriptableObjectChild::AnswerConstruct(const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
PluginScriptableObjectChild::AnswerConstruct(const nsTArray<Variant>& aArgs,
Variant* aResult,
bool* aSuccess)
{
if (!mObject) {
NS_WARNING("Calling PluginScriptableObjectChild::AnswerConstruct with an invalidated object!");
NS_WARNING("Calling AnswerConstruct with an invalidated object!");
*aSuccess = false;
return true;
}
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
if (!(mObject->_class && mObject->_class->construct)) {
*aSuccess = false;
return true;
@ -486,22 +983,28 @@ PluginScriptableObjectChild::AnswerConstruct(const nsTArray<NPRemoteVariant>& aA
}
for (PRUint32 index = 0; index < argCount; index++) {
if (!ConvertToVariant(aArgs[index], convertedArgs[index])) {
*aSuccess = false;
return true;
}
ConvertToVariant(aArgs[index], convertedArgs[index]);
}
NPVariant result;
bool success = mObject->_class->construct(mObject, convertedArgs.Elements(),
argCount, &result);
for (PRUint32 index = 0; index < argCount; index++) {
PluginModuleChild::sBrowserFuncs.releasevariantvalue(&convertedArgs[index]);
}
if (!success) {
*aSuccess = false;
return true;
}
NPRemoteVariant convertedResult;
if (!ConvertToRemoteVariant(result, convertedResult, mInstance)) {
Variant convertedResult;
success = ConvertToRemoteVariant(result, convertedResult, GetInstance());
PluginModuleChild::sBrowserFuncs.releasevariantvalue(&result);
if (!success) {
*aSuccess = false;
return true;
}

Просмотреть файл

@ -41,15 +41,24 @@
#include "mozilla/plugins/PPluginScriptableObjectChild.h"
struct NPObject;
#include "npruntime.h"
namespace mozilla {
namespace plugins {
class PluginInstanceChild;
class PluginScriptableObjectChild;
struct ChildNPObject : NPObject
{
PluginScriptableObjectChild* parent;
bool invalidated;
};
class PluginScriptableObjectChild : public PPluginScriptableObjectChild
{
friend class PluginInstanceChild;
public:
PluginScriptableObjectChild();
virtual ~PluginScriptableObjectChild();
@ -63,13 +72,13 @@ public:
virtual bool
AnswerInvoke(const NPRemoteIdentifier& aId,
const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
const nsTArray<Variant>& aArgs,
Variant* aResult,
bool* aSuccess);
virtual bool
AnswerInvokeDefault(const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
AnswerInvokeDefault(const nsTArray<Variant>& aArgs,
Variant* aResult,
bool* aSuccess);
virtual bool
@ -78,12 +87,12 @@ public:
virtual bool
AnswerGetProperty(const NPRemoteIdentifier& aId,
NPRemoteVariant* aResult,
Variant* aResult,
bool* aSuccess);
virtual bool
AnswerSetProperty(const NPRemoteIdentifier& aId,
const NPRemoteVariant& aValue,
const Variant& aValue,
bool* aSuccess);
virtual bool
@ -95,8 +104,8 @@ public:
bool* aSuccess);
virtual bool
AnswerConstruct(const nsTArray<NPRemoteVariant>& aArgs,
NPRemoteVariant* aResult,
AnswerConstruct(const nsTArray<Variant>& aArgs,
Variant* aResult,
bool* aSuccess);
void
@ -109,9 +118,80 @@ public:
return mObject;
}
static const NPClass*
GetClass()
{
return &sNPClass;
}
PluginInstanceChild*
GetInstance()
{
return mInstance;
}
private:
static NPObject*
ScriptableAllocate(NPP aInstance,
NPClass* aClass);
static void
ScriptableInvalidate(NPObject* aObject);
static void
ScriptableDeallocate(NPObject* aObject);
static bool
ScriptableHasMethod(NPObject* aObject,
NPIdentifier aName);
static bool
ScriptableInvoke(NPObject* aObject,
NPIdentifier aName,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult);
static bool
ScriptableInvokeDefault(NPObject* aObject,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult);
static bool
ScriptableHasProperty(NPObject* aObject,
NPIdentifier aName);
static bool
ScriptableGetProperty(NPObject* aObject,
NPIdentifier aName,
NPVariant* aResult);
static bool
ScriptableSetProperty(NPObject* aObject,
NPIdentifier aName,
const NPVariant* aValue);
static bool
ScriptableRemoveProperty(NPObject* aObject,
NPIdentifier aName);
static bool
ScriptableEnumerate(NPObject* aObject,
NPIdentifier** aIdentifiers,
uint32_t* aCount);
static bool
ScriptableConstruct(NPObject* aObject,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult);
private:
PluginInstanceChild* mInstance;
NPObject* mObject;
static const NPClass sNPClass;
};
} /* namespace plugins */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -41,6 +41,7 @@
#include "mozilla/plugins/PPluginScriptableObjectParent.h"
#include "npfunctions.h"
#include "npruntime.h"
namespace mozilla {
@ -57,15 +58,62 @@ struct ParentNPObject : NPObject
class PluginScriptableObjectParent : public PPluginScriptableObjectParent
{
friend class PluginInstanceParent;
public:
PluginScriptableObjectParent();
virtual ~PluginScriptableObjectParent();
virtual bool
AnswerInvalidate();
virtual bool
AnswerHasMethod(const NPRemoteIdentifier& aId,
bool* aHasMethod);
virtual bool
AnswerInvoke(const NPRemoteIdentifier& aId,
const nsTArray<Variant>& aArgs,
Variant* aResult,
bool* aSuccess);
virtual bool
AnswerInvokeDefault(const nsTArray<Variant>& aArgs,
Variant* aResult,
bool* aSuccess);
virtual bool
AnswerHasProperty(const NPRemoteIdentifier& aId,
bool* aHasProperty);
virtual bool
AnswerGetProperty(const NPRemoteIdentifier& aId,
Variant* aResult,
bool* aSuccess);
virtual bool
AnswerSetProperty(const NPRemoteIdentifier& aId,
const Variant& aValue,
bool* aSuccess);
virtual bool
AnswerRemoveProperty(const NPRemoteIdentifier& aId,
bool* aSuccess);
virtual bool
AnswerEnumerate(nsTArray<NPRemoteIdentifier>* aProperties,
bool* aSuccess);
virtual bool
AnswerConstruct(const nsTArray<Variant>& aArgs,
Variant* aResult,
bool* aSuccess);
void
Initialize(PluginInstanceParent* aInstance,
ParentNPObject* aObject);
NPObject* aObject);
static NPClass*
static const NPClass*
GetClass()
{
return &sNPClass;
@ -84,10 +132,70 @@ public:
}
private:
PluginInstanceParent* mInstance;
ParentNPObject* mObject;
static NPObject*
ScriptableAllocate(NPP aInstance,
NPClass* aClass);
static NPClass sNPClass;
static void
ScriptableInvalidate(NPObject* aObject);
static void
ScriptableDeallocate(NPObject* aObject);
static bool
ScriptableHasMethod(NPObject* aObject,
NPIdentifier aName);
static bool
ScriptableInvoke(NPObject* aObject,
NPIdentifier aName,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult);
static bool
ScriptableInvokeDefault(NPObject* aObject,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult);
static bool
ScriptableHasProperty(NPObject* aObject,
NPIdentifier aName);
static bool
ScriptableGetProperty(NPObject* aObject,
NPIdentifier aName,
NPVariant* aResult);
static bool
ScriptableSetProperty(NPObject* aObject,
NPIdentifier aName,
const NPVariant* aValue);
static bool
ScriptableRemoveProperty(NPObject* aObject,
NPIdentifier aName);
static bool
ScriptableEnumerate(NPObject* aObject,
NPIdentifier** aIdentifiers,
uint32_t* aCount);
static bool
ScriptableConstruct(NPObject* aObject,
const NPVariant* aArgs,
uint32_t aArgCount,
NPVariant* aResult);
private:
PluginInstanceParent* mInstance;
// This may be a ParentNPObject or some other kind depending on who created
// it. Have to check its class to find out.
NPObject* mObject;
static const NPClass sNPClass;
};
} /* namespace plugins */

Просмотреть файл

@ -267,6 +267,8 @@ nsresult nsNPAPIPluginStreamListener::CleanUpStream(NPReason reason)
mInst->GetNPP(&npp);
if (mStreamStarted && callbacks->destroystream) {
NPPAutoPusher nppPusher(npp);
mozilla::SharedLibrary* lib = nsnull;
lib = mInst->mLibrary;
NPError error;
@ -356,6 +358,8 @@ nsNPAPIPluginStreamListener::OnStartBinding(nsIPluginStreamInfo* pluginInfo)
mStreamInfo = pluginInfo;
NPPAutoPusher nppPusher(npp);
NS_TRY_SAFE_CALL_RETURN(error, (*callbacks->newstream)(npp, (char*)contentType, &mNPStream, seekable, &streamType), mInst->mLibrary, mInst);
NPP_PLUGIN_LOG(PLUGIN_LOG_NORMAL,
@ -595,6 +599,8 @@ nsNPAPIPluginStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo,
while (mStreamBufferByteCount > 0) {
PRInt32 numtowrite;
if (callbacks->writeready) {
NPPAutoPusher nppPusher(npp);
NS_TRY_SAFE_CALL_RETURN(numtowrite, (*callbacks->writeready)(npp, &mNPStream), mInst->mLibrary, mInst);
NPP_PLUGIN_LOG(PLUGIN_LOG_NOISY,
("NPP WriteReady called: this=%p, npp=%p, "
@ -641,6 +647,8 @@ nsNPAPIPluginStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo,
numtowrite = mStreamBufferByteCount;
}
NPPAutoPusher nppPusher(npp);
PRInt32 writeCount = 0; // bytes consumed by plugin instance
NS_TRY_SAFE_CALL_RETURN(writeCount, (*callbacks->write)(npp, &mNPStream, streamPosition, numtowrite, ptrStreamBuffer), mInst->mLibrary, mInst);
@ -1191,6 +1199,10 @@ nsNPAPIPluginInstance::InitializePlugin()
PRBool oldVal = mInPluginInitCall;
mInPluginInitCall = PR_TRUE;
// Need this on the stack before calling NPP_New otherwise some callbacks that
// the plugin may make could fail (NPN_HasProperty, for example).
NPPAutoPusher autopush(&mNPP);
NS_TRY_SAFE_CALL_RETURN(error, (*mCallbacks->newp)((char*)mimetype, &mNPP, (PRUint16)mode, count, (char**)names, (char**)values, NULL), mLibrary,this);
mInPluginInitCall = oldVal;
@ -1245,6 +1257,8 @@ NS_IMETHODIMP nsNPAPIPluginInstance::SetWindow(NPWindow* window)
PRBool oldVal = mInPluginInitCall;
mInPluginInitCall = PR_TRUE;
NPPAutoPusher nppPusher(&mNPP);
NPError error;
NS_TRY_SAFE_CALL_RETURN(error, (*mCallbacks->setwindow)(&mNPP, (NPWindow*)window), mLibrary, this);