|
1 /* |
|
2 IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in |
|
3 consideration of your agreement to the following terms, and your use, installation, |
|
4 modification or redistribution of this Apple software constitutes acceptance of these |
|
5 terms. If you do not agree with these terms, please do not use, install, modify or |
|
6 redistribute this Apple software. |
|
7 |
|
8 In consideration of your agreement to abide by the following terms, and subject to these |
|
9 terms, Apple grants you a personal, non-exclusive license, under Appleās copyrights in |
|
10 this original Apple software (the "Apple Software"), to use, reproduce, modify and |
|
11 redistribute the Apple Software, with or without modifications, in source and/or binary |
|
12 forms; provided that if you redistribute the Apple Software in its entirety and without |
|
13 modifications, you must retain this notice and the following text and disclaimers in all |
|
14 such redistributions of the Apple Software. Neither the name, trademarks, service marks |
|
15 or logos of Apple Computer, Inc. may be used to endorse or promote products derived from |
|
16 the Apple Software without specific prior written permission from Apple. Except as expressly |
|
17 stated in this notice, no other rights or licenses, express or implied, are granted by Apple |
|
18 herein, including but not limited to any patent rights that may be infringed by your |
|
19 derivative works or by other works in which the Apple Software may be incorporated. |
|
20 |
|
21 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, |
|
22 EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, |
|
23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS |
|
24 USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
|
25 |
|
26 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL |
|
27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
|
28 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, |
|
29 REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND |
|
30 WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR |
|
31 OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 */ |
|
33 |
|
34 #include "TestObject.h" |
|
35 #include "PluginObject.h" |
|
36 |
|
37 static bool testEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count); |
|
38 static bool testHasProperty(NPObject *obj, NPIdentifier name); |
|
39 static NPObject *testAllocate(NPP npp, NPClass *theClass); |
|
40 static void testDeallocate(NPObject *obj); |
|
41 |
|
42 static NPClass testClass = { |
|
43 NP_CLASS_STRUCT_VERSION, |
|
44 testAllocate, |
|
45 testDeallocate, |
|
46 0, |
|
47 0, |
|
48 0, |
|
49 0, |
|
50 testHasProperty, |
|
51 0, |
|
52 0, |
|
53 0, |
|
54 testEnumerate |
|
55 }; |
|
56 |
|
57 NPClass *getTestClass(void) |
|
58 { |
|
59 return &testClass; |
|
60 } |
|
61 |
|
62 static bool identifiersInitialized = false; |
|
63 |
|
64 #define NUM_TEST_IDENTIFIERS 2 |
|
65 |
|
66 static NPIdentifier testIdentifiers[NUM_TEST_IDENTIFIERS]; |
|
67 static const NPUTF8 *testIdentifierNames[NUM_TEST_IDENTIFIERS] = { |
|
68 "foo", |
|
69 "bar" |
|
70 }; |
|
71 |
|
72 static void initializeIdentifiers(void) |
|
73 { |
|
74 browser->getstringidentifiers(testIdentifierNames, NUM_TEST_IDENTIFIERS, testIdentifiers); |
|
75 } |
|
76 |
|
77 static NPObject *testAllocate(NPP npp, NPClass *theClass) |
|
78 { |
|
79 NPObject *newInstance = (NPObject*)malloc(sizeof(NPObject)); |
|
80 |
|
81 if (!identifiersInitialized) { |
|
82 identifiersInitialized = true; |
|
83 initializeIdentifiers(); |
|
84 } |
|
85 |
|
86 return newInstance; |
|
87 } |
|
88 |
|
89 static void testDeallocate(NPObject *obj) |
|
90 { |
|
91 free(obj); |
|
92 } |
|
93 |
|
94 static bool testHasProperty(NPObject *obj, NPIdentifier name) |
|
95 { |
|
96 for (unsigned i = 0; i < NUM_TEST_IDENTIFIERS; i++) { |
|
97 if (testIdentifiers[i] == name) |
|
98 return true; |
|
99 } |
|
100 |
|
101 return false; |
|
102 } |
|
103 |
|
104 |
|
105 static bool testEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count) |
|
106 { |
|
107 *count = NUM_TEST_IDENTIFIERS; |
|
108 |
|
109 *value = (NPIdentifier*)browser->memalloc(NUM_TEST_IDENTIFIERS * sizeof(NPIdentifier)); |
|
110 memcpy(*value, testIdentifiers, sizeof(NPIdentifier) * NUM_TEST_IDENTIFIERS); |
|
111 |
|
112 return true; |
|
113 } |
|
114 |
|
115 |