2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/input/tizen-wayland/autofill-manager-impl-ecore-wl.h>
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/integration-api/debug.h>
26 #include <dali/internal/adaptor/common/adaptor-impl.h>
27 #include <dali/internal/system/common/singleton-service-impl.h>
41 #if defined(DEBUG_ENABLED)
42 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_AUTOFILL");
46 const char* const SIGNAL_AUTHENTICATION_RECEIVED = "authenticationReceived";
47 const char* const SIGNAL_FILL_RESPONSE_RECEIVED = "fillResponseReceived";
48 const char* const SIGNAL_LIST_RECEIVED = "listReceived";
51 #ifdef CAPI_AUTOFILL_SUPPORT
53 // All methods in this range are Static function calls used by ecore 'c' style callback registration
54 static void ConnectionStatusChangedCallback( autofill_h autofillHandle, autofill_connection_status_e status, void *user_data )
56 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::ConnectionStatusChangedCallback mAutofillHandle : %p \n", autofillHandle );
60 case AUTOFILL_CONNECTION_STATUS_CONNECTED:
62 DALI_LOG_INFO( gLogFilter, Debug::General, "Autofill Connected.\n" );
65 case AUTOFILL_CONNECTION_STATUS_DISCONNECTED:
67 DALI_LOG_INFO( gLogFilter, Debug::General, "Autofill Disconnected.\n" );
70 case AUTOFILL_CONNECTION_STATUS_REJECTED:
72 DALI_LOG_INFO( gLogFilter, Debug::General, "Autofill Rejected.\n" );
83 // Callback to receive the authentication information.
84 static void AuthInfoCallback( autofill_h ah, autofill_auth_info_h authInfoHandle, void *data )
86 Dali::AutofillManager autofill = AutofillManager::Get();
87 Internal::Adaptor::AutofillManager& autofillImpl = Internal::Adaptor::GetImplementation( autofill );
88 Internal::Adaptor::AutofillManagerEcoreWl& autofillImplWl = static_cast<Internal::Adaptor::AutofillManagerEcoreWl&>( autofillImpl );
89 autofillImplWl.ReceiveAuthInfo( authInfoHandle, data );
92 // If there's an only one fill response group, then this callback is called.
93 static bool FillResponseItemCallback( autofill_fill_response_item_h itemHandle, void *userData )
95 Dali::AutofillManager autofill = AutofillManager::Get();
96 Internal::Adaptor::AutofillManager& autofillImpl = Internal::Adaptor::GetImplementation( autofill );
97 Internal::Adaptor::AutofillManagerEcoreWl& autofillImplWl = static_cast<Internal::Adaptor::AutofillManagerEcoreWl&>( autofillImpl );
98 autofillImplWl.FillGroupItem( itemHandle, userData ); // Implementation here
102 // If the fill response groups are multiple, then this callback is called.
103 static bool FillResponseMultipleItemCallback( autofill_fill_response_item_h itemHandle, void *userData )
105 Dali::AutofillManager autofill = AutofillManager::Get();
106 Internal::Adaptor::AutofillManager& autofillImpl = Internal::Adaptor::GetImplementation( autofill );
107 Internal::Adaptor::AutofillManagerEcoreWl& autofillImplWl = static_cast<Internal::Adaptor::AutofillManagerEcoreWl&>( autofillImpl );
108 autofillImplWl.FillMultipleGroupItem( itemHandle, userData ); // Implementation here
112 // This callback is called according to the number of pairs to fill out.
113 static bool FillResponseGroupCallback( autofill_fill_response_group_h groupHandle, void *userData )
115 int* count = static_cast<int*>(userData);
117 // According to the number of group count, Retrieves all fill response items of each fill response group.
120 autofill_fill_response_group_foreach_item( groupHandle, FillResponseItemCallback, NULL );
122 else if( *count > 1 )
124 autofill_fill_response_group_foreach_item( groupHandle, FillResponseMultipleItemCallback, groupHandle );
130 // Callback to receive autofill fill response.
131 static void FillResponseCallback( autofill_h autofillHandle, autofill_fill_response_h fillResponseHandle, void *data )
133 if( !fillResponseHandle )
135 DALI_LOG_ERROR("Fill response handle is empty. \n");
139 // Get fill response group count
141 autofill_fill_response_get_group_count( fillResponseHandle, &count );
142 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::FillResponseCallback group count : %d \n", count );
144 // Retrieves all groups of each fill response.
145 autofill_fill_response_foreach_group( fillResponseHandle, FillResponseGroupCallback, &count );
149 // Emits the signal to make a list of multiple data.
150 Dali::AutofillManager autofill = AutofillManager::Get();
151 autofill.ListEventSignal().Emit();
154 #endif // CAPI_AUTOFILL_SUPPORT
158 return Dali::AutofillManager::Get();
161 Dali::TypeRegistration typeRegistration( typeid(Dali::AutofillManager), typeid(Dali::BaseHandle), Create );
163 Dali::SignalConnectorType signalConnector1( typeRegistration, SIGNAL_AUTHENTICATION_RECEIVED, Dali::Internal::Adaptor::AutofillManagerEcoreWl::DoConnectSignal );
164 Dali::SignalConnectorType signalConnector2( typeRegistration, SIGNAL_FILL_RESPONSE_RECEIVED, Dali::Internal::Adaptor::AutofillManagerEcoreWl::DoConnectSignal );
165 Dali::SignalConnectorType signalConnector3( typeRegistration, SIGNAL_LIST_RECEIVED, Dali::Internal::Adaptor::AutofillManagerEcoreWl::DoConnectSignal );
167 } // unnamed namespace
171 Dali::AutofillManager AutofillManagerEcoreWl::Get()
173 Dali::AutofillManager autofill;
174 AutofillManagerEcoreWl *autofillPtr = NULL;
176 Dali::SingletonService service( SingletonService::Get() );
179 // Check whether the singleton is already created
180 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AutofillManager ) );
183 // If so, downcast the handle
184 autofillPtr = dynamic_cast< AutofillManagerEcoreWl* >( handle.GetObjectPtr() );
185 autofill = Dali::AutofillManager( autofillPtr );
187 else if( Adaptor::IsAvailable() )
189 // Create instance and register singleton only if the adaptor is available
190 autofillPtr = new AutofillManagerEcoreWl();
191 autofill = Dali::AutofillManager( autofillPtr );
192 service.Register( typeid( autofill ), autofill );
194 // Connect Autofill daemon at the first time
195 autofillPtr->CreateContext();
196 autofillPtr->ConnectCallbacks();
203 AutofillManagerEcoreWl::AutofillManagerEcoreWl()
205 mAuthenticationServiceName(""),
206 mAuthenticationServiceMessage(""),
207 mAuthenticationServiceImagePath(""),
209 mFillItemPresentationText(""),
211 mIsDataPresent( false ),
212 mIsAuthNeeded( false )
214 #ifdef CAPI_AUTOFILL_SUPPORT
215 mAutofillHandle = NULL;
216 #endif // CAPI_AUTOFILL_SUPPORT
219 AutofillManagerEcoreWl::~AutofillManagerEcoreWl()
224 void AutofillManagerEcoreWl::CreateContext()
226 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::CreateContext\n" );
228 #ifdef CAPI_AUTOFILL_SUPPORT
229 int ret = autofill_create( &mAutofillHandle );
230 if( ret != AUTOFILL_ERROR_NONE )
232 DALI_LOG_ERROR( "Failed to create autofill handle : %d \n", ret );
234 #endif // CAPI_AUTOFILL_SUPPORT
237 void AutofillManagerEcoreWl::DeleteContext()
239 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::DeleteContext\n" );
240 #ifdef CAPI_AUTOFILL_SUPPORT
241 if( mAutofillHandle )
243 // Unsets the callback to receive the authentication information.
244 autofill_auth_info_unset_received_cb( mAutofillHandle );
246 autofill_destroy( mAutofillHandle );
247 mAutofillHandle = NULL;
249 #endif // CAPI_AUTOFILL_SUPPORT
252 // Callbacks for connecting to autofill daemon.
253 void AutofillManagerEcoreWl::ConnectCallbacks()
255 #ifdef CAPI_AUTOFILL_SUPPORT
256 if( mAutofillHandle )
258 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::ConnectCallbacks\n" );
260 int ret = autofill_connect( mAutofillHandle, ConnectionStatusChangedCallback, NULL );
261 if( ret != AUTOFILL_ERROR_NONE )
263 DALI_LOG_ERROR( "Failed to connect : %d \n", ret );
266 // Sets the callback to receive the authentication information.
267 autofill_auth_info_set_received_cb( mAutofillHandle, AuthInfoCallback, NULL );
269 // Sets the callback to receive autofill fill response.
270 autofill_fill_response_set_received_cb( mAutofillHandle, FillResponseCallback, NULL );
272 #endif // CAPI_AUTOFILL_SUPPORT
276 /////////////////////////////////////////////// Autofill Callback implementation ///////////////////////////////////////////////
278 #ifdef CAPI_AUTOFILL_SUPPORT
280 autofill_h AutofillManagerEcoreWl::GetAutofillHandle()
282 return mAutofillHandle;
285 // Implementation to receive the authentication information.
286 void AutofillManagerEcoreWl::ReceiveAuthInfo( autofill_auth_info_h authInfoHandle, void *data )
288 bool autofillDataPresent = false;
289 bool authenticationNeeded = false;
290 char* serviceName = NULL;
291 char* serviceMessage = NULL;
292 char* serviceLogoImagePath = NULL;
293 char* groupId = NULL;
295 // Gets the authentication information which is set by Autofill Service framework.
296 autofill_auth_info_get_view_id( authInfoHandle, &groupId );
297 autofill_auth_info_get_autofill_data_present( authInfoHandle, &autofillDataPresent );
298 autofill_auth_info_get_authentication_needed( authInfoHandle, &authenticationNeeded );
300 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::ReceiveAuthInfo group id : %s, Is autofill data present ? : %s, Is authentication needed ? : %s \n",
301 groupId, autofillDataPresent ? "true" : "false", authenticationNeeded ? "true" : "false" );
303 for( std::vector<Dali::AutofillGroup>::iterator iter = mAutofillGroupList.begin(), endIter = mAutofillGroupList.end(); iter != endIter; ++iter )
305 const std::string id = ( *iter ).GetId();
306 if( id.compare( groupId ) == 0 )
308 mAutofillGroup = ( *iter );
312 // Sets the 'autofill data present' and 'authentication needed' attributes in autofill authentication information.
313 mIsDataPresent = autofillDataPresent;
314 mIsAuthNeeded = authenticationNeeded;
321 if( !autofillDataPresent )
323 DALI_LOG_ERROR( " -> The autofill data is not present now. \n" );
327 // If autofill authentication is needed, get authentication service information and set to DALi member variables.
328 if( authenticationNeeded )
330 // Gets the authentication service information which is set by Autofill Service framework.
331 autofill_auth_info_get_service_name( authInfoHandle, &serviceName );
332 autofill_auth_info_get_service_message( authInfoHandle, &serviceMessage );
333 autofill_auth_info_get_service_logo_image_path( authInfoHandle, &serviceLogoImagePath );
335 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::ReceiveAuthInfo service name : %s, logo path : %s, message : '%s' \n",
336 serviceName, serviceLogoImagePath, serviceMessage );
338 // Sets the authentication service information in order to use in other components.
341 mAuthenticationServiceName = serviceName;
347 mAuthenticationServiceMessage = serviceMessage;
348 free( serviceMessage );
351 if( serviceLogoImagePath )
353 mAuthenticationServiceImagePath = serviceLogoImagePath;
354 free( serviceLogoImagePath );
357 // Emits the signal to receive the authentication information.
358 mAuthReceivedSignal.Emit();
362 // If Authentication is not needed, sends fill request directly to fill the data.
363 mAutofillGroup.SendFillRequest();
367 // Implementation to fill out the data
368 void AutofillManagerEcoreWl::FillGroupItem( autofill_fill_response_item_h itemHandle, void *userData )
372 char* presentationText = NULL;
374 // Gets the fill response information which is set by Autofill Service framework.
375 autofill_fill_response_item_get_id( itemHandle, &id );
376 autofill_fill_response_item_get_presentation_text( itemHandle, &presentationText );
377 autofill_fill_response_item_get_value( itemHandle, &value );
379 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::FillResponseItemCallback item id : %s, value : %s, presentation text : %s\n",
380 id, value, presentationText );
382 // Sets the fill response information in order to use in other components.
389 if( presentationText )
391 mFillItemPresentationText = presentationText;
392 free( presentationText );
397 mFillItemValue = value;
401 Dali::AutofillItem item = mAutofillGroup.GetAutofillItem( mFillItemId );
402 Internal::Adaptor::AutofillItem& itemImpl = Internal::Adaptor::GetImplementation( item );
403 itemImpl.AddPresentationList( mFillItemPresentationText );
404 itemImpl.AddFillValueList( mFillItemValue );
406 // Emits the signal to fill the data in text input field.
407 mFillReceivedSignal.Emit( item );
411 // Implementation to fill out the data when the group count is more than one.
412 void AutofillManagerEcoreWl::FillMultipleGroupItem( autofill_fill_response_item_h itemHandle, void *userData )
416 char* presentationText = NULL;
418 // Gets the fill response information which is set by Autofill Service framework.
419 autofill_fill_response_item_get_id( itemHandle, &id );
420 autofill_fill_response_item_get_presentation_text( itemHandle, &presentationText );
421 autofill_fill_response_item_get_value( itemHandle, &value );
423 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::FillResponseMultipleItemCallback item id : %s, value : %s, presentation text : %s\n",
424 id, value, presentationText );
426 // Sets the fill response information in order to use in other components.
433 if( presentationText )
435 mFillItemPresentationText = presentationText;
436 free( presentationText );
441 mFillItemValue = value;
445 Dali::AutofillItem item = mAutofillGroup.GetAutofillItem( mFillItemId );
446 Internal::Adaptor::AutofillItem& itemImpl = Internal::Adaptor::GetImplementation( item );
447 itemImpl.AddPresentationList( mFillItemPresentationText );
448 itemImpl.AddFillValueList( mFillItemValue );
451 #endif // CAPI_AUTOFILL_SUPPORT
454 /////////////////////////////////////////////// Autofill Item and Group ///////////////////////////////////////////////
456 Dali::AutofillItem AutofillManagerEcoreWl::CreateAutofillItem( const std::string& id, const std::string& label, Dali::AutofillItem::Hint hint, bool isSensitive )
458 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::CreateAutofillItem \n" );
460 Dali::AutofillItem item = AutofillItem::New( id, label, hint, isSensitive );
461 mAutofillItemList.push_back( item );
463 return mAutofillItemList.back();
466 Dali::AutofillGroup AutofillManagerEcoreWl::CreateAutofillGroup( const std::string& groupId )
468 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::CreateAutofillGroup \n" );
470 Dali::AutofillGroup group = AutofillGroup::New( groupId );
471 mAutofillGroupList.push_back( group );
473 return mAutofillGroupList.back();
477 /////////////////////////////////////////////// Autofill Authentication Information ///////////////////////////////////////////////
479 bool AutofillManagerEcoreWl::IsAutofillDataPresent() const
481 return mIsDataPresent;
484 bool AutofillManagerEcoreWl::IsAuthenticationNeeded() const
486 return mIsAuthNeeded;
489 const std::string& AutofillManagerEcoreWl::GetAuthenticationServiceName() const
491 return mAuthenticationServiceName;
494 const std::string& AutofillManagerEcoreWl::GetAuthenticationServiceMessage() const
496 return mAuthenticationServiceMessage;
499 const std::string& AutofillManagerEcoreWl::GetAuthenticationServiceImagePath() const
501 return mAuthenticationServiceImagePath;
505 /////////////////////////////////////////////// Autofill Fill Response ///////////////////////////////////////////////
507 const std::string& AutofillManagerEcoreWl::GetFillItemId() const
512 const std::string& AutofillManagerEcoreWl::GetFillItemPresentationText() const
514 return mFillItemPresentationText;
517 const std::string& AutofillManagerEcoreWl::GetFillItemValue() const
519 return mFillItemValue;
522 void AutofillManagerEcoreWl::SaveAutofillData( Dali::AutofillGroup group )
524 DALI_LOG_INFO( gLogFilter, Debug::General, "AutofillManagerEcoreWl::SaveAutofillData -> Sends request to store data. \n" );
526 #ifdef CAPI_AUTOFILL_SUPPORT
527 Internal::Adaptor::AutofillGroup& groupImpl = Internal::Adaptor::GetImplementation( group );
528 Internal::Adaptor::AutofillGroupEcoreWl& groupImplWl = static_cast<Internal::Adaptor::AutofillGroupEcoreWl&>( groupImpl );
530 // Sends request to save autofill data.
531 int ret = autofill_commit( mAutofillHandle, groupImplWl.GetAutofillSaveGroupHandle() );
532 if( ret != AUTOFILL_ERROR_NONE )
534 DALI_LOG_ERROR( "Failed to request auth info. error : %d \n", ret );
536 #endif // CAPI_AUTOFILL_SUPPORT
540 AutofillManagerEcoreWl::AuthSignalType& AutofillManagerEcoreWl::AuthenticationReceivedSignal()
542 return mAuthReceivedSignal;
545 AutofillManagerEcoreWl::FillSignalType& AutofillManagerEcoreWl::FillResponseReceivedSignal()
547 return mFillReceivedSignal;
550 AutofillManagerEcoreWl::ListSignalType& AutofillManagerEcoreWl::ListEventSignal()
552 return mListReceivedSignal;
555 bool AutofillManagerEcoreWl::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
557 Dali::BaseHandle handle( object );
559 bool connected( true );
560 AutofillManagerEcoreWl* manager = dynamic_cast< AutofillManagerEcoreWl* >( object );
564 if( 0 == signalName.compare( SIGNAL_AUTHENTICATION_RECEIVED ) )
566 manager->AuthenticationReceivedSignal().Connect( tracker, functor );
568 else if( 0 == signalName.compare( SIGNAL_FILL_RESPONSE_RECEIVED ) )
570 manager->FillResponseReceivedSignal().Connect( tracker, functor );
572 else if( 0 == signalName.compare( SIGNAL_LIST_RECEIVED ) )
574 manager->ListEventSignal().Connect( tracker, functor );
578 // signalName does not match any signal