| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 typedef void (^FetchFormsCompletionHandler)(BOOL, const FormDataVector&); | 58 typedef void (^FetchFormsCompletionHandler)(BOOL, const FormDataVector&); |
| 59 | 59 |
| 60 // Gets the first form and field specified by |fieldName| from |forms|, | 60 // Gets the first form and field specified by |fieldName| from |forms|, |
| 61 // modifying the returned field so that input elements are also handled. | 61 // modifying the returned field so that input elements are also handled. |
| 62 void GetFormAndField(autofill::FormData* form, | 62 void GetFormAndField(autofill::FormData* form, |
| 63 autofill::FormFieldData* field, | 63 autofill::FormFieldData* field, |
| 64 const FormDataVector& forms, | 64 const FormDataVector& forms, |
| 65 const std::string& fieldName, | 65 const std::string& fieldName, |
| 66 const std::string& type) { | 66 const std::string& type) { |
| 67 DCHECK_GE(forms.size(), 1U); | 67 DCHECK_GE(forms.size(), 1U); |
| 68 *form = forms[0]; | |
| 69 const base::string16 fieldName16 = base::UTF8ToUTF16(fieldName); | 68 const base::string16 fieldName16 = base::UTF8ToUTF16(fieldName); |
| 70 for (const auto& currentField : form->fields) { | 69 for (const auto& currentForm : forms) { |
| 71 if (currentField.name == fieldName16) { | 70 for (const auto& currentField : currentForm.fields) { |
| 72 *field = currentField; | 71 if (currentField.name == fieldName16) { |
| 73 break; | 72 *form = currentForm; |
| 73 *field = currentField; |
| 74 break; |
| 75 } |
| 74 } | 76 } |
| 75 } | 77 } |
| 76 if (field->SameFieldAs(autofill::FormFieldData())) | 78 if (field->SameFieldAs(autofill::FormFieldData())) |
| 77 return; | 79 return; |
| 78 | 80 |
| 79 // Hack to get suggestions from select input elements. | 81 // Hack to get suggestions from select input elements. |
| 80 if (field->form_control_type == "select-one") { | 82 if (field->form_control_type == "select-one") { |
| 81 // Any value set will cause the AutofillManager to filter suggestions (only | 83 // Any value set will cause the AutofillManager to filter suggestions (only |
| 82 // show suggestions that begin the same as the current value) with the | 84 // show suggestions that begin the same as the current value) with the |
| 83 // effect that one only suggestion would be returned; the value itself. | 85 // effect that one only suggestion would be returned; the value itself. |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 if (trustLevel != web::URLVerificationTrustLevel::kAbsolute) { | 533 if (trustLevel != web::URLVerificationTrustLevel::kAbsolute) { |
| 532 DLOG(WARNING) << "Suggestions not offered on untrusted page"; | 534 DLOG(WARNING) << "Suggestions not offered on untrusted page"; |
| 533 completion(NO); | 535 completion(NO); |
| 534 return; | 536 return; |
| 535 } | 537 } |
| 536 | 538 |
| 537 // Once the active form and field are extracted, send a query to the | 539 // Once the active form and field are extracted, send a query to the |
| 538 // AutofillManager for suggestions. | 540 // AutofillManager for suggestions. |
| 539 __weak AutofillAgent* weakSelf = self; | 541 __weak AutofillAgent* weakSelf = self; |
| 540 id completionHandler = ^(BOOL success, const FormDataVector& forms) { | 542 id completionHandler = ^(BOOL success, const FormDataVector& forms) { |
| 541 if (success && forms.size() == 1) { | 543 if (success && forms.size() >= 1) { |
| 542 [weakSelf queryAutofillWithForms:forms | 544 [weakSelf queryAutofillWithForms:forms |
| 543 field:fieldName | 545 field:fieldName |
| 544 type:type | 546 type:type |
| 545 typedValue:typedValue | 547 typedValue:typedValue |
| 546 webState:webState | 548 webState:webState |
| 547 completionHandler:completion]; | 549 completionHandler:completion]; |
| 548 } | 550 } |
| 549 }; | 551 }; |
| 550 | 552 |
| 551 // Re-extract the active form and field only. All forms with at least one | 553 // Re-extract the active form and field only. All forms with at least one |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 // if we do it now a flicker will be seen. | 738 // if we do it now a flicker will be seen. |
| 737 if (type.compare("blur") == 0) | 739 if (type.compare("blur") == 0) |
| 738 return; | 740 return; |
| 739 | 741 |
| 740 // Necessary so the strings can be used inside a block. | 742 // Necessary so the strings can be used inside a block. |
| 741 std::string fieldNameCopy = fieldName; | 743 std::string fieldNameCopy = fieldName; |
| 742 std::string typeCopy = type; | 744 std::string typeCopy = type; |
| 743 | 745 |
| 744 __weak AutofillAgent* weakSelf = self; | 746 __weak AutofillAgent* weakSelf = self; |
| 745 id completionHandler = ^(BOOL success, const FormDataVector& forms) { | 747 id completionHandler = ^(BOOL success, const FormDataVector& forms) { |
| 746 if (success && forms.size() == 1) { | 748 if (success && forms.size() >= 1) { |
| 747 [weakSelf processFormActivityExtractedData:forms | 749 [weakSelf processFormActivityExtractedData:forms |
| 748 fieldName:fieldNameCopy | 750 fieldName:fieldNameCopy |
| 749 type:typeCopy | 751 type:typeCopy |
| 750 webState:webState]; | 752 webState:webState]; |
| 751 } | 753 } |
| 752 }; | 754 }; |
| 753 | 755 |
| 754 // Re-extract the active form and field only. There is no minimum field | 756 // Re-extract the active form and field only. There is no minimum field |
| 755 // requirement because key/value suggestions are offered event on short forms. | 757 // requirement because key/value suggestions are offered event on short forms. |
| 756 [self fetchFormsWithName:base::UTF8ToUTF16(formName) | 758 [self fetchFormsWithName:base::UTF8ToUTF16(formName) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 } | 876 } |
| 875 predictionData.SetWithoutPathExpansion(base::UTF16ToUTF8(formData.name), | 877 predictionData.SetWithoutPathExpansion(base::UTF16ToUTF8(formData.name), |
| 876 std::move(formJSONData)); | 878 std::move(formJSONData)); |
| 877 } | 879 } |
| 878 std::string dataString; | 880 std::string dataString; |
| 879 base::JSONWriter::Write(predictionData, &dataString); | 881 base::JSONWriter::Write(predictionData, &dataString); |
| 880 [jsAutofillManager_ fillPredictionData:base::SysUTF8ToNSString(dataString)]; | 882 [jsAutofillManager_ fillPredictionData:base::SysUTF8ToNSString(dataString)]; |
| 881 } | 883 } |
| 882 | 884 |
| 883 @end | 885 @end |
| OLD | NEW |