blob: dd0fbac578649828ca112e70fae84c8879fd4cdc [file] [log] [blame]
Grace Klobafbe47c02009-05-14 17:31:45 -07001/*
2 IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -04003 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
Grace Klobafbe47c02009-05-14 17:31:45 -07006 redistribute this Apple software.
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -04007
8 In consideration of your agreement to abide by the following terms, and subject to these
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -05009 terms, Apple grants you a personal, non-exclusive license, under Appleƕs copyrights in
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040010 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
Grace Klobafbe47c02009-05-14 17:31:45 -070016 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
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040018 herein, including but not limited to any patent rights that may be infringed by your
Grace Klobafbe47c02009-05-14 17:31:45 -070019 derivative works or by other works in which the Apple Software may be incorporated.
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040020
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
Grace Klobafbe47c02009-05-14 17:31:45 -070024 USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040025
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
Grace Klobafbe47c02009-05-14 17:31:45 -070031 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
Derek Sollenbergerbb660dd2009-10-13 11:43:48 -040038int SubPlugin::getPluginWidth() {
39 PluginObject *obj = (PluginObject*) inst()->pdata;
40 return obj->window->width;
41}
42
43int SubPlugin::getPluginHeight() {
44 PluginObject *obj = (PluginObject*) inst()->pdata;
45 return obj->window->height;
46}
47
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -050048bool SurfaceSubPlugin::supportsDrawingModel(ANPDrawingModel model) {
49 return (model == kSurface_ANPDrawingModel);
50}
Derek Sollenberger51cce582009-12-01 08:26:20 -050051
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -050052void SurfaceSubPlugin::setContext(jobject context) {
Derek Sollenberger51cce582009-12-01 08:26:20 -050053 JNIEnv* env = NULL;
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -050054 if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) {
Derek Sollenberger51cce582009-12-01 08:26:20 -050055
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -050056 // if one exists then free its global reference
57 if (m_context) {
58 env->DeleteGlobalRef(m_context);
59 m_context = NULL;
60 }
Derek Sollenberger51cce582009-12-01 08:26:20 -050061
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -050062 // create a new global ref
63 if (context) {
64 context = env->NewGlobalRef(context);
65 }
66
67 // set the value
68 m_context = context;
Derek Sollenberger51cce582009-12-01 08:26:20 -050069 }
Derek Sollenberger51cce582009-12-01 08:26:20 -050070}
71
Grace Klobafbe47c02009-05-14 17:31:45 -070072static void pluginInvalidate(NPObject *obj);
73static bool pluginHasProperty(NPObject *obj, NPIdentifier name);
74static bool pluginHasMethod(NPObject *obj, NPIdentifier name);
75static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant);
76static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant);
77static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result);
78static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
79static NPObject *pluginAllocate(NPP npp, NPClass *theClass);
80static void pluginDeallocate(NPObject *obj);
81static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name);
82static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count);
83
84
85
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040086static NPClass pluginClass = {
Grace Klobafbe47c02009-05-14 17:31:45 -070087 NP_CLASS_STRUCT_VERSION,
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040088 pluginAllocate,
89 pluginDeallocate,
Grace Klobafbe47c02009-05-14 17:31:45 -070090 pluginInvalidate,
91 pluginHasMethod,
92 pluginInvoke,
93 pluginInvokeDefault,
94 pluginHasProperty,
95 pluginGetProperty,
96 pluginSetProperty,
97 pluginRemoveProperty,
98 pluginEnumerate
99};
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400100
Grace Klobafbe47c02009-05-14 17:31:45 -0700101NPClass *getPluginClass(void)
102{
103 return &pluginClass;
104}
105
106static bool identifiersInitialized = false;
107
108#define ID_TESTFILE_PROPERTY 0
109#define NUM_PROPERTY_IDENTIFIERS 1
110
111static NPIdentifier pluginPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS];
112static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
113 "testfile"
114};
115
116#define ID_GETTESTFILE_METHOD 0
117#define NUM_METHOD_IDENTIFIERS 1
118
119static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
120static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
121 "getTestFile"
122};
123
124static void initializeIdentifiers(void)
125{
126 browser->getstringidentifiers(pluginPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, pluginPropertyIdentifiers);
127 browser->getstringidentifiers(pluginMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, pluginMethodIdentifiers);
128}
129
130static bool pluginHasProperty(NPObject *obj, NPIdentifier name)
131{
132 int i;
133 for (i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++)
134 if (name == pluginPropertyIdentifiers[i])
135 return true;
136 return false;
137}
138
139static bool pluginHasMethod(NPObject *obj, NPIdentifier name)
140{
141 int i;
142 for (i = 0; i < NUM_METHOD_IDENTIFIERS; i++)
143 if (name == pluginMethodIdentifiers[i])
144 return true;
145 return false;
146}
147
148static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant)
149{
150 PluginObject *plugin = (PluginObject *)obj;
151 if (name == pluginPropertyIdentifiers[ID_TESTFILE_PROPERTY]) {
152 BOOLEAN_TO_NPVARIANT(true, *variant);
153 return true;
154 }
155 return false;
156}
157
158static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant)
159{
160 return false;
161}
162
163static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
164{
165 PluginObject *plugin = (PluginObject *)obj;
166 if (name == pluginMethodIdentifiers[ID_GETTESTFILE_METHOD]) {
167 return true;
168 }
169 return false;
170}
171
172static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result)
173{
174 return false;
175}
176
177static void pluginInvalidate(NPObject *obj)
178{
179 // Release any remaining references to JavaScript objects.
180}
181
182static NPObject *pluginAllocate(NPP npp, NPClass *theClass)
183{
184 PluginObject *newInstance = (PluginObject*) malloc(sizeof(PluginObject));
185 newInstance->header._class = theClass;
186 newInstance->header.referenceCount = 1;
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400187
Grace Klobafbe47c02009-05-14 17:31:45 -0700188 if (!identifiersInitialized) {
189 identifiersInitialized = true;
190 initializeIdentifiers();
191 }
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400192
Grace Klobafbe47c02009-05-14 17:31:45 -0700193 newInstance->npp = npp;
194
195 return &newInstance->header;
196}
197
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400198static void pluginDeallocate(NPObject *obj)
Grace Klobafbe47c02009-05-14 17:31:45 -0700199{
200 free(obj);
201}
202
203static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name)
204{
205 return false;
206}
207
208static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count)
209{
210 return false;
211}