wmdrm/camese/wmdrmdlaapp/src/wmdrmdlabrowserview.cpp
changeset 0 95b198f216e5
child 18 8a03a285ab14
child 23 493788a4a8a4
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
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <f32file.h>
       
    21 #include <bautils.h>
       
    22 #include <aknviewappui.h>
       
    23 #include <coeaui.h>
       
    24 #include <coecntrl.h>
       
    25 #include <brctlinterface.h>
       
    26 #include <internetconnectionmanager.h>
       
    27 #include <wmdrmdlaapp.rsg>
       
    28 #include "wmdrmdlabrowserview.h"
       
    29 #include "wmdrmdlabrowsercontainer.h"
       
    30 #include "wmdrmdlaappconstants.h"
       
    31 
       
    32 // CONTANTS
       
    33 _LIT( KDataTypeLicenseResponse, "application/vnd.ms-wmdrm.lic-resp" );
       
    34 
       
    35 // ======== LOCAL FUNCTIONS ========
       
    36 
       
    37 // ======== MEMBER FUNCTIONS ========
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CWmDrmDlaBrowserView::ConstructL
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void CWmDrmDlaBrowserView::ConstructL()
       
    44     {
       
    45     BaseConstructL( R_WMDRMDLA_APP_BROWSER_VIEW );
       
    46     iConMgr = CInternetConnectionManager::NewL( ETrue );
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CWmDrmDlaBrowserView::CWmDrmDlaBrowserView
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CWmDrmDlaBrowserView::CWmDrmDlaBrowserView()
       
    54     {
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CWmDrmDlaBrowserView::NewL
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CWmDrmDlaBrowserView* CWmDrmDlaBrowserView::NewL()
       
    62     {
       
    63     CWmDrmDlaBrowserView* self = CWmDrmDlaBrowserView::NewLC();
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CWmDrmDlaBrowserView::NewLC
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CWmDrmDlaBrowserView* CWmDrmDlaBrowserView::NewLC()
       
    74     {
       
    75     CWmDrmDlaBrowserView* self = new( ELeave ) CWmDrmDlaBrowserView();
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     return self;
       
    79     }
       
    80 
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CWmDrmDlaBrowserView::~CWmDrmDlaBrowserView
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CWmDrmDlaBrowserView::~CWmDrmDlaBrowserView()
       
    87     {
       
    88     RemoveContainer();
       
    89     delete iLicenseResponse;
       
    90     delete iConMgr;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CWmDrmDlaBrowserView::SetIAP
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 
       
    98 void CWmDrmDlaBrowserView::SetIAP( TInt aIap )
       
    99     {
       
   100     iIap = aIap;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CWmDrmDlaBrowserView::PostL
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 void CWmDrmDlaBrowserView::PostL(
       
   108     MBrowserViewLicenseReceivedCallback* aCallback,
       
   109     const TDesC& aPostUrl,
       
   110     const TDesC8& aPostContentType,
       
   111     const TDesC8& aPostData,
       
   112     const TDesC8& aPostContentBoundary )
       
   113     {
       
   114     iCallback = aCallback;
       
   115     iContainer->BrCtlInterface()->PostUrlL( aPostUrl, 
       
   116                                             aPostContentType, 
       
   117                                             aPostData, 
       
   118                                             &aPostContentBoundary, 
       
   119                                             (TAny*)iContainer );
       
   120     iContainer->BrCtlInterface()->SetFocus( ETrue, EDrawNow );
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CWmDrmDlaBrowserView::LicenseResponse
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 
       
   128 HBufC8* CWmDrmDlaBrowserView::LicenseResponse()
       
   129     {
       
   130     return iLicenseResponse;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CWmDrmDlaBrowserView::Id
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 TUid CWmDrmDlaBrowserView::Id() const
       
   138     {
       
   139     return KWmDrmDlaAppBrowserViewId;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CWmDrmDlaBrowserView::HandleCommandL
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CWmDrmDlaBrowserView::HandleCommandL(
       
   147     TInt aCommand )
       
   148     {
       
   149     if ( aCommand >= TBrCtlDefs::ECommandIdBase + 
       
   150                      TBrCtlDefs::ECommandIdWMLBase &&
       
   151          aCommand <= TBrCtlDefs::ECommandIdBase + 
       
   152                      TBrCtlDefs::ECommandIdRange )
       
   153         {
       
   154         BrCtlHandleCommandL( aCommand );
       
   155         }
       
   156     else
       
   157         {
       
   158         AppUi()->HandleCommandL( aCommand );
       
   159         }
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CWmDrmDlaBrowserView::DoActivateL
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CWmDrmDlaBrowserView::DoActivateL(
       
   167     const TVwsViewId& /*aPrevViewId*/,
       
   168     TUid /*aCustomMessageId*/,
       
   169     const TDesC8& /*aCustomMessage*/ )
       
   170     {  
       
   171     CreateContainerL();
       
   172     AppUi()->AddToStackL( *this, iContainer );
       
   173     HandleClientRectChange();
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CWmDrmDlaBrowserView::DoDeactivate
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CWmDrmDlaBrowserView::DoDeactivate()
       
   181     {
       
   182     RemoveContainer();
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CWmDrmDlaBrowserView::HandleClientRectChange
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CWmDrmDlaBrowserView::HandleClientRectChange()
       
   190     {
       
   191     if ( iContainer )
       
   192         {
       
   193         iContainer->SetRect( ClientRect() );
       
   194         }
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CWmDrmDlaBrowserView::CreateContainerL
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void CWmDrmDlaBrowserView::CreateContainerL()
       
   202     {
       
   203     RemoveContainer();
       
   204     iContainer = CWmDrmDlaBrowserContainer::NewL( this, this );
       
   205     iContainer->SetMopParent( this );    
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CWmDrmDlaBrowserView::RemoveContainer
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CWmDrmDlaBrowserView::RemoveContainer()
       
   213     {
       
   214     if ( iContainer )
       
   215         {
       
   216         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   217         delete iContainer;
       
   218         iContainer = NULL;
       
   219         }
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CWmDrmDlaBrowserView::BrCtlHandleCommandL
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CWmDrmDlaBrowserView::BrCtlHandleCommandL( TInt aCommand )
       
   227     {
       
   228     iContainer->BrCtlInterface()->HandleCommandL( aCommand );
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CWmDrmDlaBrowserView::NetworkConnectionNeededL
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void CWmDrmDlaBrowserView::NetworkConnectionNeededL( 
       
   236     TInt* aConnectionPtr, 
       
   237     TInt* aSockSvrHandle, 
       
   238     TBool* aNewConn, 
       
   239     TApBearerType* aBearerType )
       
   240     {
       
   241     TInt ret( 0 );
       
   242     // If not connected, try to start a new connection
       
   243     if ( !iConMgr->Connected() )
       
   244         {
       
   245         iConMgr->SetRequestedAP( iIap );
       
   246         ret = iConMgr->StartConnectionL( ETrue );
       
   247         }
       
   248     
       
   249     // If connected, return needed info to framework
       
   250     if ( !ret )
       
   251         {
       
   252         *aConnectionPtr =  reinterpret_cast<TInt>(&iConMgr->Connection() );
       
   253         *aSockSvrHandle =  iConMgr->SocketServer().Handle();
       
   254         *aNewConn = EFalse;
       
   255         *aBearerType = EApBearerTypeAllBearers;
       
   256         }
       
   257     else 
       
   258         {
       
   259         User::Leave( KErrCancel );
       
   260         }
       
   261     }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // CWmDrmDlaBrowserView::HandleRequestL
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 TBool CWmDrmDlaBrowserView::HandleRequestL( 
       
   268     RArray<TUint>* /*aTypeArray*/, 
       
   269     CDesCArrayFlat* /*aDesArray*/ )
       
   270     {
       
   271     return EFalse;
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // CWmDrmDlaBrowserView::HandleDownloadL
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 TBool CWmDrmDlaBrowserView::HandleDownloadL( 
       
   279     RArray<TUint>* aTypeArray, 
       
   280     CDesCArrayFlat* aDesArray )
       
   281     {
       
   282     //Check that content type and local file name exists
       
   283     //There must be both, because download manager downloads POST-content 
       
   284     //in advance calling this function
       
   285     TInt contentTypeIndex( aTypeArray->Find( EParamReceivedContentType ) ); 
       
   286     TInt fileNameIndex( aTypeArray->Find( EParamLocalFileName ) );
       
   287     if ( contentTypeIndex != KErrNotFound &&  
       
   288          fileNameIndex != KErrNotFound &&
       
   289          contentTypeIndex < aDesArray->Count() &&
       
   290          fileNameIndex < aDesArray->Count() )
       
   291         {
       
   292         //Check that the downloaded content is license response
       
   293         TPtrC16 dataTypePtr( (*aDesArray)[contentTypeIndex] );
       
   294         if ( dataTypePtr.CompareF( KDataTypeLicenseResponse ) == 0 )
       
   295             {
       
   296             //Get the path to the license response,
       
   297             //read the response, delete the file and 
       
   298             //make a license received - callback
       
   299             TPtrC16 filePathPtr( (*aDesArray)[fileNameIndex] );
       
   300             RFs fs;
       
   301             User::LeaveIfError( fs.Connect() );
       
   302             CleanupClosePushL( fs );
       
   303             RFile file;
       
   304             TInt size( 0 );
       
   305             User::LeaveIfError( file.Open( fs, filePathPtr, EFileRead ) );
       
   306             CleanupClosePushL( file );
       
   307             User::LeaveIfError( file.Size( size ) );
       
   308             delete iLicenseResponse;
       
   309             iLicenseResponse = NULL;
       
   310             iLicenseResponse = HBufC8::NewL( size );
       
   311             TPtr8 licensePtr( iLicenseResponse->Des() );
       
   312             User::LeaveIfError( file.Read( 0, licensePtr, size ) );
       
   313             CleanupStack::PopAndDestroy( &file );
       
   314             User::LeaveIfError( fs.Delete( filePathPtr ) );
       
   315             CleanupStack::PopAndDestroy( &fs );
       
   316             iCallback->LicenseReceived();
       
   317             return ETrue;
       
   318             }
       
   319         }
       
   320     return EFalse;
       
   321     }
       
   322