|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /** 00002 * ============================================================================= 00003 * Name : Bitmapplugin.cpp 00004 * Part of : Plugin test 00005 * Interface : Browser Plug-in API 00006 * Description : Example for developing a plug-in 00007 * Version : 1.0 00008 * 00009 * Copyright (c) 2005-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================= 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <e32std.h> 00018 #include "bitmapplugin.h" 00019 #include "bitmapecommain.h" 00020 #include "bitmapinst.h" 00021 00022 00023 // CONSTANTS 00024 _LIT(KMIMEDescription, "application/mbm;mbm;|image/mbm;mbm;|image/gif;gif"); 00025 _LIT(KPluginName,"S60 Bitmap Graphics Plug-in"); 00026 _LIT(KPluginDescription,"Example plug-in to demonstrate usage of different plug-in APIs"); 00027 00028 // ============================================================================ 00029 // LOCAL FUNCTIONS 00030 // ============================================================================ 00031 00032 // ---------------------------------------------------------------------------- 00033 // This function returns pointer to the plug-in object which is stored in the 00034 // pdata member of the plugin instance handle. 00035 // 00036 // @param aInstance - the plug-in instance. 00037 // @return - pointer to the plug-in object. 00038 // ---------------------------------------------------------------------------- 00039 00040 static CBitmapInst* Inst( NPP aInstance ) 00041 { 00042 CBitmapInst* inst = ( CBitmapInst* )aInstance->pdata; 00043 return inst; 00044 } 00045 00046 00047 // ---------------------------------------------------------------------------- 00048 // The browser calls the PluginDestroy function to delete an instance of a 00049 // plug-in previously constructed by PluginNew(). When this function is called, 00050 // the browser will have already cleaned up all other instance-related objects 00051 // that it created. 00052 // 00053 // @param aInstance - the instance originally passed to PluginNew(). 00054 // @param aSave - optional parameter to save data for reuse by a new 00055 // plug-in instance with the same URL. Saved data is passed 00056 // to the NP_New() call of the new plug-in instance. The buf 00057 // field of the aSave variable should always be allocated 00058 // using NPN_MemAlloc() because the browser is responsible 00059 // for deleting this value.To ensure that the browser does 00060 // not crash or leak memory when the saved data is 00061 // discarded, the buf field should be a flat structure with 00062 // no allocated substructures since the browser is not aware 00063 // of the structure of buf to free the individual allocated 00064 // members of the structure. 00065 // @return - since this is a destructor function, it should always 00066 // return NPERR_NO_ERROR. 00067 // ---------------------------------------------------------------------------- 00068 NPError PluginDestroy( NPP aInstance, NPSavedData** aSave ) 00069 { 00070 return Inst( aInstance )->PluginDestroy( aSave ); 00071 } 00072 00073 00074 // ---------------------------------------------------------------------------- 00075 // This function destroys the stream that was previously created to stream data 00076 // to the plug-in. 00077 // 00078 // @param aStream - the stream to be destroyed. 00079 // @param aReason - the reason for destroying the stream. Possible values are: 00080 // NPRES_DONE - normal completion and all data was sent to 00081 // the instance. 00082 // NPRES_USER_BREAK - the user canceled the stream 00083 // NPRES_NETWORK_ERR - stream failed because of problems 00084 // with the network, disk I/O error, lack of memory, or 00085 // some other problem. 00086 // @return - NPError status code. 00087 // ---------------------------------------------------------------------------- 00088 NPError PluginDestroyStream( NPP aInstance, NPStream* aStream, NPReason aReason ) 00089 { 00090 return Inst( aInstance )->PluginDestroyStream( aStream, aReason ); 00091 } 00092 00093 // ---------------------------------------------------------------------------- 00094 // The browser uses the PluginGetValue function to determine the name and 00095 // description of the plug-in. 00096 // 00097 // @param aInstance - the plug-in instance. 00098 // @param aVariable - the variable requested. Standard values in Symbian are: 00099 // NPPVpluginNameString 00100 // NPPVpluginDescriptionString 00101 // NPPVpluginWindowBool 00102 // NPPVpluginProgressBar 00103 // @param aValue - the return value requested. 00104 // @return - an error code; on success returns NPERR_NO_ERROR. 00105 // ---------------------------------------------------------------------------- 00106 NPError PluginGetValue( NPP /*aInstance*/, NPPVariable aVariable, void *aValue ) 00107 { 00108 const char** retValue = (const char**)aValue; 00109 00110 switch ( aVariable ) 00111 { 00112 case NPPVpluginNameString: 00113 { 00114 *( ( const TDesC** )retValue ) = &KPluginName; 00115 break; 00116 } 00117 case NPPVpluginDescriptionString: 00118 { 00119 *( ( const TDesC** )retValue ) = &KPluginDescription; 00120 break; 00121 } 00122 case NPPVpluginWindowBool: 00123 case NPPVpluginTransparentBool: 00124 default: 00125 { 00126 *retValue = NULL; 00127 break; 00128 } 00129 } 00130 return NPERR_NO_ERROR; 00131 } 00132 00133 // ---------------------------------------------------------------------------- 00134 // The browser calls PluginNew function to create a plug-in instance based on a 00135 // MIME type. The plug-in instance created can store its private data as a 00136 // member (pdata) of the instance argument passed. 00137 // 00138 // @param aPluginType - the MIME type of the plug-in. 00139 // @param aInstance - the pdata member variable is used by the plug-in to 00140 // store instance-specific private data. Commonly used to 00141 // store a pointer to an object, which is used for 00142 // operating on the plug-in in the future. 00143 // @param aMode - identifies the display mode of the plug-in. 00144 // NP_EMBED - specifies that the plug-in was created 00145 // using an embed tag within a Web document and that 00146 // the plug-in is to be displayed within a Web document. 00147 // NP_FULL - specifies that the plug-in was created by 00148 // opening a document requiring plug-in support for 00149 // display as the top level document and consumes the 00150 // entire document window. 00151 // @param aArgn - string list containing all the names of all parameters 00152 // included within the document embed tag. 00153 // @param aArgv - a string list containing values corresponding to the 00154 // parameters passed in the argn by means of the embed tag 00155 // @param aSaved - Not supported. 00156 // @return - an error code. Upon success, returns NPERR_NO_ERROR. 00157 // ---------------------------------------------------------------------------- 00158 NPError PluginNew( 00159 NPMIMEType aPluginType, NPP aInstance, uint16 aMode, 00160 CDesC16Array* aArgn, CDesC16Array* aArgv, NPSavedData* aSaved ) 00161 { 00162 CBitmapInst* inst = NULL; 00163 TRAPD( ret, inst = CBitmapInst :: NewL( aInstance ) ); 00164 if ( ret ) 00165 { 00166 return NPERR_OUT_OF_MEMORY_ERROR; 00167 } 00168 aInstance->pdata = inst; 00169 Inst( aInstance )->PluginNew( aPluginType, aInstance, aMode, 00170 aArgn, aArgv, aSaved ); 00171 return NPERR_NO_ERROR; 00172 } 00173 00174 00175 // ---------------------------------------------------------------------------- 00176 // This function notifies a plug-in instance of a new data stream. 00177 // 00178 // @param aInstance - the plug-in instance originally used in PluginNew(). 00179 // @param aMimeType - the MIME type of the stream. 00180 // @param aStream - the new stream object. 00181 // @param aSeekable - flag that indicates whether or not stream is searchable. 00182 // @param aStype - the type of the stream. The plug-in sets the stream type. 00183 // Currently supported stream types are: 00184 // NP_NORMAL 00185 // NP_ASFILE 00186 // NP_ASFILEONLY 00187 // @return - NPError status code. 00188 // ---------------------------------------------------------------------------- 00189 NPError PluginNewStream( 00190 NPP aInstance, NPMIMEType aType, NPStream* aStream, 00191 NPBool aSeekable, uint16* aStype ) 00192 { 00193 return Inst( aInstance )->PluginNewStream( aType, aStream, aSeekable, 00194 aStype ); 00195 } 00196 00197 00198 // ---------------------------------------------------------------------------- 00199 // This function sets value for a plugin variable. 00200 // 00201 // @param aInstance - the plug-in instance originally used in PluginNew(). 00202 // @param aVariable - the variable whose value is to be set. 00203 // @param aValue - pointer to the 32-bit parameter that contains the value. 00204 // @return - NPError status code. 00205 // ---------------------------------------------------------------------------- 00206 NPError PluginSetValue( NPP aInstance, NPNVariable aVariable, void *aValue ) 00207 { 00208 return Inst( aInstance )->PluginSetValue( aVariable, aValue ); 00209 } 00210 00211 00212 // ---------------------------------------------------------------------------- 00213 // The browser calls the NPP_SetWindow() function to set the parent and the 00214 // coordinates for the plug-in. The first time this function is called, it is 00215 // important to construct the corresponding plug-in control.The other times 00216 // this call is made, it is expected that the function simply updates the 00217 // bounds of the control. 00218 // 00219 // @param aInstance - the plug-in instance originally used in PluginNew(). 00220 // @param aWindow - a plug-in window structure that contains window 00221 // coordinates and platform specific window information. 00222 // @return - an error code; on success returns NPERR_NO_ERROR. 00223 // ---------------------------------------------------------------------------- 00224 NPError PluginSetWindowL( NPP aInstance, NPWindow* aWindow ) 00225 { 00226 return Inst( aInstance )->PluginSetWindowL( aWindow ); 00227 } 00228 00229 00230 // ---------------------------------------------------------------------------- 00231 // This function passes a file name to the plug-in in which the stream data 00232 // is stored. 00233 // 00234 // @param aInstance - the plug-in instance originally used in PluginNew(). 00235 // @param aStream - the stream 00236 // @param aFileName - the file name 00237 // ---------------------------------------------------------------------------- 00238 void PluginStreamAsFile( 00239 NPP aInstance, NPStream* aStream, const TDesC16& aFileName ) 00240 { 00241 Inst( aInstance )->PluginStreamAsFile( aStream, aFileName ); 00242 } 00243 00244 00245 // ---------------------------------------------------------------------------- 00246 // The browser calls the NPP_URLNotify() function to notify the plug-in of the 00247 // completion of a URL request made by the NPN_GetURLNotify() function or the 00248 // NPN_PostURLNotify() function. 00249 // 00250 // @param aInstance - the plug-in instance originally used in PluginNew(). 00251 // @param aUrl - url of the NPN_GetURLNotify() function or of the 00252 // NPN_PostURLNotify() function request. 00253 // @param aReason - reason code for completion of the request. 00254 // @param aNotifyData - contains the private plug-in data passed to the 00255 // corresponding call to the NPN_GetURLNotify() function. 00256 // ---------------------------------------------------------------------------- 00257 void PluginURLNotify( 00258 NPP aInstance, const TDesC16& aUrl, NPReason aReason, 00259 void* aNotifyData ) 00260 { 00261 Inst( aInstance )->PluginURLNotify( aUrl, aReason, aNotifyData ); 00262 } 00263 00264 00265 // ---------------------------------------------------------------------------- 00266 // This function writes a chunk of data to the plug-in. 00267 // 00268 // @param aInstance - the plug-in instance originally used in PluginNew(). 00269 // @param aStream - the stream. 00270 // @param aOffset - the offset in the stream. 00271 // @param aLength - the size of the new data. 00272 // @param aBuffer - the data. 00273 // @return - the number of bytes consumed by the plug-in instance. 00274 // ---------------------------------------------------------------------------- 00275 int32 PluginWrite( 00276 NPP aInstance, NPStream* aStream, int32 aOffset, int32 aLength, 00277 void* aBuffer ) 00278 { 00279 return Inst( aInstance )->PluginWrite( aStream, aOffset, aLength, aBuffer ); 00280 } 00281 00282 00283 // ---------------------------------------------------------------------------- 00284 // The browser calls the NPP_Write() function with the amount of data returned 00285 // from the NPP_WriteReady() function. 00286 // 00287 // @param aInstance - the plug-in instance originally used in PluginNew(). 00288 // @param aStream - the stream 00289 // @return - maximum data size that the plug-in can handle. 00290 // ---------------------------------------------------------------------------- 00291 int32 PluginWriteReady( NPP aInstance, NPStream* aStream ) 00292 { 00293 return Inst( aInstance )->PluginWriteReady( aStream ); 00294 } 00295 00296 00297 // ---------------------------------------------------------------------------- 00298 // The initialization function of the plug-in exchanges function pointers 00299 // between the browser and the plug-in, allowing calls to and from the plug-in. 00300 // This function also initializes plug-in library global data. 00301 // All unimplemented functions should be set to NULL in the function table. 00302 // For example, in the S60 and Series 90 platforms,JRI support is not 00303 // available. Therefore, aPpf->javaClass should be set to NULL. 00304 // 00305 // @param aPpf - allocated but uninitialized structure containing function 00306 // pointers to implemented plug-in functions. 00307 // @return - an error code, on success returns NPERR_NO_ERROR. 00308 // ---------------------------------------------------------------------------- 00309 EXPORT_C NPError InitializeFuncs(NPPluginFuncs* aPpf) 00310 { 00311 aPpf->size = sizeof ( NPPluginFuncs ); 00312 aPpf->version = 1; 00313 aPpf->newp = PluginNew; 00314 aPpf->destroy = PluginDestroy; 00315 aPpf->setwindow = PluginSetWindowL; 00316 aPpf->newstream = PluginNewStream; 00317 aPpf->destroystream = PluginDestroyStream; 00318 aPpf->asfile = PluginStreamAsFile; 00319 aPpf->writeready = PluginWriteReady; 00320 aPpf->write = PluginWrite; 00321 aPpf->print = NULL; 00322 aPpf->event = NULL; 00323 aPpf->urlnotify = PluginURLNotify; 00324 aPpf->javaClass = NULL; 00325 aPpf->getvalue = PluginGetValue; 00326 aPpf->setvalue = PluginSetValue; 00327 00328 return NPERR_NO_ERROR; 00329 } 00330 00331 00332 // ---------------------------------------------------------------------------- 00333 // This function has no input parameters and no return value. It is called to 00334 // allow the plug-in to clean up its data before the plug-in library is unloaded. 00335 // ---------------------------------------------------------------------------- 00336 EXPORT_C const TDesC* NPP_GetMIMEDescription(void) 00337 { 00338 return &KMIMEDescription; 00339 00340 } 00341 00342 00343 // ---------------------------------------------------------------------------- 00344 // The browser uses the PluginGetValue function to determine the name and 00345 // description of the plug-in. 00346 // 00347 // @param aInstance - the plug-in instance. 00348 // @param aVariable - the variable requested. Standard values in Symbian are: 00349 // NPPVpluginNameString 00350 // NPPVpluginDescriptionString 00351 // NPPVpluginWindowBool 00352 // NPPVpluginProgressBar 00353 // @param aValue - the return value requested. 00354 // @return - an error code; on success returns NPERR_NO_ERROR. 00355 // ---------------------------------------------------------------------------- 00356 EXPORT_C NPError NPP_GetValue(void* instance, NPPVariable aVariable, void* aValue) 00357 { 00358 return PluginGetValue((NPP)instance, aVariable , aValue); 00359 } 00360 00361 00362 EXPORT_C void NPP_Shutdown( void ) 00363 { 00364 CBitmapEcomMain* npm = ( CBitmapEcomMain* )Dll :: Tls(); 00365 delete npm; 00366 Dll :: SetTls( NULL ); 00367 } 00368
|
© Nokia 2006 |