1212#include " flutter/shell/platform/tizen/logger.h"
1313
1414TizenAutofill::TizenAutofill () {
15- InitailizeAutofill ();
15+ Initailize ();
1616}
1717
1818TizenAutofill::~TizenAutofill () {
19+ autofill_fill_response_unset_received_cb (autofill_);
1920 autofill_destroy (autofill_);
2021}
2122
22- void TizenAutofill::InitailizeAutofill () {
23- autofill_create (&autofill_);
23+ void TizenAutofill::Initailize () {
24+ int ret = AUTOFILL_ERROR_NONE;
25+ if (!autofill_) {
26+ ret = autofill_create (&autofill_);
27+ if (ret != AUTOFILL_ERROR_NONE) {
28+ FT_LOG (Error) << " Fail to create autofill handle." ;
29+ return ;
30+ }
31+ }
2432
25- int ret = autofill_connect (
33+ ret = autofill_connect (
2634 autofill_,
2735 [](autofill_h autofill, autofill_connection_status_e status,
28- void * user_data) {},
36+ void * user_data) { TizenAutofill::GetInstance (). SetConnected ( true ); },
2937 nullptr );
3038 if (ret != AUTOFILL_ERROR_NONE) {
31- FT_LOG (Error) << " connect_autofill_daemon error" ;
39+ FT_LOG (Error) << " Fail to connect to the autofill daemon." ;
40+ return ;
3241 }
3342
34- autofill_fill_response_set_received_cb (
43+ ret = autofill_fill_response_set_received_cb (
3544 autofill_,
3645 [](autofill_h autofill, autofill_fill_response_h fill_response,
3746 void * data) {
@@ -45,18 +54,18 @@ void TizenAutofill::InitailizeAutofill() {
4554 [](autofill_fill_response_item_h item, void * user_data) {
4655 char * id = nullptr ;
4756 char * value = nullptr ;
48- char * presentation_text = nullptr ;
57+ char * label = nullptr ;
4958
5059 autofill_fill_response_item_get_id (item, &id);
51- autofill_fill_response_item_get_presentation_text (
52- item, &presentation_text );
60+ autofill_fill_response_item_get_presentation_text (item,
61+ &label );
5362 autofill_fill_response_item_get_value (item, &value);
5463
5564 std::unique_ptr<AutofillItem> response_item =
5665 std::make_unique<AutofillItem>();
57- response_item->label_ = std::string (presentation_text);
5866 response_item->id_ = std::string (id);
5967 response_item->value_ = std::string (value);
68+ response_item->label_ = std::string (label);
6069
6170 TizenAutofill::GetInstance ().StoreResponseItem (
6271 move (response_item));
@@ -69,8 +78,8 @@ void TizenAutofill::InitailizeAutofill() {
6978 free (value);
7079 }
7180
72- if (presentation_text ) {
73- free (presentation_text );
81+ if (label ) {
82+ free (label );
7483 }
7584
7685 return true ;
@@ -82,12 +91,26 @@ void TizenAutofill::InitailizeAutofill() {
8291 TizenAutofill::GetInstance ().OnPopup ();
8392 },
8493 nullptr );
94+ if (ret != AUTOFILL_ERROR_NONE) {
95+ FT_LOG (Error) << " Fail to set fill response received callback." ;
96+ return ;
97+ }
8598
8699 response_items_.clear ();
100+ initailzed_ = true ;
87101}
88102
89103void TizenAutofill::RequestAutofill (std::vector<std::string> hints,
90104 std::string id) {
105+ if (!initailzed_) {
106+ Initailize ();
107+ return ;
108+ }
109+
110+ if (!connected_) {
111+ return ;
112+ }
113+
91114 char * app_id = nullptr ;
92115 app_get_id (&app_id);
93116
@@ -115,17 +138,24 @@ void TizenAutofill::RequestAutofill(std::vector<std::string> hints,
115138
116139 int ret = autofill_fill_request (autofill_, view_info);
117140 if (ret != AUTOFILL_ERROR_NONE) {
118- FT_LOG (Error) << " autofill_fill_request error " ;
141+ FT_LOG (Error) << " Fail to request autofill " ;
119142 }
120143 autofill_view_info_destroy (view_info);
121144
122145 response_items_.clear ();
123146}
124147
125- void TizenAutofill::RegisterAutofillItem (std::string view_id,
126- AutofillItem item) {
127- autofill_save_item_h save_item = nullptr ;
148+ void TizenAutofill::RegisterItem (std::string view_id, AutofillItem item) {
149+ if (!initailzed_) {
150+ Initailize ();
151+ return ;
152+ }
153+
154+ if (!connected_) {
155+ return ;
156+ }
128157
158+ autofill_save_item_h save_item = nullptr ;
129159 autofill_save_item_create (&save_item);
130160 autofill_save_item_set_autofill_hint (save_item, item.hint_ );
131161 autofill_save_item_set_id (save_item, item.id_ .c_str ());
@@ -137,11 +167,9 @@ void TizenAutofill::RegisterAutofillItem(std::string view_id,
137167 app_get_id (&app_id);
138168
139169 autofill_save_view_info_h save_view_info = nullptr ;
140-
141170 autofill_save_view_info_create (&save_view_info);
142171 autofill_save_view_info_set_app_id (save_view_info, app_id);
143172 autofill_save_view_info_set_view_id (save_view_info, view_id.c_str ());
144-
145173 autofill_save_view_info_add_item (save_view_info, save_item);
146174
147175 if (app_id) {
@@ -150,7 +178,7 @@ void TizenAutofill::RegisterAutofillItem(std::string view_id,
150178
151179 int ret = autofill_commit (autofill_, save_view_info);
152180 if (ret != AUTOFILL_ERROR_NONE) {
153- FT_LOG (Error) << " autofill_commit error " ;
181+ FT_LOG (Error) << " Fail to register autofill item. " ;
154182 }
155183
156184 autofill_save_view_info_destroy (save_view_info);
0 commit comments