Index: components/autofill/browser/autofill_manager.cc |
diff --git a/components/autofill/browser/autofill_manager.cc b/components/autofill/browser/autofill_manager.cc |
index b488ff611d1b9435ac718db2028d16a33d0c469f..56f5eaeae29ee19a0f99410c10f705082d940006 100644 |
--- a/components/autofill/browser/autofill_manager.cc |
+++ b/components/autofill/browser/autofill_manager.cc |
@@ -323,13 +323,17 @@ bool AutofillManager::OnFormSubmitted(const FormData& form, |
if (!IsAutofillEnabled()) |
return false; |
- if (web_contents()->GetBrowserContext()->IsOffTheRecord()) |
+ if (external_delegate_ && external_delegate_->ShouldIgnoreFormData()) |
Ilya Sherman
2013/06/03 23:22:19
Should this check just be part of the IsAutofillEn
sgurun-gerrit only
2013/06/13 01:13:31
Agreed. much less error prone.
On 2013/06/03 23:2
|
return false; |
// Don't save data that was submitted through JavaScript. |
if (!form.user_submitted) |
return false; |
+ // If there is no personal_data_, nothing to do. |
+ if (!personal_data_) |
+ return false; |
+ |
// Grab a copy of the form data. |
scoped_ptr<FormStructure> submitted_form( |
new FormStructure(form, GetAutocheckoutURLPrefix())); |
@@ -425,7 +429,6 @@ void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, |
metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); |
has_logged_autofill_enabled_ = true; |
} |
- |
Ilya Sherman
2013/06/03 23:22:19
nit: Spurious diff.
sgurun-gerrit only
2013/06/13 01:13:31
Done.
|
if (!enabled) |
return; |
@@ -482,6 +485,30 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
display_warning); |
} |
+ if (personal_data_) { |
Ilya Sherman
2013/06/03 23:22:19
Please move this check into the wrapped method.
sgurun-gerrit only
2013/06/13 01:13:31
Done. Actually this seems redundant since wrapped
|
+ OnQueryFormFieldAutofillPersonalData(query_id, |
+ form, |
+ field, |
+ &values, |
+ &labels, |
+ &icons, |
+ &unique_ids); |
+ } |
Ilya Sherman
2013/06/03 23:22:19
nit: Please add a newline after this one.
sgurun-gerrit only
2013/06/13 01:13:31
Done.
|
+ // Add the results from AutoComplete. They come back asynchronously, so we |
+ // hand off what we generated and they will send the results back to the |
+ // renderer. |
+ autocomplete_history_manager_.OnGetAutocompleteSuggestions( |
+ query_id, field.name, field.value, values, labels, icons, unique_ids); |
+} |
+ |
+void AutofillManager::OnQueryFormFieldAutofillPersonalData( |
+ int query_id, |
Ilya Sherman
2013/06/03 23:22:19
This parameter doesn't seem to be used.
sgurun-gerrit only
2013/06/13 01:13:31
Done.
|
+ const FormData& form, |
+ const FormFieldData& field, |
+ std::vector<base::string16>* values, |
+ std::vector<base::string16>* labels, |
+ std::vector<string16>* icons, |
+ std::vector<int>* unique_ids) { |
RenderViewHost* host = NULL; |
FormStructure* form_structure = NULL; |
AutofillField* autofill_field = NULL; |
@@ -494,17 +521,17 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
(AutofillType(type).group() == AutofillType::CREDIT_CARD); |
if (is_filling_credit_card) { |
GetCreditCardSuggestions( |
- field, type, &values, &labels, &icons, &unique_ids); |
+ field, type, values, labels, icons, unique_ids); |
} else { |
GetProfileSuggestions( |
- form_structure, field, type, &values, &labels, &icons, &unique_ids); |
+ form_structure, field, type, values, labels, icons, unique_ids); |
} |
- DCHECK_EQ(values.size(), labels.size()); |
- DCHECK_EQ(values.size(), icons.size()); |
- DCHECK_EQ(values.size(), unique_ids.size()); |
+ DCHECK_EQ(values->size(), labels->size()); |
+ DCHECK_EQ(values->size(), icons->size()); |
+ DCHECK_EQ(values->size(), unique_ids->size()); |
- if (!values.empty()) { |
+ if (!values->empty()) { |
// Don't provide Autofill suggestions when Autofill is disabled, and don't |
// provide credit card suggestions for non-HTTPS pages. However, provide a |
// warning to the user in these cases. |
@@ -514,11 +541,11 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
else if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) |
warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; |
if (warning) { |
- values.assign(1, l10n_util::GetStringUTF16(warning)); |
- labels.assign(1, base::string16()); |
- icons.assign(1, base::string16()); |
- unique_ids.assign(1, |
- WebKit::WebAutofillClient::MenuItemIDWarningMessage); |
+ values->assign(1, l10n_util::GetStringUTF16(warning)); |
+ labels->assign(1, base::string16()); |
+ icons->assign(1, base::string16()); |
+ unique_ids->assign(1, |
+ WebKit::WebAutofillClient::MenuItemIDWarningMessage); |
} else { |
bool section_is_autofilled = |
SectionIsAutofilled(*form_structure, form, |
@@ -528,8 +555,8 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
// for suggestions, then the user is editing the value of a field. |
// In this case, mimic autocomplete: don't display labels or icons, |
// as that information is redundant. |
- labels.assign(labels.size(), base::string16()); |
- icons.assign(icons.size(), base::string16()); |
+ labels->assign(labels->size(), base::string16()); |
+ icons->assign(icons->size(), base::string16()); |
} |
// When filling credit card suggestions, the values and labels are |
@@ -537,23 +564,17 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
// duplicates only tend to be a problem when filling address forms |
// anyway, only don't de-dup credit card suggestions. |
if (!is_filling_credit_card) |
- RemoveDuplicateSuggestions(&values, &labels, &icons, &unique_ids); |
+ RemoveDuplicateSuggestions(values, labels, icons, unique_ids); |
// The first time we show suggestions on this page, log the number of |
// suggestions shown. |
if (!has_logged_address_suggestions_count_ && !section_is_autofilled) { |
- metric_logger_->LogAddressSuggestionsCount(values.size()); |
+ metric_logger_->LogAddressSuggestionsCount(values->size()); |
has_logged_address_suggestions_count_ = true; |
} |
} |
} |
} |
- |
- // Add the results from AutoComplete. They come back asynchronously, so we |
- // hand off what we generated and they will send the results back to the |
- // renderer. |
- autocomplete_history_manager_.OnGetAutocompleteSuggestions( |
- query_id, field.name, field.value, values, labels, icons, unique_ids); |
} |
void AutofillManager::OnFillAutofillFormData(int query_id, |
@@ -688,6 +709,10 @@ void AutofillManager::OnHideAutofillUi() { |
} |
void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) { |
+ |
Ilya Sherman
2013/06/03 23:22:19
nit: Spurious newline.
sgurun-gerrit only
2013/06/13 01:13:31
Done.
|
+ if (!personal_data_) |
+ return; |
Ilya Sherman
2013/06/03 23:22:19
Why is this code reachable?
sgurun-gerrit only
2013/06/13 01:13:31
should not be reachable. removing.
|
+ |
const AutofillDataModel* data_model = NULL; |
size_t variant = 0; |
if (!GetProfileOrCreditCard(unique_id, &data_model, &variant)) { |
@@ -865,7 +890,9 @@ std::string AutofillManager::GetAutocheckoutURLPrefix() const { |
autofill::autocheckout::WhitelistManager* whitelist_manager = |
manager_delegate_->GetAutocheckoutWhitelistManager(); |
- return whitelist_manager->GetMatchedURLPrefix(web_contents()->GetURL()); |
+ return whitelist_manager ? |
+ whitelist_manager->GetMatchedURLPrefix(web_contents()->GetURL()) : |
+ std::string(); |
} |
bool AutofillManager::IsAutofillEnabled() const { |
@@ -891,6 +918,10 @@ void AutofillManager::SendAutofillTypePredictions( |
void AutofillManager::ImportFormData(const FormStructure& submitted_form) { |
const CreditCard* imported_credit_card; |
Ilya Sherman
2013/06/03 23:22:19
nit: Please keep this just above line 925.
sgurun-gerrit only
2013/06/13 01:13:31
I think this code should also be unreachable?
|
+ |
+ if (!personal_data_) |
+ return; |
+ |
if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card)) |
return; |
@@ -924,7 +955,7 @@ void AutofillManager::UploadFormDataAsyncCallback( |
} |
void AutofillManager::UploadFormData(const FormStructure& submitted_form) { |
- if (!download_manager_) |
+ if (!download_manager_ || !personal_data_) |
return; |
// Check if the form is among the forms that were recently auto-filled. |
@@ -991,6 +1022,9 @@ bool AutofillManager::GetHost(RenderViewHost** host) const { |
if (!IsAutofillEnabled()) |
return false; |
+ if (!personal_data_) |
+ return false; |
Ilya Sherman
2013/06/03 23:22:19
Why is this code reachable?
sgurun-gerrit only
2013/06/13 01:13:31
it is eventually reachable via OnQueryFormFieldAut
|
+ |
// No autofill data to return if the profiles are empty. |
if (personal_data_->GetProfiles().empty() && |
personal_data_->GetCreditCards().empty()) { |
@@ -1008,6 +1042,9 @@ bool AutofillManager::GetProfileOrCreditCard( |
int unique_id, |
const AutofillDataModel** data_model, |
size_t* variant) const { |
+ if (!personal_data_) |
+ return false; |
Ilya Sherman
2013/06/03 23:22:19
Why is this code reachable?
sgurun-gerrit only
2013/06/13 01:13:31
Done.
|
+ |
// Unpack the |unique_id| into component parts. |
GUIDPair credit_card_guid; |
GUIDPair profile_guid; |
@@ -1157,6 +1194,9 @@ void AutofillManager::GetProfileSuggestions( |
std::vector<base::string16>* labels, |
std::vector<base::string16>* icons, |
std::vector<int>* unique_ids) const { |
+ |
Ilya Sherman
2013/06/03 23:22:19
nit: Spurious newline.
sgurun-gerrit only
2013/06/13 01:13:31
Done.
|
+ if (!personal_data_) |
+ return; |
Ilya Sherman
2013/06/03 23:22:19
nit: Please add a newline after this line.
Ilya Sherman
2013/06/03 23:22:19
Why is this code reachable?
sgurun-gerrit only
2013/06/13 01:13:31
Done.
sgurun-gerrit only
2013/06/13 01:13:31
Done.
|
std::vector<AutofillFieldType> field_types(form->field_count()); |
for (size_t i = 0; i < form->field_count(); ++i) { |
field_types[i] = form->field(i)->type(); |
@@ -1180,6 +1220,10 @@ void AutofillManager::GetCreditCardSuggestions( |
std::vector<base::string16>* labels, |
std::vector<base::string16>* icons, |
std::vector<int>* unique_ids) const { |
+ |
Ilya Sherman
2013/06/03 23:22:19
nit: Spurious newline.
sgurun-gerrit only
2013/06/13 01:13:31
Done.
|
+ if (!personal_data_) |
+ return; |
Ilya Sherman
2013/06/03 23:22:19
Why is this code reachable?
sgurun-gerrit only
2013/06/13 01:13:31
removed.
On 2013/06/03 23:22:19, Ilya Sherman wro
|
+ |
std::vector<GUIDPair> guid_pairs; |
personal_data_->GetCreditCardSuggestions( |
type, field.value, values, labels, icons, &guid_pairs); |