browserplugin/cpixnpplugin/src/ccpixnpsearcher.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 <common.h>
       
    18 
       
    19 #include "CCPixNPSearcher.h"
       
    20 
       
    21 #include "CNPSearchDocument.h"
       
    22 #include "CPixNPExceptions.h"
       
    23 
       
    24 #include <CSearchDocument.h>
       
    25 #include <CCPixSearcher.h>
       
    26 
       
    27 CCPixNPSearcher::CCPixNPSearcher()
       
    28 :	iSearcher( NULL ),
       
    29 	iObserver( NULL )
       
    30 	{
       
    31 	}
       
    32 
       
    33 CCPixNPSearcher::~CCPixNPSearcher()
       
    34 	{
       
    35 	delete iSearcher; 
       
    36 	delete iObserver; 
       
    37 	iSearchSession.Close();
       
    38 	}
       
    39     
       
    40 CCPixNPSearcher* CCPixNPSearcher::NewL( const TDesC& aBaseAppClass, const TDesC& aDefaultSearchField )
       
    41 	{
       
    42 	CCPixNPSearcher* self = new (ELeave)CCPixNPSearcher();
       
    43     CleanupStack::PushL(self);
       
    44     self->ConstructL( aBaseAppClass, aDefaultSearchField );
       
    45     CleanupStack::Pop(); // self;
       
    46     return self;
       
    47 	}
       
    48 
       
    49 CCPixNPSearcher* CCPixNPSearcher::NewL( const TDesC& aBaseAppClass )
       
    50 	{
       
    51 	CCPixNPSearcher* self = new (ELeave)CCPixNPSearcher();
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL( aBaseAppClass );
       
    54     CleanupStack::Pop(); // self;
       
    55     return self;
       
    56 	}
       
    57 
       
    58 void CCPixNPSearcher::ConstructL( const TDesC& aBaseAppClass, const TDesC& aDefaultSearchField )
       
    59 	{
       
    60 	InitInterfaceL();
       
    61 	User::LeaveIfError(iSearchSession.Connect());
       
    62 	iSearcher = CCPixSearcher::NewL(iSearchSession, aDefaultSearchField);
       
    63 	iSearcher->OpenDatabaseL( aBaseAppClass  );
       
    64 	}
       
    65 
       
    66 void CCPixNPSearcher::ConstructL( const TDesC& aBaseAppClass  )
       
    67 	{
       
    68 	InitInterfaceL();
       
    69 	User::LeaveIfError(iSearchSession.Connect());
       
    70 	iSearcher = CCPixSearcher::NewL(iSearchSession);
       
    71 	iSearcher->OpenDatabaseL( aBaseAppClass  );
       
    72 	}
       
    73 
       
    74 void CCPixNPSearcher::Invalidate() 
       
    75 	{
       
    76 	// Get rid of observer. Trying to call JavaScript methods
       
    77 	delete iObserver; 
       
    78 	iObserver = NULL; 
       
    79 	
       
    80 	iSearcher->Cancel(); 
       
    81 	}
       
    82 
       
    83 void CCPixNPSearcher::SetObserverL( NPObject* aObserver )
       
    84 	{
       
    85 	delete iObserver; 
       
    86 	iObserver = NULL;
       
    87 	if ( aObserver != NULL ) 
       
    88 		{
       
    89 		iObserver = new (ELeave)CCPixNPSearcherObserver( iInstanceHandle, aObserver ); 
       
    90 		}
       
    91 	}
       
    92 
       
    93 void CCPixNPSearcher::SetAnalyzerL( const TDesC& aAnalyzer ) 
       
    94 	{
       
    95 	if ( !iSearcher->IsActive() )
       
    96 		{
       
    97 		iSearcher->SetAnalyzerL( aAnalyzer ); 
       
    98 		}
       
    99 	else 
       
   100 		{
       
   101 		// TODO Raise error
       
   102 		}
       
   103 	}
       
   104 
       
   105 void CCPixNPSearcher::SearchL( const TDesC& aSearchTerms, const TDesC& aDocumentField )
       
   106 	{
       
   107 	PERFORMANCE_LOG_START("CCPixNPSearcher::SearchL");
       
   108 	PERFORMANCE_LOG_MESSAGE(aSearchTerms);
       
   109 	
       
   110 	if ( !iSearcher->IsActive() ) 
       
   111 		{
       
   112 		iSearcher->SearchL( *this, aSearchTerms, aDocumentField );
       
   113 		}
       
   114 	else 
       
   115 		{
       
   116 		// TODO Raise error
       
   117 		}
       
   118 	
       
   119 	}
       
   120 
       
   121 void CCPixNPSearcher::GetDocumentL(TInt aIndex)
       
   122 	{
       
   123     PERFORMANCE_LOG_START("CCPixNPSearcher::GetDocumentL");
       
   124 
       
   125 	if ( !iSearcher->IsActive() ) 
       
   126 		{
       
   127 		iSearcher->GetDocumentL( aIndex, *this );
       
   128 		}
       
   129 	else 
       
   130 		{
       
   131 		// TODO Raise error
       
   132 		}
       
   133 	}
       
   134 
       
   135 void CCPixNPSearcher::Cancel()
       
   136 	{
       
   137 	iSearcher->Cancel();
       
   138 	}
       
   139 
       
   140 TBool CCPixNPSearcher::IsActive()
       
   141 	{
       
   142 	return iSearcher->IsActive(); 
       
   143 	}
       
   144 
       
   145 void CCPixNPSearcher::HandleSearchResultsL(TInt aError, TInt aEstimatedResultCount)
       
   146 	{
       
   147 	PERFORMANCE_LOG_START("CCPixNPSearcher::HandleSearchResultsL");
       
   148 	if ( iObserver != NULL ) 
       
   149 		{
       
   150 		iObserver->HandleSearchResultsL( DescribeErrorCode( aError ), 
       
   151 										 aEstimatedResultCount ); 
       
   152 		}
       
   153 	}
       
   154 
       
   155 void CCPixNPSearcher::HandleDocumentL( TInt aError, CSearchDocument* aDocument )
       
   156 	{
       
   157 	if ( iObserver != NULL ) 
       
   158 		{
       
   159 		if ( aDocument != NULL ) 
       
   160 			{
       
   161 			NPSearchDocumentObject *object = reinterpret_cast<NPSearchDocumentObject *>(NPN_CreateObject (iInstanceHandle, NPSearchDocumentClass));
       
   162 			CNPSearchDocument* documentObject = CNPSearchDocument::NewL( aDocument );
       
   163 			documentObject->SetInstance( iInstanceHandle, &object->object );
       
   164 	        object->plugin = documentObject;
       
   165 			iObserver->HandleDocumentL( DescribeErrorCode( aError ), 
       
   166 											object ); 
       
   167 		} else {
       
   168 			iObserver->HandleDocumentL( DescribeErrorCode( aError ), 
       
   169 											NULL ); 
       
   170 			}
       
   171 		} 
       
   172 	else 
       
   173 		{
       
   174 		delete aDocument; 
       
   175 		}
       
   176 	}
       
   177 
       
   178