os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32agentcontent.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2004-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 the License "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: 
    15 *
    16 */
    17 
    18 
    19 #include <caf/embeddedobject.h>
    20 #include <apmstd.h>
    21 #include "f32agentcontent.h"
    22 #include "f32defaultattributes.h"
    23 #include <caf/f32agentui.h>
    24 
    25 using namespace ContentAccess;
    26 
    27 CF32AgentContent* CF32AgentContent::NewL(const TDesC& aURI, TContentShareMode aShareMode)
    28 	{
    29 	CF32AgentContent* self = new (ELeave) CF32AgentContent;
    30 	CleanupStack::PushL(self);
    31 	self->ConstructL(aURI, aShareMode);
    32 	CleanupStack::Pop(self);
    33 	return self;
    34 	}
    35 
    36 CF32AgentContent* CF32AgentContent::NewL(RFile& aFile)
    37 	{
    38 	CF32AgentContent* self = new (ELeave) CF32AgentContent;
    39 	CleanupStack::PushL(self);
    40 	self->ConstructL(aFile);
    41 	CleanupStack::Pop(self);
    42 	return self;
    43 	}
    44 
    45 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    46 CF32AgentContent* CF32AgentContent::NewL(const TDesC8& aHeaderData)
    47 	{
    48 	CF32AgentContent* self = new (ELeave) CF32AgentContent;
    49 	CleanupStack::PushL(self);
    50 	self->ConstructL(aHeaderData);
    51 	CleanupStack::Pop(self);
    52 	return self;
    53 	}
    54 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    55 	
    56 CF32AgentContent::CF32AgentContent()
    57 	{
    58 	}
    59 
    60 CF32AgentContent::~CF32AgentContent()
    61 	{
    62 	iFile.Close();
    63 	if(iURI)
    64 		{
    65 		// file session only created when file is opened by name
    66 		iFs.Close();
    67 		}
    68 	delete iURI;
    69 	
    70 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT	
    71 	delete iHeaderData;
    72 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    73 	}
    74   
    75 void CF32AgentContent::ConstructL(const TDesC& aURI, TContentShareMode aShareMode)
    76 	{
    77 	iURI = aURI.AllocL();
    78 	iShareMode = aShareMode;
    79 	
    80 	// Test that the file exists and hold it open so nobody deletes it etc
    81 	TUint mode = TF32DefaultAttributes::GetFileMode(aShareMode);
    82 	User::LeaveIfError(iFs.Connect());
    83 	User::LeaveIfError(iFile.Open(iFs, *iURI, mode));
    84 	}
    85 
    86 void CF32AgentContent::ConstructL(RFile& aFile)
    87 	{
    88 	User::LeaveIfError(iFile.Duplicate(aFile));
    89 	}
    90 
    91 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT	
    92 void CF32AgentContent::ConstructL(const TDesC8& aHeaderData)
    93 	{
    94 	if(aHeaderData.Length() > 0)
    95 		iHeaderData = aHeaderData.AllocL();
    96 	else
    97 		User::Leave(KErrMissingWmdrmHeaderData);
    98 	}
    99 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   100 
   101 TInt CF32AgentContent::OpenContainer(const TDesC&)
   102 	{
   103 	return KErrNotFound;
   104 	}
   105 
   106 TInt CF32AgentContent::CloseContainer()
   107 	{
   108 	return KErrNotFound;
   109 	}
   110 
   111 void CF32AgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& aArray)
   112 	{
   113 	TBuf8 <KMaxDataTypeLength> mimeType;
   114 	CEmbeddedObject *embeddedObject = NULL;
   115 	
   116 	// the only embedded object is the file itself	
   117 	// Try to get the mime type
   118 	mimeType.SetLength(0);
   119 	if(iURI)
   120 		{
   121 		TF32DefaultAttributes::GetMimeTypeL(*iURI, mimeType);
   122 		}
   123 	else
   124 		{
   125 		TF32DefaultAttributes::GetMimeTypeL(iFile, mimeType);
   126 		}	
   127 	embeddedObject = CEmbeddedObject::NewL(KDefaultContentObject(), mimeType, EContentObject);
   128 	CleanupStack::PushL(embeddedObject);
   129 	aArray.AppendL(embeddedObject);
   130 	
   131 	// Now owned by the array so do not destroy
   132 	CleanupStack::Pop(embeddedObject);
   133 	}
   134 
   135 void CF32AgentContent::GetEmbeddedObjectsL(RStreamablePtrArray<CEmbeddedObject>& aArray, TEmbeddedType aType)
   136 	{
   137 	// the only embedded object is the file itself
   138 	if(aType == EContentObject)
   139 		{
   140 		// just get the default object since there is only one content object
   141 		GetEmbeddedObjectsL(aArray);
   142 		}
   143 	}
   144 
   145 void CF32AgentContent::SearchL(RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8& aMimeType, TBool /* aRecurse */)
   146 	{
   147 	TBuf8 <KMaxDataTypeLength> mimeType;
   148 	
   149 	CEmbeddedObject *embeddedObject = NULL;
   150 	
   151 	// the only embedded object is the file itself	
   152 	if(iURI)
   153 		{
   154 		TF32DefaultAttributes::GetMimeTypeL(*iURI, mimeType);
   155 		}
   156 	else
   157 		{
   158 		TF32DefaultAttributes::GetMimeTypeL(iFile, mimeType);
   159 		}
   160 	
   161 	// Check the file has the correct mime type
   162 	if(aMimeType == mimeType)
   163 		{
   164 		embeddedObject = CEmbeddedObject::NewL(KDefaultContentObject(), mimeType, EContentObject);
   165 		CleanupStack::PushL(embeddedObject);		
   166 		aArray.AppendL(embeddedObject);
   167 	
   168 		// Now owned by the array so do not destroy
   169 		CleanupStack::Pop(embeddedObject);
   170 		}
   171 	else
   172 		{
   173 		// Mime type was incorrect. Set error to indicate no content object
   174 		// of the desired type was found in the file.
   175 		User::Leave(KErrNotFound);
   176 		}
   177 	}
   178 
   179 TInt CF32AgentContent::Search(RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8& aMimeType, TBool aRecurse)
   180 	{
   181 	TRAPD( err, SearchL(aArray, aMimeType, aRecurse) );
   182 	return err;
   183 	}
   184 
   185 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   186 TInt CF32AgentContent::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& aUniqueId)
   187 	{
   188 	
   189 	// check that the unique Id exists
   190 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   191 		{
   192 		return KErrNotFound;	
   193 		}
   194 	
   195 	TInt err = KErrNone;
   196 	if(iURI)
   197 		{
   198 		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, *iURI);
   199 		}
   200 	else if(iHeaderData)
   201 		{
   202 		err = TF32DefaultAttributes::GetAttribute(*iHeaderData, aAttribute, aValue);
   203 		}
   204 	else
   205 		{
   206 		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iFile);
   207 		}
   208 	return err;
   209 	}
   210 
   211 #else
   212 TInt CF32AgentContent::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& aUniqueId)
   213 	{
   214 	// check that the unique Id exists
   215 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   216 		{
   217 		return KErrNotFound;	
   218 		}
   219 	
   220 	TInt err = KErrNone;
   221 	if(iURI)
   222 		{
   223 		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, *iURI);
   224 		}
   225 	else
   226 		{
   227 		err = TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iFile);
   228 		}
   229 	return err;
   230 	}
   231 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   232 
   233 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   234 
   235 TInt CF32AgentContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId)
   236 	{
   237 	// check that the unique Id exists
   238 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   239 		{
   240 		return KErrNotFound;	
   241 		}
   242 		
   243 	TInt err = KErrNone;
   244 	if(iURI)
   245 		{
   246 		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, *iURI);
   247 		}
   248 	else if(iHeaderData)
   249 		{
   250 		err = TF32DefaultAttributes::GetAttributeSet(*iHeaderData, aAttributeSet);
   251 		}
   252 	else
   253 		{
   254 		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iFile);
   255 		}
   256 	return err;
   257 	}
   258 
   259 #else
   260 
   261 TInt CF32AgentContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId)
   262 	{
   263 	// check that the unique Id exists
   264 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   265 		{
   266 		return KErrNotFound;	
   267 		}
   268 		
   269 	TInt err = KErrNone;
   270 	if(iURI)
   271 		{
   272 		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, *iURI);
   273 		}
   274 	else
   275 		{
   276 		err = TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iFile);
   277 		}
   278 	return err;
   279 	}
   280 
   281 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   282 
   283 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   284 
   285 TInt CF32AgentContent::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUniqueId)
   286 	{
   287 	// check that the unique Id exists
   288 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   289 		{
   290 		return KErrNotFound;	
   291 		}
   292 		
   293 	TInt err = KErrNone;
   294 	if(iURI)
   295 		{
   296 		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, *iURI);
   297 		}
   298 	else if(iHeaderData)
   299 		{
   300 		err = TF32DefaultAttributes::GetStringAttribute(*iHeaderData, aAttribute, aValue);
   301 		}
   302 	else
   303 		{
   304 		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iFile);
   305 		}
   306 	return err;
   307 	}
   308 
   309 #else
   310 TInt CF32AgentContent::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUniqueId)
   311 	{
   312 	// check that the unique Id exists
   313 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   314 		{
   315 		return KErrNotFound;	
   316 		}
   317 		
   318 	TInt err = KErrNone;
   319 	if(iURI)
   320 		{
   321 		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, *iURI);
   322 		}
   323 	else
   324 		{
   325 		err = TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iFile);
   326 		}
   327 	return err;
   328 	}
   329 #endif
   330 
   331 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   332 
   333 TInt CF32AgentContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId)
   334 	{
   335 	// check that the unique Id exists
   336 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   337 		{
   338 		return KErrNotFound;	
   339 		}
   340 	
   341 	TInt err = KErrNone;
   342 	if(iURI)
   343 		{
   344 		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, *iURI);
   345 		}
   346 	else if(iHeaderData)
   347 		{
   348 		err = TF32DefaultAttributes::GetStringAttributeSet(*iHeaderData, aStringAttributeSet);
   349 		}
   350 	else
   351 		{
   352 		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iFile);
   353 		}
   354 	return err;
   355 	}
   356 
   357 #else
   358 
   359 TInt CF32AgentContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId)
   360 	{
   361 	// check that the unique Id exists
   362 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   363 		{
   364 		return KErrNotFound;	
   365 		}
   366 	
   367 	TInt err = KErrNone;
   368 	if(iURI)
   369 		{
   370 		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, *iURI);
   371 		}
   372 	else
   373 		{
   374 		err = TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iFile);
   375 		}
   376 	return err;
   377 	}
   378 
   379 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   380 
   381 TInt CF32AgentContent::AgentSpecificCommand(TInt , const TDesC8& , TDes8& )
   382 	{
   383 	return KErrCANotSupported;
   384 	}
   385 
   386 void CF32AgentContent::AgentSpecificCommand(TInt , const TDesC8& , TDes8& , TRequestStatus& aStatus)
   387 	{
   388 	TRequestStatus* ptr = &aStatus;
   389 	User::RequestComplete(ptr, KErrCANotSupported);
   390 	}
   391 
   392 void CF32AgentContent::NotifyStatusChange(TEventMask , TRequestStatus& aStatus, const TDesC& )
   393 	{
   394 	TRequestStatus* ptr = &aStatus;
   395 	User::RequestComplete(ptr, KErrCANotSupported);
   396 	}
   397 
   398 TInt CF32AgentContent::CancelNotifyStatusChange(TRequestStatus& , const TDesC& )
   399 	{
   400 	return KErrCANotSupported;
   401 	}
   402 
   403 void CF32AgentContent::RequestRights(TRequestStatus& aStatus, const TDesC& )
   404 	{
   405 	TRequestStatus* ptr = &aStatus;
   406 	User::RequestComplete(ptr, KErrCANotSupported);
   407 	}
   408 
   409 TInt CF32AgentContent::CancelRequestRights(TRequestStatus& , const TDesC& )
   410 	{
   411 	return KErrCANotSupported;
   412 	}
   413 
   414 void CF32AgentContent::DisplayInfoL(TDisplayInfo aInfo, const TDesC& aUniqueId)
   415 	{
   416 	// Check that the client hasn't specified some incorrect UniqueId
   417 	User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aUniqueId));
   418 
   419 
   420 	if(iURI)
   421 		{
   422 		// Open the file handle in order to pass it to the Agent UI
   423 		RFs fs;
   424 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   425 		RFile64 file;
   426 #else
   427 		RFile file;
   428 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   429 		
   430 		// default share mode of EFileShareReadersOnly
   431 		TUint mode = EFileShareReadersOnly | EFileStream | EFileRead;
   432 
   433 		if(iShareMode == EContentShareReadWrite)
   434 			{
   435 			mode = EFileShareAny | EFileStream | EFileRead;
   436 			}
   437 		else if(iShareMode == EContentShareExclusive)
   438 			{
   439 			mode = EFileShareExclusive | EFileStream | EFileRead;
   440 			}
   441 
   442 		
   443 		User::LeaveIfError(fs.Connect());
   444 		CleanupClosePushL(fs);
   445 		User::LeaveIfError(file.Open(fs, *iURI, mode));
   446 		CleanupClosePushL(file);
   447 		AgentUiL().DisplayInfoL(aInfo, file);	
   448 		CleanupStack::PopAndDestroy(2, &fs); // file, fs
   449 		}
   450 	else
   451 		{
   452 		// just pass existing file handle
   453 		AgentUiL().DisplayInfoL(aInfo, iFile);
   454 		}
   455 	}
   456 
   457 TInt CF32AgentContent::SetProperty(TAgentProperty aProperty, TInt aValue)
   458 	{
   459 	if(aProperty==EAgentPropertyAgentUI)
   460 		// should only pass type EAgentPropertyAgentUI 
   461 		{
   462 		
   463 		CF32AgentUi* ui = NULL;
   464 	
   465 		// get a pointer to the UI
   466 		TRAPD(err, ui = &AgentUiL());
   467 		if(err)
   468 			{
   469 			return err;
   470 			}
   471 		return ui->SetProperty(aProperty, aValue);
   472 		}
   473 	else
   474 		{
   475 		return KErrCANotSupported;
   476 		}
   477 	}
   478 
   479 
   480 CF32AgentUi& CF32AgentContent::AgentUiL()
   481 	{
   482 	if(!iAgentUi)
   483 		{
   484 		// load agent UI from f32AgentUi.dll
   485 		iAgentUi = TF32AgentUiFactory::CreateF32AgentUiL();
   486 		}
   487 	return *iAgentUi;
   488 	}