Back to index

lightning-sunbird  0.9+nobinonly
npshell.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Stephen Mak <smak@sun.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 /*
00041  * npshell.c
00042  *
00043  * Netscape Client Plugin API
00044  * - Function that need to be implemented by plugin developers
00045  *
00046  * This file defines a "shell" plugin that plugin developers can use
00047  * as the basis for a real plugin.  This shell just provides empty
00048  * implementations of all functions that the plugin can implement
00049  * that will be called by Netscape (the NPP_xxx methods defined in
00050  * npapi.h).
00051  *
00052  * dp Suresh <dp@netscape.com>
00053  * updated 5/1998 <pollmann@netscape.com>
00054  * updated 9/2000 <smak@sun.com>
00055  * updated 3/2004 <dantifer.dang@sun.com>
00056  *
00057  */
00058 
00059 #include <stdio.h>
00060 #include <string.h>
00061 #include "npapi.h"
00062 #include "printplugin.h"
00063 #include "strings.h"
00064 #include "plstr.h"
00065 
00066 /***********************************************************************
00067  *
00068  * Implementations of plugin API functions
00069  *
00070  ***********************************************************************/
00071 
00072 char*
00073 NPP_GetMIMEDescription(void)
00074 {
00075     return(MIME_TYPES_HANDLED);
00076 }
00077 
00078 NPError
00079 NPP_GetValue(NPP instance, NPPVariable variable, void *value)
00080 {
00081     NPError err = NPERR_NO_ERROR;
00082 
00083     switch (variable) {
00084         case NPPVpluginNameString:
00085             *((char **)value) = PLUGIN_NAME;
00086             break;
00087         case NPPVpluginDescriptionString:
00088             *((char **)value) = PLUGIN_DESCRIPTION;
00089             break;
00090         default:
00091             err = NPERR_GENERIC_ERROR;
00092     }
00093     return err;
00094 }
00095 
00096 NPError
00097 NPP_Initialize(void)
00098 {
00099     return NPERR_NO_ERROR;
00100 }
00101 
00102 #ifdef OJI
00103 jref
00104 NPP_GetJavaClass()
00105 {
00106     return NULL;
00107 }
00108 #endif
00109 
00110 void
00111 NPP_Shutdown(void)
00112 {
00113 }
00114 
00115 NPError
00116 NPP_New(NPMIMEType pluginType,
00117     NPP instance,
00118     uint16 mode,
00119     int16 argc,
00120     char* argn[],
00121     char* argv[],
00122     NPSavedData* saved)
00123 {
00124 
00125     PluginInstance* This;
00126 
00127     if (instance == NULL)
00128         return NPERR_INVALID_INSTANCE_ERROR;
00129 
00130     instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
00131 
00132     This = (PluginInstance*) instance->pdata;
00133 
00134     if (This == NULL)
00135     {
00136         return NPERR_OUT_OF_MEMORY_ERROR;
00137     }
00138 
00139     memset(This, 0, sizeof(PluginInstance));
00140 
00141     /* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
00142     This->mode = mode;
00143     This->type = dupMimeType(pluginType);
00144     This->instance = instance;
00145     This->pluginsPrintMessage = NULL;
00146     This->exists = FALSE;
00147 
00148     /* Parse argument list passed to plugin instance */
00149     /* We are interested in these arguments
00150      *  PLUGINSPAGE = <url>
00151      */
00152     while (argc > 0)
00153     {
00154         argc --;
00155         if (argv[argc] != NULL)
00156         {
00157         if (!PL_strcasecmp(argn[argc], "PRINTMSG"))
00158             This->pluginsPrintMessage = strdup(argv[argc]);
00159         else if (!PL_strcasecmp(argn[argc], "HIDDEN"))
00160             This->pluginsHidden = (!PL_strcasecmp(argv[argc],
00161             "TRUE"));
00162         }
00163     }
00164 
00165     return NPERR_NO_ERROR;
00166 }
00167 
00168 NPError
00169 NPP_Destroy(NPP instance, NPSavedData** save)
00170 {
00171 
00172     PluginInstance* This;
00173 
00174     if (instance == NULL)
00175         return NPERR_INVALID_INSTANCE_ERROR;
00176 
00177     This = (PluginInstance*) instance->pdata;
00178 
00179     if (This != NULL) {
00180         if (This->type)
00181             NPN_MemFree(This->type);
00182         if (This->pluginsPrintMessage)
00183             NPN_MemFree(This->pluginsPrintMessage);
00184         NPN_MemFree(instance->pdata);
00185         instance->pdata = NULL;
00186     }
00187 
00188     return NPERR_NO_ERROR;
00189 }
00190 
00191 
00192 NPError
00193 NPP_SetWindow(NPP instance, NPWindow* window)
00194 {
00195     PluginInstance* This;
00196     NPSetWindowCallbackStruct *ws_info;
00197 
00198     if (instance == NULL)
00199         return NPERR_INVALID_INSTANCE_ERROR;
00200 
00201     This = (PluginInstance*) instance->pdata;
00202 
00203     if (This == NULL)
00204         return NPERR_INVALID_INSTANCE_ERROR;
00205 
00206     ws_info = (NPSetWindowCallbackStruct *)window->ws_info;
00207 
00208 #ifdef MOZ_X11
00209     if (This->window == (Window) window->window) {
00210         /* The page with the plugin is being resized.
00211            Save any UI information because the next time
00212            around expect a SetWindow with a new window
00213            id.
00214         */
00215 #ifdef DEBUG
00216         fprintf(stderr, "Printplugin: plugin received window resize.\n");
00217         fprintf(stderr, "Window=(%i)\n", (int)window);
00218         if (window) {
00219            fprintf(stderr, "W=(%i) H=(%i)\n",
00220                (int)window->width, (int)window->height);
00221         }
00222 #endif
00223         return NPERR_NO_ERROR;
00224     } else {
00225 
00226       This->window = (Window) window->window;
00227       This->x = window->x;
00228       This->y = window->y;
00229       This->width = window->width;
00230       This->height = window->height;
00231       This->display = ws_info->display;
00232       This->visual = ws_info->visual;
00233       This->depth = ws_info->depth;
00234       This->colormap = ws_info->colormap;
00235       printScreenMessage(This);
00236     }
00237 #endif  /* #ifdef MOZ_X11 */
00238 
00239     return NPERR_NO_ERROR;
00240 }
00241 
00242 
00243 NPError
00244 NPP_NewStream(NPP instance,
00245           NPMIMEType type,
00246           NPStream *stream,
00247           NPBool seekable,
00248           uint16 *stype)
00249 {
00250     if (instance == NULL)
00251         return NPERR_INVALID_INSTANCE_ERROR;
00252 
00253     return NPERR_NO_ERROR;
00254 }
00255 
00256 
00257 int32
00258 NPP_WriteReady(NPP instance, NPStream *stream)
00259 {
00260     if (instance == NULL)
00261         return NPERR_INVALID_INSTANCE_ERROR;
00262 
00263     /* We don't want any data, kill the stream */
00264     NPN_DestroyStream(instance, stream, NPRES_DONE);
00265 
00266     /* Number of bytes ready to accept in NPP_Write() */
00267     return -1L;   /* don't accept any bytes in NPP_Write() */
00268 }
00269 
00270 
00271 int32
00272 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
00273 {
00274     if (instance == NULL)
00275         return NPERR_INVALID_INSTANCE_ERROR;
00276 
00277     /* We don't want any data, kill the stream */
00278     NPN_DestroyStream(instance, stream, NPRES_DONE);
00279 
00280     return -1L;   /* don't accept any bytes in NPP_Write() */
00281 }
00282 
00283 
00284 NPError
00285 NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
00286 {
00287     if (instance == NULL)
00288         return NPERR_INVALID_INSTANCE_ERROR;
00289 
00290     /***** Insert NPP_DestroyStream code here *****\
00291     PluginInstance* This;
00292     This = (PluginInstance*) instance->pdata;
00293     \**********************************************/
00294 
00295     return NPERR_NO_ERROR;
00296 }
00297 
00298 
00299 void
00300 NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
00301 {
00302     /***** Insert NPP_StreamAsFile code here *****\
00303     PluginInstance* This;
00304     if (instance != NULL)
00305         This = (PluginInstance*) instance->pdata;
00306     \*********************************************/
00307 }
00308 
00309 
00310 void
00311 NPP_URLNotify(NPP instance, const char* url,
00312                 NPReason reason, void* notifyData)
00313 {
00314     /***** Insert NPP_URLNotify code here *****\
00315     PluginInstance* This;
00316     if (instance != NULL)
00317         This = (PluginInstance*) instance->pdata;
00318     \*********************************************/
00319 }
00320 
00321 
00322 void
00323 NPP_Print(NPP instance, NPPrint* printInfo)
00324 {
00325     if(printInfo == NULL)
00326         return;
00327 
00328     if (instance != NULL) {
00329     /***** Insert NPP_Print code here *****\
00330         PluginInstance* This = (PluginInstance*) instance->pdata;
00331     \**************************************/
00332 
00333         if (printInfo->mode == NP_FULL) {
00334             /*
00335              * PLUGIN DEVELOPERS:
00336              *  If your plugin would like to take over
00337              *  printing completely when it is in full-screen mode,
00338              *  set printInfo->pluginPrinted to TRUE and print your
00339              *  plugin as you see fit.  If your plugin wants Netscape
00340              *  to handle printing in this case, set
00341              *  printInfo->pluginPrinted to FALSE (the default) and
00342              *  do nothing.  If you do want to handle printing
00343              *  yourself, printOne is true if the print button
00344              *  (as opposed to the print menu) was clicked.
00345              *  On the Macintosh, platformPrint is a THPrint; on
00346              *  Windows, platformPrint is a structure
00347              *  (defined in npapi.h) containing the printer name, port,
00348              *  etc.
00349              */
00350 
00351     /***** Insert NPP_Print code here *****\
00352             void* platformPrint =
00353                 printInfo->print.fullPrint.platformPrint;
00354             NPBool printOne =
00355                 printInfo->print.fullPrint.printOne;
00356     \**************************************/
00357 
00358             /* Do the default*/
00359             printInfo->print.fullPrint.pluginPrinted = FALSE;
00360         }
00361         else {  /* If not fullscreen, we must be embedded */
00362             /*
00363              * PLUGIN DEVELOPERS:
00364              *  If your plugin is embedded, or is full-screen
00365              *  but you returned false in pluginPrinted above, NPP_Print
00366              *  will be called with mode == NP_EMBED.  The NPWindow
00367              *  in the printInfo gives the location and dimensions of
00368              *  the embedded plugin on the printed page.  On the
00369              *  Macintosh, platformPrint is the printer port; on
00370              *  Windows, platformPrint is the handle to the printing
00371              *  device context.
00372              */
00373 
00374     /***** Insert NPP_Print code here *****\
00375             NPWindow* printWindow =
00376                 &(printInfo->print.embedPrint.window);
00377             void* platformPrint =
00378                 printInfo->print.embedPrint.platformPrint;
00379     \**************************************/
00380             PluginInstance* This;
00381             NPPrintCallbackStruct* platformPrint;
00382             FILE *output;
00383 
00384             platformPrint =
00385                 (NPPrintCallbackStruct *)(printInfo->print.embedPrint.platformPrint);
00386 
00387             output = (FILE*)(platformPrint->fp);
00388             if (output == NULL)
00389                 return;
00390 
00391             
00392             This =  (PluginInstance*) instance->pdata;
00393             if (This == NULL)
00394                 return;
00395 
00396             printEPSMessage(This, output, printInfo->print.embedPrint.window);
00397 
00398         }
00399     }
00400 }