2009-10-07 22:49:30 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2009-06-30 11:51:05 -07:00
|
|
|
* vim: sw=4 ts=4 et :
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Plugin App.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
2009-08-10 16:28:22 -07:00
|
|
|
* Ben Turner <bent.mozilla@gmail.com>
|
2009-06-30 11:51:05 -07:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2009-09-23 00:12:52 -07:00
|
|
|
#include "PluginScriptableObjectParent.h"
|
|
|
|
#include "PluginInstanceParent.h"
|
|
|
|
#include "PluginModuleParent.h"
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-09-23 00:12:52 -07:00
|
|
|
#include "npapi.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
|
|
|
|
using namespace mozilla::plugins;
|
|
|
|
|
|
|
|
using mozilla::ipc::NPRemoteIdentifier;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
inline PluginInstanceParent*
|
|
|
|
GetInstance(NPObject* aObject)
|
|
|
|
{
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ASSERTION(aObject->_class == PluginScriptableObjectParent::GetClass(),
|
|
|
|
"Bad class!");
|
|
|
|
|
2009-09-23 00:12:52 -07:00
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
return object->parent->GetInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const NPNetscapeFuncs*
|
|
|
|
GetNetscapeFuncs(PluginInstanceParent* aInstance)
|
|
|
|
{
|
2009-10-27 12:51:12 -07:00
|
|
|
PluginModuleParent* module = aInstance->Module();
|
2009-09-23 00:12:52 -07:00
|
|
|
if (!module) {
|
|
|
|
NS_WARNING("Null module?!");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
return module->GetNetscapeFuncs();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const NPNetscapeFuncs*
|
|
|
|
GetNetscapeFuncs(NPObject* aObject)
|
|
|
|
{
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ASSERTION(aObject->_class == PluginScriptableObjectParent::GetClass(),
|
|
|
|
"Bad class!");
|
|
|
|
|
2009-09-23 00:12:52 -07:00
|
|
|
PluginInstanceParent* instance = GetInstance(aObject);
|
|
|
|
if (!instance) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2009-10-07 16:50:48 -07:00
|
|
|
|
2009-09-23 00:12:52 -07:00
|
|
|
return GetNetscapeFuncs(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NPObject*
|
2009-10-07 16:50:48 -07:00
|
|
|
NPObjectFromVariant(const Variant& aRemoteVariant) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_ASSERTION(aRemoteVariant.type() ==
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant::TPPluginScriptableObjectParent,
|
2009-09-23 00:12:52 -07:00
|
|
|
"Wrong variant type!");
|
|
|
|
PluginScriptableObjectParent* actor =
|
|
|
|
const_cast<PluginScriptableObjectParent*>(
|
|
|
|
reinterpret_cast<const PluginScriptableObjectParent*>(
|
|
|
|
aRemoteVariant.get_PPluginScriptableObjectParent()));
|
|
|
|
return actor->GetObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline NPObject*
|
|
|
|
NPObjectFromVariant(const NPVariant& aVariant) {
|
|
|
|
NS_ASSERTION(NPVARIANT_IS_OBJECT(aVariant), "Wrong variant type!");
|
|
|
|
return NPVARIANT_TO_OBJECT(aVariant);
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
inline void
|
|
|
|
ReleaseVariant(NPVariant& aVariant,
|
|
|
|
PluginInstanceParent* aInstance)
|
|
|
|
{
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(aInstance);
|
|
|
|
if (npn) {
|
|
|
|
npn->releasevariantvalue(&aVariant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-23 00:12:52 -07:00
|
|
|
inline bool
|
2009-10-07 16:50:48 -07:00
|
|
|
EnsureValidIdentifier(PluginInstanceParent* aInstance,
|
2009-09-23 00:12:52 -07:00
|
|
|
NPIdentifier aIdentifier)
|
|
|
|
{
|
2009-10-27 12:51:12 -07:00
|
|
|
PluginModuleParent* module = aInstance->Module();
|
2009-10-07 16:50:48 -07:00
|
|
|
if (!module) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_WARNING("Huh?!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
return module->EnsureValidNPIdentifier(aIdentifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
EnsureValidIdentifier(NPObject* aObject,
|
|
|
|
NPIdentifier aIdentifier)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* instance = GetInstance(aObject);
|
|
|
|
if (!instance) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_WARNING("Huh?!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
return EnsureValidIdentifier(instance, aIdentifier);
|
2009-09-23 00:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
ConvertToVariant(const Variant& aRemoteVariant,
|
|
|
|
NPVariant& aVariant,
|
|
|
|
PluginInstanceParent* aInstance)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
switch (aRemoteVariant.type()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
case Variant::Tvoid_t: {
|
2009-09-23 00:12:52 -07:00
|
|
|
VOID_TO_NPVARIANT(aVariant);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
case Variant::Tnull_t: {
|
2009-09-23 00:12:52 -07:00
|
|
|
NULL_TO_NPVARIANT(aVariant);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
case Variant::Tbool: {
|
2009-09-23 00:12:52 -07:00
|
|
|
BOOLEAN_TO_NPVARIANT(aRemoteVariant.get_bool(), aVariant);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
case Variant::Tint: {
|
2009-09-23 00:12:52 -07:00
|
|
|
INT32_TO_NPVARIANT(aRemoteVariant.get_int(), aVariant);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
case Variant::Tdouble: {
|
2009-09-23 00:12:52 -07:00
|
|
|
DOUBLE_TO_NPVARIANT(aRemoteVariant.get_double(), aVariant);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
case Variant::TnsCString: {
|
2009-09-23 00:12:52 -07:00
|
|
|
const nsCString& string = aRemoteVariant.get_nsCString();
|
|
|
|
NPUTF8* buffer = reinterpret_cast<NPUTF8*>(strdup(string.get()));
|
|
|
|
if (!buffer) {
|
|
|
|
NS_ERROR("Out of memory!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
STRINGN_TO_NPVARIANT(buffer, string.Length(), aVariant);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
case Variant::TPPluginScriptableObjectParent: {
|
2009-09-23 00:12:52 -07:00
|
|
|
NPObject* object = NPObjectFromVariant(aRemoteVariant);
|
|
|
|
if (!object) {
|
|
|
|
NS_ERROR("Er, this shouldn't fail!");
|
|
|
|
return false;
|
|
|
|
}
|
2009-10-07 16:50:48 -07:00
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(aInstance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("Null netscape funcs!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
npn->retainobject(object);
|
2009-09-23 00:12:52 -07:00
|
|
|
OBJECT_TO_NPVARIANT(object, aVariant);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Shouldn't get here!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ConvertToRemoteVariant(const NPVariant& aVariant,
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant& aRemoteVariant,
|
|
|
|
PluginInstanceParent* aInstance)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (NPVARIANT_IS_VOID(aVariant)) {
|
|
|
|
aRemoteVariant = mozilla::void_t();
|
|
|
|
}
|
|
|
|
else if (NPVARIANT_IS_NULL(aVariant)) {
|
|
|
|
aRemoteVariant = mozilla::null_t();
|
|
|
|
}
|
|
|
|
else if (NPVARIANT_IS_BOOLEAN(aVariant)) {
|
|
|
|
aRemoteVariant = NPVARIANT_TO_BOOLEAN(aVariant);
|
|
|
|
}
|
|
|
|
else if (NPVARIANT_IS_INT32(aVariant)) {
|
|
|
|
aRemoteVariant = NPVARIANT_TO_INT32(aVariant);
|
|
|
|
}
|
|
|
|
else if (NPVARIANT_IS_DOUBLE(aVariant)) {
|
|
|
|
aRemoteVariant = NPVARIANT_TO_DOUBLE(aVariant);
|
|
|
|
}
|
|
|
|
else if (NPVARIANT_IS_STRING(aVariant)) {
|
|
|
|
NPString str = NPVARIANT_TO_STRING(aVariant);
|
|
|
|
nsCString string(str.UTF8Characters, str.UTF8Length);
|
|
|
|
aRemoteVariant = string;
|
|
|
|
}
|
|
|
|
else if (NPVARIANT_IS_OBJECT(aVariant)) {
|
|
|
|
NPObject* object = NPVARIANT_TO_OBJECT(aVariant);
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent* actor = aInstance->GetActorForNPObject(object);
|
2009-09-23 00:12:52 -07:00
|
|
|
if (!actor) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Null actor!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aRemoteVariant = actor;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_NOTREACHED("Shouldn't get here!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
NPObject*
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableAllocate(NPP aInstance,
|
|
|
|
NPClass* aClass)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aClass == PluginScriptableObjectParent::GetClass(),
|
|
|
|
"Huh?! Wrong class!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = PluginModuleParent::InstCast(aInstance);
|
|
|
|
NS_ASSERTION(instance, "This should never be null!");
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_WARNING("Can't allocate!");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object =
|
|
|
|
reinterpret_cast<ParentNPObject*>(npn->memalloc(sizeof(ParentNPObject)));
|
|
|
|
if (object) {
|
|
|
|
memset(object, 0, sizeof(ParentNPObject));
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
void
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableInvalidate(NPObject* aObject)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
2009-10-07 16:50:48 -07:00
|
|
|
// This can happen more than once, and is just fine.
|
2009-09-23 00:12:52 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent* actor = object->parent;
|
|
|
|
NS_ASSERTION(actor, "Null actor?!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = actor->GetInstance();
|
|
|
|
NS_WARN_IF_FALSE(instance, "No instance?!");
|
|
|
|
|
|
|
|
if (!actor->CallInvalidate()) {
|
|
|
|
NS_WARNING("Failed to send message!");
|
2009-09-23 00:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
object->invalidated = true;
|
2009-10-07 16:50:48 -07:00
|
|
|
|
|
|
|
if (instance &&
|
|
|
|
!instance->CallPPluginScriptableObjectDestructor(actor)) {
|
|
|
|
NS_WARNING("Failed to send message!");
|
|
|
|
}
|
2009-09-23 00:12:52 -07:00
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
void
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableDeallocate(NPObject* aObject)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (!object->invalidated) {
|
|
|
|
ScriptableInvalidate(aObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(object->invalidated, "Should be invalidated!");
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_Free(aObject);
|
2009-09-23 00:12:52 -07:00
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableHasMethod(NPObject* aObject,
|
|
|
|
NPIdentifier aName)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(aObject, aName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginScriptableObjectParent* 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;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableInvoke(NPObject* aObject,
|
|
|
|
NPIdentifier aName,
|
|
|
|
const NPVariant* aArgs,
|
|
|
|
uint32_t aArgCount,
|
|
|
|
NPVariant* aResult)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(aObject, aName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginScriptableObjectParent* actor = object->parent;
|
|
|
|
NS_ASSERTION(actor, "This shouldn't ever be null!");
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
nsAutoTArray<Variant, 10> args;
|
2009-09-23 00:12:52 -07:00
|
|
|
if (!args.SetLength(aArgCount)) {
|
|
|
|
NS_ERROR("Out of memory?!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < aArgCount; index++) {
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant& arg = args[index];
|
|
|
|
if (!ConvertToRemoteVariant(aArgs[index], arg, actor->GetInstance())) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_WARNING("Failed to convert argument!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant remoteResult;
|
2009-09-23 00:12:52 -07:00
|
|
|
bool success;
|
|
|
|
if (!actor->CallInvoke((NPRemoteIdentifier)aName, args, &remoteResult,
|
|
|
|
&success)) {
|
|
|
|
NS_WARNING("Failed to send message!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
if (!ConvertToVariant(remoteResult, *aResult, actor->GetInstance())) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_WARNING("Failed to convert result!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableInvokeDefault(NPObject* aObject,
|
|
|
|
const NPVariant* aArgs,
|
|
|
|
uint32_t aArgCount,
|
|
|
|
NPVariant* aResult)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginScriptableObjectParent* actor = object->parent;
|
|
|
|
NS_ASSERTION(actor, "This shouldn't ever be null!");
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
nsAutoTArray<Variant, 10> args;
|
2009-09-23 00:12:52 -07:00
|
|
|
if (!args.SetLength(aArgCount)) {
|
|
|
|
NS_ERROR("Out of memory?!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < aArgCount; index++) {
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant& arg = args[index];
|
|
|
|
if (!ConvertToRemoteVariant(aArgs[index], arg, actor->GetInstance())) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_WARNING("Failed to convert argument!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant remoteResult;
|
2009-09-23 00:12:52 -07:00
|
|
|
bool success;
|
|
|
|
if (!actor->CallInvokeDefault(args, &remoteResult, &success)) {
|
|
|
|
NS_WARNING("Failed to send message!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
if (!ConvertToVariant(remoteResult, *aResult, actor->GetInstance())) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_WARNING("Failed to convert result!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableHasProperty(NPObject* aObject,
|
|
|
|
NPIdentifier aName)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(aObject, aName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginScriptableObjectParent* 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;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableGetProperty(NPObject* aObject,
|
|
|
|
NPIdentifier aName,
|
|
|
|
NPVariant* aResult)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(aObject, aName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginScriptableObjectParent* actor = object->parent;
|
|
|
|
NS_ASSERTION(actor, "This shouldn't ever be null!");
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant result;
|
2009-09-23 00:12:52 -07:00
|
|
|
bool success;
|
|
|
|
if (!actor->CallGetProperty((NPRemoteIdentifier)aName, &result, &success)) {
|
|
|
|
NS_WARNING("Failed to send message!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
if (!ConvertToVariant(result, *aResult, actor->GetInstance())) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_WARNING("Failed to convert result!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableSetProperty(NPObject* aObject,
|
|
|
|
NPIdentifier aName,
|
|
|
|
const NPVariant* aValue)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(aObject, aName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginScriptableObjectParent* actor = object->parent;
|
|
|
|
NS_ASSERTION(actor, "This shouldn't ever be null!");
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant value;
|
|
|
|
if (!ConvertToRemoteVariant(*aValue, value, actor->GetInstance())) {
|
2009-09-23 00:12:52 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableRemoveProperty(NPObject* aObject,
|
|
|
|
NPIdentifier aName)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(aObject, aName)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginScriptableObjectParent* 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;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableEnumerate(NPObject* aObject,
|
|
|
|
NPIdentifier** aIdentifiers,
|
|
|
|
uint32_t* aCount)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginScriptableObjectParent* actor = object->parent;
|
|
|
|
NS_ASSERTION(actor, "This shouldn't ever be null!");
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(aObject);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = (NPIdentifier*)npn->memalloc(*aCount * sizeof(NPIdentifier));
|
|
|
|
if (!*aIdentifiers) {
|
|
|
|
NS_ERROR("Out of memory!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < *aCount; index++) {
|
|
|
|
NPIdentifier& id = *aIdentifiers[index];
|
|
|
|
id = (NPIdentifier)identifiers[index];
|
|
|
|
if (!EnsureValidIdentifier(aObject, id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
// static
|
2009-09-23 00:12:52 -07:00
|
|
|
bool
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableConstruct(NPObject* aObject,
|
|
|
|
const NPVariant* aArgs,
|
|
|
|
uint32_t aArgCount,
|
|
|
|
NPVariant* aResult)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
if (aObject->_class != PluginScriptableObjectParent::GetClass()) {
|
2009-10-07 16:50:48 -07:00
|
|
|
NS_ERROR("Don't know what kind of object this is!");
|
2009-09-23 00:12:52 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
|
|
|
|
if (object->invalidated) {
|
|
|
|
NS_WARNING("Calling method on an invalidated object!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginScriptableObjectParent* actor = object->parent;
|
|
|
|
NS_ASSERTION(actor, "This shouldn't ever be null!");
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
nsAutoTArray<Variant, 10> args;
|
2009-09-23 00:12:52 -07:00
|
|
|
if (!args.SetLength(aArgCount)) {
|
|
|
|
NS_ERROR("Out of memory?!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < aArgCount; index++) {
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant& arg = args[index];
|
|
|
|
if (!ConvertToRemoteVariant(aArgs[index], arg, actor->GetInstance())) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_WARNING("Failed to convert argument!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
Variant remoteResult;
|
2009-09-23 00:12:52 -07:00
|
|
|
bool success;
|
|
|
|
if (!actor->CallConstruct(args, &remoteResult, &success)) {
|
|
|
|
NS_WARNING("Failed to send message!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
if (!ConvertToVariant(remoteResult, *aResult, actor->GetInstance())) {
|
2009-09-23 00:12:52 -07:00
|
|
|
NS_WARNING("Failed to convert result!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
const NPClass PluginScriptableObjectParent::sNPClass = {
|
2009-09-23 00:12:52 -07:00
|
|
|
NP_CLASS_STRUCT_VERSION,
|
2009-10-07 16:50:48 -07:00
|
|
|
PluginScriptableObjectParent::ScriptableAllocate,
|
|
|
|
PluginScriptableObjectParent::ScriptableDeallocate,
|
|
|
|
PluginScriptableObjectParent::ScriptableInvalidate,
|
|
|
|
PluginScriptableObjectParent::ScriptableHasMethod,
|
|
|
|
PluginScriptableObjectParent::ScriptableInvoke,
|
|
|
|
PluginScriptableObjectParent::ScriptableInvokeDefault,
|
|
|
|
PluginScriptableObjectParent::ScriptableHasProperty,
|
|
|
|
PluginScriptableObjectParent::ScriptableGetProperty,
|
|
|
|
PluginScriptableObjectParent::ScriptableSetProperty,
|
|
|
|
PluginScriptableObjectParent::ScriptableRemoveProperty,
|
|
|
|
PluginScriptableObjectParent::ScriptableEnumerate,
|
|
|
|
PluginScriptableObjectParent::ScriptableConstruct
|
2009-09-23 00:12:52 -07:00
|
|
|
};
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginScriptableObjectParent::PluginScriptableObjectParent()
|
2009-09-23 00:12:52 -07:00
|
|
|
: mInstance(nsnull),
|
|
|
|
mObject(nsnull)
|
2009-06-30 11:51:05 -07:00
|
|
|
{
|
2009-08-10 16:28:22 -07:00
|
|
|
}
|
2009-06-30 11:51:05 -07:00
|
|
|
|
2009-09-08 23:31:35 -07:00
|
|
|
PluginScriptableObjectParent::~PluginScriptableObjectParent()
|
2009-08-10 16:28:22 -07:00
|
|
|
{
|
2009-10-07 16:50:48 -07:00
|
|
|
if (mObject) {
|
|
|
|
if (mObject->_class == GetClass()) {
|
|
|
|
if (!static_cast<ParentNPObject*>(mObject)->invalidated) {
|
|
|
|
ScriptableInvalidate(mObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mInstance->GetNPNIface()->releaseobject(mObject);
|
|
|
|
}
|
2009-09-23 00:12:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PluginScriptableObjectParent::Initialize(PluginInstanceParent* aInstance,
|
2009-10-07 16:50:48 -07:00
|
|
|
NPObject* aObject)
|
2009-09-23 00:12:52 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aInstance && aObject, "Null pointers!");
|
|
|
|
NS_ASSERTION(!(mInstance && mObject), "Calling Initialize more than once!");
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
if (aObject->_class == GetClass()) {
|
|
|
|
ParentNPObject* object = static_cast<ParentNPObject*>(aObject);
|
|
|
|
|
|
|
|
NS_ASSERTION(!object->parent, "Bad object!");
|
|
|
|
object->parent = const_cast<PluginScriptableObjectParent*>(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 child.
|
|
|
|
NS_ASSERTION(aObject->referenceCount == 1, "Some kind of live object!");
|
|
|
|
object->referenceCount = 0;
|
2009-11-12 14:16:54 -08:00
|
|
|
NS_LOG_RELEASE(aObject, 0, "BrowserNPObject");
|
2009-10-07 16:50:48 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aInstance->GetNPNIface()->retainobject(aObject);
|
|
|
|
}
|
2009-09-23 00:12:52 -07:00
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
mInstance = aInstance;
|
2009-09-23 00:12:52 -07:00
|
|
|
mObject = aObject;
|
2009-10-07 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerInvalidate()
|
|
|
|
{
|
|
|
|
if (mObject) {
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(GetInstance());
|
|
|
|
if (npn) {
|
|
|
|
npn->releaseobject(mObject);
|
|
|
|
}
|
|
|
|
mObject = nsnull;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerHasMethod(const NPRemoteIdentifier& aId,
|
|
|
|
bool* aHasMethod)
|
|
|
|
{
|
|
|
|
if (!mObject) {
|
|
|
|
NS_WARNING("Calling AnswerHasMethod with an invalidated object!");
|
|
|
|
*aHasMethod = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
|
|
|
*aHasMethod = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs?!");
|
|
|
|
*aHasMethod = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(instance, (NPIdentifier)aId)) {
|
|
|
|
NS_WARNING("Invalid NPIdentifier!");
|
|
|
|
*aHasMethod = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aHasMethod = npn->hasmethod(instance->GetNPP(), mObject, (NPIdentifier)aId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerInvoke(const NPRemoteIdentifier& aId,
|
|
|
|
const nsTArray<Variant>& aArgs,
|
|
|
|
Variant* aResult,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
if (!mObject) {
|
|
|
|
NS_WARNING("Calling AnswerInvoke with an invalidated object!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs?!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(instance, (NPIdentifier)aId)) {
|
|
|
|
NS_WARNING("Invalid NPIdentifier!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<NPVariant, 10> convertedArgs;
|
|
|
|
PRUint32 argCount = aArgs.Length();
|
|
|
|
|
|
|
|
if (!convertedArgs.SetLength(argCount)) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < argCount; index++) {
|
|
|
|
if (!ConvertToVariant(aArgs[index], convertedArgs[index], instance)) {
|
|
|
|
// Don't leak things we've already converted!
|
|
|
|
while (index-- > 0) {
|
|
|
|
ReleaseVariant(convertedArgs[index], instance);
|
|
|
|
}
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NPVariant result;
|
|
|
|
bool success = npn->invoke(instance->GetNPP(), mObject, (NPIdentifier)aId,
|
|
|
|
convertedArgs.Elements(), argCount, &result);
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < argCount; index++) {
|
|
|
|
ReleaseVariant(convertedArgs[index], instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant convertedResult;
|
|
|
|
success = ConvertToRemoteVariant(result, convertedResult, GetInstance());
|
|
|
|
|
|
|
|
ReleaseVariant(result, instance);
|
|
|
|
|
|
|
|
if (!success) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = convertedResult;
|
2009-10-08 11:36:50 -07:00
|
|
|
*aSuccess = true;
|
2009-10-07 16:50:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerInvokeDefault(const nsTArray<Variant>& aArgs,
|
|
|
|
Variant* aResult,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
if (!mObject) {
|
|
|
|
NS_WARNING("Calling AnswerInvoke with an invalidated object!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs?!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<NPVariant, 10> convertedArgs;
|
|
|
|
PRUint32 argCount = aArgs.Length();
|
|
|
|
|
|
|
|
if (!convertedArgs.SetLength(argCount)) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < argCount; index++) {
|
|
|
|
if (!ConvertToVariant(aArgs[index], convertedArgs[index], instance)) {
|
|
|
|
// Don't leak things we've already converted!
|
|
|
|
while (index-- > 0) {
|
|
|
|
ReleaseVariant(convertedArgs[index], instance);
|
|
|
|
}
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NPVariant result;
|
|
|
|
bool success = npn->invokeDefault(instance->GetNPP(), mObject,
|
|
|
|
convertedArgs.Elements(), argCount,
|
|
|
|
&result);
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < argCount; index++) {
|
|
|
|
ReleaseVariant(convertedArgs[index], instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant convertedResult;
|
|
|
|
success = ConvertToRemoteVariant(result, convertedResult, GetInstance());
|
|
|
|
|
|
|
|
ReleaseVariant(result, instance);
|
|
|
|
|
|
|
|
if (!success) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = convertedResult;
|
2009-10-08 11:36:50 -07:00
|
|
|
*aSuccess = true;
|
2009-10-07 16:50:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerHasProperty(const NPRemoteIdentifier& aId,
|
|
|
|
bool* aHasProperty)
|
|
|
|
{
|
|
|
|
if (!mObject) {
|
|
|
|
NS_WARNING("Calling AnswerHasProperty with an invalidated object!");
|
|
|
|
*aHasProperty = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
|
|
|
*aHasProperty = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs?!");
|
|
|
|
*aHasProperty = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(instance, (NPIdentifier)aId)) {
|
|
|
|
NS_WARNING("Invalid NPIdentifier!");
|
|
|
|
*aHasProperty = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aHasProperty = npn->hasproperty(instance->GetNPP(), mObject,
|
|
|
|
(NPIdentifier)aId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerGetProperty(const NPRemoteIdentifier& aId,
|
|
|
|
Variant* aResult,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
if (!mObject) {
|
|
|
|
NS_WARNING("Calling AnswerGetProperty with an invalidated object!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs?!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(instance, (NPIdentifier)aId)) {
|
|
|
|
NS_WARNING("Invalid NPIdentifier!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPVariant result;
|
|
|
|
if (!npn->getproperty(instance->GetNPP(), mObject, (NPIdentifier)aId,
|
|
|
|
&result)) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant converted;
|
|
|
|
if ((*aSuccess = ConvertToRemoteVariant(result, converted, instance))) {
|
|
|
|
ReleaseVariant(result, instance);
|
|
|
|
*aResult = converted;
|
|
|
|
}
|
2009-10-08 11:45:20 -07:00
|
|
|
else {
|
|
|
|
*aResult = void_t();
|
|
|
|
}
|
|
|
|
|
2009-10-07 16:50:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerSetProperty(const NPRemoteIdentifier& aId,
|
|
|
|
const Variant& aValue,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
if (!mObject) {
|
|
|
|
NS_WARNING("Calling AnswerSetProperty with an invalidated object!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs?!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(instance, (NPIdentifier)aId)) {
|
|
|
|
NS_WARNING("Invalid NPIdentifier!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPVariant converted;
|
|
|
|
if (!ConvertToVariant(aValue, converted, instance)) {
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*aSuccess = npn->setproperty(instance->GetNPP(), mObject,
|
|
|
|
(NPIdentifier)aId, &converted))) {
|
|
|
|
ReleaseVariant(converted, instance);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerRemoveProperty(const NPRemoteIdentifier& aId,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
if (!mObject) {
|
|
|
|
NS_WARNING("Calling AnswerRemoveProperty with an invalidated object!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs?!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EnsureValidIdentifier(instance, (NPIdentifier)aId)) {
|
|
|
|
NS_WARNING("Invalid NPIdentifier!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSuccess = npn->removeproperty(instance->GetNPP(), mObject,
|
|
|
|
(NPIdentifier)aId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerEnumerate(nsTArray<NPRemoteIdentifier>* aProperties,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
if (!mObject) {
|
|
|
|
NS_WARNING("Calling AnswerEnumerate with an invalidated object!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_WARNING("No netscape funcs?!");
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPIdentifier* ids;
|
|
|
|
uint32_t idCount;
|
|
|
|
if (!npn->enumerate(instance->GetNPP(), mObject, &ids, &idCount)) {
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aProperties->SetCapacity(idCount)) {
|
|
|
|
npn->memfree(ids);
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < idCount; index++) {
|
|
|
|
NS_ASSERTION(EnsureValidIdentifier(instance, ids[index]),
|
|
|
|
"Identifier not yet in hashset!");
|
|
|
|
#ifdef DEBUG
|
|
|
|
NPRemoteIdentifier* remoteId =
|
|
|
|
#endif
|
|
|
|
aProperties->AppendElement((NPRemoteIdentifier)ids[index]);
|
|
|
|
NS_ASSERTION(remoteId, "Shouldn't fail if SetCapacity above succeeded!");
|
|
|
|
}
|
|
|
|
|
|
|
|
npn->memfree(ids);
|
|
|
|
*aSuccess = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerConstruct(const nsTArray<Variant>& aArgs,
|
|
|
|
Variant* aResult,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
if (!mObject) {
|
|
|
|
NS_WARNING("Calling AnswerConstruct with an invalidated object!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
|
|
|
|
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs?!");
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<NPVariant, 10> convertedArgs;
|
|
|
|
PRUint32 argCount = aArgs.Length();
|
|
|
|
|
|
|
|
if (!convertedArgs.SetLength(argCount)) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < argCount; index++) {
|
|
|
|
if (!ConvertToVariant(aArgs[index], convertedArgs[index], instance)) {
|
|
|
|
// Don't leak things we've already converted!
|
|
|
|
while (index-- > 0) {
|
|
|
|
ReleaseVariant(convertedArgs[index], instance);
|
|
|
|
}
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NPVariant result;
|
|
|
|
bool success = npn->construct(instance->GetNPP(), mObject,
|
|
|
|
convertedArgs.Elements(), argCount, &result);
|
|
|
|
|
|
|
|
for (PRUint32 index = 0; index < argCount; index++) {
|
|
|
|
ReleaseVariant(convertedArgs[index], instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!success) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant convertedResult;
|
|
|
|
success = ConvertToRemoteVariant(result, convertedResult, instance);
|
|
|
|
|
|
|
|
ReleaseVariant(result, instance);
|
|
|
|
|
|
|
|
if (!success) {
|
2009-10-08 11:36:50 -07:00
|
|
|
*aResult = void_t();
|
2009-10-07 16:50:48 -07:00
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSuccess = true;
|
|
|
|
*aResult = convertedResult;
|
|
|
|
return true;
|
2009-08-10 16:28:22 -07:00
|
|
|
}
|
2009-10-13 10:54:41 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
PluginScriptableObjectParent::AnswerNPN_Evaluate(const nsCString& aScript,
|
|
|
|
Variant* aResult,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
PluginInstanceParent* instance = GetInstance();
|
|
|
|
if (!instance) {
|
|
|
|
NS_ERROR("No instance?!");
|
|
|
|
*aResult = void_t();
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
|
|
|
|
if (!npn) {
|
|
|
|
NS_ERROR("No netscape funcs?!");
|
|
|
|
*aResult = void_t();
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NPString script = { aScript.get(), aScript.Length() };
|
|
|
|
|
|
|
|
NPVariant result;
|
|
|
|
bool success = npn->evaluate(instance->GetNPP(), mObject, &script, &result);
|
|
|
|
if (!success) {
|
|
|
|
*aResult = void_t();
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant convertedResult;
|
|
|
|
success = ConvertToRemoteVariant(result, convertedResult, instance);
|
|
|
|
|
|
|
|
ReleaseVariant(result, instance);
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
*aResult = void_t();
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSuccess = true;
|
|
|
|
*aResult = convertedResult;
|
|
|
|
return true;
|
|
|
|
}
|