browserui/browser/Launcher2/src/BrowserLauncherExtension.cpp
changeset 51 48e827313edd
parent 37 481242ead638
child 53 f427d27b98d8
equal deleted inserted replaced
37:481242ead638 51:48e827313edd
     1 /*
       
     2 * Copyright (c) 2002-2004 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 the License "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:  BrowserLauncherExtension
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <browserlauncher.h>
       
    20 #include "BrowserLauncherExtension.h"
       
    21 #include "logger.h"
       
    22 #include <downloadedcontenthandler.h>
       
    23 #include <favouriteslimits.h> // Context Id:s
       
    24 
       
    25 #include <eikenv.h>
       
    26 #include <AiwGenericParam.h>
       
    27 #include <s32mem.h>
       
    28 #include <coecntrl.h>
       
    29 #include <eikappui.h>
       
    30 
       
    31 NONSHARABLE_CLASS( CLauncherCommandAbsorbingControl ) : public CCoeControl
       
    32     {
       
    33     public:
       
    34         /**
       
    35         * Two-phased constructor.
       
    36         */
       
    37         static CLauncherCommandAbsorbingControl* NewL( CActiveSchedulerWait& aWaiter, TInt& aExitCode );
       
    38 
       
    39         /**
       
    40         * Destructor.
       
    41         */
       
    42         ~CLauncherCommandAbsorbingControl();
       
    43         
       
    44         /**
       
    45         * Set enabled/disabled status
       
    46         */
       
    47         inline void SetEnabled( TBool aEnabled ) { iEnabled = aEnabled; }
       
    48 
       
    49     private:
       
    50         /**
       
    51         * From CCoeControl
       
    52         */
       
    53         virtual TKeyResponse OfferKeyEventL( const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/ );
       
    54 
       
    55     private:
       
    56         /**
       
    57         * C++ default constructor.
       
    58         */
       
    59         CLauncherCommandAbsorbingControl( CActiveSchedulerWait& aWaiter, TInt& aExitCode );
       
    60 
       
    61         /**
       
    62         * Symbian OS constructor.
       
    63         */
       
    64         void ConstructL();
       
    65 
       
    66     private: // Data
       
    67         CEikAppUi* iAppUi;
       
    68         CActiveSchedulerWait& iWaiter;
       
    69         TBool iEnabled;
       
    70         TInt& iExitCode;
       
    71     };
       
    72 
       
    73 
       
    74 // ============================ MEMBER FUNCTIONS ===============================
       
    75 
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CLauncherCommandAbsorbingControl::CLauncherCommandAbsorbingControl
       
    79 //
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82 CLauncherCommandAbsorbingControl::CLauncherCommandAbsorbingControl( CActiveSchedulerWait& aWaiter, TInt& aExitCode )
       
    83 :   iWaiter( aWaiter ), iExitCode( aExitCode )
       
    84     {
       
    85     }
       
    86 
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // CLauncherCommandAbsorbingControl::~CLauncherCommandAbsorbingControl
       
    90 //
       
    91 // ---------------------------------------------------------
       
    92 //
       
    93 CLauncherCommandAbsorbingControl::~CLauncherCommandAbsorbingControl()
       
    94     {
       
    95     if ( iCoeEnv && iAppUi )
       
    96         {
       
    97         iAppUi->RemoveFromStack( this );
       
    98         }
       
    99     }
       
   100 
       
   101 
       
   102 // ---------------------------------------------------------
       
   103 // CLauncherCommandAbsorbingControl::NewLC
       
   104 //
       
   105 // ---------------------------------------------------------
       
   106 //
       
   107 CLauncherCommandAbsorbingControl* CLauncherCommandAbsorbingControl::NewL( CActiveSchedulerWait& aWaiter, TInt& aExitCode )
       
   108     {
       
   109     CLauncherCommandAbsorbingControl* self = new( ELeave ) CLauncherCommandAbsorbingControl( aWaiter, aExitCode );
       
   110     CleanupStack::PushL( self );
       
   111     self->ConstructL();
       
   112     CleanupStack::Pop( self );
       
   113     return self;
       
   114     }
       
   115 
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // CLauncherCommandAbsorbingControl::ConstructL
       
   120 //
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 void CLauncherCommandAbsorbingControl::ConstructL()
       
   124     {
       
   125     iAppUi = iEikonEnv->EikAppUi();
       
   126     //
       
   127     CreateWindowL();
       
   128     SetExtent( TPoint( 0,0 ), TSize( 0,0 ) );
       
   129     ActivateL();
       
   130     SetPointerCapture( ETrue );
       
   131     ClaimPointerGrab( ETrue );
       
   132     //
       
   133     iAppUi->AddToStackL( this, ECoeStackPriorityDialog );
       
   134     }
       
   135 
       
   136 
       
   137 // ---------------------------------------------------------
       
   138 // CLauncherCommandAbsorbingControl::OfferKeyEventL
       
   139 //
       
   140 // ---------------------------------------------------------
       
   141 //
       
   142 TKeyResponse CLauncherCommandAbsorbingControl::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   143     {
       
   144     TKeyResponse response = EKeyWasNotConsumed;
       
   145     //  
       
   146     if ( iEnabled )
       
   147         {
       
   148         if ( aKeyEvent.iCode == EKeyEscape && aType == EEventKey )
       
   149             {
       
   150             if ( iWaiter.IsStarted() )
       
   151                 {
       
   152                 iExitCode = KErrCancel;
       
   153                 iWaiter.AsyncStop();
       
   154                 }
       
   155             }
       
   156 
       
   157         response = EKeyWasConsumed;
       
   158         }
       
   159     //
       
   160     return response;
       
   161     }
       
   162 
       
   163 // ============================ MEMBER FUNCTIONS ===============================
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CBrowserLauncherExtension::CBrowserLauncherExtension
       
   167 // C++ default constructor can NOT contain any code, that
       
   168 // might leave.
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 CBrowserLauncherExtension::CBrowserLauncherExtension
       
   172     ( CBrowserLauncher& aLauncher )
       
   173 :   CActive( CActive::EPriorityStandard ), iLauncher( aLauncher ), iBufferSizeP( iBufferSize )
       
   174     {
       
   175     CActiveScheduler::Add( this );
       
   176     }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CBrowserLauncherExtension::ConstructL
       
   180 // Symbian 2nd phase constructor can leave.
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 void CBrowserLauncherExtension::ConstructL()
       
   184     {
       
   185     
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CBrowserLauncherExtension::NewL
       
   190 // Two-phased constructor.
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 CBrowserLauncherExtension* CBrowserLauncherExtension::NewL( CBrowserLauncher& aLauncher )
       
   194     {
       
   195     LOG_ENTERFN( "CBrowserLauncherExtension::NewL" );
       
   196     CBrowserLauncherExtension* self = new (ELeave) CBrowserLauncherExtension( aLauncher );
       
   197     CleanupStack::PushL(self);
       
   198     self->ConstructL();
       
   199     CleanupStack::Pop(self);
       
   200     return self;
       
   201     }
       
   202 
       
   203 // Destructor
       
   204 CBrowserLauncherExtension::~CBrowserLauncherExtension()
       
   205     {
       
   206     LOG_ENTERFN( "CBrowserLauncherExtension::~CBrowserLauncherExtension" );
       
   207     Cancel();
       
   208     iLauncherClientService.Close();
       
   209     delete iReceiveBuffer;
       
   210     delete iPackedLauncherData;
       
   211     delete iCommandAbsorber;
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CBrowserLauncherExtension::WaitBrowserToFinish
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 TInt CBrowserLauncherExtension::WaitBrowserToFinish()
       
   219     {
       
   220     LOG_ENTERFN( "CBrowserLauncherExtension::WaitBrowserToFinish" );
       
   221 	if( !iCommandAbsorber )
       
   222 	  {
       
   223 	  iCommandAbsorber = CLauncherCommandAbsorbingControl::NewL( iWait, iExitCode );
       
   224 	  }
       
   225     iCommandAbsorber->SetEnabled( ETrue );
       
   226     iWait.Start();
       
   227     iCommandAbsorber->SetEnabled( EFalse );
       
   228 
       
   229     // This class will complete us as an MAknServerAppExitObserver.
       
   230     return iExitCode;
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CBrowserLauncherExtension::SetPackedLauncherData
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CBrowserLauncherExtension::SetPackedLauncherData( HBufC8* aBuf )
       
   238     {
       
   239     delete iPackedLauncherData;
       
   240     iPackedLauncherData = aBuf;
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // CBrowserLauncherExtension::DoCancel
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CBrowserLauncherExtension::DoCancel()
       
   248     {
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CBrowserLauncherExtension::RunL
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CBrowserLauncherExtension::RunL()
       
   256     {
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CBrowserLauncherExtension::RunError
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 TInt CBrowserLauncherExtension::RunError( TInt aError )
       
   264     {
       
   265     return aError;
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CBrowserLauncherExtension::HandleServerAppExit
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CBrowserLauncherExtension::HandleServerAppExit( TInt aReason )
       
   273     {
       
   274     LOG_ENTERFN( "CBrowserLauncherExtension::HandleServerAppExit" );
       
   275     if ( iWait.IsStarted() )
       
   276         {
       
   277         /* If the Launcher was started synchronously, then 
       
   278            iBrowserLauncherClientExitObserver cannot be set => 
       
   279            no need to call iBrowserLauncherClientExitObserver->HandleServerAppExit() */
       
   280 
       
   281         // Note down the exit reason
       
   282         iExitCode = aReason;
       
   283         iWait.AsyncStop();
       
   284         iCommandAbsorber->SetEnabled( EFalse );
       
   285         }
       
   286     else if ( iBrowserLauncherClientExitObserver )
       
   287         {
       
   288         // Forward the exit event
       
   289         iBrowserLauncherClientExitObserver->HandleServerAppExit( aReason );
       
   290         }
       
   291     }
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CBrowserLauncherExtension::HandleReceivedDataL
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 void CBrowserLauncherExtension::HandleReceivedDataL( TRequestStatus aStatus )
       
   298     {
       
   299     LOG_ENTERFN( "CBrowserLauncherExtension::HandleReceivedDataL" );
       
   300     
       
   301     LOG_WRITE_FORMAT(" aStatus.Int(): %d", aStatus.Int());
       
   302     User::LeaveIfError( aStatus.Int() );
       
   303     
       
   304     //--------------------create buffer for server-----
       
   305     // Create buffer to hold data, sent by Browser application.
       
   306     // iBufferSize was defined by the server by now...
       
   307     delete iReceiveBuffer;
       
   308     iReceiveBuffer = 0;
       
   309     iReceiveBuffer = HBufC8::NewL( iBufferSize );
       
   310     TPtr8 tempRecBuf ( iReceiveBuffer->Des() );
       
   311     // Send the allocated descriptor to server, who fills it.
       
   312     User::LeaveIfError( iLauncherClientService.SendSyncBuffer( tempRecBuf ) );
       
   313     // OK, buffer has been filled.
       
   314 
       
   315     //--------------------internalize stream-----------
       
   316     // Create Stream object.
       
   317     RDesReadStream readStream( tempRecBuf );
       
   318     CleanupClosePushL( readStream );
       
   319     // Create param list object
       
   320     CAiwGenericParamList* paramList = CAiwGenericParamList::NewL( readStream );
       
   321     LOG_WRITE(" paramList OK");
       
   322     CleanupStack::PopAndDestroy( &readStream );
       
   323     CleanupStack::PushL( paramList );
       
   324     //--------------------eof internalize stream-------
       
   325 
       
   326     TBool clientWantsToContinue( EFalse );
       
   327     TBool wasContentHandled = EFalse;
       
   328 
       
   329     // If the embedding application handles the downloaded content.
       
   330     if ( iDownloadedContentHandler )
       
   331         {
       
   332         LOG_WRITE_FORMAT(" iDownloadedContentHandler: 0x%x", iDownloadedContentHandler);
       
   333         // Extract the file name from the generic paam list
       
   334         TInt index(0);
       
   335         const TAiwGenericParam* paramFileName = 
       
   336             paramList->FindFirst( index, EGenericParamFile, EVariantTypeDesC );
       
   337         TPtrC fileName;
       
   338         if ( index == KErrNotFound )
       
   339             {
       
   340             fileName.Set( KNullDesC );
       
   341             }
       
   342         else
       
   343             {
       
   344             fileName.Set( paramFileName->Value().AsDes() );
       
   345             }
       
   346 
       
   347         // Call the embedding app with these parameters, to handle the downloaded
       
   348         // content
       
   349         TRAPD( handlerLeave, wasContentHandled = 
       
   350                                             iDownloadedContentHandler->HandleContentL( 
       
   351                                                                         fileName, 
       
   352                                                                         *paramList, 
       
   353                                                                         clientWantsToContinue ) );
       
   354         ++handlerLeave; // To avoid warnings. Used for logging.
       
   355         LOG_WRITE_FORMAT(" handlerLeave: %d", handlerLeave);
       
   356         }
       
   357         
       
   358     // Tell the server app the output parameters
       
   359     User::LeaveIfError( iLauncherClientService.SendSyncBools
       
   360                                  ( clientWantsToContinue, wasContentHandled ) );
       
   361     
       
   362     // This async request completed, reinitialize it
       
   363     iLauncherClientService.SendAsync(iBufferSizeP);
       
   364     
       
   365     CleanupStack::PopAndDestroy( paramList ); // paramList
       
   366     }
       
   367 
       
   368 // End of file