|
1 /* |
|
2 * Copyright (c) 2008 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: Implementation class for WMDRM DLA HTTP FW plugin resolver |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ecom/ecom.h> |
|
20 #include <badesca.h> |
|
21 #include <akniconutils.h> |
|
22 #include <akniconarray.h> |
|
23 #include <gulicon.h> |
|
24 #include <wmdrmdlatypes.h> |
|
25 #include <wmdrmdlahttpplugin.h> |
|
26 #include <wmdrmdlauinotifier.h> |
|
27 #include <wmdrmdla.mbg> |
|
28 #include "wmdrmdlahttpfwpluginresolver.h" |
|
29 #include "wmdrmdlaui.h" |
|
30 #include "wmdrmdlaplugincontainer.h" |
|
31 |
|
32 #define _LOGGING_FILE L"wmdrmdla.txt" |
|
33 #include "logfn.h" |
|
34 |
|
35 // CONSTANTS |
|
36 _LIT( KMbmFileName, "\\resource\\apps\\wmdrmdla.mbm" ); |
|
37 _LIT( KTab, "\t" ); |
|
38 |
|
39 const TInt KWmDrmDlaIndexMaxLength( 5 ); |
|
40 |
|
41 // ======== LOCAL FUNCTIONS ======== |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // PointerArrayResetDestroyAndClose |
|
45 // Template method used to push RPointerArrays to the cleanup stack. Takes |
|
46 // care of deleting all pointers in the array. |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 template <class T> |
|
50 LOCAL_C void PointerArrayResetDestroyAndClose( TAny* aPtr ) |
|
51 { |
|
52 (reinterpret_cast<RPointerArray<T>*>(aPtr))->ResetAndDestroy(); |
|
53 (reinterpret_cast<RPointerArray<T>*>(aPtr))->Close(); |
|
54 } |
|
55 |
|
56 // ======== MEMBER FUNCTIONS ======== |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // WmDrmDlaHttpFwPluginResolver::ResolveHttpPluginL |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 void WmDrmDlaHttpFwPluginResolver::ResolveHttpPluginL( |
|
63 const RFile& aFile, |
|
64 CWmDrmDlaHttpPluginIf*& aHttpPlugin, |
|
65 CWmDrmDlaUiNotifier*& aUiNotifier ) |
|
66 { |
|
67 TInt err( KErrNone ); |
|
68 |
|
69 LOGFNR( "WmDrmDlaHttpFwPluginResolver::ResolveHttpPluginL", err ); |
|
70 |
|
71 //Array where all supported plugins are gathered |
|
72 RPointerArray<CWmDrmDlaPluginContainer> supportedPluginArray; |
|
73 CleanupStack::PushL( |
|
74 TCleanupItem( |
|
75 PointerArrayResetDestroyAndClose<CWmDrmDlaPluginContainer>, |
|
76 &supportedPluginArray ) ); |
|
77 |
|
78 //Array where all http plugin implementation infos are gathered |
|
79 RImplInfoPtrArray implArray; |
|
80 CleanupStack::PushL( |
|
81 TCleanupItem( |
|
82 PointerArrayResetDestroyAndClose<CImplementationInformation>, |
|
83 &implArray ) ); |
|
84 REComSession::ListImplementationsL( KWmDrmDlaHttpPluginIfUid, implArray ); |
|
85 |
|
86 //Lets go through all implementation infos and find out what http plugins |
|
87 //support this content |
|
88 for ( TInt i( 0 ); i < implArray.Count(); ++i ) |
|
89 { |
|
90 //Only plugins with NOKIA vendor ID are currently allowed |
|
91 if ( implArray[i]->VendorId() == VID_DEFAULT ) |
|
92 { |
|
93 CWmDrmDlaUiNotifier* uiNotifier( NULL ); |
|
94 CWmDrmDlaHttpPluginIf* httpPlugin( NULL ); |
|
95 //Try to initialize http plugin |
|
96 TRAP( err, httpPlugin = |
|
97 CWmDrmDlaHttpPluginIf::NewL( |
|
98 implArray[i]->ImplementationUid() ) ); |
|
99 if ( !err ) |
|
100 { |
|
101 CleanupStack::PushL( httpPlugin ); |
|
102 TBool supported( EFalse ); |
|
103 //Check if current http plugin supports content |
|
104 TRAP( err, supported = |
|
105 httpPlugin->SupportedFileL( aFile, uiNotifier ) ) |
|
106 CleanupStack::PushL( uiNotifier ); |
|
107 //If current http plugin supports content, then |
|
108 //add implementation index, http plugin and ui notifier to |
|
109 //plugin container. |
|
110 //Otherwise delete current http plugin and ui notifier. |
|
111 if ( !err && supported ) |
|
112 { |
|
113 CWmDrmDlaPluginContainer* container( |
|
114 CWmDrmDlaPluginContainer::NewL() ); |
|
115 container->SetIndex( i ); |
|
116 container->SetHttpPlugin( httpPlugin ); |
|
117 container->SetUiNotifier( uiNotifier ); |
|
118 CleanupStack::Pop( 2, httpPlugin ); //uiNotifier, httpPlugin |
|
119 CleanupStack::PushL( container ); |
|
120 supportedPluginArray.AppendL( container ); |
|
121 CleanupStack::Pop( container ); |
|
122 } |
|
123 else |
|
124 { |
|
125 CleanupStack::PopAndDestroy( 2, httpPlugin ); //uiNotifier, httpPlugin |
|
126 } |
|
127 } |
|
128 } |
|
129 } |
|
130 |
|
131 //Select the plugin to be used for license acquisition |
|
132 SelectPluginL( supportedPluginArray, implArray, aHttpPlugin, aUiNotifier ); |
|
133 CleanupStack::PopAndDestroy( 2, &supportedPluginArray ); //implArray, supportedPluginArray |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // WmDrmDlaHttpFwPluginResolver::ResolveHttpPluginL |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 void WmDrmDlaHttpFwPluginResolver::ResolveHttpPluginL( |
|
141 const TDesC8& aDrmHeader, |
|
142 CWmDrmDlaHttpPluginIf*& aHttpPlugin, |
|
143 CWmDrmDlaUiNotifier*& aUiNotifier ) |
|
144 { |
|
145 TInt err( KErrNone ); |
|
146 |
|
147 LOGFNR( "WmDrmDlaHttpFwPluginResolver::ResolveHttpPluginL", err ); |
|
148 |
|
149 //Array where all supported plugins are gathered |
|
150 RPointerArray<CWmDrmDlaPluginContainer> supportedPluginArray; |
|
151 CleanupStack::PushL( |
|
152 TCleanupItem( |
|
153 PointerArrayResetDestroyAndClose<CWmDrmDlaPluginContainer>, |
|
154 &supportedPluginArray ) ); |
|
155 |
|
156 //Array where all http plugin implementation infos are gathered |
|
157 RImplInfoPtrArray implArray; |
|
158 CleanupStack::PushL( |
|
159 TCleanupItem( |
|
160 PointerArrayResetDestroyAndClose<CImplementationInformation>, |
|
161 &implArray ) ); |
|
162 REComSession::ListImplementationsL( KWmDrmDlaHttpPluginIfUid, implArray ); |
|
163 |
|
164 //Lets go through all implementation infos and find out what http plugins |
|
165 //support this content |
|
166 for ( TInt i( 0 ); i < implArray.Count(); ++i ) |
|
167 { |
|
168 //Only plugins with NOKIA vendor ID are currently allowed |
|
169 if ( implArray[i]->VendorId() == VID_DEFAULT ) |
|
170 { |
|
171 CWmDrmDlaUiNotifier* uiNotifier( NULL ); |
|
172 CWmDrmDlaHttpPluginIf* httpPlugin( NULL ); |
|
173 //Try to initialize http plugin |
|
174 TRAP( err, httpPlugin = |
|
175 CWmDrmDlaHttpPluginIf::NewL( |
|
176 implArray[i]->ImplementationUid() ) ); |
|
177 if ( !err ) |
|
178 { |
|
179 CleanupStack::PushL( httpPlugin ); |
|
180 TBool supported( EFalse ); |
|
181 //Check if current http plugin supports content |
|
182 TRAP( err, supported = |
|
183 httpPlugin->SupportedDrmHeaderL( aDrmHeader, uiNotifier ) ) |
|
184 CleanupStack::PushL( uiNotifier ); |
|
185 //If current http plugin supports content, then |
|
186 //add implementation index, http plugin and ui notifier to |
|
187 //plugin container. |
|
188 //Otherwise delete current http plugin and ui notifier. |
|
189 if ( !err && supported ) |
|
190 { |
|
191 CWmDrmDlaPluginContainer* container( |
|
192 CWmDrmDlaPluginContainer::NewL() ); |
|
193 container->SetIndex( i ); |
|
194 container->SetHttpPlugin( httpPlugin ); |
|
195 container->SetUiNotifier( uiNotifier ); |
|
196 CleanupStack::Pop( 2, httpPlugin ); //uiNotifier, httpPlugin |
|
197 CleanupStack::PushL( container ); |
|
198 supportedPluginArray.AppendL( container ); |
|
199 CleanupStack::Pop( container ); |
|
200 } |
|
201 else |
|
202 { |
|
203 CleanupStack::PopAndDestroy( 2, httpPlugin ); //uiNotifier, httpPlugin |
|
204 } |
|
205 } |
|
206 } |
|
207 } |
|
208 |
|
209 //Select the plugin to be used for license acquisition |
|
210 SelectPluginL( supportedPluginArray, implArray, aHttpPlugin, aUiNotifier ); |
|
211 CleanupStack::PopAndDestroy( 2, &supportedPluginArray ); //implArray, supportedPluginArray |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // WmDrmDlaHttpFwPluginResolver::::ResolveHttpPluginWithCertificateL |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void WmDrmDlaHttpFwPluginResolver::ResolveHttpPluginWithCertificateL( |
|
219 const TDesC8& aCertificate, |
|
220 CWmDrmDlaHttpPluginIf*& aHttpPlugin, |
|
221 CWmDrmDlaUiNotifier*& aUiNotifier ) |
|
222 { |
|
223 TInt err( KErrNone ); |
|
224 |
|
225 LOGFNR( "WmDrmDlaHttpFwPluginResolver::ResolveHttpPluginL", err ); |
|
226 |
|
227 //Array where all supported plugins are gathered |
|
228 RPointerArray<CWmDrmDlaPluginContainer> supportedPluginArray; |
|
229 CleanupStack::PushL( |
|
230 TCleanupItem( |
|
231 PointerArrayResetDestroyAndClose<CWmDrmDlaPluginContainer>, |
|
232 &supportedPluginArray ) ); |
|
233 |
|
234 //Array where all http plugin implementation infos are gathered |
|
235 RImplInfoPtrArray implArray; |
|
236 CleanupStack::PushL( |
|
237 TCleanupItem( |
|
238 PointerArrayResetDestroyAndClose<CImplementationInformation>, |
|
239 &implArray ) ); |
|
240 REComSession::ListImplementationsL( KWmDrmDlaHttpPluginIfUid, implArray ); |
|
241 |
|
242 //Lets go through all implementation infos and find out what http plugins |
|
243 //support this content |
|
244 for ( TInt i( 0 ); i < implArray.Count(); ++i ) |
|
245 { |
|
246 //Only plugins with NOKIA vendor ID are currently allowed |
|
247 if ( implArray[i]->VendorId() == VID_DEFAULT ) |
|
248 { |
|
249 CWmDrmDlaUiNotifier* uiNotifier( NULL ); |
|
250 CWmDrmDlaHttpPluginIf* httpPlugin( NULL ); |
|
251 //Try to initialize http plugin |
|
252 TRAP( err, httpPlugin = |
|
253 CWmDrmDlaHttpPluginIf::NewL( |
|
254 implArray[i]->ImplementationUid() ) ); |
|
255 if ( !err ) |
|
256 { |
|
257 CleanupStack::PushL( httpPlugin ); |
|
258 TBool supported( EFalse ); |
|
259 //Check if current http plugin supports content |
|
260 TRAP( err, supported = |
|
261 httpPlugin->SupportedMeteringCertificateL( aCertificate, |
|
262 uiNotifier ) ) |
|
263 CleanupStack::PushL( uiNotifier ); |
|
264 //If current http plugin supports content, then |
|
265 //add implementation index, http plugin and ui notifier to |
|
266 //plugin container. |
|
267 //Otherwise delete current http plugin and ui notifier. |
|
268 if ( !err && supported ) |
|
269 { |
|
270 CWmDrmDlaPluginContainer* container( |
|
271 CWmDrmDlaPluginContainer::NewL() ); |
|
272 container->SetIndex( i ); |
|
273 container->SetHttpPlugin( httpPlugin ); |
|
274 container->SetUiNotifier( uiNotifier ); |
|
275 CleanupStack::Pop( 2, httpPlugin ); //uiNotifier, httpPlugin |
|
276 CleanupStack::PushL( container ); |
|
277 supportedPluginArray.AppendL( container ); |
|
278 CleanupStack::Pop( container ); |
|
279 } |
|
280 else |
|
281 { |
|
282 CleanupStack::PopAndDestroy( 2, httpPlugin ); //uiNotifier, httpPlugin |
|
283 } |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 //Select the plugin to be used for metering |
|
289 SelectPluginL( supportedPluginArray, implArray, aHttpPlugin, aUiNotifier ); |
|
290 CleanupStack::PopAndDestroy( 2, &supportedPluginArray ); //implArray, supportedPluginArray |
|
291 } |
|
292 |
|
293 // ---------------------------------------------------------------------------- |
|
294 // WmDrmDlaHttpFwPluginResolver::SelectPluginL |
|
295 // ---------------------------------------------------------------------------- |
|
296 // |
|
297 void WmDrmDlaHttpFwPluginResolver::SelectPluginL( |
|
298 RPointerArray<CWmDrmDlaPluginContainer>& aSupportedPluginArray, |
|
299 RImplInfoPtrArray& aImplArray, |
|
300 CWmDrmDlaHttpPluginIf*& aHttpPlugin, |
|
301 CWmDrmDlaUiNotifier*& aUiNotifier ) |
|
302 { |
|
303 LOGFN( "WmDrmDlaHttpFwPluginResolver::SelectPluginL" ); |
|
304 |
|
305 //Find out how many plugins support this content |
|
306 TInt supportedCount( aSupportedPluginArray.Count() ); |
|
307 LOG2( "supportedCount: %d", supportedCount ); |
|
308 //If more than one plugin supports the content, then query |
|
309 //user to select one to be used |
|
310 if ( supportedCount > 1 ) |
|
311 { |
|
312 CWmDrmDlaUi* ui( CWmDrmDlaUi::NewLC() ); |
|
313 |
|
314 CAknIconArray* listIcons = new (ELeave) CAknIconArray( 2 ); |
|
315 CleanupStack::PushL( listIcons ); |
|
316 |
|
317 //Create default icon to be used with plugins that don't |
|
318 //have own icon. Default icon index is always 0. |
|
319 DefaultIconL( listIcons ); |
|
320 |
|
321 CPtrC16Array* listItems = new (ELeave) CPtrC16Array( 2 ); |
|
322 CleanupStack::PushL( listItems ); |
|
323 |
|
324 //Go through supported plugins, try to get their display name |
|
325 //and icon. If plugin doesn't have icon, use default one. |
|
326 for ( TInt i( 0 ); i < supportedCount; ++i ) |
|
327 { |
|
328 TInt index( aSupportedPluginArray[i]->Index() ); |
|
329 TPtrC displayName( aImplArray[index]->DisplayName() ); |
|
330 HBufC* listItem( HBufC::NewLC( displayName.Length() + |
|
331 KWmDrmDlaIndexMaxLength ) ); |
|
332 TPtr listItemPtr( listItem->Des() ); |
|
333 CGulIcon* pluginIcon( aSupportedPluginArray[ i ]-> |
|
334 HttpPlugin()->ServiceIcon() ); |
|
335 if ( pluginIcon ) |
|
336 { |
|
337 CleanupStack::PushL( pluginIcon ); |
|
338 listIcons->AppendL( pluginIcon ); |
|
339 CleanupStack::Pop( pluginIcon ); |
|
340 listItemPtr.AppendNum( listIcons->Count() - 1 ); |
|
341 } |
|
342 else |
|
343 { |
|
344 listItemPtr.AppendNum( 0 ); |
|
345 } |
|
346 listItemPtr.Append( KTab ); |
|
347 listItemPtr.Append( displayName ); |
|
348 listItems->AppendL( listItemPtr ); |
|
349 CleanupStack::Pop( listItem ); |
|
350 } |
|
351 //listItems and listItems ownership is transferred to ui |
|
352 CleanupStack::Pop( 2, listIcons ); //listItems, listIcons |
|
353 //Query user to make a selection. |
|
354 //Take user selected plugin to use or leave, if user cancels query. |
|
355 TInt selection( ui->ShowListQueryL( listItems, listIcons ) ); |
|
356 LOG2( "selection: %d", selection ); |
|
357 if ( selection >= 0 ) |
|
358 { |
|
359 aSupportedPluginArray[selection]->GetHttpPlugin( aHttpPlugin ); |
|
360 aSupportedPluginArray[selection]->GetUiNotifier( aUiNotifier ); |
|
361 } |
|
362 else |
|
363 { |
|
364 User::Leave( KErrNotFound ); |
|
365 } |
|
366 CleanupStack::PopAndDestroy( ui ); |
|
367 } |
|
368 //Only one supporting http plugin |
|
369 else if ( supportedCount == 1 ) |
|
370 { |
|
371 aSupportedPluginArray[0]->GetHttpPlugin( aHttpPlugin ); |
|
372 aSupportedPluginArray[0]->GetUiNotifier( aUiNotifier ); |
|
373 } |
|
374 //No supporting http plugins |
|
375 else |
|
376 { |
|
377 User::Leave( KErrNotFound ); |
|
378 } |
|
379 } |
|
380 |
|
381 // ---------------------------------------------------------------------------- |
|
382 // WmDrmDlaHttpFwPluginResolver::DefaultIconL |
|
383 // ---------------------------------------------------------------------------- |
|
384 // |
|
385 void WmDrmDlaHttpFwPluginResolver::DefaultIconL( |
|
386 CAknIconArray*& aIconArray ) |
|
387 { |
|
388 LOGFN( "WmDrmDlaHttpFwPluginResolver::DefaultIconL" ); |
|
389 CFbsBitmap* bitmap( NULL ); |
|
390 CFbsBitmap* bitmapMask( NULL ); |
|
391 AknIconUtils::CreateIconLC( bitmap, bitmapMask, KMbmFileName, |
|
392 EMbmWmdrmdlaQgn_prop_drm_valid_large, |
|
393 EMbmWmdrmdlaQgn_prop_drm_valid_large_mask ); |
|
394 CGulIcon* defaultIcon( CGulIcon::NewL( bitmap, bitmapMask ) ); |
|
395 CleanupStack::Pop( 2 ); // bitmapMask, bitmap. Icon has now ownership |
|
396 CleanupStack::PushL( defaultIcon ); |
|
397 aIconArray->AppendL( defaultIcon ); |
|
398 CleanupStack::Pop( defaultIcon ); |
|
399 } |