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 <stdlib.h>
35 #include "main.h"
36 #include "PluginObject.h"
37
38 static void pluginInvalidate(NPObject *obj);
39 static bool pluginHasProperty(NPObject *obj, NPIdentifier name);
40 static bool pluginHasMethod(NPObject *obj, NPIdentifier name);
41 static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant);
42 static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant);
43 static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result);
44 static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
45 static NPObject *pluginAllocate(NPP npp, NPClass *theClass);
46 static void pluginDeallocate(NPObject *obj);
47 static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name);
48 static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count);
49
50
51
52 static NPClass pluginClass = {
53 NP_CLASS_STRUCT_VERSION,
54 pluginAllocate,
55 pluginDeallocate,
56 pluginInvalidate,
57 pluginHasMethod,
58 pluginInvoke,
59 pluginInvokeDefault,
60 pluginHasProperty,
61 pluginGetProperty,
62 pluginSetProperty,
63 pluginRemoveProperty,
64 pluginEnumerate
65 };
66
getPluginClass(void)67 NPClass *getPluginClass(void)
68 {
69 return &pluginClass;
70 }
71
72 static bool identifiersInitialized = false;
73
74 #define ID_TESTFILE_PROPERTY 0
75 #define NUM_PROPERTY_IDENTIFIERS 1
76
77 static NPIdentifier pluginPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS];
78 static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
79 "testfile"
80 };
81
82 #define ID_GETTESTFILE_METHOD 0
83 #define NUM_METHOD_IDENTIFIERS 1
84
85 static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
86 static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
87 "getTestFile"
88 };
89
initializeIdentifiers(void)90 static void initializeIdentifiers(void)
91 {
92 browser->getstringidentifiers(pluginPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, pluginPropertyIdentifiers);
93 browser->getstringidentifiers(pluginMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, pluginMethodIdentifiers);
94 }
95
pluginHasProperty(NPObject * obj,NPIdentifier name)96 static bool pluginHasProperty(NPObject *obj, NPIdentifier name)
97 {
98 int i;
99 for (i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++)
100 if (name == pluginPropertyIdentifiers[i])
101 return true;
102 return false;
103 }
104
pluginHasMethod(NPObject * obj,NPIdentifier name)105 static bool pluginHasMethod(NPObject *obj, NPIdentifier name)
106 {
107 int i;
108 for (i = 0; i < NUM_METHOD_IDENTIFIERS; i++)
109 if (name == pluginMethodIdentifiers[i])
110 return true;
111 return false;
112 }
113
pluginGetProperty(NPObject * obj,NPIdentifier name,NPVariant * variant)114 static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant)
115 {
116 PluginObject *plugin = (PluginObject *)obj;
117 if (name == pluginPropertyIdentifiers[ID_TESTFILE_PROPERTY]) {
118 BOOLEAN_TO_NPVARIANT(true, *variant);
119 return true;
120 }
121 return false;
122 }
123
pluginSetProperty(NPObject * obj,NPIdentifier name,const NPVariant * variant)124 static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant)
125 {
126 return false;
127 }
128
pluginInvoke(NPObject * obj,NPIdentifier name,const NPVariant * args,uint32_t argCount,NPVariant * result)129 static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
130 {
131 PluginObject *plugin = (PluginObject *)obj;
132 if (name == pluginMethodIdentifiers[ID_GETTESTFILE_METHOD]) {
133 return true;
134 }
135 return false;
136 }
137
pluginInvokeDefault(NPObject * obj,const NPVariant * args,uint32_t argCount,NPVariant * result)138 static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result)
139 {
140 return false;
141 }
142
pluginInvalidate(NPObject * obj)143 static void pluginInvalidate(NPObject *obj)
144 {
145 // Release any remaining references to JavaScript objects.
146 }
147
pluginAllocate(NPP npp,NPClass * theClass)148 static NPObject *pluginAllocate(NPP npp, NPClass *theClass)
149 {
150 PluginObject *newInstance = (PluginObject*) malloc(sizeof(PluginObject));
151 newInstance->header._class = theClass;
152 newInstance->header.referenceCount = 1;
153
154 if (!identifiersInitialized) {
155 identifiersInitialized = true;
156 initializeIdentifiers();
157 }
158
159 newInstance->npp = npp;
160
161 return &newInstance->header;
162 }
163
pluginDeallocate(NPObject * obj)164 static void pluginDeallocate(NPObject *obj)
165 {
166 free(obj);
167 }
168
pluginRemoveProperty(NPObject * npobj,NPIdentifier name)169 static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name)
170 {
171 return false;
172 }
173
pluginEnumerate(NPObject * npobj,NPIdentifier ** value,uint32_t * count)174 static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count)
175 {
176 return false;
177 }
178