commondrm/drmutility/src/drmutilitywmdrmwrapper.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:  WM Drm wrapper implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 // launching embedded details view
       
    22 #include <aknlaunchappservice.h>
       
    23 #include <aiwgenericparam.h>
       
    24 #include <apgcli.h>
       
    25 #include <apgtask.h>
       
    26 #include <w32std.h>
       
    27 
       
    28 // character conversions
       
    29 #include <utf.h>
       
    30 #include <f32file.h>
       
    31 #include <avkon.hrh>
       
    32 
       
    33 // access point utils
       
    34 #include <centralrepository.h>
       
    35 #include <cdblen.h>
       
    36 #include <cmconnectionmethod.h>
       
    37 #include <cmdestination.h>
       
    38 #include <cmconnectionmethoddef.h>
       
    39 #include <cmmanager.h>
       
    40 #ifdef __SERIES60_NATIVE_BROWSER
       
    41 #include <browseruisdkcrkeys.h>
       
    42 #endif
       
    43 
       
    44 #include    <wmdrmagent.h> // for WMDRM file details view
       
    45 #include    <drmutilitytypes.h>
       
    46 #include    <drmuicheckrightsobserver.h>
       
    47 
       
    48 // resources
       
    49 #include    <drmutility.rsg>
       
    50 
       
    51 #include    "drmutilitywmdrmwrapper.h"
       
    52 #include    "drmutilityui.h"
       
    53 
       
    54 #include    "drmagents.h"
       
    55 #include    "drmclockclient.h"
       
    56 
       
    57 #include    "drmutilityinternaltypes.h"
       
    58 #include    "drmutilitywmdrmutilities.h"
       
    59 
       
    60 #include    "wmdrmdlawrapper.h"
       
    61 
       
    62 // CONSTANTS
       
    63 const TInt KMaxUrlLength( 1024 );
       
    64 const TInt KMaxUrlSanityLength( 102400 );
       
    65 
       
    66 #ifndef __SERIES60_NATIVE_BROWSER
       
    67 const TUid KCRUidBrowser = {0x10008D39};
       
    68 const TUint32 KBrowserDefaultAccessPoint = 0x0000000E;
       
    69 const TUint32 KBrowserAccessPointSelectionMode = 0x0000001E;
       
    70 #endif
       
    71 
       
    72 #ifdef _DEBUG
       
    73 // debug panic
       
    74 _LIT( KWmDrmWrapperDebugPanicMessage, "WmDrmWrapperDebugPanic" );
       
    75 const TInt KWmDrmWrapperDebugPanicCode( 1 );
       
    76 #endif
       
    77 
       
    78 // ============================ MEMBER FUNCTIONS ===============================
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CDrmUtilityWMDrmWrapper::CDrmUtilityWMDrmWrapper
       
    82 // C++ default constructor can NOT contain any code, that
       
    83 // might leave.
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 DRM::CDrmUtilityWMDrmWrapper::CDrmUtilityWMDrmWrapper() :
       
    87     iCoeEnv( NULL ),
       
    88     iDrmUtilityUi( NULL )
       
    89     {
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CDrmUtilityWMDrmWrapper::ConstructL
       
    94 // Symbian 2nd phase constructor can leave.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void DRM::CDrmUtilityWMDrmWrapper::ConstructL()
       
    98     {
       
    99     User::LeaveIfError( iFs.Connect() );
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CDrmUtilityWMDrmWrapper::NewL
       
   104 // Two-phased constructor.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C DRM::CDrmUtilityWMDrmWrapper* DRM::CDrmUtilityWMDrmWrapper::NewL()
       
   108     {
       
   109     DRM::CDrmUtilityWMDrmWrapper* self( NewLC() );
       
   110 
       
   111     CleanupStack::Pop( self );
       
   112 
       
   113     return self;
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CDrmUtilityWMDrmWrapper::NewLC
       
   119 // Two-phased constructor.
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 EXPORT_C DRM::CDrmUtilityWMDrmWrapper* DRM::CDrmUtilityWMDrmWrapper::NewLC()
       
   123     {
       
   124     DRM::CDrmUtilityWMDrmWrapper* self( new( ELeave ) CDrmUtilityWMDrmWrapper );
       
   125 
       
   126     CleanupStack::PushL( self );
       
   127     self->ConstructL();
       
   128 
       
   129     return self;
       
   130     }
       
   131 
       
   132 
       
   133 // Destructor
       
   134 DRM::CDrmUtilityWMDrmWrapper::~CDrmUtilityWMDrmWrapper()
       
   135     {
       
   136     delete iDrmUtilityUi;
       
   137     delete iDlaWrapper;
       
   138     iDlaWrapperDll.Close();
       
   139     iFs.Close();
       
   140     }
       
   141 
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CDrmUtilityWMDrmWrapper::CheckWmRightsAmountL()
       
   145 // Syncronous method
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 
       
   149 EXPORT_C void DRM::CDrmUtilityWMDrmWrapper::CheckWmRightsAmountL(
       
   150     ContentAccess::CData& aContent,
       
   151     ContentAccess::TIntent aIntent,
       
   152     DRM::MDrmUiCheckRightsObserver* aObserver,
       
   153     TInt aOperationId )
       
   154     {
       
   155     TInt value( EFalse );
       
   156     HBufC* contentId( HBufC::NewLC( KMaxUrlLength ) ); // 1024
       
   157     TPtr cid( contentId->Des() );
       
   158     TBool unlimited( EFalse );
       
   159     TInt32 reason( 0 );
       
   160     TInt counts( 0 );
       
   161     TTimeIntervalSeconds time( 0 );
       
   162     TTimeIntervalSeconds accumulated( 0 );
       
   163     TInt error( KErrNone );
       
   164 
       
   165     // Check intent:
       
   166     switch( aIntent )
       
   167         {
       
   168         case ContentAccess::EPlay:
       
   169         case ContentAccess::EView:
       
   170 
       
   171             break;
       
   172 
       
   173         default:
       
   174 
       
   175             // Intent not supported, leave with argument:
       
   176             User::Leave( KErrArgument );
       
   177 
       
   178             break;
       
   179         }
       
   180 
       
   181 
       
   182     // Ask the rights from CAF, same call for both ECanPlay and ECanView
       
   183     User::LeaveIfError( aContent.GetAttribute( ContentAccess::ECanPlay, value ) );
       
   184 
       
   185     // Loop needed to make sure the full path name fits to the cid.
       
   186     // If the size is not enough, increase it in steps of one kB.
       
   187     while ( ( error = aContent.GetStringAttribute( DRM::EDrmFullName, cid ) )
       
   188         == KErrOverflow )
       
   189         {
       
   190         if ( contentId->Size() + KMaxUrlLength > KMaxUrlSanityLength )
       
   191             {
       
   192             // Cid is so big that it can not fit to the 100 kB default max buffer.
       
   193             User::Leave( error );
       
   194             }
       
   195         CleanupStack::Pop( contentId );
       
   196         contentId->ReAllocL( contentId->Size() + KMaxUrlLength );
       
   197         cid.Set( contentId->Des() );
       
   198         CleanupStack::PushL( contentId );
       
   199         }
       
   200 
       
   201     if ( error )
       
   202         {
       
   203         User::Leave( error );
       
   204         }
       
   205 
       
   206     // Object can be played and rights are in order:
       
   207     if ( value )
       
   208         {
       
   209         // Get the rights data
       
   210         GetRightsDataL(
       
   211             cid,
       
   212             unlimited,
       
   213             time,
       
   214             counts,
       
   215             accumulated );
       
   216 
       
   217         // call given CheckRightsObserver
       
   218         // What kind of rights are available:
       
   219         CallRightsLeftL (
       
   220             aObserver,
       
   221             aOperationId,
       
   222             unlimited,
       
   223             time,
       
   224             counts,
       
   225             accumulated,
       
   226             aContent,
       
   227             cid );
       
   228         }
       
   229     else // The rights are not valid at this point always claim they have expired
       
   230         {
       
   231         CallRightsNotValidL(
       
   232             aObserver,
       
   233             aOperationId,
       
   234             EUHCheckRightsExpiredRights,
       
   235             reason,
       
   236             aContent,
       
   237             cid );
       
   238         }
       
   239 
       
   240     CleanupStack::PopAndDestroy( contentId );
       
   241     }
       
   242 
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CDrmUtilityWMDrmWrapper::HandleWmErrorL()
       
   246 // Syncronous method
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 
       
   250 EXPORT_C void DRM::CDrmUtilityWMDrmWrapper::HandleWmErrorL(
       
   251     ContentAccess::CData& aContent,
       
   252     ContentAccess::TIntent /* aIntent */,
       
   253     TInt /* aError */,
       
   254     DRM::MDrmHandleErrorObserver* aObserver,
       
   255     TInt aOperationId )
       
   256     {
       
   257 
       
   258     TInt32 reason( 0 );
       
   259     TInt value( EFalse );
       
   260     HBufC* contentId( HBufC::NewLC( KMaxUrlLength ) ); // 1024
       
   261     TPtr cid( contentId->Des() );
       
   262 
       
   263     // Check Content Id via CAF
       
   264     User::LeaveIfError( aContent.GetStringAttribute( ContentAccess::EContentId, cid ) );
       
   265 
       
   266     // Ask the rights from CAF, same call for both ECanPlay and ECanView
       
   267     User::LeaveIfError( aContent.GetAttribute( ContentAccess::ECanPlay, value ) );
       
   268 
       
   269     if ( !value )
       
   270         {
       
   271         ShowNoRightsNoteL( aContent, reason );
       
   272         User::LeaveIfError( aContent.GetAttribute( ContentAccess::ECanPlay, value ) );
       
   273         if ( value )
       
   274             {
       
   275             CallRightsAvailable( aObserver, aOperationId, KErrNone );
       
   276             }
       
   277         else
       
   278             {
       
   279             CallRightsAvailable( aObserver, aOperationId, KErrCANoRights );
       
   280             }
       
   281         }
       
   282     else
       
   283         {
       
   284         User::Leave( KErrArgument );
       
   285         }
       
   286 
       
   287     CleanupStack::PopAndDestroy( contentId );
       
   288     }
       
   289 
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CDrmUtilityWMDrmWrapper::SetCoeEnv()
       
   293 // Syncronous method
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 EXPORT_C void DRM::CDrmUtilityWMDrmWrapper::SetCoeEnv( CCoeEnv* aCoeEnv )
       
   297     {
       
   298     iCoeEnv = aCoeEnv;
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CDrmUtilityWMDrmWrapper::GetRightsManagerL
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 ContentAccess::CRightsManager* DRM::CDrmUtilityWMDrmWrapper::GetRightsManagerL()
       
   306     {
       
   307     ContentAccess::CManager* manager( NULL );
       
   308     ContentAccess::CRightsManager* rightsManager( NULL );
       
   309     RArray<ContentAccess::TAgent> agents;
       
   310     TInt agent( 0 );
       
   311 
       
   312     CleanupClosePushL( agents );
       
   313     manager = ContentAccess::CManager::NewLC();
       
   314 
       
   315     manager->ListAgentsL( agents );
       
   316 
       
   317     for ( agent = 0; agent < agents.Count(); agent++ )
       
   318         {
       
   319         if (agents[agent].Name().Compare( KWmDrmAgentName ) == 0)
       
   320             {
       
   321             break;
       
   322             }
       
   323         }
       
   324 
       
   325     // If no WM DRM agent is found, leave
       
   326     if( agent >= agents.Count() )
       
   327         {
       
   328         User::Leave( KErrNotSupported );
       
   329         }
       
   330 
       
   331 
       
   332     // Create a CRightsManager for the agent found
       
   333     rightsManager = manager->CreateRightsManagerL( agents[agent] );
       
   334 
       
   335     CleanupStack::PopAndDestroy( manager ); // manager
       
   336     CleanupStack::PopAndDestroy( &agents ); // agents
       
   337     return rightsManager;
       
   338     }
       
   339 
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CDrmUtilityWMDrmWrapper::GetRightsDataL
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void DRM::CDrmUtilityWMDrmWrapper::GetRightsDataL(
       
   346     const TDesC& aUniqueId,
       
   347     TBool& aUnconstrained,
       
   348     TTimeIntervalSeconds& aTime,
       
   349     TInt& aCounts,
       
   350     TTimeIntervalSeconds& aAccumulated )
       
   351     {
       
   352     ContentAccess::RStreamablePtrArray<ContentAccess::CRightsInfo> aArray;
       
   353     ContentAccess::CRightsManager* manager( NULL );
       
   354     CleanupClosePushL(aArray);
       
   355 
       
   356     aUnconstrained = EFalse;
       
   357     aTime = 0;
       
   358     aCounts = 0;
       
   359     aAccumulated = 0;
       
   360 
       
   361     // Create the manager:
       
   362     manager = GetRightsManagerL();
       
   363     CleanupStack::PushL( manager );
       
   364 
       
   365     // Get the list of rights:
       
   366     manager->ListRightsL( aArray, aUniqueId );
       
   367 
       
   368     // Evaluate the rights:
       
   369     if( aArray.Count() )
       
   370         {
       
   371         for ( TInt i( 0 ); i < aArray.Count(); i++ )
       
   372             {
       
   373             switch( aArray[i]->RightsStatus() )
       
   374                 {
       
   375                 // All of these the rights don't exist or are expired:
       
   376                 case ContentAccess::ERightsStatusNone:
       
   377                 case ContentAccess::ERightsStatusExpired:
       
   378                 case ContentAccess::ERightsStatusPending:
       
   379 
       
   380                     break;
       
   381 
       
   382                 // the rights are valid:
       
   383                 // Check the duration, counts and whether the rights
       
   384                 // are unlimited or not
       
   385                 case ContentAccess::ERightsStatusValid:
       
   386                     DrmUtilityWmDrmUtilities::CheckWmDrmRightsL( 
       
   387                         aUnconstrained, aTime, aCounts, *aArray[0] );
       
   388                     break;
       
   389                 }
       
   390             }
       
   391         }
       
   392     else
       
   393         {
       
   394         User::Leave( KErrCANoRights );
       
   395         }
       
   396 
       
   397     CleanupStack::PopAndDestroy( manager );
       
   398     CleanupStack::PopAndDestroy( &aArray ); // aArray
       
   399     }
       
   400 
       
   401 
       
   402 // -----------------------------------------------------------------------------
       
   403 // CDrmUtilityWMDrmWrapper::CallRightsLeftL
       
   404 // -----------------------------------------------------------------------------
       
   405 //
       
   406 void DRM::CDrmUtilityWMDrmWrapper::CallRightsLeftL(
       
   407     DRM::MDrmUiCheckRightsObserver* aObserver,
       
   408     TInt aOperationId,
       
   409     TBool aUnconstrained,
       
   410     TTimeIntervalSeconds aTime,
       
   411     TInt aCounts,
       
   412     TTimeIntervalSeconds aAccumulated,
       
   413     ContentAccess::CData& aContent,
       
   414     const TDesC& aContentUri )
       
   415     {
       
   416     DRM::TCheckRightsAction rightsAction( DRM::EUHCheckRightsActionDefault );
       
   417 
       
   418     if ( aObserver )
       
   419         {
       
   420         rightsAction = aObserver->RightsLeft( aOperationId,
       
   421                                               aUnconstrained,
       
   422                                               aTime,
       
   423                                               aCounts,
       
   424                                               aAccumulated );
       
   425         }
       
   426 
       
   427     switch ( rightsAction )
       
   428         {
       
   429         case DRM::EUHCheckRightsActionDefault:
       
   430             {
       
   431             // show appropriate notes, none at the moment
       
   432             }
       
   433             break;
       
   434 
       
   435         case DRM::EUHCheckRightsActionOpenDetailsView:
       
   436             {
       
   437             // Commented out for now, should do details for WM DRM when supported
       
   438             // create parameter string
       
   439             HBufC* launchParam( NULL );
       
   440             CreateLaunchParamL( &aContentUri, launchParam ); // use zero as localid
       
   441             CleanupStack::PushL( launchParam );
       
   442 
       
   443             // show details
       
   444             LaunchRightsManagerUiL( *launchParam );
       
   445             CleanupStack::PopAndDestroy( launchParam );
       
   446             }
       
   447             break;
       
   448 
       
   449         case DRM::EUHCheckRightsActionAcquireNewRights:
       
   450             TRAPD( err, LoadDlaWrapperL() );
       
   451             if ( !err )
       
   452                 {
       
   453                 SilentDlaLicenseAcquisitionL( aContent );
       
   454                 }
       
   455             break;
       
   456 
       
   457         case DRM::EUHCheckRightsActionIgnore:
       
   458             // do nothing
       
   459             break;
       
   460 
       
   461         default:
       
   462             break;
       
   463         }
       
   464     }
       
   465 
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // CDrmUtilityWMDrmWrapper::CallRightsNotValidL
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 void DRM::CDrmUtilityWMDrmWrapper::CallRightsNotValidL(
       
   472     DRM::MDrmUiCheckRightsObserver* aObserver,
       
   473     TInt aOperationId,
       
   474     DRM::TCheckRightsStatus aRightsStatus,
       
   475     TUint32 aReason,
       
   476     ContentAccess::CData& aContent,
       
   477     const TDesC& aContentUri )
       
   478     {
       
   479     DRM::TCheckRightsAction rightsAction( DRM::EUHCheckRightsActionDefault );
       
   480 
       
   481     if ( aObserver )
       
   482         {
       
   483         // call given CheckRightsObserver
       
   484         rightsAction = aObserver->RightsNotValid( aOperationId,
       
   485                                                   aRightsStatus,
       
   486                                                   RejectReason( aReason ) );
       
   487         }
       
   488 
       
   489     //rightsAction = DRM::EUHCheckRightsActionDefault;
       
   490 
       
   491     switch ( rightsAction )
       
   492         {
       
   493         case DRM::EUHCheckRightsActionDefault:
       
   494             {
       
   495             ShowNoRightsNoteL( aContent, aReason );
       
   496             }
       
   497             break;
       
   498 
       
   499         case DRM::EUHCheckRightsActionOpenDetailsView:
       
   500             {
       
   501             // Commented out for now, should do details for WM DRM when supported
       
   502             // create parameter string
       
   503             HBufC* launchParam( NULL );
       
   504             CreateLaunchParamL( &aContentUri, launchParam ); // use zero as localid
       
   505             CleanupStack::PushL( launchParam );
       
   506 
       
   507             // show details
       
   508             LaunchRightsManagerUiL( *launchParam );
       
   509             CleanupStack::PopAndDestroy( launchParam );
       
   510             }
       
   511             break;
       
   512 
       
   513         case DRM::EUHCheckRightsActionAcquireNewRights:
       
   514             TRAPD( err, LoadDlaWrapperL() );
       
   515             if ( !err )
       
   516                 {
       
   517                 SilentDlaLicenseAcquisitionL( aContent );
       
   518                 }
       
   519             break;
       
   520 
       
   521         case DRM::EUHCheckRightsActionIgnore:
       
   522             // do nothing
       
   523             break;
       
   524 
       
   525         default:
       
   526             break;
       
   527         }
       
   528     }
       
   529 
       
   530 // -----------------------------------------------------------------------------
       
   531 // CDrmUtilityWMDrmWrapper::CallRightsAvailable
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 void DRM::CDrmUtilityWMDrmWrapper::CallRightsAvailable(
       
   535     DRM::MDrmHandleErrorObserver* aObserver,
       
   536     TInt aOperationId,
       
   537     TInt aError )
       
   538     {
       
   539 
       
   540     if ( aObserver )
       
   541         {
       
   542         // call given HandleErrorObserver
       
   543         aObserver->RightsAvailable( aOperationId, aError );
       
   544         }
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 // CDrmUtilityWMDrmWrapper::ShowNoRightsNoteL
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 void DRM::CDrmUtilityWMDrmWrapper::ShowNoRightsNoteL(
       
   552     ContentAccess::CData& aContent,
       
   553     TUint32 /*aReason*/ )
       
   554     {
       
   555     TRAPD( err, LoadDlaWrapperL() );
       
   556     if ( !err )
       
   557         {
       
   558         TInt ret( EAknSoftkeyYes );
       
   559         RFile file;
       
   560         GetRFileFromCDataL( aContent, file );
       
   561         CleanupClosePushL( file );
       
   562         TBool isSilent( EFalse );
       
   563         TRAP( err, isSilent = IsDlaLicenseAcquisitionSilentL( file ) );
       
   564         if ( !err && !isSilent )
       
   565             {
       
   566             if ( !iDrmUtilityUi )
       
   567                 {
       
   568                 iDrmUtilityUi = DRM::CDrmUtilityUI::NewL( iCoeEnv );
       
   569                 }
       
   570             TFileName fileName;
       
   571             User::LeaveIfError( aContent.GetStringAttribute( DRM::EDrmFileName, fileName ) );
       
   572             ret = iDrmUtilityUi->DisplayQueryL( R_DRM_QUERY_EXPIRED_OR_NO_RO, fileName );
       
   573             }
       
   574 
       
   575         if ( !err && ( ret == EAknSoftkeyYes || ret == EAknSoftkeyOk ) )
       
   576             {
       
   577             TRAP_IGNORE( DlaLicenseAcquisitionL( file ) );
       
   578             }
       
   579         CleanupStack::PopAndDestroy( &file );
       
   580         }
       
   581     else
       
   582         {
       
   583         if ( !iDrmUtilityUi )
       
   584             {
       
   585             iDrmUtilityUi = DRM::CDrmUtilityUI::NewL( iCoeEnv );
       
   586             }
       
   587         iDrmUtilityUi->DisplayNoteL( R_DRM_INFO_EXPIRED_OR_NO_RO );
       
   588         }
       
   589     }
       
   590 
       
   591 // -----------------------------------------------------------------------------
       
   592 // CDrmUtilityWMDrmWrapper::RejectReason
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 TInt DRM::CDrmUtilityWMDrmWrapper::RejectReason(
       
   596     TUint32 /* aReason */ )
       
   597     {
       
   598     TInt ret = DRM::EURejectionNone;
       
   599 
       
   600     return ret;
       
   601     }
       
   602 
       
   603 
       
   604 // -----------------------------------------------------------------------------
       
   605 // CDrmUtilityWMDrmWrapper::LaunchRightsManagerUiL
       
   606 // -----------------------------------------------------------------------------
       
   607 //
       
   608 void DRM::CDrmUtilityWMDrmWrapper::LaunchRightsManagerUiL(
       
   609     const TDesC& aParam16 )
       
   610     {
       
   611 
       
   612     const TUid KUidDRMUI = { 0x101f85c7 };
       
   613 
       
   614     if ( iCoeEnv )
       
   615         {
       
   616         CAiwGenericParamList* paramList( CAiwGenericParamList::NewLC() );
       
   617         TAiwVariant variantObject( aParam16 );
       
   618         TAiwGenericParam param( EGenericParamFile, variantObject );
       
   619         paramList->AppendL( param );
       
   620 
       
   621         CAknLaunchAppService* launchAppService(
       
   622                                     CAknLaunchAppService::NewL( KUidDRMUI,
       
   623                                                                 this,
       
   624                                                                 paramList ) );
       
   625         iWait.Start();
       
   626         delete launchAppService;
       
   627         CleanupStack::PopAndDestroy( paramList );
       
   628         }
       
   629     else
       
   630         {
       
   631         // no UI to embed, launch Rights Manager UI stand-alone
       
   632         // check if Rights Manager UI is already running
       
   633         RWsSession wsSession;
       
   634         User::LeaveIfError( wsSession.Connect() );
       
   635         CleanupClosePushL( wsSession );
       
   636         TApaTaskList tasklist( wsSession );
       
   637         TApaTask task( tasklist.FindApp( KUidDRMUI ) );
       
   638         if ( task.Exists() )
       
   639             {
       
   640             // Rights Manager UI is already running
       
   641             HBufC8* param8( HBufC8::NewLC( aParam16.Length() ) );
       
   642             TPtr8 parametersPtr( param8->Des() );
       
   643             parametersPtr.Copy( aParam16 );
       
   644             task.SendMessage( TUid::Uid( KUidApaMessageSwitchOpenFileValue ),
       
   645                                          *param8 );
       
   646             CleanupStack::PopAndDestroy( param8 );
       
   647             }
       
   648         else
       
   649             {
       
   650             RApaLsSession appArcSession;
       
   651             User::LeaveIfError( appArcSession.Connect() );
       
   652             TThreadId id;
       
   653             appArcSession.StartDocument( aParam16, KUidDRMUI, id );
       
   654             appArcSession.Close();
       
   655             }
       
   656         CleanupStack::PopAndDestroy( &wsSession );
       
   657         }
       
   658     }
       
   659 
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 // CDrmUtilityWMDrmWrapper::CreateLaunchParamL
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 void DRM::CDrmUtilityWMDrmWrapper::CreateLaunchParamL(
       
   666     const TDesC* aUrl,
       
   667     HBufC*& aLaunchParam )
       
   668     {
       
   669 
       
   670     __ASSERT_DEBUG( !aLaunchParam && aUrl,
       
   671                     User::Panic( KWmDrmWrapperDebugPanicMessage,
       
   672                                  KWmDrmWrapperDebugPanicCode ) );
       
   673 
       
   674     _LIT( KZero, "0" );
       
   675     _LIT( KSpace, " " );
       
   676 
       
   677     TPtr ptr( NULL, 0 );
       
   678 
       
   679     // length of startparam and drm protection type indicator and zero local id
       
   680     // are always 1 and total of 3 spaces are needed
       
   681     TInt length( 1 + aUrl->Length() + 1 + 3 + 1 );
       
   682 
       
   683     aLaunchParam = HBufC::NewLC( length );
       
   684     ptr.Set( aLaunchParam->Des() );
       
   685 
       
   686     // Start parameter is 3 or 4 for launching details view embedded or standalone from
       
   687     // DRM Utility, respectively, with full path name included as a parameter. Values 1
       
   688     // and 2 are for launching details view from DRM Helper.
       
   689     if ( iCoeEnv )
       
   690         {
       
   691         ptr.AppendNum( EDrmLaunchParamEmbeddedUtility );
       
   692         }
       
   693     else
       
   694         {
       
   695         ptr.AppendNum( EDrmLaunchParamStandAloneUtility );
       
   696         }
       
   697     ptr.Append( KSpace );
       
   698     // Default value 0 for localId in case of WM DRM file
       
   699     ptr.Append( KZero );
       
   700     ptr.Append( KSpace );
       
   701     ptr.Append( *aUrl );
       
   702     ptr.Append( KSpace );
       
   703     // WM DRM protection scheme
       
   704     ptr.AppendNum( EDrmSchemeWmDrm );
       
   705 
       
   706     CleanupStack::Pop( aLaunchParam );
       
   707     }
       
   708 
       
   709 // -----------------------------------------------------------------------------
       
   710 // CDrmUtilityWMDrmWrapper::HandleServerAppExit
       
   711 // -----------------------------------------------------------------------------
       
   712 //
       
   713 void DRM::CDrmUtilityWMDrmWrapper::HandleServerAppExit( TInt /*aReason*/ )
       
   714     {
       
   715     if ( iWait.IsStarted() )
       
   716         {
       
   717         iWait.AsyncStop();
       
   718         }
       
   719     }
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // CDrmUtilityWMDrmWrapper::LoadDlaWrapperL
       
   723 // -----------------------------------------------------------------------------
       
   724 //
       
   725 void DRM::CDrmUtilityWMDrmWrapper::LoadDlaWrapperL()
       
   726     {
       
   727     if ( !iDlaWrapper )
       
   728         {
       
   729         User::LeaveIfError( iDlaWrapperDll.Load( KWmDrmDlaWrapperName ) );
       
   730         iDlaWrapper = (CWmDrmDlaWrapper*)iDlaWrapperDll.Lookup( KWmDrmDlaNewL )();
       
   731         }
       
   732     }
       
   733 
       
   734 // -----------------------------------------------------------------------------
       
   735 // CDrmUtilityWMDrmWrapper::GetRFileFromCDataL
       
   736 // -----------------------------------------------------------------------------
       
   737 //
       
   738 void DRM::CDrmUtilityWMDrmWrapper::GetRFileFromCDataL( 
       
   739     ContentAccess::CData& aContent,
       
   740     RFile& aFile )
       
   741     {
       
   742     TFileName fileName;
       
   743     User::LeaveIfError( aContent.GetStringAttribute( DRM::EDrmFullName, fileName ) );
       
   744     User::LeaveIfError( aFile.Open( iFs, fileName, EFileRead | EFileShareReadersOnly ) );
       
   745     }
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 // CDrmUtilityWMDrmWrapper::IsDlaLicenseAcquisitionSilentL
       
   749 // -----------------------------------------------------------------------------
       
   750 //
       
   751 TBool DRM::CDrmUtilityWMDrmWrapper::IsDlaLicenseAcquisitionSilentL( 
       
   752     RFile& aFile  )
       
   753     {
       
   754     LoadDlaWrapperL();
       
   755     return iDlaWrapper->SilentL( aFile );
       
   756     }
       
   757 
       
   758 // -----------------------------------------------------------------------------
       
   759 // CDrmUtilityWMDrmWrapper::DlaLicenseAcquisitionL
       
   760 // -----------------------------------------------------------------------------
       
   761 //
       
   762 void DRM::CDrmUtilityWMDrmWrapper::DlaLicenseAcquisitionL( 
       
   763     RFile& aFile )
       
   764     {
       
   765     TInt iapId( 0 );
       
   766     HBufC* contentUrl( NULL );
       
   767     HBufC* htmlData( NULL );
       
   768     LoadDlaWrapperL();
       
   769     TRAPD( err, iapId = DefaultAccessPointL() );
       
   770     if ( !err )
       
   771         {
       
   772         iDlaWrapper->SetIapId( iapId );
       
   773         }
       
   774     iDlaWrapper->AcquireLicenseL( aFile, contentUrl, htmlData  );
       
   775     delete contentUrl;
       
   776     delete htmlData;
       
   777     }
       
   778 
       
   779 // -----------------------------------------------------------------------------
       
   780 // CDrmUtilityWMDrmWrapper::SilentDlaLicenseAcquisitionL
       
   781 // -----------------------------------------------------------------------------
       
   782 //
       
   783 void DRM::CDrmUtilityWMDrmWrapper::SilentDlaLicenseAcquisitionL(
       
   784     ContentAccess::CData& aContent )
       
   785     {
       
   786     RFile file;
       
   787     GetRFileFromCDataL( aContent, file );
       
   788     CleanupClosePushL( file );
       
   789     DlaLicenseAcquisitionL( file );
       
   790     CleanupStack::PopAndDestroy( &file );
       
   791     }
       
   792 
       
   793 // -----------------------------------------------------------------------------
       
   794 // CDrmUtilityWMDrmWrapper::DefaultAccessPointL
       
   795 // -----------------------------------------------------------------------------
       
   796 //
       
   797 TInt DRM::CDrmUtilityWMDrmWrapper::DefaultAccessPointL()
       
   798     {
       
   799     const TInt KDestinationSelectionMode( 2 );
       
   800     CRepository* repository( NULL );
       
   801     TInt ap( 0 );
       
   802     TInt alwaysAsk( 0 );
       
   803     TUint32 iapd32( 0 );
       
   804     TInt defaultSnap( 0 );
       
   805 
       
   806     repository = CRepository::NewL( KCRUidBrowser );
       
   807     CleanupStack::PushL( repository );
       
   808     repository->Get( KBrowserDefaultAccessPoint, ap );
       
   809     repository->Get( KBrowserAccessPointSelectionMode, alwaysAsk );
       
   810     repository->Get( KBrowserNGDefaultSnapId, defaultSnap );
       
   811     CleanupStack::PopAndDestroy( repository );
       
   812     
       
   813     if ( ap <= KErrNotFound && defaultSnap <= KErrNotFound )
       
   814         {
       
   815         alwaysAsk = ETrue;
       
   816         }
       
   817     else
       
   818         {
       
   819         RCmManager cmManager;
       
   820         cmManager.OpenLC();
       
   821         if ( !alwaysAsk )
       
   822             {
       
   823             iapd32 = 
       
   824                 cmManager.GetConnectionMethodInfoIntL( ap, 
       
   825                                                        CMManager::ECmIapId );
       
   826             }
       
   827         else if ( alwaysAsk == KDestinationSelectionMode )
       
   828             {
       
   829             RCmDestination dest( cmManager.DestinationL( defaultSnap ) );
       
   830             CleanupClosePushL( dest );
       
   831 
       
   832             if ( dest.ConnectionMethodCount() <= 0 )
       
   833                 {
       
   834                 User::Leave( KErrNotFound );
       
   835                 }
       
   836 
       
   837             RCmConnectionMethod cMeth( dest.ConnectionMethodL( 0 ) );
       
   838             CleanupClosePushL( cMeth );
       
   839 
       
   840             iapd32 = cMeth.GetIntAttributeL( CMManager::ECmIapId );
       
   841             CleanupStack::PopAndDestroy( 2, &dest ); //cMeth, dest
       
   842             }
       
   843         CleanupStack::PopAndDestroy( &cmManager );
       
   844         }
       
   845     if ( alwaysAsk && alwaysAsk != KDestinationSelectionMode )
       
   846         {
       
   847         User::Leave( KErrAccessDenied );
       
   848         }
       
   849     return iapd32;
       
   850     }
       
   851 
       
   852 //  End of File