21 |
21 |
22 #include <f32file.h> |
22 #include <f32file.h> |
23 #include <bautils.h> |
23 #include <bautils.h> |
24 #include <e32cmn.h> |
24 #include <e32cmn.h> |
25 |
25 |
|
26 #include <libxml2_globals.h> |
|
27 #include <libc/stdlib.h> |
|
28 #include <libxml2_parser.h> |
|
29 #include <libxml2_tree.h> |
|
30 |
|
31 #include "Browser_platform_variant.hrh" |
|
32 |
|
33 #ifdef BRDO_SYMBIAN_LIBXML_FF |
|
34 #include <xmlengxestd.h> |
|
35 #endif |
|
36 |
26 #include "WidgetInstaller.h" |
37 #include "WidgetInstaller.h" |
27 #include "WidgetConfigHandler.h" // info.plist parser |
38 #include "WidgetConfigHandler.h" // info.plist parser |
28 #include "WidgetRegistrationManager.h" // interface to "shell" |
39 #include "WidgetRegistrationManager.h" // interface to "shell" |
29 #include "IconConverter.h" |
40 #include "IconConverter.h" |
|
41 #include "WidgetBackupRegistryXml.h" |
30 |
42 |
31 // CONSTANTS |
43 // CONSTANTS |
32 _LIT( KInfoPList,"Info.plist" ); |
44 _LIT( KInfoPList,"Info.plist" ); |
33 _LIT( KIconFile, "Icon.png" ); |
45 _LIT( KIconFile, "Icon.png" ); |
34 _LIT( KMBMExt, ".mbm"); |
46 _LIT( KMBMExt, ".mbm"); |
35 _LIT( KLprojExt, ".lproj" ); |
47 _LIT( KLprojExt, ".lproj" ); |
36 _LIT( KInfoPlistStrings, "InfoPlist.strings" ); |
48 _LIT( KInfoPlistStrings, "InfoPlist.strings" ); |
|
49 _LIT( KWidgetPropFile, "\\private\\10282822\\WidgetEntryStore.xml" ); |
|
50 |
|
51 // For parsing backedup registration file |
|
52 _LIT8( KWidgetRegistry, "widgetregistry" ); |
|
53 _LIT8( KEntry, "entry" ); |
|
54 _LIT8( KXmlPropTag, "prop" ); |
|
55 _LIT8( KXmlValTag, "val" ); |
|
56 _LIT8( KXmlTypeTag, "type" ); |
|
57 _LIT( KXmlDataTypeBool, "bool" ); |
|
58 _LIT( KXmlDataTypeInt, "int" ); |
|
59 _LIT( KXmlDataTypeString, "string" ); |
|
60 _LIT( KXmlDataTypeUid, "uid" ); |
37 |
61 |
38 // TODO MW has a hard dependency to APP domain. Not very good... |
62 // TODO MW has a hard dependency to APP domain. Not very good... |
39 // TODO Hard-coded UID. |
63 // TODO Hard-coded UID. |
40 _LIT( KWidgetAppDir, "\\private\\10282822\\" ); |
64 _LIT( KWidgetAppDir, "\\private\\10282822\\" ); |
41 _LIT( KBackSlash, "\\" ); |
65 _LIT( KBackSlash, "\\" ); |
248 CleanupStack::PopAndDestroy(); // entryList |
272 CleanupStack::PopAndDestroy(); // entryList |
249 } // end of if iRfs |
273 } // end of if iRfs |
250 |
274 |
251 return found; |
275 return found; |
252 } |
276 } |
|
277 |
|
278 // ============================================================================ |
|
279 // CWidgetInstaller::FixWidgetPropsL() |
|
280 // Handles preprocessing of widget properties |
|
281 // |
|
282 // @since 5.0 |
|
283 // ============================================================================ |
|
284 // |
|
285 void CWidgetInstaller::FixWidgetPropsL() |
|
286 { |
|
287 TInt backupBlanketPerm = -1; |
|
288 |
|
289 CWidgetBackupRegistryXml* aXmlProcessor = CWidgetBackupRegistryXml::NewL(); |
|
290 RPointerArray<CWidgetPropertyValue> backupPropertyValues; |
|
291 |
|
292 TInt i = 0; |
|
293 // empty values |
|
294 for ( ; i < EWidgetPropertyIdCount; ++i ) |
|
295 { |
|
296 CWidgetPropertyValue* value = CWidgetPropertyValue::NewL(); |
|
297 CleanupStack::PushL( value ); |
|
298 User::LeaveIfError( backupPropertyValues.Insert( value, i ) ); |
|
299 CleanupStack::Pop( value ); |
|
300 } |
|
301 |
|
302 // Algorithm |
|
303 // 1. Look for the entry |
|
304 // 2. Check if the EBundleIdentifier is what we are looking for |
|
305 // 3. If so, looking for the value of EBlanketPermGranted |
|
306 // 4. If exist, then we fix it |
|
307 // hardcode the filename first |
|
308 RFile file; |
|
309 TFileName propFile( KWidgetPropFile ); |
|
310 User::LeaveIfError( file.Open( iRfs, propFile, EFileRead )); |
|
311 CleanupClosePushL( file ); |
|
312 |
|
313 TInt size; |
|
314 User::LeaveIfError ( file.Size ( size )); |
|
315 HBufC8* buf = HBufC8::NewLC ( size ); |
|
316 TPtr8 bufPtr ( buf->Des() ); |
|
317 User::LeaveIfError( file.Read( bufPtr ) ); |
|
318 |
|
319 // initialize the parser and check compiled code matches lib version |
|
320 LIBXML_TEST_VERSION |
|
321 |
|
322 xmlDocPtr doc; |
|
323 doc = xmlReadMemory( (const char *)bufPtr.Ptr(), bufPtr.Length(), |
|
324 NULL, |
|
325 NULL, |
|
326 0); |
|
327 if ( !doc ) |
|
328 { |
|
329 User::Leave( KErrCorrupt ); |
|
330 } |
|
331 |
|
332 xmlNode* rootElement = xmlDocGetRootElement( doc ); |
|
333 TPtrC8 rootTag( rootElement->name ); |
|
334 if ( 0 != rootTag.Compare( KWidgetRegistry() ) ) |
|
335 { |
|
336 User::Leave( KErrCorrupt ); |
|
337 } |
|
338 |
|
339 for ( xmlNode* m = rootElement->children; |
|
340 m; |
|
341 m = m->next ) |
|
342 { |
|
343 if ( m->type == XML_ELEMENT_NODE ) |
|
344 { |
|
345 TPtrC8 element( m->name ); |
|
346 |
|
347 if ( 0 == element.Compare( KEntry() ) ) |
|
348 { |
|
349 backupBlanketPerm = -1; // reset this value for every entry |
|
350 if ( NULL == m->children ) |
|
351 { |
|
352 // malformed? should we require entry to have |
|
353 // some minimal info? |
|
354 continue; |
|
355 } |
|
356 |
|
357 // extract one entry |
|
358 xmlNode* n; |
|
359 n = m->children; |
|
360 for ( ; |
|
361 n; |
|
362 ) |
|
363 { |
|
364 while ( n && ( n->type != XML_ELEMENT_NODE )) |
|
365 { |
|
366 n = n->next; |
|
367 } |
|
368 if ( NULL == n ) |
|
369 { |
|
370 break; |
|
371 } |
|
372 |
|
373 TPtrC8 propTag( n->name ); |
|
374 if ( 0 != propTag.Compare( KXmlPropTag() ) ) |
|
375 { |
|
376 // unrecognized subtree? |
|
377 break; |
|
378 } |
|
379 // validate n->children != NULL and type XML_TEXT_NODE |
|
380 HBufC* name; |
|
381 aXmlProcessor->GetContentL( iRfs, doc, n->children, &name ); |
|
382 |
|
383 // get value array index (TWidgetPropertyId) for name |
|
384 TPtr namePtr( name->Des() ); |
|
385 TInt propId = |
|
386 aXmlProcessor->GetPropertyId( namePtr ); |
|
387 delete name; |
|
388 name = NULL; |
|
389 if ( EWidgetPropertyIdInvalid == propId ) |
|
390 { |
|
391 User::Leave( KErrNoMemory ); |
|
392 } |
|
393 |
|
394 n = n->children->next; // down to val |
|
395 if ( NULL == n ) |
|
396 { |
|
397 User::Leave( KErrCorrupt ); |
|
398 } |
|
399 TPtrC8 valTag( n->name ); |
|
400 if ( 0 != valTag.Compare( KXmlValTag() ) ) |
|
401 { |
|
402 User::Leave( KErrCorrupt ); |
|
403 } |
|
404 if (propId >= EWidgetPropertyIdCount) // unsupported property |
|
405 { |
|
406 HBufC* value = NULL; |
|
407 if (n->children) |
|
408 { |
|
409 aXmlProcessor->GetTextContentAsStringL( iRfs, doc, n->children, &value ); |
|
410 } |
|
411 else |
|
412 { |
|
413 value = KNullDesC().AllocL(); |
|
414 } |
|
415 |
|
416 n = (n->parent)->next; // up two and next sibling |
|
417 continue; |
|
418 } |
|
419 HBufC* value; |
|
420 aXmlProcessor->GetContentL( iRfs, doc, n->children, &value ); |
|
421 CleanupStack::PushL( value ); |
|
422 |
|
423 n = n->children->next; // down to type |
|
424 if ( NULL == n ) |
|
425 { |
|
426 User::Leave( KErrCorrupt ); |
|
427 } |
|
428 TPtrC8 typeTag( n->name ); |
|
429 if ( 0 != typeTag.Compare( KXmlTypeTag() ) ) |
|
430 { |
|
431 User::Leave( KErrCorrupt ); |
|
432 } |
|
433 // validate n->children != NULL and type XML_TEXT_NODE |
|
434 HBufC* type; |
|
435 aXmlProcessor->GetContentL( iRfs, doc, n->children, &type ); |
|
436 CleanupStack::PushL( type ); |
|
437 // |
|
438 // assume void/unknown is not put in XML format so anything |
|
439 // not recognized should be handled like other unrecognized |
|
440 // subtree |
|
441 TWidgetPropertyType typeEnum = EWidgetPropTypeUnknown; |
|
442 if ( 0 == type->Des().Compare( KXmlDataTypeBool() ) ) |
|
443 { |
|
444 typeEnum = EWidgetPropTypeBool; |
|
445 } |
|
446 else if ( 0 == type->Des().Compare( KXmlDataTypeInt() ) ) |
|
447 { |
|
448 typeEnum = EWidgetPropTypeInt; |
|
449 } |
|
450 else if ( 0 == type->Des().Compare( KXmlDataTypeString() ) ) |
|
451 { |
|
452 typeEnum = EWidgetPropTypeString; |
|
453 } |
|
454 else if ( 0 == type->Des().Compare( KXmlDataTypeUid() ) ) |
|
455 { |
|
456 typeEnum = EWidgetPropTypeUid; |
|
457 } |
|
458 CleanupStack::PopAndDestroy( type ); |
|
459 |
|
460 // set prop according to type |
|
461 switch ( typeEnum ) |
|
462 { |
|
463 case EWidgetPropTypeBool: |
|
464 if ( 0 == value->Des().Compare( _L("0") ) ) |
|
465 { |
|
466 *backupPropertyValues[propId] = 0; |
|
467 } |
|
468 else |
|
469 { |
|
470 *(backupPropertyValues[propId]) = 1; |
|
471 } |
|
472 break; |
|
473 |
|
474 case EWidgetPropTypeInt: |
|
475 TLex toInt( value->Des() ); |
|
476 TInt k; |
|
477 if ( KErrNone != toInt.Val( k ) ) |
|
478 { |
|
479 User::Leave( KErrCorrupt ); |
|
480 } |
|
481 if ( propId == EBlanketPermGranted ) |
|
482 backupBlanketPerm = k; |
|
483 break; |
|
484 |
|
485 case EWidgetPropTypeString: |
|
486 *(backupPropertyValues[propId]) = *value; |
|
487 break; |
|
488 |
|
489 case EWidgetPropTypeUid: |
|
490 { |
|
491 TLex toUid( value->Des() ); |
|
492 TInt u; |
|
493 if ( KErrNone != toUid.Val( u ) ) |
|
494 { |
|
495 User::Leave( KErrCorrupt ); |
|
496 } |
|
497 *(backupPropertyValues[propId]) = TUid::Uid( u ); |
|
498 } |
|
499 break; |
|
500 }; |
|
501 |
|
502 CleanupStack::Pop( value ); |
|
503 if ( EWidgetPropTypeString != typeEnum ) |
|
504 { |
|
505 delete value; |
|
506 } |
|
507 |
|
508 n = ((n->parent)->parent)->next; // up two and next sibling |
|
509 } |
|
510 // Compare to see if it's this widget |
|
511 if ( 0 == (iPropertyValues[EBundleIdentifier]->iValue.s)->Compare(*backupPropertyValues[EBundleIdentifier]->iValue.s) ) |
|
512 { |
|
513 if ( backupBlanketPerm != -1 ) |
|
514 { |
|
515 (*iPropertyValues[EBlanketPermGranted]) = backupBlanketPerm; |
|
516 } |
|
517 break; |
|
518 } |
|
519 } // if <entry> |
|
520 } // if n is element |
|
521 } // for |
|
522 |
|
523 |
|
524 TInt j = 0; |
|
525 for ( ; j < EWidgetPropertyIdCount; ++j ) |
|
526 { |
|
527 delete backupPropertyValues[j]; |
|
528 } |
|
529 backupPropertyValues.Close(); |
|
530 |
|
531 // cleanup |
|
532 xmlFreeDoc(doc); |
|
533 xmlCleanupParser(); |
|
534 |
|
535 #ifdef BRDO_SYMBIAN_LIBXML_FF |
|
536 XmlEngineCleanup(); |
|
537 #else |
|
538 xmlCleanupGlobalData(); |
|
539 #endif |
|
540 CleanupStack::PopAndDestroy( 2, &file ); // buf, file |
|
541 |
|
542 delete aXmlProcessor; |
|
543 } |
253 |
544 |
254 // ============================================================================ |
545 // ============================================================================ |
255 // CWidgetInstaller::PreprocessWidgetBundleL() |
546 // CWidgetInstaller::PreprocessWidgetBundleL() |
256 // Handles parsing and creating widget |
547 // Handles parsing and creating widget |
257 // Widget data are still in "\private\[WidgetBackupRestoreUid]\WidgetBURTemp\bundleID\ |
548 // Widget data are still in "\private\[WidgetBackupRestoreUid]\WidgetBURTemp\bundleID\ |