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