os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32agentcontent.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32agentcontent.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,488 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <caf/embeddedobject.h>
    1.23 +#include <apmstd.h>
    1.24 +#include "f32agentcontent.h"
    1.25 +#include "f32defaultattributes.h"
    1.26 +#include <caf/f32agentui.h>
    1.27 +
    1.28 +using namespace ContentAccess;
    1.29 +
    1.30 +CF32AgentContent* CF32AgentContent::NewL(const TDesC& aURI, TContentShareMode aShareMode)
    1.31 +	{
    1.32 +	CF32AgentContent* self = new (ELeave) CF32AgentContent;
    1.33 +	CleanupStack::PushL(self);
    1.34 +	self->ConstructL(aURI, aShareMode);
    1.35 +	CleanupStack::Pop(self);
    1.36 +	return self;
    1.37 +	}
    1.38 +
    1.39 +CF32AgentContent* CF32AgentContent::NewL(RFile& aFile)
    1.40 +	{
    1.41 +	CF32AgentContent* self = new (ELeave) CF32AgentContent;
    1.42 +	CleanupStack::PushL(self);
    1.43 +	self->ConstructL(aFile);
    1.44 +	CleanupStack::Pop(self);
    1.45 +	return self;
    1.46 +	}
    1.47 +
    1.48 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    1.49 +CF32AgentContent* CF32AgentContent::NewL(const TDesC8& aHeaderData)
    1.50 +	{
    1.51 +	CF32AgentContent* self = new (ELeave) CF32AgentContent;
    1.52 +	CleanupStack::PushL(self);
    1.53 +	self->ConstructL(aHeaderData);
    1.54 +	CleanupStack::Pop(self);
    1.55 +	return self;
    1.56 +	}
    1.57 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    1.58 +	
    1.59 +CF32AgentContent::CF32AgentContent()
    1.60 +	{
    1.61 +	}
    1.62 +
    1.63 +CF32AgentContent::~CF32AgentContent()
    1.64 +	{
    1.65 +	iFile.Close();
    1.66 +	if(iURI)
    1.67 +		{
    1.68 +		// file session only created when file is opened by name
    1.69 +		iFs.Close();
    1.70 +		}
    1.71 +	delete iURI;
    1.72 +	
    1.73 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT	
    1.74 +	delete iHeaderData;
    1.75 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    1.76 +	}
    1.77 +  
    1.78 +void CF32AgentContent::ConstructL(const TDesC& aURI, TContentShareMode aShareMode)
    1.79 +	{
    1.80 +	iURI = aURI.AllocL();
    1.81 +	iShareMode = aShareMode;
    1.82 +	
    1.83 +	// Test that the file exists and hold it open so nobody deletes it etc
    1.84 +	TUint mode = TF32DefaultAttributes::GetFileMode(aShareMode);
    1.85 +	User::LeaveIfError(iFs.Connect());
    1.86 +	User::LeaveIfError(iFile.Open(iFs, *iURI, mode));
    1.87 +	}
    1.88 +
    1.89 +void CF32AgentContent::ConstructL(RFile& aFile)
    1.90 +	{
    1.91 +	User::LeaveIfError(iFile.Duplicate(aFile));
    1.92 +	}
    1.93 +
    1.94 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT	
    1.95 +void CF32AgentContent::ConstructL(const TDesC8& aHeaderData)
    1.96 +	{
    1.97 +	if(aHeaderData.Length() > 0)
    1.98 +		iHeaderData = aHeaderData.AllocL();
    1.99 +	else
   1.100 +		User::Leave(KErrMissingWmdrmHeaderData);
   1.101 +	}
   1.102 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.103 +
   1.104 +TInt CF32AgentContent::OpenContainer(const TDesC&)
   1.105 +	{
   1.106 +	return KErrNotFound;
   1.107 +	}
   1.108 +
   1.109 +TInt CF32AgentContent::CloseContainer()
   1.110 +	{
   1.111 +	return KErrNotFound;
   1.112 +	}
   1.113 +
   1.114 +void CF32AgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& aArray)
   1.115 +	{
   1.116 +	TBuf8 <KMaxDataTypeLength> mimeType;
   1.117 +	CEmbeddedObject *embeddedObject = NULL;
   1.118 +	
   1.119 +	// the only embedded object is the file itself	
   1.120 +	// Try to get the mime type
   1.121 +	mimeType.SetLength(0);
   1.122 +	if(iURI)
   1.123 +		{
   1.124 +		TF32DefaultAttributes::GetMimeTypeL(*iURI, mimeType);
   1.125 +		}
   1.126 +	else
   1.127 +		{
   1.128 +		TF32DefaultAttributes::GetMimeTypeL(iFile, mimeType);
   1.129 +		}	
   1.130 +	embeddedObject = CEmbeddedObject::NewL(KDefaultContentObject(), mimeType, EContentObject);
   1.131 +	CleanupStack::PushL(embeddedObject);
   1.132 +	aArray.AppendL(embeddedObject);
   1.133 +	
   1.134 +	// Now owned by the array so do not destroy
   1.135 +	CleanupStack::Pop(embeddedObject);
   1.136 +	}
   1.137 +
   1.138 +void CF32AgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& aArray, TEmbeddedType aType)
   1.139 +	{
   1.140 +	// the only embedded object is the file itself
   1.141 +	if(aType == EContentObject)
   1.142 +		{
   1.143 +		// just get the default object since there is only one content object
   1.144 +		GetEmbeddedObjectsL(aArray);
   1.145 +		}
   1.146 +	}
   1.147 +
   1.148 +void CF32AgentContent::SearchL(RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8& aMimeType, TBool /* aRecurse */)
   1.149 +	{
   1.150 +	TBuf8 <KMaxDataTypeLength> mimeType;
   1.151 +	
   1.152 +	CEmbeddedObject *embeddedObject = NULL;
   1.153 +	
   1.154 +	// the only embedded object is the file itself	
   1.155 +	if(iURI)
   1.156 +		{
   1.157 +		TF32DefaultAttributes::GetMimeTypeL(*iURI, mimeType);
   1.158 +		}
   1.159 +	else
   1.160 +		{
   1.161 +		TF32DefaultAttributes::GetMimeTypeL(iFile, mimeType);
   1.162 +		}
   1.163 +	
   1.164 +	// Check the file has the correct mime type
   1.165 +	if(aMimeType == mimeType)
   1.166 +		{
   1.167 +		embeddedObject = CEmbeddedObject::NewL(KDefaultContentObject(), mimeType, EContentObject);
   1.168 +		CleanupStack::PushL(embeddedObject);		
   1.169 +		aArray.AppendL(embeddedObject);
   1.170 +	
   1.171 +		// Now owned by the array so do not destroy
   1.172 +		CleanupStack::Pop(embeddedObject);
   1.173 +		}
   1.174 +	else
   1.175 +		{
   1.176 +		// Mime type was incorrect. Set error to indicate no content object
   1.177 +		// of the desired type was found in the file.
   1.178 +		User::Leave(KErrNotFound);
   1.179 +		}
   1.180 +	}
   1.181 +
   1.182 +TInt CF32AgentContent::Search(RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8& aMimeType, TBool aRecurse)
   1.183 +	{
   1.184 +	TRAPD( err, SearchL(aArray, aMimeType, aRecurse) );
   1.185 +	return err;
   1.186 +	}
   1.187 +
   1.188 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.189 +TInt CF32AgentContent::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& aUniqueId)
   1.190 +	{
   1.191 +	
   1.192 +	// check that the unique Id exists
   1.193 +	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   1.194 +		{
   1.195 +		return KErrNotFound;	
   1.196 +		}
   1.197 +	
   1.198 +	TInt err = KErrNone;
   1.199 +	if(iURI)
   1.200 +		{
   1.201 +		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, *iURI);
   1.202 +		}
   1.203 +	else if(iHeaderData)
   1.204 +		{
   1.205 +		err = TF32DefaultAttributes::GetAttribute(*iHeaderData, aAttribute, aValue);
   1.206 +		}
   1.207 +	else
   1.208 +		{
   1.209 +		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iFile);
   1.210 +		}
   1.211 +	return err;
   1.212 +	}
   1.213 +
   1.214 +#else
   1.215 +TInt CF32AgentContent::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& aUniqueId)
   1.216 +	{
   1.217 +	// check that the unique Id exists
   1.218 +	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   1.219 +		{
   1.220 +		return KErrNotFound;	
   1.221 +		}
   1.222 +	
   1.223 +	TInt err = KErrNone;
   1.224 +	if(iURI)
   1.225 +		{
   1.226 +		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, *iURI);
   1.227 +		}
   1.228 +	else
   1.229 +		{
   1.230 +		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iFile);
   1.231 +		}
   1.232 +	return err;
   1.233 +	}
   1.234 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.235 +
   1.236 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.237 +
   1.238 +TInt CF32AgentContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId)
   1.239 +	{
   1.240 +	// check that the unique Id exists
   1.241 +	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   1.242 +		{
   1.243 +		return KErrNotFound;	
   1.244 +		}
   1.245 +		
   1.246 +	TInt err = KErrNone;
   1.247 +	if(iURI)
   1.248 +		{
   1.249 +		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, *iURI);
   1.250 +		}
   1.251 +	else if(iHeaderData)
   1.252 +		{
   1.253 +		err = TF32DefaultAttributes::GetAttributeSet(*iHeaderData, aAttributeSet);
   1.254 +		}
   1.255 +	else
   1.256 +		{
   1.257 +		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iFile);
   1.258 +		}
   1.259 +	return err;
   1.260 +	}
   1.261 +
   1.262 +#else
   1.263 +
   1.264 +TInt CF32AgentContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId)
   1.265 +	{
   1.266 +	// check that the unique Id exists
   1.267 +	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   1.268 +		{
   1.269 +		return KErrNotFound;	
   1.270 +		}
   1.271 +		
   1.272 +	TInt err = KErrNone;
   1.273 +	if(iURI)
   1.274 +		{
   1.275 +		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, *iURI);
   1.276 +		}
   1.277 +	else
   1.278 +		{
   1.279 +		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iFile);
   1.280 +		}
   1.281 +	return err;
   1.282 +	}
   1.283 +
   1.284 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.285 +
   1.286 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.287 +
   1.288 +TInt CF32AgentContent::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUniqueId)
   1.289 +	{
   1.290 +	// check that the unique Id exists
   1.291 +	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   1.292 +		{
   1.293 +		return KErrNotFound;	
   1.294 +		}
   1.295 +		
   1.296 +	TInt err = KErrNone;
   1.297 +	if(iURI)
   1.298 +		{
   1.299 +		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, *iURI);
   1.300 +		}
   1.301 +	else if(iHeaderData)
   1.302 +		{
   1.303 +		err = TF32DefaultAttributes::GetStringAttribute(*iHeaderData, aAttribute, aValue);
   1.304 +		}
   1.305 +	else
   1.306 +		{
   1.307 +		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iFile);
   1.308 +		}
   1.309 +	return err;
   1.310 +	}
   1.311 +
   1.312 +#else
   1.313 +TInt CF32AgentContent::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUniqueId)
   1.314 +	{
   1.315 +	// check that the unique Id exists
   1.316 +	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   1.317 +		{
   1.318 +		return KErrNotFound;	
   1.319 +		}
   1.320 +		
   1.321 +	TInt err = KErrNone;
   1.322 +	if(iURI)
   1.323 +		{
   1.324 +		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, *iURI);
   1.325 +		}
   1.326 +	else
   1.327 +		{
   1.328 +		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iFile);
   1.329 +		}
   1.330 +	return err;
   1.331 +	}
   1.332 +#endif
   1.333 +
   1.334 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.335 +
   1.336 +TInt CF32AgentContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId)
   1.337 +	{
   1.338 +	// check that the unique Id exists
   1.339 +	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   1.340 +		{
   1.341 +		return KErrNotFound;	
   1.342 +		}
   1.343 +	
   1.344 +	TInt err = KErrNone;
   1.345 +	if(iURI)
   1.346 +		{
   1.347 +		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, *iURI);
   1.348 +		}
   1.349 +	else if(iHeaderData)
   1.350 +		{
   1.351 +		err = TF32DefaultAttributes::GetStringAttributeSet(*iHeaderData, aStringAttributeSet);
   1.352 +		}
   1.353 +	else
   1.354 +		{
   1.355 +		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iFile);
   1.356 +		}
   1.357 +	return err;
   1.358 +	}
   1.359 +
   1.360 +#else
   1.361 +
   1.362 +TInt CF32AgentContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId)
   1.363 +	{
   1.364 +	// check that the unique Id exists
   1.365 +	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   1.366 +		{
   1.367 +		return KErrNotFound;	
   1.368 +		}
   1.369 +	
   1.370 +	TInt err = KErrNone;
   1.371 +	if(iURI)
   1.372 +		{
   1.373 +		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, *iURI);
   1.374 +		}
   1.375 +	else
   1.376 +		{
   1.377 +		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iFile);
   1.378 +		}
   1.379 +	return err;
   1.380 +	}
   1.381 +
   1.382 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.383 +
   1.384 +TInt CF32AgentContent::AgentSpecificCommand(TInt , const TDesC8& , TDes8& )
   1.385 +	{
   1.386 +	return KErrCANotSupported;
   1.387 +	}
   1.388 +
   1.389 +void CF32AgentContent::AgentSpecificCommand(TInt , const TDesC8& , TDes8& , TRequestStatus& aStatus)
   1.390 +	{
   1.391 +	TRequestStatus* ptr = &aStatus;
   1.392 +	User::RequestComplete(ptr, KErrCANotSupported);
   1.393 +	}
   1.394 +
   1.395 +void CF32AgentContent::NotifyStatusChange(TEventMask , TRequestStatus& aStatus, const TDesC& )
   1.396 +	{
   1.397 +	TRequestStatus* ptr = &aStatus;
   1.398 +	User::RequestComplete(ptr, KErrCANotSupported);
   1.399 +	}
   1.400 +
   1.401 +TInt CF32AgentContent::CancelNotifyStatusChange(TRequestStatus& , const TDesC& )
   1.402 +	{
   1.403 +	return KErrCANotSupported;
   1.404 +	}
   1.405 +
   1.406 +void CF32AgentContent::RequestRights(TRequestStatus& aStatus, const TDesC& )
   1.407 +	{
   1.408 +	TRequestStatus* ptr = &aStatus;
   1.409 +	User::RequestComplete(ptr, KErrCANotSupported);
   1.410 +	}
   1.411 +
   1.412 +TInt CF32AgentContent::CancelRequestRights(TRequestStatus& , const TDesC& )
   1.413 +	{
   1.414 +	return KErrCANotSupported;
   1.415 +	}
   1.416 +
   1.417 +void CF32AgentContent::DisplayInfoL(TDisplayInfo aInfo, const TDesC& aUniqueId)
   1.418 +	{
   1.419 +	// Check that the client hasn't specified some incorrect UniqueId
   1.420 +	User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aUniqueId));
   1.421 +
   1.422 +
   1.423 +	if(iURI)
   1.424 +		{
   1.425 +		// Open the file handle in order to pass it to the Agent UI
   1.426 +		RFs fs;
   1.427 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   1.428 +		RFile64 file;
   1.429 +#else
   1.430 +		RFile file;
   1.431 +#endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   1.432 +		
   1.433 +		// default share mode of EFileShareReadersOnly
   1.434 +		TUint mode = EFileShareReadersOnly | EFileStream | EFileRead;
   1.435 +
   1.436 +		if(iShareMode == EContentShareReadWrite)
   1.437 +			{
   1.438 +			mode = EFileShareAny | EFileStream | EFileRead;
   1.439 +			}
   1.440 +		else if(iShareMode == EContentShareExclusive)
   1.441 +			{
   1.442 +			mode = EFileShareExclusive | EFileStream | EFileRead;
   1.443 +			}
   1.444 +
   1.445 +		
   1.446 +		User::LeaveIfError(fs.Connect());
   1.447 +		CleanupClosePushL(fs);
   1.448 +		User::LeaveIfError(file.Open(fs, *iURI, mode));
   1.449 +		CleanupClosePushL(file);
   1.450 +		AgentUiL().DisplayInfoL(aInfo, file);	
   1.451 +		CleanupStack::PopAndDestroy(2, &fs); // file, fs
   1.452 +		}
   1.453 +	else
   1.454 +		{
   1.455 +		// just pass existing file handle
   1.456 +		AgentUiL().DisplayInfoL(aInfo, iFile);
   1.457 +		}
   1.458 +	}
   1.459 +
   1.460 +TInt CF32AgentContent::SetProperty(TAgentProperty aProperty, TInt aValue)
   1.461 +	{
   1.462 +	if(aProperty==EAgentPropertyAgentUI)
   1.463 +		// should only pass type EAgentPropertyAgentUI 
   1.464 +		{
   1.465 +		
   1.466 +		CF32AgentUi* ui = NULL;
   1.467 +	
   1.468 +		// get a pointer to the UI
   1.469 +		TRAPD(err, ui = &AgentUiL());
   1.470 +		if(err)
   1.471 +			{
   1.472 +			return err;
   1.473 +			}
   1.474 +		return ui->SetProperty(aProperty, aValue);
   1.475 +		}
   1.476 +	else
   1.477 +		{
   1.478 +		return KErrCANotSupported;
   1.479 +		}
   1.480 +	}
   1.481 +
   1.482 +
   1.483 +CF32AgentUi& CF32AgentContent::AgentUiL()
   1.484 +	{
   1.485 +	if(!iAgentUi)
   1.486 +		{
   1.487 +		// load agent UI from f32AgentUi.dll
   1.488 +		iAgentUi = TF32AgentUiFactory::CreateF32AgentUiL();
   1.489 +		}
   1.490 +	return *iAgentUi;
   1.491 +	}