omadrm/drmengine/agentv2/src/Oma2AgentContent.cpp
changeset 0 95b198f216e5
child 18 8a03a285ab14
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: OMA DRM ContentAccess::CContent implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <caf/caf.h>
       
    22 #include <caf/bitset.h>
       
    23 #include <caf/attribute.h>
       
    24 #include <e32test.h>
       
    25 #include <utf.h>
       
    26 
       
    27 
       
    28 #include <schemehandler.h>
       
    29 
       
    30 
       
    31 #include "oma2agentcontent.h"
       
    32 #include "oma2agentattributes.h"
       
    33 #include "oma1dcf.h"
       
    34 #include "oma2dcf.h"
       
    35 #include "symmetric.h"
       
    36 #include "DrmRights.h"
       
    37 #include "Oma2DcfPartInfo.h"
       
    38 #include "DrmProtectedRoParser.h"
       
    39 
       
    40 using namespace ContentAccess;
       
    41 
       
    42 // LOCAL FUNCTION PROTOTYPES
       
    43 LOCAL_C TInt MapContentShareMode(TContentShareMode aMode);
       
    44 template<class S>
       
    45 LOCAL_C void PointerArrayResetDestroyAndClose(TAny* aPtr);
       
    46 
       
    47 // ============================= LOCAL FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // MapContentShareMode
       
    51 // Maps the CAF specific file share mode to the RFs/RFile sharing mode
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 TInt MapContentShareMode(TContentShareMode aMode)
       
    55     {
       
    56     TInt r = EFileRead | EFileShareAny;
       
    57 
       
    58     switch (aMode)
       
    59         {
       
    60         case EContentShareReadOnly:
       
    61             r = EFileRead | EFileShareReadersOnly;
       
    62             break;
       
    63         case EContentShareReadWrite:
       
    64             r = EFileRead | EFileShareReadersOrWriters;
       
    65             break;
       
    66         case EContentShareExclusive:
       
    67             r = EFileRead | EFileShareExclusive;
       
    68             break;
       
    69         }
       
    70     return r;
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // PointerArrayResetDestroyAndClose
       
    75 // Template method used to push RPointerArrays to the cleanup stack. Takes
       
    76 // care of deleting all pointers in the array.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 template<class S>
       
    80 void PointerArrayResetDestroyAndClose(TAny* aPtr)
       
    81     {
       
    82     (reinterpret_cast<RPointerArray<S>*>(aPtr))->ResetAndDestroy();
       
    83     (reinterpret_cast<RPointerArray<S>*>(aPtr))->Close();
       
    84     }
       
    85 
       
    86 // ============================ MEMBER FUNCTIONS ===============================
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // COma2AgentContent::COma2AgentContent
       
    90 // Reset all member variables
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 COma2AgentContent::COma2AgentContent(void):
       
    94     iDcf(NULL),
       
    95     iFilePosition(0),
       
    96     iDataPosition(0),
       
    97     iUri(NULL),
       
    98     iCurrentContainer(NULL),
       
    99     iNotifier(NULL),
       
   100     iWatchedId(NULL)
       
   101     {
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // COma2AgentContent::ConstructL
       
   106 // Initialize the agent from a URI (file name) and file mode, opens the
       
   107 // the file and takes membership of the handle
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void COma2AgentContent::ConstructL(
       
   111     const TDesC& aUri,
       
   112     TContentShareMode aShareMode)
       
   113     {
       
   114     iUri = aUri.AllocL();
       
   115     User::LeaveIfError(iRdb.Connect());
       
   116     User::LeaveIfError(iFs.Connect());
       
   117     User::LeaveIfError(iFs.ShareAuto());
       
   118     User::LeaveIfError(iFile.Open(iFs, aUri, MapContentShareMode(aShareMode)));
       
   119     iDcf = CDcfCommon::NewL(iFile);
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // COma2AgentContent::ConstructL
       
   124 // Initialize the agent from a file handle, duplicates the handle
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void COma2AgentContent::ConstructL(RFile& aFile)
       
   128     {
       
   129     TFileName name;
       
   130     User::LeaveIfError(iRdb.Connect());
       
   131     User::LeaveIfError(iFile.Duplicate(aFile));
       
   132     User::LeaveIfError(iFs.Connect());
       
   133     User::LeaveIfError(iFs.ShareAuto());
       
   134     iFile.Name(name);
       
   135     iUri = name.AllocL();
       
   136     iDcf = CDcfCommon::NewL(iFile);
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // COma2AgentContent::NewL
       
   141 // Two-phased constructors
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 COma2AgentContent* COma2AgentContent::NewL(
       
   145     const TDesC& aUri,
       
   146     TContentShareMode aShareMode)
       
   147     {
       
   148     COma2AgentContent* self = NewLC(aUri, aShareMode);
       
   149     CleanupStack::Pop(self);
       
   150     return self;
       
   151     }
       
   152 
       
   153 COma2AgentContent* COma2AgentContent::NewLC(
       
   154     const TDesC& aUri,
       
   155     TContentShareMode aShareMode)
       
   156     {
       
   157     COma2AgentContent* self=new(ELeave) COma2AgentContent();
       
   158     CleanupStack::PushL(self);
       
   159     self->ConstructL(aUri, aShareMode);
       
   160     return self;
       
   161     }
       
   162 
       
   163 COma2AgentContent* COma2AgentContent::NewL(RFile& aFile)
       
   164     {
       
   165     COma2AgentContent* self = NewLC(aFile);
       
   166     CleanupStack::Pop(self);
       
   167     return self;
       
   168     }
       
   169 
       
   170 COma2AgentContent* COma2AgentContent::NewLC(RFile& aFile)
       
   171     {
       
   172     COma2AgentContent* self=new(ELeave) COma2AgentContent();
       
   173     CleanupStack::PushL(self);
       
   174     self->ConstructL(aFile);
       
   175     return self;
       
   176     }
       
   177 
       
   178 
       
   179 // Destructor
       
   180 COma2AgentContent::~COma2AgentContent()
       
   181     {
       
   182     iRdb.Close();
       
   183     iFile.Close();
       
   184     iFs.Close();
       
   185     delete iDcf;
       
   186     delete iUri;
       
   187     delete iCurrentContainer;
       
   188     if (iNotifier != NULL)
       
   189         {
       
   190         if( iWatchedId )
       
   191             {
       
   192 
       
   193             TRAP_IGNORE( iNotifier->UnRegisterEventObserverL(*this, KEventAddRemove, *iWatchedId) );
       
   194             TRAP_IGNORE( iNotifier->UnRegisterEventObserverL(*this, KEventModify, *iWatchedId) );
       
   195 
       
   196             }
       
   197 
       
   198         delete iNotifier;
       
   199         }
       
   200     delete iWatchedId;
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // COma2AgentContent::OpenContainer
       
   205 // Checks if the part ID is valid and sets the current ID to the part ID
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 TInt COma2AgentContent::OpenContainer(
       
   209     const TDesC& aUniqueId)
       
   210     {
       
   211     TInt r = KErrNotFound;
       
   212     TInt err = KErrNone;
       
   213 
       
   214     // Only the outermost file can be opened, parts within the file don't have
       
   215     // subparts, only attributes.
       
   216     if (iCurrentContainer == NULL)
       
   217         {
       
   218         r = iDcf->CheckUniqueId(aUniqueId);
       
   219         if (r == KErrNone)
       
   220             {
       
   221 
       
   222             TRAP(err, iCurrentContainer = aUniqueId.AllocL() );
       
   223             if(err)
       
   224                 {
       
   225                 return err;
       
   226                 }
       
   227             }
       
   228         }
       
   229     return r;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // COma2AgentContent::CloseContainer
       
   234 // Resets the current part ID
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 TInt COma2AgentContent::CloseContainer()
       
   238     {
       
   239     TInt r = KErrNone;
       
   240 
       
   241     if (iCurrentContainer != NULL)
       
   242         {
       
   243         delete iCurrentContainer;
       
   244         iCurrentContainer = NULL;
       
   245         }
       
   246     else
       
   247         {
       
   248         r = KErrNotFound;
       
   249         }
       
   250     return r;
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // COma2AgentContent::GetEmbeddedObjectsL
       
   255 // Returns all parts embedded in the current part
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void COma2AgentContent::GetEmbeddedObjectsL(
       
   259     RStreamablePtrArray<CEmbeddedObject>& aArray)
       
   260     {
       
   261     TInt i;
       
   262     CEmbeddedObject* part = NULL;
       
   263     HBufC* id = NULL;
       
   264     COma2Dcf* dcf2 = NULL;
       
   265 
       
   266     aArray.ResetAndDestroy();
       
   267     if (iCurrentContainer == NULL)
       
   268         {
       
   269         if (iDcf->iVersion == EOma2Dcf)
       
   270             {
       
   271             dcf2 = static_cast<COma2Dcf*>(iDcf);
       
   272             for (i = 0; i < dcf2->iParts.Count(); i++)
       
   273                 {
       
   274                 id = CnvUtfConverter::ConvertToUnicodeFromUtf8L(
       
   275                     *dcf2->iParts[i]->iContentId);
       
   276                 CleanupStack::PushL(id);
       
   277                 part = CEmbeddedObject::NewL(*id, *dcf2->iParts[i]->iMimeType,
       
   278                     EContentObject);
       
   279                 CleanupStack::PopAndDestroy(id);
       
   280                 aArray.AppendL(part);
       
   281                 }
       
   282             }
       
   283         else
       
   284             {
       
   285             id = CnvUtfConverter::ConvertToUnicodeFromUtf8L(
       
   286                 *iDcf->iContentID);
       
   287             CleanupStack::PushL(id);
       
   288             part = CEmbeddedObject::NewL(*id, *iDcf->iMimeType,
       
   289                 EContentObject);
       
   290             CleanupStack::PopAndDestroy(id);
       
   291             aArray.AppendL(part);
       
   292             }
       
   293         }
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // COma2AgentContent::GetEmbeddedObjectsL
       
   298 // Returns all parts embedded in the current part, filtered by type
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 void COma2AgentContent::GetEmbeddedObjectsL(
       
   302     RStreamablePtrArray<CEmbeddedObject>& aArray,
       
   303     TEmbeddedType aType)
       
   304     {
       
   305     if (aType == EContentObject)
       
   306         {
       
   307         GetEmbeddedObjectsL(aArray);
       
   308         }
       
   309     }
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // COma2AgentContent::Search
       
   313 //
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 TInt COma2AgentContent::Search(
       
   317     RStreamablePtrArray<CEmbeddedObject>& aArray,
       
   318     const TDesC8& aMimeType,
       
   319     TBool /*aRecursive*/)
       
   320     {
       
   321     TInt i;
       
   322     TInt r = KErrNone;
       
   323     RStreamablePtrArray<CEmbeddedObject> parts;
       
   324     CEmbeddedObject* item = NULL;
       
   325 
       
   326     TRAP(r, GetEmbeddedObjectsL(parts));
       
   327     for (i = 0; r == KErrNone && i < parts.Count(); i++)
       
   328         {
       
   329         if (parts[i]->MimeType().CompareF(aMimeType) == 0)
       
   330             {
       
   331 
       
   332             TRAP_IGNORE( item = CEmbeddedObject::NewL(
       
   333                 parts[i]->UniqueId(), parts[i]->Name(),
       
   334                 parts[i]->MimeType(), parts[i]->Type()) );
       
   335 
       
   336             TRAP(r, aArray.AppendL(item));
       
   337             }
       
   338         }
       
   339     parts.ResetAndDestroy();
       
   340     parts.Close();
       
   341     return r;
       
   342     }
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 // COma2AgentContent::GetAttribute
       
   346 //
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 TInt COma2AgentContent::GetAttribute(
       
   350     TInt aAttribute,
       
   351     TInt& aValue,
       
   352     const TDesC& aUniqueId)
       
   353     {
       
   354     TInt r;
       
   355 
       
   356     r = iDcf->OpenPart(aUniqueId);
       
   357     if (r == KErrNone)
       
   358         {
       
   359         TRAP(r,aValue = TOma2AgentAttributes::GetAttribute(*iDcf, aAttribute,
       
   360             TVirtualPathPtr(*iUri, aUniqueId), &iRdb));
       
   361         }
       
   362     return r;
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // COma2AgentContent::GetAttributeSet
       
   367 //
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 TInt COma2AgentContent::GetAttributeSet(
       
   371     RAttributeSet& aAttributeSet,
       
   372     const TDesC& aUniqueId)
       
   373     {
       
   374     TInt r;
       
   375     TInt err = KErrNone;
       
   376 
       
   377     r = iDcf->OpenPart(aUniqueId);
       
   378     if (r == KErrNone)
       
   379         {
       
   380         TRAP(err,r = TOma2AgentAttributes::GetAttributeSet(*iDcf, aAttributeSet,
       
   381             TVirtualPathPtr(*iUri, aUniqueId), &iRdb));
       
   382         if (err != KErrNone)
       
   383             {
       
   384             return err;
       
   385             }
       
   386         }
       
   387     return r;
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // COma2AgentContent::GetStringAttribute
       
   392 //
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 TInt COma2AgentContent::GetStringAttribute(
       
   396     TInt aAttribute,
       
   397     TDes& aValue,
       
   398     const TDesC& aUniqueId)
       
   399     {
       
   400     TInt r = KErrNone;
       
   401     TInt err = KErrNone;
       
   402 
       
   403     r = iDcf->OpenPart(aUniqueId);
       
   404     if (r == KErrNone)
       
   405         {
       
   406         TRAP(err, r = TOma2AgentAttributes::GetStringAttribute(*iDcf, aAttribute,
       
   407             aValue, TVirtualPathPtr(*iUri, aUniqueId), &iRdb));
       
   408         if(err != KErrNone)
       
   409             {
       
   410             return err;
       
   411             }
       
   412         }
       
   413     return r;
       
   414     }
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // COma2AgentContent::GetStringAttributeSet
       
   418 //
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 TInt COma2AgentContent::GetStringAttributeSet(
       
   422     RStringAttributeSet& aStringAttributeSet,
       
   423     const TDesC& aUniqueId)
       
   424     {
       
   425     TInt r;
       
   426     TInt err = KErrNone;
       
   427 
       
   428     r = iDcf->OpenPart(aUniqueId);
       
   429     if (r == KErrNone)
       
   430         {
       
   431         TRAP(err, r = TOma2AgentAttributes::GetStringAttributeSet(*iDcf,
       
   432             aStringAttributeSet, TVirtualPathPtr(*iUri, aUniqueId), &iRdb));
       
   433         if(err != KErrNone)
       
   434             {
       
   435             return err;
       
   436             }
       
   437         }
       
   438     return r;
       
   439     }
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // COma2AgentContent::AgentSpecificCommand
       
   443 //
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 TInt COma2AgentContent::AgentSpecificCommand(
       
   447     TInt aCommand,
       
   448     const TDesC8& /*aInputBuffer*/,
       
   449     TDes8& /*aOutputBuffer*/)
       
   450     {
       
   451     TInt r = KErrCANotSupported;
       
   452 
       
   453     if (aCommand == EEmbedDomainRo)
       
   454         {
       
   455         TRAP(r, EmbedDomainRoL());
       
   456         }
       
   457     return r;
       
   458     }
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // COma2AgentContent::AgentSpecificCommand
       
   462 //
       
   463 // -----------------------------------------------------------------------------
       
   464 //
       
   465 void COma2AgentContent::AgentSpecificCommand(
       
   466     TInt aCommand,
       
   467     const TDesC8& aInputBuffer,
       
   468     TDes8& aOutputBuffer,
       
   469     TRequestStatus& aStatus)
       
   470     {
       
   471     TRequestStatus *ptr = &aStatus;
       
   472     User::RequestComplete(ptr, AgentSpecificCommand(aCommand, aInputBuffer,
       
   473         aOutputBuffer));
       
   474     }
       
   475 
       
   476 // -----------------------------------------------------------------------------
       
   477 // COma2AgentContent::NotifyStatusChange
       
   478 //
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 void COma2AgentContent::NotifyStatusChangeL(
       
   482     TEventMask aEventMask,
       
   483     TRequestStatus& aStatus,
       
   484     const TDesC& aUniqueId)
       
   485     {
       
   486     TInt r = KErrNone;
       
   487     TInt i;
       
   488     TInt part = KErrNotFound;
       
   489     COma2Dcf* dcf2 = NULL;
       
   490     HBufC8* uniqueId = NULL;
       
   491 
       
   492     iStatus = &aStatus;
       
   493     iWatchedEvents = aEventMask;
       
   494     if (iWatchedId != NULL)
       
   495         {
       
   496         if( iNotifier )
       
   497             {
       
   498             iNotifier->UnRegisterEventObserverL(*this, KEventAddRemove, *iWatchedId);
       
   499             iNotifier->UnRegisterEventObserverL(*this, KEventModify, *iWatchedId);
       
   500             }
       
   501         delete iWatchedId;
       
   502         iWatchedId = NULL;
       
   503         }
       
   504     if (iDcf->iVersion == EOma1Dcf || aUniqueId.Compare(KDefaultContentObject) == 0)
       
   505         {
       
   506         iWatchedId = iDcf->iContentID->AllocL();
       
   507         }
       
   508     else
       
   509         {
       
   510         dcf2 = static_cast<COma2Dcf*>(iDcf);
       
   511         uniqueId = CnvUtfConverter::ConvertFromUnicodeToUtf8L(aUniqueId);
       
   512         CleanupStack::PushL(uniqueId);
       
   513         for (i = 0; part == KErrNotFound && i < dcf2->iParts.Count(); i++)
       
   514             {
       
   515             if (dcf2->iParts[i]->iContentId->CompareF(*uniqueId) == 0)
       
   516                 {
       
   517                 iWatchedId = dcf2->iParts[i]->iContentId->AllocL();
       
   518                 }
       
   519             }
       
   520         CleanupStack::PopAndDestroy();
       
   521         }
       
   522     if (iWatchedId != NULL)
       
   523         {
       
   524         if (iNotifier == NULL)
       
   525             {
       
   526             iNotifier = CDRMNotifier::NewL();
       
   527             }
       
   528         if (iNotifier != NULL)
       
   529             {
       
   530             iNotifier->RegisterEventObserverL(*this, KEventAddRemove, *iWatchedId);
       
   531             iNotifier->RegisterEventObserverL(*this, KEventModify, *iWatchedId);
       
   532             *iStatus = KRequestPending;
       
   533             }
       
   534         else
       
   535             {
       
   536             User::Leave(r);
       
   537             }
       
   538         }
       
   539     else
       
   540         {
       
   541         User::Leave(KErrNotFound);
       
   542         }
       
   543     }
       
   544 
       
   545 // -----------------------------------------------------------------------------
       
   546 // COma2AgentContent::NotifyStatusChange
       
   547 //
       
   548 // -----------------------------------------------------------------------------
       
   549 // 
       
   550 void COma2AgentContent::NotifyStatusChange(
       
   551     TEventMask aEventMask,
       
   552     TRequestStatus& aStatus,
       
   553     const TDesC& aUniqueId)
       
   554     {
       
   555     TInt err = KErrNone;
       
   556     TRequestStatus *status = 0;
       
   557     TRAP(err, NotifyStatusChangeL(  aEventMask,
       
   558                                     aStatus,
       
   559                                     aUniqueId ));
       
   560     if(err)
       
   561         {
       
   562         status = &aStatus;
       
   563         User::RequestComplete(status, err);
       
   564         }
       
   565     }
       
   566 
       
   567 // -----------------------------------------------------------------------------
       
   568 // COma2AgentContent::CancelNotifyStatusChange
       
   569 //
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 TInt COma2AgentContent::CancelNotifyStatusChange(
       
   573     TRequestStatus& aStatus,
       
   574     const TDesC& /*aUniqueId*/)
       
   575     {
       
   576     iStatus = &aStatus;
       
   577     if(iNotifier == NULL)
       
   578          {
       
   579          User::RequestComplete(iStatus, KErrNotFound);
       
   580          return KErrNotFound;
       
   581          }
       
   582 
       
   583     TRAP_IGNORE( iNotifier->UnRegisterEventObserverL(*this, KEventAddRemove, *iWatchedId) );
       
   584     TRAP_IGNORE( iNotifier->UnRegisterEventObserverL(*this, KEventModify, *iWatchedId) );
       
   585 
       
   586     if (iWatchedId != NULL)
       
   587         {
       
   588         delete iWatchedId;
       
   589         iWatchedId = NULL;
       
   590         }
       
   591     User::RequestComplete(iStatus, KErrCancel);
       
   592     return KErrNone;
       
   593     }
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // COma2AgentContent::RequestRights
       
   597 // Opens the browser with the rights issuer URL
       
   598 // -----------------------------------------------------------------------------
       
   599 //
       
   600 
       
   601 void COma2AgentContent::RequestRights(
       
   602     TRequestStatus& aStatus,
       
   603     const TDesC& aUniqueId)
       
   604     {
       
   605     TRequestStatus *ptr = &aStatus;
       
   606     TInt r;
       
   607     HBufC* b = NULL;
       
   608     CSchemeHandler* handler = NULL;
       
   609 
       
   610     r = iDcf->OpenPart(aUniqueId);
       
   611     if (r == KErrNone && iDcf->iRightsIssuerURL != NULL)
       
   612         {
       
   613         TRAP(r, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(
       
   614             *iDcf->iRightsIssuerURL));
       
   615         if (b != NULL)
       
   616             {
       
   617             TRAP(r, handler = CSchemeHandler::NewL(*b));
       
   618             if (handler != NULL)
       
   619                 {
       
   620                 TRAP(r, handler->HandleUrlStandaloneL());
       
   621                 delete handler;
       
   622                 }
       
   623             delete b;
       
   624             }
       
   625         }
       
   626     User::RequestComplete(ptr, r);
       
   627     }
       
   628 
       
   629 // -----------------------------------------------------------------------------
       
   630 // COma2AgentContent::CancelRequestRights
       
   631 // Not supported, getting rights is handled outside the scope of the agent and
       
   632 // cannot be cancelled
       
   633 // -----------------------------------------------------------------------------
       
   634 //
       
   635 
       
   636 TInt COma2AgentContent::CancelRequestRights(
       
   637     TRequestStatus& aStatus,
       
   638     const TDesC& /*aUniqueId*/)
       
   639     {
       
   640     TRequestStatus *ptr = &aStatus;
       
   641     User::RequestComplete(ptr, KErrNone);
       
   642     return KErrNone;
       
   643     }
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // COma2AgentContent::DisplayInfoL
       
   647 //
       
   648 // -----------------------------------------------------------------------------
       
   649 //
       
   650 void COma2AgentContent::DisplayInfoL(
       
   651     TDisplayInfo /*aDisplayInfo*/,
       
   652     const TDesC& /*aUniqueId*/)
       
   653     {
       
   654     User::Leave(KErrCANotSupported);
       
   655     }
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 // COma2AgentContent::SetProperty
       
   659 //
       
   660 // -----------------------------------------------------------------------------
       
   661 //
       
   662 TInt COma2AgentContent::SetProperty(
       
   663     TAgentProperty /*aProperty*/,
       
   664     TInt /*aValue*/)
       
   665     {
       
   666     return KErrCANotSupported;
       
   667     }
       
   668 
       
   669 // -----------------------------------------------------------------------------
       
   670 // COma2AgentContent::EmbedDomainRoL
       
   671 //
       
   672 // -----------------------------------------------------------------------------
       
   673 //
       
   674 void COma2AgentContent::EmbedDomainRoL()
       
   675     {
       
   676     RPointerArray<HBufC8> roList;
       
   677     TCleanupItem listCleanup(PointerArrayResetDestroyAndClose<HBufC8>,
       
   678         &roList);
       
   679     COma2Dcf* dcf;
       
   680     CDrmProtectedRoParser* parser = NULL;
       
   681     RPointerArray<CDRMRights> rights;
       
   682 
       
   683     if (iDcf->iVersion == EOma2Dcf)
       
   684         {
       
   685         dcf = static_cast<COma2Dcf*>(iDcf);
       
   686 
       
   687         __UHEAP_MARK;
       
   688         for (TInt i = 0; i < dcf->iRightsObjects.Count(); i++)
       
   689             {
       
   690             parser = CDrmProtectedRoParser::NewL();
       
   691             CleanupStack::PushL(parser);
       
   692             TRAP_IGNORE( parser->ParseAndStoreL(*dcf->iRightsObjects[i],
       
   693                     rights));
       
   694             CleanupStack::PopAndDestroy(); // parser
       
   695             rights.ResetAndDestroy();
       
   696             rights.Close();
       
   697             }
       
   698         __UHEAP_MARKEND;
       
   699 
       
   700         iRdb.GetDomainRosForCidL(*dcf->iContentID, roList);
       
   701         CleanupStack::PushL(listCleanup);
       
   702         if(roList.Count())
       
   703             {
       
   704             // this is not replaceable in UHEAP_MARK delimiters
       
   705             dcf->SetRightsObjectsL(roList);
       
   706             }
       
   707         CleanupStack::PopAndDestroy(); // listCleanup
       
   708         }
       
   709     else
       
   710         {
       
   711         User::Leave(KErrArgument);
       
   712         }
       
   713     }
       
   714 
       
   715 // -----------------------------------------------------------------------------
       
   716 // COma2AgentContent::HandleEventL
       
   717 // Handle notifier events here. Not much logic, consider all events as rights
       
   718 // changes.
       
   719 // -----------------------------------------------------------------------------
       
   720 //
       
   721 void COma2AgentContent::HandleEventL(
       
   722     MDRMEvent* /*aEvent*/)
       
   723     {
       
   724     TInt r;
       
   725     TUint32 reason = 0;
       
   726 
       
   727     if ( iWatchedId != NULL)
       
   728         {
       
   729         r = iRdb.CheckRights(EUnknown, *iWatchedId, reason);
       
   730         if (r == KErrNone && (iWatchedEvents & ERightsAvailable) ||
       
   731             r != KErrNone && (iWatchedEvents & ERightsExpired))
       
   732             {
       
   733             iNotifier->UnRegisterEventObserverL(*this, KEventAddRemove, *iWatchedId);
       
   734             iNotifier->UnRegisterEventObserverL(*this, KEventModify, *iWatchedId);
       
   735             delete iWatchedId;
       
   736             iWatchedId = NULL;
       
   737             User::RequestComplete(iStatus, KErrNone);
       
   738             }
       
   739         }
       
   740     }
       
   741 
       
   742 //  End of File