1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/autofill/core/common/mojom/autofill_types_mojom_traits.h"
6
7 #include "base/i18n/rtl.h"
8 #include "mojo/public/cpp/base/string16_mojom_traits.h"
9 #include "mojo/public/cpp/base/time_mojom_traits.h"
10 #include "ui/gfx/geometry/mojom/geometry_mojom_traits.h"
11 #include "url/mojom/origin_mojom_traits.h"
12 #include "url/mojom/url_gurl_mojom_traits.h"
13
14 namespace mojo {
15
16 // static
17 bool StructTraits<autofill::mojom::FormRendererIdDataView,
18 autofill::FormRendererId>::
Read(autofill::mojom::FormRendererIdDataView data,autofill::FormRendererId * out)19 Read(autofill::mojom::FormRendererIdDataView data,
20 autofill::FormRendererId* out) {
21 *out = autofill::FormRendererId(data.id());
22 return true;
23 }
24
25 // static
26 bool StructTraits<autofill::mojom::FieldRendererIdDataView,
27 autofill::FieldRendererId>::
Read(autofill::mojom::FieldRendererIdDataView data,autofill::FieldRendererId * out)28 Read(autofill::mojom::FieldRendererIdDataView data,
29 autofill::FieldRendererId* out) {
30 *out = autofill::FieldRendererId(data.id());
31 return true;
32 }
33
34 // static
35 bool StructTraits<
36 autofill::mojom::FormFieldDataDataView,
Read(autofill::mojom::FormFieldDataDataView data,autofill::FormFieldData * out)37 autofill::FormFieldData>::Read(autofill::mojom::FormFieldDataDataView data,
38 autofill::FormFieldData* out) {
39 if (!data.ReadLabel(&out->label))
40 return false;
41 if (!data.ReadName(&out->name))
42 return false;
43 if (!data.ReadIdAttribute(&out->id_attribute))
44 return false;
45 if (!data.ReadNameAttribute(&out->name_attribute))
46 return false;
47 if (!data.ReadValue(&out->value))
48 return false;
49
50 if (!data.ReadFormControlType(&out->form_control_type))
51 return false;
52 if (!data.ReadAutocompleteAttribute(&out->autocomplete_attribute))
53 return false;
54
55 if (!data.ReadPlaceholder(&out->placeholder))
56 return false;
57
58 if (!data.ReadCssClasses(&out->css_classes))
59 return false;
60
61 if (!data.ReadAriaLabel(&out->aria_label))
62 return false;
63
64 if (!data.ReadAriaDescription(&out->aria_description))
65 return false;
66
67 if (!data.ReadSection(&out->section))
68 return false;
69
70 out->properties_mask = data.properties_mask();
71
72 if (!data.ReadUniqueRendererId(&out->unique_renderer_id))
73 return false;
74
75 out->form_control_ax_id = data.form_control_ax_id();
76 out->max_length = data.max_length();
77 out->is_autofilled = data.is_autofilled();
78
79 if (!data.ReadCheckStatus(&out->check_status))
80 return false;
81
82 out->is_focusable = data.is_focusable();
83 out->should_autocomplete = data.should_autocomplete();
84
85 if (!data.ReadRole(&out->role))
86 return false;
87
88 if (!data.ReadTextDirection(&out->text_direction))
89 return false;
90
91 out->is_enabled = data.is_enabled();
92 out->is_readonly = data.is_readonly();
93 if (!data.ReadTypedValue(&out->typed_value))
94 return false;
95
96 if (!data.ReadOptionValues(&out->option_values))
97 return false;
98 if (!data.ReadOptionContents(&out->option_contents))
99 return false;
100
101 if (!data.ReadLabelSource(&out->label_source))
102 return false;
103
104 if (!data.ReadBounds(&out->bounds))
105 return false;
106
107 if (!data.ReadDatalistValues(&out->datalist_values))
108 return false;
109 if (!data.ReadDatalistLabels(&out->datalist_labels))
110 return false;
111
112 return true;
113 }
114
115 // static
116 bool StructTraits<autofill::mojom::ButtonTitleInfoDataView,
117 autofill::ButtonTitleInfo>::
Read(autofill::mojom::ButtonTitleInfoDataView data,autofill::ButtonTitleInfo * out)118 Read(autofill::mojom::ButtonTitleInfoDataView data,
119 autofill::ButtonTitleInfo* out) {
120 return data.ReadTitle(&out->first) && data.ReadType(&out->second);
121 }
122
123 // static
Read(autofill::mojom::FormDataDataView data,autofill::FormData * out)124 bool StructTraits<autofill::mojom::FormDataDataView, autofill::FormData>::Read(
125 autofill::mojom::FormDataDataView data,
126 autofill::FormData* out) {
127 if (!data.ReadIdAttribute(&out->id_attribute))
128 return false;
129 if (!data.ReadNameAttribute(&out->name_attribute))
130 return false;
131 if (!data.ReadName(&out->name))
132 return false;
133 if (!data.ReadButtonTitles(&out->button_titles))
134 return false;
135 if (!data.ReadUrl(&out->url))
136 return false;
137 if (!data.ReadFullUrl(&out->full_url))
138 return false;
139 if (!data.ReadAction(&out->action))
140 return false;
141 out->is_action_empty = data.is_action_empty();
142 if (!data.ReadMainFrameOrigin(&out->main_frame_origin))
143 return false;
144
145 out->is_form_tag = data.is_form_tag();
146 out->is_formless_checkout = data.is_formless_checkout();
147
148 if (!data.ReadUniqueRendererId(&out->unique_renderer_id))
149 return false;
150
151 if (!data.ReadSubmissionEvent(&out->submission_event))
152 return false;
153
154 if (!data.ReadFields(&out->fields))
155 return false;
156
157 if (!data.ReadUsernamePredictions(&out->username_predictions))
158 return false;
159
160 out->is_gaia_with_skip_save_password_form =
161 data.is_gaia_with_skip_save_password_form();
162
163 return true;
164 }
165
166 // static
167 bool StructTraits<autofill::mojom::FormFieldDataPredictionsDataView,
168 autofill::FormFieldDataPredictions>::
Read(autofill::mojom::FormFieldDataPredictionsDataView data,autofill::FormFieldDataPredictions * out)169 Read(autofill::mojom::FormFieldDataPredictionsDataView data,
170 autofill::FormFieldDataPredictions* out) {
171 if (!data.ReadSignature(&out->signature))
172 return false;
173 if (!data.ReadHeuristicType(&out->heuristic_type))
174 return false;
175 if (!data.ReadServerType(&out->server_type))
176 return false;
177 if (!data.ReadOverallType(&out->overall_type))
178 return false;
179 if (!data.ReadParseableName(&out->parseable_name))
180 return false;
181 if (!data.ReadSection(&out->section))
182 return false;
183
184 return true;
185 }
186
187 // static
188 bool StructTraits<autofill::mojom::FormDataPredictionsDataView,
189 autofill::FormDataPredictions>::
Read(autofill::mojom::FormDataPredictionsDataView data,autofill::FormDataPredictions * out)190 Read(autofill::mojom::FormDataPredictionsDataView data,
191 autofill::FormDataPredictions* out) {
192 if (!data.ReadData(&out->data))
193 return false;
194 if (!data.ReadSignature(&out->signature))
195 return false;
196 if (!data.ReadFields(&out->fields))
197 return false;
198
199 return true;
200 }
201
202 // static
203 bool StructTraits<autofill::mojom::PasswordAndMetadataDataView,
204 autofill::PasswordAndMetadata>::
Read(autofill::mojom::PasswordAndMetadataDataView data,autofill::PasswordAndMetadata * out)205 Read(autofill::mojom::PasswordAndMetadataDataView data,
206 autofill::PasswordAndMetadata* out) {
207 if (!data.ReadUsername(&out->username))
208 return false;
209 if (!data.ReadPassword(&out->password))
210 return false;
211 if (!data.ReadRealm(&out->realm))
212 return false;
213
214 out->uses_account_store = data.uses_account_store();
215
216 return true;
217 }
218
219 // static
220 bool StructTraits<autofill::mojom::PasswordFormFillDataDataView,
221 autofill::PasswordFormFillData>::
Read(autofill::mojom::PasswordFormFillDataDataView data,autofill::PasswordFormFillData * out)222 Read(autofill::mojom::PasswordFormFillDataDataView data,
223 autofill::PasswordFormFillData* out) {
224 if (!data.ReadFormRendererId(&out->form_renderer_id) ||
225 !data.ReadUrl(&out->url) || !data.ReadAction(&out->action) ||
226 !data.ReadUsernameField(&out->username_field) ||
227 !data.ReadPasswordField(&out->password_field) ||
228 !data.ReadPreferredRealm(&out->preferred_realm) ||
229 !data.ReadAdditionalLogins(&out->additional_logins))
230 return false;
231
232 out->uses_account_store = data.uses_account_store();
233 out->wait_for_username = data.wait_for_username();
234 out->username_may_use_prefilled_placeholder =
235 data.username_may_use_prefilled_placeholder();
236
237 return true;
238 }
239
240 // static
241 bool StructTraits<autofill::mojom::PasswordFormGenerationDataDataView,
242 autofill::PasswordFormGenerationData>::
Read(autofill::mojom::PasswordFormGenerationDataDataView data,autofill::PasswordFormGenerationData * out)243 Read(autofill::mojom::PasswordFormGenerationDataDataView data,
244 autofill::PasswordFormGenerationData* out) {
245 return data.ReadNewPasswordRendererId(&out->new_password_renderer_id) &&
246 data.ReadConfirmationPasswordRendererId(
247 &out->confirmation_password_renderer_id);
248 }
249
250 // static
251 bool StructTraits<autofill::mojom::PasswordGenerationUIDataDataView,
252 autofill::password_generation::PasswordGenerationUIData>::
Read(autofill::mojom::PasswordGenerationUIDataDataView data,autofill::password_generation::PasswordGenerationUIData * out)253 Read(autofill::mojom::PasswordGenerationUIDataDataView data,
254 autofill::password_generation::PasswordGenerationUIData* out) {
255 if (!data.ReadBounds(&out->bounds))
256 return false;
257
258 out->max_length = data.max_length();
259 out->is_generation_element_password_type =
260 data.is_generation_element_password_type();
261
262 return data.ReadGenerationElementId(&out->generation_element_id) &&
263 data.ReadGenerationElement(&out->generation_element) &&
264 data.ReadTextDirection(&out->text_direction) &&
265 data.ReadFormData(&out->form_data);
266 }
267
268 bool StructTraits<
269 autofill::mojom::ParsingResultDataView,
Read(autofill::mojom::ParsingResultDataView data,autofill::ParsingResult * out)270 autofill::ParsingResult>::Read(autofill::mojom::ParsingResultDataView data,
271 autofill::ParsingResult* out) {
272 return data.ReadUsernameRendererId(&out->username_renderer_id) &&
273 data.ReadPasswordRendererId(&out->password_renderer_id) &&
274 data.ReadNewPasswordRendererId(&out->new_password_renderer_id) &&
275 data.ReadConfirmPasswordRendererId(&out->confirm_password_renderer_id);
276 }
277
278 } // namespace mojo
279