|
1 /* |
|
2 * Copyright (c) 2006-2007 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: |
|
15 * CUniDrmInfo, Storage for single attachment in presentation. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // ========== INCLUDE FILES ================================ |
|
22 |
|
23 #include <e32def.h> // for basic types |
|
24 #include <eikenv.h> // for CBase |
|
25 #include <coemain.h> // for CEikonEnv |
|
26 #include <mtclbase.h> // for CBaseMtm |
|
27 #include <msvids.h> // for KMsvTempIndexEntryId |
|
28 #include <msvstore.h> |
|
29 #include <mmsvattachmentmanager.h> |
|
30 #include <mmsvattachmentmanagersync.h> |
|
31 #include <cmsvattachment.h> |
|
32 |
|
33 // Features |
|
34 #include <featmgr.h> |
|
35 #include <bldvariant.hrh> |
|
36 |
|
37 // DRM |
|
38 #ifndef DRMCOMMONIN_POISTO |
|
39 #include <DRMCommon.h> |
|
40 #endif |
|
41 |
|
42 #include <DRMHelper.h> |
|
43 |
|
44 #include <MsgMediaInfo.h> |
|
45 #include <MsgTextInfo.h> |
|
46 |
|
47 #include "UniModelConst.h" |
|
48 #include "UniMimeInfo.h" |
|
49 #include "UniDrmInfo.h" |
|
50 #include "UniObject.h" |
|
51 #include "UniDataUtils.h" |
|
52 |
|
53 //#include "UniEditorLogging.h" |
|
54 #include "fileprotectionresolver.h" |
|
55 #include "MsgMimeTypes.h" |
|
56 |
|
57 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
58 |
|
59 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
60 |
|
61 // ========== CONSTANTS ==================================== |
|
62 |
|
63 // ========== MACROS ======================================= |
|
64 |
|
65 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
66 |
|
67 // ========== MODULE DATA STRUCTURES ======================= |
|
68 |
|
69 |
|
70 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
71 |
|
72 // ========== LOCAL FUNCTIONS ============================== |
|
73 |
|
74 // ========== MEMBER FUNCTIONS ============================= |
|
75 |
|
76 // --------------------------------------------------------- |
|
77 // CUniDrmInfo::NewLC |
|
78 // |
|
79 // Factory method. |
|
80 // --------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C CUniDrmInfo* CUniDrmInfo::NewLC( RFs& aFs, |
|
83 CBaseMtm& aMtm, |
|
84 TMsvAttachmentId& aId, |
|
85 CMsgMediaInfo& aMediaInfo ) |
|
86 { |
|
87 CUniDrmInfo* self = new ( ELeave ) CUniDrmInfo( aFs, aMtm, aId, aMediaInfo ); |
|
88 |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL(); |
|
91 |
|
92 return self; |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------- |
|
96 // CUniDrmInfo::NewL |
|
97 // |
|
98 // Factory method. |
|
99 // --------------------------------------------------------- |
|
100 // |
|
101 EXPORT_C CUniDrmInfo* CUniDrmInfo::NewL( RFs& aFs, |
|
102 CBaseMtm& aMtm, |
|
103 TMsvAttachmentId& aId, |
|
104 CMsgMediaInfo& aMediaInfo ) |
|
105 { |
|
106 CUniDrmInfo* self = NewLC( aFs, aMtm, aId, aMediaInfo ); |
|
107 CleanupStack::Pop( self ); |
|
108 |
|
109 return self; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CUniDrmInfo::CUniDrmInfo |
|
114 // |
|
115 // Constructor. |
|
116 // --------------------------------------------------------- |
|
117 // |
|
118 CUniDrmInfo::CUniDrmInfo( RFs& aFs, |
|
119 CBaseMtm& aMtm, |
|
120 TMsvAttachmentId& aId, |
|
121 CMsgMediaInfo& aMediaInfo ) : |
|
122 iFs( aFs ), |
|
123 iMtm( aMtm ), |
|
124 iAttachmentId( aId ), |
|
125 iMediaInfo( aMediaInfo ), |
|
126 iDRMConsumeStatus( EUniDRMNone ), |
|
127 iDRMConsumeCount( 0 ), |
|
128 iDRMRightsExist( ETrue ), //Rights ok by default |
|
129 iDRMExpiration( CDRMRights::EValidRights ), |
|
130 iDRMRestriction( CDRMRights::EFullRights ), |
|
131 iDRMConstraintType( CDRMRights::ENoConstraints ) |
|
132 { |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------- |
|
136 // CUniDrmInfo::CUniDrmInfo |
|
137 // |
|
138 // Destructor. |
|
139 // --------------------------------------------------------- |
|
140 // |
|
141 CUniDrmInfo::~CUniDrmInfo() |
|
142 { |
|
143 ReleaseRights(); |
|
144 delete iDRMHelper; |
|
145 |
|
146 #ifdef DRMCOMMONIN_POISTO |
|
147 delete iRightsManager; |
|
148 #else |
|
149 delete iDRMCommon; |
|
150 #endif |
|
151 |
|
152 delete iSendContentUrl; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------- |
|
156 // CUniDrmInfo::ConstructL |
|
157 // |
|
158 // 2nd phase constructor. |
|
159 // --------------------------------------------------------- |
|
160 // |
|
161 void CUniDrmInfo::ConstructL() |
|
162 { |
|
163 if ( !iMediaInfo.DRMContentURI()->Length() ) |
|
164 { |
|
165 User::Leave( KErrNotSupported ); |
|
166 } |
|
167 |
|
168 // Get supported features from feature manager. |
|
169 /* |
|
170 FeatureManager::InitializeLibL(); |
|
171 if ( FeatureManager::FeatureSupported( KFeatureIdDrmFull ) ) |
|
172 { |
|
173 iSupportedFeatures |= EUniFeatureDrmFull; |
|
174 } |
|
175 FeatureManager::UnInitializeLib(); |
|
176 */ |
|
177 |
|
178 #ifdef DRMCOMMONIN_POISTO |
|
179 |
|
180 // Seems pretty heavy. Should be done only once by e.g. Document |
|
181 // and a reference should be passed as an input parameter? |
|
182 CManager* manager = CManager::NewLC(); |
|
183 |
|
184 RArray<TAgent> agents; |
|
185 manager->ListAgentsL( agents ); |
|
186 CleanupClosePushL( agents ); |
|
187 |
|
188 for ( TInt i = 0; !iRightsManager && i < agents.Count(); ++i ) |
|
189 { |
|
190 if ( agents[ i ].Name().Compare( KOmaDrm2AgentName ) == 0 ) |
|
191 { |
|
192 iRightsManager = manager->CreateRightsManagerL( agents[ i ] ); |
|
193 } |
|
194 } |
|
195 |
|
196 CleanupStack::PopAndDestroy( 2, manager ); // agents, manager |
|
197 |
|
198 if ( !iRightsManager ) |
|
199 { |
|
200 User::Leave( KErrNotFound ); |
|
201 } |
|
202 |
|
203 #else // DRMCOMMONIN_POISTO |
|
204 |
|
205 iDRMCommon = DRMCommon::NewL(); |
|
206 |
|
207 #endif // DRMCOMMONIN_POISTO |
|
208 |
|
209 iDRMHelper = CDRMHelper::NewL( *CEikonEnv::Static( ), iFs ); |
|
210 DoGetRightsInfoL(); |
|
211 |
|
212 // Check it here that image count is rights. |
|
213 // When image is displayed, use count is already decremented. |
|
214 SetIsDrmWithOnePreviewL(); |
|
215 |
|
216 TInt drmMethods; |
|
217 CDRMHelper::TDRMHelperOMALevel omaLevel; |
|
218 iDRMHelper->SupportedDRMMethods2( drmMethods, omaLevel ); |
|
219 iOma2 = ( omaLevel == CDRMHelper::EOMA_2_0 ? ETrue : EFalse ); |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------- |
|
223 // CUniDrmInfo::DoGetRightsInfoL |
|
224 // --------------------------------------------------------- |
|
225 // |
|
226 void CUniDrmInfo::DoGetRightsInfoL( CDRMRights** /*aRightsObj*/ ) |
|
227 { |
|
228 /* |
|
229 if ( iSupportedFeatures & EUniFeatureDrmFull ) |
|
230 { |
|
231 CDRMRights* rightsObj = NULL; |
|
232 TInt rightSpec = ConsumeIntent(); |
|
233 |
|
234 #ifdef DRMCOMMONIN_POISTO |
|
235 |
|
236 MAgentRightsBase* cafRights = NULL; |
|
237 RStreamablePtrArray<CRightsInfo> rights; |
|
238 |
|
239 // Copy to 16-bit buffer |
|
240 // TODO: Is this really the correct parameter to give to ListRightsL?! |
|
241 HBufC* temp = HBufC::NewLC( iMediaInfo.DRMContentURI()->Length() ); |
|
242 TPtr ptr = temp->Des(); |
|
243 ptr.Copy( *iMediaInfo.DRMContentURI() ); |
|
244 |
|
245 iRightsManager->ListRightsL( rights, *temp ); |
|
246 |
|
247 CleanupStack::PopAndDestroy( temp ); |
|
248 if ( rights.Count() ) |
|
249 { |
|
250 // The active RO is the first one in the list |
|
251 //CRightsInfo* rightsInfo = rights[0]->AllocL(); |
|
252 CRightsInfo* rightsInfo = rights[ 0 ]; |
|
253 cafRights = iRightsManager->GetRightsDataL( *rightsInfo ); |
|
254 rightsObj = reinterpret_cast<CDRMRights*>( cafRights ); |
|
255 rightsObj->GetRightsInfo( |
|
256 rightSpec, |
|
257 iDRMRestriction, |
|
258 iDRMExpiration, |
|
259 iDRMConstraintType ); |
|
260 iDRMRightsExist = ETrue; |
|
261 } |
|
262 else |
|
263 { |
|
264 iDRMRightsExist = EFalse; |
|
265 } |
|
266 rights.ResetAndDestroy(); |
|
267 |
|
268 #else // DRMCOMMONIN_POISTO |
|
269 |
|
270 TInt restriction = iDRMCommon->GetActiveRights( |
|
271 *iMediaInfo.DRMContentURI(), |
|
272 rightSpec, |
|
273 rightsObj ); |
|
274 |
|
275 if ( restriction == CDRMRights::ENoRights || |
|
276 !rightsObj ) |
|
277 { |
|
278 iDRMRightsExist = EFalse; |
|
279 } |
|
280 else |
|
281 { |
|
282 rightsObj->GetRightsInfo( |
|
283 rightSpec, |
|
284 iDRMRestriction, |
|
285 iDRMExpiration, |
|
286 iDRMConstraintType ); |
|
287 iDRMRightsExist = ETrue; |
|
288 } |
|
289 |
|
290 #endif // DRMCOMMONIN_POISTO |
|
291 |
|
292 if ( aRightsObj ) |
|
293 { |
|
294 (*aRightsObj) = rightsObj; |
|
295 } |
|
296 else |
|
297 { |
|
298 delete rightsObj; |
|
299 } |
|
300 } |
|
301 */ |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------- |
|
305 // CUniDrmInfo::ConsumeRights |
|
306 // --------------------------------------------------------- |
|
307 // |
|
308 EXPORT_C TInt CUniDrmInfo::ConsumeRights() |
|
309 { |
|
310 // UNILOGGER_ENTERFN( "CUniDrmInfo::ConsumeRights" ); |
|
311 |
|
312 TInt err( KErrNone ); |
|
313 if ( ( iMediaInfo.MediaType() == EMsgMediaAudio || |
|
314 ( iMediaInfo.MediaType() != EMsgMediaAudio && |
|
315 iDRMExpiration == CDRMRights::EValidRights ) ) && |
|
316 iDRMConsumeStatus != EUniDRMConsumed ) |
|
317 { |
|
318 if ( iDRMConsumeCount ) |
|
319 { |
|
320 //UNILOGGER_WRITE( "Rights freezed" ); |
|
321 |
|
322 // Already once consumed. Freeze is enough! |
|
323 FreezeRights(); |
|
324 } |
|
325 else |
|
326 { |
|
327 if ( iDRMConsumeStatus == EUniDRMFrozen ) |
|
328 { |
|
329 //UNILOGGER_WRITE( "Rights released" ); |
|
330 |
|
331 ReleaseRights(); |
|
332 } |
|
333 |
|
334 err = iDRMHelper->Consume2( iMediaInfo.DRMContentURI()->Des(), |
|
335 ConsumeIntent(), |
|
336 CDRMHelper::EStart ); |
|
337 |
|
338 if ( !err ) |
|
339 { |
|
340 //UNILOGGER_WRITE( "Rights consumed" ); |
|
341 |
|
342 iDRMConsumeStatus = EUniDRMConsumed; |
|
343 iDRMConsumeCount++; |
|
344 } |
|
345 } |
|
346 } |
|
347 // else - never consume for preview |
|
348 |
|
349 //UNILOGGER_WRITEF( _L("Result: %d"), err ); |
|
350 //UNILOGGER_LEAVEFN( "CUniDrmInfo::ConsumeRights" ); |
|
351 |
|
352 return err; |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------- |
|
356 // CUniDrmInfo::EvaluateRights |
|
357 // --------------------------------------------------------- |
|
358 // |
|
359 EXPORT_C TInt CUniDrmInfo::EvaluateRights( TBool& aConsumed ) |
|
360 { |
|
361 //UNILOGGER_ENTERFN( "CUniDrmInfo::EvaluateRights" ); |
|
362 |
|
363 aConsumed = ( iDRMConsumeStatus == EUniDRMConsumed || iDRMConsumeCount ); |
|
364 |
|
365 TInt err( KErrNone ); |
|
366 |
|
367 CData* cData = NULL; |
|
368 TRAP_IGNORE( cData = CreateCDataL() ); |
|
369 |
|
370 if ( cData ) |
|
371 { |
|
372 err = cData->EvaluateIntent( ConsumeIntent() ); |
|
373 delete cData; |
|
374 } |
|
375 |
|
376 //UNILOGGER_WRITEF( _L("Result: %d, aConsumed %d"), err, aConsumed ); |
|
377 //UNILOGGER_LEAVEFN( "CUniDrmInfo::EvaluateRights" ); |
|
378 |
|
379 return err; |
|
380 } |
|
381 |
|
382 // --------------------------------------------------------- |
|
383 // CUniDrmInfo::FreezeRights |
|
384 // --------------------------------------------------------- |
|
385 // |
|
386 EXPORT_C TInt CUniDrmInfo::FreezeRights() |
|
387 { |
|
388 //UNILOGGER_ENTERFN( "CUniDrmInfo::FreezeRights" ); |
|
389 |
|
390 TInt err( KErrNone ); |
|
391 if ( ( iMediaInfo.MediaType() == EMsgMediaAudio || |
|
392 ( iMediaInfo.MediaType() != EMsgMediaAudio && |
|
393 iDRMExpiration == CDRMRights::EValidRights ) ) && |
|
394 iDRMConsumeStatus == EUniDRMNone ) |
|
395 { |
|
396 err = iDRMHelper->Consume2( iMediaInfo.DRMContentURI()->Des(), |
|
397 ContentAccess::EInstall, |
|
398 CDRMHelper::EStart ); |
|
399 |
|
400 if ( !err ) |
|
401 { |
|
402 //UNILOGGER_WRITE( "Rights frozen" ); |
|
403 |
|
404 iDRMConsumeStatus = EUniDRMFrozen; |
|
405 } |
|
406 } |
|
407 |
|
408 //UNILOGGER_WRITEF( _L("Result: %d"), err ); |
|
409 //UNILOGGER_LEAVEFN( "CUniDrmInfo::FreezeRights" ); |
|
410 |
|
411 return err; |
|
412 } |
|
413 |
|
414 // --------------------------------------------------------- |
|
415 // CUniDrmInfo::ReleaseRights |
|
416 // --------------------------------------------------------- |
|
417 // |
|
418 EXPORT_C TInt CUniDrmInfo::ReleaseRights() |
|
419 { |
|
420 //UNILOGGER_ENTERFN( "CUniDrmInfo::ReleaseRights" ); |
|
421 |
|
422 TInt err( KErrNone ); |
|
423 if ( iDRMConsumeStatus != EUniDRMNone ) |
|
424 { |
|
425 TUint32 rightsSpec = ( iDRMConsumeStatus == EUniDRMFrozen ) |
|
426 ? ContentAccess::EInstall |
|
427 : ConsumeIntent(); |
|
428 |
|
429 err = iDRMHelper->Consume2( iMediaInfo.DRMContentURI()->Des(), |
|
430 rightsSpec, |
|
431 CDRMHelper::EFinish ); |
|
432 |
|
433 //UNILOGGER_WRITE( "Rights released" ); |
|
434 |
|
435 // else - never consumed for preview |
|
436 iDRMConsumeStatus = EUniDRMNone; |
|
437 } |
|
438 |
|
439 //UNILOGGER_WRITEF( _L("Result: %d"), err ); |
|
440 //UNILOGGER_LEAVEFN( "CUniDrmInfo::ReleaseRights" ); |
|
441 |
|
442 return err; |
|
443 } |
|
444 |
|
445 // --------------------------------------------------------- |
|
446 // CUniDrmInfo::RightsValidL |
|
447 // --------------------------------------------------------- |
|
448 // |
|
449 EXPORT_C TBool CUniDrmInfo::RightsValidL( TBool aUpdate ) |
|
450 { |
|
451 //UNILOGGER_ENTERFN( "CUniDrmInfo::RightsValidL" ); |
|
452 //UNILOGGER_WRITEF( _L("aUpdate: %d"), aUpdate ); |
|
453 |
|
454 // By default rights are valid |
|
455 TBool retVal = ETrue; |
|
456 if ( aUpdate ) |
|
457 { |
|
458 DoGetRightsInfoL(); |
|
459 |
|
460 //UNILOGGER_WRITE( "Update done" ); |
|
461 } |
|
462 |
|
463 if ( iMediaInfo.Protection() & |
|
464 ( EFileProtForwardLocked | EFileProtSuperDistributable ) ) |
|
465 { |
|
466 if ( iDRMRightsExist ) |
|
467 { |
|
468 if ( iDRMExpiration == CDRMRights::EExpiredRights || |
|
469 iDRMExpiration == CDRMRights::EFutureRights ) |
|
470 { |
|
471 // Expired or future rights |
|
472 retVal = EFalse; |
|
473 } |
|
474 } |
|
475 else |
|
476 { |
|
477 // No rights |
|
478 retVal = EFalse; |
|
479 } |
|
480 } |
|
481 |
|
482 //UNILOGGER_WRITEF( _L("Result: %d"), retVal ); |
|
483 //UNILOGGER_LEAVEFN( "CUniDrmInfo::RightsValidL" ); |
|
484 |
|
485 return retVal; |
|
486 } |
|
487 |
|
488 // --------------------------------------------------------- |
|
489 // CUniDrmInfo::IsDrmWithOnePreview |
|
490 // --------------------------------------------------------- |
|
491 // |
|
492 EXPORT_C TBool CUniDrmInfo::IsDrmWithOnePreview() |
|
493 { |
|
494 return iDrmOnePreview; |
|
495 } |
|
496 |
|
497 // --------------------------------------------------------- |
|
498 // CUniDrmInfo::SetIsDrmWithOnePreviewL |
|
499 // --------------------------------------------------------- |
|
500 // |
|
501 void CUniDrmInfo::SetIsDrmWithOnePreviewL() |
|
502 { |
|
503 /* |
|
504 iDrmOnePreview = EFalse; |
|
505 if ( !( iSupportedFeatures & EUniFeatureDrmFull ) ) |
|
506 { |
|
507 return; |
|
508 } |
|
509 |
|
510 // Check only object list. Attachments are left for |
|
511 // dedicated attachment handler's responsibility. |
|
512 CDRMRights* rights = NULL; |
|
513 DoGetRightsInfoL(&rights); |
|
514 |
|
515 if ( rights && |
|
516 iDRMRightsExist && |
|
517 !( iDRMConstraintType ^ CDRMRights::ECountBased ) && // only ECountBased bit set |
|
518 iMediaInfo.Protection() & EFileProtForwardLocked ) |
|
519 { |
|
520 // must get count still |
|
521 // no leaving functions in this function |
|
522 CDRMRightsConstraints* constraint = NULL; |
|
523 TMsgMediaType mediaType = iMediaInfo.MediaType(); |
|
524 |
|
525 if ( mediaType == EMsgMediaImage || |
|
526 mediaType == EMsgMediaSvg ) |
|
527 { |
|
528 rights->GetDisplayRight( constraint ); |
|
529 } |
|
530 else if ( mediaType == EMsgMediaAudio || |
|
531 mediaType == EMsgMediaVideo ) |
|
532 { |
|
533 rights->GetPlayRight( constraint ); |
|
534 } |
|
535 |
|
536 if ( constraint && |
|
537 constraint->IsPreview() ) |
|
538 { |
|
539 TUint32 origCount = 0; |
|
540 TUint32 nowCount = 0; |
|
541 constraint->GetCounters( nowCount, origCount); |
|
542 |
|
543 if ( nowCount == 1 ) |
|
544 { |
|
545 iDrmOnePreview = ETrue; |
|
546 } |
|
547 } |
|
548 |
|
549 delete constraint; |
|
550 } |
|
551 |
|
552 delete rights; |
|
553 */ |
|
554 } |
|
555 |
|
556 |
|
557 // --------------------------------------------------------- |
|
558 // CUniDrmInfo::CreateCDataL |
|
559 // --------------------------------------------------------- |
|
560 // |
|
561 CData* CUniDrmInfo::CreateCDataL() |
|
562 { |
|
563 CData* result = NULL; |
|
564 |
|
565 if ( iMediaInfo.DRMContentURI() ) |
|
566 { |
|
567 // depends on iAttachmentId |
|
568 RFile attachmentFile = CUniDataUtils::GetAttachmentFileL( iMtm, iAttachmentId ); |
|
569 CleanupClosePushL( attachmentFile ); |
|
570 |
|
571 result = CData::NewL( attachmentFile, |
|
572 KDefaultContentObject, |
|
573 EPeek ); |
|
574 |
|
575 CleanupStack::PopAndDestroy( &attachmentFile ); |
|
576 } |
|
577 |
|
578 return result; |
|
579 } |
|
580 |
|
581 // --------------------------------------------------------- |
|
582 // CUniDrmInfo::HandleDrmErrorL |
|
583 // --------------------------------------------------------- |
|
584 // |
|
585 EXPORT_C void CUniDrmInfo::HandleDrmErrorL( TInt aError ) |
|
586 { |
|
587 if ( iDRMHelper ) |
|
588 { |
|
589 RFile attachmentFile = CUniDataUtils::GetAttachmentFileL( iMtm, iAttachmentId ); |
|
590 CleanupClosePushL( attachmentFile ); |
|
591 |
|
592 iDRMHelper->HandleErrorL( aError, |
|
593 attachmentFile ); |
|
594 CleanupStack::PopAndDestroy( &attachmentFile ); |
|
595 } |
|
596 } |
|
597 |
|
598 |
|
599 // EOF |