omadrm/drmhelper/src/drmhelper.cpp
changeset 0 95b198f216e5
child 2 76350b5be3d8
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2003-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of CDRMHelper class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "DRMHelper.h"
       
    21 
       
    22 #include "DRMHelperGlobalNoteWrapper.h"
       
    23 #include "DRMHelperInfoNoteWrapper.h"
       
    24 #include "DRMRightsClient.h"
       
    25 #include "DcfCommon.h"
       
    26 #include "DRMHelperDownloadManager.h"
       
    27 
       
    28 #include <SaCls.h>
       
    29 #include <DRMHelper.rsg>
       
    30 #include <AknQueryDialog.h>
       
    31 #include <DRMCommon.h>
       
    32 
       
    33 #include <StarterClient.h>
       
    34 
       
    35 #ifdef RD_MULTIPLE_DRIVE
       
    36 #include <DriveInfo.h>
       
    37 #endif
       
    38 
       
    39 #include <StringLoader.h>
       
    40 #include <eikproc.h> //CEikProcess
       
    41 #include <eikdoc.h> //CEikDocument
       
    42 #include <documenthandler.h> // KDRMErr*
       
    43 #include <aknnotewrappers.h> // information note
       
    44 #include <aknglobalnote.h> // global info note
       
    45 
       
    46 #include <drmconstraint.h>
       
    47 
       
    48 #include <stringresourcereader.h>
       
    49 #include <apgcli.h>
       
    50 #include <data_caging_path_literals.hrh>
       
    51 
       
    52 #include <AiwGenericParam.h>
       
    53 #include <dcfrep.h>
       
    54 #include <DcfEntry.h>
       
    55 
       
    56 #include <caf/caf.h>
       
    57 
       
    58 #include <AknLaunchAppService.h> // for launching RMUI embedded
       
    59 
       
    60 #include <utf.h>
       
    61 
       
    62 #include <schemehandler.h> // for handling URLs
       
    63 #include "drmhelperserver.h"
       
    64 #include "consumedata.h"
       
    65 #include "drmtypes.h"
       
    66 #include "drmclockclient.h"
       
    67 #include "DRMPointerArray.h"
       
    68 
       
    69 #include <SecondaryDisplay/DRMHelperSecondaryDisplay.h> // for secondary display support
       
    70 #include <aknmediatorfacade.h>
       
    71 #include <mediatoreventprovider.h>
       
    72 #include <mediatordomainuids.h>
       
    73 #include <featmgr.h>
       
    74 
       
    75 #include "RoapStorageClient.h"
       
    76 
       
    77 #include <centralrepository.h>
       
    78 #include <e32property.h>
       
    79 #ifdef RD_DRM_SILENT_RIGHTS_ACQUISITION
       
    80 #include "drmsettingsplugininternalcrkeys.h"
       
    81 #endif
       
    82 #include "DRMRIContext.h"
       
    83 #include "DRMDomainContext.h"
       
    84 
       
    85 #include <cmconnectionmethod.h>
       
    86 #include <cmdestination.h>
       
    87 #include <cmconnectionmethoddef.h>
       
    88 #include <cmmanager.h>
       
    89 
       
    90 // publish & subrscibe
       
    91 #include <E32Property.h>
       
    92 #include <PsVariables.h>
       
    93 
       
    94 #ifdef __SERIES60_NATIVE_BROWSER
       
    95 #include <browseruisdkcrkeys.h>
       
    96 #endif
       
    97 
       
    98 #ifndef __SERIES60_NATIVE_BROWSER
       
    99 const TUid KCRUidBrowser   = {0x10008D39};
       
   100 const TUint32 KBrowserDefaultAccessPoint =  0x0000000E;
       
   101 const TUint32 KBrowserAccessPointSelectionMode = 0x0000001E;
       
   102 #endif
       
   103 
       
   104 
       
   105 // EXTERNAL DATA STRUCTURES
       
   106 
       
   107 // EXTERNAL FUNCTION PROTOTYPES
       
   108 
       
   109 // CONSTANTS
       
   110 
       
   111 #ifndef RD_MULTIPLE_DRIVE
       
   112 _LIT( KDriveZ, "z:" );
       
   113 #endif
       
   114 
       
   115 _LIT( KCDRMHelperResFileName,"DRMHelper.rsc" );
       
   116 _LIT( KEncryptedRightsIssuerMatchString, "flk*" );
       
   117 _LIT( KDRMHelperClassificationRingingTone, "Ringtone" );
       
   118 _LIT( KDRMHelperClassificationVideoTone, "Videotone" );
       
   119 
       
   120 
       
   121 // masks for constaint existence
       
   122 const TInt KDRMHelperConstraintCount = 1;
       
   123 const TInt KDRMHelperConstraintTime = 2;
       
   124 const TInt KDRMHelperConstraintAccumulated = 4;
       
   125 
       
   126 // Buffer sizes
       
   127 const TInt KDRMHelperMaxDateFormatLen = 30;
       
   128 const TInt KDRMHelperMaxDateLen = 30;
       
   129 const TInt KDRMHelperMaxTimeFormatLen = 30;
       
   130 const TInt KDRMHelperMaxTimeLen = 30;
       
   131 const TInt KUrlMaxLen = 1024;
       
   132 const TInt KDRMHelperMaxETABufSize = 11;
       
   133 
       
   134 // limit in minutes when start to display 'about to expire' notes for accumulated
       
   135 // time content
       
   136 #ifndef RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
   137 const TInt KDRMHelperAccumulatedTimeLimit = 15;
       
   138 #endif // RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
   139 
       
   140 // MACROS
       
   141 
       
   142 // LOCAL CONSTANTS AND MACROS
       
   143 
       
   144 // MODULE DATA STRUCTURES
       
   145 
       
   146 // LOCAL FUNCTION PROTOTYPES
       
   147 
       
   148 // FORWARD DECLARATIONS
       
   149 
       
   150 
       
   151 // ============================ auto_handde helper class =======================
       
   152 //Auto handle for easening handle release on exceptional exit situations
       
   153 template<typename T> class auto_handle
       
   154     {
       
   155 public:
       
   156 
       
   157     auto_handle() {}
       
   158     auto_handle(T aHandle) : iHandle( aHandle ) {}
       
   159     auto_handle( auto_handle<T>& aHandle) : iHandle( aHandle.release() ) {}
       
   160     ~auto_handle() { iHandle.Close(); }
       
   161     const T& operator()() const { return iHandle; }
       
   162     T& operator()() { return iHandle; }
       
   163     T get() const { return iHandle; }
       
   164     T release() { T temp = iHandle; iHandle = 0; return temp; }
       
   165 
       
   166 private:
       
   167     T iHandle;
       
   168     };
       
   169 
       
   170 // ============================= LOCAL FUNCTIONS ===============================
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // IapIdOfDefaultSnapL
       
   174 // for trapping purposes only
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 LOCAL_C TUint32 IapIdOfDefaultSnapL(
       
   178     RCmManager& aCmManager,
       
   179     const TUint32 aDefaultSnap )
       
   180     {
       
   181     RCmDestination dest( aCmManager.DestinationL( aDefaultSnap ) );
       
   182     CleanupClosePushL( dest );
       
   183     TUint32 iapIdOfDest( 0 );
       
   184 
       
   185     if ( dest.ConnectionMethodCount() <= 0 )
       
   186         {
       
   187         User::Leave( KErrNotFound );
       
   188         }
       
   189 
       
   190     RCmConnectionMethod cMeth( dest.ConnectionMethodL( 0 ) );
       
   191     CleanupClosePushL( cMeth );
       
   192 
       
   193     iapIdOfDest = cMeth.GetIntAttributeL( CMManager::ECmIapId );
       
   194     CleanupStack::PopAndDestroy( &cMeth );
       
   195     CleanupStack::PopAndDestroy( &dest );
       
   196     return iapIdOfDest;
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // Creates note for resource text to be viewed,
       
   201 // Defaults to information note.
       
   202 // -----------------------------------------------------------------------------
       
   203 LOCAL_C CAknResourceNoteDialog* CreateNoteForResourceL( TInt aResId )
       
   204     {
       
   205     CAknResourceNoteDialog* r( NULL );
       
   206     switch (aResId)
       
   207         {
       
   208         case R_DRM_ERR_OPENING_FAIL_PERM:
       
   209             r = new ( ELeave ) CAknErrorNote( ETrue );
       
   210             break;
       
   211         case R_DRM_WARN_NO_CONN_DEFINED:
       
   212         case R_DRM_WARN_INVALID_OR_NO_AP:
       
   213             r = new  ( ELeave ) CAknWarningNote( ETrue );
       
   214             break;
       
   215         default:
       
   216             r = new ( ELeave ) CAknInformationNote( ETrue );
       
   217             break;
       
   218         }
       
   219     return r;
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // Returns note type for globan note to be viewed.
       
   224 // Defaults to information note.
       
   225 // -----------------------------------------------------------------------------
       
   226 LOCAL_C TAknGlobalNoteType GlobalNoteTypeForResource( TInt aResId )
       
   227     {
       
   228     TAknGlobalNoteType t( EAknGlobalInformationNote );
       
   229     switch (aResId)
       
   230         {
       
   231         case R_DRM_ERR_OPENING_FAIL_PERM:
       
   232             t = EAknGlobalErrorNote;
       
   233             break;
       
   234         case R_DRM_WARN_NO_CONN_DEFINED:
       
   235         case R_DRM_WARN_INVALID_OR_NO_AP:
       
   236             t = EAknGlobalWarningNote;
       
   237             break;
       
   238         default:
       
   239             break;
       
   240         }
       
   241     return t;
       
   242 
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // LeaveIfWrongReturnForHandleErrorOrPreviewL
       
   247 // Leaves if error code under test (argument aError) does match those documented
       
   248 // for HandleErrorOrPreviewL
       
   249 // -----------------------------------------------------------------------------
       
   250 LOCAL_C void LeaveIfWrongReturnForHandleErrorOrPreviewL( TInt aError )
       
   251     {
       
   252     switch ( aError )
       
   253         {
       
   254         case KErrNone:
       
   255         case KErrCancel:
       
   256         case KErrCANoRights:
       
   257         case KErrCANoPermission:
       
   258         case KErrCompletion:
       
   259             break;
       
   260         default:
       
   261             User::Leave( aError );
       
   262         }
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // Checks whether given media type is video type
       
   267 // -----------------------------------------------------------------------------
       
   268 LOCAL_C TBool IsVideo(const CData* aData)
       
   269     {
       
   270     TPtr mimeDes( NULL, 0);
       
   271     TBool ret( EFalse );
       
   272     HBufC* mimeType( HBufC::New( KMaxDataTypeLength ) );
       
   273     if ( !mimeType )
       
   274         {
       
   275         return ret;
       
   276         }
       
   277     mimeDes.Set( mimeType->Des() );
       
   278 
       
   279     //Note mime types borrowed from CDRMHelper::Intent
       
   280     _LIT( KDRMHelperMimeTypeVideo, "Video" );
       
   281     _LIT( KDRMHelperMimeTypeShockwave, "Application/x-shockwave-flash" );
       
   282     _LIT( KDRMHelperMimeTypeRealMedia, "Application/x-pn-realmedia" );
       
   283     _LIT( KDRMHelperMimeTypeVndRealMedia, "Application/vnd.rn-realmedia" );
       
   284 
       
   285     if ( aData->GetStringAttribute( EMimeType, mimeDes ) == KErrNone )
       
   286         {
       
   287         ret = !mimeDes.FindF( KDRMHelperMimeTypeShockwave ) ||
       
   288             !mimeDes.FindF( KDRMHelperMimeTypeRealMedia ) ||
       
   289             !mimeDes.FindF( KDRMHelperMimeTypeVndRealMedia ) ||
       
   290             !mimeDes.FindF( KDRMHelperMimeTypeVideo );
       
   291         }
       
   292     delete mimeType;
       
   293     return ret;
       
   294     }
       
   295 
       
   296 // ---------------------------------------------------------
       
   297 // Evaluate media type for preview playback
       
   298 // ---------------------------------------------------------
       
   299 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
   300 LOCAL_C TInt EvaluatePreviewMediaType( CData* aContent )
       
   301     {
       
   302     TInt theType( -1 );
       
   303     _LIT( KDRMHelperMimeTypeAudio, "Audio" );
       
   304     HBufC* mimeType( HBufC::New( KMaxDataTypeLength ) );
       
   305     if ( !mimeType )
       
   306         {
       
   307         return theType;
       
   308         }
       
   309     TPtr ptr = mimeType->Des();
       
   310     TInt error = aContent->GetStringAttribute( EMimeType, ptr );
       
   311     if ( IsVideo( aContent ) )
       
   312         {
       
   313         theType = EPreviewTypeVideo;
       
   314         }
       
   315     else if ( !ptr.FindF( KDRMHelperMimeTypeAudio ) )
       
   316         {
       
   317         theType = EPreviewTypeAudio;
       
   318         }
       
   319     delete mimeType;
       
   320     return theType;
       
   321     }
       
   322 
       
   323 #endif
       
   324 
       
   325 #pragma mark -
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 // Functions related to WMDRM protection check
       
   329 //
       
   330 // -----------------------------------------------------------------------------
       
   331 
       
   332 // Some magic constants
       
   333 static const TInt KMinContentLength( 16 );
       
   334 _LIT8( KWrmHeader, "W\0R\0M\0H\0E\0A\0D\0E\0R\0" );
       
   335 _LIT8( KASFHeaderObject, "75B22630668E11CFA6D900AA0062CE6C" );
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // FormatGUID
       
   339 // -----------------------------------------------------------------------------
       
   340 LOCAL_C void FormatGUID( TDes8 &aGUID )
       
   341     {
       
   342     TBuf8<16> copyGUID(aGUID);
       
   343     TInt i;
       
   344     for (i = 0; i < 4; i++)
       
   345         {
       
   346         copyGUID[i] = aGUID[3 - i];
       
   347         }
       
   348     for (i = 4; i < 6; i++)
       
   349         {
       
   350         copyGUID[i] = aGUID[9 - i];
       
   351         }
       
   352     for (i = 6; i < 8; i++)
       
   353         {
       
   354         copyGUID[i] = aGUID[13 - i];
       
   355         }
       
   356     for (i = 8; i < 16 ; i++)
       
   357         {
       
   358         copyGUID[i] = aGUID[i];
       
   359         }
       
   360     aGUID.Delete(0, 32);
       
   361     for (i = 0; i <16; i++)
       
   362         {
       
   363         aGUID.AppendNumFixedWidthUC(copyGUID[i], EHex, 2);
       
   364         }
       
   365     }
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // ConvertToInt64
       
   369 // -----------------------------------------------------------------------------
       
   370 LOCAL_C TInt64 ConvertToInt64( TDesC8& aDes )
       
   371     {
       
   372     TInt64 num = 0;
       
   373     TInt i;
       
   374     for (i = 7 ; i >= 0; i--)
       
   375         {
       
   376         num <<= 8;
       
   377         num |= aDes[i];
       
   378         }
       
   379     return num;
       
   380     }
       
   381 
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // IsProtectedWmDrmL
       
   385 // returns ETrue, if file is protected WMDRM file
       
   386 //         EFalse if file is not protected WMDRM file
       
   387 // Leaves with KErrUnderflow if file has too little data to decide
       
   388 //         whether WmDrm or not
       
   389 //         may also leave with other system wide error code
       
   390 // -----------------------------------------------------------------------------
       
   391 LOCAL_C TBool IsProtectedWmDrmL( RFile& aFileHandle )
       
   392     {
       
   393     TInt r( KErrNone );
       
   394     HBufC8* buffer( NULL );
       
   395     TInt pos( 0 );
       
   396     RFile file;
       
   397     TBuf8< 32 > header;
       
   398 
       
   399     TInt64 headerSize( 0 );
       
   400     TBool isProtectedWmDrm( EFalse );
       
   401     TPtr8 headerPtr( NULL, 0 );
       
   402 
       
   403     // Leave if given handle is invalid
       
   404     if ( !aFileHandle.SubSessionHandle() )
       
   405         {
       
   406         User::Leave( KErrBadHandle );
       
   407         }
       
   408 
       
   409     User::LeaveIfError( file.Duplicate( aFileHandle ) );
       
   410     CleanupClosePushL( file );
       
   411 
       
   412     User::LeaveIfError( file.Seek( ESeekStart, pos ) );
       
   413 
       
   414     // Check if the file is an ASF file
       
   415 
       
   416     User::LeaveIfError( file.Read( 0, header, KMinContentLength ) );
       
   417     if ( header.Length() < KMinContentLength )
       
   418         {
       
   419         User::Leave( KErrUnderflow );
       
   420         }
       
   421 
       
   422     FormatGUID( header );
       
   423 
       
   424     if ( header == KASFHeaderObject )
       
   425         {
       
   426         // It's ASF, check still whether it's WM DRM protected or not
       
   427         file.Read( header,8 );
       
   428         headerSize = ConvertToInt64( header );
       
   429         if ( headerSize <= 30 )
       
   430             {
       
   431             User::Leave( KErrUnderflow );
       
   432             }
       
   433         if ( headerSize > ( ( KMaxTInt32 / 2 ) - 1 ) )
       
   434             {
       
   435             User::Leave( KErrOverflow );
       
   436             }
       
   437         buffer = HBufC8::NewLC( headerSize );
       
   438 
       
   439         headerPtr.Set( buffer->Des() );
       
   440         User::LeaveIfError( file.Read( headerPtr, headerSize - 24 ) );
       
   441 
       
   442         r = headerPtr.Find( KWrmHeader );
       
   443         if ( r != KErrNotFound )
       
   444             {
       
   445             isProtectedWmDrm = ETrue;
       
   446             }
       
   447         CleanupStack::PopAndDestroy( buffer );
       
   448         }
       
   449     CleanupStack::PopAndDestroy( &file );
       
   450     return isProtectedWmDrm;
       
   451     }
       
   452 
       
   453 #pragma mark -
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 // End of Functions related to WMDRM protection check
       
   457 //
       
   458 // -----------------------------------------------------------------------------
       
   459 
       
   460 // ---------------------------------------------------------
       
   461 // UpdateDCFRepositoryL()
       
   462 // Update saved file to DCFRepository
       
   463 // ---------------------------------------------------------
       
   464 
       
   465 LOCAL_C void UpdateDCFRepositoryL( const RFile& aFileHandle )
       
   466     {
       
   467     TFileName fullName;
       
   468     aFileHandle.FullName( fullName );
       
   469 
       
   470     CDcfEntry* dcfEntry = NULL;
       
   471     dcfEntry = CDcfEntry::NewL();
       
   472     CleanupStack::PushL( dcfEntry );
       
   473 
       
   474     CDcfRep* dcfRep = NULL;
       
   475     dcfRep = CDcfRep::NewL();
       
   476     CleanupStack::PushL( dcfRep );
       
   477 
       
   478     dcfEntry->SetLocationL( fullName, 0 );
       
   479     dcfRep->UpdateL( dcfEntry );
       
   480     CleanupStack::PopAndDestroy( dcfRep );
       
   481     CleanupStack::PopAndDestroy( dcfEntry );
       
   482     }
       
   483 #pragma mark -
       
   484 
       
   485 
       
   486 // ============================= MEMBER FUNCTIONS ===============================
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CDRMHelperRightsConstraints::CDRMHelperRightsConstraints
       
   490 // C++ default constructor can NOT contain any code, that
       
   491 // might leave.
       
   492 // -----------------------------------------------------------------------------
       
   493 //
       
   494 CDRMHelperRightsConstraints::CDRMHelperRightsConstraints(
       
   495     CDRMRightsConstraints* aConstraints )
       
   496     {
       
   497     iConstraints = aConstraints;
       
   498     }
       
   499 
       
   500 // -----------------------------------------------------------------------------
       
   501 // CDRMHelperRightsConstraints::ConstructL
       
   502 // Symbian 2nd phase constructor can leave.
       
   503 // -----------------------------------------------------------------------------
       
   504 //
       
   505 void CDRMHelperRightsConstraints::ConstructL()
       
   506     {
       
   507     }
       
   508 
       
   509 // -----------------------------------------------------------------------------
       
   510 // CDRMHelperRightsConstraints::NewL
       
   511 // Two-phased constructor.
       
   512 // -----------------------------------------------------------------------------
       
   513 //
       
   514 CDRMHelperRightsConstraints* CDRMHelperRightsConstraints::NewLC(
       
   515     CDRMRightsConstraints* aConstraints )
       
   516     {
       
   517     CleanupStack::PushL( aConstraints );
       
   518     CDRMHelperRightsConstraints* self =
       
   519         new (ELeave) CDRMHelperRightsConstraints( aConstraints );
       
   520     CleanupStack::Pop( aConstraints );
       
   521     CleanupStack::PushL( self );
       
   522     self->ConstructL();
       
   523     return self;
       
   524     }
       
   525 
       
   526 CDRMHelperRightsConstraints* CDRMHelperRightsConstraints::NewL(
       
   527     CDRMRightsConstraints* aConstraints )
       
   528     {
       
   529     CDRMHelperRightsConstraints* self = NewLC( aConstraints );
       
   530     CleanupStack::Pop( self );
       
   531     return self;
       
   532     }
       
   533 
       
   534 
       
   535 // Destructor
       
   536 EXPORT_C CDRMHelperRightsConstraints::~CDRMHelperRightsConstraints()
       
   537     {
       
   538     delete iConstraints;
       
   539     }
       
   540 
       
   541 // -----------------------------------------------------------------------------
       
   542 // CDRMHelperRightsConstraints::FullRights
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 EXPORT_C TBool CDRMHelperRightsConstraints::FullRights()
       
   546     {
       
   547     return iConstraints->FullRights();
       
   548     }
       
   549 
       
   550 // -----------------------------------------------------------------------------
       
   551 // CDRMHelperRightsConstraints::IsPreview
       
   552 // -----------------------------------------------------------------------------
       
   553 //
       
   554 EXPORT_C TBool CDRMHelperRightsConstraints::IsPreview()
       
   555     {
       
   556     return iConstraints->IsPreview();
       
   557     }
       
   558 
       
   559 // -----------------------------------------------------------------------------
       
   560 // CDRMHelperRightsConstraints::GetCountersL
       
   561 // -----------------------------------------------------------------------------
       
   562 //
       
   563 EXPORT_C void CDRMHelperRightsConstraints::GetCountersL(
       
   564     TUint32& aCounter,
       
   565     TUint32& aOriginalCounter )
       
   566     {
       
   567     if ( iConstraints->GetCounters( aCounter, aOriginalCounter ) ==
       
   568         DRMCommon::ENoRights )
       
   569         {
       
   570         User::Leave( KErrNotFound );
       
   571         }
       
   572     }
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // CDRMHelperRightsConstraints::GetStartTimeL
       
   576 // -----------------------------------------------------------------------------
       
   577 //
       
   578 EXPORT_C void CDRMHelperRightsConstraints::GetStartTimeL( TTime& aStartTime )
       
   579     {
       
   580     if ( iConstraints->GetStartTime( aStartTime ) == DRMCommon::ENoRights )
       
   581         {
       
   582         User::Leave( KErrNotFound );
       
   583         }
       
   584     }
       
   585 
       
   586 // -----------------------------------------------------------------------------
       
   587 // CDRMHelperRightsConstraints::GetEndTimeL
       
   588 // -----------------------------------------------------------------------------
       
   589 //
       
   590 EXPORT_C void CDRMHelperRightsConstraints::GetEndTimeL( TTime& aEndTime )
       
   591     {
       
   592     if ( iConstraints->GetEndTime( aEndTime ) == DRMCommon::ENoRights )
       
   593         {
       
   594         User::Leave( KErrNotFound );
       
   595         }
       
   596     }
       
   597 
       
   598 // -----------------------------------------------------------------------------
       
   599 // CDRMHelperRightsConstraints::GetIntervalL
       
   600 // -----------------------------------------------------------------------------
       
   601 //
       
   602 EXPORT_C void CDRMHelperRightsConstraints::GetIntervalL(
       
   603     TTimeIntervalSeconds& aInterval )
       
   604     {
       
   605     if ( iConstraints->GetInterval( aInterval ) == DRMCommon::ENoRights )
       
   606         {
       
   607         User::Leave( KErrNotFound );
       
   608         }
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CDRMHelperRightsConstraints::GetIntervalStartL
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 EXPORT_C void CDRMHelperRightsConstraints::GetIntervalStartL(
       
   616     TTime& aStartTime )
       
   617     {
       
   618     if ( iConstraints->GetIntervalStart( aStartTime ) == DRMCommon::ENoRights )
       
   619         {
       
   620         User::Leave( KErrNotFound );
       
   621         }
       
   622     }
       
   623 
       
   624 // -----------------------------------------------------------------------------
       
   625 // CDRMHelperRightsConstraints::GetTimedCountL
       
   626 // -----------------------------------------------------------------------------
       
   627 //
       
   628 EXPORT_C void CDRMHelperRightsConstraints::GetTimedCountL( TUint32& aCounter,
       
   629     TUint32& aOriginalCounter, TTimeIntervalSeconds& aTimer )
       
   630     {
       
   631     if ((iConstraints->GetConstraint()).iActiveConstraints & EConstraintTimedCounter)
       
   632         {
       
   633         aCounter = (iConstraints->GetConstraint()).iTimedCounter;
       
   634         aOriginalCounter = aCounter;
       
   635         aTimer = ( iConstraints->GetConstraint() ).iTimedInterval;
       
   636         }
       
   637     else
       
   638         {
       
   639         User::Leave(KErrNotFound);
       
   640         }
       
   641 
       
   642     }
       
   643 
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // CDRMHelperRightsConstraints::GetTimedCountL
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 EXPORT_C void CDRMHelperRightsConstraints::GetAccumulatedTimeL(
       
   650     TTimeIntervalSeconds& aAccumulatedTime )
       
   651     {
       
   652     if ((iConstraints->GetConstraint()).iActiveConstraints & EConstraintAccumulated)
       
   653         {
       
   654         aAccumulatedTime = (iConstraints->GetConstraint()).iAccumulatedTime;
       
   655         }
       
   656     else
       
   657         {
       
   658         User::Leave(KErrNotFound);
       
   659         }
       
   660     }
       
   661 
       
   662 #pragma mark -
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // CDRMHelper::CDRMHelper
       
   666 // C++ default constructor can NOT contain any code, that
       
   667 // might leave.
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 CDRMHelper::CDRMHelper( CCoeEnv& aCoeEnv ) :
       
   671     iCoeEnv( &aCoeEnv ),
       
   672     iUseCoeEnv( ETrue ),
       
   673     iAutomatedType( EAutomatedTypeOther ),
       
   674     iPreviewMediaType(-1)
       
   675     {
       
   676     }
       
   677 
       
   678 // -----------------------------------------------------------------------------
       
   679 // CDRMHelper::CDRMHelper
       
   680 // C++ default constructor can NOT contain any code, that
       
   681 // might leave.
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 CDRMHelper::CDRMHelper() :
       
   685     iUseCoeEnv( EFalse ),
       
   686     iAutomatedType( EAutomatedTypeOther )
       
   687     {
       
   688     }
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CDRMHelper::ConstructL
       
   692 // Symbian 2nd phase constructor can leave.
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 void CDRMHelper::ConstructL( RFs* aFs )
       
   696     {
       
   697     TInt drmMethods;
       
   698     DRMCommon::TOMALevel omaLevel;
       
   699 
       
   700     iDRMCommon = DRMCommon::NewL();
       
   701     User::LeaveIfError( iDRMCommon->Connect() );
       
   702     User::LeaveIfError( iHelperServer.Connect() );
       
   703 
       
   704     iDRMCommon->SupportedDRMMethods( drmMethods, omaLevel );
       
   705     iOma2 = omaLevel == DRMCommon::EOMA_2_0 ? ETrue : EFalse;
       
   706 
       
   707     if ( aFs )
       
   708         {
       
   709         iFs = *aFs;
       
   710         iFsOwned = EFalse;
       
   711         }
       
   712     else
       
   713         {
       
   714         User::LeaveIfError( iFs.Connect() );
       
   715         User::LeaveIfError(iFs.ShareAuto());
       
   716         iFsOwned = ETrue;
       
   717         }
       
   718 
       
   719 #ifndef RD_MULTIPLE_DRIVE
       
   720 
       
   721     TFileName fileName( KDriveZ );
       
   722 
       
   723 #else //RD_MULTIPLE_DRIVE
       
   724 
       
   725     _LIT( KDrive, "%c:");
       
   726     TInt driveNumber( -1 );
       
   727     TChar driveLetter;
       
   728     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
   729     iFs.DriveToChar( driveNumber, driveLetter );
       
   730 
       
   731     TFileName fileName;
       
   732 
       
   733     fileName.Format( KDrive, (TUint)driveLetter );
       
   734 
       
   735 #endif
       
   736 
       
   737     fileName.Append( KDC_RESOURCE_FILES_DIR );
       
   738     fileName.Append( KCDRMHelperResFileName );
       
   739 
       
   740     TRAP_IGNORE( FeatureManager::InitializeLibL() );
       
   741 
       
   742     iStringResourceReader = CStringResourceReader::NewL( fileName, iFs );
       
   743 
       
   744     if ( FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) )
       
   745         {
       
   746         iEventProvider = CMediatorEventProvider::NewL();
       
   747         }
       
   748     }
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // CDRMHelper::NewL
       
   752 // Two-phased constructor.
       
   753 // -----------------------------------------------------------------------------
       
   754 //
       
   755 EXPORT_C CDRMHelper* CDRMHelper::NewLC( CCoeEnv& aCoeEnv )
       
   756     {
       
   757     CDRMHelper* self = new (ELeave) CDRMHelper( aCoeEnv );
       
   758     CleanupStack::PushL( self );
       
   759     self->ConstructL( NULL );
       
   760     return self;
       
   761     }
       
   762 
       
   763 EXPORT_C CDRMHelper* CDRMHelper::NewL( CCoeEnv& aCoeEnv )
       
   764     {
       
   765     CDRMHelper* self = NewLC( aCoeEnv );
       
   766     CleanupStack::Pop( self );
       
   767     return self;
       
   768     }
       
   769 
       
   770 EXPORT_C CDRMHelper* CDRMHelper::NewL()
       
   771     {
       
   772     CDRMHelper* self = NewLC();
       
   773     CleanupStack::Pop( self );
       
   774     return self;
       
   775     }
       
   776 
       
   777 EXPORT_C CDRMHelper* CDRMHelper::NewLC()
       
   778     {
       
   779     CDRMHelper* self = new (ELeave) CDRMHelper();
       
   780     CleanupStack::PushL( self );
       
   781     self->ConstructL( NULL );
       
   782     return self;
       
   783     }
       
   784 
       
   785 EXPORT_C CDRMHelper* CDRMHelper::NewLC( CCoeEnv& aCoeEnv, RFs& aFs )
       
   786     {
       
   787     CDRMHelper* self = new (ELeave) CDRMHelper( aCoeEnv );
       
   788     CleanupStack::PushL( self );
       
   789     self->ConstructL( &aFs );
       
   790     return self;
       
   791     }
       
   792 
       
   793 EXPORT_C CDRMHelper* CDRMHelper::NewL( CCoeEnv& aCoeEnv, RFs& aFs )
       
   794     {
       
   795     CDRMHelper* self = NewLC( aCoeEnv, aFs );
       
   796     CleanupStack::Pop( self );
       
   797     return self;
       
   798     }
       
   799 
       
   800 EXPORT_C CDRMHelper* CDRMHelper::NewL( RFs& aFs )
       
   801     {
       
   802     CDRMHelper* self = NewLC( aFs );
       
   803     CleanupStack::Pop( self );
       
   804     return self;
       
   805     }
       
   806 
       
   807 EXPORT_C CDRMHelper* CDRMHelper::NewLC( RFs& aFs )
       
   808     {
       
   809     CDRMHelper* self = new (ELeave) CDRMHelper();
       
   810     CleanupStack::PushL( self );
       
   811     self->ConstructL( &aFs );
       
   812     return self;
       
   813     }
       
   814 
       
   815 // Destructor
       
   816 EXPORT_C CDRMHelper::~CDRMHelper()
       
   817     {
       
   818     // closing all rdb sessions is handled in the destructor
       
   819     // of the CConsumeData objects
       
   820     // delete rdb connections array
       
   821     iConsumeList.ResetAndDestroy();
       
   822     iConsumeList.Close();
       
   823     iHelperServer.Close();
       
   824 
       
   825     iNoteList.ResetAndDestroy(); // GlobalNoteInfo
       
   826     iNoteList.Close();
       
   827 
       
   828     if (iDRMCommon)
       
   829         {
       
   830         iDRMCommon->Disconnect();
       
   831         }
       
   832     delete iStringResourceReader;
       
   833     delete iDRMCommon;
       
   834 
       
   835     if ( iFsOwned )
       
   836         {
       
   837         iFs.Close();
       
   838         }
       
   839 
       
   840     FeatureManager::UnInitializeLib();
       
   841 
       
   842     delete iSchemeHandler;
       
   843     delete iEventProvider;
       
   844     }
       
   845 
       
   846 #pragma mark -
       
   847 
       
   848 // -----------------------------------------------------------------------------
       
   849 // CDRMHelper::HandleErrorL
       
   850 // -----------------------------------------------------------------------------
       
   851 //
       
   852 
       
   853 EXPORT_C TInt CDRMHelper::HandleErrorL( TInt aError,
       
   854     const TDesC8& aURI )
       
   855     {
       
   856     RFile fileHandle;
       
   857     TInt ret( KErrNotFound );
       
   858     CleanupClosePushL( fileHandle );
       
   859 
       
   860     if ( GetFileHandleFromURIL( aURI, fileHandle ) == KErrNone )
       
   861         {
       
   862         ret = CDRMHelper::HandleErrorL( aError, fileHandle );
       
   863         }
       
   864     CleanupStack::PopAndDestroy( &fileHandle );
       
   865     return ret;
       
   866     }
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 // CDRMHelper::HandleErrorL
       
   870 // -----------------------------------------------------------------------------
       
   871 //
       
   872 EXPORT_C TInt CDRMHelper::HandleErrorL( TInt aError, RFile& aFileHandle )
       
   873     {
       
   874     TInt ret = KErrNone;
       
   875     HBufC* rightsIssuer = NULL;
       
   876     HBufC* mimeType = NULL;
       
   877     HBufC* contentURI = NULL;
       
   878     HBufC* domainRoUrl = NULL;
       
   879     HBufC* eta = NULL;
       
   880     HBufC8* contentURI8 = NULL;
       
   881     HBufC* riId = NULL;
       
   882     HBufC8* riId8 = NULL;
       
   883     HBufC* domainId = NULL;
       
   884     HBufC8* domainId8 = NULL;
       
   885 
       
   886     TInt error;
       
   887     TPtr ptr(NULL, 0);
       
   888     TFileName fileName;
       
   889 
       
   890     // To embed Domain RO in superdistribution case, register the content
       
   891     TRAP_IGNORE( UpdateDCFRepositoryL( aFileHandle ) );
       
   892 
       
   893     CData* content = CData::NewLC( aFileHandle, KDefaultContentObject, EPeek );
       
   894 
       
   895     // get rights-issuer URL
       
   896     TRAP_IGNORE(GetRightsIssuerL( *content, rightsIssuer ) );
       
   897     if ( rightsIssuer )
       
   898         {
       
   899         CleanupStack::PushL( rightsIssuer );
       
   900         }
       
   901 
       
   902     mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
   903     contentURI = HBufC::NewLC( KUrlMaxLen );
       
   904     domainRoUrl = HBufC::NewLC( KUrlMaxLen );
       
   905     eta = HBufC::NewLC( KDRMHelperMaxETABufSize );
       
   906     riId = HBufC::NewLC( KUrlMaxLen );
       
   907     domainId = HBufC::NewLC( KUrlMaxLen );
       
   908 
       
   909     // create attribute set
       
   910     RStringAttributeSet stringAttributeSet;
       
   911     CleanupClosePushL( stringAttributeSet );
       
   912     // add the attributes we are interested in
       
   913     stringAttributeSet.AddL( EContentID );
       
   914     stringAttributeSet.AddL( EMimeType );
       
   915     stringAttributeSet.AddL( EDomainRightsIssuerUrl );
       
   916     stringAttributeSet.AddL( EPendingRightsETA );
       
   917     stringAttributeSet.AddL( EDomainRightsIssuerId );
       
   918     stringAttributeSet.AddL( EDomainId );
       
   919 
       
   920     User::LeaveIfError( content->GetStringAttributeSet( stringAttributeSet ) );
       
   921 
       
   922     // pass on values of string attributes
       
   923     ptr.Set( contentURI->Des() );
       
   924     error = stringAttributeSet.GetValue( EContentID, ptr );
       
   925     if ( error == KErrNone )
       
   926         {
       
   927         ptr.Set( domainRoUrl->Des() );
       
   928         stringAttributeSet.GetValue( EDomainRightsIssuerUrl, ptr );
       
   929 
       
   930         ptr.Set( mimeType->Des() );
       
   931         error = stringAttributeSet.GetValue( EMimeType, ptr );
       
   932 
       
   933         ptr.Set( riId->Des() );
       
   934         stringAttributeSet.GetValue( EDomainRightsIssuerId, ptr );
       
   935 
       
   936         ptr.Set( domainId->Des() );
       
   937         stringAttributeSet.GetValue( EDomainId, ptr );
       
   938 
       
   939         if ( error == KErrNone )
       
   940             {
       
   941             ptr.Set( eta->Des() );
       
   942             error = stringAttributeSet.GetValue( EPendingRightsETA, ptr );
       
   943             HBufC* etaPtr = error == KErrNone ? eta : NULL;
       
   944             aFileHandle.Name( fileName );
       
   945             contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
   946             contentURI8->Des().Copy( contentURI->Des() );
       
   947             riId8 = HBufC8::NewLC( riId->Length() );
       
   948             riId8->Des().Copy( riId->Des() );
       
   949             domainId8 = HBufC8::NewLC( domainId->Length() );
       
   950             domainId8->Des().Copy( domainId->Des() );
       
   951             ret = DoHandleErrorL( aError,
       
   952                 contentURI8,
       
   953                 mimeType,
       
   954                 rightsIssuer,
       
   955                 domainRoUrl,
       
   956                 etaPtr,
       
   957                 riId8,
       
   958                 domainId8,
       
   959                 StripPathAndExtension( fileName ) );
       
   960             CleanupStack::PopAndDestroy( 3, contentURI8 ); // contentURI8, riId8
       
   961             }
       
   962         else
       
   963             {
       
   964             User::Leave( KErrArgument );
       
   965             }
       
   966         }
       
   967     else
       
   968         {
       
   969         User::Leave( KErrArgument );
       
   970         }
       
   971 
       
   972     CleanupStack::PopAndDestroy( 7, mimeType );
       
   973 
       
   974     if ( rightsIssuer )
       
   975         {
       
   976         CleanupStack::PopAndDestroy( rightsIssuer );
       
   977         }
       
   978 
       
   979     CleanupStack::PopAndDestroy( content );
       
   980     return ret;
       
   981     }
       
   982 
       
   983 // -----------------------------------------------------------------------------
       
   984 // CDRMHelper::HandleErrorL
       
   985 // -----------------------------------------------------------------------------
       
   986 //
       
   987 EXPORT_C TInt CDRMHelper::HandleErrorL( TInt aError, const TDesC& aFileName )
       
   988     {
       
   989     RFile file;
       
   990     TInt r = KErrNone;
       
   991 
       
   992     r = file.Open(iFs, aFileName, EFileRead | EFileShareReadersOrWriters);
       
   993 
       
   994     if (r == KErrInUse)
       
   995         {
       
   996         r = file.Open(iFs, aFileName, EFileRead | EFileShareAny);
       
   997         if (r == KErrInUse)
       
   998             {
       
   999             r = file.Open(iFs, aFileName, EFileRead | EFileShareReadersOnly);
       
  1000             }
       
  1001         }
       
  1002     User::LeaveIfError(r);
       
  1003 
       
  1004     CleanupClosePushL( file );
       
  1005     r = HandleErrorL( aError, file );
       
  1006     CleanupStack::PopAndDestroy( &file );
       
  1007     return r;
       
  1008     }
       
  1009 
       
  1010 // -----------------------------------------------------------------------------
       
  1011 // CDRMHelper::DoHandleErrorL
       
  1012 // -----------------------------------------------------------------------------
       
  1013 //
       
  1014 TInt CDRMHelper::DoHandleErrorL(
       
  1015     TInt aError,
       
  1016     HBufC8* aContentUri,
       
  1017     HBufC* aMimeType,
       
  1018     HBufC* aRIUrl,
       
  1019     HBufC* aDomainRoUrl,
       
  1020     HBufC* aEta,
       
  1021     HBufC8* aRiId8,
       
  1022     HBufC8* aDomainId8,
       
  1023     const TDesC& aFileName )
       
  1024     {
       
  1025     TBool automated( EFalse );
       
  1026     TInt error(0);
       
  1027     TInt ret(0);
       
  1028     TInt resId(0);
       
  1029     CDRMRights* rights = NULL;
       
  1030     Roap::RRoapStorageClient storage;
       
  1031     CDRMRIContext* riContext = NULL;
       
  1032     CDRMDomainContext* domainContext = NULL;
       
  1033     TBool isRegistered = EFalse;
       
  1034     TBool isJoined = EFalse;
       
  1035 
       
  1036     iReturnCancel = EFalse;
       
  1037     switch ( aError )
       
  1038         {
       
  1039         case KErrCAPendingRights:
       
  1040         case DRMCommon::ERightsExpired:
       
  1041         case DRMCommon::ENoRights:
       
  1042         case KDRMErrNoRights:
       
  1043             if ( aError == DRMCommon::ENoRights || aError == KDRMErrNoRights )
       
  1044                 {
       
  1045                 // check if it is expired situation after all
       
  1046                 error = GetExpirationDetails(
       
  1047                     aContentUri, Intent( aMimeType ), rights );
       
  1048                 if ( error == CDRMRights::EExpiredRights )
       
  1049                     {
       
  1050                     aError = DRMCommon::ERightsExpired;
       
  1051                     }
       
  1052                 if ( rights )
       
  1053                     {
       
  1054                     delete rights;
       
  1055                     rights = NULL;
       
  1056                     }
       
  1057                 }
       
  1058 
       
  1059             if ( aRiId8 && aRiId8->Length() && aDomainRoUrl && aDomainRoUrl->Length() )
       
  1060                 {
       
  1061                 // Check if we have domain RO
       
  1062                 User::LeaveIfError( storage.Connect() );
       
  1063                 CleanupClosePushL( storage );
       
  1064                 riContext = storage.GetRIContextL( *aRiId8 );
       
  1065                 if ( riContext )
       
  1066                     {
       
  1067                     isRegistered = ETrue;
       
  1068                     delete riContext;
       
  1069                     riContext = NULL;
       
  1070                     if ( aDomainId8 && aDomainId8->Length() )
       
  1071                         {
       
  1072                         domainContext = storage.GetDomainContextL( *aDomainId8 );
       
  1073                         if ( domainContext )
       
  1074                             {
       
  1075                             // last three digits presents the domain generation
       
  1076                             TInt generation = 0;
       
  1077                             TLex8 lex( aDomainId8->Right( 3 ) );
       
  1078                             lex.Val( generation );
       
  1079 
       
  1080                             if ( domainContext->DomainGeneration() >= generation )
       
  1081                                 {
       
  1082                                 isJoined = ETrue;
       
  1083                                 }
       
  1084                             delete domainContext;
       
  1085                             domainContext = NULL;
       
  1086                             }
       
  1087                         }
       
  1088                     }
       
  1089                 CleanupStack::PopAndDestroy( &storage );
       
  1090                 }
       
  1091 
       
  1092             // check if future rights
       
  1093             if ( aError != KErrCAPendingRights &&
       
  1094                 GetExpirationDetails(
       
  1095                     aContentUri, Intent( aMimeType ), rights ) ==
       
  1096                 CDRMRights::EFutureRights )
       
  1097                 {
       
  1098                 if ( aContentUri )
       
  1099                     {
       
  1100                     TRAPD( err,
       
  1101                         error = ShowFutureNoteL( aMimeType, rights ) );
       
  1102                     if ( err )
       
  1103                         {
       
  1104                         error = err;
       
  1105                         }
       
  1106                     }
       
  1107                 if ( rights )
       
  1108                     {
       
  1109                     delete rights;
       
  1110                     rights = NULL;
       
  1111                     }
       
  1112                 }
       
  1113             else
       
  1114                 {
       
  1115                 TInt type(0);
       
  1116 
       
  1117                 // check if this is automated content
       
  1118                 if ( aContentUri )
       
  1119                     {
       
  1120                     error = iHelperServer.IsAutomated(
       
  1121                         *aContentUri,
       
  1122                         iAutomatedType,
       
  1123                         Intent( aMimeType ),
       
  1124                         automated,
       
  1125                         type );
       
  1126                     if (!error && automated)
       
  1127                         {
       
  1128                         aError = DRMCommon::ERightsExpired;
       
  1129                         }
       
  1130                     }
       
  1131 
       
  1132                 if ( aError == DRMCommon::ERightsExpired )
       
  1133                     {
       
  1134 
       
  1135                     if ( !error && automated )
       
  1136                         {
       
  1137                         // automated content
       
  1138                         TBool active = (type ==
       
  1139                             CDRMHelperServer::EActive ? ETrue : EFalse);
       
  1140                         TUint32 rejectReason = RejectReasonL(
       
  1141                             Intent( aMimeType ), *aContentUri );
       
  1142                         if ( aRIUrl )
       
  1143                             {
       
  1144                             // superdistributable
       
  1145                             // get resource id
       
  1146                             resId = AutomatedResIdL( ETrue, ETrue, rejectReason );
       
  1147                             ret = DisplayQueryL( resId, aFileName );
       
  1148                             if ( ret == 0 )
       
  1149                                 {
       
  1150                                 // Query has been closed with cancel or similar,
       
  1151                                 // So handleErrorOrPreviewL should return KErrCancel
       
  1152                                 iReturnCancel = ETrue;
       
  1153                                 // new rights not bought, unregister content
       
  1154                                 iHelperServer.RemoveAutomatedAll(
       
  1155                                     *aContentUri,
       
  1156                                     active,
       
  1157                                     iAutomatedType,
       
  1158                                     Intent( aMimeType ) );
       
  1159                                 }
       
  1160                             }
       
  1161                         else
       
  1162                             {
       
  1163                             // non-superdistributable, show note and unregister
       
  1164                             resId = AutomatedResIdL( ETrue, EFalse, rejectReason );
       
  1165                             ret = DisplayQueryWithIdValueL(
       
  1166                                 resId,
       
  1167                                 R_DRMHELPER_WAITING_RIGHTS_CONFIRMATION_QUERY,
       
  1168                                 aFileName );
       
  1169 
       
  1170                             if ( ret == 0 )
       
  1171                                 {
       
  1172                                 // Query has been closed with cancel or similar,
       
  1173                                 // So handleErrorOrPreviewL should return KErrCancel
       
  1174                                 iReturnCancel = ETrue;
       
  1175                                 }
       
  1176                             iHelperServer.RemoveAutomatedAll(
       
  1177                                 *aContentUri,
       
  1178                                 active,
       
  1179                                 iAutomatedType,
       
  1180                                 Intent( aMimeType ) );
       
  1181                             }
       
  1182                         }
       
  1183                     else
       
  1184                         {
       
  1185                         if ( aRIUrl )
       
  1186                             {
       
  1187                             resId = ErrorResIdL(
       
  1188                                 *aContentUri, Intent( aMimeType ), ETrue, ETrue );
       
  1189                             ret = DisplayQueryWithIdL(
       
  1190                                 resId,
       
  1191                                 R_DRMHELPER_CONFIRMATION_QUERY );
       
  1192                             if ( ret == 0 )
       
  1193                                 {
       
  1194                                 // Query has been closed with cancel or similar,
       
  1195                                 // So handleErrorOrPreviewL should return KErrCancel
       
  1196                                 iReturnCancel = ETrue;
       
  1197                                 }
       
  1198                             }
       
  1199                         else
       
  1200                             {
       
  1201                             resId = ErrorResIdL(
       
  1202                                 *aContentUri, Intent( aMimeType ), EFalse, ETrue );
       
  1203                             DisplayInfoNoteL( resId );
       
  1204                             }
       
  1205                         }
       
  1206                     }
       
  1207                 else
       
  1208                     {
       
  1209                     // check if rights are expected to arrive
       
  1210                     TInt eta(0);
       
  1211                     if ( aEta )
       
  1212                         {
       
  1213                         TLex lexer( *aEta );
       
  1214                         error = lexer.Val( eta );
       
  1215                         }
       
  1216                     if (!error && aError == KErrCAPendingRights && eta == -1)
       
  1217                         {
       
  1218                         // rights should have come
       
  1219                         if ( aRIUrl )
       
  1220                             {
       
  1221                             ret = DisplayQueryWithIdL(
       
  1222                                 R_DRMHELPER_RIGHTS_SHOULD_HAVE_COME,
       
  1223                                 R_DRMHELPER_CONFIRMATION_QUERY );
       
  1224                             if ( ret == 0 )
       
  1225                                 {
       
  1226                                 // Query has been closed with cancel or similar,
       
  1227                                 // So handleErrorOrPreviewL should return KErrCancel
       
  1228                                 iReturnCancel = ETrue;
       
  1229                                 }
       
  1230                             }
       
  1231                         else
       
  1232                             {
       
  1233                             // no Rights-Issuer
       
  1234                             DisplayQueryWithIdL(
       
  1235                                 R_DRMHELPER_RIGHTS_SHOULD_HAVE_COME_NO_RI,
       
  1236                                 R_DRMHELPER_WAITING_RIGHTS_CONFIRMATION_QUERY );
       
  1237                             }
       
  1238                         }
       
  1239                     else if ( !eta || error || eta == -1 )
       
  1240                         { // rights not expected to arrive
       
  1241                         if ( aDomainRoUrl && aDomainRoUrl->Length() && isRegistered && !isJoined ) // Domain ro case
       
  1242                             {
       
  1243                             ret = DisplayQueryWithIdL( R_DRMHELPER_ACTIVATE_ACCOUNT,
       
  1244                                 R_DRMHELPER_CONFIRMATION_QUERY );
       
  1245                             if ( ret == 0 )
       
  1246                                 {
       
  1247                                 // Query has been closed with cancel or similar,
       
  1248                                 // So handleErrorOrPreviewL should return KErrCancel
       
  1249                                 iReturnCancel = ETrue;
       
  1250                                 }
       
  1251                             }
       
  1252                         else if ( aRIUrl ) // Device ro case
       
  1253                             {
       
  1254                             resId = ErrorResIdL(
       
  1255                                 *aContentUri, Intent( aMimeType ), ETrue, EFalse );
       
  1256                             ret = DisplayQueryL( resId, aFileName );
       
  1257                             if ( ret == 0 )
       
  1258                                 {
       
  1259                                 // Query has been closed with cancel or similar,
       
  1260                                 // So handleErrorOrPreviewL should return KErrCancel
       
  1261                                 iReturnCancel = ETrue;
       
  1262                                 }
       
  1263                             }
       
  1264                         else
       
  1265                             {
       
  1266                             resId = ErrorResIdL(
       
  1267                                 *aContentUri, Intent( aMimeType ), EFalse, EFalse );
       
  1268                             DisplayInfoNoteL( resId );
       
  1269                             }
       
  1270                         }
       
  1271                     else
       
  1272                         {
       
  1273                         // rights expected to arrive
       
  1274                         if ( eta != KErrCAPendingRights )
       
  1275                             {
       
  1276                             // rights expected to arrive in eta seconds
       
  1277                             DisplayQueryWithIdL( R_DRMHELPER_WAITING_FOR_RIGHTS,
       
  1278                                 R_DRMHELPER_WAITING_RIGHTS_CONFIRMATION_QUERY );
       
  1279                             }
       
  1280                         else
       
  1281                             {
       
  1282                             // rights should have come
       
  1283                             if ( aRIUrl )
       
  1284                                 {
       
  1285                                 ret = DisplayQueryWithIdL(
       
  1286                                     R_DRMHELPER_RIGHTS_SHOULD_HAVE_COME,
       
  1287                                     R_DRMHELPER_CONFIRMATION_QUERY );
       
  1288                                 if ( ret == 0 )
       
  1289                                     {
       
  1290                                     // Query has been closed with cancel or similar,
       
  1291                                     // So handleErrorOrPreviewL should return KErrCancel
       
  1292                                     iReturnCancel = ETrue;
       
  1293                                     }
       
  1294                                 }
       
  1295                             else
       
  1296                                 {
       
  1297                                 // no Rights-Issuer
       
  1298                                 DisplayQueryWithIdL(
       
  1299                                     R_DRMHELPER_RIGHTS_SHOULD_HAVE_COME_NO_RI,
       
  1300                                     R_DRMHELPER_WAITING_RIGHTS_CONFIRMATION_QUERY );
       
  1301                                 }
       
  1302                             }
       
  1303                         }
       
  1304                     }
       
  1305 
       
  1306                 if ( ret == EAknSoftkeyYes )
       
  1307                     {
       
  1308                     if ( aDomainRoUrl && aDomainRoUrl->Length() && !isRegistered )
       
  1309                         { // Domain RO but not registered
       
  1310                         LaunchBrowserL( aDomainRoUrl );
       
  1311                         }
       
  1312                     else if ( aDomainRoUrl && aDomainRoUrl->Length() && !isJoined )
       
  1313                         { // Domain RO but not part of the domain
       
  1314                         LaunchBrowserL( aDomainRoUrl );
       
  1315                         }
       
  1316                     else if (aRIUrl && aRIUrl->Length() )
       
  1317                         {
       
  1318                         LaunchBrowserL( aRIUrl );
       
  1319                         }
       
  1320                     }
       
  1321                 }
       
  1322             break;
       
  1323 
       
  1324         case DRMCommon::ERightsDBCorrupted:
       
  1325         case KDRMErrRightsDBCorrupted:
       
  1326             // flow through
       
  1327 
       
  1328         default:
       
  1329             User::LeaveIfError( aError );
       
  1330             break;
       
  1331         }
       
  1332     return ret;
       
  1333     }
       
  1334 
       
  1335 // -----------------------------------------------------------------------------
       
  1336 // CDRMHelper::ShowFutureNoteL
       
  1337 // -----------------------------------------------------------------------------
       
  1338 //
       
  1339 TInt CDRMHelper::ShowFutureNoteL( const HBufC* aMimeType, CDRMRights* aRightsObject)
       
  1340     {
       
  1341     TInt error( KErrArgument );
       
  1342     TInt intent = Intent( aMimeType );
       
  1343 
       
  1344     TTime startTime;
       
  1345 
       
  1346     error = GetStartTime( aRightsObject, intent, startTime );
       
  1347     if ( !error )
       
  1348         {
       
  1349         TBuf<KDRMHelperMaxDateFormatLen> dateFormat;
       
  1350         TBuf<KDRMHelperMaxDateLen + KDRMHelperMaxTimeLen + 1> startDateBuf;
       
  1351         TBuf<KDRMHelperMaxTimeFormatLen> timeFormat;
       
  1352         TBuf<KDRMHelperMaxTimeLen> startTimeBuf;
       
  1353 
       
  1354 #ifndef RD_MULTIPLE_DRIVE
       
  1355 
       
  1356         TFileName avkonResFile( KDriveZ );
       
  1357 
       
  1358 #else //RD_MULTIPLE_DRIVE
       
  1359 
       
  1360         _LIT( KDrive, "%c:");
       
  1361         TInt driveNumber( -1 );
       
  1362         TChar driveLetter;
       
  1363         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  1364         iFs.DriveToChar( driveNumber, driveLetter );
       
  1365 
       
  1366         TFileName avkonResFile;
       
  1367 
       
  1368         avkonResFile.Format( KDrive, (TUint)driveLetter );
       
  1369 
       
  1370 #endif
       
  1371 
       
  1372         _LIT( KCDRMHelperAvkonResFileName, "avkon.rsc" );
       
  1373         _LIT( KSpace, " " );
       
  1374 
       
  1375         avkonResFile.Append( KDC_RESOURCE_FILES_DIR );
       
  1376         avkonResFile.Append( KCDRMHelperAvkonResFileName );
       
  1377 
       
  1378         // get date string format
       
  1379         CStringResourceReader* avkonResReader =
       
  1380             CStringResourceReader::NewLC( avkonResFile );
       
  1381 
       
  1382         dateFormat = avkonResReader->ReadResourceString(
       
  1383             R_QTN_DATE_USUAL_WITH_ZERO );
       
  1384 
       
  1385         // get time string format
       
  1386         timeFormat = avkonResReader->ReadResourceString(
       
  1387             R_QTN_TIME_USUAL_WITH_ZERO );
       
  1388 
       
  1389         CleanupStack::PopAndDestroy( avkonResReader );
       
  1390 
       
  1391         // format date and time
       
  1392         startTime.FormatL( startDateBuf, dateFormat );
       
  1393         startTime.FormatL( startTimeBuf, timeFormat );
       
  1394         startDateBuf.Append( KSpace );
       
  1395         startDateBuf.Append( startTimeBuf );
       
  1396 
       
  1397         // display note with start date
       
  1398         DisplayInfoNoteL( R_DRMHELPER_USAGE_RIGHTS_IN_FUTURE,
       
  1399             startDateBuf );
       
  1400         }
       
  1401 
       
  1402     return error;
       
  1403     }
       
  1404 
       
  1405 // -----------------------------------------------------------------------------
       
  1406 // CDRMHelper::ErrorResIdL
       
  1407 // -----------------------------------------------------------------------------
       
  1408 //
       
  1409 TInt CDRMHelper::ErrorResIdL(
       
  1410     const TDesC8& aContentUri,
       
  1411     TInt aIntent,
       
  1412     TBool aRightsIssuer,
       
  1413     TBool aExpired )
       
  1414     {
       
  1415     TInt resId(0);
       
  1416 
       
  1417     TUint32 rejectReason = RejectReasonL( aIntent, aContentUri );
       
  1418     if ( rejectReason & EConstraintIndividual )
       
  1419         {
       
  1420         if ( aRightsIssuer )
       
  1421             {
       
  1422             resId = R_DRMHELPER_INVALID_SIM;
       
  1423             }
       
  1424         else
       
  1425             {
       
  1426             resId = R_DRM_INFO_SIM_NOT_ALLOWED;
       
  1427             }
       
  1428         }
       
  1429     else
       
  1430         {
       
  1431         if ( aExpired )
       
  1432             {
       
  1433             resId = aRightsIssuer ? R_DRMHELPER_USAGE_RIGHTS_EXPIRED_BUY_NEW :
       
  1434                 R_DRMHELPER_USAGE_RIGHTS_EXPIRED;
       
  1435             }
       
  1436         else
       
  1437             {
       
  1438             // no rights
       
  1439             resId = aRightsIssuer ? R_DRMHELPER_NO_USAGE_RIGHTS_BUY_NEW :
       
  1440                 R_DRMHELPER_NO_USAGE_RIGHTS;
       
  1441             }
       
  1442         }
       
  1443 
       
  1444     return resId;
       
  1445     }
       
  1446 
       
  1447 // -----------------------------------------------------------------------------
       
  1448 // CDRMHelper::RejectReasonL
       
  1449 // -----------------------------------------------------------------------------
       
  1450 //
       
  1451 TUint32 CDRMHelper::RejectReasonL( TInt aIntent, const TDesC8& aContentUri )
       
  1452     {
       
  1453     RDRMRightsClient rightsClient;
       
  1454     TUint32 rejectReason(0);
       
  1455 
       
  1456     User::LeaveIfError( rightsClient.Connect() );
       
  1457     rightsClient.CheckRights( aIntent, aContentUri, rejectReason );
       
  1458     rightsClient.Close();
       
  1459 
       
  1460     return rejectReason;
       
  1461     }
       
  1462 
       
  1463 // -----------------------------------------------------------------------------
       
  1464 // CDRMHelper::GetExpirationDetails
       
  1465 // -----------------------------------------------------------------------------
       
  1466 //
       
  1467 TInt CDRMHelper::GetExpirationDetails( HBufC8* aContentUri, TInt aIntent,
       
  1468     CDRMRights*& aRightsObject )
       
  1469     {
       
  1470     RPointerArray<CDRMRights>* uriList = NULL;
       
  1471     TInt r = KErrNone;
       
  1472     TInt expired(0);
       
  1473     TInt future(0);
       
  1474     TInt valid(0);
       
  1475     TTime startTime( Time::NullTTime() );
       
  1476     TInt startIndex( -1 );
       
  1477     DRMClock::ESecurityLevel secLevel = DRMClock::KInsecure;
       
  1478     TUint32 expiration;
       
  1479     CDRMRightsConstraints* constraint = NULL;
       
  1480     TUint32 rightsType;
       
  1481     auto_handle<RDRMClockClient> client; // autohandle deletes on scope end
       
  1482     auto_handle<RDRMRightsClient> rclient; // autohandle closes on scope end
       
  1483     RPointerArray<HBufC8> individuals;
       
  1484     TUint32 retval = 0;
       
  1485     TTime time = Time::NullTTime();
       
  1486 
       
  1487     if ( !aContentUri )
       
  1488         {
       
  1489         return KErrArgument;
       
  1490         }
       
  1491 
       
  1492     r = client().Connect();
       
  1493 
       
  1494     if ( !r )
       
  1495         {
       
  1496         TInt timeZone(0);
       
  1497         client().GetSecureTime(time, timeZone, secLevel);
       
  1498         }
       
  1499 
       
  1500     // Client to rights client needed to retrieve the individual information:
       
  1501     r = rclient().Connect();
       
  1502     if ( r )
       
  1503         {
       
  1504         return r;
       
  1505         }
       
  1506 
       
  1507     r = rclient().CheckRights( aIntent, *aContentUri, expiration );
       
  1508     if ( r && expiration == EConstraintMetering )
       
  1509         {
       
  1510         r = CDRMRights::EExpiredRights;
       
  1511         return r;
       
  1512         }
       
  1513 
       
  1514     r = KErrNone;
       
  1515 
       
  1516     iDRMCommon->GetDetailedContentRights(*aContentUri, uriList);
       
  1517 
       
  1518     if ( !uriList || !uriList->Count() )
       
  1519         {
       
  1520         delete uriList;
       
  1521         uriList = NULL;
       
  1522         return KErrCANoRights;
       
  1523         }
       
  1524 
       
  1525 
       
  1526     TRAP( r, r = rclient().GetSupportedIndividualsL( individuals ) );
       
  1527     rclient().Close();
       
  1528 
       
  1529     for ( TInt i = 0; i < uriList->Count(); ++i )
       
  1530         {
       
  1531         switch ( aIntent )
       
  1532             {
       
  1533             case EPlay:
       
  1534                 r = (*uriList)[i]->GetPlayRight(constraint);
       
  1535                 break;
       
  1536             case EView:
       
  1537                 r = (*uriList)[i]->GetDisplayRight(constraint);
       
  1538                 break;
       
  1539             case EExecute:
       
  1540                 r = (*uriList)[i]->GetExecuteRight(constraint);
       
  1541                 break;
       
  1542             case EPrint:
       
  1543                 r = (*uriList)[i]->GetPrintRight(constraint);
       
  1544                 break;
       
  1545             default:
       
  1546                 // Cleanup required when returning and error:
       
  1547                 // auto_handle closes client
       
  1548                 uriList->ResetAndDestroy(); //uriList
       
  1549                 delete uriList;
       
  1550                 uriList = NULL;
       
  1551                 return KErrGeneral;
       
  1552             }
       
  1553         if ( r )
       
  1554             {
       
  1555             delete constraint;
       
  1556             constraint = NULL;
       
  1557             continue;
       
  1558             }
       
  1559         constraint->GetConstraintInfo(expiration, rightsType);
       
  1560 
       
  1561         if ( secLevel != DRMClock::KSecure &&
       
  1562             (rightsType & CDRMRights::ETimeBased || rightsType & CDRMRights::EInActiveInterval ))
       
  1563             {
       
  1564             delete constraint;
       
  1565             constraint = NULL;
       
  1566             continue;
       
  1567             }
       
  1568 
       
  1569         if ( expiration == CDRMRights::EFutureRights )
       
  1570             {
       
  1571             // We already know it's not valid, ignore the return value of Valid:
       
  1572             constraint->GetConstraint().Valid( time, individuals, retval);
       
  1573 
       
  1574             if ( retval & EConstraintIndividual )
       
  1575                 {
       
  1576                 ++expired;
       
  1577                 }
       
  1578             else
       
  1579                 {
       
  1580                 if ( rightsType & CDRMRights::ETimeBased )
       
  1581                     {
       
  1582                     TTime tempTime;
       
  1583                     if ( constraint->GetStartTime( tempTime ) != DRMCommon::ENoRights )
       
  1584                         {
       
  1585                         if ( startTime != Time::NullTTime() && tempTime < startTime )
       
  1586                             {
       
  1587                             startTime = tempTime;
       
  1588                             startIndex = i;
       
  1589                             }
       
  1590                         else if ( startTime == Time::NullTTime() )
       
  1591                             {
       
  1592                             startTime = tempTime;
       
  1593                             startIndex = i;
       
  1594                             }
       
  1595                         }
       
  1596                     }
       
  1597                 ++future;
       
  1598                 }
       
  1599             }
       
  1600         else if ( expiration == CDRMRights::EExpiredRights )
       
  1601             {
       
  1602             ++expired;
       
  1603             }
       
  1604         else
       
  1605             {
       
  1606             if ( !(constraint->GetConstraint().Valid( time, individuals, retval) ) )
       
  1607                 {
       
  1608                 ++expired;
       
  1609                 }
       
  1610             else
       
  1611                 {
       
  1612                 ++valid;
       
  1613                 }
       
  1614             }
       
  1615 
       
  1616         delete constraint;
       
  1617         constraint = NULL;
       
  1618         }
       
  1619 
       
  1620     if ( valid )
       
  1621         {
       
  1622         r = CDRMRights::EValidRights;
       
  1623         }
       
  1624     else if ( future )
       
  1625         {
       
  1626         r = CDRMRights::EFutureRights;
       
  1627         if ( startIndex >= 0 )
       
  1628             {
       
  1629             aRightsObject = (*uriList)[startIndex];
       
  1630             (*uriList)[startIndex] = NULL;
       
  1631             uriList->Remove(startIndex);
       
  1632             }
       
  1633         }
       
  1634     else
       
  1635         {
       
  1636         r = CDRMRights::EExpiredRights;
       
  1637         }
       
  1638     // Reset the individuals
       
  1639     individuals.ResetAndDestroy();
       
  1640     individuals.Close();
       
  1641 
       
  1642     // autohandle closes client
       
  1643 
       
  1644     // Reset the urilist
       
  1645     uriList->ResetAndDestroy(); //uriList
       
  1646     delete uriList;
       
  1647     uriList = NULL;
       
  1648 
       
  1649     return r;
       
  1650     }
       
  1651 
       
  1652 #pragma mark -
       
  1653 
       
  1654 // -----------------------------------------------------------------------------
       
  1655 // CDRMHelper::HandleErrorOrPreviewL
       
  1656 // -----------------------------------------------------------------------------
       
  1657 //
       
  1658 EXPORT_C TInt CDRMHelper::HandleErrorOrPreviewL(
       
  1659     TInt aError,
       
  1660     RFile& aFile,
       
  1661     HBufC8*& aEmbeddedPreviewUri )
       
  1662     {
       
  1663     ContentAccess::CData* content( NULL );
       
  1664     TPtr ptr( NULL,0 );
       
  1665     TInt previewType = 0;
       
  1666     TInt buttonCode = 0;
       
  1667     HBufC* previewUri16 = NULL;
       
  1668     HBufC* rightsIssuer = NULL;
       
  1669     HBufC8* silentUrl( NULL );
       
  1670     TInt r( aError );
       
  1671 
       
  1672 
       
  1673     aEmbeddedPreviewUri = NULL;
       
  1674     content = ContentAccess::CData::NewLC(
       
  1675             aFile, ContentAccess::KDefaultContentObject, ContentAccess::EPeek );
       
  1676 
       
  1677     // To embed Domain RO in superdistribution case, register the content
       
  1678     TRAP_IGNORE( UpdateDCFRepositoryL( aFile ) );
       
  1679 
       
  1680     if (aError != KErrCANoPermission &&
       
  1681         aError != KErrCANoRights &&
       
  1682         aError != KDRMErrNoRights )
       
  1683         {
       
  1684         // not a preview case
       
  1685         HandleErrorL( aError, aFile );
       
  1686         }
       
  1687     else if ( !IsVideo( content ) &&
       
  1688         ( silentUrl = HasSilentRightsUrlL( content ) ) != NULL )
       
  1689         {
       
  1690         // get rights silently if we have the URL and if we are registered
       
  1691         CleanupStack::PushL( silentUrl );
       
  1692         r = GetSilentRightsL( *silentUrl );
       
  1693         CleanupStack::PopAndDestroy( silentUrl );
       
  1694         if ( r == KErrNone )
       
  1695             {
       
  1696             // check if we can use the file now
       
  1697             HBufC* mimeBuf( HBufC::NewLC( KMaxDataTypeLength ) );
       
  1698             TPtr mimePtr( mimeBuf->Des() );
       
  1699             User::LeaveIfError( content->GetStringAttribute( EMimeType,
       
  1700                 mimePtr ) );
       
  1701             r = content->EvaluateIntent(
       
  1702                 static_cast<ContentAccess::TIntent>( Intent( mimeBuf ) ) );
       
  1703             CleanupStack::PopAndDestroy( mimeBuf );
       
  1704             mimeBuf = NULL;
       
  1705 
       
  1706             LeaveIfWrongReturnForHandleErrorOrPreviewL( r );
       
  1707             if ( r != KErrNone )
       
  1708                 {
       
  1709                 HandleErrorL( r, aFile );
       
  1710                 }
       
  1711             }
       
  1712         else if ( r != KErrCancel )
       
  1713             {
       
  1714             HandleErrorL( aError, aFile );
       
  1715             }
       
  1716         }
       
  1717     else
       
  1718         {
       
  1719         CheckPreviewUriL(content,previewUri16,previewType);
       
  1720         CleanupStack::PushL(previewUri16);
       
  1721 
       
  1722         // display according to preview type
       
  1723         switch (previewType)
       
  1724             {
       
  1725             case ContentAccess::ENoPreview:
       
  1726                 // no preview
       
  1727                 HandleErrorL(aError,aFile);
       
  1728                 break;
       
  1729             case ContentAccess::EInstantPreview:
       
  1730             case ContentAccess::EPreviewRights:
       
  1731 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  1732                 if ( iPreviewMediaType < 0 )
       
  1733                     { // if no preview type set by application
       
  1734                     SetPreviewMediaType( static_cast<TDRMHelperPreviewMediaType>(
       
  1735                             EvaluatePreviewMediaType( content ) ) );
       
  1736                     if ( iPreviewMediaType < 0 )
       
  1737                         { //unable to resolve media type, cancel preview
       
  1738                         HandleErrorL( aError, aFile );
       
  1739                         break;
       
  1740                         }
       
  1741                     }
       
  1742                 buttonCode = DisplayPopupWindowsForPreviewL(previewType);
       
  1743                 aEmbeddedPreviewUri = HBufC8::NewL( previewUri16->Length() );
       
  1744                 aEmbeddedPreviewUri->Des().Copy( previewUri16->Des() );
       
  1745 #else
       
  1746                 HandleErrorL( aError, aFile );
       
  1747 #endif // RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  1748 
       
  1749                 break;
       
  1750             default:
       
  1751                 break;
       
  1752             }
       
  1753         CleanupStack::PopAndDestroy(previewUri16);
       
  1754         previewUri16 = NULL;
       
  1755 
       
  1756         // behave based on user's action
       
  1757         switch (buttonCode)
       
  1758             {
       
  1759             case 1:
       
  1760                 // activate rights
       
  1761                 delete aEmbeddedPreviewUri;
       
  1762                 aEmbeddedPreviewUri = NULL;
       
  1763                 GetRightsIssuerL( *content, rightsIssuer );
       
  1764                 CleanupStack::PushL( rightsIssuer );
       
  1765                 LaunchBrowserL( rightsIssuer );
       
  1766                 CleanupStack::PopAndDestroy(rightsIssuer);
       
  1767 
       
  1768                 // check if we can use the file now
       
  1769                 if ( content->EvaluateIntent( ContentAccess::EUnknown ) == KErrNone )
       
  1770                     {
       
  1771                     r = KErrNone;
       
  1772                     }
       
  1773                 else
       
  1774                     {
       
  1775                     r = KErrCompletion;
       
  1776                     }
       
  1777                 break;
       
  1778             case 2:
       
  1779                 // get preview or play preview
       
  1780                 if (previewType == ContentAccess::EPreviewRights)
       
  1781                     {
       
  1782                     CleanupStack::PushL(aEmbeddedPreviewUri);
       
  1783                     CDrmHelperDownloadManager* dlMgr =
       
  1784                         CDrmHelperDownloadManager::NewL();
       
  1785                     CleanupStack::PushL( dlMgr );
       
  1786 
       
  1787                     if ( iUseCoeEnv )
       
  1788                         {
       
  1789                         TRAP(r, dlMgr->DownloadAndHandleRoapTriggerL(
       
  1790                                 aEmbeddedPreviewUri, *iCoeEnv ) );
       
  1791                         // ignore error
       
  1792                         }
       
  1793                     else
       
  1794                         {
       
  1795                         TRAP(r, dlMgr->DownloadAndHandleRoapTriggerL( aEmbeddedPreviewUri ) );
       
  1796                         // ignore error
       
  1797                         }
       
  1798 
       
  1799                     CleanupStack::PopAndDestroy( dlMgr );
       
  1800                     CleanupStack::PopAndDestroy( aEmbeddedPreviewUri );
       
  1801                     aEmbeddedPreviewUri = NULL;
       
  1802 
       
  1803                     // check if we can use the file now
       
  1804                     r = content->EvaluateIntent( ContentAccess::EUnknown );
       
  1805                     LeaveIfWrongReturnForHandleErrorOrPreviewL( r );
       
  1806                     }
       
  1807                 else
       
  1808                     {
       
  1809                     r = KErrNone;
       
  1810                     }
       
  1811                 break;
       
  1812             case 0:
       
  1813             default:
       
  1814                 // cancelled or no preview
       
  1815                 delete aEmbeddedPreviewUri;
       
  1816                 aEmbeddedPreviewUri = NULL;
       
  1817                 if ( previewType != ContentAccess::ENoPreview )
       
  1818                     {
       
  1819                     r = KErrCancel;
       
  1820                     }
       
  1821                 break;
       
  1822             }
       
  1823         }
       
  1824     if ( iReturnCancel )
       
  1825         {
       
  1826         // Cancel pressed in query intitiated from HandleErrorL
       
  1827         r = KErrCancel;
       
  1828         }
       
  1829     CleanupStack::PopAndDestroy(content);
       
  1830     return r;
       
  1831     }
       
  1832 
       
  1833 // -----------------------------------------------------------------------------
       
  1834 // CDRMHelper::HandleErrorOrPreviewL
       
  1835 // -----------------------------------------------------------------------------
       
  1836 //
       
  1837 EXPORT_C TInt CDRMHelper::HandleErrorOrPreviewL(
       
  1838     TInt aError,
       
  1839     const TDesC& aFileName,
       
  1840     HBufC8*& aEmbeddedPreviewUri )
       
  1841     {
       
  1842     RFile file;
       
  1843     TInt r = KErrNone;
       
  1844 
       
  1845     r = file.Open(iFs, aFileName, EFileRead | EFileShareReadersOrWriters);
       
  1846 
       
  1847     if (r == KErrInUse)
       
  1848         {
       
  1849         r = file.Open(iFs, aFileName, EFileRead | EFileShareAny);
       
  1850         if (r == KErrInUse)
       
  1851             {
       
  1852             r = file.Open(iFs, aFileName, EFileRead | EFileShareReadersOnly);
       
  1853             }
       
  1854         }
       
  1855     User::LeaveIfError(r);
       
  1856     CleanupClosePushL( file );
       
  1857     r = HandleErrorOrPreviewL( aError, file, aEmbeddedPreviewUri );
       
  1858     CleanupStack::PopAndDestroy( &file );
       
  1859     return r;
       
  1860     }
       
  1861 
       
  1862 // -----------------------------------------------------------------------------
       
  1863 // CDRMHelper::SetPreviewMediaType
       
  1864 // -----------------------------------------------------------------------------
       
  1865 //
       
  1866 EXPORT_C TInt CDRMHelper::SetPreviewMediaType( TDRMHelperPreviewMediaType aMediaType )
       
  1867     {
       
  1868     iPreviewMediaType = aMediaType;
       
  1869     return KErrNone;
       
  1870     }
       
  1871 
       
  1872 // -----------------------------------------------------------------------------
       
  1873 // CDRMHelper::CheckPreviewUriL
       
  1874 // -----------------------------------------------------------------------------
       
  1875 //
       
  1876 void CDRMHelper::CheckPreviewUriL(
       
  1877     const CData* aContent,
       
  1878     HBufC*& aEmbeddedPreviewUri,
       
  1879     TInt& aPreviewType )
       
  1880     {
       
  1881     TPtr ptr(NULL,0);
       
  1882     TInt error = 0;
       
  1883     aPreviewType = ContentAccess::ENoPreview;
       
  1884     aEmbeddedPreviewUri = HBufC::NewLC( KUrlMaxLen );
       
  1885     ptr.Set(aEmbeddedPreviewUri->Des());
       
  1886     error = aContent->GetStringAttribute( EInstantPreviewUri , ptr );
       
  1887     if (!error && ptr.Length()>0)
       
  1888         {
       
  1889         // embedded preview
       
  1890         aPreviewType = ContentAccess::EInstantPreview;
       
  1891         }
       
  1892     else
       
  1893         {
       
  1894         error = aContent->GetStringAttribute( EPreviewRightsUri , ptr );
       
  1895         if (!error && ptr.Length()>0)
       
  1896             {
       
  1897             // preview rights url
       
  1898             aPreviewType = ContentAccess::EPreviewRights;
       
  1899             }
       
  1900         }
       
  1901     if (aPreviewType == ContentAccess::ENoPreview)
       
  1902         {
       
  1903         CleanupStack::PopAndDestroy(aEmbeddedPreviewUri);
       
  1904         aEmbeddedPreviewUri = NULL;
       
  1905         }
       
  1906     else
       
  1907         {
       
  1908         CleanupStack::Pop(aEmbeddedPreviewUri);
       
  1909         }
       
  1910     }
       
  1911 
       
  1912 // -----------------------------------------------------------------------------
       
  1913 // CDRMHelper::DisplayPopupWindowsForPreviewL
       
  1914 // -----------------------------------------------------------------------------
       
  1915 //
       
  1916 #ifdef RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  1917 TInt CDRMHelper::DisplayPopupWindowsForPreviewL( TInt aPreviewType )
       
  1918     {
       
  1919     TInt buttonCode = 0;
       
  1920     CAknListQueryDialog* dlg;
       
  1921     TInt index( 0 );
       
  1922     TInt resourceId = -1;
       
  1923     TInt answer = 0;
       
  1924 
       
  1925     if (aPreviewType == ContentAccess::EPreviewRights)
       
  1926         {
       
  1927         // preview rights
       
  1928         if (iPreviewMediaType == EPreviewTypeAudio)
       
  1929             {
       
  1930             resourceId = R_DRMHELPER_PREV_AUDIO_GET_LIST_QUERY;
       
  1931             }
       
  1932         else if (iPreviewMediaType == EPreviewTypeVideo)
       
  1933             {
       
  1934             resourceId = R_DRMHELPER_PREV_VIDEO_GET_LIST_QUERY;
       
  1935             }
       
  1936         }
       
  1937     else if (aPreviewType == ContentAccess::EInstantPreview)
       
  1938         {
       
  1939         // embedded preview
       
  1940         if (iPreviewMediaType == EPreviewTypeAudio)
       
  1941             {
       
  1942             resourceId = R_DRMHELPER_PREV_AUDIO_PLAY_LIST_QUERY;
       
  1943             }
       
  1944         else if (iPreviewMediaType == EPreviewTypeVideo)
       
  1945             {
       
  1946             resourceId = R_DRMHELPER_PREV_VIDEO_PLAY_LIST_QUERY;
       
  1947             }
       
  1948         }
       
  1949 
       
  1950 
       
  1951     if (resourceId != -1)
       
  1952         {
       
  1953 
       
  1954 #ifndef RD_MULTIPLE_DRIVE
       
  1955 
       
  1956         TFileName fileName( KDriveZ );
       
  1957 
       
  1958 #else //RD_MULTIPLE_DRIVE
       
  1959 
       
  1960         _LIT( KDrive, "%c:");
       
  1961         TInt driveNumber( -1 );
       
  1962         TChar driveLetter;
       
  1963         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  1964         iFs.DriveToChar( driveNumber, driveLetter );
       
  1965 
       
  1966         TFileName fileName;
       
  1967 
       
  1968         fileName.Format( KDrive, (TUint)driveLetter );
       
  1969 
       
  1970 #endif
       
  1971 
       
  1972         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
  1973         fileName.Append( KCDRMHelperResFileName );
       
  1974         RConeResourceLoader loader( *iCoeEnv );
       
  1975         loader.OpenL( fileName );
       
  1976         CleanupClosePushL( loader );
       
  1977 
       
  1978         dlg = new( ELeave ) CAknListQueryDialog( &index );
       
  1979         CleanupStack::PushL( dlg );
       
  1980 
       
  1981         PrepareSecondaryDisplayL( *dlg, resourceId );
       
  1982 
       
  1983         CleanupStack::Pop( dlg );
       
  1984 
       
  1985         answer = dlg->ExecuteLD( resourceId );
       
  1986 
       
  1987         CancelSecondaryDisplayL( resourceId );
       
  1988 
       
  1989         CleanupStack::PopAndDestroy( &loader );
       
  1990         }
       
  1991 
       
  1992     if ( answer )
       
  1993         {
       
  1994         buttonCode = index+1;
       
  1995         }
       
  1996     else
       
  1997         {
       
  1998         buttonCode = 0;
       
  1999         }
       
  2000 
       
  2001     iPreviewMediaType = -1; // reset preview type
       
  2002     return buttonCode;
       
  2003     }
       
  2004 #else // RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  2005 TInt CDRMHelper::DisplayPopupWindowsForPreviewL( TInt /* aPreviewType */ )
       
  2006     {
       
  2007     return 0;
       
  2008     }
       
  2009 #endif // RD_DRM_PREVIEW_RIGHT_FOR_AUDIO
       
  2010 
       
  2011 // -----------------------------------------------------------------------------
       
  2012 // CDRMHelper::HasPreviewL
       
  2013 // -----------------------------------------------------------------------------
       
  2014 //
       
  2015 EXPORT_C CDRMHelper::TDRMHelperPreviewType CDRMHelper::HasPreviewL(
       
  2016     CData& aContent,
       
  2017     HBufC8*& aPreviewUri )
       
  2018     {
       
  2019     TDRMHelperPreviewType ret( ENoPreview );
       
  2020     if ( iOma2 )
       
  2021         {
       
  2022         TInt error;
       
  2023         TInt silent(0);
       
  2024         TInt previewRightsType;
       
  2025         TBuf<KUrlMaxLen> previewUrl;
       
  2026         TInt previewType( ENoPreview );
       
  2027         aContent.GetAttribute( EPreviewType, previewType );
       
  2028         switch ( previewType )
       
  2029             {
       
  2030             case EInstantPreview:
       
  2031                 // get URI of embedded preview
       
  2032                 error = aContent.GetStringAttribute( EInstantPreviewUri,
       
  2033                     previewUrl );
       
  2034                 if ( !error )
       
  2035                     {
       
  2036                     ret = EEmbeddedPreview;
       
  2037                     aPreviewUri = HBufC8::NewL( previewUrl.Length() );
       
  2038                     aPreviewUri->Des().Copy( previewUrl );
       
  2039                     }
       
  2040                 break;
       
  2041             case EPreviewRights:
       
  2042                 // Check if it is silent preview
       
  2043                 aContent.GetAttribute( ESilentRightsType, silent );
       
  2044                 previewRightsType =
       
  2045                     silent ? ESilentRightsUrl : EPreviewRightsUri;
       
  2046                 error = aContent.GetStringAttribute( previewRightsType,
       
  2047                     previewUrl );
       
  2048                 if ( !error )
       
  2049                     {
       
  2050                     ret = EPreviewRights;
       
  2051                     aPreviewUri = HBufC8::NewL( previewUrl.Length() );
       
  2052                     aPreviewUri->Des().Copy( previewUrl );
       
  2053                     }
       
  2054                 break;
       
  2055             default:
       
  2056                 // no preview
       
  2057                 break;
       
  2058             }
       
  2059         }
       
  2060     else
       
  2061         {
       
  2062         User::Leave( KErrNotSupported );
       
  2063         }
       
  2064     return ret;
       
  2065     }
       
  2066 
       
  2067 
       
  2068 // -----------------------------------------------------------------------------
       
  2069 // CDRMHelper::HasPreviewL
       
  2070 // -----------------------------------------------------------------------------
       
  2071 //
       
  2072 EXPORT_C CDRMHelper::TDRMHelperPreviewType CDRMHelper::HasPreviewL(
       
  2073     TDesC& aFileName,
       
  2074     HBufC8*& aPreviewUri )
       
  2075     {
       
  2076     TDRMHelperPreviewType ret( ENoPreview );
       
  2077     if ( iOma2 )
       
  2078         {
       
  2079         TVirtualPathPtr virtualPath( aFileName );
       
  2080 
       
  2081         CData* content = NULL;
       
  2082         TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  2083         if ( r == KErrInUse )
       
  2084             {
       
  2085             content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  2086             }
       
  2087         else
       
  2088             {
       
  2089             User::LeaveIfError( r );
       
  2090             }
       
  2091 
       
  2092         CleanupStack::PushL( content );
       
  2093 
       
  2094         ret = HasPreviewL( *content, aPreviewUri );
       
  2095         CleanupStack::PopAndDestroy( content );
       
  2096         }
       
  2097     else
       
  2098         {
       
  2099         User::Leave( KErrNotSupported );
       
  2100         }
       
  2101     return ret;
       
  2102     }
       
  2103 
       
  2104 
       
  2105 // -----------------------------------------------------------------------------
       
  2106 // CDRMHelper::GetPreviewRightsL
       
  2107 // -----------------------------------------------------------------------------
       
  2108 //
       
  2109 EXPORT_C void CDRMHelper::GetPreviewRightsL( CData& aContent )
       
  2110     {
       
  2111     if ( iOma2 )
       
  2112         {
       
  2113         HBufC8* previewUri = NULL;
       
  2114         TDRMHelperPreviewType previewType = HasPreviewL( aContent, previewUri );
       
  2115         CleanupStack::PushL( previewUri );
       
  2116         if ( previewType == EPreviewRights )
       
  2117             {
       
  2118             TInt silent(0);
       
  2119             // Check if it is silent preview
       
  2120             aContent.GetAttribute( ESilentRightsType, silent );
       
  2121             if ( silent )
       
  2122                 {
       
  2123                 CDrmHelperDownloadManager* dlMgr =
       
  2124                     CDrmHelperDownloadManager::NewL();
       
  2125                 CleanupStack::PushL( dlMgr );
       
  2126 
       
  2127                 if ( iUseCoeEnv )
       
  2128                     {
       
  2129                     dlMgr->DownloadAndHandleRoapTriggerL( previewUri, *iCoeEnv );
       
  2130                     }
       
  2131                 else
       
  2132                     {
       
  2133                     dlMgr->DownloadAndHandleRoapTriggerL( previewUri );
       
  2134                     }
       
  2135 
       
  2136                 CleanupStack::PopAndDestroy( dlMgr );
       
  2137                 }
       
  2138             else
       
  2139                 {
       
  2140                 // launch browser
       
  2141                 LaunchBrowserL( previewUri );
       
  2142                 }
       
  2143             }
       
  2144         else
       
  2145             {
       
  2146             // No preview rights available, this function should not be called
       
  2147             User::Leave( KErrArgument );
       
  2148             }
       
  2149         CleanupStack::PopAndDestroy( previewUri );
       
  2150         }
       
  2151     else
       
  2152         {
       
  2153         User::Leave( KErrNotSupported );
       
  2154         }
       
  2155     }
       
  2156 
       
  2157 
       
  2158 // -----------------------------------------------------------------------------
       
  2159 // CDRMHelper::GetPreviewRightsL
       
  2160 // -----------------------------------------------------------------------------
       
  2161 //
       
  2162 EXPORT_C void CDRMHelper::GetPreviewRightsL(TDesC& aFileName )
       
  2163     {
       
  2164     if ( iOma2 )
       
  2165         {
       
  2166         TVirtualPathPtr virtualPath( aFileName );
       
  2167 
       
  2168         CData* content( NULL );
       
  2169         TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  2170         if ( r == KErrInUse )
       
  2171             {
       
  2172             content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  2173             }
       
  2174         else
       
  2175             {
       
  2176             User::LeaveIfError( r );
       
  2177             }
       
  2178 
       
  2179         CleanupStack::PushL( content );
       
  2180 
       
  2181         GetPreviewRightsL( *content );
       
  2182         CleanupStack::PopAndDestroy( content );
       
  2183         }
       
  2184     else
       
  2185         {
       
  2186         User::Leave( KErrNotSupported );
       
  2187         }
       
  2188     }
       
  2189 
       
  2190 
       
  2191 // -----------------------------------------------------------------------------
       
  2192 // CDRMHelper::EmbeddedPreviewCompletedL
       
  2193 // -----------------------------------------------------------------------------
       
  2194 //
       
  2195 EXPORT_C TBool CDRMHelper::EmbeddedPreviewCompletedL( CData& aContent )
       
  2196     {
       
  2197     TBool proceeded = EFalse;
       
  2198     if ( iOma2 )
       
  2199         {
       
  2200         TInt error = KErrNone;
       
  2201         TInt canPlay;
       
  2202         HBufC* rightsIssuer = NULL;
       
  2203         TInt buyRights(0);
       
  2204 
       
  2205         error = aContent.GetAttribute( ECanPlay, canPlay );
       
  2206         if ( !error && !canPlay )
       
  2207             {
       
  2208             TFileName fileName;
       
  2209 
       
  2210             // Get RI URL
       
  2211             GetRightsIssuerL( aContent, rightsIssuer );
       
  2212             CleanupStack::PushL( rightsIssuer );
       
  2213             // Ask if user wants to buy rights
       
  2214             error = aContent.GetStringAttribute( EFileName, fileName );
       
  2215             if ( !error )
       
  2216                 {
       
  2217                 if ( buyRights )
       
  2218                     {
       
  2219                     // launch browser
       
  2220                     LaunchBrowserL( rightsIssuer );
       
  2221                     proceeded = ETrue;
       
  2222                     }
       
  2223                 else
       
  2224                     {
       
  2225                     proceeded = EFalse;
       
  2226                     }
       
  2227                 }
       
  2228             else
       
  2229                 {
       
  2230                 User::Leave( KErrArgument );
       
  2231                 }
       
  2232             CleanupStack::PopAndDestroy( rightsIssuer );
       
  2233             }
       
  2234         else
       
  2235             {
       
  2236             User::Leave( KErrArgument );
       
  2237             }
       
  2238         }
       
  2239     else
       
  2240         {
       
  2241         User::Leave( KErrNotSupported );
       
  2242         }
       
  2243     return proceeded;
       
  2244     }
       
  2245 
       
  2246 
       
  2247 // -----------------------------------------------------------------------------
       
  2248 // CDRMHelper::EmbeddedPreviewCompletedL
       
  2249 // -----------------------------------------------------------------------------
       
  2250 //
       
  2251 EXPORT_C TBool CDRMHelper::EmbeddedPreviewCompletedL( TDesC& aFileName )
       
  2252     {
       
  2253     TBool proceeded( EFalse );
       
  2254     if ( iOma2 )
       
  2255         {
       
  2256         TVirtualPathPtr virtualPath( aFileName );
       
  2257 
       
  2258         CData* content( NULL );
       
  2259         TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  2260         if ( r == KErrInUse )
       
  2261             {
       
  2262             content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  2263             }
       
  2264         else
       
  2265             {
       
  2266             User::LeaveIfError( r );
       
  2267             }
       
  2268 
       
  2269         CleanupStack::PushL( content );
       
  2270 
       
  2271         proceeded = EmbeddedPreviewCompletedL( *content );
       
  2272         CleanupStack::PopAndDestroy( content );
       
  2273         }
       
  2274     else
       
  2275         {
       
  2276         User::Leave( KErrNotSupported );
       
  2277         }
       
  2278     return proceeded;
       
  2279     }
       
  2280 
       
  2281 #ifdef RD_DRM_SILENT_RIGHTS_ACQUISITION
       
  2282 HBufC8* CDRMHelper::HasSilentRightsUrlL( CData* aContent )
       
  2283     {
       
  2284     HBufC* url = NULL;
       
  2285     HBufC8* url8 = NULL;
       
  2286     HBufC8* r = NULL;
       
  2287     TPtr urlDes( NULL, 0);
       
  2288     Roap::RRoapStorageClient storage;
       
  2289 
       
  2290     url = HBufC::NewLC( KMaxPath * 4 );
       
  2291     urlDes.Set( url->Des() );
       
  2292     if ( aContent->GetStringAttribute( ESilentRightsUrl, urlDes ) == KErrNone )
       
  2293         {
       
  2294         url8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *url );
       
  2295         CleanupStack::PushL( url8 );
       
  2296         User::LeaveIfError( storage.Connect() );
       
  2297         CleanupClosePushL( storage );
       
  2298         // check that SilentRightsUrl is on the white list
       
  2299         // URL is not searched from pre-configured white list
       
  2300         TBool fromPreConfiguredWhiteList( EFalse );
       
  2301         if ( storage.WhiteListURLExistsL( *url8, fromPreConfiguredWhiteList ) )
       
  2302             {
       
  2303             r = url8->AllocL();
       
  2304             }
       
  2305         CleanupStack::PopAndDestroy( &storage );
       
  2306         CleanupStack::PopAndDestroy( url8 );
       
  2307         }
       
  2308     CleanupStack::PopAndDestroy( url );
       
  2309 
       
  2310     return r;
       
  2311     }
       
  2312 #else
       
  2313 HBufC8* CDRMHelper::HasSilentRightsUrlL( CData* /*aContent*/ )
       
  2314     {
       
  2315     return NULL;
       
  2316     }
       
  2317 #endif
       
  2318 
       
  2319 
       
  2320 TInt CDRMHelper::GetSilentRightsL( const TDesC8& aUrl )
       
  2321     {
       
  2322     TInt r = KErrCancel;
       
  2323 #ifdef RD_DRM_SILENT_RIGHTS_ACQUISITION
       
  2324     TInt buttonCode = EAknSoftkeyYes;
       
  2325     HBufC8* url = NULL;
       
  2326 
       
  2327     if ( !SilentRightsAllowedL() )
       
  2328         {
       
  2329         buttonCode = DisplayQueryWithIdL( R_DRM_QRY_CONNECT_TO_ACTIVATE,
       
  2330             R_DRMHELPER_CONFIRMATION_QUERY );
       
  2331         }
       
  2332     else if ( !BrowserAPDefinedL() )
       
  2333         {
       
  2334         buttonCode = DisplayQueryWithIdL( R_DRM_QRY_CONNECT_TO_ACTIVATE,
       
  2335             R_DRMHELPER_CONFIRMATION_QUERY );
       
  2336         }
       
  2337 
       
  2338     if ( buttonCode == EAknSoftkeyYes )
       
  2339         {
       
  2340         // check if there are any APs defined
       
  2341         RCmManager cmManager;
       
  2342         cmManager.OpenLC();
       
  2343         RArray<TUint32> aps;
       
  2344         CleanupClosePushL( aps );
       
  2345         cmManager.ConnectionMethodL( aps, EFalse, EFalse, ETrue );
       
  2346         TUint32 APs( aps.Count() );
       
  2347         CleanupStack::PopAndDestroy( 2, &cmManager ); //aps, cmManager
       
  2348         if ( !APs )
       
  2349             {
       
  2350             // No AP defined
       
  2351             DisplayInfoNoteL( R_DRM_WARN_NO_CONN_DEFINED );
       
  2352             r = KErrCANoRights;
       
  2353             }
       
  2354         else
       
  2355             {
       
  2356             // ok to start download
       
  2357             CDrmHelperDownloadManager* dlMgr = CDrmHelperDownloadManager::NewL();
       
  2358             CleanupStack::PushL( dlMgr );
       
  2359             url = aUrl.AllocLC();
       
  2360 
       
  2361             if ( iUseCoeEnv )
       
  2362                 {
       
  2363                 TRAP(r, dlMgr->DownloadAndHandleRoapTriggerL( url, *iCoeEnv ) );
       
  2364                 }
       
  2365             else
       
  2366                 {
       
  2367                 TRAP(r, dlMgr->DownloadAndHandleRoapTriggerL( url ) );
       
  2368                 }
       
  2369             CleanupStack::PopAndDestroy( url );
       
  2370 
       
  2371             if ( r != KErrNone )
       
  2372                 {
       
  2373                 // rights were tried to get only if the user hasn't cancelled
       
  2374                 if ( r != KErrCancel )
       
  2375                     {
       
  2376                     if ( r == KErrCouldNotConnect )
       
  2377                         {
       
  2378                         // Connection failed with selected AP
       
  2379                         DisplayInfoNoteL( R_DRM_WARN_INVALID_OR_NO_AP );
       
  2380                         r = KErrCANoRights;
       
  2381                         }
       
  2382                     else
       
  2383                         {
       
  2384                         // get error url
       
  2385                         HBufC8* errorUrl = NULL;
       
  2386                         errorUrl = dlMgr->GetErrorUrlL();
       
  2387                         CleanupStack::PushL( errorUrl );
       
  2388 
       
  2389                         // error url is got only if temporary roap error
       
  2390                         if ( errorUrl )
       
  2391                             {
       
  2392                             // ask user whether error url should be opened
       
  2393                             buttonCode = DisplayQueryWithIdL( R_DRM_QUERY_OPEN_ERROR_URL,
       
  2394                                 R_DRMHELPER_CONFIRMATION_QUERY );
       
  2395                             if ( buttonCode == EAknSoftkeyYes )
       
  2396                                 {
       
  2397                                 // Launch browser
       
  2398                                 LaunchBrowserL( errorUrl );
       
  2399                                 }
       
  2400                             }
       
  2401                         else
       
  2402                             {
       
  2403                             DisplayInfoNoteL( R_DRM_ERR_OPENING_FAIL_PERM );
       
  2404                             }
       
  2405 
       
  2406                         CleanupStack::PopAndDestroy( errorUrl );
       
  2407                         }
       
  2408                     }
       
  2409                 }
       
  2410             CleanupStack::PopAndDestroy( dlMgr );
       
  2411             }
       
  2412         }
       
  2413 #endif // RD_DRM_SILENT_RIGHTS_ACQUISITION
       
  2414     return r;
       
  2415     }
       
  2416 
       
  2417 
       
  2418 TBool CDRMHelper::SilentRightsAllowedL()
       
  2419     {
       
  2420 #ifdef RD_DRM_SILENT_RIGHTS_ACQUISITION
       
  2421     TInt value = KErrNone;
       
  2422     CRepository* repository = CRepository::NewL( KCRUidDRMSettings );
       
  2423     repository->Get( KDRMSettingsSilentRightsAcquisition, value );
       
  2424     delete repository;
       
  2425     return (value == 0 ? EFalse: ETrue);
       
  2426 #else
       
  2427     return EFalse;
       
  2428 #endif
       
  2429     }
       
  2430 
       
  2431 
       
  2432 TBool CDRMHelper::BrowserAPDefinedL()
       
  2433     {
       
  2434     const TInt KDestinationSelectionMode( 2 );
       
  2435     TInt err( KErrNone );
       
  2436     TInt ap( 0 );
       
  2437     TInt alwaysAsk( 0 );
       
  2438     TInt defaultSnap( 0 );
       
  2439 
       
  2440     CRepository* repository( CRepository::NewL( KCRUidBrowser ) );
       
  2441     repository->Get( KBrowserDefaultAccessPoint, ap );
       
  2442     repository->Get( KBrowserAccessPointSelectionMode, alwaysAsk );
       
  2443     repository->Get( KBrowserNGDefaultSnapId, defaultSnap );
       
  2444     delete repository;
       
  2445     if ( ap <= KErrNotFound && defaultSnap <= KErrNotFound )
       
  2446         {
       
  2447         alwaysAsk = ETrue;
       
  2448         }
       
  2449     else
       
  2450         {
       
  2451         RCmManager cmManager;
       
  2452         cmManager.OpenLC();
       
  2453         if ( !alwaysAsk )
       
  2454             {
       
  2455             TRAP( err, cmManager.GetConnectionMethodInfoIntL(
       
  2456                     ap, CMManager::ECmIapId ) );
       
  2457             }
       
  2458         else if ( alwaysAsk == KDestinationSelectionMode )
       
  2459             {
       
  2460             TRAP( err, IapIdOfDefaultSnapL( cmManager, defaultSnap ) );
       
  2461             }
       
  2462         CleanupStack::PopAndDestroy( &cmManager );
       
  2463         if ( !err && ( !alwaysAsk || alwaysAsk == KDestinationSelectionMode ) )
       
  2464             {
       
  2465             return ETrue;
       
  2466             }
       
  2467         }
       
  2468     return EFalse;
       
  2469     }
       
  2470 
       
  2471 
       
  2472 #pragma mark -
       
  2473 
       
  2474 // -----------------------------------------------------------------------------
       
  2475 // CDRMHelper::CheckRightsPercentL
       
  2476 // -----------------------------------------------------------------------------
       
  2477 //
       
  2478 EXPORT_C TInt CDRMHelper::CheckRightsPercentL(
       
  2479     const TDesC& aFileName,
       
  2480     TInt aThreshold )
       
  2481     {
       
  2482     TInt ret(0);
       
  2483     HBufC* rightsIssuer = NULL;
       
  2484     HBufC* mimeType = NULL;
       
  2485     HBufC* contentURI = NULL;
       
  2486     HBufC8* contentURI8 = NULL;
       
  2487     TInt error( KErrNone );
       
  2488 
       
  2489     // check that threshold value is within bounds
       
  2490     if ( aThreshold < 0 || aThreshold > 100 )
       
  2491         {
       
  2492         User::Leave( KErrArgument );
       
  2493         }
       
  2494 
       
  2495     TVirtualPathPtr virtualPath( aFileName, KDefaultContentObject );
       
  2496 
       
  2497     CData* content = NULL;
       
  2498     TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  2499     if ( r == KErrInUse )
       
  2500         {
       
  2501         content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  2502         }
       
  2503     else
       
  2504         {
       
  2505         User::LeaveIfError( r );
       
  2506         }
       
  2507 
       
  2508     CleanupStack::PushL( content );
       
  2509 
       
  2510     // get rights-issuer URL
       
  2511     TRAPD(err, GetRightsIssuerL( *content, rightsIssuer ) );
       
  2512     if (!err )
       
  2513         {
       
  2514         CleanupStack::PushL( rightsIssuer );
       
  2515         }
       
  2516 
       
  2517     mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
  2518     contentURI = HBufC::NewLC( KUrlMaxLen );
       
  2519 
       
  2520     // create attribute set
       
  2521     RStringAttributeSet stringAttributeSet;
       
  2522     CleanupClosePushL( stringAttributeSet );
       
  2523     // add the attributes we are interested in
       
  2524     stringAttributeSet.AddL( EContentID );
       
  2525     stringAttributeSet.AddL( EMimeType );
       
  2526 
       
  2527     User::LeaveIfError( content->GetStringAttributeSet( stringAttributeSet ));
       
  2528 
       
  2529     // pass on values of string attributes
       
  2530     TPtr ptr = contentURI->Des();
       
  2531     error = stringAttributeSet.GetValue( EContentID, ptr );
       
  2532     if ( error == KErrNone )
       
  2533         {
       
  2534         TPtr ptr2 = mimeType->Des();
       
  2535         error = stringAttributeSet.GetValue( EMimeType, ptr2 );
       
  2536         if ( error == KErrNone )
       
  2537             {
       
  2538             contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  2539             contentURI8->Des().Copy( contentURI->Des() );
       
  2540             ret = DoCheckRightsPercentL(
       
  2541                 contentURI8,
       
  2542                 mimeType,
       
  2543                 rightsIssuer,
       
  2544                 StripPathAndExtension( aFileName ),
       
  2545                 aThreshold );
       
  2546             CleanupStack::PopAndDestroy( contentURI8 );
       
  2547             }
       
  2548         else
       
  2549             {
       
  2550             User::Leave( KErrArgument );
       
  2551             }
       
  2552         }
       
  2553     else
       
  2554         {
       
  2555         User::Leave( KErrArgument );
       
  2556         }
       
  2557 
       
  2558     CleanupStack::PopAndDestroy(3, mimeType); // stringAttributeSet.Close(), contentURI, mimeType
       
  2559 
       
  2560     if ( !err )
       
  2561         {
       
  2562         CleanupStack::PopAndDestroy( rightsIssuer );
       
  2563         }
       
  2564 
       
  2565     CleanupStack::PopAndDestroy( content );
       
  2566     return ret;
       
  2567     }
       
  2568 
       
  2569 
       
  2570 // -----------------------------------------------------------------------------
       
  2571 // CDRMHelper::CheckRightsPercentL
       
  2572 // -----------------------------------------------------------------------------
       
  2573 //
       
  2574 EXPORT_C TInt CDRMHelper::CheckRightsPercentL(
       
  2575     RFile& aFileHandle,
       
  2576     TInt aThreshold )
       
  2577     {
       
  2578     TInt ret(0);
       
  2579     HBufC* rightsIssuer = NULL;
       
  2580     HBufC* mimeType = NULL;
       
  2581     HBufC* contentURI = NULL;
       
  2582     HBufC8* contentURI8 = NULL;
       
  2583     TFileName fileName;
       
  2584     TInt error;
       
  2585 
       
  2586     // check that threshold value is within bounds
       
  2587     if ( aThreshold < 0 || aThreshold > 100 )
       
  2588         {
       
  2589         User::Leave( KErrArgument );
       
  2590         }
       
  2591 
       
  2592     CData* content = CData::NewLC( aFileHandle, KDefaultContentObject, EPeek );
       
  2593 
       
  2594     // get rights-issuer URL
       
  2595     TRAPD(err, GetRightsIssuerL( *content, rightsIssuer ) );
       
  2596     if (!err )
       
  2597         {
       
  2598         CleanupStack::PushL( rightsIssuer );
       
  2599         }
       
  2600 
       
  2601     mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
  2602     contentURI = HBufC::NewLC( KUrlMaxLen );
       
  2603 
       
  2604     // create attribute set
       
  2605     RStringAttributeSet stringAttributeSet;
       
  2606     CleanupClosePushL( stringAttributeSet );
       
  2607     // add the attributes we are interested in
       
  2608     stringAttributeSet.AddL( EContentID );
       
  2609     stringAttributeSet.AddL( EMimeType );
       
  2610 
       
  2611     User::LeaveIfError( content->GetStringAttributeSet( stringAttributeSet ));
       
  2612 
       
  2613     // pass on values of string attributes
       
  2614     TPtr ptr = contentURI->Des();
       
  2615     error = stringAttributeSet.GetValue( EContentID, ptr );
       
  2616     if ( error == KErrNone )
       
  2617         {
       
  2618         TPtr ptr2 = mimeType->Des();
       
  2619         error = stringAttributeSet.GetValue( EMimeType, ptr2 );
       
  2620         if ( error == KErrNone )
       
  2621             {
       
  2622             aFileHandle.Name( fileName );
       
  2623             contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  2624             contentURI8->Des().Copy( contentURI->Des() );
       
  2625             ret = DoCheckRightsPercentL(
       
  2626                 contentURI8,
       
  2627                 mimeType,
       
  2628                 rightsIssuer,
       
  2629                 StripPathAndExtension( fileName ),
       
  2630                 aThreshold );
       
  2631             CleanupStack::PopAndDestroy( contentURI8 );
       
  2632             }
       
  2633         else
       
  2634             {
       
  2635             User::Leave( KErrArgument );
       
  2636             }
       
  2637         }
       
  2638     else
       
  2639         {
       
  2640         User::Leave( KErrArgument );
       
  2641         }
       
  2642 
       
  2643     CleanupStack::PopAndDestroy(3, mimeType); // stringAttributeSet.Close(), contentURI, mimeType
       
  2644 
       
  2645     if ( !err )
       
  2646         {
       
  2647         CleanupStack::PopAndDestroy( rightsIssuer );
       
  2648         }
       
  2649 
       
  2650     CleanupStack::PopAndDestroy( content );
       
  2651     return ret;
       
  2652     }
       
  2653 
       
  2654 
       
  2655 // -----------------------------------------------------------------------------
       
  2656 // CDRMHelper::CheckRightsAmountL
       
  2657 // -----------------------------------------------------------------------------
       
  2658 //
       
  2659 EXPORT_C TInt CDRMHelper::CheckRightsAmountL(
       
  2660     const TDesC& aFileName,
       
  2661     TInt aCount,
       
  2662     TInt aDays )
       
  2663     {
       
  2664     TInt ret(0);
       
  2665     HBufC* rightsIssuer = NULL;
       
  2666     HBufC* mimeType = NULL;
       
  2667     HBufC* contentURI = NULL;
       
  2668     HBufC8* contentURI8 = NULL;
       
  2669     TInt error( KErrNone );
       
  2670     TInt drmProtected(0);
       
  2671 
       
  2672     // Leave if limit is negative
       
  2673     if ( aCount < 0 || aDays < 0 )
       
  2674         {
       
  2675         User::Leave( KErrArgument );
       
  2676         }
       
  2677 
       
  2678     TVirtualPathPtr virtualPath( aFileName, KDefaultContentObject );
       
  2679 
       
  2680     CData* content( NULL );
       
  2681     TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  2682     if ( r == KErrInUse )
       
  2683         {
       
  2684         content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  2685         }
       
  2686     else
       
  2687         {
       
  2688         User::LeaveIfError( r );
       
  2689         }
       
  2690 
       
  2691     CleanupStack::PushL( content );
       
  2692 
       
  2693     User::LeaveIfError( content->GetAttribute( EIsProtected, drmProtected ) ) ;
       
  2694     if ( drmProtected ) // do nothing if non-DRM file
       
  2695         {
       
  2696         // get rights-issuer URL
       
  2697         TRAPD(err, GetRightsIssuerL( *content, rightsIssuer ) );
       
  2698         if (!err )
       
  2699             {
       
  2700             CleanupStack::PushL( rightsIssuer );
       
  2701             }
       
  2702 
       
  2703         mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
  2704         contentURI = HBufC::NewLC( KUrlMaxLen );
       
  2705 
       
  2706         // create attribute set
       
  2707         RStringAttributeSet stringAttributeSet;
       
  2708         CleanupClosePushL( stringAttributeSet );
       
  2709         // add the attributes we are interested in
       
  2710         stringAttributeSet.AddL( EContentID );
       
  2711         stringAttributeSet.AddL( EMimeType );
       
  2712 
       
  2713         User::LeaveIfError( content->GetStringAttributeSet( stringAttributeSet ));
       
  2714 
       
  2715         // pass on values of string attributes
       
  2716         TPtr ptr = contentURI->Des();
       
  2717         error = stringAttributeSet.GetValue( EContentID, ptr );
       
  2718         if ( error == KErrNone )
       
  2719             {
       
  2720             TPtr ptr2 = mimeType->Des();
       
  2721             error = stringAttributeSet.GetValue( EMimeType, ptr2 );
       
  2722             if ( error == KErrNone )
       
  2723                 {
       
  2724                 contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  2725                 contentURI8->Des().Copy( contentURI->Des() );
       
  2726                 ret = DoCheckRightsAmountL(
       
  2727                     contentURI8,
       
  2728                     mimeType,
       
  2729                     rightsIssuer,
       
  2730                     StripPathAndExtension( aFileName ),
       
  2731                     aCount,
       
  2732                     aDays );
       
  2733                 CleanupStack::PopAndDestroy( contentURI8 );
       
  2734                 }
       
  2735             else
       
  2736                 {
       
  2737                 User::Leave( KErrArgument );
       
  2738                 }
       
  2739             }
       
  2740         else
       
  2741             {
       
  2742             User::Leave( KErrArgument );
       
  2743             }
       
  2744 
       
  2745         CleanupStack::PopAndDestroy(3, mimeType); // stringAttributeSet.Close(), contentURI, mimeType
       
  2746 
       
  2747         if ( !err )
       
  2748             {
       
  2749             CleanupStack::PopAndDestroy( rightsIssuer );
       
  2750             }
       
  2751         }
       
  2752 
       
  2753     CleanupStack::PopAndDestroy( content );
       
  2754     return ret;
       
  2755     }
       
  2756 
       
  2757 
       
  2758 // -----------------------------------------------------------------------------
       
  2759 // CDRMHelper::CheckRightsAmountL
       
  2760 // -----------------------------------------------------------------------------
       
  2761 //
       
  2762 EXPORT_C TInt CDRMHelper::CheckRightsAmountL(
       
  2763     RFile& aFileHandle,
       
  2764     TInt aCount,
       
  2765     TInt aDays )
       
  2766     {
       
  2767     TInt ret(0);
       
  2768     HBufC* rightsIssuer = NULL;
       
  2769     HBufC* mimeType = NULL;
       
  2770     HBufC* contentURI = NULL;
       
  2771     HBufC8* contentURI8 = NULL;
       
  2772     TFileName fileName;
       
  2773     TInt error;
       
  2774     TInt drmProtected(0);
       
  2775 
       
  2776     // Leave if limit is negative
       
  2777     if ( aCount < 0 || aDays < 0 )
       
  2778         {
       
  2779         User::Leave( KErrArgument );
       
  2780         }
       
  2781 
       
  2782     CData* content = CData::NewLC( aFileHandle, KDefaultContentObject, EPeek );
       
  2783     User::LeaveIfError( content->GetAttribute( EIsProtected, drmProtected ) ) ;
       
  2784     if ( drmProtected ) // do nothing if non-DRM file
       
  2785         {
       
  2786         // get rights-issuer URL
       
  2787         TRAPD(err, GetRightsIssuerL( *content, rightsIssuer ) );
       
  2788         if (!err )
       
  2789             {
       
  2790             CleanupStack::PushL( rightsIssuer );
       
  2791             }
       
  2792 
       
  2793         mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
  2794         contentURI = HBufC::NewLC( KUrlMaxLen );
       
  2795 
       
  2796         // create attribute set
       
  2797         RStringAttributeSet stringAttributeSet;
       
  2798         CleanupClosePushL( stringAttributeSet );
       
  2799         // add the attributes we are interested in
       
  2800         stringAttributeSet.AddL( EContentID );
       
  2801         stringAttributeSet.AddL( EMimeType );
       
  2802 
       
  2803         User::LeaveIfError( content->GetStringAttributeSet( stringAttributeSet ));
       
  2804 
       
  2805         // pass on values of string attributes
       
  2806         TPtr ptr = contentURI->Des();
       
  2807         error = stringAttributeSet.GetValue( EContentID, ptr );
       
  2808         if ( error == KErrNone )
       
  2809             {
       
  2810             TPtr ptr2 = mimeType->Des();
       
  2811             error = stringAttributeSet.GetValue( EMimeType, ptr2 );
       
  2812             if ( error == KErrNone )
       
  2813                 {
       
  2814                 aFileHandle.Name( fileName );
       
  2815                 contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  2816                 contentURI8->Des().Copy( contentURI->Des() );
       
  2817                 ret = DoCheckRightsAmountL(
       
  2818                     contentURI8,
       
  2819                     mimeType,
       
  2820                     rightsIssuer,
       
  2821                     StripPathAndExtension( fileName ),
       
  2822                     aCount,
       
  2823                     aDays );
       
  2824                 CleanupStack::PopAndDestroy( contentURI8 );
       
  2825 
       
  2826                 }
       
  2827             else
       
  2828                 {
       
  2829                 User::Leave( KErrArgument );
       
  2830                 }
       
  2831             }
       
  2832         else
       
  2833             {
       
  2834             User::Leave( KErrArgument );
       
  2835             }
       
  2836 
       
  2837         CleanupStack::PopAndDestroy(3, mimeType); // stringAttributeSet.Close(), contentURI, mimeType
       
  2838 
       
  2839         if ( !err )
       
  2840             {
       
  2841             CleanupStack::PopAndDestroy( rightsIssuer );
       
  2842             }
       
  2843 
       
  2844         }
       
  2845     CleanupStack::PopAndDestroy( content );
       
  2846     return ret;
       
  2847     }
       
  2848 
       
  2849 
       
  2850 // -----------------------------------------------------------------------------
       
  2851 // CDRMHelper::CheckRightsAmountL
       
  2852 // -----------------------------------------------------------------------------
       
  2853 //
       
  2854 EXPORT_C TInt CDRMHelper::CheckRightsAmountL(
       
  2855     const TDesC8& aUri,
       
  2856     TInt aCount,
       
  2857     TInt aDays )
       
  2858     {
       
  2859     TInt buttonCode( 0 );
       
  2860     RFile fileHandle;
       
  2861 
       
  2862     CleanupClosePushL( fileHandle );
       
  2863     if ( !GetFileHandleFromURIL( aUri, fileHandle ) )
       
  2864         {
       
  2865         buttonCode = CheckRightsAmountL( fileHandle, aCount, aDays );
       
  2866         }
       
  2867     CleanupStack::PopAndDestroy( &fileHandle );
       
  2868     return buttonCode;
       
  2869     }
       
  2870 
       
  2871 
       
  2872 
       
  2873 // -----------------------------------------------------------------------------
       
  2874 // CDRMHelper::DoCheckRightsPercentL
       
  2875 // -----------------------------------------------------------------------------
       
  2876 //
       
  2877 TInt CDRMHelper::DoCheckRightsPercentL(
       
  2878     HBufC8* aContentUri,
       
  2879     HBufC* aMimeType,
       
  2880     HBufC* aRIUrl,
       
  2881     const TDesC& aFileName,
       
  2882     TInt aThreshold )
       
  2883     {
       
  2884     TInt buttonCode(0);
       
  2885     TUint32 originalValue(0);
       
  2886     TTimeIntervalDays duration(0);
       
  2887     CDRMRightsConstraints* constraint = NULL;
       
  2888     TInt mask(0);
       
  2889     CDRMRights::TRestriction restriction;
       
  2890     CDRMRights::TExpiration expiration;
       
  2891     TUint32 constType;
       
  2892 
       
  2893     // get original amount of rights
       
  2894     if ( aContentUri )
       
  2895         {
       
  2896         TInt intent = Intent( aMimeType );
       
  2897         CDRMRights* rights = NULL; // rights object
       
  2898 
       
  2899         if ( iDRMCommon->GetActiveRights( *aContentUri, intent, rights ) ==
       
  2900             DRMCommon::ENoRights )
       
  2901             {
       
  2902             //no rights for given content URI, handle error
       
  2903             buttonCode = DoHandleErrorL( DRMCommon::ENoRights, aContentUri,
       
  2904                 aMimeType, aRIUrl, NULL, NULL, NULL, NULL, aFileName );
       
  2905             }
       
  2906         else
       
  2907             {
       
  2908             User::LeaveIfNull( rights );
       
  2909 
       
  2910             rights->GetRightsInfo( intent, restriction, expiration,
       
  2911                 constType );
       
  2912 
       
  2913             // No need to do anything for full or preview rights
       
  2914             if ( restriction == CDRMRights::ERestrictedRights )
       
  2915                 {
       
  2916                 if ( expiration == CDRMRights::EExpiredRights ||
       
  2917                     expiration == CDRMRights::EFutureRights )
       
  2918                     {
       
  2919                     // rights expired or not yet valid for given content URI,
       
  2920                     // handle error
       
  2921                     buttonCode = DoHandleErrorL( DRMCommon::ERightsExpired,
       
  2922                         aContentUri, aMimeType, aRIUrl, NULL, NULL, NULL, NULL, aFileName );
       
  2923                     }
       
  2924                 else
       
  2925                     {
       
  2926                     if ( (intent == DRMCommon::EPlay) &&
       
  2927                         rights->GetPlayRight( constraint ) ==
       
  2928                         DRMCommon::EOk )
       
  2929                         {
       
  2930                         mask = GetCounts( constraint, originalValue,
       
  2931                             duration );
       
  2932                         }
       
  2933                     delete constraint;
       
  2934                     constraint = NULL;
       
  2935 
       
  2936                     if ( (intent == DRMCommon::EDisplay) &&
       
  2937                         rights->GetDisplayRight( constraint ) ==
       
  2938                         DRMCommon::EOk )
       
  2939                         {
       
  2940                         mask = GetCounts( constraint, originalValue,
       
  2941                             duration );
       
  2942                         }
       
  2943                     delete constraint;
       
  2944                     constraint = NULL;
       
  2945 
       
  2946                     if ( (intent == DRMCommon::EPrint) &&
       
  2947                         rights->GetPrintRight( constraint ) ==
       
  2948                         DRMCommon::EOk )
       
  2949                         {
       
  2950                         mask = GetCounts( constraint, originalValue,
       
  2951                             duration );
       
  2952                         }
       
  2953                     delete constraint;
       
  2954                     constraint = NULL;
       
  2955 
       
  2956                     if ( (intent == DRMCommon::EExecute) &&
       
  2957                         rights->GetExecuteRight( constraint ) ==
       
  2958                         DRMCommon::EOk )
       
  2959                         {
       
  2960                         mask = GetCounts( constraint, originalValue,
       
  2961                             duration );
       
  2962                         }
       
  2963                     delete constraint;
       
  2964                     constraint = NULL;
       
  2965                     }
       
  2966                 }
       
  2967             delete rights;
       
  2968             }
       
  2969 
       
  2970         // calculate new threshold values and call next function
       
  2971         switch ( mask )
       
  2972             {
       
  2973             case KDRMHelperConstraintCount:
       
  2974                 buttonCode = DoCheckRightsAmountL( aContentUri,
       
  2975                     aMimeType, aRIUrl, aFileName,
       
  2976                     (aThreshold * originalValue) / 100,
       
  2977                     KDRMHelperDefaultTimeThreshold );
       
  2978                 break;
       
  2979 
       
  2980             case KDRMHelperConstraintTime:
       
  2981                 buttonCode = DoCheckRightsAmountL( aContentUri,
       
  2982                     aMimeType, aRIUrl, aFileName,
       
  2983                     KDRMHelperDefaultCountThreshold,
       
  2984                     (aThreshold * duration.Int()) / 100 );
       
  2985                 break;
       
  2986 
       
  2987             case (KDRMHelperConstraintCount | KDRMHelperConstraintTime):
       
  2988                 buttonCode = DoCheckRightsAmountL( aContentUri,
       
  2989                     aMimeType, aRIUrl, aFileName,
       
  2990                     (aThreshold * originalValue) / 100,
       
  2991                     (aThreshold * duration.Int()) / 100 );
       
  2992                 break;
       
  2993 
       
  2994             default:
       
  2995                 break;
       
  2996             }
       
  2997         }
       
  2998     return buttonCode;
       
  2999     }
       
  3000 
       
  3001 // -----------------------------------------------------------------------------
       
  3002 // CDRMHelper::DoCheckRightsAmountL
       
  3003 // -----------------------------------------------------------------------------
       
  3004 //
       
  3005 #ifndef RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
  3006 TInt CDRMHelper::DoCheckRightsAmountL(
       
  3007     HBufC8* aContentUri,
       
  3008     HBufC* aMimeType,
       
  3009     HBufC* aRIUrl,
       
  3010     const TDesC& aFileName,
       
  3011     TInt aCount,
       
  3012     TInt aDays )
       
  3013 #else // RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
  3014 TInt CDRMHelper::DoCheckRightsAmountL(
       
  3015     HBufC8* aContentUri,
       
  3016     HBufC* aMimeType,
       
  3017     HBufC* aRIUrl,
       
  3018     const TDesC& aFileName,
       
  3019     TInt /* aCount */,
       
  3020     TInt /* aDays */ )
       
  3021 #endif // RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
  3022     {
       
  3023     TInt errorButton(0); // button code returned by HandleErrorL
       
  3024     TInt buttonCode(0); // button code to be returned
       
  3025 #ifndef RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
  3026     TUint32 countsLeft(0); // number of counts left
       
  3027     TTime endTime; // end time of time-based rights
       
  3028     TTimeIntervalDays daysLeft(0); // days until end of time-based rights
       
  3029     TTimeIntervalMinutes minutesLeft(0); // minutes until end of time-based rights
       
  3030     TInt mask(0); // tells if object has count or time based rights
       
  3031 #endif // RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
  3032     TTime now; // current time
       
  3033     RDRMRightsClient client;
       
  3034     CDRMPointerArray<HBufC8>* individual = NULL;
       
  3035     TUint32 reason = 0;
       
  3036 
       
  3037     now.HomeTime();
       
  3038     if ( aContentUri )
       
  3039         {
       
  3040         TIntent intent = static_cast<TIntent>( Intent( aMimeType ) );
       
  3041         TRightsType type;
       
  3042         CDRMPermission* permission = NULL;
       
  3043 
       
  3044         User::LeaveIfError( client.Connect() );
       
  3045         CleanupClosePushL( client );
       
  3046         permission = client.GetActiveRightsL( intent, *aContentUri, reason );
       
  3047 
       
  3048         if ( !permission )
       
  3049             {
       
  3050             CleanupStack::PopAndDestroy( &client );
       
  3051             //no rights for given content URI, handle error
       
  3052             errorButton = DoHandleErrorL( DRMCommon::ENoRights, aContentUri,
       
  3053                 aMimeType, aRIUrl, NULL, NULL, NULL, NULL, aFileName );
       
  3054             }
       
  3055         else
       
  3056             {
       
  3057             // rights object found
       
  3058             CleanupStack::PushL( permission );
       
  3059             individual = CDRMPointerArray<HBufC8>::NewLC();
       
  3060             individual->SetAutoCleanup(ETrue);
       
  3061             client.GetSupportedIndividualsL( *individual );
       
  3062             switch ( intent )
       
  3063                 {
       
  3064                 case EPlay: type = ERightsPlay; break;
       
  3065                 case EView: type = ERightsDisplay; break;
       
  3066                 case EPrint: type = ERightsPrint; break;
       
  3067                 case EExecute: type = ERightsExecute; break;
       
  3068                 default: type = ERightsAll; break;
       
  3069                 }
       
  3070             if ( !permission->Valid( now, *individual, reason, type ) )
       
  3071                 {
       
  3072                 //rights expired for given content URI, handle error
       
  3073                 errorButton = DoHandleErrorL(
       
  3074                     DRMCommon::ERightsExpired, aContentUri,
       
  3075                     aMimeType, aRIUrl, NULL, NULL, NULL, NULL, aFileName );
       
  3076                 }
       
  3077 #ifndef RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
  3078             else
       
  3079                 {
       
  3080                 CDRMConstraint* constraint;
       
  3081                 constraint = permission->ConstraintForIntent( intent );
       
  3082                 if ( constraint )
       
  3083                     {
       
  3084                     _LIT8( KForwardLockCidStartString, "flk:" );
       
  3085                     TInt matchFound =
       
  3086                         aContentUri->FindF( KForwardLockCidStartString );
       
  3087                     // Don't display about to expire note for preview
       
  3088                     // note SD with 1 count is not a preview
       
  3089                     // unless in FL and not having RI URL
       
  3090                     if ( constraint->iOriginalCounter != 1 ||
       
  3091                         matchFound == KErrNotFound ||
       
  3092                         matchFound > 0 || // flk not found at beginning
       
  3093                         ( aRIUrl && aRIUrl->Length() > 0 ) )
       
  3094                         {
       
  3095                         mask = GetCounts( constraint, countsLeft, endTime );
       
  3096                         }
       
  3097                     }
       
  3098                 }
       
  3099 #endif // RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
  3100             CleanupStack::PopAndDestroy( individual );
       
  3101             CleanupStack::PopAndDestroy( permission );
       
  3102             CleanupStack::PopAndDestroy( &client );
       
  3103             }
       
  3104 
       
  3105 #ifndef RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
  3106         // calculate days left in case of time based constraint
       
  3107         if ( mask & ( KDRMHelperConstraintTime | KDRMHelperConstraintAccumulated ) )
       
  3108             {
       
  3109             daysLeft = endTime.DaysFrom( now );
       
  3110             endTime.MinutesFrom( now, minutesLeft );
       
  3111             }
       
  3112 
       
  3113         // display correct warning note if needed.
       
  3114         switch ( mask )
       
  3115             {
       
  3116             case KDRMHelperConstraintCount:
       
  3117                 if ( countsLeft == 1 )
       
  3118                     {
       
  3119                     if ( aRIUrl && aRIUrl->Length() > 0 )
       
  3120                         {
       
  3121                         buttonCode = DisplayQueryWithIdL(
       
  3122                             R_DRMHELPER_QUERY_EXP_1_USE_GET_NEW,
       
  3123                             R_DRMHELPER_CONFIRMATION_QUERY );
       
  3124                         }
       
  3125                     else
       
  3126                         {
       
  3127                         DisplayInfoNoteL( R_DRMHELPER_INFO_EXP_1_USE );
       
  3128                         }
       
  3129                     }
       
  3130                 else
       
  3131                     {
       
  3132                     if ( countsLeft <= (TUint32)aCount )
       
  3133                         {
       
  3134                         if ( aRIUrl && aRIUrl->Length() > 0 )
       
  3135                             {
       
  3136                             buttonCode = DisplayQueryL(
       
  3137                                 R_DRMHELPER_QUERY_EXP_N_USE_GET_NEW,
       
  3138                                 countsLeft );
       
  3139                             }
       
  3140                         else
       
  3141                             {
       
  3142                             DisplayInfoNoteL( R_DRMHELPER_INFO_EXP_N_USES , countsLeft );
       
  3143                             }
       
  3144                         }
       
  3145 
       
  3146                     }
       
  3147                 break;
       
  3148 
       
  3149             case KDRMHelperConstraintTime:
       
  3150                 if ( daysLeft.Int() == 1 )
       
  3151                     {
       
  3152                     if ( aRIUrl && aRIUrl->Length() > 0 )
       
  3153                         {
       
  3154                         buttonCode = DisplayQueryWithIdL(
       
  3155                             R_DRMHELPER_QUERY_EXP_1_DAY_GET_NEW,
       
  3156                             R_DRMHELPER_CONFIRMATION_QUERY );
       
  3157                         }
       
  3158                     else
       
  3159                         {
       
  3160                         DisplayInfoNoteL( R_DRMHELPER_INFO_EXP_1_DAY );
       
  3161                         }
       
  3162                     }
       
  3163                 else
       
  3164                     {
       
  3165                     if ( daysLeft.Int() < aDays )
       
  3166                         {
       
  3167                         if ( aRIUrl && aRIUrl->Length() > 0 )
       
  3168                             {
       
  3169                             buttonCode = DisplayQueryL(
       
  3170                                 R_DRMHELPER_QUERY_EXP_N_DAY_GET_NEW,
       
  3171                                 daysLeft.Int() );
       
  3172                             }
       
  3173                         else
       
  3174                             {
       
  3175                             DisplayInfoNoteL( R_DRMHELPER_INFO_EXP_N_DAYS , daysLeft.Int() );
       
  3176                             }
       
  3177                         }
       
  3178                     }
       
  3179                 break;
       
  3180 
       
  3181             case KDRMHelperConstraintAccumulated:
       
  3182                 if ( minutesLeft.Int() == 1 )
       
  3183                     {
       
  3184                     buttonCode = DisplayQueryWithIdL(
       
  3185                         R_DRMHELPER_QUERY_EXP_1_MIN_GET_NEW,
       
  3186                         R_DRMHELPER_CONFIRMATION_QUERY );
       
  3187                     }
       
  3188                 else
       
  3189                     {
       
  3190                     if ( daysLeft.Int() < KDRMHelperAccumulatedTimeLimit )
       
  3191                         {
       
  3192                         buttonCode = DisplayQueryL(
       
  3193                             R_DRMHELPER_QUERY_EXP_N_MIN_GET_NEW,
       
  3194                             minutesLeft.Int() );
       
  3195                         }
       
  3196                     }
       
  3197                 break;
       
  3198 
       
  3199             case (KDRMHelperConstraintTime | KDRMHelperConstraintAccumulated):
       
  3200             case (KDRMHelperConstraintCount | KDRMHelperConstraintAccumulated):
       
  3201             case (KDRMHelperConstraintCount | KDRMHelperConstraintTime):
       
  3202                 if ( countsLeft <= (TUint32)aCount || daysLeft.Int() < aDays )
       
  3203             {
       
  3204             if ( aRIUrl && aRIUrl->Length() > 0 )
       
  3205                 {
       
  3206                 buttonCode = DisplayQueryWithIdL(
       
  3207                     R_DRMHELPER_QUERY_EXP_MANY_CONSTR,
       
  3208                     R_DRMHELPER_CONFIRMATION_QUERY );
       
  3209 
       
  3210                 }
       
  3211             else
       
  3212                 {
       
  3213                 buttonCode = DisplayQueryWithIdL(
       
  3214                     R_DRMHELPER_USAGE_RIGHTS_TO_EXPIRE,
       
  3215                     R_DRMHELPER_CONFIRMATION_QUERY );
       
  3216                 if ( buttonCode )
       
  3217                     {
       
  3218                     LaunchDetailsViewEmbeddedL( aContentUri );
       
  3219                     buttonCode = 0;
       
  3220                     }
       
  3221                 }
       
  3222 
       
  3223             }
       
  3224                 break;
       
  3225 
       
  3226             default:
       
  3227                 break;
       
  3228             }
       
  3229 #endif // RD_DRM_REMOVAL_OF_EXPIRATION_WARNING_PROMPTS
       
  3230 
       
  3231         // Launch details view if needed
       
  3232         if ( buttonCode == EAknSoftkeyYes )
       
  3233             {
       
  3234             LaunchBrowserL( aRIUrl );
       
  3235             }
       
  3236 
       
  3237         if ( errorButton )
       
  3238             {
       
  3239             buttonCode = errorButton;
       
  3240             }
       
  3241         }
       
  3242     return buttonCode;
       
  3243     }
       
  3244 
       
  3245 EXPORT_C void CDRMHelper::SetCountLimitL( TUint /*aCounts*/ )
       
  3246     {
       
  3247     }
       
  3248 
       
  3249 EXPORT_C void CDRMHelper::SetTimeLimitL( TUint /*aDays*/ )
       
  3250     {
       
  3251     }
       
  3252 
       
  3253 EXPORT_C void CDRMHelper::SetPercentageLimitL( TUint /*aPercentage*/ )
       
  3254     {
       
  3255     }
       
  3256 
       
  3257 // -----------------------------------------------------------------------------
       
  3258 // CDRMHelper::GetCounts
       
  3259 // -----------------------------------------------------------------------------
       
  3260 //
       
  3261 TInt CDRMHelper::GetCounts(
       
  3262     CDRMRightsConstraints* aConstraint,
       
  3263     TUint32& aOriginalCount,
       
  3264     TTimeIntervalDays& aDuration )
       
  3265     {
       
  3266     TInt ret(0);
       
  3267     TTime startTime;
       
  3268     TTime endTime;
       
  3269     TUint32 countsLeft;
       
  3270     TTimeIntervalSeconds interval;
       
  3271     TUint32 count(0);
       
  3272 
       
  3273     aOriginalCount = KMaxTUint32;
       
  3274     interval = 0;
       
  3275     aDuration = 0;
       
  3276     if ( aConstraint->GetCounters( countsLeft, count ) ==
       
  3277         DRMCommon::EOk )
       
  3278         {
       
  3279         ret |= KDRMHelperConstraintCount;
       
  3280         aOriginalCount = count;
       
  3281         }
       
  3282     if ( aConstraint->GetTimedCounters( countsLeft, count ) ==
       
  3283         DRMCommon::EOk )
       
  3284         {
       
  3285         ret |= KDRMHelperConstraintCount;
       
  3286         aOriginalCount = Min( count, aOriginalCount );
       
  3287         }
       
  3288     if ( aConstraint->GetStartTime( startTime ) == DRMCommon::EOk )
       
  3289         {
       
  3290         aConstraint->GetEndTime( endTime );
       
  3291         aDuration = endTime.DaysFrom( startTime );
       
  3292         ret |= KDRMHelperConstraintTime;
       
  3293         }
       
  3294     if ( aConstraint->GetInterval( interval ) == DRMCommon::EOk )
       
  3295         {
       
  3296         // change to days
       
  3297         aDuration = interval.Int() / (60*60*24);
       
  3298         ret |= KDRMHelperConstraintTime;
       
  3299         }
       
  3300     if ( aConstraint->GetAccumulated( interval ) == DRMCommon::EOk )
       
  3301         {
       
  3302         // change to days
       
  3303         aDuration = Min( aDuration.Int(), interval.Int() / (60*60*24) );
       
  3304         ret |= KDRMHelperConstraintAccumulated;
       
  3305         }
       
  3306     return ret;
       
  3307     }
       
  3308 
       
  3309 // -----------------------------------------------------------------------------
       
  3310 // CDRMHelper::GetCounts
       
  3311 // -----------------------------------------------------------------------------
       
  3312 //
       
  3313 TInt CDRMHelper::GetCounts(
       
  3314     CDRMRightsConstraints* aConstraint,
       
  3315     TUint32& aCountsLeft,
       
  3316     TTime& aEndTime )
       
  3317     {
       
  3318     TInt ret(0);
       
  3319     TUint32 originalCount;
       
  3320     TTime start;
       
  3321     TTimeIntervalSeconds interval;
       
  3322     TUint32 count(0);
       
  3323 
       
  3324     aCountsLeft = KMaxTUint32;
       
  3325     aEndTime = Time::NullTTime();
       
  3326     if ( aConstraint->GetCounters( count, originalCount ) ==
       
  3327         DRMCommon::EOk )
       
  3328         {
       
  3329         ret |= KDRMHelperConstraintCount;
       
  3330         aCountsLeft = count;
       
  3331         }
       
  3332     if ( aConstraint->GetTimedCounters( count, originalCount ) ==
       
  3333         DRMCommon::EOk )
       
  3334         {
       
  3335         ret |= KDRMHelperConstraintCount;
       
  3336         aCountsLeft = Min( count, aCountsLeft );
       
  3337         }
       
  3338     if ( aConstraint->GetEndTime( aEndTime ) == DRMCommon::EOk )
       
  3339         {
       
  3340         ret |= KDRMHelperConstraintTime;
       
  3341         }
       
  3342     if ( aConstraint->GetInterval( interval ) == DRMCommon::EOk )
       
  3343         {
       
  3344         if ( aConstraint->GetIntervalStart( start ) == DRMCommon::ENoRights )
       
  3345             {
       
  3346             // interval not yet started
       
  3347             start.HomeTime();
       
  3348             }
       
  3349         aEndTime = start + interval;
       
  3350         ret |= KDRMHelperConstraintTime;
       
  3351         }
       
  3352     if ( aConstraint->GetAccumulated( interval ) == DRMCommon::EOk )
       
  3353         {
       
  3354         if ( aEndTime != Time::NullTTime() &&
       
  3355             aEndTime + interval > aEndTime ||
       
  3356             aEndTime == Time::NullTTime() )
       
  3357             {
       
  3358             aEndTime.HomeTime();
       
  3359             aEndTime = aEndTime + interval;
       
  3360             ret |= KDRMHelperConstraintAccumulated;
       
  3361             }
       
  3362         }
       
  3363     return ret;
       
  3364     }
       
  3365 
       
  3366 // -----------------------------------------------------------------------------
       
  3367 // CDRMHelper::GetCounts
       
  3368 // -----------------------------------------------------------------------------
       
  3369 //
       
  3370 TInt CDRMHelper::GetCounts(
       
  3371     CDRMConstraint* aConstraint,
       
  3372     TUint32& aOriginalCount,
       
  3373     TTimeIntervalDays& aDuration )
       
  3374     {
       
  3375     TInt ret(0);
       
  3376     TTime endTime;
       
  3377 
       
  3378     aOriginalCount = KMaxTUint32;
       
  3379     aDuration = 0;
       
  3380     if ( aConstraint->iActiveConstraints & EConstraintCounter ||
       
  3381         aConstraint->iActiveConstraints & EConstraintTimedCounter )
       
  3382         {
       
  3383         ret |= KDRMHelperConstraintCount;
       
  3384         aOriginalCount = aConstraint->iOriginalCounter;
       
  3385         }
       
  3386     if ( aConstraint->iActiveConstraints & EConstraintStartTime &&
       
  3387         aConstraint->iActiveConstraints & EConstraintEndTime )
       
  3388         {
       
  3389         aDuration = aConstraint->iEndTime.DaysFrom( aConstraint->iStartTime );
       
  3390         ret |= KDRMHelperConstraintTime;
       
  3391         }
       
  3392     if ( aConstraint->iActiveConstraints & EConstraintInterval )
       
  3393         {
       
  3394         // change to days
       
  3395         aDuration = aConstraint->iInterval.Int() / ( 60 * 60 * 24 );
       
  3396         ret |= KDRMHelperConstraintTime;
       
  3397         }
       
  3398     if ( aConstraint->iActiveConstraints & EConstraintAccumulated )
       
  3399         {
       
  3400         // change to days
       
  3401         aDuration = Min( aDuration.Int(),
       
  3402             aConstraint->iAccumulatedTime.Int() / (60*60*24) );
       
  3403         ret |= KDRMHelperConstraintAccumulated;
       
  3404         }
       
  3405     return ret;
       
  3406     }
       
  3407 
       
  3408 // -----------------------------------------------------------------------------
       
  3409 // CDRMHelper::GetCounts
       
  3410 // -----------------------------------------------------------------------------
       
  3411 //
       
  3412 TInt CDRMHelper::GetCounts(
       
  3413     CDRMConstraint* aConstraint,
       
  3414     TUint32& aCountsLeft,
       
  3415     TTime& aEndTime )
       
  3416     {
       
  3417     TInt ret(0);
       
  3418     TTime start;
       
  3419 
       
  3420     aCountsLeft = KDRMCounterMax;
       
  3421     aEndTime = Time::NullTTime();
       
  3422     if ( aConstraint->iActiveConstraints & EConstraintCounter )
       
  3423         {
       
  3424         ret |= KDRMHelperConstraintCount;
       
  3425         aCountsLeft = aConstraint->iCounter;
       
  3426         }
       
  3427     if ( aConstraint->iActiveConstraints & EConstraintTimedCounter )
       
  3428         {
       
  3429         ret |= KDRMHelperConstraintCount;
       
  3430         if ( aConstraint->iTimedCounter < aCountsLeft )
       
  3431             {
       
  3432             aCountsLeft = aConstraint->iTimedCounter;
       
  3433             }
       
  3434         }
       
  3435     if ( aConstraint->iActiveConstraints & EConstraintEndTime )
       
  3436         {
       
  3437         ret |= KDRMHelperConstraintTime;
       
  3438         aEndTime = aConstraint->iEndTime;
       
  3439         }
       
  3440     if ( aConstraint->iActiveConstraints & EConstraintInterval )
       
  3441         {
       
  3442         start = aConstraint->iIntervalStart;
       
  3443         if ( start == Time::NullTTime() )
       
  3444             {
       
  3445             start.HomeTime();
       
  3446             }
       
  3447         aEndTime = start + aConstraint->iInterval;
       
  3448         ret |= KDRMHelperConstraintTime;
       
  3449         }
       
  3450     if ( aConstraint->iActiveConstraints & EConstraintAccumulated )
       
  3451         {
       
  3452         if ( aEndTime != Time::NullTTime() &&
       
  3453             aEndTime + aConstraint->iAccumulatedTime > aEndTime ||
       
  3454             aEndTime == Time::NullTTime() )
       
  3455             {
       
  3456             aEndTime.HomeTime();
       
  3457             aEndTime = aEndTime + aConstraint->iAccumulatedTime;
       
  3458             ret |= KDRMHelperConstraintAccumulated;
       
  3459             }
       
  3460         }
       
  3461     return ret;
       
  3462     }
       
  3463 
       
  3464 #pragma mark -
       
  3465 
       
  3466 // -----------------------------------------------------------------------------
       
  3467 // CDRMHelper::LaunchDetailsViewEmbeddedL
       
  3468 // -----------------------------------------------------------------------------
       
  3469 //
       
  3470 EXPORT_C void CDRMHelper::LaunchDetailsViewEmbeddedL( const HBufC8* aContentURI )
       
  3471     {
       
  3472     CDRMRights* rights = NULL; // rights object
       
  3473 
       
  3474     if ( iDRMCommon->GetActiveRights( *aContentURI, 0, rights ) ==
       
  3475         DRMCommon::ENoRights )
       
  3476         {
       
  3477         //no rights for given content URI, leave
       
  3478         User::Leave( DRMCommon::ENoRights );
       
  3479         }
       
  3480     else
       
  3481         {
       
  3482         User::LeaveIfNull( rights );
       
  3483 
       
  3484         // get local ID
       
  3485         TUint32 localId = rights->GetLocalID();
       
  3486         HBufC* launchParam;
       
  3487 
       
  3488 
       
  3489         // create string needed to launch rights manager ui embedded.
       
  3490         CreateLaunchParamL( localId, aContentURI, launchParam );
       
  3491         CleanupStack::PushL( launchParam );
       
  3492         LaunchRightsManagerUiL( *launchParam );
       
  3493         CleanupStack::PopAndDestroy( launchParam );
       
  3494 
       
  3495         }
       
  3496 
       
  3497     // delete rights
       
  3498     delete rights;
       
  3499     }
       
  3500 
       
  3501 
       
  3502 // -----------------------------------------------------------------------------
       
  3503 // CDRMHelper::LaunchDetailsViewEmbeddedL
       
  3504 // -----------------------------------------------------------------------------
       
  3505 //
       
  3506 EXPORT_C void CDRMHelper::LaunchDetailsViewEmbeddedL( const TDesC& aFileName )
       
  3507     {
       
  3508     HBufC* contentURI( NULL );
       
  3509     HBufC8* contentURI8( NULL );
       
  3510     TInt error( KErrNone );
       
  3511 
       
  3512     TVirtualPathPtr virtualPath( aFileName, KDefaultContentObject );
       
  3513 
       
  3514     CData* content( NULL );
       
  3515     TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  3516     if ( r == KErrInUse )
       
  3517         {
       
  3518         content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  3519         }
       
  3520     else
       
  3521         {
       
  3522         User::LeaveIfError( r );
       
  3523         }
       
  3524 
       
  3525     CleanupStack::PushL( content );
       
  3526 
       
  3527     contentURI = HBufC::NewLC( KUrlMaxLen );
       
  3528     TPtr ptr = contentURI->Des();
       
  3529     error = content->GetStringAttribute( EContentID, ptr );
       
  3530     if ( !error )
       
  3531         {
       
  3532         contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  3533         contentURI8->Des().Copy( contentURI->Des() );
       
  3534         LaunchDetailsViewEmbeddedL( contentURI8 );
       
  3535         CleanupStack::PopAndDestroy( contentURI8 );
       
  3536         }
       
  3537     else
       
  3538         {
       
  3539         User::Leave( KErrArgument );
       
  3540         }
       
  3541     CleanupStack::PopAndDestroy( 2, content ); // contentURI, content
       
  3542     }
       
  3543 
       
  3544 
       
  3545 // -----------------------------------------------------------------------------
       
  3546 // CDRMHelper::LaunchDetailsViewEmbeddedL
       
  3547 // -----------------------------------------------------------------------------
       
  3548 //
       
  3549 EXPORT_C void CDRMHelper::LaunchDetailsViewEmbeddedL( RFile& aFileHandle )
       
  3550     {
       
  3551     HBufC* contentURI = NULL;
       
  3552     HBufC8* contentURI8 = NULL;
       
  3553     TInt error;
       
  3554 
       
  3555     CData* content = CData::NewLC( aFileHandle, KDefaultContentObject, EPeek );
       
  3556 
       
  3557     contentURI = HBufC::NewLC( KUrlMaxLen );
       
  3558     TPtr ptr = contentURI->Des();
       
  3559     error = content->GetStringAttribute( EContentID, ptr );
       
  3560     if ( !error )
       
  3561         {
       
  3562         contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  3563         contentURI8->Des().Copy( contentURI->Des() );
       
  3564         LaunchDetailsViewEmbeddedL( contentURI8 );
       
  3565         CleanupStack::PopAndDestroy( contentURI8 );
       
  3566         }
       
  3567     else
       
  3568         {
       
  3569         User::Leave( KErrArgument );
       
  3570         }
       
  3571     CleanupStack::PopAndDestroy( 2, content ); // contentURI, content
       
  3572     }
       
  3573 
       
  3574 EXPORT_C void CDRMHelper::LaunchDetailsViewEmbeddedL(
       
  3575     const TDesC8& /*aURI*/ )
       
  3576     {
       
  3577     }
       
  3578 
       
  3579 // -----------------------------------------------------------------------------
       
  3580 // CDRMHelper::CreateLaunchParamL
       
  3581 // -----------------------------------------------------------------------------
       
  3582 //
       
  3583 void CDRMHelper::CreateLaunchParamL(
       
  3584     TUint32 aLocalId,
       
  3585     const HBufC8* aUrl,
       
  3586     HBufC*& aLaunchParam )
       
  3587     {
       
  3588     TInt index;
       
  3589 
       
  3590     // MaxInt will fit into 10 characters
       
  3591     HBufC* b( HBufC::NewLC( 10 ) );
       
  3592     b->Des().NumUC( aLocalId );
       
  3593     HBufC* localIDBuf( b->ReAllocL( b->Des().Length() ) );
       
  3594     CleanupStack::Pop( b );
       
  3595     b = NULL;
       
  3596     CleanupStack::PushL( localIDBuf );
       
  3597 
       
  3598     // length of startparam is always 1 and 2 spaces are needed
       
  3599     TInt length = 1 + aUrl->Length() + localIDBuf->Des().Length() + 2;
       
  3600 
       
  3601     aLaunchParam = HBufC::NewMaxL( length );
       
  3602 
       
  3603     TPtr ptr( aLaunchParam->Des() );
       
  3604     ptr.SetLength( 0 );
       
  3605     _LIT( KOne, "1" );
       
  3606     _LIT( KTwo, "2" );
       
  3607     _LIT( KSpace, " " );
       
  3608 
       
  3609     // start param is 1 for embedded launch and 2 for launching details view
       
  3610     // standalone
       
  3611     if ( iUseCoeEnv )
       
  3612         {
       
  3613         ptr.Append( KOne() );
       
  3614         }
       
  3615     else
       
  3616         {
       
  3617         ptr.Append( KTwo() );
       
  3618         }
       
  3619     ptr.Append( KSpace() );
       
  3620     ptr.Append( localIDBuf->Des() );
       
  3621     ptr.Append( KSpace() );
       
  3622 
       
  3623     index = ptr.Length();
       
  3624     ptr.SetLength( length );
       
  3625     for ( TInt i = 0 ; i < aUrl->Length(); i++ )
       
  3626         {
       
  3627         ptr[index++] = ( unsigned char ) (*aUrl)[i];
       
  3628         }
       
  3629 
       
  3630     CleanupStack::PopAndDestroy( localIDBuf );
       
  3631     }
       
  3632 
       
  3633 
       
  3634 // -----------------------------------------------------------------------------
       
  3635 // CDRMHelper::GetRightsDetailsL
       
  3636 // -----------------------------------------------------------------------------
       
  3637 //
       
  3638 EXPORT_C void CDRMHelper::GetRightsDetailsL(
       
  3639     const TDesC& aFileName,
       
  3640     TUint32 aIntent,
       
  3641     TBool& aExpired,
       
  3642     TBool& aSendingAllowed,
       
  3643     CDRMHelperRightsConstraints*& aPlay,
       
  3644     CDRMHelperRightsConstraints*& aDisplay,
       
  3645     CDRMHelperRightsConstraints*& aExecute,
       
  3646     CDRMHelperRightsConstraints*& aPrint )
       
  3647     {
       
  3648     HBufC* contentURI = NULL;
       
  3649     HBufC8* contentURI8 = NULL;
       
  3650     TInt drmProtected(0);
       
  3651     TInt intent;
       
  3652 
       
  3653     TVirtualPathPtr virtualPath( aFileName, KDefaultContentObject );
       
  3654 
       
  3655     CData* content( NULL );
       
  3656     TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  3657     if ( r == KErrInUse )
       
  3658         {
       
  3659         content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  3660         }
       
  3661     else
       
  3662         {
       
  3663         User::LeaveIfError( r );
       
  3664         }
       
  3665 
       
  3666     CleanupStack::PushL( content );
       
  3667 
       
  3668     User::LeaveIfError( content->GetAttribute( EIsProtected, drmProtected ) ) ;
       
  3669 
       
  3670     if ( !drmProtected )
       
  3671         {
       
  3672         User::Leave( KErrArgument );
       
  3673         }
       
  3674 
       
  3675     User::LeaveIfError( content->GetAttribute( EIsForwardable, aSendingAllowed ) ) ;
       
  3676 
       
  3677     contentURI = HBufC::NewLC( KUrlMaxLen );
       
  3678     TPtr ptr = contentURI->Des();
       
  3679     User::LeaveIfError( content->GetStringAttribute( EContentID, ptr ) );
       
  3680 
       
  3681     contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  3682     contentURI8->Des().Copy( contentURI->Des() );
       
  3683     if ( aIntent == ContentAccess::EPlay ||
       
  3684         aIntent == ContentAccess::EView ||
       
  3685         aIntent == ContentAccess::EExecute ||
       
  3686         aIntent == ContentAccess::EPrint )
       
  3687         {
       
  3688         intent = aIntent;
       
  3689         }
       
  3690     else
       
  3691         {
       
  3692         // not valid CAF intent, determine intent from mimetype
       
  3693         HBufC* mimetype = HBufC::NewLC( KUrlMaxLen );
       
  3694         ptr.Set( mimetype->Des() );
       
  3695         content->GetStringAttribute( EMimeType, ptr );
       
  3696         intent = Intent( mimetype );
       
  3697         CleanupStack::PopAndDestroy( mimetype );
       
  3698         }
       
  3699     DoGetRightsDetailsL( contentURI8, intent, aExpired, aPlay, aDisplay,
       
  3700         aExecute, aPrint );
       
  3701     CleanupStack::PopAndDestroy( 3, content ); // contentURI8, contentURI, content
       
  3702     }
       
  3703 
       
  3704 // -----------------------------------------------------------------------------
       
  3705 // CDRMHelper::GetRightsDetailsL
       
  3706 // -----------------------------------------------------------------------------
       
  3707 //
       
  3708 EXPORT_C void CDRMHelper::GetRightsDetailsL(
       
  3709     RFile& aFileHandle,
       
  3710     TUint32 aIntent,
       
  3711     TBool& aExpired,
       
  3712     TBool& aSendingAllowed,
       
  3713     CDRMHelperRightsConstraints*& aPlay,
       
  3714     CDRMHelperRightsConstraints*& aDisplay,
       
  3715     CDRMHelperRightsConstraints*& aExecute,
       
  3716     CDRMHelperRightsConstraints*& aPrint )
       
  3717     {
       
  3718     HBufC* contentURI = NULL;
       
  3719     HBufC8* contentURI8 = NULL;
       
  3720     TInt drmProtected(0);
       
  3721     TInt intent;
       
  3722 
       
  3723     CData* content = CData::NewLC( aFileHandle, KDefaultContentObject, EPeek );
       
  3724 
       
  3725     User::LeaveIfError( content->GetAttribute( EIsProtected, drmProtected ) ) ;
       
  3726 
       
  3727     if ( !drmProtected )
       
  3728         {
       
  3729         User::Leave( KErrArgument );
       
  3730         }
       
  3731 
       
  3732     User::LeaveIfError( content->GetAttribute( EIsForwardable, aSendingAllowed ) ) ;
       
  3733 
       
  3734     contentURI = HBufC::NewLC( KUrlMaxLen );
       
  3735     TPtr ptr = contentURI->Des();
       
  3736     User::LeaveIfError( content->GetStringAttribute( EContentID, ptr ) );
       
  3737 
       
  3738     contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  3739     contentURI8->Des().Copy( contentURI->Des() );
       
  3740     if ( aIntent == ContentAccess::EPlay ||
       
  3741         aIntent == ContentAccess::EView ||
       
  3742         aIntent == ContentAccess::EExecute ||
       
  3743         aIntent == ContentAccess::EPrint )
       
  3744         {
       
  3745         intent = aIntent;
       
  3746         }
       
  3747     else
       
  3748         {
       
  3749         // not valid CAF intent, determine intent from mimetype
       
  3750         HBufC* mimetype = HBufC::NewLC( KUrlMaxLen );
       
  3751         ptr.Set( mimetype->Des() );
       
  3752         content->GetStringAttribute( EMimeType, ptr );
       
  3753         intent = Intent( mimetype );
       
  3754         CleanupStack::PopAndDestroy( mimetype );
       
  3755         }
       
  3756 
       
  3757     DoGetRightsDetailsL( contentURI8, intent, aExpired, aPlay, aDisplay,
       
  3758         aExecute, aPrint );
       
  3759 
       
  3760     CleanupStack::PopAndDestroy( 3, content );  // contentURI8, contentURI, content
       
  3761     }
       
  3762 
       
  3763 
       
  3764 // -----------------------------------------------------------------------------
       
  3765 // CDRMHelper::DoGetRightsDetailsL
       
  3766 // -----------------------------------------------------------------------------
       
  3767 //
       
  3768 void CDRMHelper::DoGetRightsDetailsL(
       
  3769     HBufC8* aContentUri,
       
  3770     TUint32 aIntent,
       
  3771     TBool& aExpired,
       
  3772     CDRMHelperRightsConstraints*& aPlay,
       
  3773     CDRMHelperRightsConstraints*& aDisplay,
       
  3774     CDRMHelperRightsConstraints*& aExecute,
       
  3775     CDRMHelperRightsConstraints*& aPrint )
       
  3776     {
       
  3777     CDRMRights* activeRights = NULL;
       
  3778 
       
  3779     // GetActiveRights returns negative value if rights are not valid
       
  3780     if ( iDRMCommon->GetActiveRights( *aContentUri, aIntent, activeRights ) > 0 )
       
  3781         {
       
  3782         // rights are valid
       
  3783         aExpired = EFalse;
       
  3784         CleanupStack::PushL( activeRights );
       
  3785         GetConstraintsL( *activeRights,
       
  3786                 aPlay,
       
  3787                 aDisplay,
       
  3788                 aExecute,
       
  3789                 aPrint );
       
  3790         CleanupStack::PopAndDestroy( activeRights );
       
  3791         }
       
  3792     else
       
  3793         {
       
  3794         // rights are not valid, check if they are future or expired.
       
  3795         TInt expiration = GetExpirationDetails(
       
  3796             aContentUri, aIntent, activeRights );
       
  3797         CleanupStack::PushL( activeRights );
       
  3798         switch ( expiration )
       
  3799             {
       
  3800             case CDRMRights::EExpiredRights:
       
  3801                 // expired rights
       
  3802                 aExpired = ETrue;
       
  3803                 break;
       
  3804             case CDRMRights::EFutureRights:
       
  3805                 // future rights, mark it as "expired" but return also
       
  3806                 // constraint objects
       
  3807                 aExpired = ETrue;
       
  3808                 GetConstraintsL( *activeRights,
       
  3809                         aPlay,
       
  3810                         aDisplay,
       
  3811                         aExecute,
       
  3812                         aPrint );
       
  3813                 break;
       
  3814             case KErrCANoRights:
       
  3815                 // no rights, leave
       
  3816                 User::Leave( KErrCANoRights );
       
  3817                 break;
       
  3818             default:
       
  3819                 // something else, should never come here
       
  3820                 User::Leave( KErrGeneral );
       
  3821                 break;
       
  3822             }
       
  3823         CleanupStack::PopAndDestroy( activeRights );
       
  3824         }
       
  3825     }
       
  3826 
       
  3827 // -----------------------------------------------------------------------------
       
  3828 // CDRMHelper::GetConstraintsL
       
  3829 // -----------------------------------------------------------------------------
       
  3830 //
       
  3831 void CDRMHelper::GetConstraintsL(
       
  3832     CDRMRights& aRights,
       
  3833     CDRMHelperRightsConstraints*& aPlay,
       
  3834     CDRMHelperRightsConstraints*& aDisplay,
       
  3835     CDRMHelperRightsConstraints*& aExecute,
       
  3836     CDRMHelperRightsConstraints*& aPrint )
       
  3837     {
       
  3838     CDRMRightsConstraints* constraint( NULL );
       
  3839     CDRMHelperRightsConstraints* play( NULL );
       
  3840     CDRMHelperRightsConstraints* display( NULL );
       
  3841     CDRMHelperRightsConstraints* execute( NULL );
       
  3842     CDRMHelperRightsConstraints* print( NULL );
       
  3843     TInt poppableItems(0);
       
  3844 
       
  3845     aRights.GetPlayRight( constraint );
       
  3846     if ( constraint )
       
  3847         {
       
  3848         // takes ownership of constraint
       
  3849         play = CDRMHelperRightsConstraints::NewLC( constraint );
       
  3850         poppableItems++;
       
  3851         constraint = NULL;
       
  3852         }
       
  3853     aRights.GetDisplayRight( constraint );
       
  3854     if ( constraint )
       
  3855         {
       
  3856         // takes ownership of constraint
       
  3857         display = CDRMHelperRightsConstraints::NewLC( constraint );
       
  3858         poppableItems++;
       
  3859         constraint = NULL;
       
  3860         }
       
  3861     aRights.GetExecuteRight( constraint );
       
  3862     if ( constraint )
       
  3863         {
       
  3864         // takes ownership of constraint
       
  3865         execute = CDRMHelperRightsConstraints::NewLC( constraint );
       
  3866         poppableItems++;
       
  3867         constraint = NULL;
       
  3868         }
       
  3869     aRights.GetPrintRight( constraint );
       
  3870     if ( constraint )
       
  3871         {
       
  3872         // takes ownership of constraint
       
  3873         print = CDRMHelperRightsConstraints::NewLC( constraint );
       
  3874         poppableItems++;
       
  3875         constraint = NULL;
       
  3876         }
       
  3877     if ( poppableItems )
       
  3878         {
       
  3879         CleanupStack::Pop( poppableItems );
       
  3880         }
       
  3881     aPlay = play;
       
  3882     aDisplay = display;
       
  3883     aExecute = execute;
       
  3884     aPrint = print;
       
  3885     }
       
  3886 
       
  3887 // -----------------------------------------------------------------------------
       
  3888 // CDRMHelper::GetRightsDetailsL
       
  3889 // -----------------------------------------------------------------------------
       
  3890 //
       
  3891 EXPORT_C void CDRMHelper::GetRightsDetailsL( const TDesC& aFileName,
       
  3892     TUint32 aIntent, TBool& aExpired, TBool& aSendingAllowed,
       
  3893     CDRMRightsConstraints*& aPlay,
       
  3894     CDRMRightsConstraints*& aDisplay,
       
  3895     CDRMRightsConstraints*& aExecute,
       
  3896     CDRMRightsConstraints*& aPrint )
       
  3897     {
       
  3898     TVirtualPathPtr virtualPath( aFileName, KDefaultContentObject );
       
  3899     TInt intent;
       
  3900 
       
  3901     CData* content( NULL );
       
  3902     TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  3903     if ( r == KErrInUse )
       
  3904         {
       
  3905         content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  3906         }
       
  3907     else
       
  3908         {
       
  3909         User::LeaveIfError( r );
       
  3910         }
       
  3911 
       
  3912     CleanupStack::PushL( content );
       
  3913 
       
  3914     // if aIntent is not any of CAF intents, use default intent
       
  3915     if ( aIntent == ContentAccess::EPlay ||
       
  3916         aIntent == ContentAccess::EView ||
       
  3917         aIntent == ContentAccess::EExecute ||
       
  3918         aIntent == ContentAccess::EPrint )
       
  3919         {
       
  3920         intent = aIntent;
       
  3921         }
       
  3922     else
       
  3923         {
       
  3924         // not valid CAF intent, determine intent from mimetype
       
  3925         HBufC* mimetype = HBufC::NewLC( KUrlMaxLen );
       
  3926         TPtr ptr = mimetype->Des();
       
  3927         content->GetStringAttribute( EMimeType, ptr );
       
  3928         intent = Intent( mimetype );
       
  3929         CleanupStack::PopAndDestroy( mimetype );
       
  3930         }
       
  3931 
       
  3932     DoGetRightsDetailsL( content, intent, aExpired, aSendingAllowed, aPlay,
       
  3933         aDisplay, aExecute, aPrint );
       
  3934 
       
  3935     CleanupStack::PopAndDestroy( content ); // content
       
  3936     }
       
  3937 
       
  3938 // -----------------------------------------------------------------------------
       
  3939 // CDRMHelper::GetRightsDetailsL
       
  3940 // -----------------------------------------------------------------------------
       
  3941 //
       
  3942 EXPORT_C void CDRMHelper::GetRightsDetailsL( RFile& aFileHandle,
       
  3943     TUint32 aIntent, TBool& aExpired, TBool& aSendingAllowed,
       
  3944     CDRMRightsConstraints*& aPlay,
       
  3945     CDRMRightsConstraints*& aDisplay,
       
  3946     CDRMRightsConstraints*& aExecute,
       
  3947     CDRMRightsConstraints*& aPrint )
       
  3948     {
       
  3949     TInt intent;
       
  3950     CData* content = CData::NewLC( aFileHandle, KDefaultContentObject, EPeek );
       
  3951 
       
  3952     // if aIntent is not any of CAF intents, use default intent
       
  3953     if ( aIntent == ContentAccess::EPlay ||
       
  3954         aIntent == ContentAccess::EView ||
       
  3955         aIntent == ContentAccess::EExecute ||
       
  3956         aIntent == ContentAccess::EPrint )
       
  3957         {
       
  3958         intent = aIntent;
       
  3959         }
       
  3960     else
       
  3961         {
       
  3962         // not valid CAF intent, determine intent from mimetype
       
  3963         HBufC* mimetype = HBufC::NewLC( KUrlMaxLen );
       
  3964         TPtr ptr = mimetype->Des();
       
  3965         content->GetStringAttribute( EMimeType, ptr );
       
  3966         intent = Intent( mimetype );
       
  3967         CleanupStack::PopAndDestroy( mimetype );
       
  3968         }
       
  3969     DoGetRightsDetailsL( content, intent, aExpired, aSendingAllowed, aPlay,
       
  3970         aDisplay, aExecute, aPrint );
       
  3971     CleanupStack::PopAndDestroy( content ); // content
       
  3972     }
       
  3973 
       
  3974 // -----------------------------------------------------------------------------
       
  3975 // CDRMHelper::DoGetRightsDetailsL
       
  3976 // -----------------------------------------------------------------------------
       
  3977 //
       
  3978 void CDRMHelper::DoGetRightsDetailsL(
       
  3979     CData* aContent,
       
  3980     TUint32 aIntent,
       
  3981     TBool& aExpired,
       
  3982     TBool& aSendingAllowed,
       
  3983     CDRMRightsConstraints*& aPlay,
       
  3984     CDRMRightsConstraints*& aDisplay,
       
  3985     CDRMRightsConstraints*& aExecute,
       
  3986     CDRMRightsConstraints*& aPrint )
       
  3987     {
       
  3988     HBufC* contentURI = NULL;
       
  3989     HBufC8* contentURI8 = NULL;
       
  3990     TInt drmProtected(0);
       
  3991     CDRMRights* activeRights;
       
  3992 
       
  3993     __ASSERT_DEBUG( aContent, User::Invariant() );
       
  3994     User::LeaveIfNull( aContent );
       
  3995     User::LeaveIfError( aContent->GetAttribute( EIsProtected, drmProtected ) ) ;
       
  3996     if ( !drmProtected )
       
  3997         {
       
  3998         User::Leave( KErrArgument );
       
  3999         }
       
  4000 
       
  4001     User::LeaveIfError(
       
  4002         aContent->GetAttribute( EIsForwardable, aSendingAllowed ) ) ;
       
  4003 
       
  4004     contentURI = HBufC::NewLC( KUrlMaxLen );
       
  4005     TPtr ptr = contentURI->Des();
       
  4006     User::LeaveIfError( aContent->GetStringAttribute( EContentID, ptr ) );
       
  4007     contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  4008     contentURI8->Des().Copy( contentURI->Des() );
       
  4009 
       
  4010     // GetActiveRights returns negative value if rights are not valid
       
  4011     if ( iDRMCommon->GetActiveRights( *contentURI8, aIntent, activeRights ) > 0 )
       
  4012         {
       
  4013         // rights are valid
       
  4014         aExpired = EFalse;
       
  4015         CleanupStack::PushL( activeRights );
       
  4016         activeRights->GetPlayRight( aPlay );
       
  4017         activeRights->GetDisplayRight( aDisplay );
       
  4018         activeRights->GetExecuteRight( aExecute );
       
  4019         activeRights->GetPrintRight( aPrint );
       
  4020         CleanupStack::PopAndDestroy( activeRights );
       
  4021         }
       
  4022     else
       
  4023         {
       
  4024         // rights are not valid, check if they are future or expired.
       
  4025         TInt expiration = GetExpirationDetails(
       
  4026             contentURI8, aIntent, activeRights );
       
  4027         CleanupStack::PushL( activeRights );
       
  4028         switch ( expiration )
       
  4029             {
       
  4030             case CDRMRights::EExpiredRights:
       
  4031                 // expired rights
       
  4032                 aExpired = ETrue;
       
  4033                 break;
       
  4034             case CDRMRights::EFutureRights:
       
  4035                 // future rights, mark it as "expired" but return also
       
  4036                 // constraint objects
       
  4037                 aExpired = ETrue;
       
  4038                 activeRights->GetPlayRight( aPlay );
       
  4039                 activeRights->GetDisplayRight( aDisplay );
       
  4040                 activeRights->GetExecuteRight( aExecute );
       
  4041                 activeRights->GetPrintRight( aPrint );
       
  4042                 break;
       
  4043             case KErrCANoRights:
       
  4044                 // no rights, leave
       
  4045                 User::Leave( KErrCANoRights );
       
  4046                 break;
       
  4047             default:
       
  4048                 // something else, should never come here
       
  4049 #ifdef _DEBUG
       
  4050                 User::Invariant();
       
  4051 #endif
       
  4052                 User::Leave( KErrGeneral );
       
  4053                 break;
       
  4054             }
       
  4055         CleanupStack::PopAndDestroy( activeRights );
       
  4056         }
       
  4057     CleanupStack::PopAndDestroy( 2, contentURI ); // contentURI8, contentURI
       
  4058     }
       
  4059 
       
  4060 EXPORT_C TInt CDRMHelper::ShowDRMUINotification2L( TDRMHelperNotificationID /*aTextId*/,
       
  4061     const TDesC8& /*aURI*/ )
       
  4062     {
       
  4063     return KErrNotSupported;
       
  4064     }
       
  4065 
       
  4066 EXPORT_C TInt CDRMHelper::ShowDRMUINotification2L( TDRMHelperNotificationID /*aTextId*/,
       
  4067     const TDesC& /*aFileName*/ )
       
  4068     {
       
  4069     return KErrNotSupported;
       
  4070     }
       
  4071 
       
  4072 #pragma mark -
       
  4073 
       
  4074 // -----------------------------------------------------------------------------
       
  4075 // CDRMHelper::CanSetAutomated
       
  4076 // -----------------------------------------------------------------------------
       
  4077 //
       
  4078 EXPORT_C TInt CDRMHelper::CanSetAutomated(
       
  4079     const TDesC& aFilename,
       
  4080     TBool& aValue )
       
  4081     {
       
  4082     CData* content( NULL );
       
  4083     TInt error( KErrNone );
       
  4084 
       
  4085     RFile fileHandle;
       
  4086     TBool protectedWmDrm( EFalse );
       
  4087 
       
  4088     error = fileHandle.Open( iFs, aFilename,
       
  4089         EFileRead | EFileShareReadersOrWriters );
       
  4090     if ( error == KErrInUse )
       
  4091         {
       
  4092         error = fileHandle.Open( iFs, aFilename, EFileRead | EFileShareAny );
       
  4093         if ( error == KErrInUse )
       
  4094             {
       
  4095             error = fileHandle.Open( iFs, aFilename, EFileRead | EFileShareReadersOnly );
       
  4096             }
       
  4097         }
       
  4098 
       
  4099     if ( error == KErrNone )
       
  4100         {
       
  4101         // check if file is WMDRM protected
       
  4102         TRAP( error, protectedWmDrm = IsProtectedWmDrmL( fileHandle ) );
       
  4103         fileHandle.Close();
       
  4104         if ( protectedWmDrm || error != KErrNone )
       
  4105             {
       
  4106             // file is either corrupt or WMDRM protected
       
  4107             // so it can not be set as automated
       
  4108             aValue = EFalse;
       
  4109             return error;
       
  4110             }
       
  4111         }
       
  4112     else
       
  4113         {
       
  4114         return error;
       
  4115         }
       
  4116 
       
  4117     // do other needed checks
       
  4118     TVirtualPathPtr virtualPath( aFilename, KDefaultContentObject );
       
  4119 
       
  4120     TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  4121     if ( error == KErrInUse )
       
  4122         {
       
  4123         TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly ) );
       
  4124         }
       
  4125 
       
  4126     if ( error == KErrNone )
       
  4127         {
       
  4128 
       
  4129         TRAPD( err, error =  PerformCanSetAutomatedL( *content, aValue ) );
       
  4130         if ( err )
       
  4131             {
       
  4132             error = err;
       
  4133             }
       
  4134 
       
  4135         delete content;
       
  4136         }
       
  4137 
       
  4138     return error;
       
  4139     }
       
  4140 
       
  4141 
       
  4142 // -----------------------------------------------------------------------------
       
  4143 // CDRMHelper::CanSetAutomated
       
  4144 // -----------------------------------------------------------------------------
       
  4145 //
       
  4146 EXPORT_C TInt CDRMHelper::CanSetAutomated(
       
  4147     RFile& aFileHandle,
       
  4148     TBool& aValue )
       
  4149     {
       
  4150     CData* content( NULL );
       
  4151     TInt error( KErrNone );
       
  4152     TBool protectedWmDrm( EFalse );
       
  4153 
       
  4154     // check if file is WMDRM protected
       
  4155     TRAP( error, protectedWmDrm = IsProtectedWmDrmL( aFileHandle ) );
       
  4156     if ( protectedWmDrm || error != KErrNone )
       
  4157         {
       
  4158         // file is either corrupt or WMDRM protected
       
  4159         // so it can not be set as automated
       
  4160         aValue = EFalse;
       
  4161         return error;
       
  4162         }
       
  4163     // do other checks for given file
       
  4164     TRAP(error, content = CData::NewL( aFileHandle, KDefaultContentObject, EPeek ) );
       
  4165     if ( error == KErrNone )
       
  4166         {
       
  4167 
       
  4168         TRAPD( err, error =  PerformCanSetAutomatedL( *content, aValue ) );
       
  4169         if ( err )
       
  4170             {
       
  4171             error = err;
       
  4172             }
       
  4173 
       
  4174         delete content;
       
  4175         }
       
  4176 
       
  4177     return error;
       
  4178     }
       
  4179 
       
  4180 
       
  4181 // -----------------------------------------------------------------------------
       
  4182 // CDRMHelper::CanSetAutomated
       
  4183 // -----------------------------------------------------------------------------
       
  4184 //
       
  4185 EXPORT_C TInt CDRMHelper::CanSetAutomated( const TDesC8& aURI, TBool& aValue )
       
  4186     {
       
  4187     HBufC* mimeType = NULL;
       
  4188     TRAPD( error, mimeType = MimeTypeFromURIL( aURI ) );
       
  4189     if ( !error )
       
  4190         {
       
  4191         error = DoCanSetAutomated( aURI, mimeType, aValue );
       
  4192         }
       
  4193     delete mimeType;
       
  4194     return error;
       
  4195     }
       
  4196 
       
  4197 
       
  4198 // -----------------------------------------------------------------------------
       
  4199 // CDRMHelper::SetAutomated
       
  4200 // -----------------------------------------------------------------------------
       
  4201 //
       
  4202 EXPORT_C TInt CDRMHelper::SetAutomated( const TDesC& aFilename )
       
  4203     {
       
  4204     CData* content( NULL );
       
  4205     TInt error( KErrNone );
       
  4206 
       
  4207     TVirtualPathPtr virtualPath( aFilename, KDefaultContentObject );
       
  4208 
       
  4209     TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  4210     if ( error == KErrInUse )
       
  4211         {
       
  4212         TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly ) );
       
  4213         }
       
  4214 
       
  4215     if ( error == KErrNone )
       
  4216         {
       
  4217 
       
  4218         TRAPD( err, error =  PerformSetAutomatedL( *content, ETrue ) );
       
  4219         if ( err )
       
  4220             {
       
  4221             error = err;
       
  4222             }
       
  4223 
       
  4224         delete content;
       
  4225         }
       
  4226 
       
  4227     return error;
       
  4228     }
       
  4229 
       
  4230 
       
  4231 // -----------------------------------------------------------------------------
       
  4232 // CDRMHelper::SetAutomated
       
  4233 // -----------------------------------------------------------------------------
       
  4234 //
       
  4235 EXPORT_C TInt CDRMHelper::SetAutomated( RFile& aFileHandle )
       
  4236     {
       
  4237     CData* content( NULL );
       
  4238     TInt error( KErrNone );
       
  4239 
       
  4240     TRAP(error, content = CData::NewL( aFileHandle, KDefaultContentObject, EPeek ) );
       
  4241     if ( error == KErrNone )
       
  4242         {
       
  4243 
       
  4244         TRAPD( err, error =  PerformSetAutomatedL( *content, ETrue ) );
       
  4245         if ( err )
       
  4246             {
       
  4247             error = err;
       
  4248             }
       
  4249 
       
  4250         delete content;
       
  4251         }
       
  4252 
       
  4253     return error;
       
  4254     }
       
  4255 
       
  4256 
       
  4257 // -----------------------------------------------------------------------------
       
  4258 // CDRMHelper::SetAutomated
       
  4259 // -----------------------------------------------------------------------------
       
  4260 //
       
  4261 EXPORT_C TInt CDRMHelper::SetAutomated( const TDesC8& aURI )
       
  4262     {
       
  4263     TInt error( KErrArgument );
       
  4264     HBufC* mimeType = NULL;
       
  4265 
       
  4266     TRAPD( err, mimeType = MimeTypeFromURIL( aURI ) );
       
  4267     if ( !err && mimeType )
       
  4268         {
       
  4269         TRAP( err, error = DoSetAutomatedL( aURI, ETrue, mimeType ) );
       
  4270         }
       
  4271     if ( err )
       
  4272         {
       
  4273         error = err;
       
  4274         }
       
  4275     delete mimeType;
       
  4276     return error;
       
  4277     }
       
  4278 
       
  4279 
       
  4280 // -----------------------------------------------------------------------------
       
  4281 // CDRMHelper::ShowAutomatedNote
       
  4282 // -----------------------------------------------------------------------------
       
  4283 //
       
  4284 EXPORT_C TInt CDRMHelper::ShowAutomatedNote( const TDesC& aFilename )
       
  4285     {
       
  4286     CData* content( NULL );
       
  4287     TInt error( KErrNone );
       
  4288 
       
  4289     TVirtualPathPtr virtualPath( aFilename, KDefaultContentObject );
       
  4290     TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  4291     if ( error == KErrInUse )
       
  4292         {
       
  4293         TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly ) );
       
  4294         }
       
  4295 
       
  4296     if ( error == KErrNone )
       
  4297         {
       
  4298 
       
  4299         TRAPD( err, error =  PerformShowAutomatedNoteL( *content ) );
       
  4300         if ( err )
       
  4301             {
       
  4302             error = err;
       
  4303             }
       
  4304 
       
  4305         delete content;
       
  4306         }
       
  4307 
       
  4308     return error;
       
  4309     }
       
  4310 
       
  4311 
       
  4312 // -----------------------------------------------------------------------------
       
  4313 // CDRMHelper::ShowAutomatedNote
       
  4314 // -----------------------------------------------------------------------------
       
  4315 //
       
  4316 EXPORT_C TInt CDRMHelper::ShowAutomatedNote( RFile& aFileHandle )
       
  4317     {
       
  4318     CData* content( NULL );
       
  4319     TInt error( KErrNone );
       
  4320 
       
  4321     TRAP(error, content = CData::NewL( aFileHandle, KDefaultContentObject, EPeek ) );
       
  4322     if ( error == KErrNone )
       
  4323         {
       
  4324 
       
  4325         TRAPD( err, error =  PerformShowAutomatedNoteL( *content ) );
       
  4326         if ( err )
       
  4327             {
       
  4328             error = err;
       
  4329             }
       
  4330 
       
  4331         delete content;
       
  4332         }
       
  4333 
       
  4334     return error;
       
  4335     }
       
  4336 
       
  4337 
       
  4338 // -----------------------------------------------------------------------------
       
  4339 // CDRMHelper::ShowAutomatedNote
       
  4340 // -----------------------------------------------------------------------------
       
  4341 //
       
  4342 EXPORT_C TInt CDRMHelper::ShowAutomatedNote( const TDesC8& aURI )
       
  4343     {
       
  4344     TInt error ( KErrArgument );
       
  4345     HBufC* mimeType = NULL;
       
  4346 
       
  4347     TRAPD( err, mimeType = MimeTypeFromURIL( aURI ) );
       
  4348     if ( !err && mimeType )
       
  4349         {
       
  4350         TRAP( err, error = DoShowAutomatedNoteL( aURI, mimeType ) );
       
  4351         }
       
  4352     if ( err )
       
  4353         {
       
  4354         error = err;
       
  4355         }
       
  4356     delete mimeType;
       
  4357     return error;
       
  4358     }
       
  4359 
       
  4360 
       
  4361 // -----------------------------------------------------------------------------
       
  4362 // CDRMHelper::SetAutomatedPassive
       
  4363 // -----------------------------------------------------------------------------
       
  4364 //
       
  4365 EXPORT_C TInt CDRMHelper::SetAutomatedPassive( const TDesC& aFilename )
       
  4366     {
       
  4367     CData* content( NULL );
       
  4368     TInt error( KErrNone );
       
  4369 
       
  4370     TVirtualPathPtr virtualPath( aFilename, KDefaultContentObject );
       
  4371     TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  4372     if ( error == KErrInUse )
       
  4373         {
       
  4374         TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly ) );
       
  4375         }
       
  4376 
       
  4377     if ( error == KErrNone )
       
  4378         {
       
  4379 
       
  4380         TRAPD( err, error =  PerformSetAutomatedL( *content, EFalse ) );
       
  4381         if ( err )
       
  4382             {
       
  4383             error = err;
       
  4384             }
       
  4385 
       
  4386         delete content;
       
  4387         }
       
  4388 
       
  4389     return error;
       
  4390     }
       
  4391 
       
  4392 
       
  4393 // -----------------------------------------------------------------------------
       
  4394 // CDRMHelper::SetAutomatedPassive
       
  4395 // -----------------------------------------------------------------------------
       
  4396 //
       
  4397 EXPORT_C TInt CDRMHelper::SetAutomatedPassive( RFile& aFileHandle )
       
  4398     {
       
  4399     CData* content( NULL );
       
  4400     TInt error( KErrNone );
       
  4401 
       
  4402     TRAP(error, content = CData::NewL( aFileHandle, KDefaultContentObject, EPeek ) );
       
  4403     if ( error == KErrNone )
       
  4404         {
       
  4405 
       
  4406         TRAPD( err, error =  PerformSetAutomatedL( *content, EFalse ) );
       
  4407         if ( err )
       
  4408             {
       
  4409             error = err;
       
  4410             }
       
  4411 
       
  4412         delete content;
       
  4413         }
       
  4414 
       
  4415     return error;
       
  4416     }
       
  4417 
       
  4418 
       
  4419 // -----------------------------------------------------------------------------
       
  4420 // CDRMHelper::SetAutomatedPassive
       
  4421 // -----------------------------------------------------------------------------
       
  4422 //
       
  4423 EXPORT_C TInt CDRMHelper::SetAutomatedPassive( const TDesC8& aURI )
       
  4424     {
       
  4425     TInt error( KErrArgument );
       
  4426     HBufC* mimeType = NULL;
       
  4427 
       
  4428     TRAPD( err, mimeType = MimeTypeFromURIL( aURI ) );
       
  4429     if ( !err && mimeType )
       
  4430         {
       
  4431         TRAP( err, error = DoSetAutomatedL( aURI, EFalse, mimeType ) );
       
  4432         }
       
  4433     if ( err )
       
  4434         {
       
  4435         error = err;
       
  4436         }
       
  4437     delete mimeType;
       
  4438     return error;
       
  4439     }
       
  4440 
       
  4441 
       
  4442 // -----------------------------------------------------------------------------
       
  4443 // CDRMHelper::SetAutomatedSilent
       
  4444 // -----------------------------------------------------------------------------
       
  4445 //
       
  4446 EXPORT_C TInt CDRMHelper::SetAutomatedSilent( const TDesC& aFilename,
       
  4447     TBool aActive )
       
  4448     {
       
  4449     CData* content( NULL );
       
  4450     TInt error( KErrNone );
       
  4451 
       
  4452     TVirtualPathPtr virtualPath( aFilename, KDefaultContentObject );
       
  4453     TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  4454     if ( error == KErrInUse )
       
  4455         {
       
  4456         TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly ) );
       
  4457         }
       
  4458 
       
  4459     if ( error == KErrNone )
       
  4460         {
       
  4461 
       
  4462         TRAPD( err, error =  PerformSetAutomatedSilentL( *content, aActive ) );
       
  4463         if ( err )
       
  4464             {
       
  4465             error = err;
       
  4466             }
       
  4467 
       
  4468         delete content;
       
  4469         }
       
  4470 
       
  4471     return error;
       
  4472     }
       
  4473 
       
  4474 
       
  4475 // -----------------------------------------------------------------------------
       
  4476 // CDRMHelper::SetAutomatedSilent
       
  4477 // -----------------------------------------------------------------------------
       
  4478 //
       
  4479 EXPORT_C TInt CDRMHelper::SetAutomatedSilent( RFile& aFileHandle,
       
  4480     TBool aActive )
       
  4481     {
       
  4482     CData* content( NULL );
       
  4483     TInt error( KErrNone );
       
  4484 
       
  4485     TRAP(error, content = CData::NewL( aFileHandle, KDefaultContentObject, EPeek ) );
       
  4486     if ( error == KErrNone )
       
  4487         {
       
  4488         TRAPD( err, error =  PerformSetAutomatedSilentL( *content, aActive ) );
       
  4489         if ( err )
       
  4490             {
       
  4491             error = err;
       
  4492             }
       
  4493         delete content;
       
  4494         }
       
  4495 
       
  4496     return error;
       
  4497     }
       
  4498 
       
  4499 
       
  4500 // -----------------------------------------------------------------------------
       
  4501 // CDRMHelper::SetAutomatedSilent
       
  4502 // -----------------------------------------------------------------------------
       
  4503 //
       
  4504 EXPORT_C TInt CDRMHelper::SetAutomatedSilent( const TDesC8& aURI,
       
  4505     TBool aActive )
       
  4506     {
       
  4507     HBufC* mimetype = NULL;
       
  4508     TRAPD( err, mimetype = MimeTypeFromURIL( aURI ) );
       
  4509     if ( !err )
       
  4510         {
       
  4511         err = DoSetAutomatedSilent( aURI, aActive, Intent( mimetype ) );
       
  4512         }
       
  4513     delete mimetype;
       
  4514     return err;
       
  4515     }
       
  4516 
       
  4517 
       
  4518 // -----------------------------------------------------------------------------
       
  4519 // CDRMHelper::RemoveAutomated
       
  4520 // -----------------------------------------------------------------------------
       
  4521 //
       
  4522 EXPORT_C TInt CDRMHelper::RemoveAutomated( const TDesC& aFilename )
       
  4523     {
       
  4524     CData* content( NULL );
       
  4525     TInt error( KErrNone );
       
  4526 
       
  4527     TVirtualPathPtr virtualPath( aFilename, KDefaultContentObject );
       
  4528     TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  4529     if ( error == KErrInUse )
       
  4530         {
       
  4531         TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly ) );
       
  4532         }
       
  4533 
       
  4534     if ( error == KErrNone )
       
  4535         {
       
  4536 
       
  4537         TRAPD( err, error =  PerformRemoveAutomatedL( *content, ETrue ) );
       
  4538         if ( err )
       
  4539             {
       
  4540             error = err;
       
  4541             }
       
  4542 
       
  4543         delete content;
       
  4544         }
       
  4545 
       
  4546     return error;
       
  4547     }
       
  4548 
       
  4549 
       
  4550 // -----------------------------------------------------------------------------
       
  4551 // CDRMHelper::RemoveAutomated
       
  4552 // -----------------------------------------------------------------------------
       
  4553 //
       
  4554 EXPORT_C TInt CDRMHelper::RemoveAutomated( RFile& aFileHandle )
       
  4555     {
       
  4556     CData* content( NULL );
       
  4557     TInt error( KErrNone );
       
  4558 
       
  4559     TRAP(error, content = CData::NewL( aFileHandle, KDefaultContentObject, EPeek ) );
       
  4560     if ( error == KErrNone )
       
  4561         {
       
  4562         TRAPD( err, error =  PerformRemoveAutomatedL( *content, ETrue ) );
       
  4563         if ( err )
       
  4564             {
       
  4565             error = err;
       
  4566             }
       
  4567         delete content;
       
  4568         }
       
  4569 
       
  4570     return error;
       
  4571     }
       
  4572 
       
  4573 
       
  4574 // -----------------------------------------------------------------------------
       
  4575 // CDRMHelper::RemoveAutomated
       
  4576 // -----------------------------------------------------------------------------
       
  4577 //
       
  4578 EXPORT_C TInt CDRMHelper::RemoveAutomated( const TDesC8& aURI )
       
  4579     {
       
  4580     HBufC* mimetype = NULL;
       
  4581     TRAPD( error, mimetype = MimeTypeFromURIL( aURI ) );
       
  4582     if ( !error )
       
  4583         {
       
  4584         error = iHelperServer.RemoveAutomated(
       
  4585             aURI, ETrue, iAutomatedType, Intent( mimetype ) );
       
  4586         }
       
  4587     delete mimetype;
       
  4588     return error;
       
  4589     }
       
  4590 
       
  4591 
       
  4592 // -----------------------------------------------------------------------------
       
  4593 // CDRMHelper::RemoveAutomatedPassive
       
  4594 // -----------------------------------------------------------------------------
       
  4595 //
       
  4596 EXPORT_C TInt CDRMHelper::RemoveAutomatedPassive( const TDesC& aFilename )
       
  4597     {
       
  4598     CData* content( NULL );
       
  4599     TInt error( KErrNone );
       
  4600 
       
  4601     TVirtualPathPtr virtualPath( aFilename, KDefaultContentObject );
       
  4602     TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  4603     if ( error == KErrInUse )
       
  4604         {
       
  4605         TRAP( error, content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly ) );
       
  4606         }
       
  4607 
       
  4608     if ( error == KErrNone )
       
  4609         {
       
  4610         TRAPD( err, error =  PerformRemoveAutomatedL( *content, EFalse ) );
       
  4611         if ( err )
       
  4612             {
       
  4613             error = err;
       
  4614             }
       
  4615 
       
  4616         delete content;
       
  4617         }
       
  4618 
       
  4619     return error;
       
  4620     }
       
  4621 
       
  4622 
       
  4623 // -----------------------------------------------------------------------------
       
  4624 // CDRMHelper::RemoveAutomatedPassive
       
  4625 // -----------------------------------------------------------------------------
       
  4626 //
       
  4627 EXPORT_C TInt CDRMHelper::RemoveAutomatedPassive( RFile& aFileHandle )
       
  4628     {
       
  4629     CData* content( NULL );
       
  4630     TInt error( KErrNone );
       
  4631 
       
  4632     TRAP(error, content = CData::NewL( aFileHandle, KDefaultContentObject, EPeek ) );
       
  4633     if ( error == KErrNone )
       
  4634         {
       
  4635         TRAPD( err, error =  PerformRemoveAutomatedL( *content, EFalse ) );
       
  4636         if ( err )
       
  4637             {
       
  4638             error = err;
       
  4639             }
       
  4640         delete content;
       
  4641         }
       
  4642 
       
  4643     return error;
       
  4644     }
       
  4645 
       
  4646 // -----------------------------------------------------------------------------
       
  4647 // CDRMHelper::RemoveAutomatedPassive
       
  4648 // -----------------------------------------------------------------------------
       
  4649 //
       
  4650 EXPORT_C TInt CDRMHelper::RemoveAutomatedPassive( const TDesC8& aURI )
       
  4651     {
       
  4652     HBufC* mimetype = NULL;
       
  4653     TRAPD( error, mimetype = MimeTypeFromURIL( aURI ) );
       
  4654     if ( !error )
       
  4655         {
       
  4656         error = iHelperServer.RemoveAutomated(
       
  4657             aURI, EFalse, iAutomatedType, Intent( mimetype ) );
       
  4658         }
       
  4659     delete mimetype;
       
  4660     return error;
       
  4661     }
       
  4662 
       
  4663 
       
  4664 // -----------------------------------------------------------------------------
       
  4665 // CDRMHelper::SetAutomatedType
       
  4666 // -----------------------------------------------------------------------------
       
  4667 //
       
  4668 EXPORT_C TInt CDRMHelper::SetAutomatedType(
       
  4669     CDRMHelper::TDRMHelperAutomatedType aAutomatedType )
       
  4670     {
       
  4671     iAutomatedType = aAutomatedType;
       
  4672     return KErrNone;
       
  4673     }
       
  4674 
       
  4675 
       
  4676 // -----------------------------------------------------------------------------
       
  4677 // CDRMHelper::DoSetAutomatedL
       
  4678 // -----------------------------------------------------------------------------
       
  4679 //
       
  4680 TInt CDRMHelper::DoSetAutomatedL(
       
  4681     const TDesC8& aURI,
       
  4682     TBool aActive,
       
  4683     const HBufC* aMimeType )
       
  4684     {
       
  4685     TInt error = DoShowAutomatedNoteL( aURI, aMimeType );
       
  4686     if ( !error )
       
  4687         {
       
  4688         // register with server
       
  4689         error = DoSetAutomatedSilent( aURI, aActive, Intent( aMimeType) );
       
  4690         }
       
  4691     return error;
       
  4692     }
       
  4693 
       
  4694 // -----------------------------------------------------------------------------
       
  4695 // CDRMHelper::DoShowAutomatedNoteL
       
  4696 // -----------------------------------------------------------------------------
       
  4697 //
       
  4698 TInt CDRMHelper::DoShowAutomatedNoteL(
       
  4699     const TDesC8& aURI,
       
  4700     const HBufC* aMimeType )
       
  4701     {
       
  4702     CDRMRights* rights = NULL;
       
  4703     TInt error( KErrArgument );
       
  4704     TInt intent = Intent( aMimeType );
       
  4705     TInt rightsType = iDRMCommon->GetActiveRights( aURI, intent, rights );
       
  4706     if ( rightsType == CDRMRights::ERestrictedRights )
       
  4707         {
       
  4708         CDRMRights::TRestriction restriction;
       
  4709         CDRMRights::TExpiration expiration;
       
  4710         TUint32 constType( 0 );
       
  4711 
       
  4712         rights->GetRightsInfo( intent, restriction, expiration, constType );
       
  4713         if ( !(constType & CDRMRights::ECountBased) &&
       
  4714             !(constType & CDRMRights::ETimeIsAccumulatedTime) &&
       
  4715             expiration == CDRMRights::EValidRights )
       
  4716             {
       
  4717             TTime endTime;
       
  4718             TBool inactive;
       
  4719 
       
  4720             error = CalculateEndTime( rights, intent, endTime, inactive );
       
  4721             if ( !error )
       
  4722                 {
       
  4723                 TBuf<KDRMHelperMaxDateFormatLen> dateFormat;
       
  4724                 TBuf<KDRMHelperMaxDateLen> endDate;
       
  4725                 TInt buttonCode( 0 );
       
  4726 
       
  4727 #ifndef RD_MULTIPLE_DRIVE
       
  4728 
       
  4729                 TFileName avkonResFile( KDriveZ );
       
  4730 
       
  4731 #else //RD_MULTIPLE_DRIVE
       
  4732 
       
  4733                 _LIT( KDrive, "%c:");
       
  4734                 TInt driveNumber( -1 );
       
  4735                 TChar driveLetter;
       
  4736                 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  4737                 iFs.DriveToChar( driveNumber, driveLetter );
       
  4738 
       
  4739                 TFileName avkonResFile;
       
  4740 
       
  4741                 avkonResFile.Format( KDrive, (TUint)driveLetter );
       
  4742 
       
  4743 #endif
       
  4744 
       
  4745                 _LIT( KCDRMHelperAvkonResFileName, "avkon.rsc" );
       
  4746 
       
  4747                 avkonResFile.Append( KDC_RESOURCE_FILES_DIR );
       
  4748                 avkonResFile.Append( KCDRMHelperAvkonResFileName );
       
  4749 
       
  4750                 if ( inactive )
       
  4751                     {
       
  4752                     buttonCode = DisplayQueryWithIdL( R_DRM_QUERY_SET_AUTO_INTERVAL ,
       
  4753                         R_DRMHELPER_CONFIRMATION_QUERY );
       
  4754                     }
       
  4755                 else
       
  4756                     {
       
  4757                     // get date string format
       
  4758                     CStringResourceReader* avkonResReader(
       
  4759                         CStringResourceReader::NewLC( avkonResFile ) );
       
  4760 
       
  4761                     dateFormat = avkonResReader->ReadResourceString(
       
  4762                         R_QTN_DATE_USUAL_WITH_ZERO );
       
  4763 
       
  4764                     CleanupStack::PopAndDestroy( avkonResReader );
       
  4765 
       
  4766                     // format date
       
  4767                     endTime.FormatL( endDate, dateFormat );
       
  4768                     AknTextUtils::LanguageSpecificNumberConversion( endDate );
       
  4769 
       
  4770                     // display query
       
  4771                     buttonCode = DisplayQueryL( R_DRMHELPER_SET_AUTOMATED,
       
  4772                         endDate );
       
  4773                     }
       
  4774                 error = buttonCode ? KErrNone : KErrCancel;
       
  4775                 }
       
  4776             else if ( error == KErrNotFound )
       
  4777                 {
       
  4778                 // end time not found, this is datetime constraint without end
       
  4779                 // time
       
  4780                 error = KErrNone;
       
  4781                 }
       
  4782             }
       
  4783         }
       
  4784     else
       
  4785         {
       
  4786         if ( rightsType == CDRMRights::EFullRights )
       
  4787             {
       
  4788             error = KErrNone;
       
  4789             }
       
  4790         }
       
  4791     delete rights;
       
  4792     return error;
       
  4793     }
       
  4794 
       
  4795 
       
  4796 // -----------------------------------------------------------------------------
       
  4797 // CDRMHelper::DoSetAutomatedSilent
       
  4798 // -----------------------------------------------------------------------------
       
  4799 //
       
  4800 TInt CDRMHelper::DoSetAutomatedSilent(
       
  4801     const TDesC8& aURI,
       
  4802     TBool aActive,
       
  4803     TInt aIntent )
       
  4804     {
       
  4805     return iHelperServer.SetAutomated( aURI, aActive, iAutomatedType, aIntent );
       
  4806     }
       
  4807 
       
  4808 // -----------------------------------------------------------------------------
       
  4809 // CDRMHelper::DoCheckSkinCanSetAutomated
       
  4810 //
       
  4811 // Checks all rights constraints for certain RO and checks if interval is the same
       
  4812 // If not, return EFalse
       
  4813 // -----------------------------------------------------------------------------
       
  4814 //
       
  4815 TBool CDRMHelper::DoCheckSkinCanSetAutomated(CDRMRights* aRights)
       
  4816     {
       
  4817     TBool Rights[3] = {EFalse, EFalse, EFalse}; //Display, Execute, Play
       
  4818     TTimeIntervalSeconds EndTimes[3] = {0, 0, 0}; //Display, Execute, Play
       
  4819     TBool interval = EFalse;
       
  4820     TTimeIntervalSeconds endTime = 0;
       
  4821 
       
  4822     CDRMRightsConstraints *constraint = NULL;
       
  4823 
       
  4824     // Display rights
       
  4825     if ( aRights->GetDisplayRight( constraint ) == KErrNone)
       
  4826         {
       
  4827         Rights[0] = ETrue;
       
  4828         constraint->GetInterval( endTime );
       
  4829         EndTimes[0] = endTime;
       
  4830         }
       
  4831     delete constraint;
       
  4832     constraint = NULL;
       
  4833     endTime = 0;
       
  4834 
       
  4835     // Execute rights
       
  4836     if ( aRights->GetExecuteRight( constraint ) == KErrNone)
       
  4837         {
       
  4838         Rights[1] = ETrue;
       
  4839         constraint->GetInterval( endTime );
       
  4840         EndTimes[1] = endTime;
       
  4841         }
       
  4842     delete constraint;
       
  4843     constraint = NULL;
       
  4844     endTime = 0;
       
  4845 
       
  4846     // Play rights
       
  4847     if ( aRights->GetPlayRight( constraint )  == KErrNone )
       
  4848         {
       
  4849         Rights[2] = ETrue;
       
  4850         constraint->GetInterval( endTime );
       
  4851         EndTimes[2] = endTime;
       
  4852         }
       
  4853     delete constraint;
       
  4854     constraint = NULL;
       
  4855     endTime = 0;
       
  4856 
       
  4857     for (TInt i = 0; i < 3; ++i)
       
  4858         {
       
  4859         // we have a interval
       
  4860         if (EndTimes[i].Int() != 0)
       
  4861             {
       
  4862             interval = ETrue;
       
  4863             // test if we have endtimes
       
  4864             if (EndTimes[i].Int() != 0)
       
  4865                 {
       
  4866                 // compare to other
       
  4867                 for (TInt u = 0; u < 3 ; u++)
       
  4868                     {
       
  4869                     if ( Rights[u] && (EndTimes[u].Int() != EndTimes[i].Int() ))
       
  4870                         {
       
  4871                         return EFalse;
       
  4872                         }
       
  4873                     }
       
  4874                 }
       
  4875             }
       
  4876         else if ( interval )
       
  4877             {
       
  4878             // If no interval but constraint found
       
  4879             if (Rights[i])
       
  4880                 {
       
  4881                 return EFalse;
       
  4882                 }
       
  4883             }
       
  4884         }
       
  4885 
       
  4886     // If time intervals were ok.
       
  4887     return ETrue;
       
  4888     }
       
  4889 
       
  4890 // -----------------------------------------------------------------------------
       
  4891 // CDRMHelper::DoCanSetAutomated
       
  4892 // -----------------------------------------------------------------------------
       
  4893 //
       
  4894 TInt CDRMHelper::DoCanSetAutomated(
       
  4895     const TDesC8& aURI,
       
  4896     const HBufC* aMimeType,
       
  4897     TBool& aValue )
       
  4898     {
       
  4899     TInt rightsType;
       
  4900     CDRMRights* rights = NULL;
       
  4901     TInt error( KErrNone );
       
  4902     TInt intent = Intent( aMimeType );
       
  4903 
       
  4904     rightsType = iDRMCommon->GetActiveRights( aURI, intent, rights );
       
  4905     if ( rightsType == CDRMRights::EFullRights )
       
  4906         {
       
  4907         aValue = ETrue;
       
  4908         }
       
  4909     else
       
  4910         {
       
  4911         if ( rights )
       
  4912             {
       
  4913             CDRMRights::TRestriction restriction;
       
  4914             CDRMRights::TExpiration expiration;
       
  4915             TUint32 constType;
       
  4916 
       
  4917             rights->GetRightsInfo( intent, restriction, expiration, constType );
       
  4918             if ( expiration == CDRMRights::EValidRights )
       
  4919                 {
       
  4920                 // Check theme interval rights validity
       
  4921                 if ( iAutomatedType == EAutomatedTypeTheme)
       
  4922                     {
       
  4923                     if (!DoCheckSkinCanSetAutomated(rights))
       
  4924                         {
       
  4925                         delete rights;
       
  4926                         aValue = EFalse;
       
  4927                         return DRMCommon::EInvalidRights;
       
  4928                         }
       
  4929                     }
       
  4930 
       
  4931                 // if rights are valid and not count or accumulated time
       
  4932                 // based, content can be set automated
       
  4933                 aValue = !(constType &
       
  4934                     ( CDRMRights::ECountBased | CDRMRights::ETimeIsAccumulatedTime ) );
       
  4935                 }
       
  4936             else
       
  4937                 {
       
  4938                 // expired or future rights
       
  4939                 aValue = EFalse;
       
  4940 
       
  4941                 // return expired error code only for content that has
       
  4942                 // time-based rights
       
  4943                 if ( !(constType &
       
  4944                         ( CDRMRights::ECountBased | CDRMRights::ETimeIsAccumulatedTime ) ) )
       
  4945                     {
       
  4946                     error = DRMCommon::ERightsExpired;
       
  4947                     }
       
  4948                 }
       
  4949             }
       
  4950         else
       
  4951             {
       
  4952             // no rights
       
  4953             aValue = EFalse;
       
  4954             error = DRMCommon::ENoRights;
       
  4955             }
       
  4956         }
       
  4957     delete rights;
       
  4958     return error;
       
  4959     }
       
  4960 
       
  4961 // -----------------------------------------------------------------------------
       
  4962 // CDRMHelper::PerformCanSetAutomatedL
       
  4963 // -----------------------------------------------------------------------------
       
  4964 //
       
  4965 TInt CDRMHelper::PerformCanSetAutomatedL(
       
  4966     const CData& aContent,
       
  4967     TBool& aValue )
       
  4968     {
       
  4969     HBufC* mimeType = NULL;
       
  4970     HBufC* contentURI = NULL;
       
  4971     HBufC8* contentURI8 = NULL;
       
  4972     TInt drmProtected(0);
       
  4973     TInt error;
       
  4974     TInt dcfType(0);
       
  4975 
       
  4976     error = aContent.GetAttribute( EIsProtected, drmProtected );
       
  4977     if ( !error )
       
  4978         {
       
  4979         if ( !drmProtected )
       
  4980             {
       
  4981             aValue = ETrue;
       
  4982             error = KErrNone;
       
  4983             }
       
  4984         else
       
  4985             {
       
  4986             mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
  4987             contentURI = HBufC::NewLC( KUrlMaxLen );
       
  4988 
       
  4989             // create attribute set
       
  4990             RStringAttributeSet stringAttributeSet;
       
  4991             CleanupClosePushL( stringAttributeSet );
       
  4992             // add the attributes we are interested in
       
  4993             stringAttributeSet.AddL( EContentID );
       
  4994             stringAttributeSet.AddL( EMimeType );
       
  4995 
       
  4996             error = aContent.GetStringAttributeSet( stringAttributeSet );
       
  4997 
       
  4998             if ( error == KErrNone )
       
  4999                 {
       
  5000                 // pass on values of string attributes
       
  5001                 TPtr ptr = contentURI->Des();
       
  5002                 error = stringAttributeSet.GetValue( EContentID, ptr );
       
  5003                 if ( error == KErrNone )
       
  5004                     {
       
  5005                     TPtr ptr2 = mimeType->Des();
       
  5006                     error = stringAttributeSet.GetValue( EMimeType, ptr2 );
       
  5007 
       
  5008                     //OMA2 content with is not allowed without classification info
       
  5009                     if ( error == KErrNone )
       
  5010                         {
       
  5011                         error = aContent.GetAttribute( EFileType, dcfType );
       
  5012                         TInt intent = Intent( mimeType );
       
  5013 
       
  5014                         if (dcfType == EOma2Dcf && intent == EPlay )
       
  5015                             {
       
  5016 
       
  5017                             HBufC* classificationInfo = HBufC::NewLC( KUrlMaxLen );
       
  5018                             TPtr ptr = classificationInfo->Des();
       
  5019                             aContent.GetStringAttribute( EClassificationInfo, ptr);
       
  5020 
       
  5021                             if ( !classificationInfo->FindF(
       
  5022                                     KDRMHelperClassificationRingingTone ) ||
       
  5023                                 !classificationInfo->FindF(
       
  5024                                     KDRMHelperClassificationVideoTone ) )
       
  5025                                 {
       
  5026                                 aValue = ETrue;
       
  5027                                 CleanupStack::PopAndDestroy(
       
  5028                                     classificationInfo );
       
  5029                                 }
       
  5030                             else
       
  5031                                 {
       
  5032                                 aValue = EFalse;
       
  5033                                 CleanupStack::PopAndDestroy( 4, mimeType );
       
  5034                                 // classificationInfo, stringAttributeSet.Close(),
       
  5035                                 // contentURI, mimeType
       
  5036                                 return error;
       
  5037                                 }
       
  5038                             }
       
  5039                         }
       
  5040                     if ( error == KErrNone )
       
  5041                         {
       
  5042                         contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  5043                         contentURI8->Des().Copy( contentURI->Des() );
       
  5044                         error = DoCanSetAutomated( *contentURI8, mimeType, aValue );
       
  5045                         CleanupStack::PopAndDestroy( contentURI8 );
       
  5046                         }
       
  5047                     else
       
  5048                         {
       
  5049                         error = KErrArgument;
       
  5050                         }
       
  5051                     }
       
  5052                 else
       
  5053                     {
       
  5054                     error = KErrArgument;
       
  5055                     }
       
  5056                 }
       
  5057             else
       
  5058                 {
       
  5059                 error = KErrArgument;
       
  5060                 }
       
  5061             CleanupStack::PopAndDestroy(3, mimeType); // stringAttributeSet.Close(), contentURI, mimeType
       
  5062             }
       
  5063         }
       
  5064     else
       
  5065         {
       
  5066         error = KErrArgument;
       
  5067         }
       
  5068     return error;
       
  5069     }
       
  5070 
       
  5071 
       
  5072 // -----------------------------------------------------------------------------
       
  5073 // CDRMHelper::PerformSetAutomatedL
       
  5074 // -----------------------------------------------------------------------------
       
  5075 //
       
  5076 TInt CDRMHelper::PerformSetAutomatedL( const CData& aContent, TBool aActive )
       
  5077     {
       
  5078     HBufC* mimeType = NULL;
       
  5079     HBufC* contentURI = NULL;
       
  5080     HBufC8* contentURI8 = NULL;
       
  5081     TInt drmProtected(0);
       
  5082     TInt error;
       
  5083 
       
  5084     error = aContent.GetAttribute( EIsProtected, drmProtected );
       
  5085     if ( !error )
       
  5086         {
       
  5087         if ( drmProtected )
       
  5088             {
       
  5089             mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
  5090             contentURI = HBufC::NewLC( KUrlMaxLen );
       
  5091 
       
  5092             // create attribute set
       
  5093             RStringAttributeSet stringAttributeSet;
       
  5094             CleanupClosePushL( stringAttributeSet );
       
  5095             // add the attributes we are interested in
       
  5096             stringAttributeSet.AddL( EContentID );
       
  5097             stringAttributeSet.AddL( EMimeType );
       
  5098 
       
  5099             error = aContent.GetStringAttributeSet( stringAttributeSet );
       
  5100 
       
  5101             if ( error == KErrNone )
       
  5102                 {
       
  5103                 // pass on values of string attributes
       
  5104                 TPtr ptr = contentURI->Des();
       
  5105                 error = stringAttributeSet.GetValue( EContentID, ptr );
       
  5106                 if ( error == KErrNone )
       
  5107                     {
       
  5108                     TPtr ptr2 = mimeType->Des();
       
  5109                     error = stringAttributeSet.GetValue( EMimeType, ptr2 );
       
  5110                     if ( error == KErrNone )
       
  5111                         {
       
  5112                         contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  5113                         contentURI8->Des().Copy( contentURI->Des() );
       
  5114 
       
  5115                         TRAPD( err, error = DoSetAutomatedL( *contentURI8, aActive, mimeType ) );
       
  5116                         if ( err )
       
  5117                             {
       
  5118                             error = err;
       
  5119                             }
       
  5120                         CleanupStack::PopAndDestroy( contentURI8 );
       
  5121                         }
       
  5122                     else
       
  5123                         {
       
  5124                         error = KErrArgument;
       
  5125                         }
       
  5126                     }
       
  5127                 else
       
  5128                     {
       
  5129                     error = KErrArgument;
       
  5130                     }
       
  5131                 }
       
  5132             else
       
  5133                 {
       
  5134                 error = KErrArgument;
       
  5135                 }
       
  5136             CleanupStack::PopAndDestroy(3, mimeType); // stringAttributeSet.Close(), contentURI, mimeType
       
  5137             }
       
  5138         }
       
  5139     else
       
  5140         {
       
  5141         error = KErrArgument;
       
  5142         }
       
  5143     return error;
       
  5144     }
       
  5145 
       
  5146 
       
  5147 
       
  5148 // -----------------------------------------------------------------------------
       
  5149 // CDRMHelper::PerformShowAutomatedNoteL
       
  5150 // -----------------------------------------------------------------------------
       
  5151 //
       
  5152 TInt CDRMHelper::PerformShowAutomatedNoteL( const CData& aContent )
       
  5153     {
       
  5154     HBufC* mimeType = NULL;
       
  5155     HBufC* contentURI = NULL;
       
  5156     HBufC8* contentURI8 = NULL;
       
  5157     TInt drmProtected(0);
       
  5158     TInt error;
       
  5159 
       
  5160     error = aContent.GetAttribute( EIsProtected, drmProtected );
       
  5161     if ( !error )
       
  5162         {
       
  5163         if ( drmProtected )
       
  5164             {
       
  5165             mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
  5166             contentURI = HBufC::NewLC( KUrlMaxLen );
       
  5167 
       
  5168             // create attribute set
       
  5169             RStringAttributeSet stringAttributeSet;
       
  5170             CleanupClosePushL( stringAttributeSet );
       
  5171             // add the attributes we are interested in
       
  5172             stringAttributeSet.AddL( EContentID );
       
  5173             stringAttributeSet.AddL( EMimeType );
       
  5174 
       
  5175             error = aContent.GetStringAttributeSet( stringAttributeSet );
       
  5176 
       
  5177             if ( error == KErrNone )
       
  5178                 {
       
  5179                 // pass on values of string attributes
       
  5180                 TPtr ptr = contentURI->Des();
       
  5181                 error = stringAttributeSet.GetValue( EContentID, ptr );
       
  5182                 if ( error == KErrNone )
       
  5183                     {
       
  5184                     TPtr ptr2 = mimeType->Des();
       
  5185                     error = stringAttributeSet.GetValue( EMimeType, ptr2 );
       
  5186                     if ( error == KErrNone )
       
  5187                         {
       
  5188                         contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  5189                         contentURI8->Des().Copy( contentURI->Des() );
       
  5190 
       
  5191                         TRAPD( err, error = DoShowAutomatedNoteL( *contentURI8, mimeType ) );
       
  5192                         if ( err )
       
  5193                             {
       
  5194                             error = err;
       
  5195                             }
       
  5196                         CleanupStack::PopAndDestroy( contentURI8 );
       
  5197                         }
       
  5198                     else
       
  5199                         {
       
  5200                         error = KErrArgument;
       
  5201                         }
       
  5202                     }
       
  5203                 else
       
  5204                     {
       
  5205                     error = KErrArgument;
       
  5206                     }
       
  5207                 }
       
  5208             else
       
  5209                 {
       
  5210                 error = KErrArgument;
       
  5211                 }
       
  5212             CleanupStack::PopAndDestroy(3, mimeType); // stringAttributeSet.Close(), contentURI, mimeType
       
  5213             }
       
  5214         }
       
  5215     else
       
  5216         {
       
  5217         error = KErrArgument;
       
  5218         }
       
  5219     return error;
       
  5220     }
       
  5221 
       
  5222 
       
  5223 // -----------------------------------------------------------------------------
       
  5224 // CDRMHelper::PerformSetAutomatedSilentL
       
  5225 // -----------------------------------------------------------------------------
       
  5226 //
       
  5227 TInt CDRMHelper::PerformSetAutomatedSilentL( const CData& aContent, TBool aActive )
       
  5228     {
       
  5229     HBufC* contentURI = NULL;
       
  5230     HBufC8* contentURI8 = NULL;
       
  5231     TInt drmProtected(0);
       
  5232     TInt error;
       
  5233 
       
  5234     error = aContent.GetAttribute( EIsProtected, drmProtected );
       
  5235     if ( !error )
       
  5236         {
       
  5237         if ( drmProtected )
       
  5238             {
       
  5239             contentURI = HBufC::NewLC( KUrlMaxLen );
       
  5240             TPtr ptr = contentURI->Des();
       
  5241             error = aContent.GetStringAttribute( EContentID, ptr );
       
  5242             if ( !error )
       
  5243                 {
       
  5244                 HBufC* mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
  5245                 TPtr ptr2 = mimeType->Des();
       
  5246                 error = aContent.GetStringAttribute( EMimeType, ptr2 );
       
  5247                 if ( !error )
       
  5248                     {
       
  5249                     contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  5250                     contentURI8->Des().Copy( contentURI->Des() );
       
  5251                     error = DoSetAutomatedSilent( *contentURI8, aActive, Intent( mimeType ) );
       
  5252                     CleanupStack::PopAndDestroy( contentURI8 );
       
  5253                     }
       
  5254                 CleanupStack::PopAndDestroy( mimeType );
       
  5255                 }
       
  5256             CleanupStack::PopAndDestroy( contentURI );
       
  5257             }
       
  5258         }
       
  5259     else
       
  5260         {
       
  5261         error = KErrArgument;
       
  5262         }
       
  5263     return error;
       
  5264     }
       
  5265 
       
  5266 
       
  5267 // -----------------------------------------------------------------------------
       
  5268 // CDRMHelper::PerformRemoveAutomatedL
       
  5269 // -----------------------------------------------------------------------------
       
  5270 //
       
  5271 TInt CDRMHelper::PerformRemoveAutomatedL( const CData& aContent, TBool aActive )
       
  5272     {
       
  5273     HBufC* contentURI = NULL;
       
  5274     HBufC8* contentURI8 = NULL;
       
  5275     TInt drmProtected(0);
       
  5276     TInt error;
       
  5277 
       
  5278     error = aContent.GetAttribute( EIsProtected, drmProtected );
       
  5279     if ( !error )
       
  5280         {
       
  5281         if ( !drmProtected )
       
  5282             {
       
  5283             error = KErrArgument;
       
  5284             }
       
  5285         else
       
  5286             {
       
  5287             contentURI = HBufC::NewLC( KUrlMaxLen );
       
  5288             TPtr ptr = contentURI->Des();
       
  5289             error = aContent.GetStringAttribute( EContentID, ptr );
       
  5290             if ( !error )
       
  5291                 {
       
  5292                 contentURI8 = HBufC8::NewLC( contentURI->Length() );
       
  5293                 contentURI8->Des().Copy( contentURI->Des() );
       
  5294                 if ( aActive )
       
  5295                     {
       
  5296                     error = RemoveAutomated( *contentURI8 );
       
  5297                     }
       
  5298                 else
       
  5299                     {
       
  5300                     error = RemoveAutomatedPassive( *contentURI8 );
       
  5301                     }
       
  5302                 CleanupStack::PopAndDestroy( contentURI8 );
       
  5303                 }
       
  5304             CleanupStack::PopAndDestroy( contentURI );
       
  5305             }
       
  5306         }
       
  5307     else
       
  5308         {
       
  5309         error = KErrArgument;
       
  5310         }
       
  5311     return error;
       
  5312     }
       
  5313 
       
  5314 // -----------------------------------------------------------------------------
       
  5315 // CDRMHelper::AutomatedResIdL
       
  5316 // -----------------------------------------------------------------------------
       
  5317 //
       
  5318 TInt CDRMHelper::AutomatedResIdL( TBool aExpired, TBool aSecondParameter, TUint32 aRejectReason )
       
  5319     {
       
  5320     TInt resId(0);
       
  5321     TBool invalidImsi( EFalse );
       
  5322     invalidImsi = aRejectReason & EConstraintIndividual;
       
  5323 
       
  5324     switch ( iAutomatedType )
       
  5325         {
       
  5326         case EAutomatedTypeRingingTone:
       
  5327             if ( aExpired )
       
  5328                 {
       
  5329                 if ( aSecondParameter )
       
  5330                     {
       
  5331                     resId = invalidImsi ?
       
  5332                         R_DRMHELPER_RINGING_TONE_INVALID_SIM_BUY_NEW :
       
  5333                         R_DRMHELPER_RINGING_TONE_EXPIRED_BUY_NEW;
       
  5334                     }
       
  5335                 else
       
  5336                     {
       
  5337                     resId = invalidImsi ?
       
  5338                         R_DRM_NON_SD_RTONE_WRONG_SIM :
       
  5339                         R_DRMHELPER_RINGING_TONE_EXPIRED;
       
  5340                     }
       
  5341                 }
       
  5342             break;
       
  5343         case EAutomatedTypeMessageAlert:
       
  5344             if ( aExpired )
       
  5345                 {
       
  5346                 if ( aSecondParameter )
       
  5347                     {
       
  5348                     resId = invalidImsi ?
       
  5349                         R_DRMHELPER_MESSAGE_TONE_INVALID_SIM_BUY_NEW :
       
  5350                         R_DRMHELPER_MESSAGE_TONE_EXPIRED_BUY_NEW;
       
  5351                     }
       
  5352                 else
       
  5353                     {
       
  5354                     resId = invalidImsi ?
       
  5355                         R_DRM_NON_SD_MSG_AL_WRONG_SIM :
       
  5356                         R_DRMHELPER_MESSAGE_TONE_EXPIRED;
       
  5357                     }
       
  5358                 }
       
  5359             break;
       
  5360         case EAutomatedTypeEmailAlert:
       
  5361             if ( aExpired )
       
  5362                 {
       
  5363                 if ( aSecondParameter )
       
  5364                     {
       
  5365                     resId = invalidImsi ?
       
  5366                         R_DRMHELPER_EMAIL_TONE_INVALID_SIM_BUY_NEW :
       
  5367                         R_DRMHELPER_EMAIL_TONE_EXPIRED_BUY_NEW;
       
  5368                     }
       
  5369                 else
       
  5370                     {
       
  5371                     resId = invalidImsi ?
       
  5372                         R_DRM_NON_SD_EMAIL_WRONG_SIM :
       
  5373                         R_DRMHELPER_EMAIL_TONE_EXPIRED;
       
  5374                     }
       
  5375                 }
       
  5376             break;
       
  5377         case EAutomatedTypeIMAlert:
       
  5378             if ( aExpired )
       
  5379                 {
       
  5380                 if ( aSecondParameter )
       
  5381                     {
       
  5382                     resId = /* invalidImsi ?
       
  5383                                R_DRMHELPER_IM_TONE_INVALID_SIM_BUY_NEW : */
       
  5384                         R_DRMHELPER_IM_TONE_EXPIRED_BUY_NEW;
       
  5385                     }
       
  5386                 else
       
  5387                     {
       
  5388                     resId = R_DRMHELPER_IM_TONE_EXPIRED;
       
  5389                     }
       
  5390                 }
       
  5391             break;
       
  5392         case EAutomatedTypeCalendarAlarm:
       
  5393             if ( aExpired )
       
  5394                 {
       
  5395                 if ( aSecondParameter )
       
  5396                     {
       
  5397                     resId = invalidImsi ?
       
  5398                         R_DRMHELPER_CAL_ALERT_INVALID_SIM_BUY_NEW :
       
  5399                         R_DRMHELPER_CAL_ALERT_EXPIRED_BUY_NEW;
       
  5400                     }
       
  5401                 else
       
  5402                     {
       
  5403                     resId = invalidImsi ?
       
  5404                         R_DRM_NON_SD_CALEND_WRONG_SIM :
       
  5405                         R_DRMHELPER_CAL_ALERT_EXPIRED;
       
  5406                     }
       
  5407                 }
       
  5408             break;
       
  5409         case EAutomatedTypeScreenSaver:
       
  5410             if ( aExpired )
       
  5411                 {
       
  5412                 if ( aSecondParameter )
       
  5413                     {
       
  5414                     resId = invalidImsi ?
       
  5415                         R_DRMHELPER_SCREENSAVER_INVALID_SIM_BUY_NEW :
       
  5416                         R_DRMHELPER_SCREENSAVER_EXPIRED_BUY_NEW;
       
  5417                     }
       
  5418                 else
       
  5419                     {
       
  5420                     resId = invalidImsi ?
       
  5421                         R_DRM_NON_SD_SCREEN_WRONG_SIM :
       
  5422                         R_DRMHELPER_SCREENSAVER_EXPIRED;
       
  5423                     }
       
  5424                 }
       
  5425             break;
       
  5426         case EAutomatedTypeWallpaper:
       
  5427             if ( aExpired )
       
  5428                 {
       
  5429                 if ( aSecondParameter )
       
  5430                     {
       
  5431                     resId = invalidImsi ?
       
  5432                         R_DRMHELPER_WALLPAPER_INVALID_SIM_BUY_NEW :
       
  5433                         R_DRMHELPER_WALLPAPER_EXPIRED_BUY_NEW;
       
  5434                     }
       
  5435                 else
       
  5436                     {
       
  5437                     resId = invalidImsi ?
       
  5438                         R_DRM_NON_SD_WALLP_WRONG_SIM :
       
  5439                         R_DRMHELPER_WALLPAPER_EXPIRED;
       
  5440                     }
       
  5441                 }
       
  5442             break;
       
  5443         case EAutomatedTypeTheme:
       
  5444             if ( aExpired )
       
  5445                 {
       
  5446                 if ( aSecondParameter )
       
  5447                     {
       
  5448                     resId = invalidImsi ?
       
  5449                         R_DRMHELPER_THEME_INVALID_SIM_BUY_NEW :
       
  5450                         R_DRMHELPER_THEME_EXPIRED_BUY_NEW;
       
  5451                     }
       
  5452                 else
       
  5453                     {
       
  5454                     resId = invalidImsi ?
       
  5455                         R_DRM_NON_SD_THEME_WRONG_SIM :
       
  5456                         R_DRMHELPER_THEME_EXPIRED;
       
  5457                     }
       
  5458                 }
       
  5459             break;
       
  5460         case EAutomatedTypeClockAlarm:
       
  5461             if ( aExpired )
       
  5462                 {
       
  5463                 if ( aSecondParameter )
       
  5464                     {
       
  5465                     resId = invalidImsi ?
       
  5466                         R_DRMHELPER_CLOCK_ALARM_INVALID_SIM_BUY_NEW :
       
  5467                         R_DRMHELPER_CLOCK_ALARM_EXPIRED_BUY_NEW;
       
  5468                     }
       
  5469                 else
       
  5470                     {
       
  5471                     resId = invalidImsi ?
       
  5472                         R_DRM_NON_SD_CLOCK_WRONG_SIM :
       
  5473                         R_DRMHELPER_CLOCK_ALARM_EXPIRED;
       
  5474                     }
       
  5475                 }
       
  5476             break;
       
  5477         case EAutomatedTypeOther:
       
  5478             // Flow through to default branch
       
  5479         default:
       
  5480             if ( aExpired )
       
  5481                 {
       
  5482                 if ( aSecondParameter )
       
  5483                     {
       
  5484                     resId = invalidImsi ?
       
  5485                         R_DRMHELPER_AUTOMATED_SD_INVALID_SIM :
       
  5486                         R_DRMHELPER_AUTOMATED_SD_EXPIRED;
       
  5487                     }
       
  5488                 else
       
  5489                     {
       
  5490                     resId = invalidImsi ?
       
  5491                         R_DRM_NON_SD_GENER_WRONG_SIM :
       
  5492                         R_DRMHELPER_AUTOMATED_CD_EXPIRED;
       
  5493                     }
       
  5494                 }
       
  5495             break;
       
  5496         }
       
  5497 
       
  5498     return resId;
       
  5499     }
       
  5500 
       
  5501 // -----------------------------------------------------------------------------
       
  5502 // CDRMHelper::IndicateIdle
       
  5503 // -----------------------------------------------------------------------------
       
  5504 //
       
  5505 EXPORT_C void CDRMHelper::IndicateIdle()
       
  5506     {
       
  5507     iHelperServer.IndicateIdle();
       
  5508     }
       
  5509 
       
  5510 #pragma mark -
       
  5511 
       
  5512 // -----------------------------------------------------------------------------
       
  5513 // CDRMHelper::LaunchBrowserL
       
  5514 // Launches browser embedded with given URL
       
  5515 // -----------------------------------------------------------------------------
       
  5516 //
       
  5517 void CDRMHelper::LaunchBrowserL( HBufC8* aUrl )
       
  5518     {
       
  5519     // URL needs to be unicode
       
  5520     HBufC* parameters = HBufC::NewLC( aUrl->Length() );
       
  5521     parameters->Des().Copy( *aUrl );
       
  5522     LaunchBrowserL( parameters );
       
  5523     CleanupStack::PopAndDestroy( parameters );
       
  5524     }
       
  5525 
       
  5526 // -----------------------------------------------------------------------------
       
  5527 // CDRMHelper::LaunchBrowserL
       
  5528 // Launches browser embedded with given URL
       
  5529 // -----------------------------------------------------------------------------
       
  5530 //
       
  5531 void CDRMHelper::LaunchBrowserL( HBufC* aUrl )
       
  5532     {
       
  5533     if ( aUrl )
       
  5534         {
       
  5535         HBufC* newUrl = NULL;
       
  5536         TInt i(0);
       
  5537         TPtrC ptr;
       
  5538         ptr.Set( *aUrl );
       
  5539         TBool space = ptr[i] == ' ' ? ETrue : EFalse;
       
  5540         while ( space )
       
  5541             {
       
  5542             i++;
       
  5543             space = ptr[i] == ' ' ? ETrue : EFalse;
       
  5544             }
       
  5545 
       
  5546         // if no scheme exists, use http as default scheme
       
  5547         _LIT( KColon, ":" );
       
  5548         if ( ptr.Find( KColon ) == KErrNotFound )
       
  5549             {
       
  5550             _LIT( KHttp, "http://" );
       
  5551             const TInt KHttpLen(7);
       
  5552             newUrl = HBufC::NewLC( KHttpLen + aUrl->Length() );
       
  5553             newUrl->Des().Copy( KHttp );
       
  5554             newUrl->Des().Append( ptr.Mid( i ) );
       
  5555             ptr.Set( *newUrl );
       
  5556             i = 0;
       
  5557             }
       
  5558 
       
  5559         CSchemeHandler* schemeHandler( CSchemeHandler::NewL( ptr.Mid( i ) ) );
       
  5560         CleanupStack::PushL( schemeHandler );
       
  5561         if ( iUseCoeEnv )
       
  5562             {
       
  5563             // launch embedded
       
  5564             schemeHandler->Observer( this );
       
  5565             schemeHandler->HandleUrlEmbeddedL();
       
  5566             CleanupStack::Pop( schemeHandler );
       
  5567             iSchemeHandler = schemeHandler;
       
  5568             iWait.Start();
       
  5569             }
       
  5570         else
       
  5571             {
       
  5572             // no CoeEnv, launch standalone with scheme app
       
  5573             schemeHandler->HandleUrlStandaloneL();
       
  5574             CleanupStack::PopAndDestroy( schemeHandler );
       
  5575             }
       
  5576         schemeHandler = NULL;
       
  5577 
       
  5578         // delete newUrl if needed
       
  5579         if ( newUrl )
       
  5580             {
       
  5581             CleanupStack::PopAndDestroy( newUrl );
       
  5582             }
       
  5583         }
       
  5584     else
       
  5585         {
       
  5586         User::Leave( KErrArgument );
       
  5587         }
       
  5588     }
       
  5589 
       
  5590 // -----------------------------------------------------------------------------
       
  5591 // CDRMHelper::LaunchRightsManagerUiL
       
  5592 // -----------------------------------------------------------------------------
       
  5593 //
       
  5594 void CDRMHelper::LaunchRightsManagerUiL( const TDesC& aParam16 )
       
  5595     {
       
  5596     const TUid KUidDRMUI = {0x101f85c7};
       
  5597 
       
  5598     if ( iUseCoeEnv )
       
  5599         {
       
  5600         CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();
       
  5601         TAiwVariant variantObject( aParam16 );
       
  5602         TAiwGenericParam param( EGenericParamFile, variantObject );
       
  5603         paramList->AppendL( param );
       
  5604 
       
  5605         CAknLaunchAppService* launchAppService =
       
  5606             CAknLaunchAppService::NewL( KUidDRMUI, this, paramList );
       
  5607         iWait.Start();
       
  5608         delete launchAppService;
       
  5609 
       
  5610         CleanupStack::PopAndDestroy( paramList ); // paramList
       
  5611         }
       
  5612     else
       
  5613         {
       
  5614         // no UI to embed, launch Rights Manager UI stand-alone
       
  5615 
       
  5616         // check if Rights Manager UI is already running
       
  5617         RWsSession wsSession;
       
  5618         User::LeaveIfError( wsSession.Connect() );
       
  5619         CleanupClosePushL( wsSession );
       
  5620         TApaTaskList tasklist( wsSession );
       
  5621         TApaTask task = tasklist.FindApp( KUidDRMUI );
       
  5622         if ( task.Exists() )
       
  5623             {
       
  5624             // Rights Manager UI is already running
       
  5625             HBufC8* param8 = HBufC8::NewLC( aParam16.Length() );
       
  5626             TPtr8 parametersPtr = param8->Des();
       
  5627             parametersPtr.Copy( aParam16 );
       
  5628             task.SendMessage( TUid::Uid( KUidApaMessageSwitchOpenFileValue ), *param8 );
       
  5629             CleanupStack::PopAndDestroy( param8 );
       
  5630             }
       
  5631         else
       
  5632             {
       
  5633             RApaLsSession appArcSession;
       
  5634             User::LeaveIfError( appArcSession.Connect() );
       
  5635             TThreadId id;
       
  5636             appArcSession.StartDocument( aParam16, KUidDRMUI, id );
       
  5637             appArcSession.Close();
       
  5638             }
       
  5639         CleanupStack::PopAndDestroy( &wsSession );
       
  5640         }
       
  5641     return;
       
  5642     }
       
  5643 
       
  5644 #pragma mark -
       
  5645 
       
  5646 // -----------------------------------------------------------------------------
       
  5647 // CDRMHelper::GetRightsIssuerL
       
  5648 // -----------------------------------------------------------------------------
       
  5649 //
       
  5650 void CDRMHelper::GetRightsIssuerL( const CData& aContent, HBufC*& aIssuer )
       
  5651     {
       
  5652     RDRMRightsClient client;
       
  5653     TInt error;
       
  5654     HBufC* decodedIssuer = NULL;
       
  5655     HBufC* newBuf = NULL;
       
  5656     TInt urlLength = KUrlMaxLen;
       
  5657 
       
  5658     // connect to the rights server
       
  5659     User::LeaveIfError( client.Connect() );
       
  5660     CleanupClosePushL( client );
       
  5661 
       
  5662     HBufC* rightsIssuerBuf = HBufC::NewLC( urlLength );
       
  5663     TPtr rightsIssuer(const_cast<TUint16*>(rightsIssuerBuf->Ptr()), 0, urlLength);
       
  5664 
       
  5665     // Get value of rights-issuer header field
       
  5666     error = aContent.GetStringAttribute( ERightsIssuerUrl, rightsIssuer );
       
  5667 
       
  5668     while ( error == KErrOverflow )
       
  5669         {
       
  5670         urlLength += KUrlMaxLen;
       
  5671         newBuf = rightsIssuerBuf->ReAllocL( urlLength );
       
  5672         CleanupStack::Pop( rightsIssuerBuf );
       
  5673         rightsIssuerBuf = newBuf;
       
  5674         CleanupStack::PushL( rightsIssuerBuf );
       
  5675         rightsIssuer.Set(const_cast<TUint16*>(rightsIssuerBuf->Ptr()), 0, urlLength);
       
  5676         error = aContent.GetStringAttribute( ERightsIssuerUrl, rightsIssuer );
       
  5677         }
       
  5678 
       
  5679     // If we got no error, and found some rights issuer
       
  5680     if ( ( !error  ) && ( rightsIssuer.Length() != 0 ) )
       
  5681         {
       
  5682         if ( aIssuer )
       
  5683             {
       
  5684             delete aIssuer;
       
  5685             aIssuer = NULL;
       
  5686             }
       
  5687 
       
  5688         // check if rights issuer is encrypted
       
  5689         if ( rightsIssuer.MatchF( KEncryptedRightsIssuerMatchString ) !=
       
  5690             KErrNotFound )
       
  5691             {
       
  5692             HBufC8* input = NULL;
       
  5693             HBufC8* output = NULL;
       
  5694 
       
  5695             input = CnvUtfConverter::ConvertFromUnicodeToUtf8L(rightsIssuer);
       
  5696             CleanupStack::PushL( input );
       
  5697 
       
  5698             // encrypted, decrypt
       
  5699             User::LeaveIfError( client.DecodeRightsIssuerField( *input,
       
  5700                     output ) );
       
  5701             CleanupStack::PopAndDestroy( input );
       
  5702             CleanupStack::PushL( output );
       
  5703 
       
  5704             decodedIssuer= CnvUtfConverter::ConvertToUnicodeFromUtf8L(*output);
       
  5705             CleanupStack::PopAndDestroy( output );
       
  5706 
       
  5707             aIssuer = decodedIssuer;
       
  5708             }
       
  5709         else
       
  5710             {
       
  5711             aIssuer = rightsIssuer.AllocL();
       
  5712             }
       
  5713         }
       
  5714     else if ( rightsIssuer.Length() != 0 )
       
  5715         {
       
  5716         if ( aIssuer )
       
  5717             {
       
  5718             delete aIssuer;
       
  5719             aIssuer = NULL;
       
  5720             }
       
  5721         User::Leave( KErrNotFound );
       
  5722         }
       
  5723     CleanupStack::PopAndDestroy( rightsIssuerBuf );
       
  5724     CleanupStack::PopAndDestroy( &client );
       
  5725     User::LeaveIfError( error );
       
  5726     }
       
  5727 
       
  5728 // -----------------------------------------------------------------------------
       
  5729 // CDRMHelper::CalculateEndTime
       
  5730 // -----------------------------------------------------------------------------
       
  5731 //
       
  5732 TInt CDRMHelper::CalculateEndTime(
       
  5733     CDRMRights* aRights,
       
  5734     TInt aIntent,
       
  5735     TTime& aEndTime,
       
  5736     TBool& aInactive )
       
  5737     {
       
  5738     CDRMRightsConstraints* constraint = NULL;
       
  5739     TInt error( KErrNotFound );
       
  5740 
       
  5741     if ( aIntent == DRMCommon::EPrint )
       
  5742         {
       
  5743         if ( aRights->GetPrintRight( constraint ) == DRMCommon::EOk )
       
  5744             {
       
  5745             error = GetEndTime( constraint, aEndTime, aInactive );
       
  5746             }
       
  5747         delete constraint;
       
  5748         constraint = NULL;
       
  5749         }
       
  5750 
       
  5751     if ( aIntent == DRMCommon::EExecute )
       
  5752         {
       
  5753         if ( aRights->GetExecuteRight( constraint ) == DRMCommon::EOk )
       
  5754             {
       
  5755             error = GetEndTime( constraint, aEndTime, aInactive );
       
  5756             }
       
  5757         delete constraint;
       
  5758         constraint = NULL;
       
  5759         }
       
  5760 
       
  5761     if ( aIntent == DRMCommon::EPlay )
       
  5762         {
       
  5763         if ( aRights->GetPlayRight( constraint ) == DRMCommon::EOk )
       
  5764             {
       
  5765             error = GetEndTime( constraint, aEndTime, aInactive );
       
  5766             }
       
  5767         delete constraint;
       
  5768         constraint = NULL;
       
  5769         }
       
  5770 
       
  5771     if ( aIntent == DRMCommon::EDisplay )
       
  5772         {
       
  5773         if ( aRights->GetDisplayRight( constraint ) == DRMCommon::EOk )
       
  5774             {
       
  5775             error = GetEndTime( constraint, aEndTime, aInactive );
       
  5776             }
       
  5777         delete constraint;
       
  5778         }
       
  5779 
       
  5780     return error;
       
  5781     }
       
  5782 
       
  5783 // -----------------------------------------------------------------------------
       
  5784 // CDRMHelper::GetStartTime
       
  5785 // -----------------------------------------------------------------------------
       
  5786 //
       
  5787 TInt CDRMHelper::GetStartTime(
       
  5788     CDRMRights* aRights,
       
  5789     TInt aIntent,
       
  5790     TTime& aStartTime)
       
  5791     {
       
  5792     CDRMRightsConstraints* constraint = NULL;
       
  5793     TInt error( KErrNotFound );
       
  5794 
       
  5795     if ( aIntent == DRMCommon::EPrint )
       
  5796         {
       
  5797         if ( aRights->GetPrintRight( constraint ) == DRMCommon::EOk )
       
  5798             {
       
  5799             error = constraint->GetStartTime( aStartTime );
       
  5800             }
       
  5801         delete constraint;
       
  5802         constraint = NULL;
       
  5803         }
       
  5804 
       
  5805     if ( aIntent == DRMCommon::EExecute )
       
  5806         {
       
  5807         if ( aRights->GetExecuteRight( constraint ) == DRMCommon::EOk )
       
  5808             {
       
  5809             error = constraint->GetStartTime( aStartTime );
       
  5810             }
       
  5811         delete constraint;
       
  5812         constraint = NULL;
       
  5813         }
       
  5814 
       
  5815     if ( aIntent == DRMCommon::EPlay )
       
  5816         {
       
  5817         if ( aRights->GetPlayRight( constraint ) == DRMCommon::EOk )
       
  5818             {
       
  5819             error = constraint->GetStartTime( aStartTime );
       
  5820             }
       
  5821         delete constraint;
       
  5822         constraint = NULL;
       
  5823         }
       
  5824 
       
  5825     if ( aIntent == DRMCommon::EDisplay )
       
  5826         {
       
  5827         if ( aRights->GetDisplayRight( constraint ) == DRMCommon::EOk )
       
  5828             {
       
  5829             error = constraint->GetStartTime( aStartTime );
       
  5830             }
       
  5831         delete constraint;
       
  5832         }
       
  5833 
       
  5834     return error;
       
  5835     }
       
  5836 
       
  5837 // -----------------------------------------------------------------------------
       
  5838 // CDRMHelper::GetEndTime
       
  5839 // -----------------------------------------------------------------------------
       
  5840 //
       
  5841 TInt CDRMHelper::GetEndTime(
       
  5842     CDRMRightsConstraints* aConstraint,
       
  5843     TTime& aEndTime,
       
  5844     TBool& aInactive )
       
  5845     {
       
  5846     TTime endTime;
       
  5847     TInt error ( KErrNotFound );
       
  5848 
       
  5849     if ( aConstraint->GetEndTime( endTime ) == DRMCommon::EOk )
       
  5850         {
       
  5851         aEndTime = endTime;
       
  5852         error = KErrNone;
       
  5853         aInactive = EFalse;
       
  5854         }
       
  5855     else
       
  5856         {
       
  5857         TTimeIntervalSeconds interval;
       
  5858 
       
  5859         if ( aConstraint->GetInterval( interval ) == DRMCommon::EOk )
       
  5860             {
       
  5861             // interval rights
       
  5862             TTime start;
       
  5863 
       
  5864             if ( aConstraint->GetIntervalStart( start ) == DRMCommon::EOk )
       
  5865                 {
       
  5866                 // activated interval
       
  5867                 aEndTime = start + interval;
       
  5868                 aInactive = EFalse;
       
  5869                 }
       
  5870             else
       
  5871                 {
       
  5872                 // inactive interval
       
  5873                 aEndTime.HomeTime();
       
  5874                 aEndTime += interval;
       
  5875                 aInactive = ETrue;
       
  5876                 }
       
  5877             error = KErrNone;
       
  5878             }
       
  5879         }
       
  5880     return error;
       
  5881     }
       
  5882 
       
  5883 
       
  5884 #pragma mark -
       
  5885 
       
  5886 EXPORT_C TInt CDRMHelper::Consume2(
       
  5887     const TDesC8& aContentURI,
       
  5888     TUint32 aRightsSpec,
       
  5889     TDRMHelperConsumeAction anAction)
       
  5890     {
       
  5891     CConsumeData* newData = NULL;
       
  5892     TInt ret = KErrNone;
       
  5893     ContentAccess::TIntent intent = ContentAccess::EUnknown;
       
  5894     TInt i;
       
  5895     TBool found = EFalse;
       
  5896 
       
  5897     // convert rights spec + action -> intent
       
  5898     if ( anAction == EStart )
       
  5899         {
       
  5900         switch ( aRightsSpec )
       
  5901             {
       
  5902             case CDRMRights::EPlay:
       
  5903                 intent = ContentAccess::EPlay;
       
  5904                 break;
       
  5905             case CDRMRights::EDisplay:
       
  5906                 intent = ContentAccess::EView;
       
  5907                 break;
       
  5908             case CDRMRights::EPrint:
       
  5909                 intent = ContentAccess::EPrint;
       
  5910                 break;
       
  5911             case CDRMRights::EExecute:
       
  5912                 intent = ContentAccess::EExecute;
       
  5913                 break;
       
  5914             case CDRMRights::EInstall:
       
  5915                 intent = ContentAccess::EInstall;
       
  5916                 break;
       
  5917             default:
       
  5918                 break;
       
  5919             }
       
  5920         }
       
  5921     else if ( anAction == EFinish )
       
  5922         {
       
  5923         intent = ContentAccess::EStop;
       
  5924         }
       
  5925     else if ( anAction == EPause )
       
  5926         {
       
  5927         intent = ContentAccess::EPause;
       
  5928         }
       
  5929     else if ( anAction == EContinue )
       
  5930         {
       
  5931         intent = ContentAccess::EContinue;
       
  5932         }
       
  5933 
       
  5934     // find correct item from list
       
  5935     for ( i = 0; i < iConsumeList.Count(); i++ )
       
  5936         {
       
  5937         if ( iConsumeList[i]->CompareUri( aContentURI ) == 0 )
       
  5938             {
       
  5939             found = ETrue;
       
  5940             break;
       
  5941             }
       
  5942         }
       
  5943 
       
  5944     if ( intent == ContentAccess::EStop )
       
  5945         {
       
  5946         if ( found )
       
  5947             {
       
  5948             // finish consume
       
  5949             ret = iConsumeList[i]->Consume( intent );
       
  5950 
       
  5951             // remove from list
       
  5952             delete iConsumeList[i];
       
  5953             iConsumeList.Remove( i );
       
  5954             }
       
  5955         else
       
  5956             {
       
  5957             // not found
       
  5958             ret = KErrNotFound;
       
  5959             }
       
  5960         }
       
  5961     else
       
  5962         {
       
  5963         // start, pause or continue
       
  5964         if ( !found )
       
  5965             {
       
  5966             TInt len = aContentURI.Length();
       
  5967             if ( len )
       
  5968                 {
       
  5969                 // for pause and continue existing connection is required
       
  5970                 if ( intent != ContentAccess::EPause &&
       
  5971                     intent != ContentAccess::EContinue )
       
  5972                     {
       
  5973                     // no previous connection with this content
       
  5974                     TRAP( ret, newData = CConsumeData::NewL( aContentURI ) );
       
  5975 
       
  5976                     if ( !ret )
       
  5977                         {
       
  5978                         iConsumeList.Append( newData );
       
  5979                         ret = newData->Consume( intent );
       
  5980                         }
       
  5981                     }
       
  5982                 else
       
  5983                     {
       
  5984                     // pause or continue
       
  5985                     ret = KErrNotFound;
       
  5986                     }
       
  5987                 }
       
  5988             else
       
  5989                 {
       
  5990                 // empty content URI
       
  5991                 ret = KErrArgument;
       
  5992                 }
       
  5993             }
       
  5994         else
       
  5995             {
       
  5996             // we have consume active for this content, just call
       
  5997             // consume again
       
  5998             ret = iConsumeList[i]->Consume( intent );
       
  5999             }
       
  6000         }
       
  6001     return ret;
       
  6002     }
       
  6003 
       
  6004 
       
  6005 EXPORT_C TInt CDRMHelper::ConsumeFile2(
       
  6006     const TDesC& aFileName,
       
  6007     TUint32 aRightsSpec,
       
  6008     TDRMHelperConsumeAction anAction)
       
  6009     {
       
  6010     CDcfCommon* dcf = NULL;
       
  6011     RFile file;
       
  6012     TInt r = KErrNone;
       
  6013 
       
  6014     r = file.Open(iFs, aFileName, EFileRead | EFileShareReadersOrWriters);
       
  6015 
       
  6016     if (r == KErrInUse)
       
  6017         {
       
  6018         r = file.Open(iFs, aFileName, EFileRead | EFileShareAny);
       
  6019         if (r == KErrInUse)
       
  6020             {
       
  6021             r = file.Open(iFs, aFileName, EFileRead | EFileShareReadersOnly);
       
  6022             }
       
  6023         }
       
  6024     if (r == KErrNone)
       
  6025         {
       
  6026         TRAP(r, dcf = CDcfCommon::NewL(file));
       
  6027         if ( dcf )
       
  6028             {
       
  6029             r = Consume2(*dcf->iContentID, aRightsSpec, anAction);
       
  6030             delete dcf;
       
  6031             }
       
  6032         file.Close();
       
  6033         }
       
  6034     return r;
       
  6035     }
       
  6036 
       
  6037 
       
  6038 EXPORT_C TInt CDRMHelper::ConsumeFile2(
       
  6039     RFile& aFileHandle,
       
  6040     TUint32 aRightsSpec,
       
  6041     TDRMHelperConsumeAction anAction)
       
  6042     {
       
  6043     CDcfCommon* dcf = NULL;
       
  6044     TInt r = KErrNone;
       
  6045 
       
  6046     TRAP(r, dcf = CDcfCommon::NewL(aFileHandle));
       
  6047     if ( dcf )
       
  6048         {
       
  6049         r = Consume2(*dcf->iContentID, aRightsSpec, anAction);
       
  6050         delete dcf;
       
  6051         }
       
  6052     return r;
       
  6053     }
       
  6054 
       
  6055 
       
  6056 #pragma mark -
       
  6057 
       
  6058 // -----------------------------------------------------------------------------
       
  6059 // CDRMHelper::ActivateContentL
       
  6060 // -----------------------------------------------------------------------------
       
  6061 //
       
  6062 EXPORT_C void CDRMHelper::ActivateContentL( CData& aContent )
       
  6063     {
       
  6064     if ( iOma2 )
       
  6065         {
       
  6066         TInt drmProtected(0);
       
  6067         aContent.GetAttribute( EIsProtected, drmProtected );
       
  6068         // no need to do anything if content is not protected
       
  6069         if ( drmProtected )
       
  6070             {
       
  6071             TInt expired(0);
       
  6072             TInt missing(0);
       
  6073 
       
  6074             // Check if rights are expired or missing
       
  6075             aContent.GetAttribute( ERightsHaveExpired, expired );
       
  6076             aContent.GetAttribute( ERightsNone, missing );
       
  6077             if ( expired || missing )
       
  6078                 {
       
  6079                 HBufC* rightsIssuer = NULL;
       
  6080 
       
  6081                 // Get RI URL
       
  6082                 TRAPD( err, GetRightsIssuerL( aContent, rightsIssuer ) );
       
  6083                 if ( !err )
       
  6084                     {
       
  6085                     TInt buyRights;
       
  6086                     // superdistributable
       
  6087                     CleanupStack::PushL( rightsIssuer );
       
  6088 
       
  6089                     if ( expired )
       
  6090                         {
       
  6091                         buyRights = DisplayQueryWithIdL(
       
  6092                             R_DRMHELPER_USAGE_RIGHTS_EXPIRED_BUY_NEW,
       
  6093                             R_DRMHELPER_CONFIRMATION_QUERY );
       
  6094                         }
       
  6095                     else
       
  6096                         {
       
  6097                         // rights missing
       
  6098                         buyRights = DisplayQueryWithIdL(
       
  6099                             R_DRMHELPER_NO_USAGE_RIGHTS_BUY_NEW,
       
  6100                             R_DRMHELPER_CONFIRMATION_QUERY );
       
  6101                         }
       
  6102 
       
  6103                     if ( buyRights )
       
  6104                         {
       
  6105                         // Launch browser
       
  6106                         LaunchBrowserL( rightsIssuer );
       
  6107                         }
       
  6108                     else
       
  6109                         {
       
  6110                         User::Leave( KErrCancel );
       
  6111                         }
       
  6112 
       
  6113                     CleanupStack::PopAndDestroy( rightsIssuer );
       
  6114                     }
       
  6115                 else
       
  6116                     {
       
  6117                     // non-superdistributable
       
  6118                     if ( expired )
       
  6119                         {
       
  6120                         // rights expired
       
  6121                         DisplayInfoNoteL( R_DRMHELPER_USAGE_RIGHTS_EXPIRED );
       
  6122                         }
       
  6123                     else
       
  6124                         {
       
  6125                         // rights missing
       
  6126                         DisplayInfoNoteL( R_DRMHELPER_NO_USAGE_RIGHTS );
       
  6127                         }
       
  6128                     }
       
  6129                 }
       
  6130             else
       
  6131                 {
       
  6132                 // If rights are valid or future rights, they should not be
       
  6133                 // updated
       
  6134                 User::Leave( KErrArgument );
       
  6135                 }
       
  6136             }
       
  6137         else
       
  6138             {
       
  6139             // this function should be called only for protected content
       
  6140             User::Leave( KErrArgument );
       
  6141             }
       
  6142         }
       
  6143     else
       
  6144         {
       
  6145         User::Leave( KErrNotSupported );
       
  6146         }
       
  6147     }
       
  6148 
       
  6149 
       
  6150 // -----------------------------------------------------------------------------
       
  6151 // CDRMHelper::ActivateContentL
       
  6152 // -----------------------------------------------------------------------------
       
  6153 //
       
  6154 EXPORT_C void CDRMHelper::ActivateContentL( TDesC& aFileName )
       
  6155     {
       
  6156     if ( iOma2 )
       
  6157         {
       
  6158         TVirtualPathPtr virtualPath( aFileName );
       
  6159 
       
  6160         CData* content = NULL;
       
  6161         TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  6162         if ( r == KErrInUse )
       
  6163             {
       
  6164             content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  6165             }
       
  6166         else
       
  6167             {
       
  6168             User::LeaveIfError( r );
       
  6169             }
       
  6170         CleanupStack::PushL( content );
       
  6171 
       
  6172         ActivateContentL( *content );
       
  6173         CleanupStack::PopAndDestroy( content );
       
  6174         }
       
  6175     else
       
  6176         {
       
  6177         User::Leave( KErrNotSupported );
       
  6178         }
       
  6179     }
       
  6180 
       
  6181 
       
  6182 #pragma mark -
       
  6183 
       
  6184 // -----------------------------------------------------------------------------
       
  6185 // CDRMHelper::HasInfoUrlL
       
  6186 // -----------------------------------------------------------------------------
       
  6187 //
       
  6188 EXPORT_C TBool CDRMHelper::HasInfoUrlL( CData& aContent, HBufC8*& aInfoUrl )
       
  6189     {
       
  6190     TBool ret = EFalse;
       
  6191 
       
  6192     if ( iOma2 )
       
  6193         {
       
  6194         TBuf<KUrlMaxLen> infoUrl;
       
  6195 
       
  6196         TInt error = aContent.GetStringAttribute( EInfoURL, infoUrl );
       
  6197         if ( !error )
       
  6198             {
       
  6199             infoUrl.TrimLeft();
       
  6200             if ( infoUrl.Length() > 0 )
       
  6201                 {
       
  6202                 aInfoUrl = HBufC8::NewL( infoUrl.Length() );
       
  6203                 aInfoUrl->Des().Copy( infoUrl );
       
  6204                 ret = ETrue;
       
  6205                 }
       
  6206             else
       
  6207                 {
       
  6208                 ret = EFalse;
       
  6209                 }
       
  6210             }
       
  6211         else
       
  6212             {
       
  6213             ret = EFalse;
       
  6214             }
       
  6215         }
       
  6216     else
       
  6217         {
       
  6218         User::Leave( KErrNotSupported );
       
  6219         }
       
  6220 
       
  6221     return ret;
       
  6222     }
       
  6223 
       
  6224 
       
  6225 // -----------------------------------------------------------------------------
       
  6226 // CDRMHelper::HasInfoUrlL
       
  6227 // -----------------------------------------------------------------------------
       
  6228 //
       
  6229 EXPORT_C TBool CDRMHelper::HasInfoUrlL(TDesC& aFileName, HBufC8*& aInfoUrl )
       
  6230     {
       
  6231     TBool ret = EFalse;
       
  6232 
       
  6233     if ( iOma2 )
       
  6234         {
       
  6235         TVirtualPathPtr virtualPath( aFileName );
       
  6236 
       
  6237         CData* content( NULL );
       
  6238         TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  6239         if ( r == KErrInUse )
       
  6240             {
       
  6241             content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  6242             }
       
  6243         else
       
  6244             {
       
  6245             User::LeaveIfError( r );
       
  6246             }
       
  6247 
       
  6248         CleanupStack::PushL( content );
       
  6249 
       
  6250         ret = HasInfoUrlL( *content, aInfoUrl );
       
  6251         CleanupStack::PopAndDestroy( content );
       
  6252         }
       
  6253     else
       
  6254         {
       
  6255         User::Leave( KErrNotSupported );
       
  6256         }
       
  6257 
       
  6258     return ret;
       
  6259     }
       
  6260 
       
  6261 
       
  6262 // -----------------------------------------------------------------------------
       
  6263 // CDRMHelper::OpenInfoUrlL
       
  6264 // -----------------------------------------------------------------------------
       
  6265 //
       
  6266 EXPORT_C void CDRMHelper::OpenInfoUrlL( CData& aContent )
       
  6267     {
       
  6268     if ( iOma2 )
       
  6269         {
       
  6270         HBufC8* infoUrl;
       
  6271         if ( HasInfoUrlL( aContent, infoUrl ) )
       
  6272             {
       
  6273             CleanupStack::PushL( infoUrl );
       
  6274             LaunchBrowserL( infoUrl );
       
  6275             CleanupStack::PopAndDestroy( infoUrl );
       
  6276             }
       
  6277         else
       
  6278             {
       
  6279             User::Leave( KErrArgument );
       
  6280             }
       
  6281         }
       
  6282     else
       
  6283         {
       
  6284         User::Leave( KErrNotSupported );
       
  6285         }
       
  6286     }
       
  6287 
       
  6288 
       
  6289 // -----------------------------------------------------------------------------
       
  6290 // CDRMHelper::OpenInfoUrlL
       
  6291 // -----------------------------------------------------------------------------
       
  6292 //
       
  6293 EXPORT_C void CDRMHelper::OpenInfoUrlL(TDesC& aFileName )
       
  6294     {
       
  6295     if ( iOma2 )
       
  6296         {
       
  6297         TVirtualPathPtr virtualPath( aFileName );
       
  6298 
       
  6299         CData* content( NULL );
       
  6300         TRAPD( r, content = CData::NewL( virtualPath, EPeek, EContentShareReadWrite ) );
       
  6301         if ( r == KErrInUse )
       
  6302             {
       
  6303             content = CData::NewL( virtualPath, EPeek, EContentShareReadOnly );
       
  6304             }
       
  6305         else
       
  6306             {
       
  6307             User::LeaveIfError( r );
       
  6308             }
       
  6309 
       
  6310         CleanupStack::PushL( content );
       
  6311 
       
  6312         OpenInfoUrlL( *content );
       
  6313         CleanupStack::PopAndDestroy( content );
       
  6314         }
       
  6315     else
       
  6316         {
       
  6317         User::Leave( KErrNotSupported );
       
  6318         }
       
  6319     }
       
  6320 
       
  6321 #pragma mark -
       
  6322 
       
  6323 // -----------------------------------------------------------------------------
       
  6324 // CDRMHelper::DisplayQueryL
       
  6325 // -----------------------------------------------------------------------------
       
  6326 //
       
  6327 TInt CDRMHelper::DisplayQueryWithIdL(
       
  6328     TInt aTextResourceId,
       
  6329     TInt aQueryResourceId )
       
  6330     {
       
  6331     TInt button(0);
       
  6332     if ( iUseCoeEnv )
       
  6333         {
       
  6334 
       
  6335 #ifndef RD_MULTIPLE_DRIVE
       
  6336 
       
  6337         TFileName fileName( KDriveZ );
       
  6338 
       
  6339 #else //RD_MULTIPLE_DRIVE
       
  6340 
       
  6341         _LIT( KDrive, "%c:");
       
  6342         TInt driveNumber( -1 );
       
  6343         TChar driveLetter;
       
  6344         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  6345         iFs.DriveToChar( driveNumber, driveLetter );
       
  6346 
       
  6347         TFileName fileName;
       
  6348 
       
  6349         fileName.Format( KDrive, (TUint)driveLetter );
       
  6350 
       
  6351 #endif
       
  6352 
       
  6353         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
  6354         fileName.Append( KCDRMHelperResFileName );
       
  6355         RConeResourceLoader loader( *iCoeEnv );
       
  6356         loader.OpenL( fileName );
       
  6357         CleanupClosePushL( loader );
       
  6358 
       
  6359         HBufC* msgText = StringLoader::LoadLC( aTextResourceId, iCoeEnv );
       
  6360         button = DisplayQueryL( *msgText, aQueryResourceId );
       
  6361         CleanupStack::PopAndDestroy( msgText );
       
  6362         CleanupStack::PopAndDestroy( &loader );
       
  6363         }
       
  6364     else
       
  6365         {
       
  6366         TInt buttonsId =
       
  6367             aQueryResourceId == R_DRMHELPER_WAITING_RIGHTS_CONFIRMATION_QUERY ?
       
  6368             R_AVKON_SOFTKEYS_OK_EMPTY__OK : R_AVKON_SOFTKEYS_YES_NO__YES;
       
  6369         CDRMHelperGlobalNoteWrapper* noteWrapper =
       
  6370             CDRMHelperGlobalNoteWrapper::NewLC( iStringResourceReader );
       
  6371 
       
  6372         button = noteWrapper->ShowNoteWithButtonsL( aTextResourceId, buttonsId );
       
  6373         CleanupStack::PopAndDestroy( noteWrapper );
       
  6374         }
       
  6375     return button;
       
  6376     }
       
  6377 
       
  6378 // -----------------------------------------------------------------------------
       
  6379 // CDRMHelper::DisplayQueryL
       
  6380 // -----------------------------------------------------------------------------
       
  6381 //
       
  6382 TInt CDRMHelper::DisplayQueryWithIdValueL(
       
  6383     TInt aTextResourceId,
       
  6384     TInt aQueryResourceId,
       
  6385     const TDesC& aString )
       
  6386     {
       
  6387     TInt button(0);
       
  6388     if ( iUseCoeEnv )
       
  6389         {
       
  6390 
       
  6391 #ifndef RD_MULTIPLE_DRIVE
       
  6392 
       
  6393         TFileName fileName( KDriveZ );
       
  6394 
       
  6395 #else //RD_MULTIPLE_DRIVE
       
  6396 
       
  6397         _LIT( KDrive, "%c:");
       
  6398         TInt driveNumber( -1 );
       
  6399         TChar driveLetter;
       
  6400         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  6401         iFs.DriveToChar( driveNumber, driveLetter );
       
  6402 
       
  6403         TFileName fileName;
       
  6404 
       
  6405         fileName.Format( KDrive, (TUint)driveLetter );
       
  6406 
       
  6407 #endif
       
  6408 
       
  6409         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
  6410         fileName.Append( KCDRMHelperResFileName );
       
  6411         RConeResourceLoader loader( *iCoeEnv );
       
  6412         loader.OpenL( fileName );
       
  6413         CleanupClosePushL( loader );
       
  6414 
       
  6415         HBufC* msgText = StringLoader::LoadLC( aTextResourceId, aString, iCoeEnv );
       
  6416         button = DisplayQueryL( *msgText, aQueryResourceId );
       
  6417         CleanupStack::PopAndDestroy( msgText );
       
  6418         CleanupStack::PopAndDestroy( &loader );
       
  6419         }
       
  6420     else
       
  6421         {
       
  6422         TInt buttonsId =
       
  6423             aQueryResourceId == R_DRMHELPER_WAITING_RIGHTS_CONFIRMATION_QUERY ?
       
  6424             R_AVKON_SOFTKEYS_OK_EMPTY__OK : R_AVKON_SOFTKEYS_YES_NO__YES;
       
  6425         CDRMHelperGlobalNoteWrapper* noteWrapper =
       
  6426             CDRMHelperGlobalNoteWrapper::NewLC( iStringResourceReader );
       
  6427 
       
  6428         button = noteWrapper->ShowNoteWithButtonsL( aTextResourceId, buttonsId, aString );
       
  6429         CleanupStack::PopAndDestroy( noteWrapper );
       
  6430         }
       
  6431     return button;
       
  6432     }
       
  6433 
       
  6434 // -----------------------------------------------------------------------------
       
  6435 // CDRMHelper::DisplayQueryL
       
  6436 // -----------------------------------------------------------------------------
       
  6437 //
       
  6438 TInt CDRMHelper::DisplayQueryL( TInt aTextResourceId, TInt aValue )
       
  6439     {
       
  6440     TInt buttonCode( 0 );
       
  6441     if ( iUseCoeEnv )
       
  6442         {
       
  6443 
       
  6444 #ifndef RD_MULTIPLE_DRIVE
       
  6445 
       
  6446         TFileName fileName( KDriveZ );
       
  6447 
       
  6448 #else //RD_MULTIPLE_DRIVE
       
  6449 
       
  6450         _LIT( KDrive, "%c:");
       
  6451         TInt driveNumber( -1 );
       
  6452         TChar driveLetter;
       
  6453         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  6454         iFs.DriveToChar( driveNumber, driveLetter );
       
  6455 
       
  6456         TFileName fileName;
       
  6457 
       
  6458         fileName.Format( KDrive, (TUint)driveLetter );
       
  6459 
       
  6460 #endif
       
  6461 
       
  6462         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
  6463         fileName.Append( KCDRMHelperResFileName );
       
  6464         RConeResourceLoader loader( *iCoeEnv );
       
  6465         loader.OpenL( fileName );
       
  6466         CleanupClosePushL( loader );
       
  6467         TPtr bufPtr(0,0);
       
  6468 
       
  6469         HBufC* stringholder = StringLoader::LoadLC( aTextResourceId, aValue,
       
  6470             iCoeEnv );
       
  6471         CAknQueryDialog* dlg = CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
       
  6472         CleanupStack::PushL( dlg );
       
  6473 
       
  6474         bufPtr.Set( stringholder->Des() );
       
  6475         AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
  6476         PrepareSecondaryDisplayL( *dlg, aTextResourceId, KNullDesC, aValue );
       
  6477 
       
  6478         CleanupStack::Pop( dlg );
       
  6479 
       
  6480         buttonCode = dlg->ExecuteLD( R_DRMHELPER_CONFIRMATION_QUERY, *stringholder );
       
  6481 
       
  6482         CancelSecondaryDisplayL( aTextResourceId );
       
  6483         CleanupStack::PopAndDestroy( stringholder );
       
  6484         CleanupStack::PopAndDestroy( &loader );
       
  6485         }
       
  6486     else
       
  6487         {
       
  6488         CDRMHelperGlobalNoteWrapper* noteWrapper =
       
  6489             CDRMHelperGlobalNoteWrapper::NewLC( iStringResourceReader );
       
  6490         buttonCode = noteWrapper->ShowNoteL( aTextResourceId, aValue );
       
  6491         CleanupStack::PopAndDestroy( noteWrapper );
       
  6492         }
       
  6493     return buttonCode;
       
  6494     }
       
  6495 
       
  6496 // -----------------------------------------------------------------------------
       
  6497 // CDRMHelper::DisplayQueryL
       
  6498 // -----------------------------------------------------------------------------
       
  6499 //
       
  6500 TInt CDRMHelper::DisplayQueryL( TInt aTextResourceId, const TDesC& aString )
       
  6501     {
       
  6502     TInt buttonCode( 0 );
       
  6503     if ( iUseCoeEnv )
       
  6504         {
       
  6505 
       
  6506 #ifndef RD_MULTIPLE_DRIVE
       
  6507 
       
  6508         TFileName fileName( KDriveZ );
       
  6509 
       
  6510 #else //RD_MULTIPLE_DRIVE
       
  6511 
       
  6512         _LIT( KDrive, "%c:");
       
  6513         TInt driveNumber( -1 );
       
  6514         TChar driveLetter;
       
  6515         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  6516         iFs.DriveToChar( driveNumber, driveLetter );
       
  6517 
       
  6518         TFileName fileName;
       
  6519 
       
  6520         fileName.Format( KDrive, (TUint)driveLetter );
       
  6521 
       
  6522 #endif
       
  6523 
       
  6524         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
  6525         fileName.Append( KCDRMHelperResFileName );
       
  6526         RConeResourceLoader loader( *iCoeEnv );
       
  6527         loader.OpenL( fileName );
       
  6528         CleanupClosePushL( loader );
       
  6529         TPtr bufPtr(0,0);
       
  6530 
       
  6531         HBufC* stringholder = StringLoader::LoadLC( aTextResourceId, aString,
       
  6532             iCoeEnv );
       
  6533         CAknQueryDialog* dlg(
       
  6534             CAknQueryDialog::NewL( CAknQueryDialog::ENoTone ) );
       
  6535         CleanupStack::PushL( dlg );
       
  6536 
       
  6537         bufPtr.Set( stringholder->Des() );
       
  6538         AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
  6539         PrepareSecondaryDisplayL( *dlg, aTextResourceId, aString, -1 );
       
  6540         CleanupStack::Pop( dlg );
       
  6541 
       
  6542         buttonCode = dlg->ExecuteLD( R_DRMHELPER_CONFIRMATION_QUERY, *stringholder );
       
  6543 
       
  6544         CancelSecondaryDisplayL( aTextResourceId );
       
  6545         CleanupStack::PopAndDestroy( stringholder );
       
  6546         CleanupStack::PopAndDestroy( &loader );
       
  6547         }
       
  6548     else
       
  6549         {
       
  6550         CDRMHelperGlobalNoteWrapper* noteWrapper =
       
  6551             CDRMHelperGlobalNoteWrapper::NewLC( iStringResourceReader );
       
  6552         buttonCode = noteWrapper->ShowNoteL( aTextResourceId, aString );
       
  6553         CleanupStack::PopAndDestroy( noteWrapper );
       
  6554         }
       
  6555     return buttonCode;
       
  6556     }
       
  6557 
       
  6558 // -----------------------------------------------------------------------------
       
  6559 // CDRMHelper::DisplayQueryL
       
  6560 // -----------------------------------------------------------------------------
       
  6561 //
       
  6562 TInt CDRMHelper::DisplayQueryL(
       
  6563     TInt aTextResourceId,
       
  6564     const TDesC& aString,
       
  6565     TInt aValue,
       
  6566     TInt aStringPos,
       
  6567     TInt aValuePos )
       
  6568     {
       
  6569     TInt buttonCode( 0 );
       
  6570     if ( iUseCoeEnv )
       
  6571         {
       
  6572 
       
  6573 #ifndef RD_MULTIPLE_DRIVE
       
  6574 
       
  6575         TFileName fileName( KDriveZ );
       
  6576 
       
  6577 #else //RD_MULTIPLE_DRIVE
       
  6578 
       
  6579         _LIT( KDrive, "%c:");
       
  6580         TInt driveNumber( -1 );
       
  6581         TChar driveLetter;
       
  6582         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  6583         iFs.DriveToChar( driveNumber, driveLetter );
       
  6584 
       
  6585         TFileName fileName;
       
  6586 
       
  6587         fileName.Format( KDrive, (TUint)driveLetter );
       
  6588 
       
  6589 #endif
       
  6590 
       
  6591         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
  6592         fileName.Append( KCDRMHelperResFileName );
       
  6593         RConeResourceLoader loader( *iCoeEnv );
       
  6594         loader.OpenL( fileName );
       
  6595         CleanupClosePushL( loader );
       
  6596         TPtr bufPtr( 0,0 );
       
  6597 
       
  6598         TBuf<KDRMHelperNoteMaxSize> textBuffer, textBuffer2;
       
  6599         StringLoader::Load( textBuffer, aTextResourceId, iCoeEnv );
       
  6600         StringLoader::Format( textBuffer2, textBuffer, aValuePos, aValue );
       
  6601         textBuffer = textBuffer2;
       
  6602         StringLoader::Format( textBuffer2, textBuffer, aStringPos, aString );
       
  6603 
       
  6604         bufPtr.Set( const_cast <TUint16*>( textBuffer2.Ptr() ), textBuffer2.Length(),
       
  6605             textBuffer2.Length() );
       
  6606         AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
  6607 
       
  6608         CAknQueryDialog* dlg =
       
  6609             CAknQueryDialog::NewL( CAknQueryDialog::ENoTone );
       
  6610         PrepareSecondaryDisplayL( *dlg, aTextResourceId, aString, aValue );
       
  6611         buttonCode =
       
  6612             dlg->ExecuteLD( R_DRMHELPER_CONFIRMATION_QUERY, textBuffer2 );
       
  6613 
       
  6614         CancelSecondaryDisplayL( aTextResourceId );
       
  6615         CleanupStack::PopAndDestroy( &loader );
       
  6616         }
       
  6617     else
       
  6618         {
       
  6619         CDRMHelperGlobalNoteWrapper* noteWrapper =
       
  6620             CDRMHelperGlobalNoteWrapper::NewLC( iStringResourceReader );
       
  6621         buttonCode = noteWrapper->ShowNoteL( aTextResourceId, aString,
       
  6622             aValue, aStringPos, aValuePos );
       
  6623         CleanupStack::PopAndDestroy( noteWrapper );
       
  6624         }
       
  6625     return buttonCode;
       
  6626     }
       
  6627 
       
  6628 // -----------------------------------------------------------------------------
       
  6629 // CDRMHelper::DisplayQueryL
       
  6630 // -----------------------------------------------------------------------------
       
  6631 //
       
  6632 TInt CDRMHelper::DisplayQueryL( TDesC& aPromptText, TInt aQueryResourceId )
       
  6633     {
       
  6634     CAknQueryDialog* dlg(
       
  6635         new (ELeave) CAknQueryDialog( aPromptText, CAknQueryDialog::ENoTone ) );
       
  6636     CleanupStack::PushL( dlg );
       
  6637 
       
  6638     TPtr bufPtr( 0,0 );
       
  6639     bufPtr.Set( const_cast <TUint16*>( aPromptText.Ptr() ), aPromptText.Length(),
       
  6640         aPromptText.Length() );
       
  6641     AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
  6642 
       
  6643     PrepareSecondaryDisplayL( *dlg, aQueryResourceId, aPromptText, -1 );
       
  6644 
       
  6645     CleanupStack::Pop( dlg );
       
  6646 
       
  6647     TInt ret = dlg->ExecuteLD( aQueryResourceId );
       
  6648     CancelSecondaryDisplayL( aQueryResourceId );
       
  6649     return ret;
       
  6650     }
       
  6651 
       
  6652 // -----------------------------------------------------------------------------
       
  6653 // CDRMHelper::DisplayInfoNoteL
       
  6654 // -----------------------------------------------------------------------------
       
  6655 //
       
  6656 void CDRMHelper::DisplayInfoNoteL( TInt aTextResourceId )
       
  6657     {
       
  6658     if ( iUseCoeEnv )
       
  6659         {
       
  6660 
       
  6661 #ifndef RD_MULTIPLE_DRIVE
       
  6662 
       
  6663         TFileName fileName( KDriveZ );
       
  6664 
       
  6665 #else //RD_MULTIPLE_DRIVE
       
  6666 
       
  6667         _LIT( KDrive, "%c:");
       
  6668         TInt driveNumber( -1 );
       
  6669         TChar driveLetter;
       
  6670         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  6671         iFs.DriveToChar( driveNumber, driveLetter );
       
  6672 
       
  6673         TFileName fileName;
       
  6674 
       
  6675         fileName.Format( KDrive, (TUint)driveLetter );
       
  6676 
       
  6677 #endif
       
  6678 
       
  6679         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
  6680         fileName.Append( KCDRMHelperResFileName );
       
  6681         RConeResourceLoader loader( *iCoeEnv );
       
  6682         loader.OpenL( fileName );
       
  6683         CleanupClosePushL( loader );
       
  6684 
       
  6685         HBufC* msgText = StringLoader::LoadLC( aTextResourceId, iCoeEnv );
       
  6686         DisplayInfoNoteL( *msgText, aTextResourceId );
       
  6687         CleanupStack::PopAndDestroy( msgText );
       
  6688         CleanupStack::PopAndDestroy( &loader );
       
  6689         }
       
  6690     else
       
  6691         {
       
  6692 
       
  6693         TBuf<KDRMHelperNoteMaxSize> buffer =
       
  6694             iStringResourceReader->ReadResourceString( aTextResourceId );
       
  6695 
       
  6696         DisplayInfoNoteL( buffer, aTextResourceId );
       
  6697         }
       
  6698     }
       
  6699 
       
  6700 // -----------------------------------------------------------------------------
       
  6701 // CDRMHelper::DisplayInfoNoteL
       
  6702 // -----------------------------------------------------------------------------
       
  6703 //
       
  6704 void CDRMHelper::DisplayInfoNoteL( TInt aTextResourceId, const TDesC& aString )
       
  6705     {
       
  6706     if ( iUseCoeEnv )
       
  6707         {
       
  6708 
       
  6709 #ifndef RD_MULTIPLE_DRIVE
       
  6710 
       
  6711         TFileName fileName( KDriveZ );
       
  6712 
       
  6713 #else //RD_MULTIPLE_DRIVE
       
  6714 
       
  6715         _LIT( KDrive, "%c:");
       
  6716         TInt driveNumber( -1 );
       
  6717         TChar driveLetter;
       
  6718         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  6719         iFs.DriveToChar( driveNumber, driveLetter );
       
  6720 
       
  6721         TFileName fileName;
       
  6722 
       
  6723         fileName.Format( KDrive, (TUint)driveLetter );
       
  6724 
       
  6725 #endif
       
  6726 
       
  6727         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
  6728         fileName.Append( KCDRMHelperResFileName );
       
  6729         RConeResourceLoader loader( *iCoeEnv );
       
  6730         loader.OpenL( fileName );
       
  6731         CleanupClosePushL( loader );
       
  6732 
       
  6733         HBufC* msgText = StringLoader::LoadLC( aTextResourceId, aString,
       
  6734             iCoeEnv );
       
  6735         DisplayInfoNoteL( *msgText, aTextResourceId );
       
  6736         CleanupStack::PopAndDestroy( msgText );
       
  6737         CleanupStack::PopAndDestroy( &loader );
       
  6738         }
       
  6739     else
       
  6740         {
       
  6741         TBuf<KDRMHelperNoteMaxSize + KMaxFileName> destBuffer;
       
  6742 
       
  6743 
       
  6744         TBuf<KDRMHelperNoteMaxSize> buffer =
       
  6745             iStringResourceReader->ReadResourceString( aTextResourceId );
       
  6746 
       
  6747 
       
  6748         StringLoader::Format( destBuffer, buffer, -1, aString );
       
  6749         DisplayInfoNoteL( destBuffer, aTextResourceId, aString, -1 );
       
  6750         }
       
  6751     }
       
  6752 
       
  6753 // -----------------------------------------------------------------------------
       
  6754 // CDRMHelper::DisplayInfoNoteL
       
  6755 // -----------------------------------------------------------------------------
       
  6756 //
       
  6757 void CDRMHelper::DisplayInfoNoteL( TInt aTextResourceId, TInt aValue )
       
  6758     {
       
  6759     if ( iUseCoeEnv )
       
  6760         {
       
  6761 
       
  6762 #ifndef RD_MULTIPLE_DRIVE
       
  6763 
       
  6764         TFileName fileName( KDriveZ );
       
  6765 
       
  6766 #else //RD_MULTIPLE_DRIVE
       
  6767 
       
  6768         _LIT( KDrive, "%c:");
       
  6769         TInt driveNumber( -1 );
       
  6770         TChar driveLetter;
       
  6771         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
       
  6772         iFs.DriveToChar( driveNumber, driveLetter );
       
  6773 
       
  6774         TFileName fileName;
       
  6775 
       
  6776         fileName.Format( KDrive, (TUint)driveLetter );
       
  6777 
       
  6778 #endif
       
  6779 
       
  6780         fileName.Append( KDC_RESOURCE_FILES_DIR );
       
  6781         fileName.Append( KCDRMHelperResFileName );
       
  6782         RConeResourceLoader loader( *iCoeEnv );
       
  6783         loader.OpenL( fileName );
       
  6784         CleanupClosePushL( loader );
       
  6785 
       
  6786         HBufC* msgText = StringLoader::LoadLC( aTextResourceId, aValue,
       
  6787             iCoeEnv );
       
  6788         DisplayInfoNoteL( *msgText, aTextResourceId, KNullDesC, aValue );
       
  6789         CleanupStack::PopAndDestroy( msgText );
       
  6790         CleanupStack::PopAndDestroy( &loader );
       
  6791         }
       
  6792     else
       
  6793         {
       
  6794         TBuf<KDRMHelperNoteMaxSize + KMaxFileName> destBuffer;
       
  6795 
       
  6796 
       
  6797         TBuf<KDRMHelperNoteMaxSize> buffer =
       
  6798             iStringResourceReader->ReadResourceString( aTextResourceId );
       
  6799 
       
  6800 
       
  6801         StringLoader::Format( destBuffer, buffer, -1, aValue );
       
  6802         DisplayInfoNoteL( destBuffer, aTextResourceId, KNullDesC, aValue );
       
  6803         }
       
  6804     }
       
  6805 
       
  6806 // -----------------------------------------------------------------------------
       
  6807 // CDRMHelper::DisplayInfoNoteL
       
  6808 // -----------------------------------------------------------------------------
       
  6809 //
       
  6810 void CDRMHelper::DisplayInfoNoteL( TDesC& aPromptText, TInt aResourceId,
       
  6811     const TDesC& aString, TInt aValue )
       
  6812     {
       
  6813     TPtr bufPtr(0,0);
       
  6814     bufPtr.Set(
       
  6815         const_cast <TUint16*>( aPromptText.Ptr() ),
       
  6816         aPromptText.Length(),
       
  6817         aPromptText.Length() );
       
  6818     AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
  6819 
       
  6820     if ( iUseCoeEnv )
       
  6821         {
       
  6822         CAknResourceNoteDialog* note( CreateNoteForResourceL( aResourceId ) );
       
  6823 
       
  6824         PrepareSecondaryDisplayL( *note, aResourceId, aString, aValue );
       
  6825         note->ExecuteLD( aPromptText );
       
  6826         CancelSecondaryDisplayL( aResourceId );
       
  6827         }
       
  6828     else
       
  6829         {
       
  6830         CDRMHelperInfoNoteWrapper* note = CDRMHelperInfoNoteWrapper::NewLC();
       
  6831         User::LeaveIfError(iNoteList.Append(note)); //a list for simultanous notes
       
  6832         CleanupStack::Pop( note );
       
  6833         note->ShowNoteL( GlobalNoteTypeForResource( aResourceId ),
       
  6834             aPromptText,
       
  6835             aResourceId,
       
  6836             aString,
       
  6837             aValue );
       
  6838         }
       
  6839     }
       
  6840 
       
  6841 #pragma mark -
       
  6842 
       
  6843 // -----------------------------------------------------------------------------
       
  6844 // CDRMHelper::StripPathAndExtensionL
       
  6845 // -----------------------------------------------------------------------------
       
  6846 //
       
  6847 TPtrC CDRMHelper::StripPathAndExtension( const TDesC& aFileName )
       
  6848     {
       
  6849     // find index of last backslash
       
  6850     TInt index = aFileName.LocateReverse( '\\' );
       
  6851 
       
  6852     // get filename+extension part
       
  6853     TPtrC filenameWithExtension = aFileName.Right(
       
  6854         aFileName.Length() - (index + 1) );
       
  6855 
       
  6856     // get index of dot
       
  6857     index = filenameWithExtension.Locate( '.' );
       
  6858 
       
  6859     // if dot not found, there's no extension
       
  6860     if ( index == KErrNotFound )
       
  6861         {
       
  6862         index = (filenameWithExtension.Length() - 1);
       
  6863         }
       
  6864 
       
  6865     // strip extension
       
  6866     return filenameWithExtension.Left( index );
       
  6867     }
       
  6868 
       
  6869 // -----------------------------------------------------------------------------
       
  6870 // CDRMHelper::GetFileHandleFromURIL
       
  6871 // -----------------------------------------------------------------------------
       
  6872 //
       
  6873 TInt CDRMHelper::GetFileHandleFromURIL( const TDesC8& aURI, RFile& aFileHandle )
       
  6874     {
       
  6875     CDcfRep* rep = CDcfRep::NewL();
       
  6876     CleanupStack::PushL( rep );
       
  6877     rep->GetFileHandleL( aURI, aFileHandle, iFs );
       
  6878     CleanupStack::PopAndDestroy( rep );
       
  6879 
       
  6880     return KErrNone;
       
  6881     }
       
  6882 
       
  6883 // -----------------------------------------------------------------------------
       
  6884 // CDRMHelper::Intent
       
  6885 // -----------------------------------------------------------------------------
       
  6886 //
       
  6887 TInt CDRMHelper::Intent( const HBufC* aMimeType )
       
  6888     {
       
  6889     TInt intent = ContentAccess::EUnknown;
       
  6890 
       
  6891     _LIT( KDRMHelperMimeTypeAudio, "Audio" );
       
  6892     _LIT( KDRMHelperMimeTypeVideo, "Video" );
       
  6893     _LIT( KDRMHelperMimeTypeImage, "Image" );
       
  6894     _LIT( KDRMHelperMimeTypeApplication, "Application" );
       
  6895     _LIT( KDRMHelperMimeTypeShockwave, "Application/x-shockwave-flash" );
       
  6896     _LIT( KDRMHelperMimeTypeRingingTone, "Application/vnd.nokia.ringing-tone" );
       
  6897     _LIT( KDRMHelperMimeTypeSkin, "Application/x-series60-skn" );
       
  6898     _LIT( KDRMHelperMimeTypePIP, "Application/x-pip" );
       
  6899     _LIT( KDRMHelperMimeTypeSis, "Application/vnd.symbian.install" );
       
  6900     _LIT( KDRMHelperMimeTypeRealMedia, "Application/x-pn-realmedia" );
       
  6901     _LIT( KDRMHelperMimeTypeVndRealMedia, "Application/vnd.rn-realmedia" );
       
  6902 
       
  6903     if ( iAutomatedType == EAutomatedTypeTheme)
       
  6904         {
       
  6905         // if automated theme
       
  6906         return DRMCommon::EDisplay;
       
  6907         }
       
  6908 
       
  6909     if ( aMimeType )
       
  6910         {
       
  6911         if ( !aMimeType->FindF( KDRMHelperMimeTypeRingingTone ) )
       
  6912             {
       
  6913             // nokia ringning tone
       
  6914             intent = DRMCommon::EPlay;
       
  6915             }
       
  6916         else if ( !aMimeType->FindF( KDRMHelperMimeTypeSkin ) )
       
  6917             {
       
  6918             // skin package
       
  6919             intent = DRMCommon::EDisplay;
       
  6920             }
       
  6921         else if ( !aMimeType->FindF( KDRMHelperMimeTypePIP ) )
       
  6922             {
       
  6923             // PIP package
       
  6924             intent = DRMCommon::EExecute;
       
  6925             }
       
  6926         else if ( !aMimeType->FindF( KDRMHelperMimeTypeSis ) )
       
  6927             {
       
  6928             // executable application or skin
       
  6929             intent = DRMCommon::EExecute;
       
  6930             }
       
  6931         else if ( !aMimeType->FindF( KDRMHelperMimeTypeShockwave ) )
       
  6932             {
       
  6933             // shockwave flash
       
  6934             intent = DRMCommon::EExecute;
       
  6935             }
       
  6936         else if ( !aMimeType->FindF( KDRMHelperMimeTypeRealMedia ) ||
       
  6937             !aMimeType->FindF( KDRMHelperMimeTypeVndRealMedia ) )
       
  6938             {
       
  6939             // realmedia
       
  6940             intent = DRMCommon::EPlay;
       
  6941             }
       
  6942         else if ( !aMimeType->FindF( KDRMHelperMimeTypeApplication ) )
       
  6943             {
       
  6944             // executable application
       
  6945             intent = DRMCommon::EExecute;
       
  6946             }
       
  6947         else if ( !aMimeType->FindF( KDRMHelperMimeTypeImage ) )
       
  6948             {
       
  6949             // image
       
  6950             intent = DRMCommon::EDisplay;
       
  6951             }
       
  6952         else if ( !aMimeType->FindF( KDRMHelperMimeTypeVideo ) )
       
  6953             {
       
  6954             // video
       
  6955             intent = DRMCommon::EPlay;
       
  6956             }
       
  6957         else if ( !aMimeType->FindF( KDRMHelperMimeTypeAudio ) )
       
  6958             {
       
  6959             // audio
       
  6960             intent = DRMCommon::EPlay;
       
  6961             }
       
  6962         }
       
  6963     return intent;
       
  6964     }
       
  6965 
       
  6966 // -----------------------------------------------------------------------------
       
  6967 // CDRMHelper::MimeTypeFromURIL
       
  6968 // -----------------------------------------------------------------------------
       
  6969 //
       
  6970 HBufC* CDRMHelper::MimeTypeFromURIL( const TDesC8& aURI )
       
  6971     {
       
  6972     HBufC* mimeType = NULL;
       
  6973     RFile fileHandle;
       
  6974     TInt error ( KErrNone );
       
  6975     CleanupClosePushL(fileHandle);
       
  6976 
       
  6977     if ( !GetFileHandleFromURIL( aURI, fileHandle ) )
       
  6978         {
       
  6979         CData* content = CData::NewLC( fileHandle, KDefaultContentObject, EPeek );
       
  6980 
       
  6981         mimeType = HBufC::NewLC( KMaxDataTypeLength );
       
  6982         TPtr ptr = mimeType->Des();
       
  6983         error = content->GetStringAttribute( EMimeType, ptr );
       
  6984         if ( error != KErrNone )
       
  6985             {
       
  6986             User::Leave( KErrArgument );
       
  6987             }
       
  6988         CleanupStack::Pop( mimeType );
       
  6989         CleanupStack::PopAndDestroy( content );
       
  6990         }
       
  6991     else
       
  6992         {
       
  6993         User::Leave( KErrArgument );
       
  6994         }
       
  6995     CleanupStack::PopAndDestroy( &fileHandle );
       
  6996     return mimeType;
       
  6997     }
       
  6998 
       
  6999 EXPORT_C TInt CDRMHelper::GetContentURIList(
       
  7000     RPointerArray<HBufC8>*& aURIList)
       
  7001     {
       
  7002     return iDRMCommon->GetContentURIList( aURIList );
       
  7003     }
       
  7004 
       
  7005 EXPORT_C TInt CDRMHelper::DataTypesCount(
       
  7006     TInt& aCount)
       
  7007     {
       
  7008     return iDRMCommon->DataTypesCount( aCount );
       
  7009     }
       
  7010 
       
  7011 EXPORT_C TInt CDRMHelper::SupportedDataType(
       
  7012     const TInt aIndex, TDataType& aDataType)
       
  7013     {
       
  7014     return iDRMCommon->SupportedDataType( aIndex, aDataType );
       
  7015     }
       
  7016 
       
  7017 EXPORT_C TInt CDRMHelper::RegisterDataType(
       
  7018     const TDataType& aDataType)
       
  7019     {
       
  7020     return iDRMCommon->RegisterDataType( aDataType );
       
  7021     }
       
  7022 
       
  7023 EXPORT_C TInt CDRMHelper::UnRegisterDataType(
       
  7024     const TInt aIndex )
       
  7025     {
       
  7026     return iDRMCommon->UnRegisterDataType( aIndex );
       
  7027     }
       
  7028 
       
  7029 EXPORT_C TInt CDRMHelper::SupportedDRMMethods2(
       
  7030     TInt& aDRMMethod, TDRMHelperOMALevel& aOMALevel)
       
  7031     {
       
  7032 #ifndef __DRM_FULL
       
  7033     aDRMMethod = CDRMHelper::EForwardLock;
       
  7034 #else
       
  7035     aDRMMethod =
       
  7036         CDRMHelper::EForwardLock |
       
  7037         CDRMHelper::ECombinedDelivery |
       
  7038         CDRMHelper::ESeparateDelivery |
       
  7039         CDRMHelper::ESuperDistribution;
       
  7040 #ifdef __DRM_OMA2
       
  7041     aOMALevel = EOMA_2_0;
       
  7042 #else
       
  7043     aOmaLevel = EOMA_1_0;
       
  7044 #endif // __DRM_OMA2
       
  7045 
       
  7046 #endif // __DRM_FULL
       
  7047     return KErrNone;
       
  7048     }
       
  7049 
       
  7050 
       
  7051 // -----------------------------------------------------------------------------
       
  7052 // CDRMHelper::HandleServerAppExit
       
  7053 // -----------------------------------------------------------------------------
       
  7054 //
       
  7055 void CDRMHelper::HandleServerAppExit( TInt aReason )
       
  7056     {
       
  7057     if ( aReason == EAknCmdExit && !iSchemeHandler )
       
  7058         {
       
  7059         CAknEnv::RunAppShutter();
       
  7060         }
       
  7061 
       
  7062     if ( iSchemeHandler )
       
  7063         {
       
  7064         delete iSchemeHandler;
       
  7065         iSchemeHandler = NULL;
       
  7066         }
       
  7067 
       
  7068     if ( iWait.IsStarted() )
       
  7069         {
       
  7070         iWait.AsyncStop();
       
  7071         }
       
  7072     }
       
  7073 
       
  7074 // -----------------------------------------------------------------------------
       
  7075 // CDRMHelper::PrepareSecondaryDisplayL
       
  7076 // -----------------------------------------------------------------------------
       
  7077 //
       
  7078 void CDRMHelper::PrepareSecondaryDisplayL( CEikDialog& aDialog , TInt aResourceId,
       
  7079     const TDesC& aString, TInt aValue )
       
  7080     {
       
  7081 
       
  7082     // Check if we have cover display and shall we display something
       
  7083     if ( !FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) ||
       
  7084         !CDRMHelperInfoNoteWrapper::EvaluateCoverResourceId( aResourceId ) )
       
  7085         {
       
  7086         return;
       
  7087         }
       
  7088 
       
  7089     RProcess myProcess;
       
  7090     TUid myProcessUid( KNullUid );
       
  7091 
       
  7092     RThread().Process( myProcess );
       
  7093     myProcessUid = myProcess.Identity();
       
  7094 
       
  7095     aDialog.PublishDialogL( aResourceId, KUidCoverUiCategoryDRMHelper );
       
  7096 
       
  7097     // fetch akn utility for mediator support
       
  7098     CAknMediatorFacade* covercl = AknMediatorFacade( &aDialog );
       
  7099 
       
  7100     if ( covercl ) // returns null if cover display is not available
       
  7101         {
       
  7102         // Package dialog data <oem/SecondaryDisplay/DRMHelperSecondaryDisplay.h>
       
  7103         THelperSDData helperData;
       
  7104 
       
  7105         helperData.iHelperUid = KUidCoverUiCategoryDRMHelper;        // First field is DRMHelper's Uid
       
  7106         helperData.iHandlerProcessId = myProcessUid; // ProcessId which uses DRMHelper
       
  7107         helperData.iCreatorProcessId = User::CreatorSecureId();
       
  7108 
       
  7109         if ( aString.Compare( KNullDesC ) )
       
  7110             {
       
  7111             // If there is filename given, it's always in the PrimaryString
       
  7112             helperData.iStringParam.Append( aString );
       
  7113             }
       
  7114         if ( aValue >= 0 )
       
  7115             {
       
  7116             // If there is no other than numeric data, put it as NumericString
       
  7117             helperData.iNumParam.AppendNum( aValue );
       
  7118             }
       
  7119         THelperSDDataPckg pckg( helperData );
       
  7120 
       
  7121         covercl->BufStream() << pckg;   // Write the package data
       
  7122         covercl->BufStream().CommitL(); // no more data to send so commit buf
       
  7123         }
       
  7124     return;
       
  7125     }
       
  7126 
       
  7127 // -----------------------------------------------------------------------------
       
  7128 // CDRMHelper::CancelSecondaryDisplayL
       
  7129 // -----------------------------------------------------------------------------
       
  7130 //
       
  7131 void CDRMHelper::CancelSecondaryDisplayL( TInt aResourceId )
       
  7132     {
       
  7133 
       
  7134     // Check if we have cover display and shall we display something
       
  7135     if ( !FeatureManager::FeatureSupported( KFeatureIdCoverDisplay ) ||
       
  7136         !CDRMHelperInfoNoteWrapper::EvaluateCoverResourceId( aResourceId ) )
       
  7137         {
       
  7138         return;
       
  7139         }
       
  7140 
       
  7141     RProcess myProcess;
       
  7142     TUid myProcessUid( KNullUid );
       
  7143 
       
  7144     RThread().Process( myProcess );
       
  7145     myProcessUid = myProcess.Identity();
       
  7146 
       
  7147     THelperSDDataCancel cancelData;
       
  7148     cancelData.iHandlerProcessId = myProcessUid;
       
  7149     cancelData.iCreatorProcessId = User::CreatorSecureId();
       
  7150     cancelData.iNoteId = aResourceId;
       
  7151 
       
  7152     TPckgBuf<THelperSDDataCancel> cancel( cancelData );
       
  7153 
       
  7154     HBufC8* buf = HBufC8::NewLC(sizeof(THelperSDDataCancel) + sizeof(TInt));
       
  7155     TPtr8 ptr = buf->Des();
       
  7156 
       
  7157     RDesWriteStream stream(ptr);
       
  7158     stream << cancel;
       
  7159     stream.CommitL();
       
  7160 
       
  7161     iEventProvider->RaiseEvent( KMediatorSecondaryDisplayDomain,
       
  7162         KUidCoverUiCategoryDRMHelper,
       
  7163         ECover_dialog_cancel,
       
  7164         TVersion( 0, 0, 0 ),
       
  7165         *buf );
       
  7166 
       
  7167     stream.Close();
       
  7168     CleanupStack::PopAndDestroy( buf );
       
  7169     }
       
  7170 
       
  7171 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  7172 
       
  7173 //  End of File