| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 static NPIdentifier testIdentifiers[NUM_TEST_IDENTIFIERS]; | 80 static NPIdentifier testIdentifiers[NUM_TEST_IDENTIFIERS]; |
| 81 static const NPUTF8 *testIdentifierNames[NUM_TEST_IDENTIFIERS] = { | 81 static const NPUTF8 *testIdentifierNames[NUM_TEST_IDENTIFIERS] = { |
| 82 "foo", | 82 "foo", |
| 83 "bar", | 83 "bar", |
| 84 "testObject", | 84 "testObject", |
| 85 "refCount", | 85 "refCount", |
| 86 "objectPointer", | 86 "objectPointer", |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 #define ID_THROW_EXCEPTION_METHOD 0 | 89 #define ID_THROW_EXCEPTION_METHOD 0 |
| 90 #define NUM_METHOD_IDENTIFIERS 1 | 90 #define ID_PAGE_TEST_OBJECT_METHOD 1 |
| 91 #define NUM_METHOD_IDENTIFIERS 2 |
| 91 | 92 |
| 92 static NPIdentifier testMethodIdentifiers[NUM_METHOD_IDENTIFIERS]; | 93 static NPIdentifier testMethodIdentifiers[NUM_METHOD_IDENTIFIERS]; |
| 93 static const NPUTF8 *testMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = { | 94 static const NPUTF8 *testMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = { |
| 94 "throwException", | 95 "throwException", |
| 96 "pageTestObject", |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 static void initializeIdentifiers(void) | 99 static void initializeIdentifiers(void) |
| 98 { | 100 { |
| 99 browser->getstringidentifiers(testIdentifierNames, NUM_TEST_IDENTIFIERS, tes
tIdentifiers); | 101 browser->getstringidentifiers(testIdentifierNames, NUM_TEST_IDENTIFIERS, tes
tIdentifiers); |
| 100 browser->getstringidentifiers(testMethodIdentifierNames, NUM_METHOD_IDENTIFI
ERS, testMethodIdentifiers); | 102 browser->getstringidentifiers(testMethodIdentifierNames, NUM_METHOD_IDENTIFI
ERS, testMethodIdentifiers); |
| 101 } | 103 } |
| 102 | 104 |
| 103 static NPObject *testAllocate(NPP npp, NPClass *theClass) | 105 static NPObject *testAllocate(NPP npp, NPClass *theClass) |
| 104 { | 106 { |
| 105 TestObject *newInstance = | 107 TestObject *newInstance = |
| 106 static_cast<TestObject*>(malloc(sizeof(TestObject))); | 108 static_cast<TestObject*>(malloc(sizeof(TestObject))); |
| 109 newInstance->npp = npp; |
| 107 newInstance->testObject = NULL; | 110 newInstance->testObject = NULL; |
| 111 newInstance->testPageObject = NULL; |
| 108 ++testObjectCount; | 112 ++testObjectCount; |
| 109 | 113 |
| 110 if (!identifiersInitialized) { | 114 if (!identifiersInitialized) { |
| 111 identifiersInitialized = true; | 115 identifiersInitialized = true; |
| 112 initializeIdentifiers(); | 116 initializeIdentifiers(); |
| 113 } | 117 } |
| 114 | 118 |
| 115 return reinterpret_cast<NPObject*>(newInstance); | 119 return reinterpret_cast<NPObject*>(newInstance); |
| 116 } | 120 } |
| 117 | 121 |
| 118 static void testDeallocate(NPObject *obj) | 122 static void testDeallocate(NPObject *obj) |
| 119 { | 123 { |
| 120 TestObject *testObject = reinterpret_cast<TestObject*>(obj); | 124 TestObject *testObject = reinterpret_cast<TestObject*>(obj); |
| 121 if (testObject->testObject) | 125 if (testObject->testObject) |
| 122 browser->releaseobject(testObject->testObject); | 126 browser->releaseobject(testObject->testObject); |
| 127 if (testObject->testPageObject) |
| 128 browser->releaseobject(testObject->testPageObject); |
| 123 --testObjectCount; | 129 --testObjectCount; |
| 124 free(obj); | 130 free(obj); |
| 125 } | 131 } |
| 126 | 132 |
| 127 static bool testHasMethod(NPObject*, NPIdentifier name) | 133 static bool testHasMethod(NPObject*, NPIdentifier name) |
| 128 { | 134 { |
| 129 for (unsigned i = 0; i < NUM_METHOD_IDENTIFIERS; i++) { | 135 for (unsigned i = 0; i < NUM_METHOD_IDENTIFIERS; i++) { |
| 130 if (testMethodIdentifiers[i] == name) | 136 if (testMethodIdentifiers[i] == name) |
| 131 return true; | 137 return true; |
| 132 } | 138 } |
| 133 return false; | 139 return false; |
| 134 } | 140 } |
| 135 | 141 |
| 136 static bool testInvoke(NPObject* header, NPIdentifier name, const NPVariant* /*a
rgs*/, uint32_t /*argCount*/, NPVariant* /*result*/) | 142 static bool testInvoke(NPObject* header, NPIdentifier name, const NPVariant* /*a
rgs*/, uint32_t /*argCount*/, NPVariant* /*result*/) |
| 137 { | 143 { |
| 138 if (name == testMethodIdentifiers[ID_THROW_EXCEPTION_METHOD]) { | 144 if (name == testMethodIdentifiers[ID_THROW_EXCEPTION_METHOD]) { |
| 139 browser->setexception(header, "test object throwException SUCCESS"); | 145 browser->setexception(header, "test object throwException SUCCESS"); |
| 140 return true; | 146 return true; |
| 147 } else if (name == testMethodIdentifiers[ID_PAGE_TEST_OBJECT_METHOD]) { |
| 148 TestObject* testObject = reinterpret_cast<TestObject*>(header); |
| 149 if (testObject->testPageObject == NULL) { |
| 150 NPObject *windowScriptObject; |
| 151 browser->getvalue(testObject->npp, NPNVWindowNPObject, &windowScriptOb
ject); |
| 152 |
| 153 NPIdentifier pageMethod = browser->getstringidentifier("dummyMethod"); |
| 154 |
| 155 NPVariant functionPointer; |
| 156 browser->invoke(testObject->npp, windowScriptObject, pageMethod, |
| 157 NULL, 0, &functionPointer); |
| 158 |
| 159 if (NPVARIANT_IS_OBJECT(functionPointer)) |
| 160 testObject->testPageObject = NPVARIANT_TO_OBJECT(functionPointer); |
| 161 |
| 162 return true; |
| 163 } |
| 141 } | 164 } |
| 142 return false; | 165 return false; |
| 143 } | 166 } |
| 144 | 167 |
| 145 static bool testInvokeDefault(NPObject *obj, const NPVariant *args, | 168 static bool testInvokeDefault(NPObject *obj, const NPVariant *args, |
| 146 uint32_t argCount, NPVariant *result) | 169 uint32_t argCount, NPVariant *result) |
| 147 { | 170 { |
| 148 INT32_TO_NPVARIANT(2, *result); | 171 INT32_TO_NPVARIANT(2, *result); |
| 149 return true; | 172 return true; |
| 150 } | 173 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 static bool testConstruct(NPObject* npobj, const NPVariant* args, uint32_t argCo
unt, NPVariant* result) | 224 static bool testConstruct(NPObject* npobj, const NPVariant* args, uint32_t argCo
unt, NPVariant* result) |
| 202 { | 225 { |
| 203 browser->retainobject(npobj); | 226 browser->retainobject(npobj); |
| 204 | 227 |
| 205 // Just return the same object. | 228 // Just return the same object. |
| 206 OBJECT_TO_NPVARIANT(npobj, *result); | 229 OBJECT_TO_NPVARIANT(npobj, *result); |
| 207 return true; | 230 return true; |
| 208 } | 231 } |
| 209 | 232 |
| 210 | 233 |
| OLD | NEW |