commondrm/drmutility/src/DrmUiHandlingImpl.cpp
changeset 0 95b198f216e5
child 2 76350b5be3d8
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2  * Copyright (c) 2006-2009 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:  DRM UI Handling implementation class
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 // connection
       
    21 #include <cmconnectionmethod.h>
       
    22 #include <cmdestination.h>
       
    23 #include <cmconnectionmethoddef.h>
       
    24 #include <cmmanager.h>
       
    25 #include <sacls.h>
       
    26 #include <utf.h>
       
    27 
       
    28 // publish & subscribe
       
    29 #include <e32property.h>
       
    30 #include <psvariables.h>
       
    31 #include <centralrepository.h>
       
    32 
       
    33 // coeenv
       
    34 #include <coemain.h>
       
    35 #include <apgtask.h>
       
    36 #include <avkon.hrh>
       
    37 #include <aknenv.h>
       
    38 
       
    39 // browser
       
    40 #ifdef __SERIES60_NATIVE_BROWSER
       
    41 #include <browseruisdkcrkeys.h>
       
    42 #endif
       
    43 
       
    44 // caf
       
    45 #include <caf/data.h>
       
    46 #include <caf/caftypes.h>
       
    47 
       
    48 // launching embedded details view
       
    49 #include <aknlaunchappservice.h>
       
    50 #include <aiwgenericparam.h>
       
    51 #include <apgcli.h>
       
    52 
       
    53 // character conversions
       
    54 #include <utf.h>
       
    55 
       
    56 // handling urls
       
    57 #include <schemehandler.h>
       
    58 
       
    59 // resources
       
    60 #include <data_caging_path_literals.hrh>
       
    61 #include <drmutility.rsg>
       
    62 
       
    63 // drm
       
    64 #include <oma2agent.h>
       
    65 #include <drmagents.h>
       
    66 #include <drmpermission.h>
       
    67 #include <drmconstraint.h>
       
    68 #include <drmrightsclient.h>
       
    69 #include <drmutility.h>
       
    70 #include <drmutilitytypes.h>
       
    71 #include <drmasyncobserver.h>
       
    72 #include <drmhandleerrorobserver.h>
       
    73 
       
    74 #ifdef _DEBUG
       
    75 #include <e32debug.h>
       
    76 #endif
       
    77 
       
    78 #include "drmutilitycommon.h"
       
    79 #include "drmutilityui.h"
       
    80 #include "drmuihandlingimpl.h"
       
    81 #include "drmuihandlingdata.h"
       
    82 #include "drmutilitydownloadmanager.h"
       
    83 #include "drmutilityinternaltypes.h"
       
    84 #include "drmuicheckrightsobserver.h"
       
    85 #include "drmutilitywmdrm.h"
       
    86 #include "drmutilitywmdrmwrapper.h"
       
    87 
       
    88 #include "roapstorageclient.h"
       
    89 #include "drmtypes.h"
       
    90 #include "drmsettingsplugininternalcrkeys.h"
       
    91 #include "drmricontext.h"
       
    92 #include "drmdomaincontext.h"
       
    93 
       
    94 #include "drmutilityinternalcrkeys.h"      // Cenrep extension for OmaBased
       
    95 
       
    96 // CONSTANTS
       
    97 const TInt KCommandHandleErrorFile( 1 );
       
    98 const TInt KCommandHandleErrorData( 2 );
       
    99 const TInt KCommandCheckRightsAmountFile( 3 );
       
   100 const TInt KCommandCheckRightsAmountData( 4 );
       
   101 const TInt KCommandShowDetailsViewFile( 5 );
       
   102 const TInt KCommandShowDetailsViewData( 6 );
       
   103 const TInt KCommandHandleUrlFile( 7 );
       
   104 const TInt KCommandHandleUrlData( 8 );
       
   105 const TInt KCommandAvailableUrlsFile( 9 );
       
   106 const TInt KCommandAvailableUrlsData( 10 );
       
   107 // browser
       
   108 #ifndef __SERIES60_NATIVE_BROWSER
       
   109 const TUid KCRUidBrowser =
       
   110     {0x10008D39};
       
   111 const TUint32 KBrowserDefaultAccessPoint = 0x0000000E;
       
   112 const TUint32 KBrowserAccessPointSelectionMode = 0x0000001E;
       
   113 const TUint32 KBrowserNGDefaultSnapId = 0x00000053;
       
   114 #endif
       
   115 
       
   116 _LIT( KEncryptedRightsIssuerMatchString, "flk*" );
       
   117 
       
   118 // buffer sizes
       
   119 const TInt KDRMMaxETABufSize( 11 );
       
   120 const TInt KUrlMaxLen( 1024 );
       
   121 const TInt KIntegerMaxLen( 10 );
       
   122 
       
   123 // constant sizes
       
   124 const TInt KOmaDomainGenerationLength( 3 );
       
   125 
       
   126 // masks for constraint existence
       
   127 const TInt KDRMOmaConstraintCount( 1 );
       
   128 const TInt KDRMOmaConstraintTime( 2 );
       
   129 const TInt KDRMOmaConstraintAccumulated( 4 );
       
   130 
       
   131 const TInt KCenRepDataLength( 50 );
       
   132 
       
   133 const TInt KresOmaBasedBuf( 512 );
       
   134 const TInt KNameBuf( 256 );
       
   135 #ifdef _DEBUG
       
   136 // debug panic
       
   137 _LIT( KDRMUtilityDebugPanicMessage, "DrmUiHandlingDebugPanic" );
       
   138 const TInt KDRMUtilityDebugPanicCode( 1 );
       
   139 #endif
       
   140 
       
   141 // ============================= LOCAL FUNCTIONS ===============================
       
   142 // -----------------------------------------------------------------------------
       
   143 // MapToCallError
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 LOCAL_C inline TInt CheckAndMapToCallError(
       
   147     RDRMRightsClient& aOmaClient,
       
   148     ContentAccess::TIntent aIntent,
       
   149     const TDesC8& aContentUri )
       
   150     {
       
   151     TUint32 rr( KErrNone );
       
   152     TInt err( aOmaClient.CheckRights( aIntent, aContentUri, rr ) );
       
   153     return err ? KErrCANoRights : KErrNone;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // IapIdOfDefaultSnapL
       
   158 // for trapping purposes only
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 LOCAL_C TUint32 IapIdOfDefaultSnapL(
       
   162     RCmManager& aCmManager,
       
   163     const TUint32 aDefaultSnap )
       
   164     {
       
   165     RCmDestination dest( aCmManager.DestinationL( aDefaultSnap ) );
       
   166     CleanupClosePushL( dest );
       
   167     TUint32 iapIdOfDest( 0 );
       
   168 
       
   169     if ( dest.ConnectionMethodCount() <= 0 )
       
   170         {
       
   171         User::Leave( KErrNotFound );
       
   172         }
       
   173 
       
   174     RCmConnectionMethod cMeth( dest.ConnectionMethodL( 0 ) );
       
   175     CleanupClosePushL( cMeth );
       
   176 
       
   177     iapIdOfDest = cMeth.GetIntAttributeL( CMManager::ECmIapId );
       
   178     CleanupStack::PopAndDestroy( &cMeth );
       
   179     CleanupStack::PopAndDestroy( &dest );
       
   180     return iapIdOfDest;
       
   181     }
       
   182 
       
   183 // ============================ MEMBER FUNCTIONS ===============================
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CDrmUiHandlingImpl::CDrmUiHandlingImpl
       
   187 // C++ default constructor can NOT contain any code, that
       
   188 // might leave.
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 DRM::CDrmUiHandlingImpl::CDrmUiHandlingImpl(
       
   192     DRM::CDrmUtility* aDrmUtility,
       
   193     CCoeEnv* aCoeEnv ) :
       
   194     CActive( EPriorityStandard ), iCoeEnv( aCoeEnv ), iDrmUtility(
       
   195         aDrmUtility )
       
   196     {
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CDrmUiHandlingImpl::ConstructL
       
   201 // Symbian 2nd phase constructor can leave.
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 void DRM::CDrmUiHandlingImpl::ConstructL()
       
   205     {
       
   206     TInt err( KErrNone );
       
   207 
       
   208     iDrmUtilityCommon = DRM::CDrmUtilityCommon::NewL();
       
   209 
       
   210     iDrmUtilityUi = DRM::CDrmUtilityUI::NewL( iCoeEnv );
       
   211 
       
   212     User::LeaveIfError( iOmaClient.Connect() );
       
   213 
       
   214     User::LeaveIfError( iSemaphore.CreateLocal( 1 ) );
       
   215 
       
   216         TRAP_IGNORE( iWrapperLoader = DRM::CDrmUtilityWMDrm::NewL( iCoeEnv ) );
       
   217 
       
   218     if ( iWrapperLoader )
       
   219         {
       
   220         iWmClient = iWrapperLoader->GetWrapper();
       
   221         }
       
   222         TRAP(err, GetOmaBasedInfoL() );
       
   223     if ( err )
       
   224         {
       
   225         if ( iOmaBasedAgentName )
       
   226             {
       
   227             delete iOmaBasedAgentName;
       
   228             }
       
   229         iOmaBasedAgentName = NULL;
       
   230         iOmaBasedUid = 0;
       
   231         if ( iOmaBasedMimeType )
       
   232             {
       
   233             delete iOmaBasedMimeType;
       
   234             }
       
   235         iOmaBasedMimeType = NULL;
       
   236         }
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CDrmUiHandlingImpl::GetOmaBasedInfoL
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void DRM::CDrmUiHandlingImpl::GetOmaBasedInfoL()
       
   244     {
       
   245     TInt err = KErrNone;
       
   246     CRepository* repository( NULL );
       
   247     RBuf bOmaBasedAgentName;
       
   248     RBuf bOmaBasedMimeType;
       
   249 
       
   250     CleanupClosePushL( bOmaBasedAgentName );
       
   251     CleanupClosePushL( bOmaBasedMimeType );
       
   252     bOmaBasedAgentName.CreateL( KCenRepDataLength );
       
   253     bOmaBasedMimeType.CreateL( KCenRepDataLength );
       
   254 
       
   255         TRAP( err, repository = CRepository::NewL( KCRUidOmaBased ) );
       
   256     if ( !err )
       
   257         {
       
   258         CleanupStack::PushL( repository );
       
   259 
       
   260         err = repository->Get( KDrmOmaBasedName, bOmaBasedAgentName );
       
   261         if ( !err )
       
   262             {
       
   263             iOmaBasedAgentName = bOmaBasedAgentName.AllocL();
       
   264             }
       
   265 
       
   266         err = repository->Get( KDrmOmaBasedUID, iOmaBasedUid );
       
   267 
       
   268         err = repository->Get( KOmaBasedMimeType, bOmaBasedMimeType );
       
   269         if ( !err )
       
   270             {
       
   271             iOmaBasedMimeType = CnvUtfConverter::ConvertFromUnicodeToUtf8L(
       
   272                 bOmaBasedMimeType );
       
   273             }
       
   274         CleanupStack::PopAndDestroy( repository );
       
   275         }
       
   276 
       
   277     CleanupStack::PopAndDestroy( 2, &bOmaBasedAgentName );
       
   278     User::LeaveIfError( err );
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CDrmUiHandlingImpl::NewL
       
   283 // Two-phased constructor.
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 EXPORT_C DRM::CDrmUiHandlingImpl* DRM::CDrmUiHandlingImpl::NewL(
       
   287     DRM::CDrmUtility* aDrmUtility,
       
   288     CCoeEnv* aCoeEnv )
       
   289     {
       
   290     DRM::CDrmUiHandlingImpl* self( NewLC( aDrmUtility, aCoeEnv ) );
       
   291 
       
   292     CleanupStack::Pop( self );
       
   293 
       
   294     return self;
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CDrmUiHandlingImpl::NewLC
       
   299 // Two-phased constructor.
       
   300 // -----------------------------------------------------------------------------
       
   301 //
       
   302 EXPORT_C DRM::CDrmUiHandlingImpl* DRM::CDrmUiHandlingImpl::NewLC(
       
   303     DRM::CDrmUtility* aDrmUtility,
       
   304     CCoeEnv* aCoeEnv )
       
   305     {
       
   306     DRM::CDrmUiHandlingImpl* self( new ( ELeave ) CDrmUiHandlingImpl(
       
   307         aDrmUtility, aCoeEnv ) );
       
   308 
       
   309     CleanupStack::PushL( self );
       
   310     self->ConstructL();
       
   311 
       
   312     return self;
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CDrmUiHandlingImpl::~CDrmUiHandlingImpl()
       
   317 // Destructor
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 DRM::CDrmUiHandlingImpl::~CDrmUiHandlingImpl()
       
   321     {
       
   322     DRM::CDrmUiHandlingData* data( PopFront() );
       
   323 
       
   324     // Empty the queue:
       
   325     while ( data )
       
   326         {
       
   327         // Complete the outstanding requestest with cancel
       
   328         data->iObserver->OperationCompleted( data->iOperationId, KErrCancel );
       
   329         delete data;
       
   330         data = PopFront();
       
   331         }
       
   332 
       
   333     delete iDrmUtilityCommon;
       
   334 
       
   335     delete iDrmUtilityUi;
       
   336 
       
   337     delete iSchemeHandler;
       
   338 
       
   339     delete iWrapperLoader;
       
   340 
       
   341     delete iOmaBasedAgentName;
       
   342 
       
   343     delete iOmaBasedMimeType;
       
   344 
       
   345     iOmaClient.Close();
       
   346 
       
   347     // Close the semaphone
       
   348     iSemaphore.Close();
       
   349 
       
   350     // Remove the object from active scheduler etc.
       
   351     if ( IsAdded() )
       
   352         {
       
   353         Deque();
       
   354         }
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CDrmUiHandlingImpl::CheckRightsAmountAsyncL
       
   359 // Check how much rights there are left for the content.
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 EXPORT_C TInt DRM::CDrmUiHandlingImpl::CheckRightsAmountAsyncL(
       
   363     RFile& aFile,
       
   364     ContentAccess::TIntent aIntent,
       
   365     DRM::MDrmUiCheckRightsObserver& aObserver )
       
   366     {
       
   367     TRequestStatus* status( &iStatus );
       
   368 
       
   369     // Create data object:
       
   370     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   371     data->iObserver = &aObserver;
       
   372     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   373     data->iOperation = KCommandCheckRightsAmountFile;
       
   374     data->iFile = &aFile;
       
   375     data->iIntent = aIntent;
       
   376     data->iCheckRightsObserver = &aObserver;
       
   377 
       
   378     // Add it to the queue:
       
   379     AppendToQueue( data );
       
   380 
       
   381     // Pop it from the cleanup stack
       
   382     CleanupStack::Pop( data );
       
   383 
       
   384     Activate( status );
       
   385 
       
   386     return data->iOperationId;
       
   387     }
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // CDrmUiHandlingImpl::CheckRightsAmountL
       
   391 // Check how much rights there are left for the content.
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 EXPORT_C void DRM::CDrmUiHandlingImpl::CheckRightsAmountL(
       
   395     RFile& aFile,
       
   396     ContentAccess::TIntent aIntent,
       
   397     DRM::MDrmUiCheckRightsObserver* aObserver )
       
   398     {
       
   399     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   400 
       
   401     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   402     data->iFile = &aFile;
       
   403     data->iIntent = aIntent;
       
   404     data->iCheckRightsObserver = aObserver;
       
   405 
       
   406     PerformCheckRightsAmountFileL( *data );
       
   407 
       
   408     CleanupStack::PopAndDestroy( data );
       
   409     }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CDrmUiHandlingImpl::CheckRightsAmountAsyncL
       
   413 // Check how much rights there are left for the content.
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 EXPORT_C TInt DRM::CDrmUiHandlingImpl::CheckRightsAmountAsyncL(
       
   417     ContentAccess::CData& aFile,
       
   418     ContentAccess::TIntent aIntent,
       
   419     DRM::MDrmUiCheckRightsObserver& aObserver )
       
   420     {
       
   421     TRequestStatus* status( &iStatus );
       
   422 
       
   423     // create data object:
       
   424     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   425 
       
   426     data->iObserver = &aObserver;
       
   427     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   428     data->iOperation = KCommandCheckRightsAmountData;
       
   429     data->iFileData = &aFile;
       
   430     data->iIntent = aIntent;
       
   431     data->iCheckRightsObserver = &aObserver;
       
   432 
       
   433     // Add it to the queue:
       
   434     AppendToQueue( data );
       
   435 
       
   436     // Pop it from the cleanup stack
       
   437     CleanupStack::Pop( data );
       
   438 
       
   439     Activate( status );
       
   440 
       
   441     return data->iOperationId;
       
   442     }
       
   443 
       
   444 // -----------------------------------------------------------------------------
       
   445 // CDrmUiHandlingImpl::CheckRightsAmountL
       
   446 // Check how much rights there are left for the content.
       
   447 // -----------------------------------------------------------------------------
       
   448 //
       
   449 EXPORT_C void DRM::CDrmUiHandlingImpl::CheckRightsAmountL(
       
   450     ContentAccess::CData& aFile,
       
   451     ContentAccess::TIntent aIntent,
       
   452     DRM::MDrmUiCheckRightsObserver* aObserver )
       
   453     {
       
   454     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   455 
       
   456     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   457     data->iFileData = &aFile;
       
   458     data->iIntent = aIntent;
       
   459     data->iCheckRightsObserver = aObserver;
       
   460 
       
   461     PerformCheckRightsAmountDataL( *data );
       
   462 
       
   463     CleanupStack::PopAndDestroy( data );
       
   464     }
       
   465 
       
   466 // -----------------------------------------------------------------------------
       
   467 // CDrmUiHandlingImpl::ShowDetailsViewAsyncL
       
   468 // Shows DRM specific details
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 EXPORT_C TInt DRM::CDrmUiHandlingImpl::ShowDetailsViewAsyncL(
       
   472     RFile& aFile,
       
   473     DRM::MDrmAsyncObserver& aObserver )
       
   474     {
       
   475     TRequestStatus* status( &iStatus );
       
   476 
       
   477     // create data object:
       
   478     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   479 
       
   480     data->iObserver = &aObserver;
       
   481     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   482     data->iOperation = KCommandShowDetailsViewFile;
       
   483     data->iFile = &aFile;
       
   484 
       
   485     // Add it to the queue:
       
   486     AppendToQueue( data );
       
   487 
       
   488     // Pop it from the cleanup stack
       
   489     CleanupStack::Pop( data );
       
   490 
       
   491     Activate( status );
       
   492 
       
   493     return data->iOperationId;
       
   494     }
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // CDrmUiHandlingImpl::ShowDetailsViewL
       
   498 // Shows DRM specific details
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 EXPORT_C void DRM::CDrmUiHandlingImpl::ShowDetailsViewL( RFile& aFile )
       
   502     {
       
   503     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   504 
       
   505     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   506     data->iFile = &aFile;
       
   507 
       
   508     PerformShowDetailsViewFileL( *data );
       
   509 
       
   510     CleanupStack::PopAndDestroy( data );
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CDrmUiHandlingImpl::ShowDetailsViewAsyncL
       
   515 // Shows DRM specific details
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 EXPORT_C TInt DRM::CDrmUiHandlingImpl::ShowDetailsViewAsyncL(
       
   519     ContentAccess::CData& aFile,
       
   520     DRM::MDrmAsyncObserver& aObserver )
       
   521     {
       
   522     TRequestStatus* status( &iStatus );
       
   523 
       
   524     // create data object:
       
   525     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   526 
       
   527     data->iObserver = &aObserver;
       
   528     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   529     data->iOperation = KCommandShowDetailsViewData;
       
   530     data->iFileData = &aFile;
       
   531 
       
   532     // Add it to the queue:
       
   533     AppendToQueue( data );
       
   534 
       
   535     // Pop it from the cleanup stack
       
   536     CleanupStack::Pop( data );
       
   537 
       
   538     Activate( status );
       
   539 
       
   540     return data->iOperationId;
       
   541     }
       
   542 
       
   543 // -----------------------------------------------------------------------------
       
   544 // CDrmUiHandlingImpl::ShowDetailsViewL
       
   545 // Shows DRM specific details.
       
   546 // -----------------------------------------------------------------------------
       
   547 //
       
   548 EXPORT_C void DRM::CDrmUiHandlingImpl::ShowDetailsViewL(
       
   549     ContentAccess::CData& aFile )
       
   550     {
       
   551     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   552 
       
   553     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   554     data->iFileData = &aFile;
       
   555 
       
   556     PerformShowDetailsViewDataL( *data );
       
   557 
       
   558     CleanupStack::PopAndDestroy( data );
       
   559     }
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // CDrmUiHandlingImpl::HandleUrlAsyncL
       
   563 // Handles a specific url defined by the file, such as InfoUrl
       
   564 // -----------------------------------------------------------------------------
       
   565 //
       
   566 EXPORT_C TInt DRM::CDrmUiHandlingImpl::HandleUrlAsyncL(
       
   567     RFile& aFile,
       
   568     DRM::TDrmUiUrlType aType,
       
   569     DRM::MDrmAsyncObserver& aObserver )
       
   570     {
       
   571     TRequestStatus* status( &iStatus );
       
   572 
       
   573     // create data object:
       
   574     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   575 
       
   576     data->iObserver = &aObserver;
       
   577     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   578     data->iOperation = KCommandHandleUrlFile;
       
   579     data->iFile = &aFile;
       
   580     data->iTypeParam = aType;
       
   581 
       
   582     // Add it to the queue:
       
   583     AppendToQueue( data );
       
   584 
       
   585     // Pop it from the cleanup stack
       
   586     CleanupStack::Pop( data );
       
   587 
       
   588     Activate( status );
       
   589 
       
   590     return data->iOperationId;
       
   591     }
       
   592 
       
   593 // -----------------------------------------------------------------------------
       
   594 // CDrmUiHandlingImpl::HandleUrlL
       
   595 // Handles a specific url defined by the file, such as InfoUrl
       
   596 // -----------------------------------------------------------------------------
       
   597 //
       
   598 EXPORT_C void DRM::CDrmUiHandlingImpl::HandleUrlL(
       
   599     RFile& aFile,
       
   600     DRM::TDrmUiUrlType aType )
       
   601     {
       
   602     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   603 
       
   604     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   605     data->iFile = &aFile;
       
   606     data->iTypeParam = aType;
       
   607 
       
   608     PerformHandleUrlFileL( *data );
       
   609 
       
   610     CleanupStack::PopAndDestroy( data );
       
   611     }
       
   612 
       
   613 // -----------------------------------------------------------------------------
       
   614 // CDrmUiHandlingImpl::HandleUrlAsyncL
       
   615 // Handles the specific url defined by the file, such as InfoUrl
       
   616 // -----------------------------------------------------------------------------
       
   617 //
       
   618 EXPORT_C TInt DRM::CDrmUiHandlingImpl::HandleUrlAsyncL(
       
   619     ContentAccess::CData& aFile,
       
   620     DRM::TDrmUiUrlType aType,
       
   621     DRM::MDrmAsyncObserver& aObserver )
       
   622     {
       
   623     TRequestStatus* status( &iStatus );
       
   624 
       
   625     // create data object:
       
   626     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   627 
       
   628     data->iObserver = &aObserver;
       
   629     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   630     data->iOperation = KCommandHandleUrlData;
       
   631     data->iFileData = &aFile;
       
   632     data->iTypeParam = aType;
       
   633 
       
   634     // Add it to the queue:
       
   635     AppendToQueue( data );
       
   636 
       
   637     // Pop it from the cleanup stack
       
   638     CleanupStack::Pop( data );
       
   639 
       
   640     Activate( status );
       
   641 
       
   642     return data->iOperationId;
       
   643     }
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // CDrmUiHandlingImpl::HandleUrlL
       
   647 // Handles the specific url defined by the file, such as InfoUrl
       
   648 // -----------------------------------------------------------------------------
       
   649 //
       
   650 EXPORT_C void DRM::CDrmUiHandlingImpl::HandleUrlL(
       
   651     ContentAccess::CData& aFile,
       
   652     DRM::TDrmUiUrlType aType )
       
   653     {
       
   654     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   655 
       
   656     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   657     data->iFileData = &aFile;
       
   658     data->iTypeParam = aType;
       
   659 
       
   660     PerformHandleUrlDataL( *data );
       
   661 
       
   662     CleanupStack::PopAndDestroy( data );
       
   663     }
       
   664 
       
   665 // -----------------------------------------------------------------------------
       
   666 // CDrmUiHandlingImpl::AvailableUrlsAsyncL
       
   667 // Gets information of the available urls
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 EXPORT_C TInt DRM::CDrmUiHandlingImpl::AvailableUrlsAsyncL(
       
   671     RFile& aFile,
       
   672     DRM::TDrmUiUrlType& aType,
       
   673     DRM::MDrmAsyncObserver& aObserver )
       
   674     {
       
   675     TRequestStatus* status( &iStatus );
       
   676 
       
   677     // create data object:
       
   678     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   679 
       
   680     data->iObserver = &aObserver;
       
   681     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   682     data->iOperation = KCommandAvailableUrlsFile;
       
   683     data->iFile = &aFile;
       
   684     data->iType = &aType;
       
   685 
       
   686     // Add it to the queue:
       
   687     AppendToQueue( data );
       
   688 
       
   689     // Pop it from the cleanup stack
       
   690     CleanupStack::Pop( data );
       
   691 
       
   692     Activate( status );
       
   693 
       
   694     return data->iOperationId;
       
   695     }
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // CDrmUiHandlingImpl::AvailableUrlsL
       
   699 // Gets information of the available urls
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 EXPORT_C void DRM::CDrmUiHandlingImpl::AvailableUrlsL(
       
   703     RFile& aFile,
       
   704     DRM::TDrmUiUrlType& aType )
       
   705     {
       
   706     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   707 
       
   708     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   709     data->iFile = &aFile;
       
   710     data->iType = &aType;
       
   711 
       
   712     PerformAvailableUrlsFileL( *data );
       
   713 
       
   714     CleanupStack::PopAndDestroy( data );
       
   715     }
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // CDrmUiHandlingImpl::AvailableUrlsAsyncL
       
   719 // Gets information of the available urls
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 EXPORT_C TInt DRM::CDrmUiHandlingImpl::AvailableUrlsAsyncL(
       
   723     ContentAccess::CData& aFile,
       
   724     DRM::TDrmUiUrlType& aType,
       
   725     DRM::MDrmAsyncObserver& aObserver )
       
   726     {
       
   727     TRequestStatus* status( &iStatus );
       
   728 
       
   729     // create data object:
       
   730     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   731 
       
   732     data->iObserver = &aObserver;
       
   733     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   734     data->iOperation = KCommandAvailableUrlsData;
       
   735     data->iFileData = &aFile;
       
   736     data->iType = &aType;
       
   737 
       
   738     // Add it to the queue:
       
   739     AppendToQueue( data );
       
   740 
       
   741     // Pop it from the cleanup stack
       
   742     CleanupStack::Pop( data );
       
   743 
       
   744     Activate( status );
       
   745 
       
   746     return data->iOperationId;
       
   747     }
       
   748 
       
   749 // -----------------------------------------------------------------------------
       
   750 // CDrmUiHandlingImpl::AvailableUrlsL
       
   751 // Gets information of the available urls
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 EXPORT_C void DRM::CDrmUiHandlingImpl::AvailableUrlsL(
       
   755     ContentAccess::CData& aFile,
       
   756     DRM::TDrmUiUrlType& aType )
       
   757     {
       
   758     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   759 
       
   760     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   761     data->iFileData = &aFile;
       
   762     data->iType = &aType;
       
   763 
       
   764     PerformAvailableUrlsDataL( *data );
       
   765 
       
   766     CleanupStack::PopAndDestroy( data );
       
   767     }
       
   768 
       
   769 // -----------------------------------------------------------------------------
       
   770 // CDrmUiHandlingImpl::HandleErrorAsyncL
       
   771 // Handles DRM specific error
       
   772 // -----------------------------------------------------------------------------
       
   773 //
       
   774 EXPORT_C TInt DRM::CDrmUiHandlingImpl::HandleErrorAsyncL(
       
   775     RFile& aFile,
       
   776     ContentAccess::TIntent aIntent,
       
   777     TInt aError,
       
   778     DRM::MDrmHandleErrorObserver& aObserver )
       
   779     {
       
   780     TRequestStatus* status( &iStatus );
       
   781 
       
   782     // create data object:
       
   783     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   784 
       
   785     data->iObserver = &aObserver;
       
   786     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   787     data->iOperation = KCommandHandleErrorFile;
       
   788     data->iFile = &aFile;
       
   789     data->iIntent = aIntent;
       
   790     data->iError = aError;
       
   791     data->iErrorObserver = &aObserver;
       
   792 
       
   793     // Add it to the queue:
       
   794     AppendToQueue( data );
       
   795 
       
   796     // Pop it from the cleanup stack
       
   797     CleanupStack::Pop( data );
       
   798 
       
   799     Activate( status );
       
   800 
       
   801     return data->iOperationId;
       
   802     }
       
   803 
       
   804 // -----------------------------------------------------------------------------
       
   805 // CDrmUiHandlingImpl::HandleError
       
   806 // Handles DRM specific error
       
   807 // -----------------------------------------------------------------------------
       
   808 //
       
   809 EXPORT_C void DRM::CDrmUiHandlingImpl::HandleErrorL(
       
   810     RFile& aFile,
       
   811     ContentAccess::TIntent aIntent,
       
   812     TInt aError,
       
   813     DRM::MDrmHandleErrorObserver* aObserver )
       
   814     {
       
   815     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   816 
       
   817     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   818     data->iFile = &aFile;
       
   819     data->iIntent = aIntent;
       
   820     data->iError = aError;
       
   821     data->iErrorObserver = aObserver;
       
   822 
       
   823     PerformHandleErrorFileL( *data );
       
   824 
       
   825     CleanupStack::PopAndDestroy( data );
       
   826     }
       
   827 
       
   828 // -----------------------------------------------------------------------------
       
   829 // CDrmUiHandlingImpl::HandleErrorAsyncL
       
   830 // Handles DRM specific error
       
   831 // -----------------------------------------------------------------------------
       
   832 //
       
   833 EXPORT_C TInt DRM::CDrmUiHandlingImpl::HandleErrorAsyncL(
       
   834     ContentAccess::CData& aFile,
       
   835     ContentAccess::TIntent aIntent,
       
   836     TInt aError,
       
   837     DRM::MDrmHandleErrorObserver& aObserver )
       
   838     {
       
   839     TRequestStatus* status( &iStatus );
       
   840 
       
   841     // create data object:
       
   842     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   843 
       
   844     data->iObserver = &aObserver;
       
   845     data->iOperationId = reinterpret_cast<TInt> ( data );
       
   846     data->iOperation = KCommandHandleErrorData;
       
   847     data->iFileData = &aFile;
       
   848     data->iIntent = aIntent;
       
   849     data->iError = aError;
       
   850     data->iErrorObserver = &aObserver;
       
   851 
       
   852     // Add it to the queue:
       
   853     AppendToQueue( data );
       
   854 
       
   855     // Pop it from the cleanup stack
       
   856     CleanupStack::Pop( data );
       
   857 
       
   858     Activate( status );
       
   859 
       
   860     return data->iOperationId;
       
   861     }
       
   862 
       
   863 // -----------------------------------------------------------------------------
       
   864 // CDrmUiHandlingImpl::HandleError
       
   865 // Handles DRM specific error
       
   866 // -----------------------------------------------------------------------------
       
   867 //
       
   868 EXPORT_C void DRM::CDrmUiHandlingImpl::HandleErrorL(
       
   869     ContentAccess::CData& aFile,
       
   870     ContentAccess::TIntent aIntent,
       
   871     TInt aError,
       
   872     DRM::MDrmHandleErrorObserver* aObserver )
       
   873     {
       
   874     DRM::CDrmUiHandlingData* data( DRM::CDrmUiHandlingData::NewLC() );
       
   875 
       
   876     data->iOperationId = 0; // operation id zero for a syncronous operation
       
   877     data->iFileData = &aFile;
       
   878     data->iIntent = aIntent;
       
   879     data->iError = aError;
       
   880     data->iErrorObserver = aObserver;
       
   881 
       
   882     PerformHandleErrorDataL( *data );
       
   883 
       
   884     CleanupStack::PopAndDestroy( data );
       
   885     }
       
   886 
       
   887 // -----------------------------------------------------------------------------
       
   888 // CDrmUiHandlingImpl::CancelOperation
       
   889 // Cancels the operation
       
   890 // -----------------------------------------------------------------------------
       
   891 //
       
   892 EXPORT_C TInt DRM::CDrmUiHandlingImpl::CancelOperation( TInt aOperationId )
       
   893     {
       
   894     // Critical area start:
       
   895     iSemaphore.Wait();
       
   896 
       
   897     TBool found( EFalse );
       
   898 
       
   899     DRM::CDrmUiHandlingData* previousData( NULL );
       
   900     DRM::CDrmUiHandlingData* currentData( iFirst );
       
   901 
       
   902     while ( currentData )
       
   903         {
       
   904         if ( currentData->iOperationId == aOperationId )
       
   905             {
       
   906             found = ETrue;
       
   907 
       
   908             //Update the previous link
       
   909             if ( previousData )
       
   910                 {
       
   911                 previousData->iNext = currentData->iNext;
       
   912                 }
       
   913             else
       
   914                 {
       
   915                 iFirst = currentData->iNext;
       
   916                 }
       
   917 
       
   918             //If the current is the only one, set iLast NULL
       
   919             if ( !iFirst )
       
   920                 {
       
   921                 iLast = NULL;
       
   922                 }
       
   923             //If only one left,set it also to be the iLast
       
   924             else if ( iFirst && !currentData->iNext )
       
   925                 {
       
   926                 iLast = iFirst;
       
   927                 }
       
   928 
       
   929             //Delete the cancelled operation
       
   930             currentData->iObserver->OperationCompleted(
       
   931                 currentData->iOperationId, KErrCancel );
       
   932             delete currentData;
       
   933             currentData = NULL;
       
   934             }
       
   935         else
       
   936             {
       
   937             previousData = currentData;
       
   938             currentData = currentData->iNext;
       
   939             }
       
   940         }
       
   941 
       
   942     if ( !found )
       
   943         {
       
   944         // Critical Area End
       
   945         iSemaphore.Signal();
       
   946         return KErrNotFound;
       
   947         }
       
   948 
       
   949     // Critical Area End
       
   950     iSemaphore.Signal();
       
   951     return KErrNone;
       
   952     }
       
   953 
       
   954 // -----------------------------------------------------------------------------
       
   955 // CDrmUiHandlingImpl::DoCancel()
       
   956 // From CActive Cancels async request.
       
   957 // -----------------------------------------------------------------------------
       
   958 //
       
   959 void DRM::CDrmUiHandlingImpl::DoCancel()
       
   960     {
       
   961     }
       
   962 
       
   963 // -----------------------------------------------------------------------------
       
   964 // CDrmUiHandlingImpl::RunL()
       
   965 // From CActive Called when async request completes.
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 void DRM::CDrmUiHandlingImpl::RunL()
       
   969     {
       
   970     DRM::CDrmUiHandlingData* data( PopFront() );
       
   971     TRequestStatus* status( &iStatus );
       
   972 
       
   973     if ( !data )
       
   974         {
       
   975         return;
       
   976         }
       
   977 
       
   978     CleanupStack::PushL( data );
       
   979 
       
   980     // Take this into the "current" variable in case an error occurs
       
   981     iObserver = data->iObserver;
       
   982     iOperationId = data->iOperationId;
       
   983 
       
   984     switch ( data->iOperation )
       
   985         {
       
   986         case KCommandHandleErrorFile:
       
   987 
       
   988             // Perform the operation
       
   989             PerformHandleErrorFileL( *data );
       
   990 
       
   991             break;
       
   992 
       
   993         case KCommandHandleErrorData:
       
   994 
       
   995             // Perform the operation
       
   996             PerformHandleErrorDataL( *data );
       
   997 
       
   998             break;
       
   999 
       
  1000         case KCommandCheckRightsAmountFile:
       
  1001 
       
  1002             // Perform the operation
       
  1003             PerformCheckRightsAmountFileL( *data );
       
  1004 
       
  1005             break;
       
  1006 
       
  1007         case KCommandCheckRightsAmountData:
       
  1008 
       
  1009             // Perform the operation
       
  1010             PerformCheckRightsAmountDataL( *data );
       
  1011 
       
  1012             break;
       
  1013 
       
  1014         case KCommandShowDetailsViewFile:
       
  1015 
       
  1016             // Perform the operation
       
  1017             PerformShowDetailsViewFileL( *data );
       
  1018 
       
  1019             break;
       
  1020 
       
  1021         case KCommandShowDetailsViewData:
       
  1022 
       
  1023             // Perform the operation
       
  1024             PerformShowDetailsViewDataL( *data );
       
  1025 
       
  1026             break;
       
  1027 
       
  1028         case KCommandHandleUrlFile:
       
  1029 
       
  1030             // Perform the operation
       
  1031             PerformHandleUrlFileL( *data );
       
  1032 
       
  1033             break;
       
  1034 
       
  1035         case KCommandHandleUrlData:
       
  1036 
       
  1037             // Perform the operation
       
  1038             PerformHandleUrlDataL( *data );
       
  1039 
       
  1040             break;
       
  1041 
       
  1042         case KCommandAvailableUrlsFile:
       
  1043 
       
  1044             // Perform the operation
       
  1045             PerformAvailableUrlsFileL( *data );
       
  1046 
       
  1047             break;
       
  1048 
       
  1049         case KCommandAvailableUrlsData:
       
  1050 
       
  1051             // Perform the operation
       
  1052             PerformAvailableUrlsDataL( *data );
       
  1053 
       
  1054             break;
       
  1055 
       
  1056         default:
       
  1057 
       
  1058             break;
       
  1059         }
       
  1060 
       
  1061     // Complete the client request
       
  1062     iObserver->OperationCompleted( iOperationId, KErrNone );
       
  1063 
       
  1064     // destroy the object:
       
  1065     CleanupStack::PopAndDestroy( data );
       
  1066 
       
  1067     // Get ready for another round:
       
  1068     SetActive();
       
  1069 
       
  1070     // complete internal request:
       
  1071     User::RequestComplete( status, KErrNone );
       
  1072     }
       
  1073 
       
  1074 // -----------------------------------------------------------------------------
       
  1075 // CDrmUiHandlingImpl::RunError()
       
  1076 // -----------------------------------------------------------------------------
       
  1077 //
       
  1078 TInt DRM::CDrmUiHandlingImpl::RunError( TInt aError )
       
  1079     {
       
  1080     iObserver->OperationCompleted( iOperationId, aError );
       
  1081     iObserver = NULL;
       
  1082     iOperationId = NULL;
       
  1083     return KErrNone;
       
  1084     }
       
  1085 
       
  1086 // -----------------------------------------------------------------------------
       
  1087 // CDrmUiHandlingImpl::Activate
       
  1088 // -----------------------------------------------------------------------------
       
  1089 //
       
  1090 void DRM::CDrmUiHandlingImpl::Activate( TRequestStatus*& aStatus )
       
  1091     {
       
  1092     if ( !IsAdded() )
       
  1093         {
       
  1094         CActiveScheduler::Add( this );
       
  1095         }
       
  1096 
       
  1097     if ( !IsActive() )
       
  1098         {
       
  1099         SetActive();
       
  1100 
       
  1101         // complete internal request:
       
  1102         User::RequestComplete( aStatus, KErrNone );
       
  1103         }
       
  1104     }
       
  1105 
       
  1106 // -----------------------------------------------------------------------------
       
  1107 // CDrmUiHandlingImpl::PerformCheckRightsAmountFileL
       
  1108 // -----------------------------------------------------------------------------
       
  1109 //
       
  1110 void DRM::CDrmUiHandlingImpl::PerformCheckRightsAmountFileL(
       
  1111     DRM::CDrmUiHandlingData& aData )
       
  1112     {
       
  1113     TPtrC agent( KNullDesC );
       
  1114     IsProtectedL( *aData.iFile, agent );
       
  1115 
       
  1116     ContentAccess::CData* content = ContentAccess::CData::NewLC(
       
  1117         *aData.iFile, ContentAccess::KDefaultContentObject,
       
  1118         ContentAccess::EPeek );
       
  1119 
       
  1120     if ( !agent.Compare( DRM::KDrmOmaAgentName ) )
       
  1121         {
       
  1122         CheckOmaRightsAmountL( *content, aData.iIntent,
       
  1123             aData.iCheckRightsObserver, aData.iOperationId );
       
  1124         }
       
  1125 
       
  1126     else if ( iOmaBasedAgentName && ( !agent.Compare( *iOmaBasedAgentName ) ) )
       
  1127         {
       
  1128         CheckOmaBasedRightsAmountL( *content, aData.iIntent,
       
  1129             aData.iCheckRightsObserver, aData.iOperationId );
       
  1130         }
       
  1131 
       
  1132     else if ( !agent.Compare( DRM::KDrmWMAgentName ) && iWmClient )
       
  1133         {
       
  1134         iWmClient->CheckWmRightsAmountL( *content, aData.iIntent,
       
  1135             aData.iCheckRightsObserver, aData.iOperationId );
       
  1136         }
       
  1137 
       
  1138     CleanupStack::PopAndDestroy( content );
       
  1139     }
       
  1140 
       
  1141 // -----------------------------------------------------------------------------
       
  1142 // CDrmUiHandlingImpl::PerformCheckRightsAmountDataL
       
  1143 // -----------------------------------------------------------------------------
       
  1144 //
       
  1145 void DRM::CDrmUiHandlingImpl::PerformCheckRightsAmountDataL(
       
  1146     DRM::CDrmUiHandlingData& aData )
       
  1147     {
       
  1148     DRM::TDrmAgentUid agentUid( DRM::EDrmOmaAgent );
       
  1149     IsProtectedL( aData.iFileData, agentUid );
       
  1150 
       
  1151     switch ( agentUid )
       
  1152         {
       
  1153         case DRM::EDrmOmaAgent:
       
  1154 
       
  1155             CheckOmaRightsAmountL( *aData.iFileData, aData.iIntent,
       
  1156                 aData.iCheckRightsObserver, aData.iOperationId );
       
  1157 
       
  1158             break;
       
  1159 
       
  1160         case DRM::EDrmWmAgent:
       
  1161 
       
  1162             if ( iWmClient )
       
  1163                 {
       
  1164                 iWmClient->CheckWmRightsAmountL( *aData.iFileData,
       
  1165                     aData.iIntent, aData.iCheckRightsObserver,
       
  1166                     aData.iOperationId );
       
  1167                 }
       
  1168 
       
  1169             break;
       
  1170 
       
  1171         default:
       
  1172 
       
  1173             break;
       
  1174         }
       
  1175     if ( agentUid == iOmaBasedUid )
       
  1176         {
       
  1177         CheckOmaBasedRightsAmountL( *aData.iFileData, aData.iIntent,
       
  1178             aData.iCheckRightsObserver, aData.iOperationId );
       
  1179         }
       
  1180 
       
  1181     }
       
  1182 
       
  1183 // -----------------------------------------------------------------------------
       
  1184 // CDrmUiHandlingImpl::PerformShowDetailsViewFileL
       
  1185 // -----------------------------------------------------------------------------
       
  1186 //
       
  1187 void DRM::CDrmUiHandlingImpl::PerformShowDetailsViewFileL(
       
  1188     DRM::CDrmUiHandlingData& aData )
       
  1189     {
       
  1190     HBufC* fullPath( NULL );
       
  1191     TPtr pathPtr( NULL, 0 );
       
  1192     TPtrC agent( KNullDesC );
       
  1193     IsProtectedL( *aData.iFile, agent );
       
  1194 
       
  1195     ContentAccess::CData* content = ContentAccess::CData::NewLC(
       
  1196         *aData.iFile, ContentAccess::KDefaultContentObject,
       
  1197         ContentAccess::EPeek );
       
  1198 
       
  1199     HBufC8* contentId( NULL );
       
  1200 
       
  1201     fullPath = HBufC::NewLC( KUrlMaxLen );
       
  1202     pathPtr.Set( fullPath->Des() );
       
  1203     User::LeaveIfError( aData.iFile->FullName( pathPtr ) );
       
  1204 
       
  1205     if ( !agent.Compare( DRM::KDrmOmaAgentName ) )
       
  1206         {
       
  1207         GetContentIdLC( *content, contentId );
       
  1208         ShowDetailsViewL( contentId, fullPath );
       
  1209         CleanupStack::PopAndDestroy( contentId );
       
  1210         }
       
  1211 
       
  1212     else if ( !agent.Compare( DRM::KDrmWMAgentName ) && iWmClient )
       
  1213         {
       
  1214         // Show details view for WMDRM file needs full path name
       
  1215         ShowDetailsViewL( fullPath );
       
  1216         }
       
  1217 
       
  1218     CleanupStack::PopAndDestroy( fullPath );
       
  1219     CleanupStack::PopAndDestroy( content ); // content
       
  1220     }
       
  1221 
       
  1222 // -----------------------------------------------------------------------------
       
  1223 // CDrmUiHandlingImpl::PerformShowDetailsViewDataL
       
  1224 // -----------------------------------------------------------------------------
       
  1225 //
       
  1226 void DRM::CDrmUiHandlingImpl::PerformShowDetailsViewDataL(
       
  1227     DRM::CDrmUiHandlingData& aData )
       
  1228     {
       
  1229     DRM::TDrmAgentUid agentUid( DRM::EDrmOmaAgent );
       
  1230     IsProtectedL( aData.iFileData, agentUid );
       
  1231     HBufC* fullPath( NULL );
       
  1232     HBufC8* contentId( NULL );
       
  1233 
       
  1234     // For OMA and WM DRM, the full path is needed, not just the Content Id
       
  1235     GetContentLocationLC( *aData.iFileData, fullPath );
       
  1236 
       
  1237     switch ( agentUid )
       
  1238         {
       
  1239         case DRM::EDrmOmaAgent:
       
  1240             GetContentIdLC( *aData.iFileData, contentId );
       
  1241             ShowDetailsViewL( contentId, fullPath );
       
  1242             CleanupStack::PopAndDestroy( contentId );
       
  1243             break;
       
  1244 
       
  1245         case DRM::EDrmWmAgent:
       
  1246 
       
  1247             if ( iWmClient )
       
  1248                 {
       
  1249                 // For WM DRM, the full path is needed, not just the Content Id
       
  1250                 ShowDetailsViewL( fullPath );
       
  1251                 }
       
  1252 
       
  1253             break;
       
  1254 
       
  1255         default:
       
  1256 
       
  1257             break;
       
  1258         }
       
  1259 
       
  1260     if ( agentUid == iOmaBasedUid )
       
  1261         {
       
  1262         User::Leave( KErrNotSupported );
       
  1263         }
       
  1264 
       
  1265     CleanupStack::PopAndDestroy( fullPath );
       
  1266     }
       
  1267 
       
  1268 // -----------------------------------------------------------------------------
       
  1269 // CDrmUiHandlingImpl::PerformHandleUrlFileL
       
  1270 // -----------------------------------------------------------------------------
       
  1271 //
       
  1272 void DRM::CDrmUiHandlingImpl::PerformHandleUrlFileL(
       
  1273     DRM::CDrmUiHandlingData& aData )
       
  1274     {
       
  1275     TPtrC agent( KNullDesC );
       
  1276     IsProtectedL( *aData.iFile, agent );
       
  1277 
       
  1278     ContentAccess::CData* content = ContentAccess::CData::NewLC(
       
  1279         *aData.iFile, ContentAccess::KDefaultContentObject,
       
  1280         ContentAccess::EPeek );
       
  1281 
       
  1282     if ( !agent.Compare( DRM::KDrmOmaAgentName ) )
       
  1283         {
       
  1284         DoHandleOmaUrlL( *content, aData.iTypeParam );
       
  1285         }
       
  1286 
       
  1287     else if ( !agent.Compare( DRM::KDrmWMAgentName ) && iWmClient )
       
  1288         {
       
  1289         //*** WMDRM does not support URL:s like that thus leaving with not supported
       
  1290         User::Leave( KErrNotSupported );
       
  1291         }
       
  1292 
       
  1293     CleanupStack::PopAndDestroy( content );
       
  1294     }
       
  1295 
       
  1296 // -----------------------------------------------------------------------------
       
  1297 // CDrmUiHandlingImpl::PerformHandleUrlDataL
       
  1298 // -----------------------------------------------------------------------------
       
  1299 //
       
  1300 void DRM::CDrmUiHandlingImpl::PerformHandleUrlDataL(
       
  1301     DRM::CDrmUiHandlingData& aData )
       
  1302     {
       
  1303     DRM::TDrmAgentUid agentUid( DRM::EDrmOmaAgent );
       
  1304     IsProtectedL( aData.iFileData, agentUid );
       
  1305 
       
  1306     // *** WMDRM
       
  1307     switch ( agentUid )
       
  1308         {
       
  1309         case DRM::EDrmOmaAgent:
       
  1310 
       
  1311             DoHandleOmaUrlL( *aData.iFileData, aData.iTypeParam );
       
  1312 
       
  1313             break;
       
  1314 
       
  1315         case DRM::EDrmWmAgent:
       
  1316 
       
  1317             if ( iWmClient )
       
  1318                 {
       
  1319                 User::Leave( KErrNotSupported );
       
  1320                 }
       
  1321 
       
  1322             break;
       
  1323 
       
  1324         default:
       
  1325 
       
  1326             break;
       
  1327 
       
  1328         }
       
  1329 
       
  1330     if ( agentUid == iOmaBasedUid )
       
  1331         {
       
  1332         User::Leave( KErrNotSupported );
       
  1333         }
       
  1334     // *** WMDRM
       
  1335     }
       
  1336 
       
  1337 // -----------------------------------------------------------------------------
       
  1338 // CDrmUiHandlingImpl::PerformAvailableUrlsFileL
       
  1339 // -----------------------------------------------------------------------------
       
  1340 //
       
  1341 void DRM::CDrmUiHandlingImpl::PerformAvailableUrlsFileL(
       
  1342     DRM::CDrmUiHandlingData& aData )
       
  1343     {
       
  1344     TPtrC agent( KNullDesC );
       
  1345     IsProtectedL( *aData.iFile, agent );
       
  1346 
       
  1347     ContentAccess::CData* content = ContentAccess::CData::NewLC(
       
  1348         *aData.iFile, ContentAccess::KDefaultContentObject,
       
  1349         ContentAccess::EPeek );
       
  1350 
       
  1351     if ( !agent.Compare( DRM::KDrmOmaAgentName ) )
       
  1352         {
       
  1353         GetAvailableOmaUrlsL( *content, *aData.iType );
       
  1354         }
       
  1355 
       
  1356     else if ( !agent.Compare( DRM::KDrmWMAgentName ) && iWmClient )
       
  1357         {
       
  1358         //*** WMDRM does not support URL:s like that thus leaving with not supported
       
  1359         User::Leave( KErrNotSupported );
       
  1360         }
       
  1361     CleanupStack::PopAndDestroy( content );
       
  1362     }
       
  1363 
       
  1364 // -----------------------------------------------------------------------------
       
  1365 // CDrmUiHandlingImpl::PerformAvailableUrlsDataL
       
  1366 // -----------------------------------------------------------------------------
       
  1367 //
       
  1368 void DRM::CDrmUiHandlingImpl::PerformAvailableUrlsDataL(
       
  1369     DRM::CDrmUiHandlingData& aData )
       
  1370     {
       
  1371     DRM::TDrmAgentUid agentUid( DRM::EDrmOmaAgent );
       
  1372     IsProtectedL( aData.iFileData, agentUid );
       
  1373 
       
  1374     // *** WMDRM
       
  1375     switch ( agentUid )
       
  1376         {
       
  1377         case DRM::EDrmOmaAgent:
       
  1378 
       
  1379             GetAvailableOmaUrlsL( *aData.iFileData, *aData.iType );
       
  1380 
       
  1381             break;
       
  1382 
       
  1383         case DRM::EDrmWmAgent:
       
  1384 
       
  1385             if ( iWmClient )
       
  1386                 {
       
  1387                 User::Leave( KErrNotSupported );
       
  1388                 }
       
  1389 
       
  1390             break;
       
  1391 
       
  1392         default:
       
  1393 
       
  1394             break;
       
  1395 
       
  1396         }
       
  1397 
       
  1398     if ( agentUid == iOmaBasedUid )
       
  1399         {
       
  1400         User::Leave( KErrNotSupported );
       
  1401         }
       
  1402     // *** WMDRM
       
  1403     }
       
  1404 
       
  1405 // -----------------------------------------------------------------------------
       
  1406 // CDrmUiHandlingImpl::PerformHandleErrorFileL
       
  1407 // -----------------------------------------------------------------------------
       
  1408 //
       
  1409 void DRM::CDrmUiHandlingImpl::PerformHandleErrorFileL(
       
  1410     DRM::CDrmUiHandlingData& aData )
       
  1411     {
       
  1412     TPtrC agent( KNullDesC );
       
  1413     IsProtectedL( *aData.iFile, agent );
       
  1414     IsProperErrorL( aData.iError );
       
  1415 
       
  1416     ContentAccess::CData* content = ContentAccess::CData::NewLC(
       
  1417         *aData.iFile, ContentAccess::KDefaultContentObject,
       
  1418         ContentAccess::EPeek );
       
  1419 
       
  1420     if ( ( !agent.Compare( DRM::KDrmOmaAgentName ) ) || ( iOmaBasedAgentName
       
  1421         && !agent.Compare( *iOmaBasedAgentName ) ) )
       
  1422         {
       
  1423         HandleOmaErrorL( *content, aData.iIntent, aData.iError,
       
  1424             aData.iErrorObserver, aData.iOperationId );
       
  1425         }
       
  1426 
       
  1427     else if ( !agent.Compare( DRM::KDrmWMAgentName ) && iWmClient )
       
  1428         {
       
  1429         // *** WMDRM
       
  1430         iWmClient->HandleWmErrorL( *content, aData.iIntent, aData.iError,
       
  1431             aData.iErrorObserver, aData.iOperationId );
       
  1432         }
       
  1433 
       
  1434     CleanupStack::PopAndDestroy( content );
       
  1435     }
       
  1436 
       
  1437 // -----------------------------------------------------------------------------
       
  1438 // CDrmUiHandlingImpl::PerformHandleErrorDataL
       
  1439 // -----------------------------------------------------------------------------
       
  1440 //
       
  1441 void DRM::CDrmUiHandlingImpl::PerformHandleErrorDataL(
       
  1442     DRM::CDrmUiHandlingData& aData )
       
  1443     {
       
  1444     DRM::TDrmAgentUid agentUid( DRM::EDrmOmaAgent );
       
  1445     IsProtectedL( aData.iFileData, agentUid );
       
  1446     IsProperErrorL( aData.iError );
       
  1447 
       
  1448     // *** WMDRM
       
  1449     switch ( agentUid )
       
  1450         {
       
  1451         case DRM::EDrmOmaAgent:
       
  1452 
       
  1453             HandleOmaErrorL( *aData.iFileData, aData.iIntent, aData.iError,
       
  1454                 aData.iErrorObserver, aData.iOperationId );
       
  1455 
       
  1456             break;
       
  1457 
       
  1458         case DRM::EDrmWmAgent:
       
  1459 
       
  1460             if ( iWmClient )
       
  1461                 {
       
  1462                 iWmClient->HandleWmErrorL( *aData.iFileData, aData.iIntent,
       
  1463                     aData.iError, aData.iErrorObserver, aData.iOperationId );
       
  1464                 }
       
  1465 
       
  1466             break;
       
  1467 
       
  1468         default:
       
  1469 
       
  1470             break;
       
  1471 
       
  1472         }
       
  1473     if ( agentUid == iOmaBasedUid )
       
  1474         {
       
  1475         HandleOmaErrorL( *aData.iFileData, aData.iIntent, aData.iError,
       
  1476             aData.iErrorObserver, aData.iOperationId );
       
  1477         }
       
  1478     // *** WMDRM
       
  1479     }
       
  1480 
       
  1481 // -----------------------------------------------------------------------------
       
  1482 // CDrmUiHandlingImpl::IsProtectedL
       
  1483 // -----------------------------------------------------------------------------
       
  1484 //
       
  1485 void DRM::CDrmUiHandlingImpl::IsProtectedL( RFile& aFile, TPtrC& aAgent )
       
  1486     {
       
  1487     DRM::TDrmProtectionStatus drmProtected( DRM::EUUnknown );
       
  1488     TInt ret( 0 );
       
  1489     ret = iDrmUtility->GetDrmInfoL( aFile, aAgent, drmProtected );
       
  1490     if ( !ret || !drmProtected ) // do nothing if non-DRM file
       
  1491         {
       
  1492         User::Leave( KErrArgument );
       
  1493         }
       
  1494     }
       
  1495 
       
  1496 // -----------------------------------------------------------------------------
       
  1497 // CDrmUiHandlingImpl::IsProtectedL
       
  1498 // -----------------------------------------------------------------------------
       
  1499 //
       
  1500 void DRM::CDrmUiHandlingImpl::IsProtectedL(
       
  1501     ContentAccess::CData* aContent,
       
  1502     DRM::TDrmAgentUid& aAgentUid )
       
  1503     {
       
  1504     TInt drmProtected( 0 );
       
  1505     User::LeaveIfError( aContent->GetAttribute( EIsProtected, drmProtected ) );
       
  1506     if ( !drmProtected ) // do nothing if non-DRM file
       
  1507         {
       
  1508         User::Leave( KErrArgument );
       
  1509         }
       
  1510 
       
  1511     TInt temp( 0 );
       
  1512 
       
  1513     HBufC* nameString = HBufC::NewLC( KNameBuf );
       
  1514 
       
  1515     TPtr namePtr( nameString->Des() );
       
  1516 
       
  1517     User::LeaveIfError( aContent->GetStringAttribute( DRM::EDrmAgentName,
       
  1518         namePtr ) );
       
  1519 
       
  1520     if ( iOmaBasedAgentName && ( !namePtr.CompareF( *iOmaBasedAgentName ) ) )
       
  1521         {
       
  1522         aAgentUid = static_cast<DRM::TDrmAgentUid> ( iOmaBasedUid );
       
  1523         }
       
  1524     else
       
  1525         {
       
  1526         User::LeaveIfError( aContent->GetAttribute( DRM::EDrmAgentUid, temp ) );
       
  1527         aAgentUid = static_cast<DRM::TDrmAgentUid> ( temp );
       
  1528         }
       
  1529     CleanupStack::PopAndDestroy( nameString );
       
  1530     }
       
  1531 
       
  1532 // -----------------------------------------------------------------------------
       
  1533 // CDrmUiHandlingImpl::IsProperErrorL
       
  1534 // -----------------------------------------------------------------------------
       
  1535 //
       
  1536 void DRM::CDrmUiHandlingImpl::IsProperErrorL( TInt aError )
       
  1537     {
       
  1538     if ( aError != ENoPermission && aError != ENoRights && aError
       
  1539         != EPendingRights )
       
  1540         {
       
  1541         User::Leave( aError );
       
  1542         }
       
  1543     }
       
  1544 
       
  1545 // -----------------------------------------------------------------------------
       
  1546 // CDrmUiHandlingImpl::CheckOmaRightsAmountL
       
  1547 // -----------------------------------------------------------------------------
       
  1548 //
       
  1549 void DRM::CDrmUiHandlingImpl::CheckOmaRightsAmountL(
       
  1550     ContentAccess::CData& aContent,
       
  1551     ContentAccess::TIntent aIntent,
       
  1552     DRM::MDrmUiCheckRightsObserver* aObserver,
       
  1553     TInt aOperationId )
       
  1554     {
       
  1555     HBufC8* contentId( NULL );
       
  1556     HBufC8* silentUrl( NULL );
       
  1557     HBufC* riUrl( NULL );
       
  1558     HBufC* domainRiUrl( NULL );
       
  1559     DRM::TDrmUiUrlType urlType( DRM::EUHRightsIssuerUrl );
       
  1560 
       
  1561     User::LeaveIfError( GetContentIdLC( aContent, contentId ) );
       
  1562     GetOmaSilentRightsUrlLC( aContent, silentUrl );
       
  1563     GetOmaRightsIssuerLC( aContent, riUrl );
       
  1564     GetOmaDomainRightsIssuerLC( aContent, domainRiUrl );
       
  1565     SelectOmaRightsUrlL( aContent, domainRiUrl, urlType );
       
  1566 
       
  1567     DoCheckOmaRightsAmountL( aContent, contentId, aIntent, urlType
       
  1568         == DRM::EUHRightsIssuerUrl ? riUrl : domainRiUrl, urlType, silentUrl,
       
  1569         aObserver, aOperationId );
       
  1570 
       
  1571     CleanupStack::PopAndDestroy( domainRiUrl );
       
  1572     CleanupStack::PopAndDestroy( riUrl );
       
  1573     CleanupStack::PopAndDestroy( silentUrl );
       
  1574     CleanupStack::PopAndDestroy( contentId );
       
  1575     }
       
  1576 
       
  1577 // -----------------------------------------------------------------------------
       
  1578 // CDrmUiHandlingImpl::DoCheckOmaRightsAmountL
       
  1579 // -----------------------------------------------------------------------------
       
  1580 //
       
  1581 void DRM::CDrmUiHandlingImpl::DoCheckOmaRightsAmountL(
       
  1582     ContentAccess::CData& aContent,
       
  1583     HBufC8*& aContentUri,
       
  1584     ContentAccess::TIntent aIntent,
       
  1585     const HBufC* aRightsUrl,
       
  1586     DRM::TDrmUiUrlType aUrlType,
       
  1587     const HBufC8* aSilentUrl,
       
  1588     DRM::MDrmUiCheckRightsObserver* aObserver,
       
  1589     TInt aOperationId )
       
  1590     {
       
  1591     TInt omaError( KErrNone );
       
  1592     CDRMPermission* permission( NULL );
       
  1593     CDRMConstraint* constraint( NULL );
       
  1594     CDRMConstraint* toplevel( NULL );
       
  1595     DRM::TDrmRightsInfo status( DRM::EURightsInfoMissing );
       
  1596     DRM::TCheckRightsStatus rightsStatus( DRM::EUHCheckRightsNoRights );
       
  1597     TTime now( Time::NullTTime() ); // current time
       
  1598     TTime endTime( Time::NullTTime() ); // end time of time-based rights
       
  1599     TInt mask( 0 ); // tells if object has count or time based rights
       
  1600     TUint32 reason( 0 );
       
  1601     TBool unlimited( EFalse );
       
  1602     TUint32 countsLeft( 0 ); // number of counts left
       
  1603     TTimeIntervalSeconds secondsLeft( 0 ); // seconds to end of time based rights
       
  1604     TTimeIntervalSeconds accumulatedSecondsLeft( 0 ); // seconds to end of
       
  1605     // accumulated time rights
       
  1606 
       
  1607     // Check rights
       
  1608     omaError = iOmaClient.CheckRights( aIntent, *aContentUri, reason );
       
  1609 
       
  1610     // valid rights
       
  1611     if ( !omaError )
       
  1612         {
       
  1613         permission = iOmaClient.GetActiveRightsL( aIntent, *aContentUri,
       
  1614             reason );
       
  1615         CleanupStack::PushL( permission );
       
  1616 
       
  1617         toplevel = permission->TopLevelConstraint();
       
  1618         constraint = permission->ConstraintForIntent( aIntent );
       
  1619 
       
  1620         // if top level constraint exists, merge it to constraint for intent
       
  1621         if ( toplevel )
       
  1622             {
       
  1623             constraint->Merge( *toplevel );
       
  1624             }
       
  1625 
       
  1626         // find out type of constraint
       
  1627         mask = GetOmaConstraintInfo( constraint, countsLeft, endTime );
       
  1628 
       
  1629         // get the current time
       
  1630         now.HomeTime();
       
  1631 
       
  1632         // calculate days left in case of time
       
  1633         // and accumulated time constraints
       
  1634         if ( mask & KDRMOmaConstraintTime )
       
  1635             {
       
  1636             endTime.SecondsFrom( now, secondsLeft );
       
  1637             }
       
  1638         if ( mask & KDRMOmaConstraintAccumulated )
       
  1639             {
       
  1640             endTime.SecondsFrom( now, accumulatedSecondsLeft );
       
  1641             }
       
  1642         // if no count or time based constraint, then unlimited
       
  1643         if ( !mask )
       
  1644             {
       
  1645             unlimited = ETrue;
       
  1646             }
       
  1647 
       
  1648         CallRightsLeftL( aObserver, aOperationId, unlimited, secondsLeft,
       
  1649             countsLeft, accumulatedSecondsLeft, aContentUri, aRightsUrl,
       
  1650             aSilentUrl, aContent, aIntent );
       
  1651 
       
  1652         CleanupStack::PopAndDestroy( permission );
       
  1653         }
       
  1654 
       
  1655     // Not valid rights
       
  1656     else
       
  1657         {
       
  1658         constraint = CDRMConstraint::NewLC();
       
  1659 
       
  1660         // No rights at all
       
  1661         if ( omaError == KErrCANoRights )
       
  1662             {
       
  1663             rightsStatus = DRM::EUHCheckRightsNoRights;
       
  1664             }
       
  1665         else
       
  1666             {
       
  1667             // rights expired or future for given content URI
       
  1668             status = iDrmUtilityCommon->GetOmaRightsStatusL( aContentUri,
       
  1669                 aIntent, constraint );
       
  1670             if ( status == DRM::EURightsInfoFuture )
       
  1671                 {
       
  1672                 rightsStatus = DRM::EUHCheckRightsFutureRights;
       
  1673                 }
       
  1674             else if ( status == DRM::EURightsInfoExpired )
       
  1675                 {
       
  1676                 rightsStatus = DRM::EUHCheckRightsExpiredRights;
       
  1677                 }
       
  1678             }
       
  1679 
       
  1680         CallRightsNotValidL( aObserver, aOperationId, rightsStatus, reason,
       
  1681             aContent, aContentUri, constraint, aRightsUrl, aUrlType,
       
  1682             aSilentUrl, aIntent );
       
  1683 
       
  1684         CleanupStack::PopAndDestroy( constraint );
       
  1685         }
       
  1686     }
       
  1687 
       
  1688 // -----------------------------------------------------------------------------
       
  1689 // CDrmUiHandlingImpl::HandleOmaErrorL
       
  1690 // -----------------------------------------------------------------------------
       
  1691 //
       
  1692 void DRM::CDrmUiHandlingImpl::HandleOmaErrorL(
       
  1693     ContentAccess::CData& aContent,
       
  1694     ContentAccess::TIntent aIntent,
       
  1695     TInt aError,
       
  1696     DRM::MDrmHandleErrorObserver* aObserver,
       
  1697     TInt aOperationId )
       
  1698     {
       
  1699     TInt omaError( KErrNone );
       
  1700     HBufC8* contentId( NULL );
       
  1701     HBufC* riUrl( NULL );
       
  1702     HBufC* domainRiUrl( NULL );
       
  1703     HBufC* previewUrl( NULL );
       
  1704     HBufC8* silentUrl( NULL );
       
  1705     CDRMConstraint* constraint( NULL );
       
  1706     DRM::TDrmRightsInfo rightsStatus( DRM::EURightsInfoValid );
       
  1707     DRM::TDrmUiUrlType urlType( DRM::EUHRightsIssuerUrl );
       
  1708     TInt previewType( ContentAccess::ENoPreview );
       
  1709     TUint32 reason( 0 );
       
  1710     TBool handled( EFalse );
       
  1711 
       
  1712     User::LeaveIfError( GetContentIdLC( aContent, contentId ) );
       
  1713 
       
  1714     // Check that this really is an error situation
       
  1715     omaError = iOmaClient.CheckRights( aIntent, *contentId, reason );
       
  1716 
       
  1717     // Show that only reason for error was rejected metering.
       
  1718     TBool onlyMeteringRejection( reason == DRM::EURejectionMetering );
       
  1719     if ( onlyMeteringRejection )
       
  1720         {
       
  1721         iDrmUtilityUi->DisplayQueryWithIdL( R_DRM_QUERY_METERING_DISABLED,
       
  1722             R_DRMUTILITY_WAITING_RIGHTS_CONFIRMATION_QUERY );
       
  1723 
       
  1724         CleanupStack::PopAndDestroy( contentId );
       
  1725         return;
       
  1726         }
       
  1727 
       
  1728     if ( omaError )
       
  1729         {
       
  1730 
       
  1731         // Get rights status
       
  1732         constraint = CDRMConstraint::NewLC();
       
  1733         rightsStatus = iDrmUtilityCommon->GetOmaRightsStatusL( contentId,
       
  1734             aIntent, constraint );
       
  1735 
       
  1736         // Try to get all needed urls
       
  1737         GetOmaPreviewInfoLC( aContent, previewUrl, previewType );
       
  1738         GetOmaSilentRightsUrlLC( aContent, silentUrl );
       
  1739         GetOmaRightsIssuerLC( aContent, riUrl );
       
  1740         GetOmaDomainRightsIssuerLC( aContent, domainRiUrl );
       
  1741         SelectOmaRightsUrlL( aContent, domainRiUrl, urlType );
       
  1742 
       
  1743         // If content has EmbeddedPreviewUrl, PreviewRightsUrl or
       
  1744         // SilentRightsUrl, handle it
       
  1745         if ( previewType == ContentAccess::EInstantPreview )
       
  1746             {
       
  1747             handled = ETrue;
       
  1748             CallEmbeddedPreviewAvailableL( aObserver, aOperationId, aContent,
       
  1749                 previewUrl, rightsStatus, reason, urlType
       
  1750                     == DRM::EUHRightsIssuerUrl ? riUrl : domainRiUrl,
       
  1751                 contentId, aIntent );
       
  1752             }
       
  1753 
       
  1754         else if ( previewType == ContentAccess::EPreviewRights )
       
  1755             {
       
  1756             handled = ETrue;
       
  1757             CallPreviewRightsUrlAvailableL( aObserver, aOperationId,
       
  1758                 aContent, previewUrl, rightsStatus, reason, urlType
       
  1759                     == DRM::EUHRightsIssuerUrl ? riUrl : domainRiUrl,
       
  1760                 contentId, aIntent );
       
  1761             }
       
  1762 
       
  1763         else if ( silentUrl )
       
  1764             {
       
  1765             handled = ETrue;
       
  1766             CallSilentRightsUrlAvailableL( aObserver, aOperationId,
       
  1767                 silentUrl, rightsStatus, reason, urlType
       
  1768                     == DRM::EUHRightsIssuerUrl ? riUrl : domainRiUrl,
       
  1769                 contentId, aIntent );
       
  1770             }
       
  1771 
       
  1772         // Check if rights were retrieved in earlier url handling
       
  1773         if ( handled )
       
  1774             {
       
  1775             omaError = iOmaClient.CheckRights( aIntent, *contentId, reason );
       
  1776             }
       
  1777 
       
  1778         if ( omaError )
       
  1779             {
       
  1780             // No rights available
       
  1781             // Perform this even if no rights issuer url found
       
  1782             CallRightsUrlAvailableL( aObserver, aOperationId, rightsStatus,
       
  1783                 reason, constraint, aContent, contentId, urlType
       
  1784                     == DRM::EUHRightsIssuerUrl ? riUrl : domainRiUrl,
       
  1785                 urlType, aIntent, aError );
       
  1786             }
       
  1787 
       
  1788         CleanupStack::PopAndDestroy( domainRiUrl );
       
  1789         CleanupStack::PopAndDestroy( riUrl );
       
  1790         CleanupStack::PopAndDestroy( silentUrl );
       
  1791         CleanupStack::PopAndDestroy( previewUrl );
       
  1792         CleanupStack::PopAndDestroy( constraint );
       
  1793         }
       
  1794     else
       
  1795         {
       
  1796         User::Leave( KErrArgument );
       
  1797         }
       
  1798 
       
  1799     CleanupStack::PopAndDestroy( contentId );
       
  1800     }
       
  1801 
       
  1802 // -----------------------------------------------------------------------------
       
  1803 // CDrmUiHandlingImpl::ShowOmaDetailsViewL
       
  1804 // -----------------------------------------------------------------------------
       
  1805 //
       
  1806 void DRM::CDrmUiHandlingImpl::ShowDetailsViewL(
       
  1807     const HBufC8* aContentId,
       
  1808     const HBufC* aFullPath )
       
  1809     {
       
  1810     __ASSERT_DEBUG( aContentId, User::Panic( KDRMUtilityDebugPanicMessage,
       
  1811             KDRMUtilityDebugPanicCode ) );
       
  1812 
       
  1813     __ASSERT_DEBUG( aFullPath, User::Panic( KDRMUtilityDebugPanicMessage,
       
  1814             KDRMUtilityDebugPanicCode ) );
       
  1815 
       
  1816     // For OMA DRM
       
  1817     HBufC* launchParam( NULL );
       
  1818 
       
  1819     // create parameter string
       
  1820     CreateLaunchParamL( aContentId, launchParam, aFullPath );
       
  1821     CleanupStack::PushL( launchParam );
       
  1822 
       
  1823     // show details
       
  1824     LaunchRightsManagerUiL( *launchParam );
       
  1825 
       
  1826     CleanupStack::PopAndDestroy( launchParam );
       
  1827     }
       
  1828 
       
  1829 // -----------------------------------------------------------------------------
       
  1830 // CDrmUiHandlingImpl::CheckOmaBasedRightsAmountL
       
  1831 // -----------------------------------------------------------------------------
       
  1832 //
       
  1833 void DRM::CDrmUiHandlingImpl::CheckOmaBasedRightsAmountL(
       
  1834     ContentAccess::CData& aContent,
       
  1835     ContentAccess::TIntent aIntent,
       
  1836     DRM::MDrmUiCheckRightsObserver* aObserver,
       
  1837     TInt aOperationId )
       
  1838     {
       
  1839     HBufC8* contentId( NULL );
       
  1840     HBufC* riUrl( NULL );
       
  1841 
       
  1842     DRM::TDrmUiUrlType urlType( DRM::EUHRightsIssuerUrl );
       
  1843 
       
  1844     User::LeaveIfError( GetContentIdLC( aContent, contentId ) );
       
  1845 
       
  1846     DoCheckOmaBasedRightsAmountL( aContent, contentId, aIntent, riUrl,
       
  1847         urlType, aObserver, aOperationId );
       
  1848 
       
  1849     CleanupStack::PopAndDestroy( contentId );
       
  1850 
       
  1851     }
       
  1852 
       
  1853 // -----------------------------------------------------------------------------
       
  1854 // CDrmUiHandlingImpl::DoCheckOmaBasedRightsAmountL
       
  1855 // -----------------------------------------------------------------------------
       
  1856 //
       
  1857 void DRM::CDrmUiHandlingImpl::DoCheckOmaBasedRightsAmountL(
       
  1858     ContentAccess::CData& aContent,
       
  1859     const HBufC8* aContentUri,
       
  1860     ContentAccess::TIntent aIntent,
       
  1861     const HBufC* aRightsUrl,
       
  1862     DRM::TDrmUiUrlType aUrlType,
       
  1863     DRM::MDrmUiCheckRightsObserver* aObserver,
       
  1864     TInt aOperationId )
       
  1865     {
       
  1866     TInt canPlay( KErrNone );
       
  1867     CDRMConstraint* constraint( NULL );
       
  1868     DRM::TCheckRightsStatus rightsStatus( DRM::EUHCheckRightsNoRights );
       
  1869 
       
  1870     TTime now( Time::NullTTime() ); // current time
       
  1871     TTime endTime( Time::NullTTime() ); // end time of time-based rights
       
  1872 
       
  1873     TUint32 reason( EConstraintEndTime );
       
  1874     TBool unlimited( EFalse );
       
  1875     TUint32 countsLeft( 0 ); // number of counts left
       
  1876     TTimeIntervalSeconds secondsLeft( 0 ); // seconds to end of time based rights
       
  1877     TTimeIntervalSeconds accumulatedSecondsLeft( 0 ); // seconds to end of
       
  1878     // accumulated time rights
       
  1879 
       
  1880     // Check rights
       
  1881 
       
  1882     User::LeaveIfError( aContent.GetAttribute( ECanPlay, canPlay ) );
       
  1883 
       
  1884     GetOmaBasedEndTimeL( aContent, endTime );
       
  1885 
       
  1886     // valid rights
       
  1887     if ( canPlay ) // check the CAF parameters
       
  1888         {
       
  1889         // get the current time
       
  1890         now.HomeTimeSecure();
       
  1891 
       
  1892         endTime.SecondsFrom( now, secondsLeft );
       
  1893 
       
  1894         CallRightsLeftL( aObserver, aOperationId, unlimited, secondsLeft,
       
  1895             countsLeft, accumulatedSecondsLeft, aContentUri, aRightsUrl,
       
  1896             NULL, aContent, aIntent );
       
  1897         }
       
  1898 
       
  1899     // Not valid rights
       
  1900     else
       
  1901         {
       
  1902         constraint = CDRMConstraint::NewLC();
       
  1903         rightsStatus = DRM::EUHCheckRightsExpiredRights;
       
  1904         constraint->iActiveConstraints |= EConstraintEndTime;
       
  1905         constraint->iEndTime = endTime;
       
  1906 
       
  1907         CallRightsNotValidL( aObserver, aOperationId, rightsStatus, reason,
       
  1908             aContent, aContentUri, constraint, aRightsUrl, aUrlType, NULL,
       
  1909             aIntent );
       
  1910 
       
  1911         CleanupStack::PopAndDestroy( constraint );
       
  1912         }
       
  1913     }
       
  1914 
       
  1915 // -----------------------------------------------------------------------------
       
  1916 // CDrmUiHandlingImpl::GetOmaBasedEndTimeL
       
  1917 // -----------------------------------------------------------------------------
       
  1918 //
       
  1919 void DRM::CDrmUiHandlingImpl::GetOmaBasedEndTimeL(
       
  1920     ContentAccess::CData& aData,
       
  1921     TTime& aEndTime )
       
  1922     {
       
  1923     TInt err = KErrNone;
       
  1924     RFs fileSession;
       
  1925     RFile file;
       
  1926     TBuf8<KIntegerMaxLen> lenTxt;
       
  1927     TInt readStart = 0;
       
  1928     TInt headerLen = 0;
       
  1929     TInt tempVal = 0;
       
  1930 
       
  1931     __UHEAP_MARK;
       
  1932 
       
  1933     User::LeaveIfError( fileSession.Connect() );
       
  1934 
       
  1935     CleanupClosePushL( fileSession );
       
  1936     CleanupClosePushL( file );
       
  1937 
       
  1938     HBufC* filename = HBufC::NewLC( KNameBuf );
       
  1939 
       
  1940     TPtr resOmaBased( const_cast<TUint16*> ( filename->Ptr() ), 0,
       
  1941         KresOmaBasedBuf );
       
  1942     err = aData.GetStringAttribute( DRM::EDrmFullName, resOmaBased );
       
  1943 
       
  1944     if ( file.Open( fileSession, resOmaBased, EFileShareReadersOrWriters
       
  1945         | EFileRead ) == KErrNone )
       
  1946         {
       
  1947         /* Read content type and uri lengths */
       
  1948         err = file.Read( 1, lenTxt, 2 );
       
  1949         if ( err == KErrNone && lenTxt.Length() == 2 )
       
  1950             {
       
  1951             readStart = lenTxt[0] + lenTxt[1];
       
  1952             }
       
  1953         if ( readStart > 0 )
       
  1954             {
       
  1955             /* Add the length of version and length informations */
       
  1956             const TInt KReadSkip( 3 );
       
  1957             readStart += KReadSkip;
       
  1958             /* Read header length information (exact length not known
       
  1959              since it is Uintvar, so read plentily) */
       
  1960             err = file.Read( readStart, lenTxt, lenTxt.MaxLength() );
       
  1961             if ( err == KErrNone && lenTxt.Length() > 0 )
       
  1962                 {
       
  1963                 TBool cont = ETrue;
       
  1964                 /* Start reading the header length */
       
  1965                 TInt i = 0;
       
  1966                 while ( i < lenTxt.Length() && cont )
       
  1967                     {
       
  1968                     tempVal = lenTxt[i];
       
  1969                     i++;
       
  1970                     if ( !( tempVal & 0x80 ) )
       
  1971                         { /* Highest bit not set, it's the last value */
       
  1972                         cont = EFalse;
       
  1973                         }
       
  1974                     else
       
  1975                         { /* Clear the highest bit */
       
  1976                         tempVal &= ~( 0x80 );
       
  1977                         }
       
  1978                     headerLen = ( ( headerLen << 0x07 ) | tempVal );
       
  1979                     }
       
  1980                 if ( cont != EFalse )
       
  1981                     { /* Reading the length failed */
       
  1982                     headerLen = 0;
       
  1983                     }
       
  1984                 else
       
  1985                     {
       
  1986                     /* Continue to read past the content length */
       
  1987                     cont = ETrue;
       
  1988                     while ( i < lenTxt.Length() && cont )
       
  1989                         {
       
  1990                         tempVal = lenTxt[i];
       
  1991                         i++;
       
  1992                         if ( !( tempVal & 0x80 ) )
       
  1993                             { /* Highest bit not set, it's the last value */
       
  1994                             cont = EFalse;
       
  1995                             }
       
  1996                         }
       
  1997                     if ( cont != EFalse )
       
  1998                         { /* Reading the length failed */
       
  1999                         headerLen = 0;
       
  2000                         }
       
  2001                     else
       
  2002                         {
       
  2003                         /* Increase read start index past length
       
  2004                          informations */
       
  2005                         readStart += i;
       
  2006                         }
       
  2007                     }
       
  2008                 }
       
  2009             }
       
  2010         if ( headerLen > 0 )
       
  2011             {
       
  2012             HBufC8 *header = HBufC8::NewLC( headerLen );
       
  2013             /* Read header */
       
  2014             TPtr8 headerPtr( header->Des() );
       
  2015             err = file.Read( readStart, headerPtr, headerLen );
       
  2016             if ( err == KErrNone && headerPtr.Length() == headerLen )
       
  2017                 {
       
  2018                 // seperate function call from here
       
  2019                 OmaBasedHeaderParserL( tempVal, headerPtr, aEndTime );
       
  2020                 }
       
  2021             /* Pop and destroy header */
       
  2022             CleanupStack::PopAndDestroy( header );
       
  2023             }
       
  2024         }
       
  2025     CleanupStack::PopAndDestroy( filename );
       
  2026     CleanupStack::PopAndDestroy( &file );
       
  2027     CleanupStack::PopAndDestroy( &fileSession );
       
  2028     __UHEAP_MARKEND;
       
  2029     }
       
  2030 
       
  2031 // -----------------------------------------------------------------------------
       
  2032 // CDrmUiHandlingImpl::OmaBasedHeaderParserL
       
  2033 // -----------------------------------------------------------------------------
       
  2034 //
       
  2035 TInt DRM::CDrmUiHandlingImpl::OmaBasedHeaderParserL(
       
  2036     TInt aOffset,
       
  2037     TPtr8 aHeaderPtr,
       
  2038     TTime& aEndTime )
       
  2039     {
       
  2040     TInt err = KErrNone;
       
  2041     TTime *time = NULL;
       
  2042     _LIT8( KEndTimeStr, "Time-Not-After/" );
       
  2043     _LIT( KZero, "0" );
       
  2044 
       
  2045     /* Get the time */
       
  2046     TInt pos = aHeaderPtr.FindF( KEndTimeStr );
       
  2047     if ( pos != KErrNotFound )
       
  2048         {
       
  2049         TPtrC8 endTimeStr( aHeaderPtr.Mid( pos + KEndTimeStr().Length() ) );
       
  2050         pos = endTimeStr.Locate( ',' );
       
  2051         if ( pos != KErrNotFound )
       
  2052             {
       
  2053             endTimeStr.Set( endTimeStr.Left( pos ) );
       
  2054             /* Check if it contains timezone information */
       
  2055             pos = endTimeStr.Locate( 'Z' );
       
  2056             if ( pos != KErrNotFound )
       
  2057                 { /* Cut the time zone information "Zxxx" */
       
  2058                 endTimeStr.Set( endTimeStr.Left( pos ) );
       
  2059                 }
       
  2060             pos = endTimeStr.Locate( '+' );
       
  2061             if ( pos != KErrNotFound )
       
  2062                 { /* Cut the time zone information "+xx" */
       
  2063                 endTimeStr.Set( endTimeStr.Left( pos ) );
       
  2064                 }
       
  2065             pos = endTimeStr.Locate( '-' );
       
  2066             if ( pos != KErrNotFound )
       
  2067                 { /* Cut the time zone information "-xx" */
       
  2068                 endTimeStr.Set( endTimeStr.Left( pos ) );
       
  2069                 }
       
  2070             /* Allocate new buffer with length enough
       
  2071              for adding needed ':' character between date and time */
       
  2072             const TInt KPlaceOfColon( 8 );
       
  2073             HBufC16* dateTimeBuf = HBufC16::NewLC( endTimeStr.Length() + 1 );
       
  2074             /* Copy provides sufficient 8bit -> 16bit conversion here */
       
  2075             dateTimeBuf->Des().Copy( endTimeStr );
       
  2076             dateTimeBuf->Des().Insert( KPlaceOfColon, _L16 ( ":" ) );
       
  2077 
       
  2078             /* Decrease 1 from month and day, cause
       
  2079              TTime::FormatL expects them to start from 0 */
       
  2080             TPtrC16 tempPtr( dateTimeBuf->Des().Mid( 4, 2 ) );
       
  2081             TLex16 lex( dateTimeBuf->Des().Mid( 4, 2 ) );
       
  2082             TBuf<2> replace;
       
  2083             err = lex.Val( aOffset );
       
  2084             if ( err == KErrNone )
       
  2085                 {
       
  2086                 replace.Num( ( aOffset - 1 ) );
       
  2087                 if ( replace.Length() == 1 )
       
  2088                     { /* Insert the '0' needed by TTime */
       
  2089                     replace.Insert( 0, KZero );
       
  2090                     }
       
  2091                 dateTimeBuf->Des().Replace( 4, 2, replace );
       
  2092 
       
  2093                 lex.Assign( dateTimeBuf->Des().Mid( 6, 2 ) );
       
  2094                 TBuf<2> replace;
       
  2095                 err = lex.Val( aOffset );
       
  2096                 if ( err == KErrNone )
       
  2097                     {
       
  2098                     replace.Num( ( aOffset - 1 ) );
       
  2099                     if ( replace.Length() == 1 )
       
  2100                         { /* Insert the '0' needed by TTime */
       
  2101                         replace.Insert( 0, KZero );
       
  2102                         }
       
  2103                     dateTimeBuf->Des().Replace( 6, 2, replace );
       
  2104 
       
  2105                     time = new ( ELeave ) TTime( dateTimeBuf->Des() );
       
  2106 
       
  2107                     CleanupStack::PushL( time );
       
  2108                     aEndTime = *time;
       
  2109 
       
  2110                     /* Pop and destroy time */
       
  2111                     CleanupStack::PopAndDestroy( time );
       
  2112                     }
       
  2113                 }
       
  2114             /* Pop and destroy dateTimeBuf */
       
  2115             CleanupStack::PopAndDestroy( dateTimeBuf );
       
  2116             }
       
  2117         }
       
  2118     else
       
  2119         {
       
  2120         return KErrNotFound;
       
  2121         }
       
  2122     return KErrNone;
       
  2123     }
       
  2124 
       
  2125 // -----------------------------------------------------------------------------
       
  2126 // CDrmUiHandlingImpl::ShowDetailsViewL
       
  2127 // -----------------------------------------------------------------------------
       
  2128 //
       
  2129 void DRM::CDrmUiHandlingImpl::ShowDetailsViewL( const HBufC* aFullPath )
       
  2130     {
       
  2131 
       
  2132     __ASSERT_DEBUG( aFullPath, User::Panic( KDRMUtilityDebugPanicMessage,
       
  2133             KDRMUtilityDebugPanicCode ) );
       
  2134     // For WM DRM
       
  2135     HBufC* launchParam( NULL );
       
  2136 
       
  2137     // create parameter string
       
  2138     CreateLaunchParamL( aFullPath, launchParam );
       
  2139     CleanupStack::PushL( launchParam );
       
  2140 
       
  2141     // show details
       
  2142     LaunchRightsManagerUiL( *launchParam );
       
  2143 
       
  2144     CleanupStack::PopAndDestroy( launchParam );
       
  2145     }
       
  2146 
       
  2147 // -----------------------------------------------------------------------------
       
  2148 // CDrmUiHandlingImpl::DoHandleOmaUrlL
       
  2149 // -----------------------------------------------------------------------------
       
  2150 //
       
  2151 void DRM::CDrmUiHandlingImpl::DoHandleOmaUrlL(
       
  2152     ContentAccess::CData& aContent,
       
  2153     DRM::TDrmUiUrlType aType )
       
  2154     {
       
  2155     HBufC* url( NULL );
       
  2156     HBufC8* url8( NULL );
       
  2157     TInt previewType( 0 );
       
  2158 
       
  2159     switch ( aType )
       
  2160         {
       
  2161         // handle RightsIssuerUrl
       
  2162         case DRM::EUHRightsIssuerUrl:
       
  2163 
       
  2164             GetOmaRightsIssuerLC( aContent, url );
       
  2165             if ( !url )
       
  2166                 {
       
  2167                 User::Leave( KErrNotFound );
       
  2168                 }
       
  2169 
       
  2170             LaunchBrowserL( url );
       
  2171 
       
  2172             CleanupStack::PopAndDestroy( url );
       
  2173 
       
  2174             break;
       
  2175 
       
  2176             // handle PreviewUrl
       
  2177         case DRM::EUHPreviewRightsUrl:
       
  2178 
       
  2179             GetOmaPreviewInfoLC( aContent, url, previewType );
       
  2180             if ( !url )
       
  2181                 {
       
  2182                 User::Leave( KErrNotFound );
       
  2183                 }
       
  2184 
       
  2185 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  2186 
       
  2187             if ( previewType == ContentAccess::EPreviewRights )
       
  2188                 {
       
  2189                 url8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *url );
       
  2190                 CleanupStack::PushL( url8 );
       
  2191 
       
  2192                 GetSilentRightsL( *url8, ETrue );
       
  2193 
       
  2194                 CleanupStack::PopAndDestroy( url8 );
       
  2195                 }
       
  2196 
       
  2197 #endif // RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  2198             CleanupStack::PopAndDestroy( url );
       
  2199 
       
  2200             break;
       
  2201 
       
  2202             // handle SilentRightsUrl
       
  2203         case DRM::EUHSilentRightsUrl:
       
  2204 
       
  2205             GetOmaSilentRightsUrlLC( aContent, url8 );
       
  2206             if ( !url8 )
       
  2207                 {
       
  2208                 User::Leave( KErrNotFound );
       
  2209                 }
       
  2210 
       
  2211             GetSilentRightsL( *url8, ETrue );
       
  2212 
       
  2213             CleanupStack::PopAndDestroy( url8 );
       
  2214 
       
  2215             break;
       
  2216 
       
  2217             // handle InfoUrl
       
  2218         case DRM::EUHInfoUrl:
       
  2219 
       
  2220             GetOmaInfoUrlLC( aContent, url );
       
  2221             if ( !url )
       
  2222                 {
       
  2223                 User::Leave( KErrNotFound );
       
  2224                 }
       
  2225 
       
  2226             LaunchBrowserL( url );
       
  2227 
       
  2228             CleanupStack::PopAndDestroy( url );
       
  2229 
       
  2230             break;
       
  2231 
       
  2232             // handle DomainRightsIssuerUrl
       
  2233         case DRM::EUHDomainRiUrl:
       
  2234 
       
  2235             GetOmaDomainRightsIssuerLC( aContent, url );
       
  2236             if ( !url )
       
  2237                 {
       
  2238                 User::Leave( KErrNotFound );
       
  2239                 }
       
  2240 
       
  2241             LaunchBrowserL( url );
       
  2242 
       
  2243             CleanupStack::PopAndDestroy( url );
       
  2244 
       
  2245             break;
       
  2246 
       
  2247         default:
       
  2248 
       
  2249             User::Leave( KErrNotSupported );
       
  2250 
       
  2251             break;
       
  2252 
       
  2253         }
       
  2254     }
       
  2255 
       
  2256 // -----------------------------------------------------------------------------
       
  2257 // CDrmUiHandlingImpl::GetAvailableOmaUrlsL
       
  2258 // -----------------------------------------------------------------------------
       
  2259 //
       
  2260 void DRM::CDrmUiHandlingImpl::GetAvailableOmaUrlsL(
       
  2261     ContentAccess::CData& aContent,
       
  2262     DRM::TDrmUiUrlType& aType )
       
  2263     {
       
  2264     HBufC* riUrl( NULL );
       
  2265     HBufC* previewUrl( NULL );
       
  2266     HBufC8* silentUrl( NULL );
       
  2267     HBufC* infoUrl( NULL );
       
  2268     HBufC* domainRiUrl( NULL );
       
  2269 
       
  2270     TInt dummy( 0 );
       
  2271     TInt temp( 0 );
       
  2272 
       
  2273     // Try to get all Urls
       
  2274     GetOmaRightsIssuerLC( aContent, riUrl );
       
  2275     if ( riUrl )
       
  2276         {
       
  2277         temp |= DRM::EUHRightsIssuerUrl;
       
  2278         }
       
  2279     CleanupStack::PopAndDestroy( riUrl );
       
  2280     riUrl = NULL;
       
  2281 
       
  2282     GetOmaPreviewInfoLC( aContent, previewUrl, dummy );
       
  2283     if ( previewUrl )
       
  2284         {
       
  2285         temp |= DRM::EUHPreviewRightsUrl;
       
  2286         }
       
  2287     CleanupStack::PopAndDestroy( previewUrl );
       
  2288     previewUrl = NULL;
       
  2289 
       
  2290     GetOmaSilentRightsUrlLC( aContent, silentUrl );
       
  2291     if ( silentUrl )
       
  2292         {
       
  2293         temp |= DRM::EUHSilentRightsUrl;
       
  2294         }
       
  2295     CleanupStack::PopAndDestroy( silentUrl );
       
  2296     silentUrl = NULL;
       
  2297 
       
  2298     GetOmaInfoUrlLC( aContent, infoUrl );
       
  2299     if ( infoUrl )
       
  2300         {
       
  2301         temp |= DRM::EUHInfoUrl;
       
  2302         }
       
  2303     CleanupStack::PopAndDestroy( infoUrl );
       
  2304     infoUrl = NULL;
       
  2305 
       
  2306     GetOmaDomainRightsIssuerLC( aContent, domainRiUrl );
       
  2307     if ( domainRiUrl )
       
  2308         {
       
  2309         temp |= DRM::EUHDomainRiUrl;
       
  2310         }
       
  2311     CleanupStack::PopAndDestroy( domainRiUrl );
       
  2312     domainRiUrl = NULL;
       
  2313 
       
  2314     // Return a bit mask of available urls
       
  2315     aType = static_cast<TDrmUiUrlType> ( temp );
       
  2316     }
       
  2317 
       
  2318 // -----------------------------------------------------------------------------
       
  2319 // CDrmUiHandlingImpl::GetContentIdLC
       
  2320 // -----------------------------------------------------------------------------
       
  2321 //
       
  2322 TInt DRM::CDrmUiHandlingImpl::GetContentIdLC(
       
  2323     const ContentAccess::CData& aContent,
       
  2324     HBufC8*& aId )
       
  2325     {
       
  2326     __ASSERT_DEBUG( !aId, User::Panic( KDRMUtilityDebugPanicMessage,
       
  2327             KDRMUtilityDebugPanicCode ) );
       
  2328 
       
  2329     TInt error( KErrNone );
       
  2330     TInt currentLength( KUrlMaxLen );
       
  2331     HBufC* contentId( NULL );
       
  2332     TPtr idPtr( NULL, 0 );
       
  2333 
       
  2334     contentId = HBufC::NewLC( currentLength );
       
  2335     idPtr.Set( contentId->Des() );
       
  2336 
       
  2337     error = aContent.GetStringAttribute( ContentAccess::EContentID, idPtr );
       
  2338 
       
  2339     while ( error == KErrOverflow )
       
  2340         {
       
  2341         currentLength += currentLength;
       
  2342         CleanupStack::PopAndDestroy( contentId );
       
  2343         contentId = HBufC::NewLC( currentLength );
       
  2344         idPtr.Set( contentId->Des() );
       
  2345         error
       
  2346             = aContent.GetStringAttribute( ContentAccess::EContentID, idPtr );
       
  2347         }
       
  2348 
       
  2349     if ( !error && idPtr.Length() )
       
  2350         {
       
  2351         aId = CnvUtfConverter::ConvertFromUnicodeToUtf8L( idPtr );
       
  2352         }
       
  2353 
       
  2354     CleanupStack::PopAndDestroy( contentId );
       
  2355     CleanupStack::PushL( aId );
       
  2356     return error;
       
  2357     }
       
  2358 
       
  2359 // -----------------------------------------------------------------------------
       
  2360 // CDrmUiHandlingImpl::GetOmaRightsIssuerLC
       
  2361 // -----------------------------------------------------------------------------
       
  2362 //
       
  2363 TInt DRM::CDrmUiHandlingImpl::GetOmaRightsIssuerLC(
       
  2364     const ContentAccess::CData& aContent,
       
  2365     HBufC*& aIssuer )
       
  2366     {
       
  2367     __ASSERT_DEBUG( !aIssuer, User::Panic( KDRMUtilityDebugPanicMessage,
       
  2368             KDRMUtilityDebugPanicCode ) );
       
  2369 
       
  2370     TInt error( KErrNone );
       
  2371     TInt currentLength( KUrlMaxLen );
       
  2372     HBufC* decodedIssuer( NULL );
       
  2373     HBufC* rightsIssuer( NULL );
       
  2374     TPtr riPtr( NULL, 0 );
       
  2375 
       
  2376     rightsIssuer = HBufC::NewLC( currentLength );
       
  2377     riPtr.Set( rightsIssuer->Des() );
       
  2378 
       
  2379     // Get value of riUrl
       
  2380     error = aContent.GetStringAttribute( ContentAccess::ERightsIssuerUrl,
       
  2381         riPtr );
       
  2382 
       
  2383     while ( error == KErrOverflow )
       
  2384         {
       
  2385         currentLength += currentLength;
       
  2386         CleanupStack::PopAndDestroy( rightsIssuer );
       
  2387         rightsIssuer = HBufC::NewLC( currentLength );
       
  2388         riPtr.Set( rightsIssuer->Des() );
       
  2389         error = aContent.GetStringAttribute( ContentAccess::ERightsIssuerUrl,
       
  2390             riPtr );
       
  2391         }
       
  2392 
       
  2393     if ( !error && riPtr.Length() )
       
  2394         {
       
  2395         riPtr.TrimLeft();
       
  2396         // check if rights issuer is encrypted
       
  2397         if ( riPtr.MatchF( KEncryptedRightsIssuerMatchString )
       
  2398             != KErrNotFound )
       
  2399             {
       
  2400             HBufC8* input( NULL );
       
  2401             HBufC8* output( NULL );
       
  2402 
       
  2403             input = CnvUtfConverter::ConvertFromUnicodeToUtf8L( riPtr );
       
  2404 
       
  2405             CleanupStack::PushL( input );
       
  2406             // encrypted, decrypt
       
  2407             User::LeaveIfError( iOmaClient.DecodeRightsIssuerField( *input,
       
  2408                 output ) );
       
  2409             CleanupStack::PopAndDestroy( input );
       
  2410 
       
  2411             CleanupStack::PushL( output );
       
  2412             decodedIssuer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(
       
  2413                 *output );
       
  2414             CleanupStack::PopAndDestroy( output );
       
  2415 
       
  2416             CleanupStack::PushL( decodedIssuer );
       
  2417             riPtr.Set( decodedIssuer->Des() );
       
  2418             aIssuer = riPtr.AllocL();
       
  2419             CleanupStack::PopAndDestroy( decodedIssuer );
       
  2420             }
       
  2421         else
       
  2422             {
       
  2423             aIssuer = riPtr.AllocL();
       
  2424             }
       
  2425         }
       
  2426 
       
  2427     CleanupStack::PopAndDestroy( rightsIssuer );
       
  2428     CleanupStack::PushL( aIssuer );
       
  2429     return error;
       
  2430     }
       
  2431 
       
  2432 // -----------------------------------------------------------------------------
       
  2433 // CDrmUiHandlingImpl::GetOmaDomainRightsIssuerLC
       
  2434 // -----------------------------------------------------------------------------
       
  2435 //
       
  2436 TInt DRM::CDrmUiHandlingImpl::GetOmaDomainRightsIssuerLC(
       
  2437     const ContentAccess::CData& aContent,
       
  2438     HBufC*& aIssuer )
       
  2439     {
       
  2440     __ASSERT_DEBUG( !aIssuer, User::Panic( KDRMUtilityDebugPanicMessage,
       
  2441             KDRMUtilityDebugPanicCode ) );
       
  2442 
       
  2443     TInt error( KErrNone );
       
  2444     TInt currentLength( KUrlMaxLen );
       
  2445     HBufC* rightsIssuer( NULL );
       
  2446     TPtr riPtr( NULL, 0 );
       
  2447 
       
  2448     rightsIssuer = HBufC::NewLC( currentLength );
       
  2449     riPtr.Set( rightsIssuer->Des() );
       
  2450 
       
  2451     // Get value of domainRIUrl
       
  2452     error = aContent.GetStringAttribute(
       
  2453         ContentAccess::EDomainRightsIssuerUrl, riPtr );
       
  2454 
       
  2455     while ( error == KErrOverflow )
       
  2456         {
       
  2457         currentLength += currentLength;
       
  2458         CleanupStack::PopAndDestroy( rightsIssuer );
       
  2459         rightsIssuer = HBufC::NewLC( currentLength );
       
  2460         riPtr.Set( rightsIssuer->Des() );
       
  2461         error = aContent.GetStringAttribute(
       
  2462             ContentAccess::EDomainRightsIssuerUrl, riPtr );
       
  2463         }
       
  2464 
       
  2465     if ( !error && riPtr.Length() )
       
  2466         {
       
  2467         aIssuer = riPtr.AllocL();
       
  2468         }
       
  2469 
       
  2470     CleanupStack::PopAndDestroy( rightsIssuer );
       
  2471     CleanupStack::PushL( aIssuer );
       
  2472     return error;
       
  2473     }
       
  2474 
       
  2475 // -----------------------------------------------------------------------------
       
  2476 // CDrmUiHandlingImpl::GetOmaPreviewInfoLC
       
  2477 // -----------------------------------------------------------------------------
       
  2478 TInt DRM::CDrmUiHandlingImpl::GetOmaPreviewInfoLC(
       
  2479     const ContentAccess::CData& aContent,
       
  2480     HBufC*& aPreviewUrl,
       
  2481     TInt& aPreviewType )
       
  2482     {
       
  2483     __ASSERT_DEBUG( !aPreviewUrl, User::Panic( KDRMUtilityDebugPanicMessage,
       
  2484             KDRMUtilityDebugPanicCode ) );
       
  2485 
       
  2486     TInt error( KErrNone );
       
  2487     TInt currentLength( KUrlMaxLen );
       
  2488     HBufC* preview( NULL );
       
  2489     TPtr previewPtr( NULL, 0 );
       
  2490 
       
  2491     aPreviewType = ContentAccess::ENoPreview;
       
  2492 
       
  2493     preview = HBufC::NewLC( currentLength );
       
  2494     previewPtr.Set( preview->Des() );
       
  2495 
       
  2496     error = aContent.GetAttribute( ContentAccess::EPreviewType, aPreviewType );
       
  2497 
       
  2498     switch ( aPreviewType )
       
  2499         {
       
  2500 
       
  2501         case ContentAccess::EInstantPreview:
       
  2502             // get URI of embedded preview
       
  2503             error = aContent.GetStringAttribute(
       
  2504                 ContentAccess::EInstantPreviewUri, previewPtr );
       
  2505 
       
  2506             while ( error == KErrOverflow )
       
  2507                 {
       
  2508                 currentLength += currentLength;
       
  2509                 CleanupStack::PopAndDestroy( preview );
       
  2510                 preview = HBufC::NewLC( currentLength );
       
  2511                 previewPtr.Set( preview->Des() );
       
  2512                 error = aContent.GetStringAttribute(
       
  2513                     ContentAccess::EInstantPreviewUri, previewPtr );
       
  2514                 }
       
  2515 
       
  2516             if ( !error && previewPtr.Length() )
       
  2517                 {
       
  2518                 aPreviewUrl = previewPtr.AllocL();
       
  2519                 }
       
  2520             else
       
  2521                 {
       
  2522                 aPreviewType = ContentAccess::ENoPreview;
       
  2523                 }
       
  2524             break;
       
  2525 
       
  2526         case ContentAccess::EPreviewRights:
       
  2527             // get URI of preview rights
       
  2528             error = aContent.GetStringAttribute(
       
  2529                 ContentAccess::EPreviewRightsUri, previewPtr );
       
  2530 
       
  2531             while ( error == KErrOverflow )
       
  2532                 {
       
  2533                 currentLength += currentLength;
       
  2534                 CleanupStack::PopAndDestroy( preview );
       
  2535                 preview = HBufC::NewLC( currentLength );
       
  2536                 previewPtr.Set( preview->Des() );
       
  2537                 error = aContent.GetStringAttribute(
       
  2538                     ContentAccess::EPreviewRightsUri, previewPtr );
       
  2539                 }
       
  2540 
       
  2541             if ( !error && previewPtr.Length() )
       
  2542                 {
       
  2543                 aPreviewUrl = previewPtr.AllocL();
       
  2544                 }
       
  2545             else
       
  2546                 {
       
  2547                 aPreviewType = ContentAccess::ENoPreview;
       
  2548                 }
       
  2549             break;
       
  2550 
       
  2551         default:
       
  2552             // no preview
       
  2553             break;
       
  2554         }
       
  2555 
       
  2556     CleanupStack::PopAndDestroy( preview );
       
  2557     CleanupStack::PushL( aPreviewUrl );
       
  2558     return error;
       
  2559     }
       
  2560 
       
  2561 // -----------------------------------------------------------------------------
       
  2562 // CDrmUiHandlingImpl::GetOmaSilentRightsUrlLC
       
  2563 // -----------------------------------------------------------------------------
       
  2564 TInt DRM::CDrmUiHandlingImpl::GetOmaSilentRightsUrlLC(
       
  2565     const ContentAccess::CData& aContent,
       
  2566     HBufC8*& aSilentUrl )
       
  2567     {
       
  2568     __ASSERT_DEBUG( !aSilentUrl, User::Panic( KDRMUtilityDebugPanicMessage,
       
  2569             KDRMUtilityDebugPanicCode ) );
       
  2570 
       
  2571     TInt error( KErrNone );
       
  2572     TInt currentLength( KUrlMaxLen );
       
  2573     Roap::RRoapStorageClient storage;
       
  2574     HBufC8* silent8( NULL );
       
  2575     HBufC* silent( NULL );
       
  2576     TPtr silentPtr( NULL, 0 );
       
  2577 
       
  2578     silent = HBufC::NewLC( currentLength );
       
  2579     silentPtr.Set( silent->Des() );
       
  2580 
       
  2581     // get SilentRightsUrl
       
  2582     error = aContent.GetStringAttribute( ContentAccess::ESilentRightsUrl,
       
  2583         silentPtr );
       
  2584 
       
  2585     while ( error == KErrOverflow )
       
  2586         {
       
  2587         currentLength += currentLength;
       
  2588         CleanupStack::PopAndDestroy( silent );
       
  2589         silent = HBufC::NewLC( currentLength );
       
  2590         silentPtr.Set( silent->Des() );
       
  2591         error = aContent.GetStringAttribute( ContentAccess::ESilentRightsUrl,
       
  2592             silentPtr );
       
  2593         }
       
  2594 
       
  2595     if ( !error && silentPtr.Length() )
       
  2596         {
       
  2597         silentPtr.TrimLeft();
       
  2598         silent8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( silentPtr );
       
  2599         TPtr8 silentPtr8( silent8->Des() );
       
  2600         CleanupStack::PushL( silent8 );
       
  2601 
       
  2602         User::LeaveIfError( storage.Connect() );
       
  2603         CleanupClosePushL( storage );
       
  2604 
       
  2605         // check that SilentRightsUrl is on the white list
       
  2606         // URL is not searched from pre-configured white list
       
  2607         TBool fromPreConfiguredWhiteList( EFalse );
       
  2608         if ( storage.WhiteListURLExistsL( *silent8,
       
  2609             fromPreConfiguredWhiteList ) )
       
  2610             {
       
  2611             aSilentUrl = silentPtr8.AllocL();
       
  2612             }
       
  2613 
       
  2614         CleanupStack::PopAndDestroy( 2, silent8 ); //storage, silent8
       
  2615         }
       
  2616 
       
  2617     CleanupStack::PopAndDestroy( silent );
       
  2618     CleanupStack::PushL( aSilentUrl );
       
  2619     return error;
       
  2620     }
       
  2621 
       
  2622 // -----------------------------------------------------------------------------
       
  2623 // CDrmUiHandlingImpl::GetOmaInfoUrlLC
       
  2624 // -----------------------------------------------------------------------------
       
  2625 //
       
  2626 TInt DRM::CDrmUiHandlingImpl::GetOmaInfoUrlLC(
       
  2627     const ContentAccess::CData& aContent,
       
  2628     HBufC*& aInfoUrl )
       
  2629     {
       
  2630     __ASSERT_DEBUG( !aInfoUrl, User::Panic( KDRMUtilityDebugPanicMessage,
       
  2631             KDRMUtilityDebugPanicCode ) );
       
  2632 
       
  2633     TInt error( KErrNone );
       
  2634     TInt currentLength( KUrlMaxLen );
       
  2635     HBufC* info( NULL );
       
  2636     TPtr infoPtr( NULL, 0 );
       
  2637 
       
  2638     info = HBufC::NewLC( currentLength );
       
  2639     infoPtr.Set( info->Des() );
       
  2640 
       
  2641     // get InfoUrl
       
  2642     error = aContent.GetStringAttribute( ContentAccess::EInfoURL, infoPtr );
       
  2643 
       
  2644     while ( error == KErrOverflow )
       
  2645         {
       
  2646         currentLength += currentLength;
       
  2647         CleanupStack::PopAndDestroy( info );
       
  2648         info = HBufC::NewLC( currentLength );
       
  2649         infoPtr.Set( info->Des() );
       
  2650         error
       
  2651             = aContent.GetStringAttribute( ContentAccess::EInfoURL, infoPtr );
       
  2652         }
       
  2653 
       
  2654     if ( !error && infoPtr.Length() )
       
  2655         {
       
  2656         aInfoUrl = infoPtr.AllocL();
       
  2657         }
       
  2658 
       
  2659     CleanupStack::PopAndDestroy( info );
       
  2660     CleanupStack::PushL( aInfoUrl );
       
  2661     return error;
       
  2662     }
       
  2663 
       
  2664 // -----------------------------------------------------------------------------
       
  2665 // CDrmUiHandlingImpl::GetOmaPendingRightsInfoLC
       
  2666 // -----------------------------------------------------------------------------
       
  2667 //
       
  2668 TInt DRM::CDrmUiHandlingImpl::GetOmaPendingRightsInfoLC(
       
  2669     const ContentAccess::CData& aContent,
       
  2670     HBufC*& aEta )
       
  2671     {
       
  2672     __ASSERT_DEBUG( !aEta, User::Panic( KDRMUtilityDebugPanicMessage,
       
  2673             KDRMUtilityDebugPanicCode ) );
       
  2674 
       
  2675     TInt error( KErrNone );
       
  2676     HBufC* eta( NULL );
       
  2677     TPtr etaPtr( NULL, 0 );
       
  2678 
       
  2679     eta = HBufC::NewLC( KDRMMaxETABufSize );
       
  2680     etaPtr.Set( eta->Des() );
       
  2681 
       
  2682     // get eta info
       
  2683     error = aContent.GetStringAttribute( EPendingRightsETA, etaPtr );
       
  2684 
       
  2685     if ( !error && etaPtr.Length() )
       
  2686         {
       
  2687         aEta = etaPtr.AllocL();
       
  2688         }
       
  2689 
       
  2690     CleanupStack::PopAndDestroy( eta );
       
  2691     CleanupStack::PushL( aEta );
       
  2692     return error;
       
  2693     }
       
  2694 
       
  2695 // -----------------------------------------------------------------------------
       
  2696 // CDrmUiHandlingImpl::GetContentLocationLC
       
  2697 // -----------------------------------------------------------------------------
       
  2698 //
       
  2699 TInt DRM::CDrmUiHandlingImpl::GetContentLocationLC(
       
  2700     const ContentAccess::CData& aContent,
       
  2701     HBufC*& aPath )
       
  2702     {
       
  2703     __ASSERT_DEBUG( !aPath, User::Panic( KDRMUtilityDebugPanicMessage,
       
  2704             KDRMUtilityDebugPanicCode ) );
       
  2705 
       
  2706     TInt error( KErrNone );
       
  2707     TInt currentLength( KUrlMaxLen );
       
  2708     TPtr pathPtr( NULL, 0 );
       
  2709 
       
  2710     aPath = HBufC::NewLC( currentLength );
       
  2711     pathPtr.Set( aPath->Des() );
       
  2712 
       
  2713     error = aContent.GetStringAttribute( DRM::EDrmFullName, pathPtr );
       
  2714 
       
  2715     while ( error == KErrOverflow )
       
  2716         {
       
  2717         currentLength += currentLength;
       
  2718         CleanupStack::PopAndDestroy( aPath );
       
  2719         aPath = HBufC::NewLC( currentLength );
       
  2720         pathPtr.Set( aPath->Des() );
       
  2721         error = aContent.GetStringAttribute( DRM::EDrmFullName, pathPtr );
       
  2722         }
       
  2723 
       
  2724     return error;
       
  2725     }
       
  2726 
       
  2727 // -----------------------------------------------------------------------------
       
  2728 // CDrmUiHandlingImpl::CheckOmaDomainStatusL
       
  2729 // -----------------------------------------------------------------------------
       
  2730 //
       
  2731 void DRM::CDrmUiHandlingImpl::CheckOmaDomainStatusL(
       
  2732     const ContentAccess::CData& aContent,
       
  2733     const HBufC* aDomainRiUrl,
       
  2734     TInt& aIsRegistered,
       
  2735     TInt& aIsJoined )
       
  2736     {
       
  2737     Roap::RRoapStorageClient storage;
       
  2738     CDRMRIContext* riContext( NULL );
       
  2739     CDRMDomainContext* domainContext( NULL );
       
  2740 
       
  2741     HBufC* riId( NULL );
       
  2742     HBufC8* riId8( NULL );
       
  2743     HBufC* domainId( NULL );
       
  2744     HBufC8* domainId8( NULL );
       
  2745 
       
  2746     TInt error( KErrNone );
       
  2747     TPtr ptr( NULL, 0 );
       
  2748 
       
  2749     aIsJoined = EFalse;
       
  2750     aIsRegistered = EFalse;
       
  2751 
       
  2752     riId = HBufC::NewLC( KUrlMaxLen );
       
  2753     domainId = HBufC::NewLC( KUrlMaxLen );
       
  2754 
       
  2755     // create attribute set
       
  2756     RStringAttributeSet stringAttributeSet;
       
  2757     CleanupClosePushL( stringAttributeSet );
       
  2758     // add the attributes we are interested in
       
  2759     stringAttributeSet.AddL( EDomainId );
       
  2760     stringAttributeSet.AddL( EDomainRightsIssuerId );
       
  2761 
       
  2762     User::LeaveIfError( aContent.GetStringAttributeSet( stringAttributeSet ) );
       
  2763 
       
  2764     // pass on values of string attributes
       
  2765     ptr.Set( domainId->Des() );
       
  2766     error = stringAttributeSet.GetValue( EDomainId, ptr );
       
  2767     if ( !error )
       
  2768         {
       
  2769         ptr.Set( riId->Des() );
       
  2770         stringAttributeSet.GetValue( EDomainRightsIssuerId, ptr );
       
  2771         if ( !error )
       
  2772             {
       
  2773             riId8 = HBufC8::NewLC( riId->Length() );
       
  2774             riId8->Des().Copy( riId->Des() );
       
  2775             domainId8 = HBufC8::NewLC( domainId->Length() );
       
  2776             domainId8->Des().Copy( domainId->Des() );
       
  2777 
       
  2778             if ( riId8 && riId8->Length() && aDomainRiUrl
       
  2779                 && aDomainRiUrl->Length() )
       
  2780                 {
       
  2781                 // Check if we have domain RO
       
  2782                 User::LeaveIfError( storage.Connect() );
       
  2783                 CleanupClosePushL( storage );
       
  2784                 riContext = storage.GetRIContextL( *riId8 );
       
  2785                 if ( riContext )
       
  2786                     {
       
  2787                     aIsRegistered = ETrue;
       
  2788                     delete riContext;
       
  2789                     if ( domainId8 && domainId8->Length() )
       
  2790                         {
       
  2791                         domainContext
       
  2792                             = storage.GetDomainContextL( *domainId8 );
       
  2793                         if ( domainContext )
       
  2794                             {
       
  2795                             // last three digits presents
       
  2796                             // the domain generation
       
  2797                             TInt generation( 0 );
       
  2798                             TLex8 lex( domainId8->Right(
       
  2799                                 KOmaDomainGenerationLength ) );
       
  2800                             lex.Val( generation );
       
  2801 
       
  2802                             if ( domainContext->DomainGeneration()
       
  2803                                 >= generation )
       
  2804                                 {
       
  2805                                 aIsJoined = ETrue;
       
  2806                                 }
       
  2807                             delete domainContext;
       
  2808                             }
       
  2809                         }
       
  2810                     }
       
  2811                 CleanupStack::PopAndDestroy( &storage );
       
  2812                 }
       
  2813             CleanupStack::PopAndDestroy( 2, riId8 ); // domainId8, riId8
       
  2814             }
       
  2815         }
       
  2816     CleanupStack::PopAndDestroy( &stringAttributeSet );
       
  2817     CleanupStack::PopAndDestroy( 2, riId ); // domainId, riId
       
  2818     }
       
  2819 
       
  2820 // -----------------------------------------------------------------------------
       
  2821 // CDrmUiHandlingImpl::CallRightsNotValidL
       
  2822 // -----------------------------------------------------------------------------
       
  2823 //
       
  2824 void DRM::CDrmUiHandlingImpl::CallRightsNotValidL(
       
  2825     DRM::MDrmUiCheckRightsObserver* aObserver,
       
  2826     TInt aOperationId,
       
  2827     DRM::TCheckRightsStatus aRightsStatus,
       
  2828     TUint32 aReason,
       
  2829     ContentAccess::CData& aContent,
       
  2830     const HBufC8* aContentUri,
       
  2831     CDRMConstraint* aConstraint,
       
  2832     const HBufC* aRightsUrl,
       
  2833     DRM::TDrmUiUrlType aUrlType,
       
  2834     const HBufC8* aSilentUrl,
       
  2835     ContentAccess::TIntent aIntent )
       
  2836     {
       
  2837     DRM::TCheckRightsAction rightsAction( DRM::EUHCheckRightsActionDefault );
       
  2838 
       
  2839     if ( aObserver )
       
  2840         {
       
  2841         // call given CheckRightsObserver
       
  2842         rightsAction = aObserver->RightsNotValid( aOperationId,
       
  2843             aRightsStatus, RejectReason( aReason ) );
       
  2844         }
       
  2845 
       
  2846     switch ( rightsAction )
       
  2847         {
       
  2848         case DRM::EUHCheckRightsActionDefault:
       
  2849             {
       
  2850             if ( RejectReason( aReason ) == DRM::EURejectionMetering )
       
  2851                 {
       
  2852                 // Show that only reason for error was rejected metering.
       
  2853                 iDrmUtilityUi->DisplayQueryWithIdL(
       
  2854                     R_DRM_QUERY_METERING_DISABLED,
       
  2855                     R_DRMUTILITY_WAITING_RIGHTS_CONFIRMATION_QUERY );
       
  2856                 }
       
  2857             else
       
  2858                 {
       
  2859                 if ( !GetSilentAndCallL( aObserver, aOperationId, aIntent,
       
  2860                     aContentUri, aSilentUrl, ETrue ) )
       
  2861                     {
       
  2862                     // Silent URL not present or silent retrieval failed
       
  2863                     // show appropriate notes
       
  2864                     if ( ShowNoRightsNoteL( aContent, RightsInfoStatus(
       
  2865                         aRightsStatus ), aReason, aConstraint, aRightsUrl,
       
  2866                         aUrlType, ENoRights ) )
       
  2867                         {
       
  2868                         GetRightsAndCallL( aObserver, aOperationId, aIntent,
       
  2869                             aContentUri, aRightsUrl );
       
  2870                         }
       
  2871                     }
       
  2872                 }
       
  2873             }
       
  2874             break;
       
  2875 
       
  2876         case DRM::EUHCheckRightsActionOpenDetailsView:
       
  2877             {
       
  2878             HBufC* fullPath( NULL );
       
  2879             GetContentLocationLC( aContent, fullPath );
       
  2880             ShowDetailsViewL( aContentUri, fullPath );
       
  2881             CleanupStack::PopAndDestroy( fullPath );
       
  2882             }
       
  2883             break;
       
  2884 
       
  2885         case DRM::EUHCheckRightsActionAcquireNewRights:
       
  2886             {
       
  2887             if ( !GetSilentAndCallL( aObserver, aOperationId, aIntent,
       
  2888                 aContentUri, aSilentUrl, EFalse ) )
       
  2889                 {
       
  2890                 GetRightsAndCallL( aObserver, aOperationId, aIntent,
       
  2891                     aContentUri, aRightsUrl );
       
  2892                 if ( !aRightsUrl )
       
  2893                     {
       
  2894                     User::Leave( KErrArgument );
       
  2895                     }
       
  2896                 }
       
  2897             }
       
  2898             break;
       
  2899 
       
  2900         case DRM::EUHCheckRightsActionIgnore:
       
  2901             // do nothing
       
  2902             break;
       
  2903 
       
  2904         default:
       
  2905             break;
       
  2906         }
       
  2907     }
       
  2908 
       
  2909 // -----------------------------------------------------------------------------
       
  2910 // CDrmUiHandlingImpl::CallRightsLeftL
       
  2911 // -----------------------------------------------------------------------------
       
  2912 //
       
  2913 void DRM::CDrmUiHandlingImpl::CallRightsLeftL(
       
  2914     DRM::MDrmUiCheckRightsObserver* aObserver,
       
  2915     TInt aOperationId,
       
  2916     TBool aUnconstrained,
       
  2917     TTimeIntervalSeconds aTime,
       
  2918     TInt aCounts,
       
  2919     TTimeIntervalSeconds aAccumulated,
       
  2920     const HBufC8* aContentUri,
       
  2921     const HBufC* aRightsUrl,
       
  2922     const HBufC8* aSilentUrl,
       
  2923     ContentAccess::CData& aContent,
       
  2924     ContentAccess::TIntent aIntent )
       
  2925     {
       
  2926     DRM::TCheckRightsAction rightsAction( DRM::EUHCheckRightsActionDefault );
       
  2927     HBufC* fullPath( NULL );
       
  2928 
       
  2929     if ( aObserver )
       
  2930         {
       
  2931         // call given CheckRightsObserver
       
  2932         rightsAction = aObserver->RightsLeft( aOperationId, aUnconstrained,
       
  2933             aTime, aCounts, aAccumulated );
       
  2934         }
       
  2935 
       
  2936     switch ( rightsAction )
       
  2937         {
       
  2938         case DRM::EUHCheckRightsActionDefault:
       
  2939             {
       
  2940             // show appropriate notes, none at the moment
       
  2941             }
       
  2942             break;
       
  2943 
       
  2944         case DRM::EUHCheckRightsActionOpenDetailsView:
       
  2945             {
       
  2946             GetContentLocationLC( aContent, fullPath );
       
  2947             ShowDetailsViewL( aContentUri, fullPath );
       
  2948             CleanupStack::PopAndDestroy( fullPath );
       
  2949             }
       
  2950             break;
       
  2951 
       
  2952         case DRM::EUHCheckRightsActionAcquireNewRights:
       
  2953             {
       
  2954             if ( !GetSilentAndCallL( aObserver, aOperationId, aIntent,
       
  2955                 aContentUri, aSilentUrl, EFalse ) )
       
  2956                 {
       
  2957                 if ( !aRightsUrl )
       
  2958                     {
       
  2959                     User::Leave( KErrArgument );
       
  2960                     }
       
  2961                 // launch browser to get new rights
       
  2962                 LaunchBrowserL( aRightsUrl );
       
  2963                 }
       
  2964             }
       
  2965             break;
       
  2966 
       
  2967         case DRM::EUHCheckRightsActionIgnore:
       
  2968             // do nothing
       
  2969             break;
       
  2970 
       
  2971         default:
       
  2972             break;
       
  2973         }
       
  2974     }
       
  2975 
       
  2976 // -----------------------------------------------------------------------------
       
  2977 // CDrmUiHandlingImpl::CallEmbeddedPreviewAvailableL
       
  2978 // -----------------------------------------------------------------------------
       
  2979 //
       
  2980 void DRM::CDrmUiHandlingImpl::CallEmbeddedPreviewAvailableL(
       
  2981     DRM::MDrmHandleErrorObserver* aObserver,
       
  2982     TInt aOperationId,
       
  2983 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  2984     ContentAccess::CData& aContent,
       
  2985 #else
       
  2986     ContentAccess::CData& /*aContent*/,
       
  2987 #endif
       
  2988     const HBufC* aPreviewUrl,
       
  2989     DRM::TDrmRightsInfo aRightsStatus,
       
  2990     TUint32 aReason,
       
  2991     const HBufC* aRightsUrl,
       
  2992     const HBufC8* aContentUri,
       
  2993     ContentAccess::TIntent aIntent )
       
  2994     {
       
  2995     DRM::TEmbeddedPreviewAction embeddedPreviewAction(
       
  2996         DRM::EUEmbeddedPreviewActionDefault );
       
  2997 
       
  2998 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  2999 
       
  3000     TInt buttonCode( 0 );
       
  3001 
       
  3002 #endif // RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  3003     if ( aObserver )
       
  3004         {
       
  3005         // call given HandleErrorObserver
       
  3006         embeddedPreviewAction
       
  3007             = aObserver->EmbeddedPreviewAvailable( aOperationId,
       
  3008                 *aPreviewUrl, aRightsStatus, RejectReason( aReason ) );
       
  3009         }
       
  3010 
       
  3011     switch ( embeddedPreviewAction )
       
  3012         {
       
  3013         case DRM::EUEmbeddedPreviewActionDefault:
       
  3014         case DRM::EUEmbeddedPreviewActionDefaultAudio:
       
  3015         case DRM::EUEmbeddedPreviewActionDefaultVideo:
       
  3016             {
       
  3017 
       
  3018 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  3019 
       
  3020             buttonCode = iDrmUtilityUi->DisplayPopupWindowsForPreviewL(
       
  3021                 aContent, ContentAccess::EInstantPreview,
       
  3022                 embeddedPreviewAction );
       
  3023 
       
  3024             switch ( buttonCode )
       
  3025                 {
       
  3026                 case 1: // Normal Rights
       
  3027 
       
  3028                     {
       
  3029                     GetRightsAndCallL( aObserver, aOperationId, aIntent,
       
  3030                         aContentUri, aRightsUrl );
       
  3031                     }
       
  3032                     break;
       
  3033 
       
  3034                 case 2: // Play Preview
       
  3035 
       
  3036                     CallPlayEmbeddedPreviewSelected( aObserver, aOperationId,
       
  3037                         aPreviewUrl );
       
  3038 
       
  3039                     break;
       
  3040 
       
  3041                 default:
       
  3042 
       
  3043                     break;
       
  3044                 }
       
  3045 
       
  3046 #endif // RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  3047             }
       
  3048             break;
       
  3049 
       
  3050         case DRM::EUEmbeddedPreviewActionFetchRights:
       
  3051             {
       
  3052             GetRightsAndCallL( aObserver, aOperationId, aIntent, aContentUri,
       
  3053                 aRightsUrl );
       
  3054             }
       
  3055             break;
       
  3056 
       
  3057         case DRM::EUEmbeddedPreviewActionPlayPreview:
       
  3058             // do nothing (observer plays the preview)
       
  3059         case DRM::EUEmbeddedPreviewActionIgnore:
       
  3060             // do nothing
       
  3061             break;
       
  3062 
       
  3063         default:
       
  3064             break;
       
  3065         }
       
  3066     }
       
  3067 
       
  3068 // -----------------------------------------------------------------------------
       
  3069 // CDrmUiHandlingImpl::CallPreviewRightsUrlAvailableL
       
  3070 // -----------------------------------------------------------------------------
       
  3071 //
       
  3072 void DRM::CDrmUiHandlingImpl::CallPreviewRightsUrlAvailableL(
       
  3073     DRM::MDrmHandleErrorObserver* aObserver,
       
  3074     TInt aOperationId,
       
  3075 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  3076     ContentAccess::CData& aContent,
       
  3077 #else
       
  3078     ContentAccess::CData& /*aContent*/,
       
  3079 #endif
       
  3080     const HBufC* aPreviewUrl,
       
  3081     DRM::TDrmRightsInfo aRightsStatus,
       
  3082     TUint32 aReason,
       
  3083     const HBufC* aRightsUrl,
       
  3084     const HBufC8* aContentUri,
       
  3085     ContentAccess::TIntent aIntent )
       
  3086     {
       
  3087     DRM::TPreviewRightsAction previewRightsAction(
       
  3088         DRM::EUPreviewRightsActionDefault );
       
  3089 
       
  3090 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  3091 
       
  3092     TInt buttonCode( 0 );
       
  3093     HBufC8* url8( NULL );
       
  3094 
       
  3095 #endif // RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  3096     if ( aObserver )
       
  3097         {
       
  3098         // call given HandleErrorObserver
       
  3099         previewRightsAction
       
  3100             = aObserver->PreviewRightsUrlAvailable( aOperationId,
       
  3101                 *aPreviewUrl, aRightsStatus, RejectReason( aReason ) );
       
  3102         }
       
  3103 
       
  3104     switch ( previewRightsAction )
       
  3105         {
       
  3106         case DRM::EUPreviewRightsActionDefault:
       
  3107         case DRM::EUPreviewRightsActionDefaultAudio:
       
  3108         case DRM::EUPreviewRightsActionDefaultVideo:
       
  3109             {
       
  3110 
       
  3111 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  3112 
       
  3113             buttonCode = iDrmUtilityUi->DisplayPopupWindowsForPreviewL(
       
  3114                 aContent, ContentAccess::EPreviewRights, previewRightsAction );
       
  3115 
       
  3116             switch ( buttonCode )
       
  3117                 {
       
  3118                 case 1: // Normal rights
       
  3119 
       
  3120                     {
       
  3121                     GetRightsAndCallL( aObserver, aOperationId, aIntent,
       
  3122                         aContentUri, aRightsUrl );
       
  3123 
       
  3124                     }
       
  3125                     break;
       
  3126 
       
  3127                 case 2: // Preview rights
       
  3128                     {
       
  3129                     TInt callError( KErrNotFound );
       
  3130                     if ( aPreviewUrl )
       
  3131                         {
       
  3132                         url8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L(
       
  3133                             *aPreviewUrl );
       
  3134                         CleanupStack::PushL( url8 );
       
  3135 
       
  3136                         GetSilentRightsL( *url8, ETrue );
       
  3137 
       
  3138                         CleanupStack::PopAndDestroy( url8 );
       
  3139 
       
  3140                         // check if rights exist now
       
  3141                         callError = CheckAndMapToCallError( iOmaClient,
       
  3142                             aIntent, *aContentUri );
       
  3143                         }
       
  3144                     CallPreviewRightsAvailable( aObserver, aOperationId,
       
  3145                         callError );
       
  3146                     }
       
  3147                     break;
       
  3148 
       
  3149                 default:
       
  3150 
       
  3151                     break;
       
  3152                 }
       
  3153 
       
  3154 #endif // RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  3155             }
       
  3156             break;
       
  3157 
       
  3158         case DRM::EUPreviewRightsActionFetchRights:
       
  3159             {
       
  3160             GetRightsAndCallL( aObserver, aOperationId, aIntent, aContentUri,
       
  3161                 aRightsUrl );
       
  3162             }
       
  3163             break;
       
  3164 
       
  3165         case DRM::EUPreviewRightsActionFetchPreviewRights:
       
  3166             // do nothing (observer fetches preview rights)
       
  3167         case DRM::EUPreviewRightsActionIgnore:
       
  3168             // do nothing
       
  3169             break;
       
  3170 
       
  3171         default:
       
  3172             break;
       
  3173         }
       
  3174     }
       
  3175 
       
  3176 // -----------------------------------------------------------------------------
       
  3177 // CDrmUiHandlingImpl::CallSilentRightsUrlAvailableL
       
  3178 // -----------------------------------------------------------------------------
       
  3179 //
       
  3180 void DRM::CDrmUiHandlingImpl::CallSilentRightsUrlAvailableL(
       
  3181     DRM::MDrmHandleErrorObserver* aObserver,
       
  3182     TInt aOperationId,
       
  3183     const HBufC8* aSilentUrl,
       
  3184     DRM::TDrmRightsInfo aRightsStatus,
       
  3185     TUint32 aReason,
       
  3186     const HBufC* aRightsUrl,
       
  3187     const HBufC8* aContentUri,
       
  3188     ContentAccess::TIntent aIntent )
       
  3189     {
       
  3190     DRM::TSilentRightsAction silentRightsAction(
       
  3191         DRM::EUSilentRightsActionDefault );
       
  3192     TInt callError( KErrNotFound );
       
  3193     HBufC * silent16(
       
  3194         CnvUtfConverter::ConvertToUnicodeFromUtf8L( *aSilentUrl ) );
       
  3195 
       
  3196     if ( aObserver )
       
  3197         {
       
  3198         // call given HandleErrorObserver
       
  3199         silentRightsAction = aObserver->SilentRightsUrlAvailable(
       
  3200             aOperationId, *silent16, aRightsStatus, RejectReason( aReason ) );
       
  3201         }
       
  3202 
       
  3203     delete silent16;
       
  3204 
       
  3205     switch ( silentRightsAction )
       
  3206         {
       
  3207         case DRM::EUSilentRightsActionDefault:
       
  3208             {
       
  3209 
       
  3210             GetSilentRightsL( *aSilentUrl, ETrue );
       
  3211 
       
  3212             // check if rights exist now
       
  3213             callError = CheckAndMapToCallError( iOmaClient, aIntent,
       
  3214                 *aContentUri );
       
  3215             CallSilentRightsAvailable( aObserver, aOperationId, callError );
       
  3216 
       
  3217             }
       
  3218             break;
       
  3219 
       
  3220         case DRM::EUSilentRightsActionFetchRights:
       
  3221             {
       
  3222             GetRightsAndCallL( aObserver, aOperationId, aIntent, aContentUri,
       
  3223                 aRightsUrl );
       
  3224             }
       
  3225             break;
       
  3226 
       
  3227         case DRM::EUSilentRightsActionFetchSilentRights:
       
  3228             // do nothing (observer fetches silent rights)
       
  3229         case DRM::EUSilentRightsActionIgnore:
       
  3230             // do nothing
       
  3231             break;
       
  3232 
       
  3233         default:
       
  3234             break;
       
  3235         }
       
  3236     }
       
  3237 
       
  3238 // -----------------------------------------------------------------------------
       
  3239 // CDrmUiHandlingImpl::CallRightsUrlAvailableL
       
  3240 // -----------------------------------------------------------------------------
       
  3241 //
       
  3242 void DRM::CDrmUiHandlingImpl::CallRightsUrlAvailableL(
       
  3243     DRM::MDrmHandleErrorObserver* aObserver,
       
  3244     TInt aOperationId,
       
  3245     DRM::TDrmRightsInfo aRightsStatus,
       
  3246     TUint32 aReason,
       
  3247     CDRMConstraint* aConstraint,
       
  3248     ContentAccess::CData& aContent,
       
  3249     const HBufC8* aContentUri,
       
  3250     const HBufC* aRightsUrl,
       
  3251     DRM::TDrmUiUrlType aUrlType,
       
  3252     ContentAccess::TIntent aIntent,
       
  3253     TInt aError )
       
  3254     {
       
  3255     DRM::TRightsAction rightsAction( DRM::EURightsActionDefault );
       
  3256 
       
  3257     if ( aObserver && aRightsUrl )
       
  3258         {
       
  3259         // call given HandleErrorObserver
       
  3260         rightsAction = aObserver->RightsUrlAvailable( aOperationId,
       
  3261             *aRightsUrl, aRightsStatus, RejectReason( aReason ), aUrlType );
       
  3262         }
       
  3263 
       
  3264     switch ( rightsAction )
       
  3265         {
       
  3266         case DRM::EURightsActionDefault:
       
  3267             {
       
  3268             if ( ShowNoRightsNoteL( aContent, aRightsStatus, aReason,
       
  3269                 aConstraint, aRightsUrl, aUrlType, aError ) )
       
  3270                 {
       
  3271                 GetRightsAndCallL( aObserver, aOperationId, aIntent,
       
  3272                     aContentUri, aRightsUrl );
       
  3273                 }
       
  3274             }
       
  3275             break;
       
  3276 
       
  3277         case DRM::EURightsActionFetchRights:
       
  3278             {
       
  3279             GetRightsAndCallL( aObserver, aOperationId, aIntent, aContentUri,
       
  3280                 aRightsUrl );
       
  3281             }
       
  3282             break;
       
  3283 
       
  3284         case DRM::EURightsActionIgnore:
       
  3285             // do nothing
       
  3286             break;
       
  3287 
       
  3288         default:
       
  3289             break;
       
  3290         }
       
  3291     }
       
  3292 
       
  3293 // -----------------------------------------------------------------------------
       
  3294 // CDrmUiHandlingImpl::CallPreviewRightsAvailable
       
  3295 // -----------------------------------------------------------------------------
       
  3296 //
       
  3297 void DRM::CDrmUiHandlingImpl::CallPreviewRightsAvailable(
       
  3298     DRM::MDrmHandleErrorObserver* aObserver,
       
  3299     TInt aOperationId,
       
  3300     TInt aError )
       
  3301     {
       
  3302 
       
  3303     if ( aObserver )
       
  3304         {
       
  3305         // call given HandleErrorObserver
       
  3306         aObserver->PreviewRightsAvailable( aOperationId, aError );
       
  3307         }
       
  3308     }
       
  3309 
       
  3310 // -----------------------------------------------------------------------------
       
  3311 // CDrmUiHandlingImpl::CallSilentRightsAvailable
       
  3312 // -----------------------------------------------------------------------------
       
  3313 //
       
  3314 void DRM::CDrmUiHandlingImpl::CallSilentRightsAvailable(
       
  3315     DRM::MDrmHandleErrorObserver* aObserver,
       
  3316     TInt aOperationId,
       
  3317     TInt aError )
       
  3318     {
       
  3319 
       
  3320     if ( aObserver )
       
  3321         {
       
  3322         // call given HandleErrorObserver
       
  3323         aObserver->SilentRightsAvailable( aOperationId, aError );
       
  3324         }
       
  3325     }
       
  3326 
       
  3327 // -----------------------------------------------------------------------------
       
  3328 // CDrmUiHandlingImpl::CallRightsAvailable
       
  3329 // -----------------------------------------------------------------------------
       
  3330 //
       
  3331 void DRM::CDrmUiHandlingImpl::CallRightsAvailable(
       
  3332     DRM::MDrmHandleErrorObserver* aObserver,
       
  3333     TInt aOperationId,
       
  3334     TInt aError )
       
  3335     {
       
  3336 
       
  3337     if ( aObserver )
       
  3338         {
       
  3339         // call given HandleErrorObserver
       
  3340         aObserver->RightsAvailable( aOperationId, aError );
       
  3341         }
       
  3342     }
       
  3343 
       
  3344 // -----------------------------------------------------------------------------
       
  3345 // CDrmUiHandlingImpl::CallPlayEmbeddedPreviewSelected
       
  3346 // -----------------------------------------------------------------------------
       
  3347 //
       
  3348 void DRM::CDrmUiHandlingImpl::CallPlayEmbeddedPreviewSelected(
       
  3349     DRM::MDrmHandleErrorObserver* aObserver,
       
  3350     TInt aOperationId,
       
  3351     const HBufC* aPreviewUrl )
       
  3352     {
       
  3353     if ( aObserver )
       
  3354         {
       
  3355         // call given HandleErrorObserver
       
  3356         aObserver->PlayEmbeddedPreviewSelected( aOperationId, *aPreviewUrl );
       
  3357         }
       
  3358     }
       
  3359 
       
  3360 // -----------------------------------------------------------------------------
       
  3361 // CDrmUiHandlingImpl::ShowNoRightsNoteL
       
  3362 // -----------------------------------------------------------------------------
       
  3363 //
       
  3364 TBool DRM::CDrmUiHandlingImpl::ShowNoRightsNoteL(
       
  3365     ContentAccess::CData& aContent,
       
  3366     DRM::TDrmRightsInfo aRightsStatus,
       
  3367     TUint32 aReason,
       
  3368     CDRMConstraint* aConstraint,
       
  3369     const HBufC* aRightsUrl,
       
  3370     DRM::TDrmUiUrlType aUrlType,
       
  3371     TInt aError )
       
  3372     {
       
  3373     HBufC* etaBuf( NULL );
       
  3374     TBool isRegistered( EFalse );
       
  3375     TBool isJoined( EFalse );
       
  3376     TInt ret( 0 );
       
  3377     TInt err( KErrNone );
       
  3378     TInt eta( 0 );
       
  3379     TFileName fileName;
       
  3380     TBool rightsRenewalWanted( EFalse );
       
  3381 
       
  3382     if ( aError != EPendingRights && aRightsStatus == DRM::EURightsInfoFuture )
       
  3383         {
       
  3384         iDrmUtilityUi->ShowFutureRightsNoteL( aConstraint );
       
  3385         }
       
  3386     else
       
  3387         {
       
  3388         // check if rights are expected to arrive
       
  3389         GetOmaPendingRightsInfoLC( aContent, etaBuf );
       
  3390         if ( etaBuf )
       
  3391             {
       
  3392             TLex lexer( *etaBuf );
       
  3393             err = lexer.Val( eta );
       
  3394             }
       
  3395         CleanupStack::PopAndDestroy( etaBuf );
       
  3396 
       
  3397         if ( !err && aError == EPendingRights && eta == -1 )
       
  3398             {
       
  3399             // rights should have come already
       
  3400             if ( aRightsUrl )
       
  3401                 {
       
  3402                 ret = iDrmUtilityUi->DisplayQueryWithIdL(
       
  3403                     R_DRMUTILITY_RIGHTS_SHOULD_HAVE_COME,
       
  3404                     R_DRMUTILITY_CONFIRMATION_QUERY );
       
  3405                 }
       
  3406             else
       
  3407                 {
       
  3408                 // no rights issuer
       
  3409                 iDrmUtilityUi->DisplayQueryWithIdL(
       
  3410                     R_DRMUTILITY_RIGHTS_SHOULD_HAVE_COME_NO_RI,
       
  3411                     R_DRMUTILITY_WAITING_RIGHTS_CONFIRMATION_QUERY );
       
  3412                 }
       
  3413             }
       
  3414         else if ( !eta || err || eta == -1 )
       
  3415             {
       
  3416             // rights not expected to arrive
       
  3417             if ( aUrlType == DRM::EUHDomainRiUrl )
       
  3418                 {
       
  3419                 CheckOmaDomainStatusL( aContent, aRightsUrl, isRegistered,
       
  3420                     isJoined );
       
  3421                 }
       
  3422 
       
  3423             if ( aRightsUrl && isRegistered && !isJoined ) // Domain ro case
       
  3424                 {
       
  3425                 ret = iDrmUtilityUi->DisplayQueryWithIdL(
       
  3426                     R_DRMUTILITY_ACTIVATE_ACCOUNT,
       
  3427                     R_DRMUTILITY_CONFIRMATION_QUERY );
       
  3428                 }
       
  3429             else if ( aRightsUrl ) // Device ro case
       
  3430                 {
       
  3431                 if ( aReason & EConstraintIndividual )
       
  3432                     {
       
  3433                     ret = iDrmUtilityUi->DisplayQueryWithIdL(
       
  3434                         R_DRMUTILITY_INVALID_SIM,
       
  3435                         R_DRMUTILITY_CONFIRMATION_QUERY );
       
  3436                     }
       
  3437                 else
       
  3438                     {
       
  3439                     // get filename
       
  3440                     User::LeaveIfError( aContent.GetStringAttribute(
       
  3441                         EFileName, fileName ) );
       
  3442 
       
  3443                     ret = iDrmUtilityUi->DisplayQueryL(
       
  3444                         R_DRM_QUERY_EXPIRED_OR_NO_RO, fileName );
       
  3445                     }
       
  3446                 }
       
  3447             else // no rights issuer
       
  3448                 {
       
  3449                 if ( aReason & EConstraintIndividual )
       
  3450                     {
       
  3451                     iDrmUtilityUi->DisplayNoteL( R_DRM_INFO_SIM_NOT_ALLOWED );
       
  3452                     }
       
  3453                 else
       
  3454                     {
       
  3455                     iDrmUtilityUi->DisplayNoteL( R_DRM_INFO_EXPIRED_OR_NO_RO );
       
  3456                     }
       
  3457                 }
       
  3458             }
       
  3459         else
       
  3460             {
       
  3461             // rights expected to arrive
       
  3462             if ( eta != KErrCAPendingRights )
       
  3463                 {
       
  3464                 // rights expected to arrive in eta seconds
       
  3465                 iDrmUtilityUi->DisplayQueryWithIdL(
       
  3466                     R_DRMUTILITY_WAITING_FOR_RIGHTS,
       
  3467                     R_DRMUTILITY_WAITING_RIGHTS_CONFIRMATION_QUERY );
       
  3468                 }
       
  3469             else
       
  3470                 {
       
  3471                 // rights should have come
       
  3472                 if ( aRightsUrl )
       
  3473                     {
       
  3474                     ret = iDrmUtilityUi->DisplayQueryWithIdL(
       
  3475                         R_DRMUTILITY_RIGHTS_SHOULD_HAVE_COME,
       
  3476                         R_DRMUTILITY_CONFIRMATION_QUERY );
       
  3477                     }
       
  3478                 else
       
  3479                     {
       
  3480                     // no rights issuer
       
  3481                     iDrmUtilityUi->DisplayQueryWithIdL(
       
  3482                         R_DRMUTILITY_RIGHTS_SHOULD_HAVE_COME_NO_RI,
       
  3483                         R_DRMUTILITY_WAITING_RIGHTS_CONFIRMATION_QUERY );
       
  3484                     }
       
  3485                 }
       
  3486             }
       
  3487         }
       
  3488 
       
  3489     if ( ret == EAknSoftkeyYes || ret == EAknSoftkeyOk )
       
  3490         {
       
  3491         rightsRenewalWanted = ETrue;
       
  3492         }
       
  3493     return rightsRenewalWanted;
       
  3494     }
       
  3495 
       
  3496 // -----------------------------------------------------------------------------
       
  3497 // CDrmUiHandlingImpl::GetOmaConstraintInfo
       
  3498 // -----------------------------------------------------------------------------
       
  3499 //
       
  3500 TInt DRM::CDrmUiHandlingImpl::GetOmaConstraintInfo(
       
  3501     CDRMConstraint* aConstraint,
       
  3502     TUint32& aCountsLeft,
       
  3503     TTime& aEndTime )
       
  3504     {
       
  3505     __ASSERT_DEBUG( aConstraint, User::Panic( KDRMUtilityDebugPanicMessage,
       
  3506             KDRMUtilityDebugPanicCode ) );
       
  3507 
       
  3508     TInt ret( 0 );
       
  3509     TTime start( Time::NullTTime() );
       
  3510     aCountsLeft = 0;
       
  3511     aEndTime = Time::NullTTime();
       
  3512 
       
  3513     if ( aConstraint->iActiveConstraints & EConstraintCounter )
       
  3514         {
       
  3515         ret |= KDRMOmaConstraintCount;
       
  3516         aCountsLeft = aConstraint->iCounter;
       
  3517         }
       
  3518     if ( aConstraint->iActiveConstraints & EConstraintTimedCounter )
       
  3519         {
       
  3520         ret |= KDRMOmaConstraintCount;
       
  3521         if ( aConstraint->iTimedCounter > aCountsLeft )
       
  3522             {
       
  3523             aCountsLeft = aConstraint->iTimedCounter;
       
  3524             }
       
  3525         }
       
  3526     if ( aConstraint->iActiveConstraints & EConstraintEndTime )
       
  3527         {
       
  3528         ret |= KDRMOmaConstraintTime;
       
  3529         aEndTime = aConstraint->iEndTime;
       
  3530         }
       
  3531     if ( aConstraint->iActiveConstraints & EConstraintInterval )
       
  3532         {
       
  3533         start = aConstraint->iIntervalStart;
       
  3534         if ( start == Time::NullTTime() )
       
  3535             {
       
  3536             start.HomeTime();
       
  3537             }
       
  3538         aEndTime = start + aConstraint->iInterval;
       
  3539         ret |= KDRMOmaConstraintTime;
       
  3540         }
       
  3541     if ( aConstraint->iActiveConstraints & EConstraintAccumulated )
       
  3542         {
       
  3543         if ( aEndTime != Time::NullTTime() && aEndTime
       
  3544             + aConstraint->iAccumulatedTime > aEndTime || aEndTime
       
  3545             == Time::NullTTime() )
       
  3546             {
       
  3547             aEndTime.HomeTime();
       
  3548             aEndTime = aEndTime + aConstraint->iAccumulatedTime;
       
  3549             ret |= KDRMOmaConstraintAccumulated;
       
  3550             }
       
  3551         }
       
  3552     return ret;
       
  3553     }
       
  3554 
       
  3555 // -----------------------------------------------------------------------------
       
  3556 // CDrmUiHandlingImpl::RejectReason
       
  3557 // -----------------------------------------------------------------------------
       
  3558 //
       
  3559 TInt DRM::CDrmUiHandlingImpl::RejectReason( TUint32 aReason )
       
  3560     {
       
  3561     TInt ret( DRM::EURejectionNone );
       
  3562 
       
  3563     if ( aReason & EConstraintStartTime )
       
  3564         {
       
  3565         ret |= DRM::EURejectionStartTime;
       
  3566         }
       
  3567 
       
  3568     if ( aReason & EConstraintEndTime )
       
  3569         {
       
  3570         ret |= DRM::EURejectionEndTime;
       
  3571         }
       
  3572 
       
  3573     if ( aReason & EConstraintInterval )
       
  3574         {
       
  3575         ret |= DRM::EURejectionInterval;
       
  3576         }
       
  3577 
       
  3578     if ( aReason & EConstraintCounter )
       
  3579         {
       
  3580         ret |= DRM::EURejectionCounter;
       
  3581         }
       
  3582 
       
  3583     if ( aReason & EConstraintTopLevel )
       
  3584         {
       
  3585         ret |= DRM::EURejectionTopLevel;
       
  3586         }
       
  3587 
       
  3588     if ( aReason & EConstraintTimedCounter )
       
  3589         {
       
  3590         ret |= DRM::EURejectionTimedCounter;
       
  3591         }
       
  3592 
       
  3593     if ( aReason & EConstraintAccumulated )
       
  3594         {
       
  3595         ret |= DRM::EURejectionAccumulated;
       
  3596         }
       
  3597 
       
  3598     if ( aReason & EConstraintIndividual )
       
  3599         {
       
  3600         ret |= DRM::EURejectionIndividual;
       
  3601         }
       
  3602 
       
  3603     if ( aReason & EConstraintSystem )
       
  3604         {
       
  3605         ret |= DRM::EURejectionSystem;
       
  3606         }
       
  3607 
       
  3608     if ( aReason & EConstraintVendor )
       
  3609         {
       
  3610         ret |= DRM::EURejectionVendor;
       
  3611         }
       
  3612 
       
  3613     if ( aReason & EConstraintSoftware )
       
  3614         {
       
  3615         ret |= DRM::EURejectionSoftware;
       
  3616         }
       
  3617 
       
  3618     if ( aReason & EConstraintMetering )
       
  3619         {
       
  3620         ret |= DRM::EURejectionMetering;
       
  3621         }
       
  3622 
       
  3623     if ( aReason & EConstraintNullDrmTime )
       
  3624         {
       
  3625         ret |= DRM::EURejectionDrmTime;
       
  3626         }
       
  3627 
       
  3628     return ret;
       
  3629     }
       
  3630 
       
  3631 // -----------------------------------------------------------------------------
       
  3632 // CDrmUiHandlingImpl::RightsInfoStatus
       
  3633 // -----------------------------------------------------------------------------
       
  3634 //
       
  3635 DRM::TDrmRightsInfo DRM::CDrmUiHandlingImpl::RightsInfoStatus(
       
  3636     DRM::TCheckRightsStatus aStatus )
       
  3637     {
       
  3638     DRM::TDrmRightsInfo ret( DRM::EURightsInfoValid );
       
  3639 
       
  3640     if ( aStatus == DRM::EUHCheckRightsExpiredRights )
       
  3641         {
       
  3642         ret = DRM::EURightsInfoExpired;
       
  3643         }
       
  3644     else if ( aStatus == DRM::EUHCheckRightsNoRights )
       
  3645         {
       
  3646         ret = DRM::EURightsInfoMissing;
       
  3647         }
       
  3648     else if ( aStatus == DRM::EUHCheckRightsFutureRights )
       
  3649         {
       
  3650         ret = DRM::EURightsInfoFuture;
       
  3651         }
       
  3652 
       
  3653     return ret;
       
  3654     }
       
  3655 
       
  3656 // -----------------------------------------------------------------------------
       
  3657 // CDrmUiHandlingImpl::SelectOmaRightsUrlL
       
  3658 // -----------------------------------------------------------------------------
       
  3659 //
       
  3660 void DRM::CDrmUiHandlingImpl::SelectOmaRightsUrlL(
       
  3661     const ContentAccess::CData& aContent,
       
  3662     const HBufC* aDomainRiUrl,
       
  3663     DRM::TDrmUiUrlType& aUrlType )
       
  3664     {
       
  3665     Roap::RRoapStorageClient storage;
       
  3666     CDRMRIContext* riContext( NULL );
       
  3667     CDRMDomainContext* domainContext( NULL );
       
  3668 
       
  3669     HBufC* riId( NULL );
       
  3670     HBufC8* riId8( NULL );
       
  3671     HBufC* domainId( NULL );
       
  3672     HBufC8* domainId8( NULL );
       
  3673 
       
  3674     TInt error( KErrNone );
       
  3675     TPtr ptr( NULL, 0 );
       
  3676     TBool isJoined( EFalse );
       
  3677     TBool isRegistered( EFalse );
       
  3678 
       
  3679     aUrlType = DRM::EUHRightsIssuerUrl;
       
  3680     riId = HBufC::NewLC( KUrlMaxLen );
       
  3681     domainId = HBufC::NewLC( KUrlMaxLen );
       
  3682 
       
  3683     // create attribute set
       
  3684     RStringAttributeSet stringAttributeSet;
       
  3685     CleanupClosePushL( stringAttributeSet );
       
  3686     // add the attributes we are interested in
       
  3687     stringAttributeSet.AddL( EDomainId );
       
  3688     stringAttributeSet.AddL( EDomainRightsIssuerId );
       
  3689 
       
  3690     User::LeaveIfError( aContent.GetStringAttributeSet( stringAttributeSet ) );
       
  3691 
       
  3692     // pass on values of string attributes
       
  3693     ptr.Set( domainId->Des() );
       
  3694     error = stringAttributeSet.GetValue( EDomainId, ptr );
       
  3695     if ( !error )
       
  3696         {
       
  3697         ptr.Set( riId->Des() );
       
  3698         stringAttributeSet.GetValue( EDomainRightsIssuerId, ptr );
       
  3699         if ( !error )
       
  3700             {
       
  3701             riId8 = HBufC8::NewLC( riId->Length() );
       
  3702             riId8->Des().Copy( riId->Des() );
       
  3703             domainId8 = HBufC8::NewLC( domainId->Length() );
       
  3704             domainId8->Des().Copy( domainId->Des() );
       
  3705 
       
  3706             if ( riId8 && riId8->Length() && aDomainRiUrl
       
  3707                 && aDomainRiUrl->Length() )
       
  3708                 {
       
  3709                 // Check if we have domain RO
       
  3710                 User::LeaveIfError( storage.Connect() );
       
  3711                 CleanupClosePushL( storage );
       
  3712                 riContext = storage.GetRIContextL( *riId8 );
       
  3713                 if ( riContext )
       
  3714                     {
       
  3715                     isRegistered = ETrue;
       
  3716                     delete riContext;
       
  3717                     if ( domainId8 && domainId8->Length() )
       
  3718                         {
       
  3719                         domainContext
       
  3720                             = storage.GetDomainContextL( *domainId8 );
       
  3721                         if ( domainContext )
       
  3722                             {
       
  3723                             // last three digits presents
       
  3724                             // the domain generation
       
  3725                             TInt generation( 0 );
       
  3726                             TLex8 lex( domainId8->Right(
       
  3727                                 KOmaDomainGenerationLength ) );
       
  3728                             lex.Val( generation );
       
  3729 
       
  3730                             if ( domainContext->DomainGeneration()
       
  3731                                 >= generation )
       
  3732                                 {
       
  3733                                 isJoined = ETrue;
       
  3734                                 }
       
  3735                             delete domainContext;
       
  3736                             }
       
  3737                         }
       
  3738                     }
       
  3739                 CleanupStack::PopAndDestroy( &storage );
       
  3740 
       
  3741                 if ( aDomainRiUrl && aDomainRiUrl->Length()
       
  3742                     && ( !isRegistered | !isJoined ) )
       
  3743                     {
       
  3744                     aUrlType = DRM::EUHDomainRiUrl;
       
  3745                     }
       
  3746 
       
  3747                 }
       
  3748             CleanupStack::PopAndDestroy( 2, riId8 ); // domainId8, riId8
       
  3749             }
       
  3750         }
       
  3751     CleanupStack::PopAndDestroy( &stringAttributeSet );
       
  3752     CleanupStack::PopAndDestroy( 2, riId ); // domainId, riId
       
  3753     }
       
  3754 
       
  3755 // -----------------------------------------------------------------------------
       
  3756 // CDrmUiHandlingImpl::LaunchRightsManagerUiL
       
  3757 // -----------------------------------------------------------------------------
       
  3758 //
       
  3759 void DRM::CDrmUiHandlingImpl::LaunchRightsManagerUiL( const TDesC& aParam16 )
       
  3760     {
       
  3761     const TUid KUidDRMUI =
       
  3762         {
       
  3763         0x101f85c7
       
  3764         };
       
  3765 
       
  3766     if ( iCoeEnv )
       
  3767         {
       
  3768         CAiwGenericParamList* paramList( CAiwGenericParamList::NewLC() );
       
  3769         TAiwVariant variantObject( aParam16 );
       
  3770         TAiwGenericParam param( EGenericParamFile, variantObject );
       
  3771         paramList->AppendL( param );
       
  3772 
       
  3773         CAknLaunchAppService* launchAppService( CAknLaunchAppService::NewL(
       
  3774             KUidDRMUI, this, paramList ) );
       
  3775         iWait.Start();
       
  3776         delete launchAppService;
       
  3777         CleanupStack::PopAndDestroy( paramList );
       
  3778         }
       
  3779     else
       
  3780         {
       
  3781         // no UI to embed, launch Rights Manager UI stand-alone
       
  3782         // check if Rights Manager UI is already running
       
  3783         RWsSession wsSession;
       
  3784         User::LeaveIfError( wsSession.Connect() );
       
  3785         CleanupClosePushL( wsSession );
       
  3786         TApaTaskList tasklist( wsSession );
       
  3787         TApaTask task( tasklist.FindApp( KUidDRMUI ) );
       
  3788         if ( task.Exists() )
       
  3789             {
       
  3790             // Rights Manager UI is already running
       
  3791             HBufC8* param8( HBufC8::NewLC( aParam16.Length() ) );
       
  3792             TPtr8 parametersPtr( param8->Des() );
       
  3793             parametersPtr.Copy( aParam16 );
       
  3794             task.SendMessage( TUid::Uid( KUidApaMessageSwitchOpenFileValue ),
       
  3795                 *param8 );
       
  3796             CleanupStack::PopAndDestroy( param8 );
       
  3797             }
       
  3798         else
       
  3799             {
       
  3800             RApaLsSession appArcSession;
       
  3801             User::LeaveIfError( appArcSession.Connect() );
       
  3802             CleanupClosePushL( appArcSession );
       
  3803             TThreadId id;
       
  3804             appArcSession.StartDocument( aParam16, KUidDRMUI, id );
       
  3805             CleanupStack::PopAndDestroy( &appArcSession );
       
  3806             }
       
  3807         CleanupStack::PopAndDestroy( &wsSession );
       
  3808         }
       
  3809     }
       
  3810 
       
  3811 // -----------------------------------------------------------------------------
       
  3812 // CDrmUiHandlingImpl::CreateLaunchParamL
       
  3813 // -----------------------------------------------------------------------------
       
  3814 //
       
  3815 void DRM::CDrmUiHandlingImpl::CreateLaunchParamL(
       
  3816     const HBufC8* aUrl,
       
  3817     HBufC*& aLaunchParam,
       
  3818     const HBufC* aFullPath )
       
  3819     {
       
  3820     __ASSERT_DEBUG( !aLaunchParam && aUrl && aFullPath,
       
  3821         User::Panic( KDRMUtilityDebugPanicMessage,
       
  3822             KDRMUtilityDebugPanicCode ) );
       
  3823     _LIT( KSpace, " " );
       
  3824 
       
  3825     RPointerArray<CDRMPermission> uriList;
       
  3826     TPtr ptr( NULL, 0 );
       
  3827 
       
  3828     TInt localId( 0 );
       
  3829     TInt err( KErrNone );
       
  3830 
       
  3831         TRAP( err, iOmaClient.GetDBEntriesL( *aUrl, uriList ) );
       
  3832 
       
  3833     if ( uriList.Count() == 1 )
       
  3834         {
       
  3835         localId = ( uriList[0] )->iUniqueID;
       
  3836         }
       
  3837 
       
  3838     uriList.ResetAndDestroy();
       
  3839     uriList.Close();
       
  3840 
       
  3841     // MaxInt will fit into 10 characters
       
  3842     HBufC* localIDBuf( HBufC::NewLC( KIntegerMaxLen ) );
       
  3843     ptr.Set( localIDBuf->Des() );
       
  3844     ptr.AppendNum( localId );
       
  3845 
       
  3846     // length of startparam and drm protection scheme are always 1 and
       
  3847     // 4 spaces are needed
       
  3848     const TInt KSpacesBetweenParams( 4 );
       
  3849     TInt length( 1 + aUrl->Length() + ptr.Length() + aFullPath->Length()
       
  3850         + KSpacesBetweenParams + 1 );
       
  3851 
       
  3852     aLaunchParam = HBufC::NewLC( length );
       
  3853     ptr.Set( aLaunchParam->Des() );
       
  3854 
       
  3855     // Start parameter is 3 or 4 for launching details view embedded or standalone from
       
  3856     // DRM Utility, respectively, with full path name included as a parameter. Values 1
       
  3857     // and 2 are for launching details view from DRM Helper.
       
  3858     if ( iCoeEnv )
       
  3859         {
       
  3860         ptr.AppendNum( EDrmLaunchParamEmbeddedUtility );
       
  3861         }
       
  3862     else
       
  3863         {
       
  3864         ptr.AppendNum( EDrmLaunchParamStandAloneUtility );
       
  3865         }
       
  3866     ptr.Append( KSpace );
       
  3867     ptr.Append( *localIDBuf );
       
  3868     ptr.Append( KSpace );
       
  3869 
       
  3870     HBufC* contentUrl( CnvUtfConverter::ConvertToUnicodeFromUtf8L( *aUrl ) );
       
  3871 
       
  3872     ptr.Append( *contentUrl );
       
  3873     ptr.Append( KSpace );
       
  3874 
       
  3875     // OMA DRM protection scheme
       
  3876     ptr.AppendNum( EDrmSchemeOmaDrm );
       
  3877     ptr.Append( KSpace );
       
  3878 
       
  3879     ptr.Append( *aFullPath );
       
  3880 
       
  3881     delete contentUrl;
       
  3882 
       
  3883     CleanupStack::Pop( aLaunchParam );
       
  3884     CleanupStack::PopAndDestroy( localIDBuf );
       
  3885     }
       
  3886 
       
  3887 // -----------------------------------------------------------------------------
       
  3888 // CDrmUiHandlingImpl::CreateLaunchParamL
       
  3889 // -----------------------------------------------------------------------------
       
  3890 //
       
  3891 void DRM::CDrmUiHandlingImpl::CreateLaunchParamL(
       
  3892     const HBufC* aUrl,
       
  3893     HBufC*& aLaunchParam )
       
  3894     {
       
  3895     __ASSERT_DEBUG( !aLaunchParam && aUrl,
       
  3896         User::Panic( KDRMUtilityDebugPanicMessage,
       
  3897             KDRMUtilityDebugPanicCode ) );
       
  3898     _LIT( KZero, "0" );
       
  3899     _LIT( KSpace, " " );
       
  3900 
       
  3901     TPtr ptr( NULL, 0 );
       
  3902 
       
  3903     // Length of startparam and drm protection scheme and zero local id
       
  3904     // are always 1 and total of 3 spaces are needed
       
  3905     TInt length( 1 + aUrl->Length() + 1 + 3 + 1 );
       
  3906 
       
  3907     aLaunchParam = HBufC::NewLC( length );
       
  3908     ptr.Set( aLaunchParam->Des() );
       
  3909 
       
  3910     // Start parameter is 3 or 4 for launching details view embedded or standalone from
       
  3911     // DRM Utility, respectively, with full path name included as a parameter. Values 1
       
  3912     // and 2 are for launching details view from DRM Helper.
       
  3913     if ( iCoeEnv )
       
  3914         {
       
  3915         ptr.AppendNum( EDrmLaunchParamEmbeddedUtility );
       
  3916         }
       
  3917     else
       
  3918         {
       
  3919         ptr.AppendNum( EDrmLaunchParamStandAloneUtility );
       
  3920         }
       
  3921     ptr.Append( KSpace );
       
  3922     // Default value 0 for localId in case of WM DRM file
       
  3923     ptr.Append( KZero );
       
  3924     ptr.Append( KSpace );
       
  3925     ptr.Append( *aUrl );
       
  3926     ptr.Append( KSpace );
       
  3927     // WM DRM protection scheme
       
  3928     ptr.AppendNum( EDrmSchemeWmDrm );
       
  3929 
       
  3930     CleanupStack::Pop( aLaunchParam );
       
  3931     }
       
  3932 
       
  3933 // -----------------------------------------------------------------------------
       
  3934 // CDrmUiHandlingImpl::LaunchBrowserL
       
  3935 // Launches browser embedded with given URL
       
  3936 // -----------------------------------------------------------------------------
       
  3937 //
       
  3938 TBool DRM::CDrmUiHandlingImpl::LaunchBrowserL( const HBufC8* aUrl )
       
  3939     {
       
  3940     __ASSERT_DEBUG( aUrl, User::Panic( KDRMUtilityDebugPanicMessage,
       
  3941             KDRMUtilityDebugPanicCode ) );
       
  3942 
       
  3943     // URL needs to be unicode
       
  3944     HBufC* parameters( HBufC::NewLC( aUrl->Length() ) );
       
  3945     parameters->Des().Copy( *aUrl );
       
  3946     TBool embeddedLaunch( LaunchBrowserL( parameters ) );
       
  3947     CleanupStack::PopAndDestroy( parameters );
       
  3948     return embeddedLaunch;
       
  3949     }
       
  3950 
       
  3951 // -----------------------------------------------------------------------------
       
  3952 // CDrmUiHandlingImpl::LaunchBrowserL
       
  3953 // Launches browser embedded with given URL
       
  3954 // -----------------------------------------------------------------------------
       
  3955 //
       
  3956 TBool DRM::CDrmUiHandlingImpl::LaunchBrowserL( const HBufC* aUrl )
       
  3957     {
       
  3958     __ASSERT_DEBUG( aUrl, User::Panic( KDRMUtilityDebugPanicMessage,
       
  3959             KDRMUtilityDebugPanicCode ) );
       
  3960 
       
  3961     HBufC* newUrl( NULL );
       
  3962     TPtrC ptrc( NULL, 0 );
       
  3963 
       
  3964     ptrc.Set( *aUrl );
       
  3965     TBool embeddedLaunch( EFalse );
       
  3966     // if no scheme exists, use http as default scheme
       
  3967     _LIT( KColon, ":" );
       
  3968     if ( ptrc.Find( KColon ) == KErrNotFound )
       
  3969         {
       
  3970         _LIT( KHttp, "http://" );
       
  3971         const TInt KHttpLen( 7 );
       
  3972         newUrl = HBufC::NewLC( KHttpLen + aUrl->Length() );
       
  3973         TPtr ptr( newUrl->Des() );
       
  3974         ptr.Append( KHttp );
       
  3975         ptr.Append( *aUrl );
       
  3976         ptrc.Set( *newUrl );
       
  3977         }
       
  3978 
       
  3979     CSchemeHandler* schemeHandler( CSchemeHandler::NewL( ptrc ) );
       
  3980     CleanupStack::PushL( schemeHandler );
       
  3981     if ( iCoeEnv )
       
  3982         {
       
  3983         embeddedLaunch = ETrue;
       
  3984         // launch embedded
       
  3985         schemeHandler->Observer( this );
       
  3986         schemeHandler->HandleUrlEmbeddedL();
       
  3987         CleanupStack::Pop( schemeHandler );
       
  3988         iSchemeHandler = schemeHandler;
       
  3989         iWait.Start();
       
  3990         }
       
  3991     else
       
  3992         {
       
  3993         // no CoeEnv, launch standalone with scheme app
       
  3994         schemeHandler->HandleUrlStandaloneL();
       
  3995         CleanupStack::PopAndDestroy( schemeHandler );
       
  3996         }
       
  3997     schemeHandler = NULL;
       
  3998 
       
  3999     // delete newUrl if needed
       
  4000     if ( newUrl )
       
  4001         {
       
  4002         CleanupStack::PopAndDestroy( newUrl );
       
  4003         }
       
  4004     return embeddedLaunch;
       
  4005     }
       
  4006 
       
  4007 // -----------------------------------------------------------------------------
       
  4008 // CDrmUiHandlingImpl::GetSilentRightsL
       
  4009 // -----------------------------------------------------------------------------
       
  4010 //
       
  4011 TInt DRM::CDrmUiHandlingImpl::GetSilentRightsL(
       
  4012     const TDesC8& aUrl,
       
  4013     const TBool aShowNotes )
       
  4014     {
       
  4015     TInt r( KErrCancel );
       
  4016     TInt buttonCode( EAknSoftkeyYes );
       
  4017     HBufC8* url( NULL );
       
  4018 
       
  4019     if ( !SilentRightsAllowedL() )
       
  4020         {
       
  4021         buttonCode = EAknSoftkeyNo;
       
  4022         if ( aShowNotes )
       
  4023             {
       
  4024             buttonCode = iDrmUtilityUi->DisplayQueryWithIdL(
       
  4025                 R_DRM_QRY_CONNECT_TO_ACTIVATE,
       
  4026                 R_DRMUTILITY_CONFIRMATION_QUERY );
       
  4027             }
       
  4028         }
       
  4029     else if ( !BrowserAPDefinedL() )
       
  4030         {
       
  4031         buttonCode = EAknSoftkeyNo;
       
  4032         if ( aShowNotes )
       
  4033             {
       
  4034             buttonCode = iDrmUtilityUi->DisplayQueryWithIdL(
       
  4035                 R_DRM_QRY_CONNECT_TO_ACTIVATE,
       
  4036                 R_DRMUTILITY_CONFIRMATION_QUERY );
       
  4037             }
       
  4038         }
       
  4039 
       
  4040     if ( buttonCode == EAknSoftkeyYes || buttonCode == EAknSoftkeyOk )
       
  4041         {
       
  4042         TInt APs( APCountL() );
       
  4043         if ( !APs )
       
  4044             {
       
  4045             // No AP defined
       
  4046             if ( aShowNotes )
       
  4047                 {
       
  4048                 iDrmUtilityUi->DisplayNoteL( R_DRM_WARN_NO_CONN_DEFINED );
       
  4049                 }
       
  4050             r = KErrCANoRights;
       
  4051             }
       
  4052         else
       
  4053             {
       
  4054             // ok to start download
       
  4055             CDrmUtilityDownloadManager* dlMgr(
       
  4056                 CDrmUtilityDownloadManager::NewL() );
       
  4057             CleanupStack::PushL( dlMgr );
       
  4058             url = aUrl.AllocLC();
       
  4059 
       
  4060             if ( iCoeEnv && aShowNotes )
       
  4061                 {
       
  4062                     TRAP( r, dlMgr->DownloadAndHandleRoapTriggerL( url,
       
  4063                             *iCoeEnv ) );
       
  4064                 }
       
  4065             else
       
  4066                 {
       
  4067                     TRAP( r, dlMgr->DownloadAndHandleRoapTriggerL( url ) );
       
  4068                 }
       
  4069             CleanupStack::PopAndDestroy( url );
       
  4070 
       
  4071             if ( r )
       
  4072                 {
       
  4073                 // rights were tried to get only if
       
  4074                 // the user hasn't cancelled
       
  4075                 if ( r != KErrCancel )
       
  4076                     {
       
  4077                     if ( r == KErrCouldNotConnect )
       
  4078                         {
       
  4079                         // Connection failed with selected AP
       
  4080                         if ( aShowNotes )
       
  4081                             {
       
  4082                             iDrmUtilityUi->DisplayNoteL(
       
  4083                                 R_DRM_WARN_INVALID_OR_NO_AP );
       
  4084                             }
       
  4085                         r = KErrCANoRights;
       
  4086                         }
       
  4087                     else
       
  4088                         {
       
  4089                         if ( aShowNotes )
       
  4090                             {
       
  4091                             // get error url
       
  4092                             HBufC8* errorUrl( dlMgr->GetErrorUrlL() );
       
  4093                             CleanupStack::PushL( errorUrl );
       
  4094 
       
  4095                             // error url is got only if temporary roap error
       
  4096 
       
  4097                             if ( errorUrl )
       
  4098                                 {
       
  4099                                 // ask user whether error url should be opened
       
  4100                                 buttonCode
       
  4101                                     = iDrmUtilityUi->DisplayQueryWithIdL(
       
  4102                                         R_DRM_QUERY_OPEN_ERROR_URL,
       
  4103                                         R_DRMUTILITY_CONFIRMATION_QUERY );
       
  4104 
       
  4105                                 if ( buttonCode == EAknSoftkeyYes
       
  4106                                     || buttonCode == EAknSoftkeyOk )
       
  4107                                     {
       
  4108                                     // Launch browser
       
  4109                                     LaunchBrowserL( errorUrl );
       
  4110                                     }
       
  4111                                 }
       
  4112                             else
       
  4113                                 {
       
  4114                                 iDrmUtilityUi->DisplayNoteL(
       
  4115                                     R_DRM_ERR_OPENING_FAIL_PERM );
       
  4116                                 }
       
  4117                             CleanupStack::PopAndDestroy( errorUrl );
       
  4118                             }
       
  4119                         }
       
  4120                     }
       
  4121                 }
       
  4122             CleanupStack::PopAndDestroy( dlMgr );
       
  4123             }
       
  4124         }
       
  4125     return r;
       
  4126     }
       
  4127 
       
  4128 // -----------------------------------------------------------------------------
       
  4129 // CDrmUiHandlingImpl::SilentRightsAllowedL
       
  4130 // -----------------------------------------------------------------------------
       
  4131 //
       
  4132 TBool DRM::CDrmUiHandlingImpl::SilentRightsAllowedL()
       
  4133     {
       
  4134     TInt value( KErrNone );
       
  4135     CRepository* repository( CRepository::NewL( KCRUidDRMSettings ) );
       
  4136     repository->Get( KDRMSettingsSilentRightsAcquisition, value );
       
  4137     delete repository;
       
  4138     return !value ? EFalse : ETrue;
       
  4139     }
       
  4140 
       
  4141 // -----------------------------------------------------------------------------
       
  4142 // CDrmUiHandlingImpl::BrowserAPDefinedL
       
  4143 // -----------------------------------------------------------------------------
       
  4144 //
       
  4145 TBool DRM::CDrmUiHandlingImpl::BrowserAPDefinedL()
       
  4146     {
       
  4147     const TInt KDestinationSelectionMode( 2 );
       
  4148     TInt err( KErrNone );
       
  4149     TInt ap( 0 );
       
  4150     TInt alwaysAsk( 0 );
       
  4151     TInt defaultSnap( 0 );
       
  4152 
       
  4153     CRepository* repository( CRepository::NewL( KCRUidBrowser ) );
       
  4154     repository->Get( KBrowserDefaultAccessPoint, ap );
       
  4155     repository->Get( KBrowserAccessPointSelectionMode, alwaysAsk );
       
  4156     repository->Get( KBrowserNGDefaultSnapId, defaultSnap );
       
  4157     delete repository;
       
  4158     if ( ap <= KErrNotFound && defaultSnap <= KErrNotFound )
       
  4159         {
       
  4160         alwaysAsk = ETrue;
       
  4161         }
       
  4162     else
       
  4163         {
       
  4164         RCmManager cmManager;
       
  4165         CleanupClosePushL( cmManager );
       
  4166         cmManager.OpenL();
       
  4167         if ( !alwaysAsk )
       
  4168             {
       
  4169                 TRAP( err, cmManager.GetConnectionMethodInfoIntL(
       
  4170                         ap, CMManager::ECmIapId ) );
       
  4171             }
       
  4172         else if ( alwaysAsk == KDestinationSelectionMode )
       
  4173             {
       
  4174                 TRAP( err, IapIdOfDefaultSnapL( cmManager, defaultSnap ) );
       
  4175             }
       
  4176         CleanupStack::PopAndDestroy( &cmManager );
       
  4177         if ( !err && ( !alwaysAsk || alwaysAsk == KDestinationSelectionMode ) )
       
  4178             {
       
  4179             return ETrue;
       
  4180             }
       
  4181         }
       
  4182     return EFalse;
       
  4183     }
       
  4184 
       
  4185 // -----------------------------------------------------------------------------
       
  4186 // CDrmUiHandlingImpl::APCountL
       
  4187 // -----------------------------------------------------------------------------
       
  4188 //
       
  4189 TInt DRM::CDrmUiHandlingImpl::APCountL()
       
  4190     {
       
  4191     TInt apCount( 0 );
       
  4192     RCmManager cmManager;
       
  4193     CleanupClosePushL( cmManager );
       
  4194     cmManager.OpenL();
       
  4195     RArray<TUint32> aps;
       
  4196     CleanupClosePushL( aps );
       
  4197     cmManager.ConnectionMethodL( aps, EFalse, EFalse, ETrue );
       
  4198     apCount = aps.Count();
       
  4199     CleanupStack::PopAndDestroy( 2, &cmManager ); //aps, cmManager
       
  4200     return apCount;
       
  4201     }
       
  4202 
       
  4203 // -----------------------------------------------------------------------------
       
  4204 // CDrmUiHandlingImpl::HandleServerAppExit
       
  4205 // -----------------------------------------------------------------------------
       
  4206 //
       
  4207 void DRM::CDrmUiHandlingImpl::HandleServerAppExit( TInt aReason )
       
  4208     {
       
  4209     if ( aReason == EAknCmdExit && !iSchemeHandler )
       
  4210         {
       
  4211         CAknEnv::RunAppShutter();
       
  4212         }
       
  4213 
       
  4214     if ( iSchemeHandler )
       
  4215         {
       
  4216         delete iSchemeHandler;
       
  4217         iSchemeHandler = NULL;
       
  4218         }
       
  4219 
       
  4220     if ( iWait.IsStarted() )
       
  4221         {
       
  4222         iWait.AsyncStop();
       
  4223         }
       
  4224     }
       
  4225 
       
  4226 // -----------------------------------------------------------------------------
       
  4227 // CDrmUiHandlingImpl::AppendToQueue
       
  4228 // -----------------------------------------------------------------------------
       
  4229 //
       
  4230 void DRM::CDrmUiHandlingImpl::AppendToQueue( DRM::CDrmUiHandlingData* aData )
       
  4231     {
       
  4232     __ASSERT_DEBUG( aData, User::Panic( KDRMUtilityDebugPanicMessage,
       
  4233             KDRMUtilityDebugPanicCode ) );
       
  4234 
       
  4235     // Critical area start:
       
  4236     iSemaphore.Wait();
       
  4237 
       
  4238     if ( !iLast )
       
  4239         {
       
  4240         iFirst = aData;
       
  4241         iLast = iFirst;
       
  4242         }
       
  4243     else
       
  4244         {
       
  4245         iLast->iNext = aData;
       
  4246         iLast = aData;
       
  4247         }
       
  4248 
       
  4249     // Critical area end
       
  4250     iSemaphore.Signal();
       
  4251     }
       
  4252 
       
  4253 // -----------------------------------------------------------------------------
       
  4254 // CDrmUiHandlingImpl::PopFront
       
  4255 // -----------------------------------------------------------------------------
       
  4256 //
       
  4257 DRM::CDrmUiHandlingData* DRM::CDrmUiHandlingImpl::PopFront()
       
  4258     {
       
  4259     DRM::CDrmUiHandlingData* data( NULL );
       
  4260 
       
  4261     // If there is nothing in the queue return NULL
       
  4262     if ( !iFirst )
       
  4263         {
       
  4264         return data;
       
  4265         }
       
  4266 
       
  4267     // Critical area start:
       
  4268     iSemaphore.Wait();
       
  4269 
       
  4270     data = iFirst;
       
  4271 
       
  4272     // Set the first and the next
       
  4273     iFirst = iFirst->iNext;
       
  4274 
       
  4275     // reset the pointer on data
       
  4276     data->iNext = NULL;
       
  4277 
       
  4278     // if there is no next in iFirst, this is the last or if there is no iFirst
       
  4279     if ( !iFirst || !iFirst->iNext )
       
  4280         {
       
  4281         iLast = iFirst;
       
  4282         }
       
  4283 
       
  4284     // Critical Area End
       
  4285     iSemaphore.Signal();
       
  4286 
       
  4287     return data;
       
  4288     }
       
  4289 
       
  4290 // -----------------------------------------------------------------------------
       
  4291 // CDrmUiHandlingImpl::GetSilentAndCallL
       
  4292 // -----------------------------------------------------------------------------
       
  4293 //
       
  4294 TBool DRM::CDrmUiHandlingImpl::GetSilentAndCallL(
       
  4295     MDrmHandleErrorObserver* aObserver,
       
  4296     TInt aOperationId,
       
  4297     const ContentAccess::TIntent aIntent,
       
  4298     const HBufC8* aContentUri,
       
  4299     const HBufC8* aSilentUrl,
       
  4300     const TBool aShowNotes )
       
  4301     {
       
  4302     TInt callError( KErrNotFound );
       
  4303     if ( aSilentUrl )
       
  4304         {
       
  4305         GetSilentRightsL( *aSilentUrl, aShowNotes );
       
  4306         callError
       
  4307             = CheckAndMapToCallError( iOmaClient, aIntent, *aContentUri );
       
  4308         CallSilentRightsAvailable( aObserver, aOperationId, callError );
       
  4309         }
       
  4310     return callError == KErrNone;
       
  4311     }
       
  4312 
       
  4313 // -----------------------------------------------------------------------------
       
  4314 // CDrmUiHandlingImpl::GetRightsAndCallL
       
  4315 // -----------------------------------------------------------------------------
       
  4316 //
       
  4317 void DRM::CDrmUiHandlingImpl::GetRightsAndCallL(
       
  4318     MDrmHandleErrorObserver* aObserver,
       
  4319     TInt aOperationId,
       
  4320     const ContentAccess::TIntent aIntent,
       
  4321     const HBufC8* aContentUri,
       
  4322     const HBufC* aRightsUrl )
       
  4323     {
       
  4324     TInt callError( KErrNotFound );
       
  4325     TBool embeddedLaunch( EFalse );
       
  4326     if ( aRightsUrl && LaunchBrowserL( aRightsUrl ) )
       
  4327         {
       
  4328         embeddedLaunch = ETrue;
       
  4329         // Browser launched in embedded mode.
       
  4330         // Check if rights exist now.
       
  4331         callError
       
  4332             = CheckAndMapToCallError( iOmaClient, aIntent, *aContentUri );
       
  4333         }
       
  4334     // Inform status to observer if possible
       
  4335     if ( embeddedLaunch || !aRightsUrl )
       
  4336         {
       
  4337         CallRightsAvailable( aObserver, aOperationId, callError );
       
  4338         }
       
  4339 
       
  4340     }
       
  4341 //  End of File