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+ state_ = State:: kNone ;
2425
25- int ret = autofill_connect (
26+ int ret = AUTOFILL_ERROR_NONE;
27+ if (!autofill_) {
28+ ret = autofill_create (&autofill_);
29+ if (ret != AUTOFILL_ERROR_NONE) {
30+ FT_LOG (Error) << " Fail to create autofill handle." ;
31+ return ;
32+ }
33+ }
34+
35+ ret = autofill_connect (
2636 autofill_,
2737 [](autofill_h autofill, autofill_connection_status_e status,
28- void * user_data) {},
38+ void * user_data) { TizenAutofill::GetInstance (). Connected (); },
2939 nullptr );
3040 if (ret != AUTOFILL_ERROR_NONE) {
31- FT_LOG (Error) << " connect_autofill_daemon error" ;
41+ FT_LOG (Error) << " Fail to connect to the autofill daemon." ;
42+ return ;
3243 }
3344
34- autofill_fill_response_set_received_cb (
45+ ret = autofill_fill_response_set_received_cb (
3546 autofill_,
3647 [](autofill_h autofill, autofill_fill_response_h fill_response,
3748 void * data) {
@@ -45,18 +56,18 @@ void TizenAutofill::InitailizeAutofill() {
4556 [](autofill_fill_response_item_h item, void * user_data) {
4657 char * id = nullptr ;
4758 char * value = nullptr ;
48- char * presentation_text = nullptr ;
59+ char * label = nullptr ;
4960
5061 autofill_fill_response_item_get_id (item, &id);
51- autofill_fill_response_item_get_presentation_text (
52- item, &presentation_text );
62+ autofill_fill_response_item_get_presentation_text (item,
63+ &label );
5364 autofill_fill_response_item_get_value (item, &value);
5465
5566 std::unique_ptr<AutofillItem> response_item =
5667 std::make_unique<AutofillItem>();
57- response_item->label_ = std::string (presentation_text);
5868 response_item->id_ = std::string (id);
5969 response_item->value_ = std::string (value);
70+ response_item->label_ = std::string (label);
6071
6172 TizenAutofill::GetInstance ().StoreResponseItem (
6273 move (response_item));
@@ -69,8 +80,8 @@ void TizenAutofill::InitailizeAutofill() {
6980 free (value);
7081 }
7182
72- if (presentation_text ) {
73- free (presentation_text );
83+ if (label ) {
84+ free (label );
7485 }
7586
7687 return true ;
@@ -82,12 +93,22 @@ void TizenAutofill::InitailizeAutofill() {
8293 TizenAutofill::GetInstance ().OnPopup ();
8394 },
8495 nullptr );
96+ if (ret != AUTOFILL_ERROR_NONE) {
97+ FT_LOG (Error) << " Fail to set fill response received callback." ;
98+ return ;
99+ }
85100
86101 response_items_.clear ();
102+ Initialized ();
87103}
88104
89105void TizenAutofill::RequestAutofill (std::vector<std::string> hints,
90106 std::string id) {
107+ if (state_ != State::kReady ) {
108+ Initailize ();
109+ return ;
110+ }
111+
91112 char * app_id = nullptr ;
92113 app_get_id (&app_id);
93114
@@ -115,17 +136,20 @@ void TizenAutofill::RequestAutofill(std::vector<std::string> hints,
115136
116137 int ret = autofill_fill_request (autofill_, view_info);
117138 if (ret != AUTOFILL_ERROR_NONE) {
118- FT_LOG (Error) << " autofill_fill_request error " ;
139+ FT_LOG (Error) << " Fail to request autofill " ;
119140 }
120141 autofill_view_info_destroy (view_info);
121142
122143 response_items_.clear ();
123144}
124145
125- void TizenAutofill::RegisterAutofillItem (std::string view_id,
126- AutofillItem item) {
127- autofill_save_item_h save_item = nullptr ;
146+ void TizenAutofill::RegisterItem (std::string view_id, AutofillItem item) {
147+ if (state_ != State::kReady ) {
148+ Initailize ();
149+ return ;
150+ }
128151
152+ autofill_save_item_h save_item = nullptr ;
129153 autofill_save_item_create (&save_item);
130154 autofill_save_item_set_autofill_hint (save_item, item.hint_ );
131155 autofill_save_item_set_id (save_item, item.id_ .c_str ());
@@ -137,11 +161,9 @@ void TizenAutofill::RegisterAutofillItem(std::string view_id,
137161 app_get_id (&app_id);
138162
139163 autofill_save_view_info_h save_view_info = nullptr ;
140-
141164 autofill_save_view_info_create (&save_view_info);
142165 autofill_save_view_info_set_app_id (save_view_info, app_id);
143166 autofill_save_view_info_set_view_id (save_view_info, view_id.c_str ());
144-
145167 autofill_save_view_info_add_item (save_view_info, save_item);
146168
147169 if (app_id) {
@@ -150,7 +172,7 @@ void TizenAutofill::RegisterAutofillItem(std::string view_id,
150172
151173 int ret = autofill_commit (autofill_, save_view_info);
152174 if (ret != AUTOFILL_ERROR_NONE) {
153- FT_LOG (Error) << " autofill_commit error " ;
175+ FT_LOG (Error) << " Fail to register autofill item. " ;
154176 }
155177
156178 autofill_save_view_info_destroy (save_view_info);
0 commit comments