dom/plugins/ipc/PluginScriptableObjectParent.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * vim: sw=2 ts=2 et :
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "PluginScriptableObjectParent.h"
michael@0 8
michael@0 9 #include "mozilla/DebugOnly.h"
michael@0 10 #include "mozilla/plugins/PluginIdentifierParent.h"
michael@0 11 #include "mozilla/unused.h"
michael@0 12 #include "nsCxPusher.h"
michael@0 13 #include "nsNPAPIPlugin.h"
michael@0 14 #include "PluginScriptableObjectUtils.h"
michael@0 15
michael@0 16 using namespace mozilla::plugins;
michael@0 17 using namespace mozilla::plugins::parent;
michael@0 18
michael@0 19 namespace {
michael@0 20
michael@0 21 inline void
michael@0 22 ReleaseVariant(NPVariant& aVariant,
michael@0 23 PluginInstanceParent* aInstance)
michael@0 24 {
michael@0 25 const NPNetscapeFuncs* npn = GetNetscapeFuncs(aInstance);
michael@0 26 if (npn) {
michael@0 27 npn->releasevariantvalue(&aVariant);
michael@0 28 }
michael@0 29 }
michael@0 30
michael@0 31 } // anonymous namespace
michael@0 32
michael@0 33 // static
michael@0 34 NPObject*
michael@0 35 PluginScriptableObjectParent::ScriptableAllocate(NPP aInstance,
michael@0 36 NPClass* aClass)
michael@0 37 {
michael@0 38 if (aClass != GetClass()) {
michael@0 39 NS_ERROR("Huh?! Wrong class!");
michael@0 40 return nullptr;
michael@0 41 }
michael@0 42
michael@0 43 return new ParentNPObject();
michael@0 44 }
michael@0 45
michael@0 46 // static
michael@0 47 void
michael@0 48 PluginScriptableObjectParent::ScriptableInvalidate(NPObject* aObject)
michael@0 49 {
michael@0 50 if (aObject->_class != GetClass()) {
michael@0 51 NS_ERROR("Don't know what kind of object this is!");
michael@0 52 return;
michael@0 53 }
michael@0 54
michael@0 55 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 56 if (object->invalidated) {
michael@0 57 // This can happen more than once, and is just fine.
michael@0 58 return;
michael@0 59 }
michael@0 60
michael@0 61 object->invalidated = true;
michael@0 62
michael@0 63 // |object->parent| may be null already if the instance has gone away.
michael@0 64 if (object->parent && !object->parent->CallInvalidate()) {
michael@0 65 NS_ERROR("Failed to send message!");
michael@0 66 }
michael@0 67 }
michael@0 68
michael@0 69 // static
michael@0 70 void
michael@0 71 PluginScriptableObjectParent::ScriptableDeallocate(NPObject* aObject)
michael@0 72 {
michael@0 73 if (aObject->_class != GetClass()) {
michael@0 74 NS_ERROR("Don't know what kind of object this is!");
michael@0 75 return;
michael@0 76 }
michael@0 77
michael@0 78 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 79 PluginScriptableObjectParent* actor = object->parent;
michael@0 80 if (actor) {
michael@0 81 NS_ASSERTION(actor->Type() == Proxy, "Bad type!");
michael@0 82 actor->DropNPObject();
michael@0 83 }
michael@0 84
michael@0 85 delete object;
michael@0 86 }
michael@0 87
michael@0 88 // static
michael@0 89 bool
michael@0 90 PluginScriptableObjectParent::ScriptableHasMethod(NPObject* aObject,
michael@0 91 NPIdentifier aName)
michael@0 92 {
michael@0 93 if (aObject->_class != GetClass()) {
michael@0 94 NS_ERROR("Don't know what kind of object this is!");
michael@0 95 return false;
michael@0 96 }
michael@0 97
michael@0 98 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 99 if (object->invalidated) {
michael@0 100 NS_WARNING("Calling method on an invalidated object!");
michael@0 101 return false;
michael@0 102 }
michael@0 103
michael@0 104 ProtectedActor<PluginScriptableObjectParent> actor(object->parent);
michael@0 105 if (!actor) {
michael@0 106 return false;
michael@0 107 }
michael@0 108
michael@0 109 PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
michael@0 110 if (!identifier) {
michael@0 111 return false;
michael@0 112 }
michael@0 113
michael@0 114 NS_ASSERTION(actor->Type() == Proxy, "Bad type!");
michael@0 115
michael@0 116 bool result;
michael@0 117 if (!actor->CallHasMethod(identifier, &result)) {
michael@0 118 NS_WARNING("Failed to send message!");
michael@0 119 return false;
michael@0 120 }
michael@0 121
michael@0 122 return result;
michael@0 123 }
michael@0 124
michael@0 125 // static
michael@0 126 bool
michael@0 127 PluginScriptableObjectParent::ScriptableInvoke(NPObject* aObject,
michael@0 128 NPIdentifier aName,
michael@0 129 const NPVariant* aArgs,
michael@0 130 uint32_t aArgCount,
michael@0 131 NPVariant* aResult)
michael@0 132 {
michael@0 133 if (aObject->_class != GetClass()) {
michael@0 134 NS_ERROR("Don't know what kind of object this is!");
michael@0 135 return false;
michael@0 136 }
michael@0 137
michael@0 138 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 139 if (object->invalidated) {
michael@0 140 NS_WARNING("Calling method on an invalidated object!");
michael@0 141 return false;
michael@0 142 }
michael@0 143
michael@0 144 ProtectedActor<PluginScriptableObjectParent> actor(object->parent);
michael@0 145 if (!actor) {
michael@0 146 return false;
michael@0 147 }
michael@0 148
michael@0 149 PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
michael@0 150 if (!identifier) {
michael@0 151 return false;
michael@0 152 }
michael@0 153
michael@0 154 NS_ASSERTION(actor->Type() == Proxy, "Bad type!");
michael@0 155
michael@0 156 ProtectedVariantArray args(aArgs, aArgCount, actor->GetInstance());
michael@0 157 if (!args.IsOk()) {
michael@0 158 NS_ERROR("Failed to convert arguments!");
michael@0 159 return false;
michael@0 160 }
michael@0 161
michael@0 162 Variant remoteResult;
michael@0 163 bool success;
michael@0 164 if (!actor->CallInvoke(identifier, args, &remoteResult,
michael@0 165 &success)) {
michael@0 166 NS_WARNING("Failed to send message!");
michael@0 167 return false;
michael@0 168 }
michael@0 169
michael@0 170 if (!success) {
michael@0 171 return false;
michael@0 172 }
michael@0 173
michael@0 174 if (!ConvertToVariant(remoteResult, *aResult, actor->GetInstance())) {
michael@0 175 NS_WARNING("Failed to convert result!");
michael@0 176 return false;
michael@0 177 }
michael@0 178 return true;
michael@0 179 }
michael@0 180
michael@0 181 // static
michael@0 182 bool
michael@0 183 PluginScriptableObjectParent::ScriptableInvokeDefault(NPObject* aObject,
michael@0 184 const NPVariant* aArgs,
michael@0 185 uint32_t aArgCount,
michael@0 186 NPVariant* aResult)
michael@0 187 {
michael@0 188 if (aObject->_class != GetClass()) {
michael@0 189 NS_ERROR("Don't know what kind of object this is!");
michael@0 190 return false;
michael@0 191 }
michael@0 192
michael@0 193 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 194 if (object->invalidated) {
michael@0 195 NS_WARNING("Calling method on an invalidated object!");
michael@0 196 return false;
michael@0 197 }
michael@0 198
michael@0 199 ProtectedActor<PluginScriptableObjectParent> actor(object->parent);
michael@0 200 if (!actor) {
michael@0 201 return false;
michael@0 202 }
michael@0 203
michael@0 204 NS_ASSERTION(actor->Type() == Proxy, "Bad type!");
michael@0 205
michael@0 206 ProtectedVariantArray args(aArgs, aArgCount, actor->GetInstance());
michael@0 207 if (!args.IsOk()) {
michael@0 208 NS_ERROR("Failed to convert arguments!");
michael@0 209 return false;
michael@0 210 }
michael@0 211
michael@0 212 Variant remoteResult;
michael@0 213 bool success;
michael@0 214 if (!actor->CallInvokeDefault(args, &remoteResult, &success)) {
michael@0 215 NS_WARNING("Failed to send message!");
michael@0 216 return false;
michael@0 217 }
michael@0 218
michael@0 219 if (!success) {
michael@0 220 return false;
michael@0 221 }
michael@0 222
michael@0 223 if (!ConvertToVariant(remoteResult, *aResult, actor->GetInstance())) {
michael@0 224 NS_WARNING("Failed to convert result!");
michael@0 225 return false;
michael@0 226 }
michael@0 227 return true;
michael@0 228 }
michael@0 229
michael@0 230 // static
michael@0 231 bool
michael@0 232 PluginScriptableObjectParent::ScriptableHasProperty(NPObject* aObject,
michael@0 233 NPIdentifier aName)
michael@0 234 {
michael@0 235 if (aObject->_class != GetClass()) {
michael@0 236 NS_ERROR("Don't know what kind of object this is!");
michael@0 237 return false;
michael@0 238 }
michael@0 239
michael@0 240 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 241 if (object->invalidated) {
michael@0 242 NS_WARNING("Calling method on an invalidated object!");
michael@0 243 return false;
michael@0 244 }
michael@0 245
michael@0 246 ProtectedActor<PluginScriptableObjectParent> actor(object->parent);
michael@0 247 if (!actor) {
michael@0 248 return false;
michael@0 249 }
michael@0 250
michael@0 251 PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
michael@0 252 if (!identifier) {
michael@0 253 return false;
michael@0 254 }
michael@0 255
michael@0 256 NS_ASSERTION(actor->Type() == Proxy, "Bad type!");
michael@0 257
michael@0 258 bool result;
michael@0 259 if (!actor->CallHasProperty(identifier, &result)) {
michael@0 260 NS_WARNING("Failed to send message!");
michael@0 261 return false;
michael@0 262 }
michael@0 263
michael@0 264 return result;
michael@0 265 }
michael@0 266
michael@0 267 // static
michael@0 268 bool
michael@0 269 PluginScriptableObjectParent::ScriptableGetProperty(NPObject* aObject,
michael@0 270 NPIdentifier aName,
michael@0 271 NPVariant* aResult)
michael@0 272 {
michael@0 273 // See GetPropertyHelper below.
michael@0 274 NS_NOTREACHED("Shouldn't ever call this directly!");
michael@0 275 return false;
michael@0 276 }
michael@0 277
michael@0 278 // static
michael@0 279 bool
michael@0 280 PluginScriptableObjectParent::ScriptableSetProperty(NPObject* aObject,
michael@0 281 NPIdentifier aName,
michael@0 282 const NPVariant* aValue)
michael@0 283 {
michael@0 284 if (aObject->_class != GetClass()) {
michael@0 285 NS_ERROR("Don't know what kind of object this is!");
michael@0 286 return false;
michael@0 287 }
michael@0 288
michael@0 289 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 290 if (object->invalidated) {
michael@0 291 NS_WARNING("Calling method on an invalidated object!");
michael@0 292 return false;
michael@0 293 }
michael@0 294
michael@0 295 ProtectedActor<PluginScriptableObjectParent> actor(object->parent);
michael@0 296 if (!actor) {
michael@0 297 return false;
michael@0 298 }
michael@0 299
michael@0 300 PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
michael@0 301 if (!identifier) {
michael@0 302 return false;
michael@0 303 }
michael@0 304
michael@0 305 NS_ASSERTION(actor->Type() == Proxy, "Bad type!");
michael@0 306
michael@0 307 ProtectedVariant value(*aValue, actor->GetInstance());
michael@0 308 if (!value.IsOk()) {
michael@0 309 NS_WARNING("Failed to convert variant!");
michael@0 310 return false;
michael@0 311 }
michael@0 312
michael@0 313 bool success;
michael@0 314 if (!actor->CallSetProperty(identifier, value, &success)) {
michael@0 315 NS_WARNING("Failed to send message!");
michael@0 316 return false;
michael@0 317 }
michael@0 318
michael@0 319 return success;
michael@0 320 }
michael@0 321
michael@0 322 // static
michael@0 323 bool
michael@0 324 PluginScriptableObjectParent::ScriptableRemoveProperty(NPObject* aObject,
michael@0 325 NPIdentifier aName)
michael@0 326 {
michael@0 327 if (aObject->_class != GetClass()) {
michael@0 328 NS_ERROR("Don't know what kind of object this is!");
michael@0 329 return false;
michael@0 330 }
michael@0 331
michael@0 332 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 333 if (object->invalidated) {
michael@0 334 NS_WARNING("Calling method on an invalidated object!");
michael@0 335 return false;
michael@0 336 }
michael@0 337
michael@0 338 ProtectedActor<PluginScriptableObjectParent> actor(object->parent);
michael@0 339 if (!actor) {
michael@0 340 return false;
michael@0 341 }
michael@0 342
michael@0 343 PluginIdentifierParent::StackIdentifier identifier(aObject, aName);
michael@0 344 if (!identifier) {
michael@0 345 return false;
michael@0 346 }
michael@0 347
michael@0 348 NS_ASSERTION(actor->Type() == Proxy, "Bad type!");
michael@0 349
michael@0 350 bool success;
michael@0 351 if (!actor->CallRemoveProperty(identifier, &success)) {
michael@0 352 NS_WARNING("Failed to send message!");
michael@0 353 return false;
michael@0 354 }
michael@0 355
michael@0 356 return success;
michael@0 357 }
michael@0 358
michael@0 359 // static
michael@0 360 bool
michael@0 361 PluginScriptableObjectParent::ScriptableEnumerate(NPObject* aObject,
michael@0 362 NPIdentifier** aIdentifiers,
michael@0 363 uint32_t* aCount)
michael@0 364 {
michael@0 365 if (aObject->_class != GetClass()) {
michael@0 366 NS_ERROR("Don't know what kind of object this is!");
michael@0 367 return false;
michael@0 368 }
michael@0 369
michael@0 370 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 371 if (object->invalidated) {
michael@0 372 NS_WARNING("Calling method on an invalidated object!");
michael@0 373 return false;
michael@0 374 }
michael@0 375
michael@0 376 ProtectedActor<PluginScriptableObjectParent> actor(object->parent);
michael@0 377 if (!actor) {
michael@0 378 return false;
michael@0 379 }
michael@0 380
michael@0 381 NS_ASSERTION(actor->Type() == Proxy, "Bad type!");
michael@0 382
michael@0 383 const NPNetscapeFuncs* npn = GetNetscapeFuncs(aObject);
michael@0 384 if (!npn) {
michael@0 385 NS_ERROR("No netscape funcs!");
michael@0 386 return false;
michael@0 387 }
michael@0 388
michael@0 389 AutoInfallibleTArray<PPluginIdentifierParent*, 10> identifiers;
michael@0 390 bool success;
michael@0 391 if (!actor->CallEnumerate(&identifiers, &success)) {
michael@0 392 NS_WARNING("Failed to send message!");
michael@0 393 return false;
michael@0 394 }
michael@0 395
michael@0 396 if (!success) {
michael@0 397 return false;
michael@0 398 }
michael@0 399
michael@0 400 *aCount = identifiers.Length();
michael@0 401 if (!*aCount) {
michael@0 402 *aIdentifiers = nullptr;
michael@0 403 return true;
michael@0 404 }
michael@0 405
michael@0 406 *aIdentifiers = (NPIdentifier*)npn->memalloc(*aCount * sizeof(NPIdentifier));
michael@0 407 if (!*aIdentifiers) {
michael@0 408 NS_ERROR("Out of memory!");
michael@0 409 return false;
michael@0 410 }
michael@0 411
michael@0 412 for (uint32_t index = 0; index < *aCount; index++) {
michael@0 413 PluginIdentifierParent* id =
michael@0 414 static_cast<PluginIdentifierParent*>(identifiers[index]);
michael@0 415 (*aIdentifiers)[index] = id->ToNPIdentifier();
michael@0 416 }
michael@0 417 return true;
michael@0 418 }
michael@0 419
michael@0 420 // static
michael@0 421 bool
michael@0 422 PluginScriptableObjectParent::ScriptableConstruct(NPObject* aObject,
michael@0 423 const NPVariant* aArgs,
michael@0 424 uint32_t aArgCount,
michael@0 425 NPVariant* aResult)
michael@0 426 {
michael@0 427 if (aObject->_class != GetClass()) {
michael@0 428 NS_ERROR("Don't know what kind of object this is!");
michael@0 429 return false;
michael@0 430 }
michael@0 431
michael@0 432 ParentNPObject* object = reinterpret_cast<ParentNPObject*>(aObject);
michael@0 433 if (object->invalidated) {
michael@0 434 NS_WARNING("Calling method on an invalidated object!");
michael@0 435 return false;
michael@0 436 }
michael@0 437
michael@0 438 ProtectedActor<PluginScriptableObjectParent> actor(object->parent);
michael@0 439 if (!actor) {
michael@0 440 return false;
michael@0 441 }
michael@0 442
michael@0 443 NS_ASSERTION(actor->Type() == Proxy, "Bad type!");
michael@0 444
michael@0 445 ProtectedVariantArray args(aArgs, aArgCount, actor->GetInstance());
michael@0 446 if (!args.IsOk()) {
michael@0 447 NS_ERROR("Failed to convert arguments!");
michael@0 448 return false;
michael@0 449 }
michael@0 450
michael@0 451 Variant remoteResult;
michael@0 452 bool success;
michael@0 453 if (!actor->CallConstruct(args, &remoteResult, &success)) {
michael@0 454 NS_WARNING("Failed to send message!");
michael@0 455 return false;
michael@0 456 }
michael@0 457
michael@0 458 if (!success) {
michael@0 459 return false;
michael@0 460 }
michael@0 461
michael@0 462 if (!ConvertToVariant(remoteResult, *aResult, actor->GetInstance())) {
michael@0 463 NS_WARNING("Failed to convert result!");
michael@0 464 return false;
michael@0 465 }
michael@0 466 return true;
michael@0 467 }
michael@0 468
michael@0 469 const NPClass PluginScriptableObjectParent::sNPClass = {
michael@0 470 NP_CLASS_STRUCT_VERSION,
michael@0 471 PluginScriptableObjectParent::ScriptableAllocate,
michael@0 472 PluginScriptableObjectParent::ScriptableDeallocate,
michael@0 473 PluginScriptableObjectParent::ScriptableInvalidate,
michael@0 474 PluginScriptableObjectParent::ScriptableHasMethod,
michael@0 475 PluginScriptableObjectParent::ScriptableInvoke,
michael@0 476 PluginScriptableObjectParent::ScriptableInvokeDefault,
michael@0 477 PluginScriptableObjectParent::ScriptableHasProperty,
michael@0 478 PluginScriptableObjectParent::ScriptableGetProperty,
michael@0 479 PluginScriptableObjectParent::ScriptableSetProperty,
michael@0 480 PluginScriptableObjectParent::ScriptableRemoveProperty,
michael@0 481 PluginScriptableObjectParent::ScriptableEnumerate,
michael@0 482 PluginScriptableObjectParent::ScriptableConstruct
michael@0 483 };
michael@0 484
michael@0 485 PluginScriptableObjectParent::PluginScriptableObjectParent(
michael@0 486 ScriptableObjectType aType)
michael@0 487 : mInstance(nullptr),
michael@0 488 mObject(nullptr),
michael@0 489 mProtectCount(0),
michael@0 490 mType(aType)
michael@0 491 {
michael@0 492 }
michael@0 493
michael@0 494 PluginScriptableObjectParent::~PluginScriptableObjectParent()
michael@0 495 {
michael@0 496 if (mObject) {
michael@0 497 if (mObject->_class == GetClass()) {
michael@0 498 NS_ASSERTION(mType == Proxy, "Wrong type!");
michael@0 499 static_cast<ParentNPObject*>(mObject)->parent = nullptr;
michael@0 500 }
michael@0 501 else {
michael@0 502 NS_ASSERTION(mType == LocalObject, "Wrong type!");
michael@0 503 GetInstance()->GetNPNIface()->releaseobject(mObject);
michael@0 504 }
michael@0 505 }
michael@0 506 }
michael@0 507
michael@0 508 void
michael@0 509 PluginScriptableObjectParent::InitializeProxy()
michael@0 510 {
michael@0 511 NS_ASSERTION(mType == Proxy, "Bad type!");
michael@0 512 NS_ASSERTION(!mObject, "Calling Initialize more than once!");
michael@0 513
michael@0 514 mInstance = static_cast<PluginInstanceParent*>(Manager());
michael@0 515 NS_ASSERTION(mInstance, "Null manager?!");
michael@0 516
michael@0 517 NPObject* object = CreateProxyObject();
michael@0 518 NS_ASSERTION(object, "Failed to create object!");
michael@0 519
michael@0 520 if (!mInstance->RegisterNPObjectForActor(object, this)) {
michael@0 521 NS_ERROR("Out of memory?");
michael@0 522 }
michael@0 523
michael@0 524 mObject = object;
michael@0 525 }
michael@0 526
michael@0 527 void
michael@0 528 PluginScriptableObjectParent::InitializeLocal(NPObject* aObject)
michael@0 529 {
michael@0 530 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 531 NS_ASSERTION(!(mInstance && mObject), "Calling Initialize more than once!");
michael@0 532
michael@0 533 mInstance = static_cast<PluginInstanceParent*>(Manager());
michael@0 534 NS_ASSERTION(mInstance, "Null manager?!");
michael@0 535
michael@0 536 mInstance->GetNPNIface()->retainobject(aObject);
michael@0 537
michael@0 538 NS_ASSERTION(!mProtectCount, "Should be zero!");
michael@0 539 mProtectCount++;
michael@0 540
michael@0 541 if (!mInstance->RegisterNPObjectForActor(aObject, this)) {
michael@0 542 NS_ERROR("Out of memory?");
michael@0 543 }
michael@0 544
michael@0 545 mObject = aObject;
michael@0 546 }
michael@0 547
michael@0 548 NPObject*
michael@0 549 PluginScriptableObjectParent::CreateProxyObject()
michael@0 550 {
michael@0 551 NS_ASSERTION(mInstance, "Must have an instance!");
michael@0 552 NS_ASSERTION(mType == Proxy, "Shouldn't call this for non-proxy object!");
michael@0 553
michael@0 554 const NPNetscapeFuncs* npn = GetNetscapeFuncs(mInstance);
michael@0 555
michael@0 556 NPObject* npobject = npn->createobject(mInstance->GetNPP(),
michael@0 557 const_cast<NPClass*>(GetClass()));
michael@0 558 NS_ASSERTION(npobject, "Failed to create object?!");
michael@0 559 NS_ASSERTION(npobject->_class == GetClass(), "Wrong kind of object!");
michael@0 560 NS_ASSERTION(npobject->referenceCount == 1, "Some kind of live object!");
michael@0 561
michael@0 562 ParentNPObject* object = static_cast<ParentNPObject*>(npobject);
michael@0 563 NS_ASSERTION(!object->invalidated, "Bad object!");
michael@0 564 NS_ASSERTION(!object->parent, "Bad object!");
michael@0 565
michael@0 566 // We don't want to have the actor own this object but rather let the object
michael@0 567 // own this actor. Set the reference count to 0 here so that when the object
michael@0 568 // dies we will send the destructor message to the child.
michael@0 569 object->referenceCount = 0;
michael@0 570 NS_LOG_RELEASE(object, 0, "BrowserNPObject");
michael@0 571
michael@0 572 object->parent = const_cast<PluginScriptableObjectParent*>(this);
michael@0 573 return object;
michael@0 574 }
michael@0 575
michael@0 576 bool
michael@0 577 PluginScriptableObjectParent::ResurrectProxyObject()
michael@0 578 {
michael@0 579 NS_ASSERTION(mInstance, "Must have an instance already!");
michael@0 580 NS_ASSERTION(!mObject, "Should not have an object already!");
michael@0 581 NS_ASSERTION(mType == Proxy, "Shouldn't call this for non-proxy object!");
michael@0 582
michael@0 583 InitializeProxy();
michael@0 584 NS_ASSERTION(mObject, "Initialize failed!");
michael@0 585
michael@0 586 if (!SendProtect()) {
michael@0 587 NS_WARNING("Failed to send message!");
michael@0 588 return false;
michael@0 589 }
michael@0 590
michael@0 591 return true;
michael@0 592 }
michael@0 593
michael@0 594 NPObject*
michael@0 595 PluginScriptableObjectParent::GetObject(bool aCanResurrect)
michael@0 596 {
michael@0 597 if (!mObject && aCanResurrect && !ResurrectProxyObject()) {
michael@0 598 NS_ERROR("Null object!");
michael@0 599 return nullptr;
michael@0 600 }
michael@0 601 return mObject;
michael@0 602 }
michael@0 603
michael@0 604 void
michael@0 605 PluginScriptableObjectParent::Protect()
michael@0 606 {
michael@0 607 NS_ASSERTION(mObject, "No object!");
michael@0 608 NS_ASSERTION(mProtectCount >= 0, "Negative protect count?!");
michael@0 609
michael@0 610 if (mType == LocalObject) {
michael@0 611 ++mProtectCount;
michael@0 612 }
michael@0 613 }
michael@0 614
michael@0 615 void
michael@0 616 PluginScriptableObjectParent::Unprotect()
michael@0 617 {
michael@0 618 NS_ASSERTION(mObject, "No object!");
michael@0 619 NS_ASSERTION(mProtectCount >= 0, "Negative protect count?!");
michael@0 620
michael@0 621 if (mType == LocalObject) {
michael@0 622 if (--mProtectCount == 0) {
michael@0 623 unused << PluginScriptableObjectParent::Send__delete__(this);
michael@0 624 }
michael@0 625 }
michael@0 626 }
michael@0 627
michael@0 628 void
michael@0 629 PluginScriptableObjectParent::DropNPObject()
michael@0 630 {
michael@0 631 NS_ASSERTION(mObject, "Invalidated object!");
michael@0 632 NS_ASSERTION(mObject->_class == GetClass(), "Wrong type of object!");
michael@0 633 NS_ASSERTION(mType == Proxy, "Shouldn't call this for non-proxy object!");
michael@0 634
michael@0 635 // We think we're about to be deleted, but we could be racing with the other
michael@0 636 // process.
michael@0 637 PluginInstanceParent* instance = GetInstance();
michael@0 638 NS_ASSERTION(instance, "Must have an instance!");
michael@0 639
michael@0 640 instance->UnregisterNPObject(mObject);
michael@0 641 mObject = nullptr;
michael@0 642
michael@0 643 unused << SendUnprotect();
michael@0 644 }
michael@0 645
michael@0 646 bool
michael@0 647 PluginScriptableObjectParent::AnswerHasMethod(PPluginIdentifierParent* aId,
michael@0 648 bool* aHasMethod)
michael@0 649 {
michael@0 650 if (!mObject) {
michael@0 651 NS_WARNING("Calling AnswerHasMethod with an invalidated object!");
michael@0 652 *aHasMethod = false;
michael@0 653 return true;
michael@0 654 }
michael@0 655
michael@0 656 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 657 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 658
michael@0 659 PluginInstanceParent* instance = GetInstance();
michael@0 660 if (!instance) {
michael@0 661 NS_ERROR("No instance?!");
michael@0 662 *aHasMethod = false;
michael@0 663 return true;
michael@0 664 }
michael@0 665
michael@0 666 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 667 if (!npn) {
michael@0 668 NS_ERROR("No netscape funcs?!");
michael@0 669 *aHasMethod = false;
michael@0 670 return true;
michael@0 671 }
michael@0 672
michael@0 673 PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
michael@0 674 *aHasMethod = npn->hasmethod(instance->GetNPP(), mObject, id->ToNPIdentifier());
michael@0 675 return true;
michael@0 676 }
michael@0 677
michael@0 678 bool
michael@0 679 PluginScriptableObjectParent::AnswerInvoke(PPluginIdentifierParent* aId,
michael@0 680 const InfallibleTArray<Variant>& aArgs,
michael@0 681 Variant* aResult,
michael@0 682 bool* aSuccess)
michael@0 683 {
michael@0 684 if (!mObject) {
michael@0 685 NS_WARNING("Calling AnswerInvoke with an invalidated object!");
michael@0 686 *aResult = void_t();
michael@0 687 *aSuccess = false;
michael@0 688 return true;
michael@0 689 }
michael@0 690
michael@0 691 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 692 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 693
michael@0 694 PluginInstanceParent* instance = GetInstance();
michael@0 695 if (!instance) {
michael@0 696 NS_ERROR("No instance?!");
michael@0 697 *aResult = void_t();
michael@0 698 *aSuccess = false;
michael@0 699 return true;
michael@0 700 }
michael@0 701
michael@0 702 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 703 if (!npn) {
michael@0 704 NS_ERROR("No netscape funcs?!");
michael@0 705 *aResult = void_t();
michael@0 706 *aSuccess = false;
michael@0 707 return true;
michael@0 708 }
michael@0 709
michael@0 710 AutoFallibleTArray<NPVariant, 10> convertedArgs;
michael@0 711 uint32_t argCount = aArgs.Length();
michael@0 712
michael@0 713 if (!convertedArgs.SetLength(argCount)) {
michael@0 714 *aResult = void_t();
michael@0 715 *aSuccess = false;
michael@0 716 return true;
michael@0 717 }
michael@0 718
michael@0 719 for (uint32_t index = 0; index < argCount; index++) {
michael@0 720 if (!ConvertToVariant(aArgs[index], convertedArgs[index], instance)) {
michael@0 721 // Don't leak things we've already converted!
michael@0 722 while (index-- > 0) {
michael@0 723 ReleaseVariant(convertedArgs[index], instance);
michael@0 724 }
michael@0 725 *aResult = void_t();
michael@0 726 *aSuccess = false;
michael@0 727 return true;
michael@0 728 }
michael@0 729 }
michael@0 730
michael@0 731 PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
michael@0 732 NPVariant result;
michael@0 733 bool success = npn->invoke(instance->GetNPP(), mObject, id->ToNPIdentifier(),
michael@0 734 convertedArgs.Elements(), argCount, &result);
michael@0 735
michael@0 736 for (uint32_t index = 0; index < argCount; index++) {
michael@0 737 ReleaseVariant(convertedArgs[index], instance);
michael@0 738 }
michael@0 739
michael@0 740 if (!success) {
michael@0 741 *aResult = void_t();
michael@0 742 *aSuccess = false;
michael@0 743 return true;
michael@0 744 }
michael@0 745
michael@0 746 Variant convertedResult;
michael@0 747 success = ConvertToRemoteVariant(result, convertedResult, GetInstance());
michael@0 748
michael@0 749 DeferNPVariantLastRelease(npn, &result);
michael@0 750
michael@0 751 if (!success) {
michael@0 752 *aResult = void_t();
michael@0 753 *aSuccess = false;
michael@0 754 return true;
michael@0 755 }
michael@0 756
michael@0 757 *aResult = convertedResult;
michael@0 758 *aSuccess = true;
michael@0 759 return true;
michael@0 760 }
michael@0 761
michael@0 762 bool
michael@0 763 PluginScriptableObjectParent::AnswerInvokeDefault(const InfallibleTArray<Variant>& aArgs,
michael@0 764 Variant* aResult,
michael@0 765 bool* aSuccess)
michael@0 766 {
michael@0 767 if (!mObject) {
michael@0 768 NS_WARNING("Calling AnswerInvoke with an invalidated object!");
michael@0 769 *aResult = void_t();
michael@0 770 *aSuccess = false;
michael@0 771 return true;
michael@0 772 }
michael@0 773
michael@0 774 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 775 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 776
michael@0 777 PluginInstanceParent* instance = GetInstance();
michael@0 778 if (!instance) {
michael@0 779 NS_ERROR("No instance?!");
michael@0 780 *aResult = void_t();
michael@0 781 *aSuccess = false;
michael@0 782 return true;
michael@0 783 }
michael@0 784
michael@0 785 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 786 if (!npn) {
michael@0 787 NS_ERROR("No netscape funcs?!");
michael@0 788 *aResult = void_t();
michael@0 789 *aSuccess = false;
michael@0 790 return true;
michael@0 791 }
michael@0 792
michael@0 793 AutoFallibleTArray<NPVariant, 10> convertedArgs;
michael@0 794 uint32_t argCount = aArgs.Length();
michael@0 795
michael@0 796 if (!convertedArgs.SetLength(argCount)) {
michael@0 797 *aResult = void_t();
michael@0 798 *aSuccess = false;
michael@0 799 return true;
michael@0 800 }
michael@0 801
michael@0 802 for (uint32_t index = 0; index < argCount; index++) {
michael@0 803 if (!ConvertToVariant(aArgs[index], convertedArgs[index], instance)) {
michael@0 804 // Don't leak things we've already converted!
michael@0 805 while (index-- > 0) {
michael@0 806 ReleaseVariant(convertedArgs[index], instance);
michael@0 807 }
michael@0 808 *aResult = void_t();
michael@0 809 *aSuccess = false;
michael@0 810 return true;
michael@0 811 }
michael@0 812 }
michael@0 813
michael@0 814 NPVariant result;
michael@0 815 bool success = npn->invokeDefault(instance->GetNPP(), mObject,
michael@0 816 convertedArgs.Elements(), argCount,
michael@0 817 &result);
michael@0 818
michael@0 819 for (uint32_t index = 0; index < argCount; index++) {
michael@0 820 ReleaseVariant(convertedArgs[index], instance);
michael@0 821 }
michael@0 822
michael@0 823 if (!success) {
michael@0 824 *aResult = void_t();
michael@0 825 *aSuccess = false;
michael@0 826 return true;
michael@0 827 }
michael@0 828
michael@0 829 Variant convertedResult;
michael@0 830 success = ConvertToRemoteVariant(result, convertedResult, GetInstance());
michael@0 831
michael@0 832 DeferNPVariantLastRelease(npn, &result);
michael@0 833
michael@0 834 if (!success) {
michael@0 835 *aResult = void_t();
michael@0 836 *aSuccess = false;
michael@0 837 return true;
michael@0 838 }
michael@0 839
michael@0 840 *aResult = convertedResult;
michael@0 841 *aSuccess = true;
michael@0 842 return true;
michael@0 843 }
michael@0 844
michael@0 845 bool
michael@0 846 PluginScriptableObjectParent::AnswerHasProperty(PPluginIdentifierParent* aId,
michael@0 847 bool* aHasProperty)
michael@0 848 {
michael@0 849 if (!mObject) {
michael@0 850 NS_WARNING("Calling AnswerHasProperty with an invalidated object!");
michael@0 851 *aHasProperty = false;
michael@0 852 return true;
michael@0 853 }
michael@0 854
michael@0 855 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 856 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 857
michael@0 858 PluginInstanceParent* instance = GetInstance();
michael@0 859 if (!instance) {
michael@0 860 NS_ERROR("No instance?!");
michael@0 861 *aHasProperty = false;
michael@0 862 return true;
michael@0 863 }
michael@0 864
michael@0 865 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 866 if (!npn) {
michael@0 867 NS_ERROR("No netscape funcs?!");
michael@0 868 *aHasProperty = false;
michael@0 869 return true;
michael@0 870 }
michael@0 871
michael@0 872 PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
michael@0 873 *aHasProperty = npn->hasproperty(instance->GetNPP(), mObject,
michael@0 874 id->ToNPIdentifier());
michael@0 875 return true;
michael@0 876 }
michael@0 877
michael@0 878 bool
michael@0 879 PluginScriptableObjectParent::AnswerGetParentProperty(
michael@0 880 PPluginIdentifierParent* aId,
michael@0 881 Variant* aResult,
michael@0 882 bool* aSuccess)
michael@0 883 {
michael@0 884 if (!mObject) {
michael@0 885 NS_WARNING("Calling AnswerGetProperty with an invalidated object!");
michael@0 886 *aResult = void_t();
michael@0 887 *aSuccess = false;
michael@0 888 return true;
michael@0 889 }
michael@0 890
michael@0 891 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 892 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 893
michael@0 894 PluginInstanceParent* instance = GetInstance();
michael@0 895 if (!instance) {
michael@0 896 NS_ERROR("No instance?!");
michael@0 897 *aResult = void_t();
michael@0 898 *aSuccess = false;
michael@0 899 return true;
michael@0 900 }
michael@0 901
michael@0 902 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 903 if (!npn) {
michael@0 904 NS_ERROR("No netscape funcs?!");
michael@0 905 *aResult = void_t();
michael@0 906 *aSuccess = false;
michael@0 907 return true;
michael@0 908 }
michael@0 909
michael@0 910 PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
michael@0 911 NPVariant result;
michael@0 912 if (!npn->getproperty(instance->GetNPP(), mObject, id->ToNPIdentifier(),
michael@0 913 &result)) {
michael@0 914 *aResult = void_t();
michael@0 915 *aSuccess = false;
michael@0 916 return true;
michael@0 917 }
michael@0 918
michael@0 919 Variant converted;
michael@0 920 if ((*aSuccess = ConvertToRemoteVariant(result, converted, instance))) {
michael@0 921 DeferNPVariantLastRelease(npn, &result);
michael@0 922 *aResult = converted;
michael@0 923 }
michael@0 924 else {
michael@0 925 *aResult = void_t();
michael@0 926 }
michael@0 927
michael@0 928 return true;
michael@0 929 }
michael@0 930
michael@0 931 bool
michael@0 932 PluginScriptableObjectParent::AnswerSetProperty(PPluginIdentifierParent* aId,
michael@0 933 const Variant& aValue,
michael@0 934 bool* aSuccess)
michael@0 935 {
michael@0 936 if (!mObject) {
michael@0 937 NS_WARNING("Calling AnswerSetProperty with an invalidated object!");
michael@0 938 *aSuccess = false;
michael@0 939 return true;
michael@0 940 }
michael@0 941
michael@0 942 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 943 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 944
michael@0 945 PluginInstanceParent* instance = GetInstance();
michael@0 946 if (!instance) {
michael@0 947 NS_ERROR("No instance?!");
michael@0 948 *aSuccess = false;
michael@0 949 return true;
michael@0 950 }
michael@0 951
michael@0 952 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 953 if (!npn) {
michael@0 954 NS_ERROR("No netscape funcs?!");
michael@0 955 *aSuccess = false;
michael@0 956 return true;
michael@0 957 }
michael@0 958
michael@0 959 NPVariant converted;
michael@0 960 if (!ConvertToVariant(aValue, converted, instance)) {
michael@0 961 *aSuccess = false;
michael@0 962 return true;
michael@0 963 }
michael@0 964
michael@0 965 PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
michael@0 966 if ((*aSuccess = npn->setproperty(instance->GetNPP(), mObject,
michael@0 967 id->ToNPIdentifier(), &converted))) {
michael@0 968 ReleaseVariant(converted, instance);
michael@0 969 }
michael@0 970 return true;
michael@0 971 }
michael@0 972
michael@0 973 bool
michael@0 974 PluginScriptableObjectParent::AnswerRemoveProperty(PPluginIdentifierParent* aId,
michael@0 975 bool* aSuccess)
michael@0 976 {
michael@0 977 if (!mObject) {
michael@0 978 NS_WARNING("Calling AnswerRemoveProperty with an invalidated object!");
michael@0 979 *aSuccess = false;
michael@0 980 return true;
michael@0 981 }
michael@0 982
michael@0 983 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 984 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 985
michael@0 986 PluginInstanceParent* instance = GetInstance();
michael@0 987 if (!instance) {
michael@0 988 NS_ERROR("No instance?!");
michael@0 989 *aSuccess = false;
michael@0 990 return true;
michael@0 991 }
michael@0 992
michael@0 993 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 994 if (!npn) {
michael@0 995 NS_ERROR("No netscape funcs?!");
michael@0 996 *aSuccess = false;
michael@0 997 return true;
michael@0 998 }
michael@0 999
michael@0 1000 PluginIdentifierParent* id = static_cast<PluginIdentifierParent*>(aId);
michael@0 1001 *aSuccess = npn->removeproperty(instance->GetNPP(), mObject,
michael@0 1002 id->ToNPIdentifier());
michael@0 1003 return true;
michael@0 1004 }
michael@0 1005
michael@0 1006 bool
michael@0 1007 PluginScriptableObjectParent::AnswerEnumerate(InfallibleTArray<PPluginIdentifierParent*>* aProperties,
michael@0 1008 bool* aSuccess)
michael@0 1009 {
michael@0 1010 if (!mObject) {
michael@0 1011 NS_WARNING("Calling AnswerEnumerate with an invalidated object!");
michael@0 1012 *aSuccess = false;
michael@0 1013 return true;
michael@0 1014 }
michael@0 1015
michael@0 1016 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 1017 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 1018
michael@0 1019 PluginInstanceParent* instance = GetInstance();
michael@0 1020 if (!instance) {
michael@0 1021 NS_ERROR("No instance?!");
michael@0 1022 *aSuccess = false;
michael@0 1023 return true;
michael@0 1024 }
michael@0 1025
michael@0 1026 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 1027 if (!npn) {
michael@0 1028 NS_WARNING("No netscape funcs?!");
michael@0 1029 *aSuccess = false;
michael@0 1030 return true;
michael@0 1031 }
michael@0 1032
michael@0 1033 NPIdentifier* ids;
michael@0 1034 uint32_t idCount;
michael@0 1035 if (!npn->enumerate(instance->GetNPP(), mObject, &ids, &idCount)) {
michael@0 1036 *aSuccess = false;
michael@0 1037 return true;
michael@0 1038 }
michael@0 1039
michael@0 1040 aProperties->SetCapacity(idCount);
michael@0 1041
michael@0 1042 mozilla::AutoSafeJSContext cx;
michael@0 1043 for (uint32_t index = 0; index < idCount; index++) {
michael@0 1044 // Because of GC hazards, all identifiers returned from enumerate
michael@0 1045 // must be made permanent.
michael@0 1046 if (_identifierisstring(ids[index])) {
michael@0 1047 JS::Rooted<JSString*> str(cx, NPIdentifierToString(ids[index]));
michael@0 1048 if (!JS_StringHasBeenInterned(cx, str)) {
michael@0 1049 DebugOnly<JSString*> str2 = JS_InternJSString(cx, str);
michael@0 1050 NS_ASSERTION(str2 == str, "Interning a JS string which is currently an ID should return itself.");
michael@0 1051 }
michael@0 1052 }
michael@0 1053 PluginIdentifierParent* id =
michael@0 1054 instance->Module()->GetIdentifierForNPIdentifier(instance->GetNPP(), ids[index]);
michael@0 1055 aProperties->AppendElement(id);
michael@0 1056 NS_ASSERTION(!id->IsTemporary(), "Should only have permanent identifiers!");
michael@0 1057 }
michael@0 1058
michael@0 1059 npn->memfree(ids);
michael@0 1060 *aSuccess = true;
michael@0 1061 return true;
michael@0 1062 }
michael@0 1063
michael@0 1064 bool
michael@0 1065 PluginScriptableObjectParent::AnswerConstruct(const InfallibleTArray<Variant>& aArgs,
michael@0 1066 Variant* aResult,
michael@0 1067 bool* aSuccess)
michael@0 1068 {
michael@0 1069 if (!mObject) {
michael@0 1070 NS_WARNING("Calling AnswerConstruct with an invalidated object!");
michael@0 1071 *aResult = void_t();
michael@0 1072 *aSuccess = false;
michael@0 1073 return true;
michael@0 1074 }
michael@0 1075
michael@0 1076 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 1077 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 1078
michael@0 1079 PluginInstanceParent* instance = GetInstance();
michael@0 1080 if (!instance) {
michael@0 1081 NS_ERROR("No instance?!");
michael@0 1082 *aResult = void_t();
michael@0 1083 *aSuccess = false;
michael@0 1084 return true;
michael@0 1085 }
michael@0 1086
michael@0 1087 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 1088 if (!npn) {
michael@0 1089 NS_ERROR("No netscape funcs?!");
michael@0 1090 *aResult = void_t();
michael@0 1091 *aSuccess = false;
michael@0 1092 return true;
michael@0 1093 }
michael@0 1094
michael@0 1095 AutoFallibleTArray<NPVariant, 10> convertedArgs;
michael@0 1096 uint32_t argCount = aArgs.Length();
michael@0 1097
michael@0 1098 if (!convertedArgs.SetLength(argCount)) {
michael@0 1099 *aResult = void_t();
michael@0 1100 *aSuccess = false;
michael@0 1101 return true;
michael@0 1102 }
michael@0 1103
michael@0 1104 for (uint32_t index = 0; index < argCount; index++) {
michael@0 1105 if (!ConvertToVariant(aArgs[index], convertedArgs[index], instance)) {
michael@0 1106 // Don't leak things we've already converted!
michael@0 1107 while (index-- > 0) {
michael@0 1108 ReleaseVariant(convertedArgs[index], instance);
michael@0 1109 }
michael@0 1110 *aResult = void_t();
michael@0 1111 *aSuccess = false;
michael@0 1112 return true;
michael@0 1113 }
michael@0 1114 }
michael@0 1115
michael@0 1116 NPVariant result;
michael@0 1117 bool success = npn->construct(instance->GetNPP(), mObject,
michael@0 1118 convertedArgs.Elements(), argCount, &result);
michael@0 1119
michael@0 1120 for (uint32_t index = 0; index < argCount; index++) {
michael@0 1121 ReleaseVariant(convertedArgs[index], instance);
michael@0 1122 }
michael@0 1123
michael@0 1124 if (!success) {
michael@0 1125 *aResult = void_t();
michael@0 1126 *aSuccess = false;
michael@0 1127 return true;
michael@0 1128 }
michael@0 1129
michael@0 1130 Variant convertedResult;
michael@0 1131 success = ConvertToRemoteVariant(result, convertedResult, instance);
michael@0 1132
michael@0 1133 DeferNPVariantLastRelease(npn, &result);
michael@0 1134
michael@0 1135 if (!success) {
michael@0 1136 *aResult = void_t();
michael@0 1137 *aSuccess = false;
michael@0 1138 return true;
michael@0 1139 }
michael@0 1140
michael@0 1141 *aSuccess = true;
michael@0 1142 *aResult = convertedResult;
michael@0 1143 return true;
michael@0 1144 }
michael@0 1145
michael@0 1146 bool
michael@0 1147 PluginScriptableObjectParent::RecvProtect()
michael@0 1148 {
michael@0 1149 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 1150 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 1151
michael@0 1152 Protect();
michael@0 1153 return true;
michael@0 1154 }
michael@0 1155
michael@0 1156 bool
michael@0 1157 PluginScriptableObjectParent::RecvUnprotect()
michael@0 1158 {
michael@0 1159 NS_ASSERTION(mObject->_class != GetClass(), "Bad object type!");
michael@0 1160 NS_ASSERTION(mType == LocalObject, "Bad type!");
michael@0 1161
michael@0 1162 Unprotect();
michael@0 1163 return true;
michael@0 1164 }
michael@0 1165
michael@0 1166 bool
michael@0 1167 PluginScriptableObjectParent::AnswerNPN_Evaluate(const nsCString& aScript,
michael@0 1168 Variant* aResult,
michael@0 1169 bool* aSuccess)
michael@0 1170 {
michael@0 1171 PluginInstanceParent* instance = GetInstance();
michael@0 1172 if (!instance) {
michael@0 1173 NS_ERROR("No instance?!");
michael@0 1174 *aResult = void_t();
michael@0 1175 *aSuccess = false;
michael@0 1176 return true;
michael@0 1177 }
michael@0 1178
michael@0 1179 const NPNetscapeFuncs* npn = GetNetscapeFuncs(instance);
michael@0 1180 if (!npn) {
michael@0 1181 NS_ERROR("No netscape funcs?!");
michael@0 1182 *aResult = void_t();
michael@0 1183 *aSuccess = false;
michael@0 1184 return true;
michael@0 1185 }
michael@0 1186
michael@0 1187 NPString script = { aScript.get(), aScript.Length() };
michael@0 1188
michael@0 1189 NPVariant result;
michael@0 1190 bool success = npn->evaluate(instance->GetNPP(), mObject, &script, &result);
michael@0 1191 if (!success) {
michael@0 1192 *aResult = void_t();
michael@0 1193 *aSuccess = false;
michael@0 1194 return true;
michael@0 1195 }
michael@0 1196
michael@0 1197 Variant convertedResult;
michael@0 1198 success = ConvertToRemoteVariant(result, convertedResult, instance);
michael@0 1199
michael@0 1200 DeferNPVariantLastRelease(npn, &result);
michael@0 1201
michael@0 1202 if (!success) {
michael@0 1203 *aResult = void_t();
michael@0 1204 *aSuccess = false;
michael@0 1205 return true;
michael@0 1206 }
michael@0 1207
michael@0 1208 *aSuccess = true;
michael@0 1209 *aResult = convertedResult;
michael@0 1210 return true;
michael@0 1211 }
michael@0 1212
michael@0 1213 bool
michael@0 1214 PluginScriptableObjectParent::GetPropertyHelper(NPIdentifier aName,
michael@0 1215 bool* aHasProperty,
michael@0 1216 bool* aHasMethod,
michael@0 1217 NPVariant* aResult)
michael@0 1218 {
michael@0 1219 NS_ASSERTION(Type() == Proxy, "Bad type!");
michael@0 1220
michael@0 1221 ParentNPObject* object = static_cast<ParentNPObject*>(mObject);
michael@0 1222 if (object->invalidated) {
michael@0 1223 NS_WARNING("Calling method on an invalidated object!");
michael@0 1224 return false;
michael@0 1225 }
michael@0 1226
michael@0 1227 PluginIdentifierParent::StackIdentifier identifier(GetInstance(), aName);
michael@0 1228 if (!identifier) {
michael@0 1229 return false;
michael@0 1230 }
michael@0 1231
michael@0 1232 bool hasProperty, hasMethod, success;
michael@0 1233 Variant result;
michael@0 1234 if (!CallGetChildProperty(identifier, &hasProperty, &hasMethod, &result,
michael@0 1235 &success)) {
michael@0 1236 return false;
michael@0 1237 }
michael@0 1238
michael@0 1239 if (!success) {
michael@0 1240 return false;
michael@0 1241 }
michael@0 1242
michael@0 1243 if (!ConvertToVariant(result, *aResult, GetInstance())) {
michael@0 1244 NS_WARNING("Failed to convert result!");
michael@0 1245 return false;
michael@0 1246 }
michael@0 1247
michael@0 1248 *aHasProperty = hasProperty;
michael@0 1249 *aHasMethod = hasMethod;
michael@0 1250 return true;
michael@0 1251 }

mercurial