| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /* | 5 /* |
| 6 * Copyright (C) 2007 Apple Inc. All rights reserved. | 6 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| 11 * 1. Redistributions of source code must retain the above copyright | 11 * 1. Redistributions of source code must retain the above copyright |
| 12 * notice, this list of conditions and the following disclaimer. | 12 * notice, this list of conditions and the following disclaimer. |
| 13 * 2. Redistributions in binary form must reproduce the above copyright | 13 * 2. Redistributions in binary form must reproduce the above copyright |
| 14 * notice, this list of conditions and the following disclaimer in the | 14 * notice, this list of conditions and the following disclaimer in the |
| 15 * documentation and/or other materials provided with the distribution. | 15 * documentation and/or other materials provided with the distribution. |
| 16 * | 16 * |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 17 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "TestObject.h" | 30 #include "content/shell/tools/plugin/test_object.h" |
| 31 |
| 31 #include "PluginObject.h" | 32 #include "PluginObject.h" |
| 32 | 33 |
| 33 #include <string.h> | 34 #include <string.h> |
| 34 #include <stdlib.h> | 35 #include <stdlib.h> |
| 35 | 36 |
| 36 static bool testEnumerate(NPObject* npobj, | 37 static bool testEnumerate(NPObject* npobj, |
| 37 NPIdentifier** value, | 38 NPIdentifier** value, |
| 38 uint32_t* count); | 39 uint32_t* count); |
| 39 static bool testHasMethod(NPObject*, NPIdentifier name); | 40 static bool testHasMethod(NPObject*, NPIdentifier name); |
| 40 static bool testInvoke(NPObject*, | 41 static bool testInvoke(NPObject*, |
| 41 NPIdentifier name, | 42 NPIdentifier name, |
| 42 const NPVariant* args, | 43 const NPVariant* args, |
| 43 uint32_t argCount, | 44 uint32_t argCount, |
| 44 NPVariant* result); | 45 NPVariant* result); |
| 45 static bool testHasProperty(NPObject*, NPIdentifier name); | 46 static bool testHasProperty(NPObject*, NPIdentifier name); |
| 46 static bool testGetProperty(NPObject*, NPIdentifier name, NPVariant*); | 47 static bool testGetProperty(NPObject*, NPIdentifier name, NPVariant*); |
| 47 static NPObject* testAllocate(NPP npp, NPClass* theClass); | 48 static NPObject* testAllocate(NPP npp, NPClass* theClass); |
| 48 static void testDeallocate(NPObject* obj); | 49 static void testDeallocate(NPObject* obj); |
| 49 static bool testConstruct(NPObject* obj, | 50 static bool testConstruct(NPObject* obj, |
| 50 const NPVariant* args, | 51 const NPVariant* args, |
| 51 uint32_t argCount, | 52 uint32_t argCount, |
| 52 NPVariant* result); | 53 NPVariant* result); |
| 53 | 54 |
| 54 static NPClass testClass = { | 55 static NPClass g_test_class = { |
| 55 NP_CLASS_STRUCT_VERSION, testAllocate, testDeallocate, 0, | 56 NP_CLASS_STRUCT_VERSION, testAllocate, testDeallocate, 0, |
| 56 testHasMethod, testInvoke, 0, testHasProperty, | 57 testHasMethod, testInvoke, 0, testHasProperty, |
| 57 testGetProperty, 0, 0, testEnumerate, | 58 testGetProperty, 0, 0, testEnumerate, |
| 58 testConstruct}; | 59 testConstruct}; |
| 59 | 60 |
| 60 NPClass* getTestClass(void) { return &testClass; } | |
| 61 | 61 |
| 62 static int testObjectCount = 0; | 62 static int g_test_object_count = 0; |
| 63 | |
| 64 int getTestObjectCount() { return testObjectCount; } | |
| 65 | 63 |
| 66 typedef struct { | 64 typedef struct { |
| 67 NPObject header; | 65 NPObject header; |
| 68 NPObject* testObject; | 66 NPObject* testObject; |
| 69 } TestObject; | 67 } TestObject; |
| 70 | 68 |
| 71 static bool identifiersInitialized = false; | 69 static bool identifiersInitialized = false; |
| 72 | 70 |
| 73 #define NUM_ENUMERATABLE_TEST_IDENTIFIERS 2 | 71 #define NUM_ENUMERATABLE_TEST_IDENTIFIERS 2 |
| 74 | 72 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 96 browser->getstringidentifiers( | 94 browser->getstringidentifiers( |
| 97 testIdentifierNames, NUM_TEST_IDENTIFIERS, testIdentifiers); | 95 testIdentifierNames, NUM_TEST_IDENTIFIERS, testIdentifiers); |
| 98 browser->getstringidentifiers( | 96 browser->getstringidentifiers( |
| 99 testMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, testMethodIdentifiers); | 97 testMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, testMethodIdentifiers); |
| 100 } | 98 } |
| 101 | 99 |
| 102 static NPObject* testAllocate(NPP npp, NPClass* /*theClass*/) { | 100 static NPObject* testAllocate(NPP npp, NPClass* /*theClass*/) { |
| 103 TestObject* newInstance = | 101 TestObject* newInstance = |
| 104 static_cast<TestObject*>(malloc(sizeof(TestObject))); | 102 static_cast<TestObject*>(malloc(sizeof(TestObject))); |
| 105 newInstance->testObject = 0; | 103 newInstance->testObject = 0; |
| 106 ++testObjectCount; | 104 ++g_test_object_count; |
| 107 | 105 |
| 108 if (!identifiersInitialized) { | 106 if (!identifiersInitialized) { |
| 109 identifiersInitialized = true; | 107 identifiersInitialized = true; |
| 110 initializeIdentifiers(); | 108 initializeIdentifiers(); |
| 111 } | 109 } |
| 112 | 110 |
| 113 return reinterpret_cast<NPObject*>(newInstance); | 111 return reinterpret_cast<NPObject*>(newInstance); |
| 114 } | 112 } |
| 115 | 113 |
| 116 static void testDeallocate(NPObject* obj) { | 114 static void testDeallocate(NPObject* obj) { |
| 117 TestObject* testObject = reinterpret_cast<TestObject*>(obj); | 115 TestObject* testObject = reinterpret_cast<TestObject*>(obj); |
| 118 if (testObject->testObject) | 116 if (testObject->testObject) |
| 119 browser->releaseobject(testObject->testObject); | 117 browser->releaseobject(testObject->testObject); |
| 120 | 118 |
| 121 --testObjectCount; | 119 --g_test_object_count; |
| 122 free(obj); | 120 free(obj); |
| 123 } | 121 } |
| 124 | 122 |
| 125 static bool testHasMethod(NPObject*, NPIdentifier name) { | 123 static bool testHasMethod(NPObject*, NPIdentifier name) { |
| 126 for (unsigned i = 0; i < NUM_METHOD_IDENTIFIERS; i++) { | 124 for (unsigned i = 0; i < NUM_METHOD_IDENTIFIERS; i++) { |
| 127 if (testMethodIdentifiers[i] == name) | 125 if (testMethodIdentifiers[i] == name) |
| 128 return true; | 126 return true; |
| 129 } | 127 } |
| 130 return false; | 128 return false; |
| 131 } | 129 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 if (name == testIdentifiers[ID_PROPERTY_OBJECT_POINTER]) { | 167 if (name == testIdentifiers[ID_PROPERTY_OBJECT_POINTER]) { |
| 170 int32_t objectPointer = | 168 int32_t objectPointer = |
| 171 static_cast<int32_t>(reinterpret_cast<long long>(npobj)); | 169 static_cast<int32_t>(reinterpret_cast<long long>(npobj)); |
| 172 | 170 |
| 173 INT32_TO_NPVARIANT(objectPointer, *result); | 171 INT32_TO_NPVARIANT(objectPointer, *result); |
| 174 return true; | 172 return true; |
| 175 } | 173 } |
| 176 if (name == testIdentifiers[ID_PROPERTY_TEST_OBJECT]) { | 174 if (name == testIdentifiers[ID_PROPERTY_TEST_OBJECT]) { |
| 177 TestObject* testObject = reinterpret_cast<TestObject*>(npobj); | 175 TestObject* testObject = reinterpret_cast<TestObject*>(npobj); |
| 178 if (!testObject->testObject) | 176 if (!testObject->testObject) |
| 179 testObject->testObject = browser->createobject(0, &testClass); | 177 testObject->testObject = browser->createobject(0, &g_test_class); |
| 180 browser->retainobject(testObject->testObject); | 178 browser->retainobject(testObject->testObject); |
| 181 OBJECT_TO_NPVARIANT(testObject->testObject, *result); | 179 OBJECT_TO_NPVARIANT(testObject->testObject, *result); |
| 182 return true; | 180 return true; |
| 183 } | 181 } |
| 184 if (name == testIdentifiers[ID_PROPERTY_REF_COUNT]) { | 182 if (name == testIdentifiers[ID_PROPERTY_REF_COUNT]) { |
| 185 INT32_TO_NPVARIANT(npobj->referenceCount, *result); | 183 INT32_TO_NPVARIANT(npobj->referenceCount, *result); |
| 186 return true; | 184 return true; |
| 187 } | 185 } |
| 188 | 186 |
| 189 return false; | 187 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 206 static bool testConstruct(NPObject* npobj, | 204 static bool testConstruct(NPObject* npobj, |
| 207 const NPVariant* /*args*/, | 205 const NPVariant* /*args*/, |
| 208 uint32_t /*argCount*/, | 206 uint32_t /*argCount*/, |
| 209 NPVariant* result) { | 207 NPVariant* result) { |
| 210 browser->retainobject(npobj); | 208 browser->retainobject(npobj); |
| 211 | 209 |
| 212 // Just return the same object. | 210 // Just return the same object. |
| 213 OBJECT_TO_NPVARIANT(npobj, *result); | 211 OBJECT_TO_NPVARIANT(npobj, *result); |
| 214 return true; | 212 return true; |
| 215 } | 213 } |
| 214 |
| 215 namespace content { |
| 216 |
| 217 NPClass* GetTestClass() { return &g_test_class; } |
| 218 |
| 219 int GetTestObjectCount() { return g_test_object_count; } |
| 220 |
| 221 } // namespace content |
| OLD | NEW |