| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/autofill/autofill_agent.h" | 5 #import "ios/chrome/browser/autofill/autofill_agent.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 fieldData->role = autofill::AutofillField::ROLE_ATTRIBUTE_PRESENTATION; | 260 fieldData->role = autofill::AutofillField::ROLE_ATTRIBUTE_PRESENTATION; |
| 261 } | 261 } |
| 262 | 262 |
| 263 // TODO(crbug.com/427614): Extract |text_direction|. | 263 // TODO(crbug.com/427614): Extract |text_direction|. |
| 264 | 264 |
| 265 // Load option values where present. | 265 // Load option values where present. |
| 266 const base::ListValue* optionValues; | 266 const base::ListValue* optionValues; |
| 267 if (field.GetList("option_values", &optionValues)) { | 267 if (field.GetList("option_values", &optionValues)) { |
| 268 for (const auto& optionValue : *optionValues) { | 268 for (const auto& optionValue : *optionValues) { |
| 269 base::string16 value; | 269 base::string16 value; |
| 270 if (optionValue.GetAsString(&value)) | 270 if (optionValue->GetAsString(&value)) |
| 271 fieldData->option_values.push_back(value); | 271 fieldData->option_values.push_back(value); |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Load option contents where present. | 275 // Load option contents where present. |
| 276 const base::ListValue* optionContents; | 276 const base::ListValue* optionContents; |
| 277 if (field.GetList("option_contents", &optionContents)) { | 277 if (field.GetList("option_contents", &optionContents)) { |
| 278 for (const auto& optionContent : *optionContents) { | 278 for (const auto& optionContent : *optionContents) { |
| 279 base::string16 content; | 279 base::string16 content; |
| 280 if (optionContent.GetAsString(&content)) | 280 if (optionContent->GetAsString(&content)) |
| 281 fieldData->option_contents.push_back(content); | 281 fieldData->option_contents.push_back(content); |
| 282 } | 282 } |
| 283 } | 283 } |
| 284 | 284 |
| 285 if (fieldData->option_values.size() != fieldData->option_contents.size()) | 285 if (fieldData->option_values.size() != fieldData->option_contents.size()) |
| 286 return NO; // Option values and contents lists should match 1-1. | 286 return NO; // Option values and contents lists should match 1-1. |
| 287 | 287 |
| 288 return YES; | 288 return YES; |
| 289 } | 289 } |
| 290 | 290 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // Get the list of forms. | 358 // Get the list of forms. |
| 359 const base::ListValue* formsList; | 359 const base::ListValue* formsList; |
| 360 if (!data->GetList("forms", &formsList)) | 360 if (!data->GetList("forms", &formsList)) |
| 361 return NO; | 361 return NO; |
| 362 | 362 |
| 363 // Iterate through all the extracted forms and copy the data from JSON into | 363 // Iterate through all the extracted forms and copy the data from JSON into |
| 364 // AutofillManager structures. | 364 // AutofillManager structures. |
| 365 for (const auto& formDict : *formsList) { | 365 for (const auto& formDict : *formsList) { |
| 366 // Each form list entry should be a JSON dictionary. | 366 // Each form list entry should be a JSON dictionary. |
| 367 const base::DictionaryValue* formData; | 367 const base::DictionaryValue* formData; |
| 368 if (!formDict.GetAsDictionary(&formData)) | 368 if (!formDict->GetAsDictionary(&formData)) |
| 369 return NO; | 369 return NO; |
| 370 | 370 |
| 371 // Form data is copied into a FormData object field-by-field. | 371 // Form data is copied into a FormData object field-by-field. |
| 372 autofill::FormData form; | 372 autofill::FormData form; |
| 373 if (!formData->GetString("name", &form.name)) | 373 if (!formData->GetString("name", &form.name)) |
| 374 return NO; | 374 return NO; |
| 375 if (!formName.empty() && formName != form.name) | 375 if (!formName.empty() && formName != form.name) |
| 376 continue; | 376 continue; |
| 377 | 377 |
| 378 // Origin is mandatory. | 378 // Origin is mandatory. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 397 if (formData->GetBoolean("is_form_tag", &is_form_tag)) | 397 if (formData->GetBoolean("is_form_tag", &is_form_tag)) |
| 398 form.is_form_tag = is_form_tag; | 398 form.is_form_tag = is_form_tag; |
| 399 | 399 |
| 400 // Field list (mandatory) is extracted. | 400 // Field list (mandatory) is extracted. |
| 401 const base::ListValue* fieldsList; | 401 const base::ListValue* fieldsList; |
| 402 if (!formData->GetList("fields", &fieldsList)) | 402 if (!formData->GetList("fields", &fieldsList)) |
| 403 return NO; | 403 return NO; |
| 404 for (const auto& fieldDict : *fieldsList) { | 404 for (const auto& fieldDict : *fieldsList) { |
| 405 const base::DictionaryValue* field; | 405 const base::DictionaryValue* field; |
| 406 autofill::FormFieldData fieldData; | 406 autofill::FormFieldData fieldData; |
| 407 if (fieldDict.GetAsDictionary(&field) && | 407 if (fieldDict->GetAsDictionary(&field) && |
| 408 [self extractFormField:*field asFieldData:&fieldData]) { | 408 [self extractFormField:*field asFieldData:&fieldData]) { |
| 409 form.fields.push_back(fieldData); | 409 form.fields.push_back(fieldData); |
| 410 } else { | 410 } else { |
| 411 return NO; | 411 return NO; |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 formsData->push_back(form); | 414 formsData->push_back(form); |
| 415 } | 415 } |
| 416 return YES; | 416 return YES; |
| 417 } | 417 } |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 } | 860 } |
| 861 predictionData.SetWithoutPathExpansion(base::UTF16ToUTF8(formData.name), | 861 predictionData.SetWithoutPathExpansion(base::UTF16ToUTF8(formData.name), |
| 862 formJSONData); | 862 formJSONData); |
| 863 } | 863 } |
| 864 std::string dataString; | 864 std::string dataString; |
| 865 base::JSONWriter::Write(predictionData, &dataString); | 865 base::JSONWriter::Write(predictionData, &dataString); |
| 866 [jsAutofillManager_ fillPredictionData:base::SysUTF8ToNSString(dataString)]; | 866 [jsAutofillManager_ fillPredictionData:base::SysUTF8ToNSString(dataString)]; |
| 867 } | 867 } |
| 868 | 868 |
| 869 @end | 869 @end |
| OLD | NEW |