1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
24 * Stephen Mak <smak@sun.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
43 * Netscape Client Plugin API
44 * - Function that need to be implemented by plugin developers
46 * This file defines a "shell" plugin that plugin developers can use
47 * as the basis for a real plugin. This shell just provides empty
48 * implementations of all functions that the plugin can implement
49 * that will be called by Netscape (the NPP_xxx methods defined in
52 * dp Suresh <dp@netscape.com>
53 * updated 5/1998 <pollmann@netscape.com>
54 * updated 9/2000 <smak@sun.com>
61 #include "nullplugin.h"
65 /***********************************************************************
67 * Implementations of plugin API functions
69 ***********************************************************************/
72 NPP_GetMIMEDescription(void)
74 return(MIME_TYPES_HANDLED
);
78 NPP_GetValue(NPP instance
, NPPVariable variable
, void *value
)
80 NPError err
= NPERR_NO_ERROR
;
83 case NPPVpluginNameString
:
84 *((char **)value
) = PLUGIN_NAME
;
86 case NPPVpluginDescriptionString
:
87 *((char **)value
) = PLUGIN_DESCRIPTION
;
90 err
= NPERR_GENERIC_ERROR
;
99 return NPERR_NO_ERROR
;
108 NPP_New(NPMIMEType pluginType
,
117 PluginInstance
* This
;
119 if (instance
== NULL
)
120 return NPERR_INVALID_INSTANCE_ERROR
;
122 instance
->pdata
= NPN_MemAlloc(sizeof(PluginInstance
));
124 This
= (PluginInstance
*) instance
->pdata
;
128 return NPERR_OUT_OF_MEMORY_ERROR
;
131 memset(This
, 0, sizeof(PluginInstance
));
133 /* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
135 This
->type
= dupMimeType(pluginType
);
136 This
->instance
= instance
;
137 This
->pluginsPageUrl
= NULL
;
138 This
->exists
= FALSE
;
140 /* Parse argument list passed to plugin instance */
141 /* We are interested in these arguments
142 * PLUGINSPAGE = <url>
147 if (argv
[argc
] != NULL
)
149 if (!PL_strcasecmp(argn
[argc
], "PLUGINSPAGE"))
150 This
->pluginsPageUrl
= strdup(argv
[argc
]);
151 else if (!PL_strcasecmp(argn
[argc
], "PLUGINURL"))
152 This
->pluginsFileUrl
= strdup(argv
[argc
]);
153 else if (!PL_strcasecmp(argn
[argc
], "CODEBASE"))
154 This
->pluginsPageUrl
= strdup(argv
[argc
]);
155 else if (!PL_strcasecmp(argn
[argc
], "CLASSID"))
156 This
->pluginsFileUrl
= strdup(argv
[argc
]);
157 else if (!PL_strcasecmp(argn
[argc
], "HIDDEN"))
158 This
->pluginsHidden
= (!PL_strcasecmp(argv
[argc
],
163 return NPERR_NO_ERROR
;
167 NPP_Destroy(NPP instance
, NPSavedData
** save
)
170 PluginInstance
* This
;
172 if (instance
== NULL
)
173 return NPERR_INVALID_INSTANCE_ERROR
;
175 This
= (PluginInstance
*) instance
->pdata
;
181 NPN_MemFree(This
->type
);
182 if (This
->pluginsPageUrl
)
183 NPN_MemFree(This
->pluginsPageUrl
);
184 if (This
->pluginsFileUrl
)
185 NPN_MemFree(This
->pluginsFileUrl
);
186 NPN_MemFree(instance
->pdata
);
187 instance
->pdata
= NULL
;
190 return NPERR_NO_ERROR
;
195 NPP_SetWindow(NPP instance
, NPWindow
* window
)
197 PluginInstance
* This
;
198 NPSetWindowCallbackStruct
*ws_info
;
200 if (instance
== NULL
)
201 return NPERR_INVALID_INSTANCE_ERROR
;
203 This
= (PluginInstance
*) instance
->pdata
;
206 return NPERR_INVALID_INSTANCE_ERROR
;
208 ws_info
= (NPSetWindowCallbackStruct
*)window
->ws_info
;
211 if (This
->window
== (Window
) window
->window
) {
212 /* The page with the plugin is being resized.
213 Save any UI information because the next time
214 around expect a SetWindow with a new window
218 fprintf(stderr
, "Nullplugin: plugin received window resize.\n");
219 fprintf(stderr
, "Window=(%i)\n", (int)window
);
220 fprintf(stderr
, "W=(%i) H=(%i)\n",
221 (int)window
->width
, (int)window
->height
);
223 return NPERR_NO_ERROR
;
226 This
->window
= (Window
) window
->window
;
229 This
->width
= window
->width
;
230 This
->height
= window
->height
;
231 This
->display
= ws_info
->display
;
232 This
->visual
= ws_info
->visual
;
233 This
->depth
= ws_info
->depth
;
234 This
->colormap
= ws_info
->colormap
;
238 #endif /* #ifdef MOZ_X11 */
240 return NPERR_NO_ERROR
;
245 NPP_NewStream(NPP instance
,
251 if (instance
== NULL
)
252 return NPERR_INVALID_INSTANCE_ERROR
;
254 return NPERR_NO_ERROR
;
259 NPP_WriteReady(NPP instance
, NPStream
*stream
)
261 if (instance
== NULL
)
262 return NPERR_INVALID_INSTANCE_ERROR
;
264 /* We don't want any data, kill the stream */
265 NPN_DestroyStream(instance
, stream
, NPRES_DONE
);
267 /* Number of bytes ready to accept in NPP_Write() */
268 return -1L; /* don't accept any bytes in NPP_Write() */
273 NPP_Write(NPP instance
, NPStream
*stream
, int32_t offset
, int32_t len
, void *buffer
)
275 if (instance
== NULL
)
276 return NPERR_INVALID_INSTANCE_ERROR
;
278 /* We don't want any data, kill the stream */
279 NPN_DestroyStream(instance
, stream
, NPRES_DONE
);
281 return -1L; /* don't accept any bytes in NPP_Write() */
286 NPP_DestroyStream(NPP instance
, NPStream
*stream
, NPError reason
)
288 if (instance
== NULL
)
289 return NPERR_INVALID_INSTANCE_ERROR
;
291 /***** Insert NPP_DestroyStream code here *****\
292 PluginInstance* This;
293 This = (PluginInstance*) instance->pdata;
294 \**********************************************/
296 return NPERR_NO_ERROR
;
301 NPP_StreamAsFile(NPP instance
, NPStream
*stream
, const char* fname
)
303 /***** Insert NPP_StreamAsFile code here *****\
304 PluginInstance* This;
305 if (instance != NULL)
306 This = (PluginInstance*) instance->pdata;
307 \*********************************************/
312 NPP_URLNotify(NPP instance
, const char* url
,
313 NPReason reason
, void* notifyData
)
315 /***** Insert NPP_URLNotify code here *****\
316 PluginInstance* This;
317 if (instance != NULL)
318 This = (PluginInstance*) instance->pdata;
319 \*********************************************/
324 NPP_Print(NPP instance
, NPPrint
* printInfo
)
326 if(printInfo
== NULL
)
329 if (instance
!= NULL
) {
330 /***** Insert NPP_Print code here *****\
331 PluginInstance* This = (PluginInstance*) instance->pdata;
332 \**************************************/
334 if (printInfo
->mode
== NP_FULL
) {
337 * If your plugin would like to take over
338 * printing completely when it is in full-screen mode,
339 * set printInfo->pluginPrinted to TRUE and print your
340 * plugin as you see fit. If your plugin wants Netscape
341 * to handle printing in this case, set
342 * printInfo->pluginPrinted to FALSE (the default) and
343 * do nothing. If you do want to handle printing
344 * yourself, printOne is true if the print button
345 * (as opposed to the print menu) was clicked.
346 * On the Macintosh, platformPrint is a THPrint; on
347 * Windows, platformPrint is a structure
348 * (defined in npapi.h) containing the printer name, port,
352 /***** Insert NPP_Print code here *****\
353 void* platformPrint =
354 printInfo->print.fullPrint.platformPrint;
356 printInfo->print.fullPrint.printOne;
357 \**************************************/
360 printInfo
->print
.fullPrint
.pluginPrinted
= FALSE
;
362 else { /* If not fullscreen, we must be embedded */
365 * If your plugin is embedded, or is full-screen
366 * but you returned false in pluginPrinted above, NPP_Print
367 * will be called with mode == NP_EMBED. The NPWindow
368 * in the printInfo gives the location and dimensions of
369 * the embedded plugin on the printed page. On the
370 * Macintosh, platformPrint is the printer port; on
371 * Windows, platformPrint is the handle to the printing
375 /***** Insert NPP_Print code here *****\
376 NPWindow* printWindow =
377 &(printInfo->print.embedPrint.window);
378 void* platformPrint =
379 printInfo->print.embedPrint.platformPrint;
380 \**************************************/