|
1 /* |
|
2 * Copyright (c) 2002-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: Crypto Token Security Dialog Notifier |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CTSecurityDialogNotifier.h" |
|
22 #include "CTSecurityDialogsAO.h" |
|
23 #include <eikenv.h> |
|
24 #include <coemain.h> |
|
25 #include <bautils.h> |
|
26 #include <StringLoader.h> |
|
27 #include <data_caging_path_literals.hrh> |
|
28 |
|
29 |
|
30 |
|
31 // CONSTANTS |
|
32 _LIT(KCTSecDlgDiskAndFile, "z:CTSecDlgs.rsc"); |
|
33 _LIT(KCTCertManUiResDiskAndFile, "z:CertManUi.rsc"); |
|
34 |
|
35 |
|
36 // ============================= LOCAL FUNCTIONS =============================== |
|
37 |
|
38 GLDEF_C void Panic(TInt aPanicCode) |
|
39 { |
|
40 _LIT(KComponentName, "CTSecNotifier"); |
|
41 User::Panic(KComponentName, aPanicCode); |
|
42 } |
|
43 |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CCTSecurityDialogNotifier::CCTSecurityDialogNotifier |
|
49 // C++ default constructor can NOT contain any code, that |
|
50 // might leave. |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CCTSecurityDialogNotifier::CCTSecurityDialogNotifier(): |
|
54 iSaveReceipt(EFalse) |
|
55 { |
|
56 WIMSECURITYDIALOGS_CREATE |
|
57 WIMSECURITYDIALOGS_WRITE_TIMESTAMP( "CCTSecurityDialogNotifier::CCTSecurityDialogNotifier()" ); |
|
58 iEikEnv = CEikonEnv::Static(); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CCTSecurityDialogNotifier::~CCTSecurityDialogNotifier() |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CCTSecurityDialogNotifier::~CCTSecurityDialogNotifier() |
|
66 { |
|
67 WIMSECURITYDIALOGS_DELETE |
|
68 Cancel(); |
|
69 if ( iResourceFileOffset ) |
|
70 { |
|
71 iEikEnv->DeleteResourceFile( iResourceFileOffset ); |
|
72 } |
|
73 if ( iResourceFileOffset2 ) |
|
74 { |
|
75 iEikEnv->DeleteResourceFile( iResourceFileOffset2 ); |
|
76 } |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CCTSecurityDialogNotifier::NewL() |
|
81 // Two-phased constructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CCTSecurityDialogNotifier* CCTSecurityDialogNotifier::NewL() |
|
85 { |
|
86 CCTSecurityDialogNotifier* self = new (ELeave) CCTSecurityDialogNotifier; |
|
87 CleanupStack::PushL( self ); |
|
88 self->ConstructL(); |
|
89 CleanupStack::Pop(); // self |
|
90 return self; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CCTSecurityDialogNotifier::ConstructL() |
|
95 // Symbian 2nd phase constructor can leave. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void CCTSecurityDialogNotifier::ConstructL() |
|
99 { |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CCTSecurityDialogNotifier::Release() |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CCTSecurityDialogNotifier::Release() |
|
107 { |
|
108 WIMSECURITYDIALOGS_WRITE_TIMESTAMP( "CCTSecurityDialogNotifier::Release" ); |
|
109 delete this; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CCTSecurityDialogNotifier::RegisterL() |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 CCTSecurityDialogNotifier::TNotifierInfo CCTSecurityDialogNotifier::RegisterL() |
|
117 { |
|
118 // Resource file loading |
|
119 RFs& fs = iEikEnv->FsSession(); |
|
120 |
|
121 TFileName fileName; |
|
122 |
|
123 TParse parse; |
|
124 parse.Set(KCTSecDlgDiskAndFile, &KDC_RESOURCE_FILES_DIR, NULL); |
|
125 |
|
126 fileName = parse.FullName(); |
|
127 |
|
128 BaflUtils::NearestLanguageFile( fs, fileName ); |
|
129 iResourceFileOffset = iEikEnv->AddResourceFileL( fileName ); |
|
130 |
|
131 parse.Set(KCTCertManUiResDiskAndFile, &KDC_RESOURCE_FILES_DIR, NULL); |
|
132 fileName = parse.FullName(); |
|
133 BaflUtils::NearestLanguageFile( fs, fileName ); |
|
134 iResourceFileOffset2 = iEikEnv->AddResourceFileL( fileName ); |
|
135 |
|
136 return Info(); |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CCTSecurityDialogNotifier::Info() |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 CCTSecurityDialogNotifier::TNotifierInfo CCTSecurityDialogNotifier::Info() const |
|
144 { |
|
145 TNotifierInfo info; |
|
146 info.iUid = KUidSecurityDialogNotifier; |
|
147 info.iChannel = KUidSecurityDialogNotifier; |
|
148 info.iPriority = ENotifierPriorityAbsolute; |
|
149 return info; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CCTSecurityDialogNotifier::StartL() |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CCTSecurityDialogNotifier::StartL( const TDesC8& aBuffer, TInt aReplySlot, |
|
157 const RMessagePtr2& aMessage ) |
|
158 { |
|
159 WIMSECURITYDIALOGS_WRITE( "CCTSecurityDialogNotifier::StartL" ); |
|
160 |
|
161 TRAPD( err, DoStartL( aBuffer, aReplySlot, aMessage ) ); |
|
162 if( err ) |
|
163 { |
|
164 if( !iSecurityDialogAODeleted ) |
|
165 { |
|
166 delete iSecurityDialogAO; |
|
167 iSecurityDialogAO = NULL; |
|
168 } |
|
169 if( !aMessage.IsNull() ) |
|
170 { |
|
171 aMessage.Complete( err ); |
|
172 } |
|
173 } |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CCTSecurityDialogNotifier::DoStartL() |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CCTSecurityDialogNotifier::DoStartL( const TDesC8& aBuffer, TInt aReplySlot, |
|
181 const RMessagePtr2& aMessage ) |
|
182 { |
|
183 // CCTSecurityDialogsAO sets the boolean iSecurityDialogAODeleted when it is |
|
184 // constructed and resets it when it is destructed, so iSecurityDialogAODeleted |
|
185 // tells whether the iSecurityDialogAO pointer is valid or not. |
|
186 iSecurityDialogAO = CCTSecurityDialogsAO::NewL( this, iSecurityDialogAODeleted ); |
|
187 |
|
188 iSecurityDialogAO->StartLD( aBuffer, aReplySlot, aMessage ); |
|
189 // StartLD() deletes the iSecurityDialogAO object when it is ready processing the |
|
190 // request. This may take some time, as CCTSecurityDialogsAO is active object, so |
|
191 // iSecurityDialogAO object exists when the above StartLD() returns here. It will |
|
192 // be deleted later when the operation completes. Started operation can be cancelled |
|
193 // before it is completed by deleting the iSecurityDialogAO object. |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CCTSecurityDialogNotifier::StartL() |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 TPtrC8 CCTSecurityDialogNotifier::StartL(const TDesC8& /*aBuffer*/) |
|
201 { |
|
202 return KNullDesC8(); |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CCTSecurityDialogNotifier::Cancel() |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 void CCTSecurityDialogNotifier::Cancel() |
|
210 { |
|
211 WIMSECURITYDIALOGS_WRITE( "CCTSecurityDialogNotifier::Cancel" ); |
|
212 |
|
213 // If iSecurityDialogAO is not completed yet, we need to cancel it now. |
|
214 // We can simply delete iSecurityDialogAO to cancel pending actions. |
|
215 if( !iSecurityDialogAODeleted ) |
|
216 { |
|
217 delete iSecurityDialogAO; |
|
218 } |
|
219 iSecurityDialogAO = NULL; |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CCTSecurityDialogNotifier::UpdateL() |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 TPtrC8 CCTSecurityDialogNotifier::UpdateL(const TDesC8& /*aBuffer*/) |
|
227 { |
|
228 return KNullDesC8(); |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CCTSecurityDialogNotifier::LoadResourceStringLC() |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 HBufC* CCTSecurityDialogNotifier::LoadResourceStringLC( const TInt aType, const TDesC& aDynamicText, const TDesC& aDynamicText2 ) |
|
236 { |
|
237 if ( aDynamicText2.Length() ) |
|
238 { |
|
239 TDialogTypeItem item = GetDialogTypeItem( aType ); |
|
240 HBufC* stringWithDynamics = StringLoader::LoadL(item.iResourceIdentifier, iEikEnv); |
|
241 CleanupStack::PushL(stringWithDynamics); |
|
242 |
|
243 if ( aDynamicText.Length() && aDynamicText2.Length() ) |
|
244 { |
|
245 _LIT(dynamicTextIdentifier, "%0U"); |
|
246 |
|
247 if (stringWithDynamics->Find(dynamicTextIdentifier) != KErrNotFound) |
|
248 { |
|
249 CleanupStack::PopAndDestroy(stringWithDynamics); |
|
250 |
|
251 CDesCArrayFlat* strings = new (ELeave) CDesCArrayFlat(2); |
|
252 CleanupStack::PushL(strings); |
|
253 |
|
254 strings->AppendL( aDynamicText ); |
|
255 strings->AppendL( aDynamicText2 ); |
|
256 |
|
257 stringWithDynamics = |
|
258 StringLoader::LoadL(item.iResourceIdentifier, |
|
259 *strings, iEikEnv); |
|
260 |
|
261 CleanupStack::PopAndDestroy(strings); |
|
262 |
|
263 CleanupStack::PushL(stringWithDynamics); |
|
264 } |
|
265 else |
|
266 { |
|
267 HBufC* dynamicText = NULL; |
|
268 _LIT(dynamicTextIdentifier, "%U"); |
|
269 |
|
270 if (stringWithDynamics->Find(dynamicTextIdentifier) != KErrNotFound) |
|
271 { |
|
272 CleanupStack::PopAndDestroy(stringWithDynamics); // stringWithDynamics, it wasn't final |
|
273 TPtrC param; |
|
274 if (item.iDynamicResourceIdentifier) |
|
275 { |
|
276 dynamicText = StringLoader::LoadL( item.iDynamicResourceIdentifier, iEikEnv ); |
|
277 CleanupStack::PushL( dynamicText ); |
|
278 param.Set( dynamicText->Des() ); |
|
279 } |
|
280 else |
|
281 { |
|
282 param.Set( aDynamicText ); |
|
283 } |
|
284 stringWithDynamics = |
|
285 StringLoader::LoadL(item.iResourceIdentifier, |
|
286 param, iEikEnv); |
|
287 if (dynamicText) |
|
288 { |
|
289 CleanupStack::PopAndDestroy(dynamicText); |
|
290 } |
|
291 CleanupStack::PushL(stringWithDynamics); |
|
292 } |
|
293 else |
|
294 { |
|
295 } |
|
296 |
|
297 } |
|
298 } |
|
299 return stringWithDynamics; |
|
300 } |
|
301 else |
|
302 { |
|
303 TDialogTypeItem item = GetDialogTypeItem( aType ); |
|
304 HBufC* stringWithDynamics = StringLoader::LoadL(item.iResourceIdentifier, iEikEnv); |
|
305 CleanupStack::PushL(stringWithDynamics); |
|
306 HBufC* dynamicText = NULL; |
|
307 |
|
308 if (item.iDynamicResourceIdentifier || aDynamicText.Length()) |
|
309 { |
|
310 _LIT(dynamicTextIdentifier, "%U"); |
|
311 |
|
312 if (stringWithDynamics->Find(dynamicTextIdentifier) != KErrNotFound) |
|
313 { |
|
314 CleanupStack::PopAndDestroy(stringWithDynamics); // stringWithDynamics, it wasn't final |
|
315 TPtrC param; |
|
316 if (item.iDynamicResourceIdentifier) |
|
317 { |
|
318 dynamicText = StringLoader::LoadL( item.iDynamicResourceIdentifier, iEikEnv ); |
|
319 CleanupStack::PushL( dynamicText ); |
|
320 param.Set( dynamicText->Des() ); |
|
321 } |
|
322 else |
|
323 { |
|
324 param.Set( aDynamicText ); |
|
325 } |
|
326 stringWithDynamics = |
|
327 StringLoader::LoadL(item.iResourceIdentifier, |
|
328 param, iEikEnv); |
|
329 if (dynamicText) |
|
330 { |
|
331 CleanupStack::PopAndDestroy(dynamicText); |
|
332 } |
|
333 CleanupStack::PushL(stringWithDynamics); |
|
334 } |
|
335 else |
|
336 { |
|
337 } |
|
338 } |
|
339 |
|
340 return stringWithDynamics; |
|
341 } |
|
342 |
|
343 } |
|
344 |
|
345 |
|
346 // ----------------------------------------------------------------------------- |
|
347 // CCTSecurityDialogNotifier::GetDialogTypeItem() |
|
348 // ----------------------------------------------------------------------------- |
|
349 // |
|
350 TDialogTypeItem CCTSecurityDialogNotifier::GetDialogTypeItem(const TInt aType) |
|
351 { |
|
352 // If the code panics here, then there's a TDialogType without |
|
353 // any TDialogTypeItem-> Check KDialogTypeToResourceMapper, and add to the mapper! |
|
354 |
|
355 |
|
356 // Find the corresponding resource to aType. |
|
357 // Algorithm: Best guess : Let's take KDialogTypeToResourceMapper[aType] |
|
358 // if its iDialogType field matches with aType -> HIT, OK |
|
359 // if not, then browse through the whole resource mapper array. If found, ok, |
|
360 // but if not, we will have to panic, as it is a developer error (fatal). |
|
361 |
|
362 const TInt mapperCount = sizeof(KDialogTypeToResourceMapper) / sizeof(TDialogTypeItem); |
|
363 __ASSERT_ALWAYS(aType < mapperCount, Panic(KErrOverflow)); |
|
364 |
|
365 TDialogTypeItem item = KDialogTypeToResourceMapper[aType]; |
|
366 |
|
367 if (item.iDialogType != aType) |
|
368 { |
|
369 TBool found(EFalse); |
|
370 |
|
371 for (TInt i = 0; i < mapperCount; i++) |
|
372 { |
|
373 item = KDialogTypeToResourceMapper[i]; |
|
374 if (item.iDialogType == aType) |
|
375 { |
|
376 found = ETrue; |
|
377 break; |
|
378 } // if |
|
379 } // for |
|
380 __ASSERT_ALWAYS(found, Panic(KErrNotFound)); |
|
381 } // if |
|
382 return item; |
|
383 } |
|
384 |
|
385 |