sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include "resolver.h" sl@0: #include sl@0: #include sl@0: #include "agentinfo.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifndef REMOVE_CAF1 sl@0: #include sl@0: #include sl@0: #endif sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: EXPORT_C CContent* CContent::NewLC(const TDesC& aURI) sl@0: { sl@0: return CContent::NewLC(aURI, EContentShareReadOnly); sl@0: } sl@0: sl@0: EXPORT_C CContent* CContent::NewL(const TDesC& aURI) sl@0: { sl@0: return CContent::NewL(aURI, EContentShareReadOnly); sl@0: } sl@0: sl@0: EXPORT_C CContent* CContent::NewLC(const TDesC& aURI, TContentShareMode aShareMode) sl@0: { sl@0: CContent* self = new(ELeave) CContent(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aURI, aShareMode); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CContent* CContent::NewL(const TDesC& aURI, TContentShareMode aShareMode) sl@0: { sl@0: CContent* self=CContent::NewLC(aURI, aShareMode); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CContent* CContent::NewLC(RFile& aFile) sl@0: { sl@0: CContent* self = new(ELeave) CContent(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aFile); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CContent* CContent::NewL(RFile& aFile) sl@0: { sl@0: CContent* self=CContent::NewLC(aFile); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: EXPORT_C CContent* CContent::NewLC(const TDesC8& aHeaderData) sl@0: { sl@0: CContent* self = new(ELeave) CContent(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aHeaderData); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CContent* CContent::NewL(const TDesC8& aHeaderData) sl@0: { sl@0: CContent* self=CContent::NewLC(aHeaderData); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: CContent::CContent() : iDefaultVirtualPath(KNullDesC(), KDefaultContentObject()) sl@0: { sl@0: } sl@0: sl@0: CContent::~CContent() sl@0: { sl@0: delete iAgentContent; sl@0: iFile.Close(); sl@0: sl@0: if(iVirtualPath) sl@0: { sl@0: delete iVirtualPath; sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: delete iHeaderData; sl@0: #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: // Finished with agent, this closes ECOM handle sl@0: delete iAgentFactory; sl@0: REComSession::FinalClose(); sl@0: } sl@0: sl@0: sl@0: void CContent::ConstructL(RFile &aFile) sl@0: { sl@0: // Make our own copy of the file handle sl@0: User::LeaveIfError(iFile.Duplicate(aFile)); sl@0: sl@0: // Rewind the file pointer sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: TInt64 pos = 0; sl@0: #else sl@0: TInt pos = 0; sl@0: #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: iFile.Seek(ESeekStart, pos); sl@0: sl@0: // For case where CAF is built with an RFile sl@0: CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); sl@0: sl@0: // Find the agent who handles the file sl@0: CAgentInfo& agentInfo = resolver->ResolveFileL(iFile); sl@0: sl@0: // copy the agent name and Uid sl@0: iAgent = agentInfo.Agent(); sl@0: sl@0: // Construct the agent factory (ECOM handle) sl@0: iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid()); sl@0: sl@0: // Construct the CAgentContent object sl@0: iAgentContent = iAgentFactory->CreateContentBrowserL(iFile); sl@0: sl@0: // Finished with resolver (and the agentInfo object it owns) sl@0: CleanupStack::PopAndDestroy(resolver); sl@0: } sl@0: sl@0: void CContent::ConstructL(const TDesC& aURI, TContentShareMode aShareMode) sl@0: { sl@0: iShareMode = aShareMode; sl@0: sl@0: // Create the agent resolver which will contains a reference to sl@0: // the agent responsible for this piece of content sl@0: CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); sl@0: sl@0: // Create a temporary buffer used to store the translated version of the URI sl@0: HBufC* actualUri = HBufC::NewLC(aURI.Length() + KMaxSIDLength); sl@0: TPtr uri = actualUri->Des(); sl@0: sl@0: // Set the TVirtualPathPtr to point to the URI supplied, sl@0: // this will decode any combined URI into the actual URI and uniqueId sl@0: // for use in subsequent functions sl@0: TVirtualPathPtr contentVirtualPath = aURI; sl@0: sl@0: // Find the agent who handles the file and translate the URI if it is pointing to a private directory sl@0: CAgentInfo& agentInfo = resolver->ResolveFileL(contentVirtualPath.URI(), uri, iShareMode); sl@0: sl@0: // Set the iVirtualPath to point to the translated URI and the uniqueId sl@0: iVirtualPath = CVirtualPath::NewL(*actualUri, contentVirtualPath.UniqueId()); sl@0: sl@0: iDefaultVirtualPath = *iVirtualPath; sl@0: sl@0: // Copy the agent name and Uid sl@0: iAgent = agentInfo.Agent(); sl@0: sl@0: // Construct the agent factory (ECOM handle) sl@0: iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid()); sl@0: sl@0: // Construct the agent content browser sl@0: iAgentContent = iAgentFactory->CreateContentBrowserL(uri, iShareMode); sl@0: sl@0: // Finished with resolver and the CAgentInfo object it owns sl@0: CleanupStack::PopAndDestroy(2, resolver); // actualUri sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: void CContent::ConstructL(const TDesC8& aHeaderData) sl@0: { sl@0: if(aHeaderData.Length() <= 0) sl@0: { sl@0: User::Leave(KErrMissingWmdrmHeaderData); sl@0: } sl@0: sl@0: iHeaderData = aHeaderData.AllocL(); sl@0: sl@0: CAgentResolver* resolver = CAgentResolver::NewLC(EFalse); sl@0: sl@0: // Find the agent who handles the file sl@0: CAgentInfo& agentInfo = resolver->ResolveFileL(aHeaderData); sl@0: sl@0: // copy the agent name and Uid sl@0: iAgent = agentInfo.Agent(); sl@0: sl@0: // Construct the agent factory (ECOM handle) sl@0: iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid()); sl@0: // Construct the CAgentContent object sl@0: iAgentContent = iAgentFactory->CreateContentBrowserL(aHeaderData); sl@0: sl@0: // Finished with resolver (and the agentInfo object it owns) sl@0: CleanupStack::PopAndDestroy(resolver); sl@0: } sl@0: sl@0: #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: EXPORT_C TInt CContent::OpenContainer(const TDesC &aUniqueId) sl@0: { sl@0: return iAgentContent->OpenContainer(aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::CloseContainer () sl@0: { sl@0: return iAgentContent->CloseContainer(); sl@0: } sl@0: sl@0: EXPORT_C void CContent::GetEmbeddedObjectsL (RStreamablePtrArray& aArray) const sl@0: { sl@0: iAgentContent->GetEmbeddedObjectsL(aArray); sl@0: } sl@0: sl@0: EXPORT_C void CContent::GetEmbeddedObjectsL (RStreamablePtrArray& aArray, TEmbeddedType aType) const sl@0: { sl@0: iAgentContent->GetEmbeddedObjectsL(aArray, aType); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::Search (RStreamablePtrArray& aArray, const TDesC8 &aMimeType, TBool aRecursive) sl@0: { sl@0: return iAgentContent->Search(aArray, aMimeType, aRecursive); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::GetAttribute (TInt aAttribute, TInt &aValue) const sl@0: { sl@0: return GetAttribute(aAttribute, aValue, iDefaultVirtualPath.UniqueId()); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::GetAttribute (TInt aAttribute, TInt& aValue, const TDesC &aUniqueId) const sl@0: { sl@0: return iAgentContent->GetAttribute(aAttribute, aValue, aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::GetAttributeSet(RAttributeSet& aAttributeSet) const sl@0: { sl@0: return GetAttributeSet(aAttributeSet, iDefaultVirtualPath.UniqueId()); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId) const sl@0: { sl@0: return iAgentContent->GetAttributeSet(aAttributeSet, aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::GetStringAttribute (TInt aAttribute, TDes &aValue) const sl@0: { sl@0: return GetStringAttribute(aAttribute, aValue, iDefaultVirtualPath.UniqueId()); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::GetStringAttribute (TInt aAttribute, TDes &aValue, const TDesC &aUniqueId) const sl@0: { sl@0: return iAgentContent->GetStringAttribute(aAttribute, aValue, aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet) const sl@0: { sl@0: return GetStringAttributeSet(aStringAttributeSet, iDefaultVirtualPath.UniqueId()); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId) const sl@0: { sl@0: return iAgentContent->GetStringAttributeSet(aStringAttributeSet, aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::AgentSpecificCommand (TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer) sl@0: { sl@0: return iAgentContent->AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer); sl@0: } sl@0: sl@0: EXPORT_C void CContent::AgentSpecificCommand (TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer, TRequestStatus &aStatus) sl@0: { sl@0: iAgentContent->AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer, aStatus); sl@0: } sl@0: sl@0: EXPORT_C void CContent::NotifyStatusChange(TEventMask aMask, TRequestStatus &aStatus) sl@0: { sl@0: NotifyStatusChange(aMask, aStatus, iDefaultVirtualPath.UniqueId()); sl@0: } sl@0: sl@0: EXPORT_C void CContent::NotifyStatusChange(TEventMask aMask, TRequestStatus &aStatus, const TDesC &aUniqueId) sl@0: { sl@0: iAgentContent->NotifyStatusChange(aMask, aStatus, aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::CancelNotifyStatusChange(TRequestStatus &aStatus) sl@0: { sl@0: return CancelNotifyStatusChange(aStatus, iDefaultVirtualPath.UniqueId()); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::CancelNotifyStatusChange(TRequestStatus &aStatus, const TDesC &aUniqueId) sl@0: { sl@0: return iAgentContent->CancelNotifyStatusChange(aStatus, aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C void CContent::RequestRights(TRequestStatus &aStatus) sl@0: { sl@0: RequestRights(aStatus, iDefaultVirtualPath.UniqueId()); sl@0: } sl@0: sl@0: EXPORT_C void CContent::RequestRights(TRequestStatus &aStatus, const TDesC &aUniqueId) sl@0: { sl@0: iAgentContent->RequestRights(aStatus, aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::CancelRequestRights(TRequestStatus &aStatus) sl@0: { sl@0: return CancelRequestRights(aStatus, iDefaultVirtualPath.UniqueId()); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::CancelRequestRights(TRequestStatus &aStatus, const TDesC& aUniqueId) sl@0: { sl@0: return iAgentContent->CancelRequestRights(aStatus, aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C void CContent::DisplayInfoL(TDisplayInfo aInfo) const sl@0: { sl@0: DisplayInfoL(aInfo, iDefaultVirtualPath.UniqueId()); sl@0: } sl@0: sl@0: EXPORT_C void CContent::DisplayInfoL(TDisplayInfo aInfo, const TDesC& aUniqueId) const sl@0: { sl@0: iAgentContent->DisplayInfoL(aInfo, aUniqueId); sl@0: } sl@0: sl@0: EXPORT_C TInt CContent::SetProperty(TAgentProperty aProperty, TInt aValue) sl@0: { sl@0: return iAgentContent->SetProperty(aProperty, aValue); sl@0: } sl@0: sl@0: EXPORT_C CData* CContent::OpenContentL(TIntent aIntent) sl@0: { sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: if(iHeaderData != NULL) sl@0: return OpenContentL(aIntent, *iHeaderData); sl@0: else sl@0: return OpenContentL(aIntent, iDefaultVirtualPath.UniqueId()); sl@0: #else sl@0: return OpenContentL(aIntent, iDefaultVirtualPath.UniqueId()); sl@0: #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: } sl@0: sl@0: EXPORT_C CData* CContent::OpenContentLC(TIntent aIntent) sl@0: { sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: if(iHeaderData != NULL) sl@0: return OpenContentLC(aIntent, *iHeaderData); sl@0: else sl@0: return OpenContentLC(aIntent, iDefaultVirtualPath.UniqueId()); sl@0: #else sl@0: return OpenContentLC(aIntent, iDefaultVirtualPath.UniqueId()); sl@0: #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: } sl@0: sl@0: EXPORT_C CData* CContent::OpenContentL(TIntent aIntent, const TDesC &aUniqueId) sl@0: { sl@0: CData* data = OpenContentLC(aIntent, aUniqueId); sl@0: CleanupStack::Pop(data); sl@0: return data; sl@0: } sl@0: sl@0: EXPORT_C CData* CContent::OpenContentLC(TIntent aIntent, const TDesC &aUniqueId) sl@0: { sl@0: // Open the content object specified by the Unique Id sl@0: if(iVirtualPath) sl@0: { sl@0: // create a CData based upon the URI supplied when this CContent was created sl@0: return CData::NewLC(iAgent.ImplementationUid(), TVirtualPathPtr(iDefaultVirtualPath.URI(), aUniqueId), aIntent, iShareMode); sl@0: } sl@0: else sl@0: { sl@0: // create a CData based upon the file handle supplied when this CContent was created sl@0: return CData::NewLC(iAgent.ImplementationUid(), iFile, aUniqueId, aIntent); sl@0: } sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: CData* CContent::OpenContentL(TIntent aIntent, const TDesC8& aHeaderData) sl@0: { sl@0: CData* data = OpenContentLC(aIntent, aHeaderData); sl@0: CleanupStack::Pop(data); sl@0: return data; sl@0: } sl@0: sl@0: CData* CContent::OpenContentLC(TIntent aIntent, const TDesC8& aHeaderData) sl@0: { sl@0: return CData::NewLC(iAgent.ImplementationUid(), aHeaderData, aIntent); sl@0: } sl@0: sl@0: #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: EXPORT_C const TAgent& CContent::Agent() const sl@0: { sl@0: // The agent handling this content sl@0: return iAgent; sl@0: } sl@0: sl@0: #ifndef REMOVE_CAF1 sl@0: // Deprecated functions sl@0: sl@0: EXPORT_C CData* CContent::OpenContentL(TIntent aIntent, TContentShareMode aShareMode) sl@0: { sl@0: CData* data = NULL; sl@0: // Open the content object specified by the Unique Id sl@0: if(iVirtualPath) sl@0: { sl@0: // create a CData based upon the URI supplied when this CContent was created sl@0: data = CData::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath, aIntent, aShareMode); sl@0: } sl@0: else sl@0: { sl@0: // create a CData based upon the file handle supplied when this CContent was created sl@0: data = CData::NewLC(iAgent.ImplementationUid(), iFile, iDefaultVirtualPath.UniqueId(), aIntent); sl@0: } sl@0: CleanupStack::Pop(data); sl@0: return data; sl@0: } sl@0: sl@0: EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded) sl@0: { sl@0: return NewAttributeL(aPreloaded, EContentShareReadOnly); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded, TContentShareMode aShareMode) sl@0: { sl@0: CAttribute* attr = NULL; sl@0: sl@0: if(iVirtualPath) sl@0: { sl@0: // if we were opened with a file name sl@0: attr = CAttribute::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath.URI(), aShareMode); sl@0: } sl@0: else if(iHeaderData) sl@0: { sl@0: attr = CAttribute::NewLC(iAgent.ImplementationUid(), *iHeaderData); sl@0: } sl@0: else sl@0: { sl@0: // if we were opened with a file handle sl@0: attr = CAttribute::NewLC(iAgent.ImplementationUid(), iFile); sl@0: } sl@0: sl@0: // If aPreloaded is set, query the agent immediately for all the attributes sl@0: if (aPreloaded) sl@0: { sl@0: attr->QuerySet().SetAll(); sl@0: attr->GetL(); sl@0: } sl@0: sl@0: CleanupStack::Pop(attr); sl@0: return attr; sl@0: } sl@0: sl@0: #else sl@0: sl@0: EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded, TContentShareMode aShareMode) sl@0: { sl@0: CAttribute* attr = NULL; sl@0: sl@0: if(iVirtualPath) sl@0: { sl@0: // if we were opened with a file name sl@0: attr = CAttribute::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath.URI(), aShareMode); sl@0: } sl@0: else sl@0: { sl@0: // if we were opened with a file handle sl@0: attr = CAttribute::NewLC(iAgent.ImplementationUid(), iFile); sl@0: } sl@0: sl@0: // If aPreloaded is set, query the agent immediately for all the attributes sl@0: if (aPreloaded) sl@0: { sl@0: attr->QuerySet().SetAll(); sl@0: attr->GetL(); sl@0: } sl@0: sl@0: CleanupStack::Pop(attr); sl@0: return attr; sl@0: } sl@0: sl@0: #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: #endif // REMOVE_CAF1 sl@0: sl@0: // DLL entry point - only for EKA1 sl@0: sl@0: sl@0: sl@0: