1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "PluginScriptableObjectParent.h"
9 #include "mozilla/DebugOnly.h"
10 #include "mozilla/plugins/PluginIdentifierParent.h"
11 #include "mozilla/unused.h"
12 #include "nsNPAPIPlugin.h"
13 #include "PluginScriptableObjectUtils.h"
15 using namespace mozilla::plugins
;
16 using namespace mozilla::plugins::parent
;
21 ReleaseVariant(NPVariant
& aVariant
,
22 PluginInstanceParent
* aInstance
)
24 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(aInstance
);
26 npn
->releasevariantvalue(&aVariant
);
30 } // anonymous namespace
34 PluginScriptableObjectParent::ScriptableAllocate(NPP aInstance
,
37 if (aClass
!= GetClass()) {
38 NS_ERROR("Huh?! Wrong class!");
42 return new ParentNPObject();
47 PluginScriptableObjectParent::ScriptableInvalidate(NPObject
* aObject
)
49 if (aObject
->_class
!= GetClass()) {
50 NS_ERROR("Don't know what kind of object this is!");
54 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
55 if (object
->invalidated
) {
56 // This can happen more than once, and is just fine.
60 object
->invalidated
= true;
62 // |object->parent| may be null already if the instance has gone away.
63 if (object
->parent
&& !object
->parent
->CallInvalidate()) {
64 NS_ERROR("Failed to send message!");
70 PluginScriptableObjectParent::ScriptableDeallocate(NPObject
* aObject
)
72 if (aObject
->_class
!= GetClass()) {
73 NS_ERROR("Don't know what kind of object this is!");
77 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
78 PluginScriptableObjectParent
* actor
= object
->parent
;
80 NS_ASSERTION(actor
->Type() == Proxy
, "Bad type!");
81 actor
->DropNPObject();
89 PluginScriptableObjectParent::ScriptableHasMethod(NPObject
* aObject
,
92 if (aObject
->_class
!= GetClass()) {
93 NS_ERROR("Don't know what kind of object this is!");
97 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
98 if (object
->invalidated
) {
99 NS_WARNING("Calling method on an invalidated object!");
103 ProtectedActor
<PluginScriptableObjectParent
> actor(object
->parent
);
108 PluginIdentifierParent::StackIdentifier
identifier(aObject
, aName
);
113 NS_ASSERTION(actor
->Type() == Proxy
, "Bad type!");
116 if (!actor
->CallHasMethod(identifier
, &result
)) {
117 NS_WARNING("Failed to send message!");
126 PluginScriptableObjectParent::ScriptableInvoke(NPObject
* aObject
,
128 const NPVariant
* aArgs
,
132 if (aObject
->_class
!= GetClass()) {
133 NS_ERROR("Don't know what kind of object this is!");
137 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
138 if (object
->invalidated
) {
139 NS_WARNING("Calling method on an invalidated object!");
143 ProtectedActor
<PluginScriptableObjectParent
> actor(object
->parent
);
148 PluginIdentifierParent::StackIdentifier
identifier(aObject
, aName
);
153 NS_ASSERTION(actor
->Type() == Proxy
, "Bad type!");
155 ProtectedVariantArray
args(aArgs
, aArgCount
, actor
->GetInstance());
157 NS_ERROR("Failed to convert arguments!");
161 Variant remoteResult
;
163 if (!actor
->CallInvoke(identifier
, args
, &remoteResult
,
165 NS_WARNING("Failed to send message!");
173 if (!ConvertToVariant(remoteResult
, *aResult
, actor
->GetInstance())) {
174 NS_WARNING("Failed to convert result!");
182 PluginScriptableObjectParent::ScriptableInvokeDefault(NPObject
* aObject
,
183 const NPVariant
* aArgs
,
187 if (aObject
->_class
!= GetClass()) {
188 NS_ERROR("Don't know what kind of object this is!");
192 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
193 if (object
->invalidated
) {
194 NS_WARNING("Calling method on an invalidated object!");
198 ProtectedActor
<PluginScriptableObjectParent
> actor(object
->parent
);
203 NS_ASSERTION(actor
->Type() == Proxy
, "Bad type!");
205 ProtectedVariantArray
args(aArgs
, aArgCount
, actor
->GetInstance());
207 NS_ERROR("Failed to convert arguments!");
211 Variant remoteResult
;
213 if (!actor
->CallInvokeDefault(args
, &remoteResult
, &success
)) {
214 NS_WARNING("Failed to send message!");
222 if (!ConvertToVariant(remoteResult
, *aResult
, actor
->GetInstance())) {
223 NS_WARNING("Failed to convert result!");
231 PluginScriptableObjectParent::ScriptableHasProperty(NPObject
* aObject
,
234 if (aObject
->_class
!= GetClass()) {
235 NS_ERROR("Don't know what kind of object this is!");
239 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
240 if (object
->invalidated
) {
241 NS_WARNING("Calling method on an invalidated object!");
245 ProtectedActor
<PluginScriptableObjectParent
> actor(object
->parent
);
250 PluginIdentifierParent::StackIdentifier
identifier(aObject
, aName
);
255 NS_ASSERTION(actor
->Type() == Proxy
, "Bad type!");
258 if (!actor
->CallHasProperty(identifier
, &result
)) {
259 NS_WARNING("Failed to send message!");
268 PluginScriptableObjectParent::ScriptableGetProperty(NPObject
* aObject
,
272 // See GetPropertyHelper below.
273 NS_NOTREACHED("Shouldn't ever call this directly!");
279 PluginScriptableObjectParent::ScriptableSetProperty(NPObject
* aObject
,
281 const NPVariant
* aValue
)
283 if (aObject
->_class
!= GetClass()) {
284 NS_ERROR("Don't know what kind of object this is!");
288 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
289 if (object
->invalidated
) {
290 NS_WARNING("Calling method on an invalidated object!");
294 ProtectedActor
<PluginScriptableObjectParent
> actor(object
->parent
);
299 PluginIdentifierParent::StackIdentifier
identifier(aObject
, aName
);
304 NS_ASSERTION(actor
->Type() == Proxy
, "Bad type!");
306 ProtectedVariant
value(*aValue
, actor
->GetInstance());
308 NS_WARNING("Failed to convert variant!");
313 if (!actor
->CallSetProperty(identifier
, value
, &success
)) {
314 NS_WARNING("Failed to send message!");
323 PluginScriptableObjectParent::ScriptableRemoveProperty(NPObject
* aObject
,
326 if (aObject
->_class
!= GetClass()) {
327 NS_ERROR("Don't know what kind of object this is!");
331 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
332 if (object
->invalidated
) {
333 NS_WARNING("Calling method on an invalidated object!");
337 ProtectedActor
<PluginScriptableObjectParent
> actor(object
->parent
);
342 PluginIdentifierParent::StackIdentifier
identifier(aObject
, aName
);
347 NS_ASSERTION(actor
->Type() == Proxy
, "Bad type!");
350 if (!actor
->CallRemoveProperty(identifier
, &success
)) {
351 NS_WARNING("Failed to send message!");
360 PluginScriptableObjectParent::ScriptableEnumerate(NPObject
* aObject
,
361 NPIdentifier
** aIdentifiers
,
364 if (aObject
->_class
!= GetClass()) {
365 NS_ERROR("Don't know what kind of object this is!");
369 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
370 if (object
->invalidated
) {
371 NS_WARNING("Calling method on an invalidated object!");
375 ProtectedActor
<PluginScriptableObjectParent
> actor(object
->parent
);
380 NS_ASSERTION(actor
->Type() == Proxy
, "Bad type!");
382 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(aObject
);
384 NS_ERROR("No netscape funcs!");
388 AutoInfallibleTArray
<PPluginIdentifierParent
*, 10> identifiers
;
390 if (!actor
->CallEnumerate(&identifiers
, &success
)) {
391 NS_WARNING("Failed to send message!");
399 *aCount
= identifiers
.Length();
401 *aIdentifiers
= nullptr;
405 *aIdentifiers
= (NPIdentifier
*)npn
->memalloc(*aCount
* sizeof(NPIdentifier
));
406 if (!*aIdentifiers
) {
407 NS_ERROR("Out of memory!");
411 for (uint32_t index
= 0; index
< *aCount
; index
++) {
412 PluginIdentifierParent
* id
=
413 static_cast<PluginIdentifierParent
*>(identifiers
[index
]);
414 (*aIdentifiers
)[index
] = id
->ToNPIdentifier();
421 PluginScriptableObjectParent::ScriptableConstruct(NPObject
* aObject
,
422 const NPVariant
* aArgs
,
426 if (aObject
->_class
!= GetClass()) {
427 NS_ERROR("Don't know what kind of object this is!");
431 ParentNPObject
* object
= reinterpret_cast<ParentNPObject
*>(aObject
);
432 if (object
->invalidated
) {
433 NS_WARNING("Calling method on an invalidated object!");
437 ProtectedActor
<PluginScriptableObjectParent
> actor(object
->parent
);
442 NS_ASSERTION(actor
->Type() == Proxy
, "Bad type!");
444 ProtectedVariantArray
args(aArgs
, aArgCount
, actor
->GetInstance());
446 NS_ERROR("Failed to convert arguments!");
450 Variant remoteResult
;
452 if (!actor
->CallConstruct(args
, &remoteResult
, &success
)) {
453 NS_WARNING("Failed to send message!");
461 if (!ConvertToVariant(remoteResult
, *aResult
, actor
->GetInstance())) {
462 NS_WARNING("Failed to convert result!");
468 const NPClass
PluginScriptableObjectParent::sNPClass
= {
469 NP_CLASS_STRUCT_VERSION
,
470 PluginScriptableObjectParent::ScriptableAllocate
,
471 PluginScriptableObjectParent::ScriptableDeallocate
,
472 PluginScriptableObjectParent::ScriptableInvalidate
,
473 PluginScriptableObjectParent::ScriptableHasMethod
,
474 PluginScriptableObjectParent::ScriptableInvoke
,
475 PluginScriptableObjectParent::ScriptableInvokeDefault
,
476 PluginScriptableObjectParent::ScriptableHasProperty
,
477 PluginScriptableObjectParent::ScriptableGetProperty
,
478 PluginScriptableObjectParent::ScriptableSetProperty
,
479 PluginScriptableObjectParent::ScriptableRemoveProperty
,
480 PluginScriptableObjectParent::ScriptableEnumerate
,
481 PluginScriptableObjectParent::ScriptableConstruct
484 PluginScriptableObjectParent::PluginScriptableObjectParent(
485 ScriptableObjectType aType
)
486 : mInstance(nullptr),
493 PluginScriptableObjectParent::~PluginScriptableObjectParent()
496 if (mObject
->_class
== GetClass()) {
497 NS_ASSERTION(mType
== Proxy
, "Wrong type!");
498 static_cast<ParentNPObject
*>(mObject
)->parent
= nullptr;
501 NS_ASSERTION(mType
== LocalObject
, "Wrong type!");
502 GetInstance()->GetNPNIface()->releaseobject(mObject
);
508 PluginScriptableObjectParent::InitializeProxy()
510 NS_ASSERTION(mType
== Proxy
, "Bad type!");
511 NS_ASSERTION(!mObject
, "Calling Initialize more than once!");
513 mInstance
= static_cast<PluginInstanceParent
*>(Manager());
514 NS_ASSERTION(mInstance
, "Null manager?!");
516 NPObject
* object
= CreateProxyObject();
517 NS_ASSERTION(object
, "Failed to create object!");
519 if (!mInstance
->RegisterNPObjectForActor(object
, this)) {
520 NS_ERROR("Out of memory?");
527 PluginScriptableObjectParent::InitializeLocal(NPObject
* aObject
)
529 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
530 NS_ASSERTION(!(mInstance
&& mObject
), "Calling Initialize more than once!");
532 mInstance
= static_cast<PluginInstanceParent
*>(Manager());
533 NS_ASSERTION(mInstance
, "Null manager?!");
535 mInstance
->GetNPNIface()->retainobject(aObject
);
537 NS_ASSERTION(!mProtectCount
, "Should be zero!");
540 if (!mInstance
->RegisterNPObjectForActor(aObject
, this)) {
541 NS_ERROR("Out of memory?");
548 PluginScriptableObjectParent::CreateProxyObject()
550 NS_ASSERTION(mInstance
, "Must have an instance!");
551 NS_ASSERTION(mType
== Proxy
, "Shouldn't call this for non-proxy object!");
553 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(mInstance
);
555 NPObject
* npobject
= npn
->createobject(mInstance
->GetNPP(),
556 const_cast<NPClass
*>(GetClass()));
557 NS_ASSERTION(npobject
, "Failed to create object?!");
558 NS_ASSERTION(npobject
->_class
== GetClass(), "Wrong kind of object!");
559 NS_ASSERTION(npobject
->referenceCount
== 1, "Some kind of live object!");
561 ParentNPObject
* object
= static_cast<ParentNPObject
*>(npobject
);
562 NS_ASSERTION(!object
->invalidated
, "Bad object!");
563 NS_ASSERTION(!object
->parent
, "Bad object!");
565 // We don't want to have the actor own this object but rather let the object
566 // own this actor. Set the reference count to 0 here so that when the object
567 // dies we will send the destructor message to the child.
568 object
->referenceCount
= 0;
569 NS_LOG_RELEASE(object
, 0, "BrowserNPObject");
571 object
->parent
= const_cast<PluginScriptableObjectParent
*>(this);
576 PluginScriptableObjectParent::ResurrectProxyObject()
578 NS_ASSERTION(mInstance
, "Must have an instance already!");
579 NS_ASSERTION(!mObject
, "Should not have an object already!");
580 NS_ASSERTION(mType
== Proxy
, "Shouldn't call this for non-proxy object!");
583 NS_ASSERTION(mObject
, "Initialize failed!");
585 if (!SendProtect()) {
586 NS_WARNING("Failed to send message!");
594 PluginScriptableObjectParent::GetObject(bool aCanResurrect
)
596 if (!mObject
&& aCanResurrect
&& !ResurrectProxyObject()) {
597 NS_ERROR("Null object!");
604 PluginScriptableObjectParent::Protect()
606 NS_ASSERTION(mObject
, "No object!");
607 NS_ASSERTION(mProtectCount
>= 0, "Negative protect count?!");
609 if (mType
== LocalObject
) {
615 PluginScriptableObjectParent::Unprotect()
617 NS_ASSERTION(mObject
, "No object!");
618 NS_ASSERTION(mProtectCount
>= 0, "Negative protect count?!");
620 if (mType
== LocalObject
) {
621 if (--mProtectCount
== 0) {
622 unused
<< PluginScriptableObjectParent::Send__delete__(this);
628 PluginScriptableObjectParent::DropNPObject()
630 NS_ASSERTION(mObject
, "Invalidated object!");
631 NS_ASSERTION(mObject
->_class
== GetClass(), "Wrong type of object!");
632 NS_ASSERTION(mType
== Proxy
, "Shouldn't call this for non-proxy object!");
634 // We think we're about to be deleted, but we could be racing with the other
636 PluginInstanceParent
* instance
= GetInstance();
637 NS_ASSERTION(instance
, "Must have an instance!");
639 instance
->UnregisterNPObject(mObject
);
642 unused
<< SendUnprotect();
646 PluginScriptableObjectParent::ActorDestroy(ActorDestroyReason aWhy
)
648 // Implement me! Bug 1005163
652 PluginScriptableObjectParent::AnswerHasMethod(PPluginIdentifierParent
* aId
,
656 NS_WARNING("Calling AnswerHasMethod with an invalidated object!");
661 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
662 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
664 PluginInstanceParent
* instance
= GetInstance();
666 NS_ERROR("No instance?!");
671 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
673 NS_ERROR("No netscape funcs?!");
678 PluginIdentifierParent
* id
= static_cast<PluginIdentifierParent
*>(aId
);
679 *aHasMethod
= npn
->hasmethod(instance
->GetNPP(), mObject
, id
->ToNPIdentifier());
684 PluginScriptableObjectParent::AnswerInvoke(PPluginIdentifierParent
* aId
,
685 const InfallibleTArray
<Variant
>& aArgs
,
690 NS_WARNING("Calling AnswerInvoke with an invalidated object!");
696 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
697 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
699 PluginInstanceParent
* instance
= GetInstance();
701 NS_ERROR("No instance?!");
707 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
709 NS_ERROR("No netscape funcs?!");
715 AutoFallibleTArray
<NPVariant
, 10> convertedArgs
;
716 uint32_t argCount
= aArgs
.Length();
718 if (!convertedArgs
.SetLength(argCount
)) {
724 for (uint32_t index
= 0; index
< argCount
; index
++) {
725 if (!ConvertToVariant(aArgs
[index
], convertedArgs
[index
], instance
)) {
726 // Don't leak things we've already converted!
727 while (index
-- > 0) {
728 ReleaseVariant(convertedArgs
[index
], instance
);
736 PluginIdentifierParent
* id
= static_cast<PluginIdentifierParent
*>(aId
);
738 bool success
= npn
->invoke(instance
->GetNPP(), mObject
, id
->ToNPIdentifier(),
739 convertedArgs
.Elements(), argCount
, &result
);
741 for (uint32_t index
= 0; index
< argCount
; index
++) {
742 ReleaseVariant(convertedArgs
[index
], instance
);
751 Variant convertedResult
;
752 success
= ConvertToRemoteVariant(result
, convertedResult
, GetInstance());
754 DeferNPVariantLastRelease(npn
, &result
);
762 *aResult
= convertedResult
;
768 PluginScriptableObjectParent::AnswerInvokeDefault(const InfallibleTArray
<Variant
>& aArgs
,
773 NS_WARNING("Calling AnswerInvoke with an invalidated object!");
779 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
780 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
782 PluginInstanceParent
* instance
= GetInstance();
784 NS_ERROR("No instance?!");
790 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
792 NS_ERROR("No netscape funcs?!");
798 AutoFallibleTArray
<NPVariant
, 10> convertedArgs
;
799 uint32_t argCount
= aArgs
.Length();
801 if (!convertedArgs
.SetLength(argCount
)) {
807 for (uint32_t index
= 0; index
< argCount
; index
++) {
808 if (!ConvertToVariant(aArgs
[index
], convertedArgs
[index
], instance
)) {
809 // Don't leak things we've already converted!
810 while (index
-- > 0) {
811 ReleaseVariant(convertedArgs
[index
], instance
);
820 bool success
= npn
->invokeDefault(instance
->GetNPP(), mObject
,
821 convertedArgs
.Elements(), argCount
,
824 for (uint32_t index
= 0; index
< argCount
; index
++) {
825 ReleaseVariant(convertedArgs
[index
], instance
);
834 Variant convertedResult
;
835 success
= ConvertToRemoteVariant(result
, convertedResult
, GetInstance());
837 DeferNPVariantLastRelease(npn
, &result
);
845 *aResult
= convertedResult
;
851 PluginScriptableObjectParent::AnswerHasProperty(PPluginIdentifierParent
* aId
,
855 NS_WARNING("Calling AnswerHasProperty with an invalidated object!");
856 *aHasProperty
= false;
860 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
861 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
863 PluginInstanceParent
* instance
= GetInstance();
865 NS_ERROR("No instance?!");
866 *aHasProperty
= false;
870 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
872 NS_ERROR("No netscape funcs?!");
873 *aHasProperty
= false;
877 PluginIdentifierParent
* id
= static_cast<PluginIdentifierParent
*>(aId
);
878 *aHasProperty
= npn
->hasproperty(instance
->GetNPP(), mObject
,
879 id
->ToNPIdentifier());
884 PluginScriptableObjectParent::AnswerGetParentProperty(
885 PPluginIdentifierParent
* aId
,
890 NS_WARNING("Calling AnswerGetProperty with an invalidated object!");
896 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
897 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
899 PluginInstanceParent
* instance
= GetInstance();
901 NS_ERROR("No instance?!");
907 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
909 NS_ERROR("No netscape funcs?!");
915 PluginIdentifierParent
* id
= static_cast<PluginIdentifierParent
*>(aId
);
917 if (!npn
->getproperty(instance
->GetNPP(), mObject
, id
->ToNPIdentifier(),
925 if ((*aSuccess
= ConvertToRemoteVariant(result
, converted
, instance
))) {
926 DeferNPVariantLastRelease(npn
, &result
);
927 *aResult
= converted
;
937 PluginScriptableObjectParent::AnswerSetProperty(PPluginIdentifierParent
* aId
,
938 const Variant
& aValue
,
942 NS_WARNING("Calling AnswerSetProperty with an invalidated object!");
947 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
948 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
950 PluginInstanceParent
* instance
= GetInstance();
952 NS_ERROR("No instance?!");
957 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
959 NS_ERROR("No netscape funcs?!");
965 if (!ConvertToVariant(aValue
, converted
, instance
)) {
970 PluginIdentifierParent
* id
= static_cast<PluginIdentifierParent
*>(aId
);
971 if ((*aSuccess
= npn
->setproperty(instance
->GetNPP(), mObject
,
972 id
->ToNPIdentifier(), &converted
))) {
973 ReleaseVariant(converted
, instance
);
979 PluginScriptableObjectParent::AnswerRemoveProperty(PPluginIdentifierParent
* aId
,
983 NS_WARNING("Calling AnswerRemoveProperty with an invalidated object!");
988 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
989 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
991 PluginInstanceParent
* instance
= GetInstance();
993 NS_ERROR("No instance?!");
998 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
1000 NS_ERROR("No netscape funcs?!");
1005 PluginIdentifierParent
* id
= static_cast<PluginIdentifierParent
*>(aId
);
1006 *aSuccess
= npn
->removeproperty(instance
->GetNPP(), mObject
,
1007 id
->ToNPIdentifier());
1012 PluginScriptableObjectParent::AnswerEnumerate(InfallibleTArray
<PPluginIdentifierParent
*>* aProperties
,
1016 NS_WARNING("Calling AnswerEnumerate with an invalidated object!");
1021 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
1022 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
1024 PluginInstanceParent
* instance
= GetInstance();
1026 NS_ERROR("No instance?!");
1031 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
1033 NS_WARNING("No netscape funcs?!");
1040 if (!npn
->enumerate(instance
->GetNPP(), mObject
, &ids
, &idCount
)) {
1045 aProperties
->SetCapacity(idCount
);
1047 mozilla::AutoSafeJSContext cx
;
1048 for (uint32_t index
= 0; index
< idCount
; index
++) {
1049 // Because of GC hazards, all identifiers returned from enumerate
1050 // must be made permanent.
1051 if (_identifierisstring(ids
[index
])) {
1052 JS::Rooted
<JSString
*> str(cx
, NPIdentifierToString(ids
[index
]));
1053 if (!JS_StringHasBeenInterned(cx
, str
)) {
1054 DebugOnly
<JSString
*> str2
= JS_InternJSString(cx
, str
);
1055 NS_ASSERTION(str2
== str
, "Interning a JS string which is currently an ID should return itself.");
1058 PluginIdentifierParent
* id
=
1059 instance
->Module()->GetIdentifierForNPIdentifier(instance
->GetNPP(), ids
[index
]);
1060 aProperties
->AppendElement(id
);
1061 NS_ASSERTION(!id
->IsTemporary(), "Should only have permanent identifiers!");
1070 PluginScriptableObjectParent::AnswerConstruct(const InfallibleTArray
<Variant
>& aArgs
,
1075 NS_WARNING("Calling AnswerConstruct with an invalidated object!");
1076 *aResult
= void_t();
1081 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
1082 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
1084 PluginInstanceParent
* instance
= GetInstance();
1086 NS_ERROR("No instance?!");
1087 *aResult
= void_t();
1092 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
1094 NS_ERROR("No netscape funcs?!");
1095 *aResult
= void_t();
1100 AutoFallibleTArray
<NPVariant
, 10> convertedArgs
;
1101 uint32_t argCount
= aArgs
.Length();
1103 if (!convertedArgs
.SetLength(argCount
)) {
1104 *aResult
= void_t();
1109 for (uint32_t index
= 0; index
< argCount
; index
++) {
1110 if (!ConvertToVariant(aArgs
[index
], convertedArgs
[index
], instance
)) {
1111 // Don't leak things we've already converted!
1112 while (index
-- > 0) {
1113 ReleaseVariant(convertedArgs
[index
], instance
);
1115 *aResult
= void_t();
1122 bool success
= npn
->construct(instance
->GetNPP(), mObject
,
1123 convertedArgs
.Elements(), argCount
, &result
);
1125 for (uint32_t index
= 0; index
< argCount
; index
++) {
1126 ReleaseVariant(convertedArgs
[index
], instance
);
1130 *aResult
= void_t();
1135 Variant convertedResult
;
1136 success
= ConvertToRemoteVariant(result
, convertedResult
, instance
);
1138 DeferNPVariantLastRelease(npn
, &result
);
1141 *aResult
= void_t();
1147 *aResult
= convertedResult
;
1152 PluginScriptableObjectParent::RecvProtect()
1154 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
1155 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
1162 PluginScriptableObjectParent::RecvUnprotect()
1164 NS_ASSERTION(mObject
->_class
!= GetClass(), "Bad object type!");
1165 NS_ASSERTION(mType
== LocalObject
, "Bad type!");
1172 PluginScriptableObjectParent::AnswerNPN_Evaluate(const nsCString
& aScript
,
1176 PluginInstanceParent
* instance
= GetInstance();
1178 NS_ERROR("No instance?!");
1179 *aResult
= void_t();
1184 const NPNetscapeFuncs
* npn
= GetNetscapeFuncs(instance
);
1186 NS_ERROR("No netscape funcs?!");
1187 *aResult
= void_t();
1192 NPString script
= { aScript
.get(), aScript
.Length() };
1195 bool success
= npn
->evaluate(instance
->GetNPP(), mObject
, &script
, &result
);
1197 *aResult
= void_t();
1202 Variant convertedResult
;
1203 success
= ConvertToRemoteVariant(result
, convertedResult
, instance
);
1205 DeferNPVariantLastRelease(npn
, &result
);
1208 *aResult
= void_t();
1214 *aResult
= convertedResult
;
1219 PluginScriptableObjectParent::GetPropertyHelper(NPIdentifier aName
,
1224 NS_ASSERTION(Type() == Proxy
, "Bad type!");
1226 ParentNPObject
* object
= static_cast<ParentNPObject
*>(mObject
);
1227 if (object
->invalidated
) {
1228 NS_WARNING("Calling method on an invalidated object!");
1232 PluginIdentifierParent::StackIdentifier
identifier(GetInstance(), aName
);
1237 bool hasProperty
, hasMethod
, success
;
1239 if (!CallGetChildProperty(identifier
, &hasProperty
, &hasMethod
, &result
,
1248 if (!ConvertToVariant(result
, *aResult
, GetInstance())) {
1249 NS_WARNING("Failed to convert result!");
1253 *aHasProperty
= hasProperty
;
1254 *aHasMethod
= hasMethod
;