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  *
00056  */
00057 
00058 #include <stdio.h>
00059 #include <string.h>
00060 #include "npapi.h"
00061 #include "nullplugin.h"
00062 #include "strings.h"
00063 #include "plstr.h"
00064 
00065 /***********************************************************************
00066  *
00067  * Implementations of plugin API functions
00068  *
00069  ***********************************************************************/
00070 
00071 char*
00072 NPP_GetMIMEDescription(void)
00073 {
00074     return(MIME_TYPES_HANDLED);
00075 }
00076 
00077 NPError
00078 NPP_GetValue(NPP instance, NPPVariable variable, void *value)
00079 {
00080     NPError err = NPERR_NO_ERROR;
00081 
00082     switch (variable) {
00083         case NPPVpluginNameString:
00084             *((char **)value) = PLUGIN_NAME;
00085             break;
00086         case NPPVpluginDescriptionString:
00087             *((char **)value) = PLUGIN_DESCRIPTION;
00088             break;
00089         default:
00090             err = NPERR_GENERIC_ERROR;
00091     }
00092     return err;
00093 }
00094 
00095 NPError
00096 NPP_Initialize(void)
00097 {
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->pluginsPageUrl = 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], "PLUGINSPAGE"))
00158             This->pluginsPageUrl = strdup(argv[argc]);
00159         else if (!PL_strcasecmp(argn[argc], "PLUGINURL"))
00160             This->pluginsFileUrl = strdup(argv[argc]);
00161         else if (!PL_strcasecmp(argn[argc], "CODEBASE"))
00162             This->pluginsPageUrl = strdup(argv[argc]);
00163         else if (!PL_strcasecmp(argn[argc], "CLASSID"))
00164             This->pluginsFileUrl = strdup(argv[argc]);
00165         else if (!PL_strcasecmp(argn[argc], "HIDDEN"))
00166             This->pluginsHidden = (!PL_strcasecmp(argv[argc],
00167             "TRUE"));
00168         }
00169     }
00170 
00171     return NPERR_NO_ERROR;
00172 }
00173 
00174 NPError 
00175 NPP_Destroy(NPP instance, NPSavedData** save)
00176 {
00177 
00178     PluginInstance* This;
00179 
00180     if (instance == NULL)
00181         return NPERR_INVALID_INSTANCE_ERROR;
00182 
00183     This = (PluginInstance*) instance->pdata;
00184 
00185     if (This != NULL) {
00186        if (This->dialogBox)
00187           destroyWidget(This);
00188         if (This->type)
00189             NPN_MemFree(This->type);
00190         if (This->pluginsPageUrl)
00191             NPN_MemFree(This->pluginsPageUrl);
00192         if (This->pluginsFileUrl)
00193                 NPN_MemFree(This->pluginsFileUrl);
00194         NPN_MemFree(instance->pdata);
00195         instance->pdata = NULL;
00196     }
00197 
00198     return NPERR_NO_ERROR;
00199 }
00200 
00201 
00202 NPError 
00203 NPP_SetWindow(NPP instance, NPWindow* window)
00204 {
00205     PluginInstance* This;
00206     NPSetWindowCallbackStruct *ws_info;
00207 
00208     if (instance == NULL)
00209         return NPERR_INVALID_INSTANCE_ERROR;
00210 
00211     This = (PluginInstance*) instance->pdata;
00212 
00213     if (This == NULL)
00214         return NPERR_INVALID_INSTANCE_ERROR;
00215 
00216     ws_info = (NPSetWindowCallbackStruct *)window->ws_info;
00217 
00218 #ifdef MOZ_X11
00219     if (This->window == (Window) window->window) {
00220         /* The page with the plugin is being resized.
00221            Save any UI information because the next time
00222            around expect a SetWindow with a new window
00223            id.
00224         */
00225 #ifdef DEBUG
00226         fprintf(stderr, "Nullplugin: plugin received window resize.\n");
00227         fprintf(stderr, "Window=(%i)\n", (int)window);
00228         if (window) {
00229            fprintf(stderr, "W=(%i) H=(%i)\n",
00230                (int)window->width, (int)window->height);
00231         }
00232 #endif
00233         return NPERR_NO_ERROR;
00234     } else {
00235 
00236       This->window = (Window) window->window;
00237       This->x = window->x;
00238       This->y = window->y;
00239       This->width = window->width;
00240       This->height = window->height;
00241       This->display = ws_info->display;
00242       This->visual = ws_info->visual;
00243       This->depth = ws_info->depth;
00244       This->colormap = ws_info->colormap;
00245       makePixmap(This);
00246       makeWidget(This);
00247     }
00248 #endif  /* #ifdef MOZ_X11 */
00249     
00250     return NPERR_NO_ERROR;
00251 }
00252 
00253 
00254 NPError 
00255 NPP_NewStream(NPP instance,
00256           NPMIMEType type,
00257           NPStream *stream, 
00258           NPBool seekable,
00259           uint16 *stype)
00260 {
00261     if (instance == NULL)
00262         return NPERR_INVALID_INSTANCE_ERROR;
00263 
00264     return NPERR_NO_ERROR;
00265 }
00266 
00267 
00268 int32 
00269 NPP_WriteReady(NPP instance, NPStream *stream)
00270 {
00271     if (instance == NULL)
00272         return NPERR_INVALID_INSTANCE_ERROR;
00273 
00274     /* We don't want any data, kill the stream */
00275     NPN_DestroyStream(instance, stream, NPRES_DONE);
00276 
00277     /* Number of bytes ready to accept in NPP_Write() */
00278     return -1L;   /* don't accept any bytes in NPP_Write() */
00279 }
00280 
00281 
00282 int32 
00283 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
00284 {
00285     if (instance == NULL)
00286         return NPERR_INVALID_INSTANCE_ERROR;
00287 
00288     /* We don't want any data, kill the stream */
00289     NPN_DestroyStream(instance, stream, NPRES_DONE);
00290 
00291     return -1L;   /* don't accept any bytes in NPP_Write() */
00292 }
00293 
00294 
00295 NPError 
00296 NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
00297 {
00298     if (instance == NULL)
00299         return NPERR_INVALID_INSTANCE_ERROR;
00300 
00301     /***** Insert NPP_DestroyStream code here *****\
00302     PluginInstance* This;
00303     This = (PluginInstance*) instance->pdata;
00304     \**********************************************/
00305 
00306     return NPERR_NO_ERROR;
00307 }
00308 
00309 
00310 void 
00311 NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
00312 {
00313     /***** Insert NPP_StreamAsFile code here *****\
00314     PluginInstance* This;
00315     if (instance != NULL)
00316         This = (PluginInstance*) instance->pdata;
00317     \*********************************************/
00318 }
00319 
00320 
00321 void
00322 NPP_URLNotify(NPP instance, const char* url,
00323                 NPReason reason, void* notifyData)
00324 {
00325     /***** Insert NPP_URLNotify code here *****\
00326     PluginInstance* This;
00327     if (instance != NULL)
00328         This = (PluginInstance*) instance->pdata;
00329     \*********************************************/
00330 }
00331 
00332 
00333 void 
00334 NPP_Print(NPP instance, NPPrint* printInfo)
00335 {
00336     if(printInfo == NULL)
00337         return;
00338 
00339     if (instance != NULL) {
00340     /***** Insert NPP_Print code here *****\
00341         PluginInstance* This = (PluginInstance*) instance->pdata;
00342     \**************************************/
00343     
00344         if (printInfo->mode == NP_FULL) {
00345             /*
00346              * PLUGIN DEVELOPERS:
00347              *  If your plugin would like to take over
00348              *  printing completely when it is in full-screen mode,
00349              *  set printInfo->pluginPrinted to TRUE and print your
00350              *  plugin as you see fit.  If your plugin wants Netscape
00351              *  to handle printing in this case, set
00352              *  printInfo->pluginPrinted to FALSE (the default) and
00353              *  do nothing.  If you do want to handle printing
00354              *  yourself, printOne is true if the print button
00355              *  (as opposed to the print menu) was clicked.
00356              *  On the Macintosh, platformPrint is a THPrint; on
00357              *  Windows, platformPrint is a structure
00358              *  (defined in npapi.h) containing the printer name, port,
00359              *  etc.
00360              */
00361 
00362     /***** Insert NPP_Print code here *****\
00363             void* platformPrint =
00364                 printInfo->print.fullPrint.platformPrint;
00365             NPBool printOne =
00366                 printInfo->print.fullPrint.printOne;
00367     \**************************************/
00368             
00369             /* Do the default*/
00370             printInfo->print.fullPrint.pluginPrinted = FALSE;
00371         }
00372         else {  /* If not fullscreen, we must be embedded */
00373             /*
00374              * PLUGIN DEVELOPERS:
00375              *  If your plugin is embedded, or is full-screen
00376              *  but you returned false in pluginPrinted above, NPP_Print
00377              *  will be called with mode == NP_EMBED.  The NPWindow
00378              *  in the printInfo gives the location and dimensions of
00379              *  the embedded plugin on the printed page.  On the
00380              *  Macintosh, platformPrint is the printer port; on
00381              *  Windows, platformPrint is the handle to the printing
00382              *  device context.
00383              */
00384 
00385     /***** Insert NPP_Print code here *****\
00386             NPWindow* printWindow =
00387                 &(printInfo->print.embedPrint.window);
00388             void* platformPrint =
00389                 printInfo->print.embedPrint.platformPrint;
00390     \**************************************/
00391         }
00392     }
00393 }