contentmgmt/contentaccessfwfordrm/source/caf/content.cpp
changeset 15 da2ae96f639b
parent 8 35751d3474b7
child 45 030c4fbc13d7
--- a/contentmgmt/contentaccessfwfordrm/source/caf/content.cpp	Fri Oct 02 13:15:59 2009 +0300
+++ b/contentmgmt/contentaccessfwfordrm/source/caf/content.cpp	Mon Oct 12 10:17:04 2009 +0300
@@ -26,6 +26,7 @@
 #include <caf/agent.h>
 #include <caf/virtualpath.h>
 #include <caf/agentfactory.h>
+#include <caf/caferr.h>
 
 #ifndef REMOVE_CAF1
 #include <caf/attribute.h>
@@ -74,6 +75,25 @@
 	return self;
 	}
 
+#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+
+EXPORT_C CContent* CContent::NewLC(const TDesC8& aHeaderData) 
+	{
+	CContent* self = new(ELeave) CContent();
+	CleanupStack::PushL(self);
+	self->ConstructL(aHeaderData);
+	return self;
+	}
+
+EXPORT_C CContent* CContent::NewL(const TDesC8& aHeaderData) 
+	{
+	CContent* self=CContent::NewLC(aHeaderData);
+	CleanupStack::Pop(self);
+	return self;
+	}
+	
+#endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+
 CContent::CContent() : iDefaultVirtualPath(KNullDesC(), KDefaultContentObject())
 	{ 
 	}
@@ -81,15 +101,16 @@
 CContent::~CContent() 
 	{ 
 	delete iAgentContent;
-
+	iFile.Close();
+	
 	if(iVirtualPath)
 		{
 		delete iVirtualPath;
 		}
-	else
-		{
-		iFile.Close();	
-		}
+	
+#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+	delete iHeaderData;
+#endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
 	
 	// Finished with agent, this closes ECOM handle
 	delete iAgentFactory;
@@ -168,6 +189,36 @@
 	CleanupStack::PopAndDestroy(2, resolver); // actualUri
 	}
 
+#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+
+void CContent::ConstructL(const TDesC8& aHeaderData) 
+	{
+	if(aHeaderData.Length() <= 0)
+		{
+		User::Leave(KErrMissingWmdrmHeaderData);
+		}
+	
+	iHeaderData = aHeaderData.AllocL();
+	
+	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
+	
+	// Find the agent who handles the file
+	CAgentInfo& agentInfo = resolver->ResolveFileL(aHeaderData);
+
+	// copy the agent name and Uid
+	iAgent = agentInfo.Agent();
+
+	// Construct the agent factory (ECOM handle)
+	iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
+	// Construct the CAgentContent object
+	iAgentContent = iAgentFactory->CreateContentBrowserL(aHeaderData);
+
+	// Finished with resolver (and the agentInfo object it owns)
+	CleanupStack::PopAndDestroy(resolver); 
+	}
+
+#endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+
 EXPORT_C TInt CContent::OpenContainer(const TDesC &aUniqueId) 
 	{
 	return iAgentContent->OpenContainer(aUniqueId);
@@ -300,12 +351,26 @@
 
 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent)
 	{
+#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+	if(iHeaderData != NULL)
+		return OpenContentL(aIntent, *iHeaderData);
+    else
+		return OpenContentL(aIntent, iDefaultVirtualPath.UniqueId());
+#else
 	return OpenContentL(aIntent, iDefaultVirtualPath.UniqueId());
+#endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
 	}
 
 EXPORT_C CData* CContent::OpenContentLC(TIntent aIntent)
 	{
+#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+	if(iHeaderData != NULL)
+		return OpenContentLC(aIntent, *iHeaderData);
+	else
+		return OpenContentLC(aIntent, iDefaultVirtualPath.UniqueId());
+#else
 	return OpenContentLC(aIntent, iDefaultVirtualPath.UniqueId());
+#endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
 	}
 
 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent, const TDesC &aUniqueId)
@@ -329,6 +394,22 @@
 		return CData::NewLC(iAgent.ImplementationUid(), iFile, aUniqueId, aIntent);
 		}
 	}
+	
+#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+
+CData* CContent::OpenContentL(TIntent aIntent, const TDesC8& aHeaderData)
+	{
+	CData* data = OpenContentLC(aIntent, aHeaderData);
+	CleanupStack::Pop(data);
+	return data;
+	}
+
+CData* CContent::OpenContentLC(TIntent aIntent, const TDesC8& aHeaderData)
+	{
+	return CData::NewLC(iAgent.ImplementationUid(), aHeaderData, aIntent);
+	}
+	
+#endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
 
 EXPORT_C const TAgent& CContent::Agent() const
 	{
@@ -362,6 +443,39 @@
 	return NewAttributeL(aPreloaded, EContentShareReadOnly);
 	}
 
+#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded, TContentShareMode aShareMode)
+	{
+	CAttribute* attr = NULL;
+	
+	if(iVirtualPath)
+		{
+		// if we were opened with a file name
+		attr = CAttribute::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath.URI(), aShareMode);
+		}
+	else if(iHeaderData)
+		{
+		attr = CAttribute::NewLC(iAgent.ImplementationUid(), *iHeaderData);
+		}
+	else
+		{
+		// if we were opened with a file handle 
+		attr = CAttribute::NewLC(iAgent.ImplementationUid(), iFile);
+		}
+
+	// If aPreloaded is set, query the agent immediately for all the attributes
+	if (aPreloaded)
+		{
+		attr->QuerySet().SetAll();
+		attr->GetL();
+		}
+
+	CleanupStack::Pop(attr);
+	return attr;
+	}
+
+#else
+
 EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded, TContentShareMode aShareMode)
 	{
 	CAttribute* attr = NULL;
@@ -388,9 +502,10 @@
 	return attr;
 	}
 
+#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
+
 #endif // REMOVE_CAF1
 
-
 // DLL entry point - only for EKA1