browserplugin/cpixnpplugin/src/ccpixnpsearcherinterface.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: 
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <common.h>
       
    20 
       
    21 #include "CCPixNPSearcherInterface.h"
       
    22 #include "utf.h"
       
    23 
       
    24 #include "e32base.h"
       
    25 
       
    26 #include "NPUtils.h"
       
    27 using namespace nputils; 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 CCPixNPSearcherInterface::~CCPixNPSearcherInterface()
       
    32     {
       
    33     }
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 
       
    37 void CCPixNPSearcherInterface::InitInterfaceL()
       
    38     {
       
    39     const NPUTF8 *CPixNPSearcherMethodNames[] =
       
    40     	{
       
    41         "setObserver",
       
    42         "search",
       
    43         "getDocument",
       
    44         "setAnalyzer",
       
    45         "cancel",
       
    46         "isActive"
       
    47     	};
       
    48     SetIdentifiersL( NULL, 0, 
       
    49     				 CPixNPSearcherMethodNames, sizeof(CPixNPSearcherMethodNames)/sizeof(CPixNPSearcherMethodNames[0]));
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 
       
    54 bool CCPixNPSearcherInterface::InvokeL(NPIdentifier name, NPVariant* args, uint32_t argCount, NPVariant *result)
       
    55     {
       
    56     
       
    57     VOID_TO_NPVARIANT( *result );
       
    58     if ( name == iMethodIdentifiers[0] ) // setObserver
       
    59         {
       
    60         if ( argCount >= 1 && NPVARIANT_IS_OBJECT( args[0] ) ) 
       
    61         	{
       
    62 			TRAPD(err, 
       
    63 				NPObject* observer = NPVARIANT_TO_OBJECT( args[0] ); 
       
    64 				SetObserverL( observer );
       
    65 				); 
       
    66 			// TODO: Report err
       
    67         	}
       
    68         else 
       
    69         	{
       
    70         	// TODO: Exception handling: NotEnoughtArgumentsException & IllegalArgumentExceptions
       
    71         	}
       
    72         return true; 
       
    73         }
       
    74     else if ( name == iMethodIdentifiers[1] ) // search
       
    75         {
       
    76         PERFORMANCE_LOG_START("CCPixNPSearcherInterface::InvokeL");
       
    77         PERFORMANCE_LOG_MESSAGE(_L("----------New search----------"));
       
    78 
       
    79         if ( argCount >= 1 ) 
       
    80         	{
       
    81 			TRAPD(err, 
       
    82 				HBufC16* query = VariantToHBufC16LC( args[0] );
       
    83 				SearchL( *query);
       
    84 				CleanupStack::PopAndDestroy( query ); 
       
    85 				); 
       
    86 			// TODO: Report err
       
    87         	}
       
    88         else 
       
    89         	{
       
    90         	// TODO: Exception handling: NotEnoughtArgumentsException & IllegalArgumentExceptions
       
    91         	}
       
    92 
       
    93         return true;
       
    94         }
       
    95     else if ( name == iMethodIdentifiers[2] ) // getDocument
       
    96         {
       
    97     	if (argCount >= 1) 
       
    98     		{
       
    99 			TInt index = VariantToInt( args[0] );
       
   100 			TRAPD(err, GetDocumentL(index));
       
   101 			// TODO: report err
       
   102     		}
       
   103 		// TODO: Report err
       
   104         return true;
       
   105         }
       
   106     else if ( name == iMethodIdentifiers[3] ) // setAnalyzer
       
   107         {
       
   108         if ( argCount >= 1 ) 
       
   109          	{
       
   110  			TRAPD(err, 
       
   111  				HBufC16* query = VariantToHBufC16LC( args[0] );
       
   112  				SetAnalyzerL( *query );
       
   113  				CleanupStack::PopAndDestroy( query ); 
       
   114  				); 
       
   115  			// TODO: Report err
       
   116          	}
       
   117          else 
       
   118          	{
       
   119          	// TODO: Exception handling: NotEnoughtArgumentsException & IllegalArgumentExceptions
       
   120          	}
       
   121         return true;
       
   122         }
       
   123     else if ( name == iMethodIdentifiers[4] ) // cancel
       
   124         {
       
   125 		TRAPD(err,
       
   126 			Cancel(); 
       
   127 			); 
       
   128 		// TODO: Report err
       
   129         return true;
       
   130         }
       
   131     else if ( name == iMethodIdentifiers[5] ) // isActive
       
   132         {
       
   133 		TRAPD(err,
       
   134 			BOOLEAN_TO_NPVARIANT(IsActive(),  *result); 
       
   135 			); 
       
   136 		// TODO: Report err
       
   137         return true;
       
   138         }
       
   139     
       
   140     return false;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 
       
   145 bool CCPixNPSearcherInterface::GetProperty (NPIdentifier name, NPVariant *variant)
       
   146     {
       
   147     // default variant value maps to javascript undefined
       
   148     VOID_TO_NPVARIANT(*variant);
       
   149     return false;
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 
       
   154 bool CCPixNPSearcherInterface::SetPropertyL( NPIdentifier name, NPVariant *variant )
       
   155     {
       
   156     return false;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // NPClass Function
       
   161 
       
   162 NPObject *CPixNPSearcherAllocate ()
       
   163     {
       
   164     CPixNPSearcherObject *newInstance = (CPixNPSearcherObject *)User::Alloc (sizeof(CPixNPSearcherObject));       
       
   165     return (NPObject *)newInstance;
       
   166     }
       
   167 
       
   168 void CPixNPSearcherInvalidate (CPixNPSearcherObject *obj)
       
   169     {
       
   170     obj->plugin->Invalidate();
       
   171     }
       
   172 
       
   173 void CPixNPSearcherDeallocate (CPixNPSearcherObject* obj) 
       
   174     {    
       
   175     obj->plugin->Deallocate();
       
   176     User::Free ((void *)obj);
       
   177     }    
       
   178  
       
   179 bool CPixNPSearcherHasMethod(CPixNPSearcherObject* obj, NPIdentifier name)
       
   180     {
       
   181     return obj->plugin->HasMethod(name);
       
   182     }
       
   183 
       
   184 bool CPixNPSearcherInvokeFunctionL(CPixNPSearcherObject* obj, NPIdentifier name, NPVariant *args, uint32_t argCount, NPVariant *result)
       
   185     {
       
   186     return obj->plugin->InvokeL(name, args, argCount, result);
       
   187     }    
       
   188 
       
   189 bool CPixNPSearcherHasProperty(CPixNPSearcherObject* obj, NPIdentifier name)
       
   190     {
       
   191     return obj->plugin->HasProperty(name);
       
   192     }    
       
   193     
       
   194 bool CPixNPSearcherGetProperty (CPixNPSearcherObject* obj, NPIdentifier name, NPVariant *variant)
       
   195     {
       
   196     return obj->plugin->GetProperty(name,variant);
       
   197     }
       
   198 
       
   199 void CPixNPSearcherSetProperty (CPixNPSearcherObject* obj, NPIdentifier name, NPVariant *variant)
       
   200     {
       
   201     TRAP_IGNORE(obj->plugin->SetPropertyL(name,variant));
       
   202     }
       
   203 
       
   204 //  End of File