|
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 |
|
20 /** |
|
21 * @internal reviewed 03/07/2007 by Rowland Cook |
|
22 */ |
|
23 |
|
24 // INCLUDES |
|
25 |
|
26 #include "glxdrmutility.h" |
|
27 |
|
28 #include <glxpanic.h> |
|
29 |
|
30 #include <DRMHelper.h> |
|
31 #include <DRMCommon.h> |
|
32 |
|
33 #include <caf/caf.h> |
|
34 #include <caf/content.h> |
|
35 #include <caf/data.h> |
|
36 #include <caf/manager.h> |
|
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 CGlxDrmTls* tls = reinterpret_cast<CGlxDrmTls*>(Dll::Tls()); |
|
67 |
|
68 if(tls==NULL) |
|
69 { |
|
70 CGlxDRMUtility* drmutil = new(ELeave)CGlxDRMUtility(); |
|
71 CleanupStack::PushL(drmutil); |
|
72 drmutil->ConstructL(); |
|
73 |
|
74 tls = new (ELeave) CGlxDrmTls(drmutil); |
|
75 |
|
76 CleanupStack::Pop(drmutil); |
|
77 |
|
78 Dll::SetTls( reinterpret_cast<TAny*>(tls)); |
|
79 } |
|
80 |
|
81 tls->iRefCount++; |
|
82 |
|
83 return tls->iDrmUtility; |
|
84 } |
|
85 |
|
86 //============================================================================ |
|
87 // Close |
|
88 //============================================================================ |
|
89 EXPORT_C void CGlxDRMUtility::Close() |
|
90 { |
|
91 CGlxDrmTls* tls = reinterpret_cast<CGlxDrmTls*>(Dll::Tls()); |
|
92 |
|
93 if (tls != NULL) |
|
94 { |
|
95 tls->iRefCount--; |
|
96 |
|
97 // Delete the tls pointer and list manager instance if this was the |
|
98 // last reference |
|
99 if (tls->iRefCount == 0) |
|
100 { |
|
101 delete tls->iDrmUtility; |
|
102 delete tls; |
|
103 Dll::SetTls(NULL); |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 //============================================================================ |
|
109 // Destructor |
|
110 //============================================================================ |
|
111 CGlxDRMUtility::~CGlxDRMUtility() |
|
112 { |
|
113 delete iCManager; |
|
114 delete iDrmHelper; |
|
115 delete iLastConsumedItemUri; |
|
116 } |
|
117 |
|
118 //============================================================================ |
|
119 // CheckOpenRightsL |
|
120 //============================================================================ |
|
121 EXPORT_C TBool CGlxDRMUtility::CheckOpenRightsL( const TDesC& aUri, |
|
122 TBool aCheckViewRights ) |
|
123 { |
|
124 // When checking current rights for a URI, clear stored URI |
|
125 TPtr ptr = iLastConsumedItemUri->Des(); |
|
126 ptr.Zero(); |
|
127 iLastConsumedItemUri = iLastConsumedItemUri->ReAllocL( 0 ); |
|
128 |
|
129 TBool rightsValid = EFalse; |
|
130 TVirtualPathPtr path( aUri, KDefaultContentObject() ); |
|
131 |
|
132 ContentAccess::TAttribute attr = |
|
133 aCheckViewRights ? ContentAccess::ECanView : ContentAccess::ECanPlay; |
|
134 |
|
135 // rightsValid is not updated if an error occurs |
|
136 iCManager->GetAttribute( attr, rightsValid, path ); |
|
137 |
|
138 return rightsValid; |
|
139 } |
|
140 |
|
141 //============================================================================ |
|
142 // CheckDisplayRightsL |
|
143 //============================================================================ |
|
144 EXPORT_C TBool CGlxDRMUtility::CheckDisplayRightsL( const TDesC& aUri, |
|
145 TBool aCheckViewRights ) |
|
146 { |
|
147 // Allow to display if rights for a URI was just consumed (i.e. same as stored URI) |
|
148 if ( iLastConsumedItemUri->Length() > 0 ) |
|
149 { |
|
150 if ( aUri.CompareF( *iLastConsumedItemUri ) == 0 ) |
|
151 { |
|
152 return ETrue; |
|
153 } |
|
154 } |
|
155 |
|
156 // Otherwise, check current rights for the URI |
|
157 return CheckOpenRightsL( aUri, aCheckViewRights ); |
|
158 } |
|
159 |
|
160 //============================================================================ |
|
161 // ConsumeRightsL |
|
162 //============================================================================ |
|
163 EXPORT_C TBool CGlxDRMUtility::ConsumeRightsL(const TDesC& aUri) |
|
164 { |
|
165 TVirtualPathPtr path( aUri, KDefaultContentObject() ); |
|
166 |
|
167 // Create a CData object to read the content |
|
168 // Tell the agent we are planning to display the content |
|
169 CData* data = CData::NewLC(path, ContentAccess::EView, EContentShareReadOnly); |
|
170 |
|
171 // When consuming rights for a URI, clear stored URI |
|
172 TPtr oldPtr = iLastConsumedItemUri->Des(); |
|
173 oldPtr.Zero(); |
|
174 iLastConsumedItemUri = iLastConsumedItemUri->ReAllocL( aUri.Length() ); |
|
175 |
|
176 // Execute the intent, tell the agent that we plan to display the content |
|
177 // It is at this point that any stateful rights will be decremented |
|
178 TInt err = data->ExecuteIntent(ContentAccess::EView); |
|
179 if ( err == KErrNone ) |
|
180 { |
|
181 // Update stored URI |
|
182 TPtr newPtr = iLastConsumedItemUri->Des(); |
|
183 newPtr.Copy( aUri ); |
|
184 } |
|
185 |
|
186 CleanupStack::PopAndDestroy(data); |
|
187 |
|
188 return (err == KErrNone); |
|
189 } |
|
190 |
|
191 //============================================================================ |
|
192 // Test whether a media item is OMA DRM 2.0 protected and has an associated |
|
193 // info URL. |
|
194 //============================================================================ |
|
195 EXPORT_C TBool CGlxDRMUtility::CanShowInfoOnlineL(TDesC& aUri) |
|
196 { |
|
197 TBool canShowInfoOnline = EFalse; |
|
198 |
|
199 HBufC8* urlBuf = NULL; |
|
200 canShowInfoOnline = iDrmHelper->HasInfoUrlL(aUri, urlBuf); |
|
201 |
|
202 // discard buf we don't need it |
|
203 delete urlBuf; |
|
204 |
|
205 return canShowInfoOnline; |
|
206 } |
|
207 |
|
208 //============================================================================ |
|
209 // Open the associated info URL for a media item in the browser. |
|
210 //============================================================================ |
|
211 EXPORT_C void CGlxDRMUtility::ShowInfoOnlineL(TDesC& aUri) |
|
212 { |
|
213 iDrmHelper->OpenInfoUrlL(aUri); |
|
214 } |
|
215 |
|
216 //============================================================================ |
|
217 // Test whether a media item can be set as automated content. |
|
218 //============================================================================ |
|
219 EXPORT_C TBool CGlxDRMUtility::CanSetAsAutomatedL(const TDesC& aUri, |
|
220 TGlxDrmAutomatedType aType) |
|
221 { |
|
222 TBool canSetAutomated = EFalse; |
|
223 switch(aType) |
|
224 { |
|
225 case EGlxDrmAutomatedTypeWallpaper: |
|
226 { |
|
227 User::LeaveIfError(iDrmHelper->SetAutomatedType(CDRMHelper::EAutomatedTypeWallpaper)); |
|
228 User::LeaveIfError(iDrmHelper->CanSetAutomated(aUri, canSetAutomated)); |
|
229 break; |
|
230 } |
|
231 default: |
|
232 break; |
|
233 }; |
|
234 return canSetAutomated; |
|
235 } |
|
236 |
|
237 //============================================================================ |
|
238 // SetAsAutomatedL |
|
239 //============================================================================ |
|
240 EXPORT_C void CGlxDRMUtility::SetAsAutomatedL(const TDesC& aUri, |
|
241 TGlxDrmAutomatedType aType) |
|
242 { |
|
243 switch(aType) |
|
244 { |
|
245 case EGlxDrmAutomatedTypeWallpaper: |
|
246 { |
|
247 TInt error = iDrmHelper->SetAutomatedType(CDRMHelper::EAutomatedTypeWallpaper); |
|
248 if(KErrNone==error) |
|
249 { |
|
250 error= iDrmHelper->SetAutomatedPassive(aUri); |
|
251 if(KErrNone!=error) |
|
252 { |
|
253 iDrmHelper->HandleErrorL(error, aUri); |
|
254 } |
|
255 } |
|
256 |
|
257 break; |
|
258 } |
|
259 default: |
|
260 break; |
|
261 }; |
|
262 } |
|
263 |
|
264 //============================================================================ |
|
265 // ShowDRMDetailsPane |
|
266 //============================================================================ |
|
267 EXPORT_C void CGlxDRMUtility::ShowDRMDetailsPaneL( const TDesC& aUri ) |
|
268 { |
|
269 TRAPD( err, iDrmHelper->LaunchDetailsViewEmbeddedL( aUri ) ); |
|
270 // if no rights ask user to re-activate? |
|
271 if( err == KErrCANoRights ) |
|
272 { |
|
273 HBufC* buf = aUri.AllocLC(); |
|
274 iDrmHelper->ActivateContentL( *buf ); |
|
275 CleanupStack::PopAndDestroy( buf ); |
|
276 } |
|
277 |
|
278 } |
|
279 |
|
280 //============================================================================ |
|
281 // IsForwardLockedL |
|
282 //============================================================================ |
|
283 EXPORT_C TBool CGlxDRMUtility::IsForwardLockedL(const TDesC& aUri) |
|
284 { |
|
285 TBool forwardLocked = EFalse; |
|
286 TVirtualPathPtr path( aUri, KDefaultContentObject() ); |
|
287 |
|
288 // forwardLocked is not updated if an error occurs |
|
289 iCManager->GetAttribute( ContentAccess::EIsForwardable, forwardLocked, path ); |
|
290 |
|
291 return forwardLocked; |
|
292 } |
|
293 |
|
294 //============================================================================ |
|
295 // ShowRightsInfoL |
|
296 //============================================================================ |
|
297 EXPORT_C void CGlxDRMUtility::ShowRightsInfoL(const TDesC& aUri) |
|
298 { |
|
299 iDrmHelper->CheckRightsAmountL( aUri ); |
|
300 } |
|
301 |
|
302 //============================================================================ |
|
303 // Return size for DRM thumbnail request. |
|
304 //============================================================================ |
|
305 EXPORT_C TSize CGlxDRMUtility::DRMThumbnailSize(TSize& aSize) |
|
306 { |
|
307 TSize thumbnailSize(KGlxDRMThumbnailWidth, KGlxDRMThumbnailHeight); |
|
308 |
|
309 if((aSize.iWidth*aSize.iHeight)/4 < |
|
310 KGlxDRMThumbnailWidth * KGlxDRMThumbnailHeight) |
|
311 { |
|
312 thumbnailSize.iWidth = aSize.iWidth/2; |
|
313 thumbnailSize.iHeight = aSize.iHeight/2; |
|
314 } |
|
315 |
|
316 return thumbnailSize; |
|
317 } |
|
318 |
|
319 /** |
|
320 * C++ default constructor. |
|
321 */ |
|
322 CGlxDRMUtility::CGlxDRMUtility() |
|
323 { |
|
324 |
|
325 } |
|
326 |
|
327 /** |
|
328 * By default Symbian 2nd phase constructor is private. |
|
329 */ |
|
330 void CGlxDRMUtility::ConstructL() |
|
331 { |
|
332 iCManager = ContentAccess::CManager::NewL(); |
|
333 iDrmHelper = CDRMHelper::NewL(); |
|
334 iLastConsumedItemUri = HBufC::NewL(0); |
|
335 } |
|
336 |
|
337 |
|
338 // End of File |