wmdrm/camese/wmdrmdlautils/src/wmdrmdlabrowserviewhandler.cpp
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation class for WMDRM DLA Browser View Handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <coemain.h>
       
    21 #include <apaserverapp.h>
       
    22 #include "wmdrmdlabrowserviewhandler.h"
       
    23 #include "wmdrmdlabrowserobserver.h"
       
    24 #include "wmdrmdlaappclient.h"
       
    25 #include "wmdrmdlaappconstants.h"
       
    26 
       
    27 #define _LOGGING_FILE L"wmdrmdlautils.txt"
       
    28 #include "logfn.h"
       
    29 
       
    30 // ======== LOCAL FUNCTIONS ========
       
    31 
       
    32 // ======== MEMBER FUNCTIONS ========
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CWmDrmDlaBrowserViewHandler::ConstructL
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 void CWmDrmDlaBrowserViewHandler::ConstructL()
       
    39     {
       
    40     LOGFN( "CWmDrmDlaBrowserViewHandler::ConstructL" );
       
    41     iClient = new (ELeave) RWmDrmDlaAppClient;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CWmDrmDlaBrowserViewHandler::CWmDrmDlaBrowserViewHandler
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CWmDrmDlaBrowserViewHandler::CWmDrmDlaBrowserViewHandler() 
       
    49     : CActive( EPriorityStandard ), iState( EIdle )
       
    50     {
       
    51     LOGFN( "CWmDrmDlaBrowserViewHandler::CWmDrmDlaBrowserViewHandler" );
       
    52     CActiveScheduler::Add( this );
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CWmDrmDlaBrowserViewHandler::NewL
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 EXPORT_C CWmDrmDlaBrowserViewHandler* CWmDrmDlaBrowserViewHandler::NewL()
       
    60     {
       
    61     LOGFN( "CWmDrmDlaBrowserViewHandler::NewL" );
       
    62     CWmDrmDlaBrowserViewHandler* self = CWmDrmDlaBrowserViewHandler::NewLC();
       
    63     CleanupStack::Pop( self );
       
    64     return self;
       
    65     }
       
    66 
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CWmDrmDlaBrowserViewHandler::NewLC
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C CWmDrmDlaBrowserViewHandler* CWmDrmDlaBrowserViewHandler::NewLC()
       
    73     {
       
    74     LOGFN( "CWmDrmDlaBrowserViewHandler::NewLC" );
       
    75     CWmDrmDlaBrowserViewHandler* self 
       
    76         = new( ELeave ) CWmDrmDlaBrowserViewHandler;
       
    77     CleanupStack::PushL( self );
       
    78     self->ConstructL();
       
    79     return self;
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CWmDrmDlaBrowserViewHandler::~CWmDrmDlaBrowserViewHandler
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CWmDrmDlaBrowserViewHandler::~CWmDrmDlaBrowserViewHandler()
       
    88     {
       
    89     LOGFN( "CWmDrmDlaBrowserViewHandler::~CWmDrmDlaBrowserViewHandler" );
       
    90     Cancel();
       
    91     delete iClient;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CWmDrmDlaBrowserViewHandler::LaunchBrowserViewL
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C void CWmDrmDlaBrowserViewHandler::LaunchBrowserViewL( 
       
    99     MWmDrmDlaBrowserObserver* aObserver )
       
   100     {
       
   101     LOGFN( "CWmDrmDlaBrowserViewHandler::LaunchBrowserViewL" );
       
   102     if ( !CCoeEnv::Static() )
       
   103         {
       
   104         User::Leave( KErrNotSupported );
       
   105         }
       
   106     if ( !aObserver )
       
   107         {
       
   108         User::Leave( KErrArgument );
       
   109         }
       
   110     if ( iState != EIdle )
       
   111         {
       
   112         User::Leave( KErrInUse );
       
   113         }
       
   114     iObserver = aObserver;
       
   115     iClient->ConnectChainedAppL( KWmDrmDlaAppUid );
       
   116     iState = CWmDrmDlaBrowserViewHandler::ELaunchBrowserView;
       
   117     CompleteSelf();
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // CWmDrmDlaBrowserViewHandler::DoCancel
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 void CWmDrmDlaBrowserViewHandler::DoCancel()
       
   125     {
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CWmDrmDlaBrowserViewHandler::RunL
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CWmDrmDlaBrowserViewHandler::RunL()
       
   133     {
       
   134     LOGFN( "CWmDrmDlaBrowserViewHandler::RunL" );
       
   135     HBufC8* licenseResponse( NULL );
       
   136     switch ( iState )
       
   137         {
       
   138         case CWmDrmDlaBrowserViewHandler::ELaunchBrowserView:
       
   139             User::LeaveIfError( iClient->SetIAP( iObserver->IapId() ) );
       
   140             User::LeaveIfError( 
       
   141                     iClient->Post( iObserver->PostUrlL(), 
       
   142                                    iObserver->PostContentTypeL(), 
       
   143                                    iObserver->PostDataL(), 
       
   144                                    iObserver->PostContentDataBoundaryL() ) );
       
   145             User::LeaveIfError( iClient->LicenseResponse( licenseResponse ) );
       
   146             iObserver->LicenseResponseReceived( *licenseResponse );
       
   147             delete licenseResponse;
       
   148             iClient->Close();
       
   149             iState = CWmDrmDlaBrowserViewHandler::EIdle;
       
   150             break;
       
   151         
       
   152         default:
       
   153             ASSERT( EFalse );
       
   154             break;
       
   155         }
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CWmDrmDlaBrowserViewHandler::RunError
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 TInt CWmDrmDlaBrowserViewHandler::RunError( TInt aError )
       
   163     {
       
   164     LOGFN( "CWmDrmDlaBrowserViewHandler::RunError" );
       
   165     LOG2( "aError: %d", aError );
       
   166     iClient->Close();
       
   167     iObserver->BrowserExit( aError );
       
   168     iState = CWmDrmDlaBrowserViewHandler::EIdle;
       
   169     return KErrNone;
       
   170     }
       
   171 
       
   172 // ----------------------------------------------------------------------------
       
   173 // CWmDrmDlaBrowserViewHandler::CompleteSelf
       
   174 // ----------------------------------------------------------------------------
       
   175 //
       
   176 void CWmDrmDlaBrowserViewHandler::CompleteSelf()
       
   177     {
       
   178     if ( !IsActive() )
       
   179         {
       
   180         TRequestStatus* status = &iStatus;
       
   181         User::RequestComplete( status, KErrNone );
       
   182         SetActive();
       
   183         }
       
   184     }