browserplugin/cpixnpplugin/src/ccpixnpsearcherobserver.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 "CCPixNPSearcherObserver.h"
       
    18 
       
    19 #include "CNPSearchDocumentInterface.h"
       
    20 #include <string.h>
       
    21 
       
    22 #include "CCPixNPPluginEcom.h"
       
    23 #include <utf.h>
       
    24 #include <common.h>
       
    25 
       
    26 /**
       
    27  * These are the methods that are called in the script object,
       
    28  * observer object is wrapping. 
       
    29  */
       
    30 _LIT8( KHandleSearchResultsMethodName, "handleSearchResults"); 
       
    31 _LIT8( KHandleDocumentMethodName, "handleDocument"); 
       
    32 
       
    33 CCPixNPSearcherObserver::CCPixNPSearcherObserver( NPP& aNpp, NPObject* aSelf )
       
    34 : iNpp( aNpp ), iSelf( aSelf )
       
    35     {
       
    36     NPN_RetainObject( iSelf ); 
       
    37     }
       
    38 
       
    39 CCPixNPSearcherObserver::~CCPixNPSearcherObserver()
       
    40     {
       
    41     if (iSelf) NPN_ReleaseObject( iSelf );
       
    42     }
       
    43 
       
    44 void CCPixNPSearcherObserver::HandleSearchResultsL(const TDesC8* aError, TInt aEstimatedResultCount)
       
    45 	{
       
    46 	PERFORMANCE_LOG_START("CCPixNPSearcherObserver::HandleSearchResultsL");
       
    47 	
       
    48     NPVariant result;
       
    49     NPString function;
       
    50     function.UTF8Characters = (const NPUTF8 *)KHandleSearchResultsMethodName().Ptr();
       
    51     function.UTF8Length = KHandleSearchResultsMethodName().Length();
       
    52 
       
    53     NPVariant args[2];
       
    54     if ( aError ) {
       
    55     	DescriptorToVariant( *aError, args[0] ); 
       
    56     } else {
       
    57     	NULL_TO_NPVARIANT( args[0] );
       
    58     }
       
    59     INT32_TO_NPVARIANT( aEstimatedResultCount, args[1] );
       
    60     
       
    61     PERFORMANCE_LOG_MESSAGE(_L("----------Start document fetching----------"));
       
    62     NPN_Invoke( iNpp, iSelf, &function, args, 2, &result );
       
    63 	}
       
    64 
       
    65 void CCPixNPSearcherObserver::HandleDocumentL(const TDesC8* aError, NPSearchDocumentObject* aDocument)
       
    66 	{
       
    67     NPVariant result;
       
    68     NPString function;
       
    69     function.UTF8Characters = (const NPUTF8 *)KHandleDocumentMethodName().Ptr();
       
    70     function.UTF8Length = KHandleDocumentMethodName().Length();
       
    71 
       
    72     NPVariant args[2];
       
    73     if ( aError ) {
       
    74     	DescriptorToVariant( *aError, args[0] ); 
       
    75     } else {
       
    76     	NULL_TO_NPVARIANT( args[0] );
       
    77     }
       
    78     if ( aDocument ) {
       
    79     	OBJECT_TO_NPVARIANT( &aDocument->object, args[1] );
       
    80     } else {
       
    81     	NULL_TO_NPVARIANT( args[1] );
       
    82     }
       
    83 
       
    84     NPN_Invoke( iNpp, iSelf, &function, args, 2, &result );
       
    85 	}
       
    86 
       
    87 void CCPixNPSearcherObserver::DescriptorToVariant(const TDesC8& aString, NPVariant& aVariant)
       
    88 	{
       
    89     CCPixNPPluginEcom* pluginEcom = (CCPixNPPluginEcom*) Dll::Tls();
       
    90     NPNetscapeFuncs* netscapeFuncs = pluginEcom->Funcs(); 
       
    91 
       
    92     int length = aString.Length();
       
    93     char* newString = (char *)netscapeFuncs->memalloc( length );
       
    94     if (newString)
       
    95     	{
       
    96         Mem::Copy(newString, aString.Ptr(), length);
       
    97         STRINGN_TO_NPVARIANT(newString, length, aVariant);
       
    98     	}
       
    99 	}
       
   100