Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / plugin / sdk / samples / unixprinting / npshell.c
blob4e52307b0724591273dbd9f481922b754c717c8c
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
14 * License.
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.
23 * Contributor(s):
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 ***** */
41 * npshell.c
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
50 * npapi.h).
52 * dp Suresh <dp@netscape.com>
53 * updated 5/1998 <pollmann@netscape.com>
54 * updated 9/2000 <smak@sun.com>
55 * updated 3/2004 <dantifer.dang@sun.com>
59 #include <stdio.h>
60 #include <string.h>
61 #include "npapi.h"
62 #include "printplugin.h"
63 #include "strings.h"
64 #include "plstr.h"
66 /***********************************************************************
68 * Implementations of plugin API functions
70 ***********************************************************************/
72 char*
73 NPP_GetMIMEDescription(void)
75 return(MIME_TYPES_HANDLED);
78 NPError
79 NPP_GetValue(NPP instance, NPPVariable variable, void *value)
81 NPError err = NPERR_NO_ERROR;
83 switch (variable) {
84 case NPPVpluginNameString:
85 *((char **)value) = PLUGIN_NAME;
86 break;
87 case NPPVpluginDescriptionString:
88 *((char **)value) = PLUGIN_DESCRIPTION;
89 break;
90 default:
91 err = NPERR_GENERIC_ERROR;
93 return err;
96 NPError
97 NPP_Initialize(void)
99 return NPERR_NO_ERROR;
102 void
103 NPP_Shutdown(void)
107 NPError
108 NPP_New(NPMIMEType pluginType,
109 NPP instance,
110 uint16_t mode,
111 int16_t argc,
112 char* argn[],
113 char* argv[],
114 NPSavedData* saved)
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;
126 if (This == NULL)
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) */
134 This->mode = mode;
135 This->type = dupMimeType(pluginType);
136 This->instance = instance;
137 This->pluginsPrintMessage = NULL;
138 This->exists = false;
140 /* Parse argument list passed to plugin instance */
141 /* We are interested in these arguments
142 * PLUGINSPAGE = <url>
144 while (argc > 0)
146 argc --;
147 if (argv[argc] != NULL)
149 if (!PL_strcasecmp(argn[argc], "PRINTMSG"))
150 This->pluginsPrintMessage = strdup(argv[argc]);
151 else if (!PL_strcasecmp(argn[argc], "HIDDEN"))
152 This->pluginsHidden = (!PL_strcasecmp(argv[argc],
153 "TRUE"));
157 return NPERR_NO_ERROR;
160 NPError
161 NPP_Destroy(NPP instance, NPSavedData** save)
164 PluginInstance* This;
166 if (instance == NULL)
167 return NPERR_INVALID_INSTANCE_ERROR;
169 This = (PluginInstance*) instance->pdata;
171 if (This != NULL) {
172 if (This->type)
173 NPN_MemFree(This->type);
174 if (This->pluginsPrintMessage)
175 NPN_MemFree(This->pluginsPrintMessage);
176 NPN_MemFree(instance->pdata);
177 instance->pdata = NULL;
180 return NPERR_NO_ERROR;
184 NPError
185 NPP_SetWindow(NPP instance, NPWindow* window)
187 PluginInstance* This;
188 NPSetWindowCallbackStruct *ws_info;
190 if (instance == NULL)
191 return NPERR_INVALID_INSTANCE_ERROR;
193 This = (PluginInstance*) instance->pdata;
195 if (This == NULL)
196 return NPERR_INVALID_INSTANCE_ERROR;
198 ws_info = (NPSetWindowCallbackStruct *)window->ws_info;
200 #ifdef MOZ_X11
201 if (This->window == (Window) window->window) {
202 /* The page with the plugin is being resized.
203 Save any UI information because the next time
204 around expect a SetWindow with a new window
207 #ifdef DEBUG
208 fprintf(stderr, "Printplugin: plugin received window resize.\n");
209 fprintf(stderr, "Window=(%i)\n", (int)window);
210 if (window) {
211 fprintf(stderr, "W=(%i) H=(%i)\n",
212 (int)window->width, (int)window->height);
214 #endif
215 return NPERR_NO_ERROR;
216 } else {
218 This->window = (Window) window->window;
219 This->x = window->x;
220 This->y = window->y;
221 This->width = window->width;
222 This->height = window->height;
223 This->display = ws_info->display;
224 This->visual = ws_info->visual;
225 This->depth = ws_info->depth;
226 This->colormap = ws_info->colormap;
227 printScreenMessage(This);
229 #endif /* #ifdef MOZ_X11 */
231 return NPERR_NO_ERROR;
235 NPError
236 NPP_NewStream(NPP instance,
237 NPMIMEType type,
238 NPStream *stream,
239 NPBool seekable,
240 uint16_t *stype)
242 if (instance == NULL)
243 return NPERR_INVALID_INSTANCE_ERROR;
245 return NPERR_NO_ERROR;
249 int32_t
250 NPP_WriteReady(NPP instance, NPStream *stream)
252 if (instance == NULL)
253 return NPERR_INVALID_INSTANCE_ERROR;
255 /* We don't want any data, kill the stream */
256 NPN_DestroyStream(instance, stream, NPRES_DONE);
258 /* Number of bytes ready to accept in NPP_Write() */
259 return -1L; /* don't accept any bytes in NPP_Write() */
263 int32_t
264 NPP_Write(NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer)
266 if (instance == NULL)
267 return NPERR_INVALID_INSTANCE_ERROR;
269 /* We don't want any data, kill the stream */
270 NPN_DestroyStream(instance, stream, NPRES_DONE);
272 return -1L; /* don't accept any bytes in NPP_Write() */
276 NPError
277 NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
279 if (instance == NULL)
280 return NPERR_INVALID_INSTANCE_ERROR;
282 /***** Insert NPP_DestroyStream code here *****\
283 PluginInstance* This;
284 This = (PluginInstance*) instance->pdata;
285 \**********************************************/
287 return NPERR_NO_ERROR;
291 void
292 NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
294 /***** Insert NPP_StreamAsFile code here *****\
295 PluginInstance* This;
296 if (instance != NULL)
297 This = (PluginInstance*) instance->pdata;
298 \*********************************************/
302 void
303 NPP_URLNotify(NPP instance, const char* url,
304 NPReason reason, void* notifyData)
306 /***** Insert NPP_URLNotify code here *****\
307 PluginInstance* This;
308 if (instance != NULL)
309 This = (PluginInstance*) instance->pdata;
310 \*********************************************/
314 void
315 NPP_Print(NPP instance, NPPrint* printInfo)
317 if(printInfo == NULL)
318 return;
320 if (instance != NULL) {
321 /***** Insert NPP_Print code here *****\
322 PluginInstance* This = (PluginInstance*) instance->pdata;
323 \**************************************/
325 if (printInfo->mode == NP_FULL) {
327 * PLUGIN DEVELOPERS:
328 * If your plugin would like to take over
329 * printing completely when it is in full-screen mode,
330 * set printInfo->pluginPrinted to TRUE and print your
331 * plugin as you see fit. If your plugin wants Netscape
332 * to handle printing in this case, set
333 * printInfo->pluginPrinted to false (the default) and
334 * do nothing. If you do want to handle printing
335 * yourself, printOne is true if the print button
336 * (as opposed to the print menu) was clicked.
337 * On the Macintosh, platformPrint is a THPrint; on
338 * Windows, platformPrint is a structure
339 * (defined in npapi.h) containing the printer name, port,
340 * etc.
343 /***** Insert NPP_Print code here *****\
344 void* platformPrint =
345 printInfo->print.fullPrint.platformPrint;
346 NPBool printOne =
347 printInfo->print.fullPrint.printOne;
348 \**************************************/
350 /* Do the default*/
351 printInfo->print.fullPrint.pluginPrinted = false;
353 else { /* If not fullscreen, we must be embedded */
355 * PLUGIN DEVELOPERS:
356 * If your plugin is embedded, or is full-screen
357 * but you returned false in pluginPrinted above, NPP_Print
358 * will be called with mode == NP_EMBED. The NPWindow
359 * in the printInfo gives the location and dimensions of
360 * the embedded plugin on the printed page. On the
361 * Macintosh, platformPrint is the printer port; on
362 * Windows, platformPrint is the handle to the printing
363 * device context.
366 /***** Insert NPP_Print code here *****\
367 NPWindow* printWindow =
368 &(printInfo->print.embedPrint.window);
369 void* platformPrint =
370 printInfo->print.embedPrint.platformPrint;
371 \**************************************/
372 PluginInstance* This;
373 NPPrintCallbackStruct* platformPrint;
374 FILE *output;
376 platformPrint =
377 (NPPrintCallbackStruct *)(printInfo->print.embedPrint.platformPrint);
379 output = (FILE*)(platformPrint->fp);
380 if (output == NULL)
381 return;
384 This = (PluginInstance*) instance->pdata;
385 if (This == NULL)
386 return;
388 printEPSMessage(This, output, printInfo->print.embedPrint.window);