webengine/device/src/DeviceLiwBinding.cpp
changeset 16 a359256acfc6
parent 0 dd21522fd290
child 17 c8a366e56285
equal deleted inserted replaced
13:10e98eab6f85 16:a359256acfc6
   107         User::LeaveIfError(widgetregistry.Disconnect());
   107         User::LeaveIfError(widgetregistry.Disconnect());
   108         CleanupStack::PopAndDestroy(); //widgetregistry
   108         CleanupStack::PopAndDestroy(); //widgetregistry
   109 
   109 
   110         // we need to keep main session allive, to keep sub session
   110         // we need to keep main session allive, to keep sub session
   111         m_secMgr = CRTSecManager::NewL();
   111         m_secMgr = CRTSecManager::NewL();
   112         
   112 
   113         CTrustInfo* trust = CTrustInfo::NewLC();
   113         CTrustInfo* trust = CTrustInfo::NewLC();
   114 
   114 
   115         // TODO: in future, to support blanket permission,
   115         // TODO: in future, to support blanket permission,
   116         // this function should be called at installation time.
   116         // this function should be called at installation time.
   117         // TInt32 exId = secMgr->RegisterScript( aPolicyId, *trust );
   117         // TInt32 exId = secMgr->RegisterScript( aPolicyId, *trust );
   121         m_scriptSession = m_secMgr->GetScriptSessionL( aPolicyId, *trust );
   121         m_scriptSession = m_secMgr->GetScriptSessionL( aPolicyId, *trust );
   122         if ( !m_scriptSession )
   122         if ( !m_scriptSession )
   123             {
   123             {
   124             User::Leave( KErrGeneral );
   124             User::Leave( KErrGeneral );
   125             }
   125             }
       
   126 #ifdef SECURITYMANAGER_PROMPT_ENHANCEMENT
       
   127 		m_scriptSession->SetPromptOption(RTPROMPTUI_PROVIDER);   //  This is for setting the new prompting method
       
   128 #endif
   126         CleanupStack::PopAndDestroy( trust );
   129         CleanupStack::PopAndDestroy( trust );
   127     }
   130     }
   128 
       
   129 
   131 
   130 // ----------------------------------------------------------------------------
   132 // ----------------------------------------------------------------------------
   131 // CDeviceLiwBinding::~CDeviceLiwBinding
   133 // CDeviceLiwBinding::~CDeviceLiwBinding
   132 // Default destructor
   134 // Default destructor
   133 //
   135 //
   139     m_serviceHandler->DetachL(*m_critArr);
   141     m_serviceHandler->DetachL(*m_critArr);
   140     m_critArr->ResetAndDestroy();
   142     m_critArr->ResetAndDestroy();
   141     delete m_critArr;
   143     delete m_critArr;
   142     delete m_serviceHandler;
   144     delete m_serviceHandler;
   143     delete m_scriptSession;
   145     delete m_scriptSession;
   144     delete m_secMgr; 
   146     delete m_secMgr;
   145     }
   147     }
   146 
   148 
   147 
   149 
   148 // ----------------------------------------------------------------------------
   150 // ----------------------------------------------------------------------------
   149 // CDeviceLiwBinding::LoadServiceProvider
   151 // CDeviceLiwBinding::LoadServiceProvider
   186                 }
   188                 }
   187 
   189 
   188             item->SetServiceClass( TUid::Uid( KLiwClassBase ) );
   190             item->SetServiceClass( TUid::Uid( KLiwClassBase ) );
   189             RCriteriaArray crit_arr;
   191             RCriteriaArray crit_arr;
   190             crit_arr.AppendL( item );
   192             crit_arr.AppendL( item );
   191             
   193 
   192             CleanupStack::Pop(item); // item
   194             CleanupStack::Pop(item); // item
   193 
   195 
   194             // "Attach" runtime to service
   196             // "Attach" runtime to service
   195             if ( m_scriptSession && m_serviceHandler )
   197             if ( m_scriptSession && m_serviceHandler )
   196                 {
   198                 {
   212                         load_err = m_serviceHandler->AttachL( crit_arr, *m_scriptSession );
   214                         load_err = m_serviceHandler->AttachL( crit_arr, *m_scriptSession );
   213                         break;
   215                         break;
   214                     case SAPIPROMPTLESS :
   216                     case SAPIPROMPTLESS :
   215                         load_err = m_serviceHandler->AttachL( crit_arr );
   217                         load_err = m_serviceHandler->AttachL( crit_arr );
   216                         break;
   218                         break;
   217                     case SAPIACCESSDENIED : 
   219                     case SAPIACCESSDENIED :
   218                         load_err = KLiwSecurityAccessCheckFailed;
   220                         load_err = KLiwSecurityAccessCheckFailed;
   219                         break;
   221                         break;
   220                     default :
   222                     default :
   221                         load_err = KLiwSecurityAccessCheckFailed;
   223                         load_err = KLiwSecurityAccessCheckFailed;
   222                         break;
   224                         break;
   223                     }
   225                     }
   224                 
   226 
   225                 User::LeaveIfError(widgetregistry.Disconnect());
   227                 User::LeaveIfError(widgetregistry.Disconnect());
   226                 CleanupStack::PopAndDestroy(); //widgetregistry
   228                 CleanupStack::PopAndDestroy(); //widgetregistry
   227                 // hard coded for now since the definition of TLiwLoadStatus is not exposed to common dir yet
   229                 // hard coded for now since the definition of TLiwLoadStatus is not exposed to common dir yet
   228                 if ( load_err == KLiwServiceLoadSuccess || load_err == KLiwServiceAlreadyLoaded )
   230                 if ( load_err == KLiwServiceLoadSuccess || load_err == KLiwServiceAlreadyLoaded )
   229                     {
   231                     {
   230                     error = KErrNone; // normalize the error
   232                     error = KErrNone; // normalize the error
   231                     m_critArr->AppendL( item );
   233                     m_critArr->AppendL( item );
   232                     }
   234                     }
   233                 else 
   235                 else
   234                     {
   236                     {
   235                     error = load_err; // pass on the TLiwLoadStatus
   237                     error = load_err; // pass on the TLiwLoadStatus
   236                     delete item;
   238                     delete item;
   237                     }
   239                     }
   238                 }
   240                 }
   479                 static_cast<DeviceLiwPeer*>( peer )->Interface()->ExecuteCmdL(
   481                 static_cast<DeviceLiwPeer*>( peer )->Interface()->ExecuteCmdL(
   480                                             *oper, *inps, *outps, cmdOption,
   482                                             *oper, *inps, *outps, cmdOption,
   481                                             callBack );
   483                                             callBack );
   482                 User::UnMarkCleanupStack(____t);
   484                 User::UnMarkCleanupStack(____t);
   483                 inps->Reset();
   485                 inps->Reset();
   484                 rval = LiwGenericParamList2JsArray( exec, outps );
   486                 rval = LiwGenericParamList2JsArray( exec, outps, ETrue );
   485                 outps->Reset();
   487                 outps->Reset();
   486                 CleanupStack::PopAndDestroy( oper ); // map
   488                 CleanupStack::PopAndDestroy( oper ); // map
   487                 CleanupStack::Pop();// outps
   489                 CleanupStack::Pop();// outps
   488                 CleanupStack::PopAndDestroy(  );// inps
   490                 CleanupStack::PopAndDestroy(  );// inps
   489                });
   491                });
   899             TLiwVariant v;
   901             TLiwVariant v;
   900             List jsList;
   902             List jsList;
   901             jsList.append( jsNumber( variant.AsMap()->Count() ) );
   903             jsList.append( jsNumber( variant.AsMap()->Count() ) );
   902             JSObject * rval = new DeviceLiwMap(exec->lexicalInterpreter()->builtinArray()->construct(
   904             JSObject * rval = new DeviceLiwMap(exec->lexicalInterpreter()->builtinArray()->construct(
   903                 exec, jsList ), variant.AsMap(), this);
   905                 exec, jsList ), variant.AsMap(), this);
   904 
   906             
       
   907             DevicePrivateBase* pMapData = (static_cast<DeviceLiwMap*> (rval))->getMapData();
       
   908             
   905             for ( TInt i = 0; i < variant.AsMap()->Count(); i++ )
   909             for ( TInt i = 0; i < variant.AsMap()->Count(); i++ )
   906                 {
   910                 {
   907                 TBuf8<KMaxKeySize> name;
   911                 TBuf8<KMaxKeySize> name;
   908                 TRAPD( error,
   912                 TRAPD( error,
   909                     {
   913                     {
   910                     if ( variant.AsMap()->AtL( i, name ) )
   914                     if ( variant.AsMap()->AtL( i, name ) )
   911                         {
   915                         {
   912                         variant.AsMap()->FindL( name, v );
   916                         variant.AsMap()->FindL( name, v );
       
   917                         JSValue* jsval = LiwVariant2JsVal( exec, v );
   913                         rval->put( exec,
   918                         rval->put( exec,
   914                                 Identifier( ( const char* ) name.PtrZ() ),
   919                                    Identifier( ( const char* ) name.PtrZ() ),
   915                                 LiwVariant2JsVal( exec, v ) );
   920                                    jsval );
       
   921                         if ( v.TypeId() == EVariantTypeIterable )
       
   922                             {
       
   923                             DeviceLiwIterable* itObj = static_cast<DeviceLiwIterable*> (jsval);
       
   924                             DevicePrivateBase* itData = itObj->getIterableData();
       
   925                             itData->SetParent( pMapData );
       
   926                             pMapData->AddChild( itData );
       
   927                             }                   
       
   928                         else if ( v.TypeId() == EVariantTypeMap )    
       
   929                             {
       
   930                             DeviceLiwMap* mapObj = static_cast<DeviceLiwMap*> (jsval);
       
   931                             DevicePrivateBase* mapData = mapObj->getMapData();
       
   932                             mapData->SetParent( pMapData ); 
       
   933                             pMapData->AddChild( mapData );
       
   934                             }
   916                         }
   935                         }
   917                     });
   936                     });
   918                 // No error processing
   937                 // No error processing
   919                 }
   938                 }
   920             v.Reset();
   939             v.Reset();
  1049 //
  1068 //
  1050 // ----------------------------------------------------------------------------
  1069 // ----------------------------------------------------------------------------
  1051 //
  1070 //
  1052 JSValue* CDeviceLiwBinding::LiwGenericParamList2JsArray(
  1071 JSValue* CDeviceLiwBinding::LiwGenericParamList2JsArray(
  1053     ExecState* exec,
  1072     ExecState* exec,
  1054     CLiwGenericParamList* aLiwList )
  1073     CLiwGenericParamList* aLiwList, TBool managed )
  1055     {
  1074     {
  1056     // the output param list should not be empty, if it is, return an undefined js obj.
  1075     // the output param list should not be empty, if it is, return an undefined js obj.
  1057     if ( aLiwList->Count() == 0 )
  1076     if ( aLiwList->Count() == 0 )
  1058         return jsUndefined();
  1077         return jsUndefined();
  1059 
  1078 
  1062     jsList.append( jsNumber( aLiwList->Count() ) );
  1081     jsList.append( jsNumber( aLiwList->Count() ) );
  1063 
  1082 
  1064     JSObject * rval = new DeviceLiwResult(exec->lexicalInterpreter()->builtinArray()->construct(
  1083     JSObject * rval = new DeviceLiwResult(exec->lexicalInterpreter()->builtinArray()->construct(
  1065                 exec, jsList ));
  1084                 exec, jsList ));
  1066 
  1085 
       
  1086     DevicePrivateBase* retData =(static_cast<DeviceLiwResult*> (rval))->getResultData();
       
  1087 
  1067     for ( TInt i = 0; i < aLiwList->Count(); i++ )
  1088     for ( TInt i = 0; i < aLiwList->Count(); i++ )
  1068         {
  1089         {
  1069         TBuf8<KMaxKeySize> name( (*aLiwList)[i].Name() );
  1090         TBuf8<KMaxKeySize> name( (*aLiwList)[i].Name() );
  1070         rval->put( exec, Identifier( (const char*) name.PtrZ() ),
  1091         JSValue* jsval = LiwVariant2JsVal( exec, (*aLiwList)[i].Value() );
  1071             LiwVariant2JsVal( exec, (*aLiwList)[i].Value() ) );  //??? should call AtL?
  1092         // connect DeviceLiwResult to DeviceLiwIterable  
       
  1093         if ( managed )
       
  1094             { 
       
  1095             if ( (*aLiwList)[i].Value().TypeId() == EVariantTypeIterable )
       
  1096                 {
       
  1097                 DeviceLiwIterable* itObj = static_cast<DeviceLiwIterable*> (jsval);
       
  1098                 DevicePrivateBase* itData = itObj->getIterableData();
       
  1099                 itData->SetParent( retData ); 
       
  1100                 retData->AddChild( itData );
       
  1101                 }
       
  1102             else if ( (*aLiwList)[i].Value().TypeId() == EVariantTypeMap )
       
  1103                 {
       
  1104                 DeviceLiwMap* mapObj = static_cast<DeviceLiwMap*> (jsval);
       
  1105                 DevicePrivateBase* mapData = mapObj->getMapData();
       
  1106                 mapData->SetParent( retData ); 
       
  1107                 retData->AddChild( mapData );
       
  1108                 }    
       
  1109             }
       
  1110         rval->put( exec, Identifier( (const char*) name.PtrZ() ), jsval);  //??? should call AtL?
  1072         }
  1111         }
  1073 
  1112 
  1074     return rval;
  1113     return rval;
  1075     }
  1114     }
  1076 
  1115 
  1082 // ----------------------------------------------------------------------------
  1121 // ----------------------------------------------------------------------------
  1083 //
  1122 //
  1084 void CDeviceLiwBinding::SetUid( const TUint& aValue)
  1123 void CDeviceLiwBinding::SetUid( const TUint& aValue)
  1085     {
  1124     {
  1086     m_Uid.iUid = aValue;
  1125     m_Uid.iUid = aValue;
  1087     }
  1126 #ifdef SECURITYMANAGER_PROMPT_ENHANCEMENT    
       
  1127     SetAppName();
       
  1128 #endif    
       
  1129     }
       
  1130 #ifdef SECURITYMANAGER_PROMPT_ENHANCEMENT
       
  1131 // ----------------------------------------------------------------------------
       
  1132 // CDeviceLiwBinding::SetAppName
       
  1133 // Sets the widget display name
       
  1134 //
       
  1135 // ----------------------------------------------------------------------------
       
  1136 //
       
  1137 void CDeviceLiwBinding::SetAppName()
       
  1138     {
       
  1139     RWidgetRegistryClientSession widgetregistry;
       
  1140     TRAP_IGNORE(
       
  1141     TInt ret = widgetregistry.Connect();
       
  1142     if ( ret == KErrNone || ret == KErrAlreadyExists )
       
  1143         {
       
  1144         CleanupClosePushL( widgetregistry );
       
  1145         }
       
  1146     else
       
  1147         {
       
  1148         User::Leave( ret );
       
  1149         }
       
  1150     
       
  1151     CWidgetPropertyValue* displayname = widgetregistry.GetWidgetPropertyValueL(m_Uid, EBundleDisplayName );
       
  1152     User::LeaveIfError(widgetregistry.Disconnect());
       
  1153     CleanupStack::PopAndDestroy(); //widgetregistry
       
  1154 
       
  1155     if ( displayname && displayname->iType == EWidgetPropTypeString )
       
  1156         {
       
  1157         m_scriptSession->SetApplicationNameL(*displayname);
       
  1158         }
       
  1159     );
       
  1160     }
       
  1161 #endif
  1088 
  1162 
  1089 // ----------------------------------------------------------------------------
  1163 // ----------------------------------------------------------------------------
  1090 // KJS::GetAsciiBufferL
  1164 // KJS::GetAsciiBufferL
  1091 // Convert the Unicode string to plain ASCII chars chopping of any higher bytes
  1165 // Convert the Unicode string to plain ASCII chars chopping of any higher bytes
  1092 //
  1166 //