browserplugin/cpixnpplugin/src/ccpixnppluginecom.cpp
changeset 0 ccd0fd43f247
equal deleted inserted replaced
-1:000000000000 0:ccd0fd43f247
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Interface to Browser
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <implementationproxy.h>
       
    20 #include "CCPixNPPluginEcom.h"
       
    21 #include "CCPixNPPlugin.h"
       
    22 
       
    23 #include "NPUtils.h"
       
    24 
       
    25 #include <uri8.h>
       
    26 
       
    27 /***************************************************/
       
    28 /**********ECOM STYLE CPix PLUGIN ENTRY POINTS******/
       
    29 /***************************************************/
       
    30 
       
    31 _LIT8( KFileScheme, "file" );
       
    32 _LIT8( KHttpScheme, "http" );
       
    33 _LIT8( KNokiaDomain, "nokia.com" ); 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CCPixNPPluginEcom::NewL
       
    37 // -----------------------------------------------------------------------------
       
    38 CCPixNPPluginEcom* CCPixNPPluginEcom::NewL( TAny* aInitParam )
       
    39     {
       
    40     TFuncs* funcs = REINTERPRET_CAST( TFuncs*, aInitParam );
       
    41     CCPixNPPluginEcom* self = new (ELeave) CCPixNPPluginEcom( funcs->iNetscapeFuncs );
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL( funcs->iPluginFuncs );
       
    44     CleanupStack::Pop( self );
       
    45     Dll::SetTls ( (void*) self );
       
    46     
       
    47         
       
    48     return self;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CCPixNPPluginEcom::ConstructL
       
    53 // -----------------------------------------------------------------------------
       
    54 void CCPixNPPluginEcom::ConstructL( NPPluginFuncs* aPluginFuncs )
       
    55     {
       
    56     InitializeFuncs( aPluginFuncs );
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CCPixNPPluginEcom::CCPixNPPluginEcom
       
    61 // -----------------------------------------------------------------------------
       
    62 CCPixNPPluginEcom::CCPixNPPluginEcom( NPNetscapeFuncs* aNpf )
       
    63     : CEcomBrowserPluginInterface(),
       
    64       iNpf( aNpf )
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CCPixNPPluginEcom::~CCPixNPPluginEcom
       
    70 // -----------------------------------------------------------------------------
       
    71 CCPixNPPluginEcom::~CCPixNPPluginEcom()
       
    72     {
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // KImplementationTable
       
    77 // -----------------------------------------------------------------------------
       
    78 const TImplementationProxy KImplementationTable[] =
       
    79     {
       
    80     {{KCPixNPPluginImplementationValue}, (TProxyNewLPtr)CCPixNPPluginEcom::NewL}
       
    81     };
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // ImplementationGroupProxy
       
    85 // Returns the filters implemented in this DLL
       
    86 // Returns: The filters implemented in this DLL
       
    87 // -----------------------------------------------------------------------------
       
    88 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    89     {
       
    90     aTableCount = sizeof(KImplementationTable) / sizeof(TImplementationProxy);
       
    91     return KImplementationTable;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // InitializeFuncs
       
    96 // -----------------------------------------------------------------------------
       
    97 EXPORT_C NPError InitializeFuncs( NPPluginFuncs* aPpf )
       
    98     {
       
    99     aPpf->size          = sizeof(NPPluginFuncs);
       
   100     aPpf->version       = 1;
       
   101     aPpf->newp          = NewNPP_NewProc(CPixPluginNewp);
       
   102     aPpf->destroy       = NewNPP_DestroyProc(CPixPluginDestroy);
       
   103     aPpf->setwindow     = 0;
       
   104     aPpf->newstream     = 0;
       
   105     aPpf->destroystream = 0;
       
   106     aPpf->asfile        = 0;
       
   107     aPpf->writeready    = 0;
       
   108     aPpf->write         = 0;
       
   109     aPpf->print         = 0;
       
   110     aPpf->event         = 0;
       
   111     aPpf->urlnotify     = 0;
       
   112     aPpf->javaClass     = 0;
       
   113     aPpf->getvalue      = NewNPP_GetValueProc(CPixPluginGetvalue);
       
   114     aPpf->setvalue      = 0;
       
   115     return NPERR_NO_ERROR;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // NPP_Shutdown
       
   120 // -----------------------------------------------------------------------------
       
   121 EXPORT_C void NPP_Shutdown(void)
       
   122     {
       
   123     CCPixNPPluginEcom* CPixPluginEcom = (CCPixNPPluginEcom*)Dll::Tls();
       
   124     delete CPixPluginEcom;
       
   125     Dll::SetTls( NULL );
       
   126     }
       
   127 
       
   128 // ============================= LOCAL FUNCTIONS ===============================
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CPixPluginNewp
       
   132 // Create a new instance of a plugin. This is non-leaving method.
       
   133 // Returns: NPError: Error codes recognized by Browser
       
   134 // -----------------------------------------------------------------------------
       
   135 NPError CPixPluginNewp( NPMIMEType /*pluginType*/,  // Not used locally
       
   136                   NPP aInstance,            // Stores pointer to SystemInfo 
       
   137                   uint16 /*mode*/,          // 
       
   138                   CDesCArray* argn,         // The number of arguments passed
       
   139                   CDesCArray* argv,         // The values of arguments in the array
       
   140                   NPSavedData* /*saved*/ )  // 
       
   141     {
       
   142     if ( !CPixPluginAcceptLoadAttempt( aInstance ) ) 
       
   143     	{
       
   144     	return NPERR_MODULE_LOAD_FAILED_ERROR; 
       
   145     	}
       
   146     TRAPD( err, CPixPluginConstructL( aInstance, argn, argv ) );
       
   147     if ( err == KErrNoMemory )
       
   148         {        
       
   149         return NPERR_OUT_OF_MEMORY_ERROR;
       
   150         }
       
   151     if ( err != KErrNone )
       
   152         {
       
   153         return NPERR_MODULE_LOAD_FAILED_ERROR;
       
   154         }
       
   155         
       
   156     return NPERR_NO_ERROR;
       
   157     }
       
   158 
       
   159 TBool CPixPluginAcceptLoadAttempt( NPP aInstance )
       
   160 	{
       
   161     CCPixNPPluginEcom* pluginEcom = (CCPixNPPluginEcom*) Dll::Tls();
       
   162     NPNetscapeFuncs* netscapeFuncs = pluginEcom->Funcs();
       
   163     
       
   164 	// Disabled, because NPN_GetValue was not found in npscript.lib
       
   165 	TBool accept = EFalse;
       
   166     NPObject *windowObj = NULL;
       
   167     if ( netscapeFuncs->getvalue( aInstance, NPNVWindowNPObject, &windowObj ) == NPERR_NO_ERROR 
       
   168     	 && windowObj )
       
   169     	{
       
   170         NPIdentifier propertyId = NPN_GetStringIdentifier( "location" );
       
   171         NPVariant location;
       
   172         if ( NPN_GetProperty( aInstance, windowObj, propertyId, &location ) )
       
   173         	{
       
   174             NPObject* locationObj = location.value.objectValue;
       
   175             if ( locationObj ) 
       
   176             	{
       
   177 				propertyId = NPN_GetStringIdentifier( "href" );
       
   178 				NPVariant href;
       
   179 				if ( NPN_GetProperty( aInstance, locationObj, propertyId, &href ) ) 
       
   180 					{
       
   181 					TRAP_IGNORE( 
       
   182 						HBufC8* buf = nputils::VariantToHBufC8LC( href );
       
   183 						if ( buf ) 
       
   184 							{
       
   185 							TUriParser8 parser; 
       
   186 							parser.Parse( *buf );
       
   187 							if ( parser.Extract( EUriScheme ) == KFileScheme() ) 
       
   188 								{
       
   189 								accept = ETrue; 
       
   190 								}
       
   191 							else if ( parser.Extract( EUriScheme ) == KHttpScheme() )
       
   192 								{
       
   193 								TDesC8 host = parser.Extract( EUriHost );
       
   194 								if (host.Right( KNokiaDomain().Length() ) == KNokiaDomain() )
       
   195 									{
       
   196 									accept = ETrue;
       
   197 									}
       
   198 								}
       
   199 							CleanupStack::PopAndDestroy( buf ); 
       
   200 							}
       
   201 						); 
       
   202 					}
       
   203             	}
       
   204 			}
       
   205     	}
       
   206     return accept; 
       
   207 	}
       
   208 
       
   209 
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CPixPluginConstructL
       
   213 // This is the leaving method to create the plugin.  We have leaving setters
       
   214 // that need to be wrapped.
       
   215 // Returns: void
       
   216 // -----------------------------------------------------------------------------
       
   217 void CPixPluginConstructL( NPP aInstance,      // Stores pointer to CPixPlugin 
       
   218                      CDesCArray* /*argn*/,      // The number of arguments passed
       
   219                      CDesCArray* /*argv*/ )     // The values of arguments in the array
       
   220     {
       
   221     CCPixNPPlugin* plugin = CCPixNPPlugin::NewL();
       
   222     plugin->SetInstance( aInstance, NULL );
       
   223     aInstance->pdata = plugin;
       
   224      
       
   225     CCPixNPPluginEcom* CPixPluginEcom = (CCPixNPPluginEcom*) Dll::Tls();
       
   226     NPNetscapeFuncs* netscapeFuncs = CPixPluginEcom->Funcs();
       
   227     NPBool value_false = 0;
       
   228     netscapeFuncs->setvalue( aInstance, NPPVpluginWindowBool, (void*)&value_false );        // not owing the window
       
   229     netscapeFuncs->setvalue( aInstance, NPPVpluginTransparentBool, (void*)&value_false );   // speed up drawing
       
   230     }
       
   231 // -----------------------------------------------------------------------------
       
   232 // CPixDestroy(NPP aInstance, NPSavedData**)
       
   233 // Called by Browser to destroy the plugin
       
   234 // Returns: NPError: Error Code
       
   235 // -----------------------------------------------------------------------------
       
   236 NPError CPixPluginDestroy( NPP aInstance,               // Link to Browser
       
   237                      NPSavedData** /*save*/ )   // Not used locally
       
   238     {
       
   239     CCPixNPPlugin* pluginInstance = STATIC_CAST( CCPixNPPlugin*, aInstance->pdata );
       
   240     delete pluginInstance;
       
   241     
       
   242     return NPERR_NO_ERROR;
       
   243     }
       
   244 
       
   245         
       
   246 // -----------------------------------------------------------------------------
       
   247 // CPixPluginGetvalue		
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 NPError CPixPluginGetvalue( NPP aInstance, NPPVariable variable, void* ret_value )	
       
   251     {
       
   252 	if (variable == NPPVpluginScriptableNPObject)
       
   253 		{        
       
   254 		CCPixNPPlugin* plugin = (CCPixNPPlugin*)aInstance->pdata;
       
   255 		CPixPluginObject* pluginObject = (CPixPluginObject *)NPN_CreateObject (aInstance, CPixPluginClass);
       
   256 		pluginObject->plugin = plugin; 
       
   257 		plugin->SetInstance( aInstance, &pluginObject->object );
       
   258 		void** ret = (void**)ret_value;
       
   259 		*ret = (void*)pluginObject;
       
   260 		} 
       
   261     return NPERR_NO_ERROR;        
       
   262     }
       
   263 
       
   264 
       
   265 //  End of File