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 "PluginObject.h"
35
36 #include <stdio.h>
37
38 extern "C"
NP_Initialize(NPNetscapeFuncs * browserFuncs)39 NPError __stdcall NP_Initialize(NPNetscapeFuncs* browserFuncs)
40 {
41 browser = browserFuncs;
42 return NPERR_NO_ERROR;
43 }
44
45 extern "C"
NP_GetEntryPoints(NPPluginFuncs * pluginFuncs)46 NPError __stdcall NP_GetEntryPoints(NPPluginFuncs* pluginFuncs)
47 {
48 pluginFuncs->version = 11;
49 pluginFuncs->size = sizeof(pluginFuncs);
50 pluginFuncs->newp = NPP_New;
51 pluginFuncs->destroy = NPP_Destroy;
52 pluginFuncs->setwindow = NPP_SetWindow;
53 pluginFuncs->newstream = NPP_NewStream;
54 pluginFuncs->destroystream = NPP_DestroyStream;
55 pluginFuncs->asfile = NPP_StreamAsFile;
56 pluginFuncs->writeready = NPP_WriteReady;
57 pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write;
58 pluginFuncs->print = NPP_Print;
59 pluginFuncs->event = NPP_HandleEvent;
60 pluginFuncs->urlnotify = NPP_URLNotify;
61 pluginFuncs->getvalue = NPP_GetValue;
62 pluginFuncs->setvalue = NPP_SetValue;
63
64 return NPERR_NO_ERROR;
65 }
66
67
68 extern "C"
NP_Shutdown()69 NPError __stdcall NP_Shutdown()
70 {
71 return NPERR_NO_ERROR;
72 }
73
74
NPP_New(NPMIMEType pluginType,NPP instance,uint16 mode,int16 argc,char * argn[],char * argv[],NPSavedData * saved)75 NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved)
76 {
77 if (browser->version >= 14) {
78 PluginObject* obj = (PluginObject*)browser->createobject(instance, getPluginClass());
79
80 for (int16 i = 0; i < argc; i++) {
81 if (_stricmp(argn[i], "onstreamload") == 0 && !obj->onStreamLoad)
82 obj->onStreamLoad = _strdup(argv[i]);
83 else if (_stricmp(argn[i], "onStreamDestroy") == 0 && !obj->onStreamDestroy)
84 obj->onStreamDestroy = _strdup(argv[i]);
85 else if (_stricmp(argn[i], "onURLNotify") == 0 && !obj->onURLNotify)
86 obj->onURLNotify = _strdup(argv[i]);
87 else if (_stricmp(argn[i], "logSrc") == 0) {
88 for (int i = 0; i < argc; i++)
89 if (_stricmp(argn[i], "src") == 0)
90 pluginLog(instance, "src: %s", argv[i]);
91 }
92 }
93
94 instance->pdata = obj;
95 }
96
97 return NPERR_NO_ERROR;
98 }
99
NPP_Destroy(NPP instance,NPSavedData ** save)100 NPError NPP_Destroy(NPP instance, NPSavedData **save)
101 {
102 PluginObject *obj = (PluginObject*)instance->pdata;
103 if (obj) {
104 if (obj->onStreamLoad)
105 free(obj->onStreamLoad);
106
107 if (obj->onURLNotify)
108 free(obj->onURLNotify);
109
110 if (obj->onStreamDestroy)
111 free(obj->onStreamDestroy);
112
113 if (obj->logDestroy)
114 printf("PLUGIN: NPP_Destroy\n");
115
116 browser->releaseobject(&obj->header);
117 }
118 return NPERR_NO_ERROR;
119 }
120
NPP_SetWindow(NPP instance,NPWindow * window)121 NPError NPP_SetWindow(NPP instance, NPWindow *window)
122 {
123 return NPERR_NO_ERROR;
124 }
125
executeScript(const PluginObject * obj,const char * script)126 static void executeScript(const PluginObject* obj, const char* script)
127 {
128 NPObject *windowScriptObject;
129 browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject);
130
131 NPString npScript;
132 npScript.UTF8Characters = script;
133 npScript.UTF8Length = strlen(script);
134
135 NPVariant browserResult;
136 browser->evaluate(obj->npp, windowScriptObject, &npScript, &browserResult);
137 browser->releasevariantvalue(&browserResult);
138 }
139
NPP_NewStream(NPP instance,NPMIMEType type,NPStream * stream,NPBool seekable,uint16 * stype)140 NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16 *stype)
141 {
142 PluginObject* obj = (PluginObject*)instance->pdata;
143
144 if (obj->returnErrorFromNewStream)
145 return NPERR_GENERIC_ERROR;
146
147 obj->stream = stream;
148 *stype = NP_ASFILEONLY;
149
150 if (obj->onStreamLoad)
151 executeScript(obj, obj->onStreamLoad);
152
153 return NPERR_NO_ERROR;
154 }
155
NPP_DestroyStream(NPP instance,NPStream * stream,NPReason reason)156 NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
157 {
158 PluginObject* obj = (PluginObject*)instance->pdata;
159
160 if (obj->onStreamDestroy)
161 executeScript(obj, obj->onStreamDestroy);
162
163 return NPERR_NO_ERROR;
164 }
165
NPP_WriteReady(NPP instance,NPStream * stream)166 int32 NPP_WriteReady(NPP instance, NPStream *stream)
167 {
168 return 0;
169 }
170
NPP_Write(NPP instance,NPStream * stream,int32 offset,int32 len,void * buffer)171 int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
172 {
173 return 0;
174 }
175
NPP_StreamAsFile(NPP instance,NPStream * stream,const char * fname)176 void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
177 {
178 }
179
NPP_Print(NPP instance,NPPrint * platformPrint)180 void NPP_Print(NPP instance, NPPrint *platformPrint)
181 {
182 }
183
NPP_HandleEvent(NPP instance,void * event)184 int16 NPP_HandleEvent(NPP instance, void *event)
185 {
186 PluginObject *obj = (PluginObject*)instance->pdata;
187 if (!obj->eventLogging)
188 return 0;
189
190 // FIXME: Implement this
191 return 0;
192 }
193
NPP_URLNotify(NPP instance,const char * url,NPReason reason,void * notifyData)194 void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
195 {
196 PluginObject *obj = (PluginObject*)instance->pdata;
197
198 if (obj->onURLNotify)
199 executeScript(obj, obj->onURLNotify);
200
201 handleCallback(obj, url, reason, notifyData);
202 }
203
NPP_GetValue(NPP instance,NPPVariable variable,void * value)204 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
205 {
206 if (variable == NPPVpluginScriptableNPObject) {
207 void **v = (void **)value;
208 PluginObject *obj = (PluginObject*)instance->pdata;
209 // Return value is expected to be retained
210 browser->retainobject((NPObject *)obj);
211 *v = obj;
212 return NPERR_NO_ERROR;
213 }
214 return NPERR_GENERIC_ERROR;
215 }
216
NPP_SetValue(NPP instance,NPNVariable variable,void * value)217 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
218 {
219 return NPERR_GENERIC_ERROR;
220 }
221