wmdrm/camese/wmdrmdlaapp/src/wmdrmdlabrowserview.cpp
branchRCL_3
changeset 26 1221b68b8a5f
parent 22 ad2863178d17
child 27 1481bf457703
equal deleted inserted replaced
25:50c53e893c3f 26:1221b68b8a5f
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    20 #include <f32file.h>
    20 #include <f32file.h>
    21 #include <bautils.h>
    21 #include <bautils.h>
    22 #include <aknViewAppUi.h>
    22 #include <aknViewAppUi.h>
    23 #include <coeaui.h>
    23 #include <coeaui.h>
    24 #include <coecntrl.h>
    24 #include <coecntrl.h>
    25 #include <brctlinterface.h>
    25 #include <InternetConnectionManager.h>
    26 #include <internetconnectionmanager.h>
       
    27 #include <wmdrmdlaapp.rsg>
    26 #include <wmdrmdlaapp.rsg>
    28 #include "wmdrmdlabrowserview.h"
    27 #include "wmdrmdlabrowserview.h"
    29 #include "wmdrmdlabrowsercontainer.h"
    28 #include "wmdrmdlabrowsercontainer.h"
    30 #include "wmdrmdlaappconstants.h"
    29 #include "wmdrmdlaappconstants.h"
    31 
    30 
    32 // CONTANTS
    31 // CONTANTS
    33 _LIT( KDataTypeLicenseResponse, "application/vnd.ms-wmdrm.lic-resp" );
       
    34 
    32 
    35 // ======== LOCAL FUNCTIONS ========
    33 // ======== LOCAL FUNCTIONS ========
    36 
    34 
    37 // ======== MEMBER FUNCTIONS ========
    35 // ======== MEMBER FUNCTIONS ========
    38 
    36 
    89     delete iLicenseResponse;
    87     delete iLicenseResponse;
    90     delete iConMgr;
    88     delete iConMgr;
    91     }
    89     }
    92 
    90 
    93 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
    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
    92 // CWmDrmDlaBrowserView::Id
   135 // ---------------------------------------------------------------------------
    93 // ---------------------------------------------------------------------------
   136 //
    94 //
   137 TUid CWmDrmDlaBrowserView::Id() const
    95 TUid CWmDrmDlaBrowserView::Id() const
   138     {
    96     {
   139     return KWmDrmDlaAppBrowserViewId;
    97     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         iContainer->BrCtlInterface()->HandleCommandL( (TInt)TBrCtlDefs::ECommandCancelFetch + 
       
   159                                                       (TInt)TBrCtlDefs::ECommandIdBase );            
       
   160         AppUi()->HandleCommandL( aCommand );
       
   161         }
       
   162     }
    98     }
   163 
    99 
   164 // ---------------------------------------------------------------------------
   100 // ---------------------------------------------------------------------------
   165 // CWmDrmDlaBrowserView::DoActivateL
   101 // CWmDrmDlaBrowserView::DoActivateL
   166 // ---------------------------------------------------------------------------
   102 // ---------------------------------------------------------------------------
   201 // ---------------------------------------------------------------------------
   137 // ---------------------------------------------------------------------------
   202 //
   138 //
   203 void CWmDrmDlaBrowserView::CreateContainerL()
   139 void CWmDrmDlaBrowserView::CreateContainerL()
   204     {
   140     {
   205     RemoveContainer();
   141     RemoveContainer();
   206     iContainer = CWmDrmDlaBrowserContainer::NewL( this, this );
       
   207     iContainer->SetMopParent( this );
       
   208     }
   142     }
   209 
   143 
   210 // ---------------------------------------------------------------------------
   144 // ---------------------------------------------------------------------------
   211 // CWmDrmDlaBrowserView::RemoveContainer
   145 // CWmDrmDlaBrowserView::RemoveContainer
   212 // ---------------------------------------------------------------------------
   146 // ---------------------------------------------------------------------------
   218         AppUi()->RemoveFromViewStack( *this, iContainer );
   152         AppUi()->RemoveFromViewStack( *this, iContainer );
   219         delete iContainer;
   153         delete iContainer;
   220         iContainer = NULL;
   154         iContainer = NULL;
   221         }
   155         }
   222     }
   156     }
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // CWmDrmDlaBrowserView::BrCtlHandleCommandL
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 void CWmDrmDlaBrowserView::BrCtlHandleCommandL( TInt aCommand )
       
   229     {
       
   230     iContainer->BrCtlInterface()->HandleCommandL( aCommand );
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CWmDrmDlaBrowserView::NetworkConnectionNeededL
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 void CWmDrmDlaBrowserView::NetworkConnectionNeededL(
       
   238     TInt* aConnectionPtr,
       
   239     TInt* aSockSvrHandle,
       
   240     TBool* aNewConn,
       
   241     TApBearerType* aBearerType )
       
   242     {
       
   243     TInt ret( 0 );
       
   244     // If not connected, try to start a new connection
       
   245     if ( !iConMgr->Connected() )
       
   246         {
       
   247         iConMgr->SetRequestedAP( iIap );
       
   248         ret = iConMgr->StartConnectionL( ETrue );
       
   249         }
       
   250 
       
   251     // If connected, return needed info to framework
       
   252     if ( !ret )
       
   253         {
       
   254         *aConnectionPtr =  reinterpret_cast<TInt>(&iConMgr->Connection() );
       
   255         *aSockSvrHandle =  iConMgr->SocketServer().Handle();
       
   256         *aNewConn = EFalse;
       
   257         *aBearerType = EApBearerTypeAllBearers;
       
   258         }
       
   259     else
       
   260         {
       
   261         User::Leave( KErrCancel );
       
   262         }
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // CWmDrmDlaBrowserView::HandleRequestL
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 TBool CWmDrmDlaBrowserView::HandleRequestL(
       
   270     RArray<TUint>* /*aTypeArray*/,
       
   271     CDesCArrayFlat* /*aDesArray*/ )
       
   272     {
       
   273     return EFalse;
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CWmDrmDlaBrowserView::HandleDownloadL
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 TBool CWmDrmDlaBrowserView::HandleDownloadL(
       
   281     RArray<TUint>* aTypeArray,
       
   282     CDesCArrayFlat* aDesArray )
       
   283     {
       
   284     //Check that content type and local file name exists
       
   285     //There must be both, because download manager downloads POST-content
       
   286     //in advance calling this function
       
   287     TInt contentTypeIndex( aTypeArray->Find( EParamReceivedContentType ) );
       
   288     TInt fileNameIndex( aTypeArray->Find( EParamLocalFileName ) );
       
   289     if ( contentTypeIndex != KErrNotFound &&
       
   290          fileNameIndex != KErrNotFound &&
       
   291          contentTypeIndex < aDesArray->Count() &&
       
   292          fileNameIndex < aDesArray->Count() )
       
   293         {
       
   294         //Check that the downloaded content is license response
       
   295         TPtrC16 dataTypePtr( (*aDesArray)[contentTypeIndex] );
       
   296         if ( dataTypePtr.CompareF( KDataTypeLicenseResponse ) == 0 )
       
   297             {
       
   298             //Get the path to the license response,
       
   299             //read the response, delete the file and
       
   300             //make a license received - callback
       
   301             TPtrC16 filePathPtr( (*aDesArray)[fileNameIndex] );
       
   302             RFs fs;
       
   303             User::LeaveIfError( fs.Connect() );
       
   304             CleanupClosePushL( fs );
       
   305             RFile file;
       
   306             TInt size( 0 );
       
   307             User::LeaveIfError( file.Open( fs, filePathPtr, EFileRead ) );
       
   308             CleanupClosePushL( file );
       
   309             User::LeaveIfError( file.Size( size ) );
       
   310             delete iLicenseResponse;
       
   311             iLicenseResponse = NULL;
       
   312             iLicenseResponse = HBufC8::NewL( size );
       
   313             TPtr8 licensePtr( iLicenseResponse->Des() );
       
   314             User::LeaveIfError( file.Read( 0, licensePtr, size ) );
       
   315             CleanupStack::PopAndDestroy( &file );
       
   316             User::LeaveIfError( fs.Delete( filePathPtr ) );
       
   317             CleanupStack::PopAndDestroy( &fs );
       
   318             iCallback->LicenseReceived();
       
   319             return ETrue;
       
   320             }
       
   321         }
       
   322     return EFalse;
       
   323     }
       
   324