browserplugin/cpixnpplugin/src/cnpsearchdocumentinterface.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 #include "CNPSearchDocumentInterface.h"
       
    18 
       
    19 #include <utf.h>
       
    20 #include "CNPDocumentFieldInterface.h"
       
    21 
       
    22 #include "NPUtils.h"
       
    23 using namespace nputils; 
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 CNPSearchDocumentInterface::~CNPSearchDocumentInterface()
       
    28     {
       
    29     }
       
    30 
       
    31 
       
    32 void CNPSearchDocumentInterface::InitInterfaceL()
       
    33     {
       
    34     const NPUTF8 *NPSearchDocumentMethodNames[] =
       
    35     	{ 
       
    36         "getFieldByName",
       
    37         "getId",
       
    38         "getAppClass",
       
    39         "getExcerpt",
       
    40         "getFieldCount"
       
    41         "getFieldByIndex",
       
    42     	};
       
    43 
       
    44     SetIdentifiersL( NULL, 0,
       
    45     				 NPSearchDocumentMethodNames, sizeof(NPSearchDocumentMethodNames)/sizeof(NPSearchDocumentMethodNames[0]));
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 
       
    50 bool CNPSearchDocumentInterface::InvokeL(NPIdentifier name, NPVariant* args, uint32_t argCount, NPVariant *result)
       
    51     {
       
    52     VOID_TO_NPVARIANT(*result);
       
    53     if ( name == iMethodIdentifiers[0] ) // getFieldByName
       
    54     	{
       
    55         if ( argCount >= 1 ) 
       
    56     		{
       
    57     		TRAP_IGNORE( 
       
    58 				HBufC16* buf = VariantToHBufC16LC( args[0] );
       
    59 				if ( buf ) 
       
    60 					{
       
    61 					NPDocumentFieldObject* ret = FieldL( *buf );
       
    62 					CleanupStack::PopAndDestroy( buf ); 
       
    63 					if ( ret != NULL )
       
    64 						{
       
    65 						OBJECT_TO_NPVARIANT( ( NPObject* ) &ret->object, *result ); 
       
    66 						}
       
    67 					else 
       
    68 						{
       
    69 						NULL_TO_NPVARIANT( *result );
       
    70 						}
       
    71 					}
       
    72 				);
       
    73     		// TODO: report err
       
    74 			return true; 
       
    75 			}
       
    76     	}
       
    77     else if ( name == iMethodIdentifiers[1] ) // getId
       
    78     	{
       
    79     	TRAP_IGNORE(
       
    80     		DescriptorToVariantL( Id(), *result);
       
    81     		);
       
    82 		// TODO: report err
       
    83     	return true;
       
    84     	}
       
    85     else if ( name == iMethodIdentifiers[2] ) // getAppClass
       
    86     	{
       
    87     	TRAP_IGNORE(
       
    88     		DescriptorToVariantL( AppClass(), *result);
       
    89 			);
       
    90 		// TODO: report err
       
    91     	return true;
       
    92     	}
       
    93     else if ( name == iMethodIdentifiers[3] ) // getExcerpt
       
    94     	{
       
    95     	TRAP_IGNORE(
       
    96 			DescriptorToVariantL( Excerpt(), *result);
       
    97 			);
       
    98 		// TODO: report err
       
    99     	return true;
       
   100     	}
       
   101     else if ( name == iMethodIdentifiers[4] ) // getFieldCount
       
   102     	{
       
   103     	INT32_TO_NPVARIANT( FieldCount(), *result);
       
   104     	return true;
       
   105     	}
       
   106     else if ( name == iMethodIdentifiers[5] ) // getFieldByIndex
       
   107     	{
       
   108     	if (argCount >= 1) 
       
   109     		{
       
   110     		TRAP_IGNORE( 
       
   111 				TInt index = VariantToInt( args[0] );
       
   112 				NPDocumentFieldObject* ret = FieldL( index );
       
   113 				if ( ret != NULL ) 
       
   114 					{
       
   115 					OBJECT_TO_NPVARIANT( ( NPObject* ) &ret->object, *result ); 
       
   116 					}
       
   117 				else 
       
   118 					{
       
   119 					NULL_TO_NPVARIANT( *result ); 
       
   120 					}
       
   121 				); 
       
   122 			// TODO: report err
       
   123     		}
       
   124     	return true;
       
   125     	}
       
   126     
       
   127     return false;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 
       
   132 bool CNPSearchDocumentInterface::GetProperty (NPIdentifier name, NPVariant *variant)
       
   133     {
       
   134     // default variant value maps to javascript undefined
       
   135     VOID_TO_NPVARIANT(*variant);
       
   136     return false;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 
       
   141 bool CNPSearchDocumentInterface::SetPropertyL( NPIdentifier name, NPVariant *variant )
       
   142     {
       
   143     return false;
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // NPClass Function
       
   148 
       
   149 NPObject *NPSearchDocumentAllocate ()
       
   150     {
       
   151     NPSearchDocumentObject *newInstance = (NPSearchDocumentObject *)User::Alloc (sizeof(NPSearchDocumentObject));       
       
   152     return (NPObject *)newInstance;
       
   153     }
       
   154 
       
   155 void NPSearchDocumentInvalidate ()
       
   156     {
       
   157     }
       
   158 
       
   159 void NPSearchDocumentDeallocate (NPSearchDocumentObject* obj) 
       
   160     {
       
   161     obj->plugin->Deallocate();
       
   162     User::Free ((void *)obj);
       
   163     }    
       
   164  
       
   165 bool NPSearchDocumentHasMethod(NPSearchDocumentObject* obj, NPIdentifier name)
       
   166     {
       
   167     return obj->plugin->HasMethod(name);
       
   168     }
       
   169 
       
   170 bool NPSearchDocumentInvokeFunctionL(NPSearchDocumentObject* obj, NPIdentifier name, NPVariant *args, uint32_t argCount, NPVariant *result)
       
   171     {
       
   172     return obj->plugin->InvokeL(name, args, argCount, result);
       
   173     }    
       
   174 
       
   175 bool NPSearchDocumentHasProperty(NPSearchDocumentObject* obj, NPIdentifier name)
       
   176     {
       
   177     return obj->plugin->HasProperty(name);
       
   178     }    
       
   179     
       
   180 bool NPSearchDocumentGetProperty (NPSearchDocumentObject* obj, NPIdentifier name, NPVariant *variant)
       
   181     {
       
   182     return obj->plugin->GetProperty(name,variant);
       
   183     }
       
   184 
       
   185 void NPSearchDocumentSetProperty (NPSearchDocumentObject* obj, NPIdentifier name, NPVariant *variant)
       
   186     {
       
   187     TRAP_IGNORE(obj->plugin->SetPropertyL(name,variant));
       
   188     }
       
   189 
       
   190 //  End of File