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>
55 * updated 3/2004 <dantifer.dang@sun.com>
62 #include "printplugin.h"
66 /***********************************************************************
68 * Implementations of plugin API functions
70 ***********************************************************************/
73 NPP_GetMIMEDescription(void)
75 return(MIME_TYPES_HANDLED
);
79 NPP_GetValue(NPP instance
, NPPVariable variable
, void *value
)
81 NPError err
= NPERR_NO_ERROR
;
84 case NPPVpluginNameString
:
85 *((char **)value
) = PLUGIN_NAME
;
87 case NPPVpluginDescriptionString
:
88 *((char **)value
) = PLUGIN_DESCRIPTION
;
91 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
->pluginsPrintMessage
= 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
], "PRINTMSG"))
150 This
->pluginsPrintMessage
= strdup(argv
[argc
]);
151 else if (!PL_strcasecmp(argn
[argc
], "HIDDEN"))
152 This
->pluginsHidden
= (!PL_strcasecmp(argv
[argc
],
157 return NPERR_NO_ERROR
;
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
;
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
;
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
;
196 return NPERR_INVALID_INSTANCE_ERROR
;
198 ws_info
= (NPSetWindowCallbackStruct
*)window
->ws_info
;
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
208 fprintf(stderr
, "Printplugin: plugin received window resize.\n");
209 fprintf(stderr
, "Window=(%i)\n", (int)window
);
211 fprintf(stderr
, "W=(%i) H=(%i)\n",
212 (int)window
->width
, (int)window
->height
);
215 return NPERR_NO_ERROR
;
218 This
->window
= (Window
) window
->window
;
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
;
236 NPP_NewStream(NPP instance
,
242 if (instance
== NULL
)
243 return NPERR_INVALID_INSTANCE_ERROR
;
245 return NPERR_NO_ERROR
;
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() */
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() */
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
;
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 \*********************************************/
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 \*********************************************/
315 NPP_Print(NPP instance
, NPPrint
* printInfo
)
317 if(printInfo
== NULL
)
320 if (instance
!= NULL
) {
321 /***** Insert NPP_Print code here *****\
322 PluginInstance* This = (PluginInstance*) instance->pdata;
323 \**************************************/
325 if (printInfo
->mode
== NP_FULL
) {
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,
343 /***** Insert NPP_Print code here *****\
344 void* platformPrint =
345 printInfo->print.fullPrint.platformPrint;
347 printInfo->print.fullPrint.printOne;
348 \**************************************/
351 printInfo
->print
.fullPrint
.pluginPrinted
= false;
353 else { /* If not fullscreen, we must be embedded */
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
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
;
377 (NPPrintCallbackStruct
*)(printInfo
->print
.embedPrint
.platformPrint
);
379 output
= (FILE*)(platformPrint
->fp
);
384 This
= (PluginInstance
*) instance
->pdata
;
388 printEPSMessage(This
, output
, printInfo
->print
.embedPrint
.window
);