No issues found
1 /*
2 * Copyright © 2007 Bastien Nocera <hadess@hadess.net>
3 * Copyright © 2005 Jorn Baayen <jbaayen@gnome.org>
4 * Copyright © 2005 Christian Persch
5 *
6 * Based on the work of:
7 *
8 * Copyright © 2004 Bastien Nocera <hadess@hadess.net>
9 * Copyright © 2002 David A. Schleef <ds@schleef.org>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
20 *
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
25 */
26
27 #include "config.h"
28
29 #define bool int
30 #include <string.h>
31 #include <npupp.h>
32
33 static NPNetscapeFuncs mozilla_functions;
34
35 static NPError
36 plugin_new_instance (NPMIMEType mime_type,
37 NPP instance,
38 uint16 mode,
39 int16 argc,
40 char **argn,
41 char **argv,
42 NPSavedData *saved)
43 {
44 return NPERR_INVALID_INSTANCE_ERROR;
45 }
46
47 static NPError
48 plugin_destroy_instance (NPP instance,
49 NPSavedData **save)
50 {
51 return NPERR_NO_ERROR;
52 }
53
54 static NPError
55 plugin_new_stream (NPP instance,
56 NPMIMEType type,
57 NPStream *stream_ptr,
58 NPBool seekable,
59 uint16 *stype)
60 {
61 return NPERR_INVALID_PARAM;
62 }
63
64 static NPError
65 plugin_stream_as_file (NPP instance,
66 NPStream* stream,
67 const char *filename)
68 {
69 return NPERR_INVALID_PARAM;
70 }
71
72 static NPError
73 plugin_destroy_stream (NPP instance,
74 NPStream *stream,
75 NPError reason)
76 {
77 return NPERR_NO_ERROR;
78 }
79
80 static int32
81 plugin_write_ready (NPP instance,
82 NPStream *stream)
83 {
84 return 0;
85 }
86
87 static int32
88 plugin_write (NPP instance,
89 NPStream *stream,
90 int32 offset,
91 int32 len,
92 void *buffer)
93 {
94 return -1;
95 }
96
97 static NPError
98 plugin_get_value (NPP instance,
99 NPPVariable variable,
100 void *value)
101 {
102 NPError err = NPERR_NO_ERROR;
103
104 switch (variable) {
105 case NPPVpluginNameString:
106 *((char **) value) = "iTunes Application Detector";
107 break;
108
109 case NPPVpluginDescriptionString:
110 *((char **) value) = "This plug-in detects the presence of iTunes when opening iTunes Store URLs in a web page with Firefox.";
111 break;
112
113 case NPPVpluginNeedsXEmbed:
114 *((NPBool *) value) = FALSE;
115 break;
116
117 default:
118 err = NPERR_INVALID_PARAM;
119 break;
120 }
121
122 return err;
123 }
124
125 NPError
126 NP_GetValue (void *future,
127 NPPVariable variable,
128 void *value)
129 {
130 return plugin_get_value (NULL, variable, value);
131 }
132
133 char *
134 NP_GetMIMEDescription (void)
135 {
136 return "application/itunes-plugin::;";
137 }
138
139 NPError
140 NP_Initialize (NPNetscapeFuncs *moz_funcs,
141 NPPluginFuncs *plugin_funcs)
142 {
143 if (moz_funcs == NULL || plugin_funcs == NULL)
144 return NPERR_INVALID_FUNCTABLE_ERROR;
145
146 if ((moz_funcs->version >> 8) > NP_VERSION_MAJOR)
147 return NPERR_INCOMPATIBLE_VERSION_ERROR;
148 if (moz_funcs->size < sizeof (NPNetscapeFuncs))
149 return NPERR_INVALID_FUNCTABLE_ERROR;
150 if (plugin_funcs->size < sizeof (NPPluginFuncs))
151 return NPERR_INVALID_FUNCTABLE_ERROR;
152
153 /*
154 * Copy all of the fields of the Mozilla function table into our
155 * copy so we can call back into Mozilla later. Note that we need
156 * to copy the fields one by one, rather than assigning the whole
157 * structure, because the Mozilla function table could actually be
158 * bigger than what we expect.
159 */
160 mozilla_functions.size = moz_funcs->size;
161 mozilla_functions.version = moz_funcs->version;
162 mozilla_functions.geturl = moz_funcs->geturl;
163 mozilla_functions.posturl = moz_funcs->posturl;
164 mozilla_functions.requestread = moz_funcs->requestread;
165 mozilla_functions.newstream = moz_funcs->newstream;
166 mozilla_functions.write = moz_funcs->write;
167 mozilla_functions.destroystream = moz_funcs->destroystream;
168 mozilla_functions.status = moz_funcs->status;
169 mozilla_functions.uagent = moz_funcs->uagent;
170 mozilla_functions.memalloc = moz_funcs->memalloc;
171 mozilla_functions.memfree = moz_funcs->memfree;
172 mozilla_functions.memflush = moz_funcs->memflush;
173 mozilla_functions.reloadplugins = moz_funcs->reloadplugins;
174 mozilla_functions.getJavaEnv = moz_funcs->getJavaEnv;
175 mozilla_functions.getJavaPeer = moz_funcs->getJavaPeer;
176 mozilla_functions.geturlnotify = moz_funcs->geturlnotify;
177 mozilla_functions.posturlnotify = moz_funcs->posturlnotify;
178 mozilla_functions.getvalue = moz_funcs->getvalue;
179 mozilla_functions.setvalue = moz_funcs->setvalue;
180 mozilla_functions.invalidaterect = moz_funcs->invalidaterect;
181 mozilla_functions.invalidateregion = moz_funcs->invalidateregion;
182 mozilla_functions.forceredraw = moz_funcs->forceredraw;
183 mozilla_functions.geturl = moz_funcs->geturl;
184
185 /*
186 * Set up a plugin function table that Mozilla will use to call
187 * into us. Mozilla needs to know about our version and size and
188 * have a UniversalProcPointer for every function we implement.
189 */
190
191 plugin_funcs->size = sizeof (NPPluginFuncs);
192 plugin_funcs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
193 plugin_funcs->newp = NewNPP_NewProc (plugin_new_instance);
194 plugin_funcs->destroy = NewNPP_DestroyProc (plugin_destroy_instance);
195 plugin_funcs->setwindow = NewNPP_SetWindowProc (NULL);
196 plugin_funcs->newstream = NewNPP_NewStreamProc (plugin_new_stream);
197 plugin_funcs->destroystream = NewNPP_DestroyStreamProc (plugin_destroy_stream);
198 plugin_funcs->asfile = NewNPP_StreamAsFileProc (plugin_stream_as_file);
199 plugin_funcs->writeready = NewNPP_WriteReadyProc (plugin_write_ready);
200 plugin_funcs->write = NewNPP_WriteProc (plugin_write);
201 plugin_funcs->print = NewNPP_PrintProc (NULL);
202 plugin_funcs->event = NewNPP_HandleEventProc (NULL);
203 plugin_funcs->urlnotify = NewNPP_URLNotifyProc (NULL);
204 plugin_funcs->javaClass = NULL;
205 plugin_funcs->getvalue = NewNPP_GetValueProc (plugin_get_value);
206 plugin_funcs->setvalue = NewNPP_SetValueProc (NULL);
207
208 return NPERR_NO_ERROR;
209 }
210
211 NPError
212 NP_Shutdown (void)
213 {
214 return NPERR_NO_ERROR;
215 }