Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1535)

Unified Diff: components/autofill/browser/autofill_manager.cc

Issue 15097004: Enable Autocomplete feature for chromium webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@setSaveFormData2
Patch Set: make personal_data_ optional Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e3ad5e56b9c81b7bde69188a4163402da0553e33 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())
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()));
@@ -396,6 +400,7 @@ bool AutofillManager::OnFormSubmitted(const FormData& form,
void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms,
const TimeTicks& timestamp,
autofill::FormsSeenState state) {
+
benm (inactive) 2013/05/23 12:02:21 nit: remove?
sgurun-gerrit only 2013/05/23 17:10:01 Done.
bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN;
bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN;
// If new forms were added via AJAX or DHML, treat as new page.
@@ -425,7 +430,6 @@ void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms,
metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled);
has_logged_autofill_enabled_ = true;
}
-
if (!enabled)
return;
@@ -482,6 +486,30 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id,
display_warning);
}
+ if (personal_data_) {
+ OnQueryFormFieldAutofillPersonalData(query_id,
+ form,
+ field,
+ &values,
+ &labels,
+ &icons,
+ &unique_ids);
+ }
+ // 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,
+ 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 +522,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 +542,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 +556,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 +565,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 +710,10 @@ void AutofillManager::OnHideAutofillUi() {
}
void AutofillManager::RemoveAutofillProfileOrCreditCard(int unique_id) {
+
+ if (!personal_data_)
+ return;
+
const AutofillDataModel* data_model = NULL;
size_t variant = 0;
if (!GetProfileOrCreditCard(unique_id, &data_model, &variant)) {
@@ -767,6 +793,7 @@ void AutofillManager::OnSetDataList(const std::vector<base::string16>& values,
void AutofillManager::OnRequestAutocomplete(
const FormData& form,
const GURL& frame_url) {
+
benm (inactive) 2013/05/23 12:02:21 nit: remove
sgurun-gerrit only 2013/05/23 17:10:01 Done.
if (!IsAutofillEnabled()) {
ReturnAutocompleteResult(WebFormElement::AutocompleteResultErrorDisabled,
FormData());
@@ -849,6 +876,7 @@ void AutofillManager::OnMaybeShowAutocheckoutBubble(
const GURL& source_url,
const content::SSLStatus& ssl_status,
const gfx::RectF& bounding_box) {
+
benm (inactive) 2013/05/23 12:02:21 nit: remove
sgurun-gerrit only 2013/05/23 17:10:01 Done.
if (!IsAutofillEnabled())
return;
@@ -865,7 +893,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 +921,10 @@ void AutofillManager::SendAutofillTypePredictions(
void AutofillManager::ImportFormData(const FormStructure& submitted_form) {
const CreditCard* imported_credit_card;
+
+ if (!personal_data_)
+ return;
+
if (!personal_data_->ImportFormData(submitted_form, &imported_credit_card))
return;
@@ -924,7 +958,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 +1025,9 @@ bool AutofillManager::GetHost(RenderViewHost** host) const {
if (!IsAutofillEnabled())
return false;
+ if (!personal_data_)
+ return false;
+
// No autofill data to return if the profiles are empty.
if (personal_data_->GetProfiles().empty() &&
personal_data_->GetCreditCards().empty()) {
@@ -1008,6 +1045,9 @@ bool AutofillManager::GetProfileOrCreditCard(
int unique_id,
const AutofillDataModel** data_model,
size_t* variant) const {
+ if (!personal_data_)
+ return false;
+
// Unpack the |unique_id| into component parts.
GUIDPair credit_card_guid;
GUIDPair profile_guid;
@@ -1157,6 +1197,9 @@ void AutofillManager::GetProfileSuggestions(
std::vector<base::string16>* labels,
std::vector<base::string16>* icons,
std::vector<int>* unique_ids) const {
+
+ if (!personal_data_)
+ return;
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 +1223,10 @@ void AutofillManager::GetCreditCardSuggestions(
std::vector<base::string16>* labels,
std::vector<base::string16>* icons,
std::vector<int>* unique_ids) const {
+
+ if (!personal_data_)
+ return;
+
std::vector<GUIDPair> guid_pairs;
personal_data_->GetCreditCardSuggestions(
type, field.value, values, labels, icons, &guid_pairs);

Powered by Google App Engine
This is Rietveld 408576698