blob: 7d92f7d801af3f6337dda9bb19ced6b441f4a996 [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
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
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
Grace Klobafbe47c02009-05-14 17:31:45 -070048static void pluginInvalidate(NPObject *obj);
49static bool pluginHasProperty(NPObject *obj, NPIdentifier name);
50static bool pluginHasMethod(NPObject *obj, NPIdentifier name);
51static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant);
52static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant);
53static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result);
54static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
55static NPObject *pluginAllocate(NPP npp, NPClass *theClass);
56static void pluginDeallocate(NPObject *obj);
57static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name);
58static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count);
59
60
61
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040062static NPClass pluginClass = {
Grace Klobafbe47c02009-05-14 17:31:45 -070063 NP_CLASS_STRUCT_VERSION,
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040064 pluginAllocate,
65 pluginDeallocate,
Grace Klobafbe47c02009-05-14 17:31:45 -070066 pluginInvalidate,
67 pluginHasMethod,
68 pluginInvoke,
69 pluginInvokeDefault,
70 pluginHasProperty,
71 pluginGetProperty,
72 pluginSetProperty,
73 pluginRemoveProperty,
74 pluginEnumerate
75};
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040076
Grace Klobafbe47c02009-05-14 17:31:45 -070077NPClass *getPluginClass(void)
78{
79 return &pluginClass;
80}
81
82static bool identifiersInitialized = false;
83
84#define ID_TESTFILE_PROPERTY 0
85#define NUM_PROPERTY_IDENTIFIERS 1
86
87static NPIdentifier pluginPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS];
88static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = {
89 "testfile"
90};
91
92#define ID_GETTESTFILE_METHOD 0
93#define NUM_METHOD_IDENTIFIERS 1
94
95static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
96static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
97 "getTestFile"
98};
99
100static void initializeIdentifiers(void)
101{
102 browser->getstringidentifiers(pluginPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, pluginPropertyIdentifiers);
103 browser->getstringidentifiers(pluginMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, pluginMethodIdentifiers);
104}
105
106static bool pluginHasProperty(NPObject *obj, NPIdentifier name)
107{
108 int i;
109 for (i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++)
110 if (name == pluginPropertyIdentifiers[i])
111 return true;
112 return false;
113}
114
115static bool pluginHasMethod(NPObject *obj, NPIdentifier name)
116{
117 int i;
118 for (i = 0; i < NUM_METHOD_IDENTIFIERS; i++)
119 if (name == pluginMethodIdentifiers[i])
120 return true;
121 return false;
122}
123
124static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant)
125{
126 PluginObject *plugin = (PluginObject *)obj;
127 if (name == pluginPropertyIdentifiers[ID_TESTFILE_PROPERTY]) {
128 BOOLEAN_TO_NPVARIANT(true, *variant);
129 return true;
130 }
131 return false;
132}
133
134static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant)
135{
136 return false;
137}
138
139static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
140{
141 PluginObject *plugin = (PluginObject *)obj;
142 if (name == pluginMethodIdentifiers[ID_GETTESTFILE_METHOD]) {
143 return true;
144 }
145 return false;
146}
147
148static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result)
149{
150 return false;
151}
152
153static void pluginInvalidate(NPObject *obj)
154{
155 // Release any remaining references to JavaScript objects.
156}
157
158static NPObject *pluginAllocate(NPP npp, NPClass *theClass)
159{
160 PluginObject *newInstance = (PluginObject*) malloc(sizeof(PluginObject));
161 newInstance->header._class = theClass;
162 newInstance->header.referenceCount = 1;
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400163
Grace Klobafbe47c02009-05-14 17:31:45 -0700164 if (!identifiersInitialized) {
165 identifiersInitialized = true;
166 initializeIdentifiers();
167 }
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400168
Grace Klobafbe47c02009-05-14 17:31:45 -0700169 newInstance->npp = npp;
170
171 return &newInstance->header;
172}
173
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400174static void pluginDeallocate(NPObject *obj)
Grace Klobafbe47c02009-05-14 17:31:45 -0700175{
176 free(obj);
177}
178
179static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name)
180{
181 return false;
182}
183
184static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count)
185{
186 return false;
187}