|
1 /* |
|
2 * Copyright (c) 2008-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 "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: DRM utility implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 |
|
21 #include "glxdrmutility.h" |
|
22 |
|
23 #include <glxpanic.h> |
|
24 |
|
25 #include <DRMHelper.h> |
|
26 #include <DRMCommon.h> |
|
27 |
|
28 #include <caf/caf.h> |
|
29 #include <caf/content.h> |
|
30 #include <caf/data.h> |
|
31 #include <caf/manager.h> |
|
32 #include "glxtracer.h" |
|
33 #include "glxlog.h" |
|
34 |
|
35 #include <drmuihandling.h> |
|
36 using namespace DRM; |
|
37 |
|
38 const TInt KGlxDRMThumbnailHeight = 120; |
|
39 const TInt KGlxDRMThumbnailWidth = 90; |
|
40 |
|
41 // ======== MEMBER FUNCTIONS ======== |
|
42 |
|
43 /** |
|
44 * CGlxDrmTls |
|
45 * |
|
46 * Global object stored in TLS. |
|
47 * Owns the only instance of a CGlxDRMUtility |
|
48 */ |
|
49 struct CGlxDrmTls |
|
50 { |
|
51 CGlxDrmTls(CGlxDRMUtility* aUtility) |
|
52 { |
|
53 iDrmUtility = aUtility; |
|
54 iRefCount = 0; |
|
55 } |
|
56 |
|
57 CGlxDRMUtility* iDrmUtility; |
|
58 TInt iRefCount; |
|
59 }; |
|
60 |
|
61 //============================================================================ |
|
62 // InstanceL |
|
63 //============================================================================ |
|
64 EXPORT_C CGlxDRMUtility* CGlxDRMUtility::InstanceL() |
|
65 { |
|
66 TRACER("CGlxDRMUtility::InstanceL()"); |
|
67 CGlxDrmTls* tls = reinterpret_cast<CGlxDrmTls*> (Dll::Tls()); |
|
68 |
|
69 if (!tls) |
|
70 { |
|
71 CGlxDRMUtility* drmutil = new (ELeave) CGlxDRMUtility(); |
|
72 CleanupStack::PushL(drmutil); |
|
73 drmutil->ConstructL(); |
|
74 |
|
75 tls = new (ELeave) CGlxDrmTls(drmutil); |
|
76 |
|
77 CleanupStack::Pop(drmutil); |
|
78 |
|
79 Dll::SetTls(reinterpret_cast<TAny*> (tls)); |
|
80 } |
|
81 |
|
82 tls->iRefCount++; |
|
83 |
|
84 return tls->iDrmUtility; |
|
85 } |
|
86 |
|
87 //============================================================================ |
|
88 // Close |
|
89 //============================================================================ |
|
90 EXPORT_C void CGlxDRMUtility::Close() |
|
91 { |
|
92 TRACER("CGlxDRMUtility::Close()"); |
|
93 CGlxDrmTls* tls = reinterpret_cast<CGlxDrmTls*> (Dll::Tls()); |
|
94 |
|
95 if (tls) |
|
96 { |
|
97 tls->iRefCount--; |
|
98 |
|
99 // Delete the tls pointer and list manager instance if this was the |
|
100 // last reference |
|
101 if (tls->iRefCount == 0) |
|
102 { |
|
103 delete tls->iDrmUtility; |
|
104 delete tls; |
|
105 Dll::SetTls(NULL); |
|
106 } |
|
107 } |
|
108 } |
|
109 |
|
110 //============================================================================ |
|
111 // Destructor |
|
112 //============================================================================ |
|
113 CGlxDRMUtility::~CGlxDRMUtility() |
|
114 { |
|
115 TRACER("CGlxDRMUtility::~CGlxDRMUtility()"); |
|
116 delete iCManager; |
|
117 delete iDrmHelper; |
|
118 delete iLastConsumedItemUri; |
|
119 } |
|
120 |
|
121 //============================================================================ |
|
122 // ItemRightsValidityCheckL |
|
123 // for checking DRM rights validity for item. |
|
124 // is called before right is consumed and for all items (focused or unfocused). |
|
125 //============================================================================ |
|
126 EXPORT_C TBool CGlxDRMUtility::ItemRightsValidityCheckL(const TDesC& aUri, |
|
127 TBool aCheckViewRights) |
|
128 { |
|
129 TRACER("CGlxDRMUtility::ItemRightsValidityCheckL(URI)"); |
|
130 #ifdef _DEBUG |
|
131 TTime startTime; |
|
132 startTime.HomeTime(); |
|
133 #endif |
|
134 // When checking current rights for a URI |
|
135 //Allow to Open if rights for a URI was just consumed (i.e. same as stored URI) |
|
136 if (iLastConsumedItemUri->Length() > 0) |
|
137 { |
|
138 if (aUri.CompareF(*iLastConsumedItemUri) == 0) |
|
139 { |
|
140 return ETrue; |
|
141 } |
|
142 } |
|
143 |
|
144 //Else for uri of non-focused uri, just check validity rights |
|
145 TBool rightsValid = EFalse; |
|
146 TVirtualPathPtr path(aUri, KDefaultContentObject()); |
|
147 |
|
148 ContentAccess::TAttribute attr = |
|
149 aCheckViewRights ? ContentAccess::ECanView : ContentAccess::ECanPlay; |
|
150 |
|
151 // rightsValid is not updated if an error occurs |
|
152 iCManager->GetAttribute(attr, rightsValid, path); |
|
153 #ifdef _DEBUG |
|
154 TTime stopTime; |
|
155 stopTime.HomeTime(); |
|
156 GLX_DEBUG2("CGlxDRMUtility::ItemRightsValidityCheckL(URI) took <%d> us", |
|
157 (TInt) stopTime.MicroSecondsFrom(startTime).Int64()); |
|
158 #endif |
|
159 return rightsValid; |
|
160 } |
|
161 |
|
162 //============================================================================ |
|
163 // ItemRightsValidityCheckL |
|
164 // for checking DRM rights validity for item. |
|
165 // is called before right is consumed and for all items (focused or unfocused). |
|
166 //============================================================================ |
|
167 EXPORT_C TBool CGlxDRMUtility::ItemRightsValidityCheckL(RFile& aFileHandle, |
|
168 TBool aCheckViewRights) |
|
169 { |
|
170 TRACER("CGlxDRMUtility::ItemRightsValidityCheckL(RFile)"); |
|
171 #ifdef _DEBUG |
|
172 TTime startTime; |
|
173 startTime.HomeTime(); |
|
174 #endif |
|
175 TBool rightsValid = EFalse; |
|
176 ContentAccess::TAttribute attrib = |
|
177 aCheckViewRights ? ContentAccess::ECanView : ContentAccess::ECanPlay; |
|
178 |
|
179 ContentAccess::CContent* content = ContentAccess::CContent::NewLC( |
|
180 aFileHandle); |
|
181 TInt err(content->GetAttribute(attrib, rightsValid)); |
|
182 CleanupStack::PopAndDestroy(content); |
|
183 #ifdef _DEBUG |
|
184 TTime stopTime; |
|
185 stopTime.HomeTime(); |
|
186 GLX_DEBUG2("CGlxDRMUtility::ItemRightsValidityCheckL(RFile) took <%d> us", |
|
187 (TInt) stopTime.MicroSecondsFrom(startTime).Int64()); |
|
188 #endif |
|
189 return rightsValid; |
|
190 } |
|
191 |
|
192 //============================================================================ |
|
193 // DisplayItemRightsCheckL |
|
194 // is called after right is consumed and for only focused/displayed item. |
|
195 //============================================================================ |
|
196 EXPORT_C TBool CGlxDRMUtility::DisplayItemRightsCheckL(const TDesC& aUri, |
|
197 TBool aCheckViewRights) |
|
198 { |
|
199 TRACER("CGlxDRMUtility::DisplayItemRightsCheckL(URI)"); |
|
200 |
|
201 // Allow to display if rights for a URI was just consumed (i.e. same as stored URI) |
|
202 if (iLastConsumedItemUri->Length() > 0) |
|
203 { |
|
204 if (aUri.CompareF(*iLastConsumedItemUri) == 0) |
|
205 { |
|
206 return ETrue; |
|
207 } |
|
208 } |
|
209 |
|
210 //Clear the stored uri since focus has changed |
|
211 ClearLastConsumedItemUriL(); |
|
212 |
|
213 // Otherwise, check current rights for the URI of newly focused item |
|
214 return ItemRightsValidityCheckL(aUri, aCheckViewRights); |
|
215 } |
|
216 |
|
217 //============================================================================ |
|
218 // DisplayItemRightsCheckL |
|
219 // is called after right is consumed and for only focused/displayed item. |
|
220 //============================================================================ |
|
221 EXPORT_C TBool CGlxDRMUtility::DisplayItemRightsCheckL(RFile& aFileHandle, |
|
222 TBool aCheckViewRights) |
|
223 { |
|
224 TRACER("CGlxDRMUtility::DisplayItemRightsCheckL(RFile)"); |
|
225 // Otherwise, check current rights for the URI of newly focused item |
|
226 return ItemRightsValidityCheckL(aFileHandle, aCheckViewRights); |
|
227 } |
|
228 |
|
229 //============================================================================ |
|
230 // ConsumeRightsL |
|
231 //============================================================================ |
|
232 EXPORT_C TBool CGlxDRMUtility::ConsumeRightsL(const TDesC& aUri) |
|
233 { |
|
234 TRACER("CGlxDRMUtility::ConsumeRightsL(URI)"); |
|
235 TVirtualPathPtr path(aUri, KDefaultContentObject()); |
|
236 |
|
237 // Create a CData object to read the content |
|
238 // Tell the agent we are planning to display the content |
|
239 CData* data = CData::NewLC(path, ContentAccess::EView, |
|
240 EContentShareReadOnly); |
|
241 |
|
242 //When consuming rights for a URI, clear stored URI |
|
243 ClearLastConsumedItemUriL(); |
|
244 |
|
245 // Execute the intent, tell the agent that we plan to display the content |
|
246 // It is at this point that any stateful rights will be decremented |
|
247 TInt err = data->ExecuteIntent(ContentAccess::EView); |
|
248 if (err == KErrNone) |
|
249 { |
|
250 //Update stored URI |
|
251 iLastConsumedItemUri = iLastConsumedItemUri->ReAllocL(aUri.Length()); |
|
252 TPtr newPtr = iLastConsumedItemUri->Des(); |
|
253 newPtr.Copy(aUri); |
|
254 } |
|
255 |
|
256 CleanupStack::PopAndDestroy(data); |
|
257 |
|
258 return (err == KErrNone); |
|
259 } |
|
260 |
|
261 //============================================================================ |
|
262 // ConsumeRightsL |
|
263 //============================================================================ |
|
264 EXPORT_C TBool CGlxDRMUtility::ConsumeRightsL(RFile& aFileHandle) |
|
265 { |
|
266 TRACER("CGlxDRMUtility::ConsumeRightsL(RFile)"); |
|
267 CData* data = CData::NewLC(aFileHandle, KDefaultContentObject(), EPeek); |
|
268 TInt err = data->ExecuteIntent(ContentAccess::EView); |
|
269 CleanupStack::PopAndDestroy(data); |
|
270 return (err == KErrNone); |
|
271 } |
|
272 |
|
273 //============================================================================ |
|
274 //Clears Last Consumed Uri |
|
275 //============================================================================ |
|
276 EXPORT_C void CGlxDRMUtility::ClearLastConsumedItemUriL() |
|
277 { |
|
278 TRACER("CGlxDRMUtility::ClearLastConsumedItemUriL()"); |
|
279 //clears the stored uri |
|
280 TPtr ptr = iLastConsumedItemUri->Des(); |
|
281 ptr.Zero(); |
|
282 iLastConsumedItemUri = iLastConsumedItemUri->ReAllocL(0); |
|
283 } |
|
284 |
|
285 //============================================================================ |
|
286 // Test whether a media item is OMA DRM 2.0 protected and has an associated |
|
287 // info URL. |
|
288 //============================================================================ |
|
289 EXPORT_C TBool CGlxDRMUtility::CanShowInfoOnlineL(const TDesC& aUri) |
|
290 { |
|
291 TRACER("CGlxDRMUtility::CanShowInfoOnlineL()"); |
|
292 TBool canShowInfoOnline = EFalse; |
|
293 |
|
294 HBufC8* urlBuf = NULL; |
|
295 canShowInfoOnline = iDrmHelper->HasInfoUrlL(const_cast<TDesC&> (aUri), |
|
296 urlBuf); |
|
297 |
|
298 // discard buf we don't need it |
|
299 delete urlBuf; |
|
300 |
|
301 return canShowInfoOnline; |
|
302 } |
|
303 |
|
304 //============================================================================ |
|
305 // Open the associated info URL for a media item in the browser. |
|
306 //============================================================================ |
|
307 EXPORT_C void CGlxDRMUtility::ShowInfoOnlineL(const TDesC& aUri) |
|
308 { |
|
309 TRACER("CGlxDRMUtility::ShowInfoOnlineL()"); |
|
310 iDrmHelper->OpenInfoUrlL(const_cast<TDesC&> (aUri)); |
|
311 } |
|
312 |
|
313 //============================================================================ |
|
314 // Test whether a media item can be set as automated content. |
|
315 //============================================================================ |
|
316 EXPORT_C TBool CGlxDRMUtility::CanSetAsAutomatedL(const TDesC& aUri, |
|
317 TGlxDrmAutomatedType aType) |
|
318 { |
|
319 TRACER("CGlxDRMUtility::CanSetAsAutomatedL()"); |
|
320 TBool canSetAutomated = EFalse; |
|
321 switch (aType) |
|
322 { |
|
323 case EGlxDrmAutomatedTypeWallpaper: |
|
324 { |
|
325 User::LeaveIfError(iDrmHelper->SetAutomatedType( |
|
326 CDRMHelper::EAutomatedTypeWallpaper)); |
|
327 User::LeaveIfError(iDrmHelper->CanSetAutomated(aUri, |
|
328 canSetAutomated)); |
|
329 break; |
|
330 } |
|
331 default: |
|
332 break; |
|
333 }; |
|
334 return canSetAutomated; |
|
335 } |
|
336 |
|
337 //============================================================================ |
|
338 // SetAsAutomatedL |
|
339 //============================================================================ |
|
340 EXPORT_C void CGlxDRMUtility::SetAsAutomatedL(const TDesC& aUri, |
|
341 TGlxDrmAutomatedType aType) |
|
342 { |
|
343 TRACER("CGlxDRMUtility::SetAsAutomatedL()"); |
|
344 switch (aType) |
|
345 { |
|
346 case EGlxDrmAutomatedTypeWallpaper: |
|
347 { |
|
348 TInt error = iDrmHelper->SetAutomatedType( |
|
349 CDRMHelper::EAutomatedTypeWallpaper); |
|
350 if (KErrNone == error) |
|
351 { |
|
352 error = iDrmHelper->SetAutomatedPassive(aUri); |
|
353 if (KErrNone != error) |
|
354 { |
|
355 iDrmHelper->HandleErrorL(error, aUri); |
|
356 } |
|
357 } |
|
358 |
|
359 break; |
|
360 } |
|
361 default: |
|
362 break; |
|
363 }; |
|
364 } |
|
365 |
|
366 //============================================================================ |
|
367 // ShowDRMDetailsPane |
|
368 //============================================================================ |
|
369 EXPORT_C void CGlxDRMUtility::ShowDRMDetailsPaneL(const TDesC& aUri) |
|
370 { |
|
371 TRACER("CGlxDRMUtility::ShowDRMDetailsPaneL(URI)"); |
|
372 GLX_LOG_URI("CGlxDRMUtility::ShowDRMDetailsPaneL(%S)", &aUri); |
|
373 RFs fs; |
|
374 User::LeaveIfError(fs.Connect()); |
|
375 CleanupClosePushL(fs); |
|
376 |
|
377 RFile64 drmFile; |
|
378 User::LeaveIfError(drmFile.Open(fs, aUri, EFileRead |
|
379 | EFileShareReadersOrWriters)); |
|
380 CleanupClosePushL(drmFile); |
|
381 |
|
382 CDrmUiHandling* drmUiHandler = CDrmUiHandling::NewLC(); |
|
383 TRAP_IGNORE(drmUiHandler->ShowDetailsViewL(drmFile)); |
|
384 CleanupStack::PopAndDestroy(drmUiHandler); |
|
385 |
|
386 CleanupStack::PopAndDestroy(&drmFile); |
|
387 CleanupStack::PopAndDestroy(&fs); |
|
388 } |
|
389 |
|
390 //============================================================================ |
|
391 // ShowDRMDetailsPane |
|
392 //============================================================================ |
|
393 EXPORT_C void CGlxDRMUtility::ShowDRMDetailsPaneL(RFile& aFileHandle) |
|
394 { |
|
395 TRACER("CGlxDRMUtility::ShowDRMDetailsPaneL(RFile)"); |
|
396 CDrmUiHandling* drmUiHandler = CDrmUiHandling::NewLC(); |
|
397 TRAP_IGNORE(drmUiHandler->ShowDetailsViewL(aFileHandle)); |
|
398 CleanupStack::PopAndDestroy(drmUiHandler); |
|
399 } |
|
400 |
|
401 //============================================================================ |
|
402 // IsForwardLockedL |
|
403 //============================================================================ |
|
404 EXPORT_C TBool CGlxDRMUtility::IsForwardLockedL(const TDesC& aUri) |
|
405 { |
|
406 TRACER("CGlxDRMUtility::IsForwardLockedL()"); |
|
407 TBool forwardLocked = EFalse; |
|
408 TVirtualPathPtr path(aUri, KDefaultContentObject()); |
|
409 |
|
410 // forwardLocked is not updated if an error occurs |
|
411 iCManager->GetAttribute(ContentAccess::EIsForwardable, forwardLocked, |
|
412 path); |
|
413 |
|
414 return forwardLocked; |
|
415 } |
|
416 |
|
417 //============================================================================ |
|
418 // ShowRightsInfoL |
|
419 //============================================================================ |
|
420 EXPORT_C void CGlxDRMUtility::ShowRightsInfoL(const TDesC& aUri) |
|
421 { |
|
422 TRACER("CGlxDRMUtility::ShowRightsInfoL(URI)"); |
|
423 iDrmHelper->CheckRightsAmountL(aUri); |
|
424 } |
|
425 |
|
426 //============================================================================ |
|
427 // ShowRightsInfoL |
|
428 //============================================================================ |
|
429 EXPORT_C void CGlxDRMUtility::ShowRightsInfoL(RFile& aFileHandle) |
|
430 { |
|
431 TRACER("CGlxDRMUtility::ShowRightsInfoL(RFile)"); |
|
432 iDrmHelper->CheckRightsAmountL(aFileHandle); |
|
433 } |
|
434 |
|
435 //============================================================================ |
|
436 // Return size for DRM thumbnail request. |
|
437 //============================================================================ |
|
438 EXPORT_C TSize CGlxDRMUtility::DRMThumbnailSize(TSize& aSize) |
|
439 { |
|
440 TRACER("CGlxDRMUtility::DRMThumbnailSize()"); |
|
441 TSize thumbnailSize(KGlxDRMThumbnailWidth, KGlxDRMThumbnailHeight); |
|
442 |
|
443 if ((aSize.iWidth * aSize.iHeight) / 4 < KGlxDRMThumbnailWidth |
|
444 * KGlxDRMThumbnailHeight) |
|
445 { |
|
446 thumbnailSize.iWidth = aSize.iWidth / 2; |
|
447 thumbnailSize.iHeight = aSize.iHeight / 2; |
|
448 } |
|
449 |
|
450 return thumbnailSize; |
|
451 } |
|
452 |
|
453 /** |
|
454 * C++ default constructor. |
|
455 */ |
|
456 CGlxDRMUtility::CGlxDRMUtility() |
|
457 { |
|
458 TRACER("CGlxDRMUtility::CGlxDRMUtility()"); |
|
459 } |
|
460 |
|
461 /** |
|
462 * By default Symbian 2nd phase constructor is private. |
|
463 */ |
|
464 void CGlxDRMUtility::ConstructL() |
|
465 { |
|
466 TRACER("CGlxDRMUtility::ConstructL()"); |
|
467 iCManager = ContentAccess::CManager::NewL(); |
|
468 iDrmHelper = CDRMHelper::NewL(); |
|
469 iLastConsumedItemUri = HBufC::NewL(0); |
|
470 } |
|
471 |
|
472 // End of File |