webengine/widgetregistry/Server/src/WidgetEntry.cpp
branchRCL_3
changeset 35 1f3c3f2f5b0a
parent 26 cb62a4f66ebe
child 46 30342f40acbf
equal deleted inserted replaced
34:220a17280356 35:1f3c3f2f5b0a
    15 *
    15 *
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 #include "WidgetEntry.h"
    19 #include "WidgetEntry.h"
       
    20 #include "UidAllocator.h"
    20 #include <widgetregistryconstants.h>
    21 #include <widgetregistryconstants.h>
    21 #include <s32file.h>
    22 #include <s32file.h>
    22 #include <f32file.h>
    23 #include <f32file.h>
    23 #include <APGTASK.H>
    24 #include <APGTASK.H>
    24 //#include <widgetappdefs.rh>
    25 //#include <widgetappdefs.rh>
    52 _LIT( KXmlDataTypeBool, "bool" );
    53 _LIT( KXmlDataTypeBool, "bool" );
    53 _LIT( KXmlDataTypeInt, "int" );
    54 _LIT( KXmlDataTypeInt, "int" );
    54 _LIT( KXmlDataTypeString, "string" );
    55 _LIT( KXmlDataTypeString, "string" );
    55 _LIT( KXmlDataTypeUid, "uid" );
    56 _LIT( KXmlDataTypeUid, "uid" );
    56 
    57 
    57 static const TInt KWidgetPropertyListVersion32 = 1;
       
    58 static const TInt KWidgetPropertyListVersion71 = 3;
       
    59 // MODULE DATA STRUCTURES
    58 // MODULE DATA STRUCTURES
    60 
    59 
    61 // LOCAL FUNCTION PROTOTYPES
    60 // LOCAL FUNCTION PROTOTYPES
    62 
    61 
    63 // FORWARD DECLARATIONS
    62 // FORWARD DECLARATIONS
    91 // ============================================================================
    90 // ============================================================================
    92 //    
    91 //    
    93 CWidgetEntry* CWidgetEntry::NewL( RPointerArray<CWidgetPropertyValue>** aProps )
    92 CWidgetEntry* CWidgetEntry::NewL( RPointerArray<CWidgetPropertyValue>** aProps )
    94 {
    93 {
    95     CWidgetEntry* tmp = NewL();
    94     CWidgetEntry* tmp = NewL();
    96     for ( TInt i = 0; i < (*aProps)->Count(); i++ )
    95     TInt i = 0;
       
    96     for ( ; i < (*aProps)->Count(); i++ )
    97     {
    97     {
    98         CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
    98         CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
    99         tmp->iPropertyValues.AppendL( value );
    99         tmp->iPropertyValues.AppendL( value );
   100         (*tmp)[i].iType = (**aProps)[i]->iType;
   100         (*tmp)[i].iType = (**aProps)[i]->iType;
   101         (*tmp)[i].iValue = (**aProps)[i]->iValue; // shallow copy of strings
   101         (*tmp)[i].iValue = (**aProps)[i]->iValue; // shallow copy of strings
   102         (**aProps)[i]->iType = EWidgetPropTypeUnknown;
   102         (**aProps)[i]->iType = EWidgetPropTypeUnknown;
   103         delete (**aProps)[i];
   103         delete (**aProps)[i];
   104     }
   104     }
       
   105 
       
   106     // Pad out with unknown properties to reach the correct number
       
   107     for ( ; i < EWidgetPropertyIdCount ; i++ )
       
   108     {
       
   109         CWidgetPropertyValue* value = CWidgetPropertyValue::NewL();
       
   110         tmp->iPropertyValues.AppendL( value );
       
   111     }
       
   112     
   105     (*aProps)->Close();
   113     (*aProps)->Close();
   106     delete *aProps;
   114     delete *aProps;
   107     *aProps = NULL;
   115     *aProps = NULL;
   108     return tmp;
   116     return tmp;
   109 }
   117 }
   168     // For now, leave if version doesn't match compiled-in version,
   176     // For now, leave if version doesn't match compiled-in version,
   169     // FUTURE do something smarter
   177     // FUTURE do something smarter
   170     //WIDGETPROPERTYLISTVERSION is 1 in case of Tiger engine and 3 in case of Leopard engine. Therefore, modifying the check such that 
   178     //WIDGETPROPERTYLISTVERSION is 1 in case of Tiger engine and 3 in case of Leopard engine. Therefore, modifying the check such that 
   171     //when the Version id is 1 or 3, we do not treat the file as corrupt.
   179     //when the Version id is 1 or 3, we do not treat the file as corrupt.
   172     if ( ( EWidgetPropTypeUnknown == (*this)[EWidgetPropertyListVersion].iType )
   180     if ( ( EWidgetPropTypeUnknown == (*this)[EWidgetPropertyListVersion].iType )
   173          || ( (KWidgetPropertyListVersion32 != (*this)[EWidgetPropertyListVersion] ) && (KWidgetPropertyListVersion71 != (*this)[EWidgetPropertyListVersion] )) )
   181          || ( (KWidgetPropertyListVersion32 != (*this)[EWidgetPropertyListVersion] ) && 
       
   182               (KWidgetPropertyListVersion71 != (*this)[EWidgetPropertyListVersion] ) &&
       
   183               (KWidgetPropertyListVersion71CWRT != (*this)[EWidgetPropertyListVersion] ) ))
   174         {
   184         {
   175         User::Leave( KErrCorrupt );
   185         User::Leave( KErrCorrupt );
   176         }
   186         }
   177     // Read only until the ENokiaWidget for the 3.2 widgets 
   187         
   178     TInt propertyIdCount =  (*this)[EWidgetPropertyListVersion] == KWidgetPropertyListVersion32 ? ENokiaWidget+1 : EWidgetPropertyIdCount; 
   188     // Provide appropriate values for EProcessUid and EMimeType
       
   189     (*this)[EProcessUid] = KUidWidgetUi.iUid;
       
   190     
       
   191     HBufC* heapBuf = HBufC::NewLC(KWidgetMime().Length());
       
   192     TPtr ptr(heapBuf->Des());   
       
   193     ptr.Copy(KWidgetMime);  // 8-bit to 16-bit copy
       
   194     (*this)[EMimeType] = *heapBuf;
       
   195     CleanupStack::PopAndDestroy();
       
   196     
       
   197     // Read only until the ENokiaWidget for the 3.2 widgets, EPreInstalled for 7.1 widgets
       
   198     TInt propertyIdCount = 0;
       
   199     switch ((*this)[EWidgetPropertyListVersion]) {
       
   200     case KWidgetPropertyListVersion32:
       
   201         propertyIdCount = ENokiaWidget+1;
       
   202         // since we've filled in the EProcessUid and EMimeType we're
       
   203         // now at KWidgetPropertyListVersion71CWRT
       
   204         (*this)[EWidgetPropertyListVersion] = KWidgetPropertyListVersion71CWRT;
       
   205         break;
       
   206     case KWidgetPropertyListVersion71:
       
   207         propertyIdCount = EPreInstalled+1;
       
   208         // since we've filled in the EProcessUid and EMimeType we're
       
   209         // now at KWidgetPropertyListVersion71CWRT
       
   210         (*this)[EWidgetPropertyListVersion] = KWidgetPropertyListVersion71CWRT;
       
   211         break;
       
   212     case KWidgetPropertyListVersion71CWRT:
       
   213         propertyIdCount = EWidgetPropertyIdCount;
       
   214         break;
       
   215     }        
       
   216 
   179     // fill property values array
   217     // fill property values array
   180     for ( TInt i = 1; i < propertyIdCount; ++i )
   218     for ( TInt i = 1; i < propertyIdCount; ++i )
   181         {
   219         {
   182         (*this)[i].DeserializeL( aReadStream );
   220         (*this)[i].DeserializeL( aReadStream );
   183         }
   221         }
   216                 CWidgetPropertyValue* val = CWidgetPropertyValue::NewL();
   254                 CWidgetPropertyValue* val = CWidgetPropertyValue::NewL();
   217                 CleanupStack::PushL(val);
   255                 CleanupStack::PushL(val);
   218                 iPropertyValues.AppendL( val );
   256                 iPropertyValues.AppendL( val );
   219                 CleanupStack::Pop(); // val
   257                 CleanupStack::Pop(); // val
   220                 }
   258                 }
       
   259             // Internalization of the Xml is complete, cleanup the properties appropriately
       
   260             PropertyCleanupL();
   221             return;
   261             return;
   222             }
   262             }
   223         TPtrC8 propTag( n->name );
   263         TPtrC8 propTag( n->name );
   224         if ( 0 != propTag.Compare( KXmlPropTag() ) )
   264         if ( 0 != propTag.Compare( KXmlPropTag() ) )
   225             {
   265             {
   582         // in the registry are running under WidgetUI
   622         // in the registry are running under WidgetUI
   583         RWsSession wsSession;
   623         RWsSession wsSession;
   584         User::LeaveIfError( wsSession.Connect() );
   624         User::LeaveIfError( wsSession.Connect() );
   585         CleanupClosePushL( wsSession );
   625         CleanupClosePushL( wsSession );
   586         TApaTaskList taskList( wsSession );
   626         TApaTaskList taskList( wsSession );
   587         TApaTask task = taskList.FindApp( KUidWidgetUi );
   627 
       
   628         TUid uid;
       
   629 
       
   630         if ( EWidgetPropTypeUnknown == (*this)[EProcessUid].iType ) {
       
   631             uid = KUidWidgetUi;
       
   632         } else {
       
   633             uid = TUid::Uid( (*this)[EProcessUid] );
       
   634         }
       
   635 
       
   636         TApaTask task = taskList.FindApp( uid );
       
   637 
   588         if ( EFalse == task.Exists() )
   638         if ( EFalse == task.Exists() )
   589             {
   639             {
   590             // widget UI crashed, reset active
   640             // widget UI crashed, reset active
   591             iActive = 0;
   641             iActive = 0;
   592             }
   642             }
   616         {
   666         {
   617         return SAPIACCESSDENIED;
   667         return SAPIACCESSDENIED;
   618         }
   668         }
   619         
   669         
   620     }
   670     }
       
   671     
       
   672 // ============================================================================
       
   673 // CWidgetEntry::PropertyCleanupL()
       
   674 // Make adjustments to bring the property values up to the current
       
   675 // property list version
       
   676 //
       
   677 // @since 
       
   678 // ============================================================================
       
   679 //
       
   680 void CWidgetEntry::PropertyCleanupL()
       
   681 {
       
   682     TInt currentVersion = (*this)[EWidgetPropertyListVersion];
       
   683 
       
   684     while (currentVersion < WIDGETPROPERTYLISTVERSION) {
       
   685         switch (currentVersion) {
       
   686         case KWidgetPropertyListVersion32:
       
   687             // Go from PropertyListVersion32 to PropertyListVersion71
       
   688             // Adds EMiniViewEnable, EBlanketPermGranted, EPreInstalled
       
   689             // (all are optional, just update the version number now
       
   690             //  and they will be undefined when serialized/deserialized)
       
   691             currentVersion = KWidgetPropertyListVersion71;
       
   692             break;
       
   693         case KWidgetPropertyListVersion71:
       
   694             // Go from PropertlyListVersion71 to PropertyListVersion71CWRT
       
   695             // 1) add ProcessUid for WRT (wgz) widgets
       
   696             (*this)[EProcessUid] = KUidWidgetUi.iUid;
       
   697 
       
   698              // 2) add MIMEType
       
   699             HBufC* heapBuf = HBufC::NewLC(KWidgetMime().Length());
       
   700             TPtr ptr(heapBuf->Des());
       
   701             ptr.Copy(KWidgetMime);  // 8-bit to 16-bit copy
       
   702             (*this)[EMimeType] = *heapBuf;
       
   703             CleanupStack::PopAndDestroy();
       
   704 
       
   705             currentVersion = KWidgetPropertyListVersion71CWRT;
       
   706             break;
       
   707         default:
       
   708             // Trouble
       
   709             return;
       
   710         }
       
   711 
       
   712         (*this)[EWidgetPropertyListVersion] = currentVersion;
       
   713     }
       
   714 }
   621 
   715 
   622 //  End of File
   716 //  End of File