summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 18:57:53 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-10 18:57:53 +0000
commit403415accf228400fc1365d5de9696348509beb8 (patch)
treecb63da5dbef81b6baa0dea28bf0d9e964185bc80
parent8ef0b11afeb11f96028f3382a08447866a7687a4 (diff)
downloadchromium_src-403415accf228400fc1365d5de9696348509beb8.zip
chromium_src-403415accf228400fc1365d5de9696348509beb8.tar.gz
chromium_src-403415accf228400fc1365d5de9696348509beb8.tar.bz2
Make RenderViewHost not know about AutoFill and AutoComplete.
This only takes care of the browser side portion, the renderer change will be done separately once the WebKit change it depends on is rolled. Review URL: http://codereview.chromium.org/5958021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70914 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete_history_manager.cc182
-rw-r--r--chrome/browser/autocomplete_history_manager.h48
-rw-r--r--chrome/browser/autocomplete_history_manager_unittest.cc6
-rw-r--r--chrome/browser/autofill/autofill_manager.cc211
-rw-r--r--chrome/browser/autofill/autofill_manager.h38
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc251
-rw-r--r--chrome/browser/autofill/autofill_metrics_unittest.cc6
-rw-r--r--chrome/browser/autofill/form_structure_browsertest.cc2
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc173
-rw-r--r--chrome/browser/renderer_host/render_view_host.h42
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.cc10
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h70
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc29
-rw-r--r--chrome/browser/tab_contents/tab_contents.h17
-rw-r--r--chrome/browser/translate/translate_manager.cc7
15 files changed, 470 insertions, 622 deletions
diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc
index 4e93aa6..84fd89d 100644
--- a/chrome/browser/autocomplete_history_manager.cc
+++ b/chrome/browser/autocomplete_history_manager.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/render_messages.h"
#include "webkit/glue/form_data.h"
using webkit_glue::FormData;
@@ -72,16 +73,13 @@ bool IsSSN(const string16& text) {
} // namespace
AutocompleteHistoryManager::AutocompleteHistoryManager(
- TabContents* tab_contents) : tab_contents_(tab_contents),
- pending_query_handle_(0) {
- DCHECK(tab_contents);
-
+ TabContents* tab_contents)
+ : tab_contents_(tab_contents),
+ pending_query_handle_(0),
+ query_id_(0) {
profile_ = tab_contents_->profile();
- DCHECK(profile_);
-
+ // May be NULL in unit tests.
web_data_service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- DCHECK(web_data_service_);
-
autofill_enabled_.Init(prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL);
}
@@ -89,47 +87,104 @@ AutocompleteHistoryManager::~AutocompleteHistoryManager() {
CancelPendingQuery();
}
-void AutocompleteHistoryManager::FormSubmitted(const FormData& form) {
- StoreFormEntriesInWebDatabase(form);
+bool AutocompleteHistoryManager::OnMessageReceived(
+ const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(AutocompleteHistoryManager, message)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_RemoveAutocompleteEntry,
+ OnRemoveAutocompleteEntry)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
}
-void AutocompleteHistoryManager::GetAutocompleteSuggestions(
- const string16& name, const string16& prefix) {
- if (!*autofill_enabled_) {
- SendSuggestions(NULL);
+void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
+ if (!*autofill_enabled_)
return;
- }
- CancelPendingQuery();
+ if (profile_->IsOffTheRecord())
+ return;
- pending_query_handle_ = web_data_service_->GetFormValuesForElementName(
- name, prefix, kMaxAutocompleteMenuItems, this);
+ // Don't save data that was submitted through JavaScript.
+ if (!form.user_submitted)
+ return;
+
+ // We put the following restriction on stored FormFields:
+ // - non-empty name
+ // - non-empty value
+ // - text field
+ // - value is not a credit card number
+ // - value is not a SSN
+ std::vector<webkit_glue::FormField> values;
+ for (std::vector<webkit_glue::FormField>::const_iterator iter =
+ form.fields.begin();
+ iter != form.fields.end(); ++iter) {
+ if (!iter->value().empty() &&
+ !iter->name().empty() &&
+ iter->form_control_type() == ASCIIToUTF16("text") &&
+ !CreditCard::IsCreditCardNumber(iter->value()) &&
+ !IsSSN(iter->value()))
+ values.push_back(*iter);
+ }
+
+ if (!values.empty() && web_data_service_)
+ web_data_service_->AddFormFields(values);
}
-void AutocompleteHistoryManager::RemoveAutocompleteEntry(
+void AutocompleteHistoryManager::OnRemoveAutocompleteEntry(
const string16& name, const string16& value) {
web_data_service_->RemoveFormValueForElementName(name, value);
}
+void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
+ int query_id,
+ const string16& name,
+ const string16& prefix,
+ const std::vector<string16>& autofill_values,
+ const std::vector<string16>& autofill_labels,
+ const std::vector<string16>& autofill_icons,
+ const std::vector<int>& autofill_unique_ids) {
+ CancelPendingQuery();
+
+ query_id_ = query_id;
+ autofill_values_ = autofill_values;
+ autofill_labels_ = autofill_labels;
+ autofill_icons_ = autofill_icons;
+ autofill_unique_ids_ = autofill_unique_ids;
+ if (!*autofill_enabled_) {
+ SendSuggestions(NULL);
+ return;
+ }
+
+ pending_query_handle_ = web_data_service_->GetFormValuesForElementName(
+ name, prefix, kMaxAutocompleteMenuItems, this);
+}
+
void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
WebDataService::Handle h,
const WDTypedResult* result) {
DCHECK(pending_query_handle_);
pending_query_handle_ = 0;
- if (*autofill_enabled_) {
- DCHECK(result);
- SendSuggestions(result);
- } else {
+ if (!*autofill_enabled_) {
SendSuggestions(NULL);
+ return;
}
+
+ DCHECK(result);
+ DCHECK(result->GetType() == AUTOFILL_VALUE_RESULT);
+ const WDResult<std::vector<string16> >* autofill_result =
+ static_cast<const WDResult<std::vector<string16> >*>(result);
+ std::vector<string16> suggestions = autofill_result->GetValue();
+ SendSuggestions(&suggestions);
}
AutocompleteHistoryManager::AutocompleteHistoryManager(
Profile* profile, WebDataService* wds) : tab_contents_(NULL),
profile_(profile),
web_data_service_(wds),
- pending_query_handle_(0) {
+ pending_query_handle_(0),
+ query_id_(0) {
autofill_enabled_.Init(
prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL);
}
@@ -138,55 +193,46 @@ void AutocompleteHistoryManager::CancelPendingQuery() {
if (pending_query_handle_) {
SendSuggestions(NULL);
web_data_service_->CancelRequest(pending_query_handle_);
+ pending_query_handle_ = 0;
}
- pending_query_handle_ = 0;
}
-void AutocompleteHistoryManager::StoreFormEntriesInWebDatabase(
- const FormData& form) {
- if (!*autofill_enabled_)
- return;
-
- if (profile_->IsOffTheRecord())
- return;
-
- // Don't save data that was submitted through JavaScript.
- if (!form.user_submitted)
- return;
-
- // We put the following restriction on stored FormFields:
- // - non-empty name
- // - non-empty value
- // - text field
- // - value is not a credit card number
- // - value is not a SSN
- std::vector<webkit_glue::FormField> values;
- for (std::vector<webkit_glue::FormField>::const_iterator iter =
- form.fields.begin();
- iter != form.fields.end(); ++iter) {
- if (!iter->value().empty() &&
- !iter->name().empty() &&
- iter->form_control_type() == ASCIIToUTF16("text") &&
- !CreditCard::IsCreditCardNumber(iter->value()) &&
- !IsSSN(iter->value()))
- values.push_back(*iter);
+void AutocompleteHistoryManager::SendSuggestions(
+ const std::vector<string16>* suggestions) {
+ if (suggestions) {
+ // Combine AutoFill and Autocomplete values into values and labels.
+ for (size_t i = 0; i < suggestions->size(); ++i) {
+ bool unique = true;
+ for (size_t j = 0; j < autofill_values_.size(); ++j) {
+ // Don't add duplicate values.
+ if (autofill_values_[j] == (*suggestions)[i]) {
+ unique = false;
+ break;
+ }
+ }
+
+ if (unique) {
+ autofill_values_.push_back((*suggestions)[i]);
+ autofill_labels_.push_back(string16());
+ autofill_icons_.push_back(string16());
+ autofill_unique_ids_.push_back(0); // 0 means no profile.
+ }
+ }
}
- if (!values.empty())
- web_data_service_->AddFormFields(values);
-}
-
-void AutocompleteHistoryManager::SendSuggestions(const WDTypedResult* result) {
RenderViewHost* host = tab_contents_->render_view_host();
- if (!host)
- return;
-
- if (result) {
- DCHECK(result->GetType() == AUTOFILL_VALUE_RESULT);
- const WDResult<std::vector<string16> >* autofill_result =
- static_cast<const WDResult<std::vector<string16> >*>(result);
- host->AutocompleteSuggestionsReturned(autofill_result->GetValue());
- } else {
- host->AutocompleteSuggestionsReturned(std::vector<string16>());
+ if (host) {
+ host->Send(new ViewMsg_AutoFillSuggestionsReturned(host->routing_id(),
+ query_id_,
+ autofill_values_,
+ autofill_labels_,
+ autofill_icons_,
+ autofill_unique_ids_));
}
+
+ query_id_ = 0;
+ autofill_values_.clear();
+ autofill_labels_.clear();
+ autofill_icons_.clear();
+ autofill_unique_ids_.clear();
}
diff --git a/chrome/browser/autocomplete_history_manager.h b/chrome/browser/autocomplete_history_manager.h
index 5752942..26a2e13 100644
--- a/chrome/browser/autocomplete_history_manager.h
+++ b/chrome/browser/autocomplete_history_manager.h
@@ -6,9 +6,11 @@
#define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_
#pragma once
+#include <vector>
+
#include "chrome/browser/prefs/pref_member.h"
-#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/webdata/web_data_service.h"
+#include "ipc/ipc_channel.h"
namespace webkit_glue {
struct FormData;
@@ -19,34 +21,43 @@ class TabContents;
// Per-tab Autocomplete history manager. Handles receiving form data from the
// renderer and the storing and retrieving of form data through WebDataService.
-class AutocompleteHistoryManager
- : public RenderViewHostDelegate::Autocomplete,
- public WebDataServiceConsumer {
+class AutocompleteHistoryManager : public IPC::Channel::Listener,
+ public WebDataServiceConsumer {
public:
explicit AutocompleteHistoryManager(TabContents* tab_contents);
virtual ~AutocompleteHistoryManager();
- // RenderViewHostDelegate::Autocomplete implementation.
- virtual void FormSubmitted(const webkit_glue::FormData& form);
- virtual void GetAutocompleteSuggestions(const string16& name,
- const string16& prefix);
- virtual void RemoveAutocompleteEntry(const string16& name,
- const string16& value);
+ // IPC::Channel::Listener implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message);
// WebDataServiceConsumer implementation.
virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
const WDTypedResult* result);
+ // Pass-through functions that are called by AutoFillManager, after it has
+ // dispatched a message.
+ void OnGetAutocompleteSuggestions(
+ int query_id,
+ const string16& name,
+ const string16& prefix,
+ const std::vector<string16>& autofill_values,
+ const std::vector<string16>& autofill_labels,
+ const std::vector<string16>& autofill_icons,
+ const std::vector<int>& autofill_unique_ids);
+ void OnFormSubmitted(const webkit_glue::FormData& form);
+
protected:
friend class AutocompleteHistoryManagerTest;
+ friend class AutoFillManagerTest;
// For tests.
AutocompleteHistoryManager(Profile* profile, WebDataService* wds);
- private:
+ void SendSuggestions(const std::vector<string16>* suggestions);
void CancelPendingQuery();
- void StoreFormEntriesInWebDatabase(const webkit_glue::FormData& form);
- void SendSuggestions(const WDTypedResult* suggestions);
+
+ private:
+ void OnRemoveAutocompleteEntry(const string16& name, const string16& value);
TabContents* tab_contents_;
Profile* profile_;
@@ -54,10 +65,15 @@ class AutocompleteHistoryManager
BooleanPrefMember autofill_enabled_;
- // When the manager makes a request from WebDataService, the database
- // is queried on another thread, we record the query handle until we
- // get called back.
+ // When the manager makes a request from WebDataService, the database is
+ // queried on another thread, we record the query handle until we get called
+ // back. We also store the autofill results so we can send them together.
WebDataService::Handle pending_query_handle_;
+ int query_id_;
+ std::vector<string16> autofill_values_;
+ std::vector<string16> autofill_labels_;
+ std::vector<string16> autofill_icons_;
+ std::vector<int> autofill_unique_ids_;
DISALLOW_COPY_AND_ASSIGN(AutocompleteHistoryManager);
};
diff --git a/chrome/browser/autocomplete_history_manager_unittest.cc b/chrome/browser/autocomplete_history_manager_unittest.cc
index 409225f2..cfc0c83 100644
--- a/chrome/browser/autocomplete_history_manager_unittest.cc
+++ b/chrome/browser/autocomplete_history_manager_unittest.cc
@@ -63,7 +63,7 @@ TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) {
form.fields.push_back(valid_cc);
EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0);
- autocomplete_manager_->FormSubmitted(form);
+ autocomplete_manager_->OnFormSubmitted(form);
}
// Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The
@@ -87,7 +87,7 @@ TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) {
form.fields.push_back(invalid_cc);
EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1);
- autocomplete_manager_->FormSubmitted(form);
+ autocomplete_manager_->OnFormSubmitted(form);
}
// Tests that SSNs are not sent to the WebDatabase to be saved.
@@ -108,5 +108,5 @@ TEST_F(AutocompleteHistoryManagerTest, SSNValue) {
form.fields.push_back(ssn);
EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0);
- autocomplete_manager_->FormSubmitted(form);
+ autocomplete_manager_->OnFormSubmitted(form);
}
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 1623752..1010a90 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -9,8 +9,10 @@
#include "app/l10n_util.h"
#include "base/basictypes.h"
+#include "base/command_line.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete_history_manager.h"
#include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
#include "chrome/browser/autofill/autofill_dialog.h"
#include "chrome/browser/autofill/autofill_metrics.h"
@@ -21,9 +23,14 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/ui/browser_list.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/guid.h"
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
#include "grit/generated_resources.h"
#include "webkit/glue/form_data.h"
@@ -162,7 +169,30 @@ void AutoFillManager::RegisterUserPrefs(PrefService* prefs) {
kAutoFillNegativeUploadRateDefaultValue);
}
-void AutoFillManager::FormSubmitted(const FormData& form) {
+bool AutoFillManager::OnMessageReceived(const IPC::Message& message) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(AutoFillManager, message)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_FormsSeen, OnFormsSeen)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_FormSubmitted, OnFormSubmitted)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_QueryFormFieldAutoFill,
+ OnQueryFormFieldAutoFill)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ShowAutoFillDialog, OnShowAutoFillDialog)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_FillAutoFillFormData,
+ OnFillAutoFillFormData)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_DidFillAutoFillFormData,
+ OnDidFillAutoFillFormData)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_DidShowAutoFillSuggestions,
+ OnDidShowAutoFillSuggestions)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+void AutoFillManager::OnFormSubmitted(const FormData& form) {
+ // Let AutoComplete know as well.
+ tab_contents_->autocomplete_history_manager()->OnFormSubmitted(form);
+
if (!IsAutoFillEnabled())
return;
@@ -190,90 +220,84 @@ void AutoFillManager::FormSubmitted(const FormData& form) {
HandleSubmit();
}
-void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) {
+void AutoFillManager::OnFormsSeen(const std::vector<FormData>& forms) {
if (!IsAutoFillEnabled())
return;
ParseForms(forms);
}
-bool AutoFillManager::GetAutoFillSuggestions(const FormData& form,
- const FormField& field) {
- RenderViewHost* host = NULL;
- FormStructure* form_structure = NULL;
- AutoFillField* autofill_field = NULL;
- if (!GetHost(personal_data_->profiles(),
- personal_data_->credit_cards(),
- &host) ||
- !FindCachedFormAndField(form, field, &form_structure, &autofill_field))
- return false;
-
- DCHECK(host);
- DCHECK(form_structure);
- DCHECK(autofill_field);
-
- // Don't send suggestions for forms that aren't auto-fillable.
- if (!form_structure->IsAutoFillable(false))
- return false;
-
+void AutoFillManager::OnQueryFormFieldAutoFill(
+ int query_id,
+ const webkit_glue::FormData& form,
+ const webkit_glue::FormField& field) {
std::vector<string16> values;
std::vector<string16> labels;
std::vector<string16> icons;
std::vector<int> unique_ids;
- AutoFillType type(autofill_field->type());
- bool is_filling_credit_card = (type.group() == AutoFillType::CREDIT_CARD);
- if (is_filling_credit_card) {
- GetCreditCardSuggestions(
- form_structure, field, type, &values, &labels, &icons, &unique_ids);
- } else {
- GetProfileSuggestions(
- 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());
-
- // No suggestions.
- if (values.empty())
- return false;
+ RenderViewHost* host = NULL;
+ FormStructure* form_structure = NULL;
+ AutoFillField* autofill_field = NULL;
+ if (GetHost(
+ personal_data_->profiles(), personal_data_->credit_cards(), &host) &&
+ FindCachedFormAndField(form, field, &form_structure, &autofill_field) &&
+ // Don't send suggestions for forms that aren't auto-fillable.
+ form_structure->IsAutoFillable(false)) {
+ AutoFillType type(autofill_field->type());
+ bool is_filling_credit_card = (type.group() == AutoFillType::CREDIT_CARD);
+ if (is_filling_credit_card) {
+ GetCreditCardSuggestions(
+ form_structure, field, type, &values, &labels, &icons, &unique_ids);
+ } else {
+ GetProfileSuggestions(
+ form_structure, field, type, &values, &labels, &icons, &unique_ids);
+ }
- // 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.
- int warning = 0;
- if (!form_structure->IsAutoFillable(true))
- warning = IDS_AUTOFILL_WARNING_FORM_DISABLED;
- 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, string16());
- icons.assign(1, string16());
- unique_ids.assign(1, -1);
- host->AutoFillSuggestionsReturned(values, labels, icons, unique_ids);
- return true;
- }
+ DCHECK_EQ(values.size(), labels.size());
+ DCHECK_EQ(values.size(), icons.size());
+ DCHECK_EQ(values.size(), unique_ids.size());
+
+ 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.
+ int warning = 0;
+ if (!form_structure->IsAutoFillable(true))
+ warning = IDS_AUTOFILL_WARNING_FORM_DISABLED;
+ 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, string16());
+ icons.assign(1, string16());
+ unique_ids.assign(1, -1);
+ } else {
+ // If the form is auto-filled and the renderer is querying 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.
+ if (FormIsAutoFilled(form_structure, form, is_filling_credit_card)) {
+ labels.assign(labels.size(), string16());
+ icons.assign(icons.size(), string16());
+ }
- // If the form is auto-filled and the renderer is querying 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.
- if (FormIsAutoFilled(form_structure, form, is_filling_credit_card)) {
- labels.assign(labels.size(), string16());
- icons.assign(icons.size(), string16());
+ RemoveDuplicateSuggestions(&values, &labels, &icons, &unique_ids);
+ }
+ }
}
- RemoveDuplicateSuggestions(&values, &labels, &icons, &unique_ids);
- host->AutoFillSuggestionsReturned(values, labels, icons, unique_ids);
- return 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.
+ tab_contents_->autocomplete_history_manager()->OnGetAutocompleteSuggestions(
+ query_id, field.name(), field.value(), values, labels, icons, unique_ids);
}
-bool AutoFillManager::FillAutoFillFormData(int query_id,
- const FormData& form,
- const FormField& field,
- int unique_id) {
+void AutoFillManager::OnFillAutoFillFormData(int query_id,
+ const FormData& form,
+ const FormField& field,
+ int unique_id) {
const std::vector<AutoFillProfile*>& profiles = personal_data_->profiles();
const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards();
RenderViewHost* host = NULL;
@@ -281,7 +305,7 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
AutoFillField* autofill_field = NULL;
if (!GetHost(profiles, credit_cards, &host) ||
!FindCachedFormAndField(form, field, &form_structure, &autofill_field))
- return false;
+ return;
DCHECK(host);
DCHECK(form_structure);
@@ -320,7 +344,7 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
}
if (!profile && !credit_card)
- return false;
+ return;
FormData result = form;
@@ -342,8 +366,9 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
}
}
- host->AutoFillFormDataFilled(query_id, result);
- return true;
+ host->Send(new ViewMsg_AutoFillFormDataFilled(
+ host->routing_id(), query_id, result));
+ return;
}
// The list of fields in |form_structure| and |result.fields| often match
@@ -384,19 +409,36 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
}
autofilled_forms_signatures_.push_front(form_structure->FormSignature());
- host->AutoFillFormDataFilled(query_id, result);
- return true;
+ host->Send(new ViewMsg_AutoFillFormDataFilled(
+ host->routing_id(), query_id, result));
}
-void AutoFillManager::ShowAutoFillDialog() {
- ::ShowAutoFillDialog(tab_contents_->GetContentNativeView(),
- personal_data_,
- tab_contents_->profile()->GetOriginalProfile());
+void AutoFillManager::OnShowAutoFillDialog() {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableTabbedOptions)) {
+ Browser* browser = BrowserList::GetLastActive();
+ if (browser)
+ browser->ShowOptionsTab(chrome::kAutoFillSubPage);
+ return;
+ }
+
+ ShowAutoFillDialog(tab_contents_->GetContentNativeView(),
+ personal_data_,
+ tab_contents_->profile()->GetOriginalProfile());
}
-void AutoFillManager::Reset() {
- upload_form_structure_.reset();
- form_structures_.reset();
+void AutoFillManager::OnDidFillAutoFillFormData() {
+ NotificationService::current()->Notify(
+ NotificationType::AUTOFILL_DID_FILL_FORM_DATA,
+ Source<RenderViewHost>(tab_contents_->render_view_host()),
+ NotificationService::NoDetails());
+}
+
+void AutoFillManager::OnDidShowAutoFillSuggestions() {
+ NotificationService::current()->Notify(
+ NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS,
+ Source<RenderViewHost>(tab_contents_->render_view_host()),
+ NotificationService::NoDetails());
}
void AutoFillManager::OnLoadedAutoFillHeuristics(
@@ -518,6 +560,11 @@ void AutoFillManager::UploadFormData() {
}
}
+void AutoFillManager::Reset() {
+ upload_form_structure_.reset();
+ form_structures_.reset();
+}
+
void AutoFillManager::OnInfoBarClosed(bool should_save) {
if (should_save)
personal_data_->SaveImportedCreditCard();
@@ -560,7 +607,7 @@ bool AutoFillManager::GetHost(const std::vector<AutoFillProfile*>& profiles,
return false;
*host = tab_contents_->render_view_host();
- if (!(*host))
+ if (!*host)
return false;
return true;
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index 750aa75..08be41c 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -16,7 +16,7 @@
#include "chrome/browser/autofill/autofill_dialog.h"
#include "chrome/browser/autofill/autofill_download.h"
#include "chrome/browser/autofill/personal_data_manager.h"
-#include "chrome/browser/renderer_host/render_view_host_delegate.h"
+#include "ipc/ipc_channel.h"
class AutoFillCCInfoBarDelegate;
class AutoFillProfile;
@@ -24,6 +24,7 @@ class AutoFillMetrics;
class CreditCard;
class FormStructure;
class PrefService;
+class RenderViewHost;
class TabContents;
namespace webkit_glue {
@@ -33,7 +34,7 @@ class FormField;
// Manages saving and restoring the user's personal information entered into web
// forms.
-class AutoFillManager : public RenderViewHostDelegate::AutoFill,
+class AutoFillManager : public IPC::Channel::Listener,
public AutoFillDownloadManager::Observer {
public:
explicit AutoFillManager(TabContents* tab_contents);
@@ -48,17 +49,8 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
// Returns the TabContents hosting this AutoFillManager.
TabContents* tab_contents() const { return tab_contents_; }
- // RenderViewHostDelegate::AutoFill implementation:
- virtual void FormSubmitted(const webkit_glue::FormData& form);
- virtual void FormsSeen(const std::vector<webkit_glue::FormData>& forms);
- virtual bool GetAutoFillSuggestions(const webkit_glue::FormData& form,
- const webkit_glue::FormField& field);
- virtual bool FillAutoFillFormData(int query_id,
- const webkit_glue::FormData& form,
- const webkit_glue::FormField& field,
- int unique_id);
- virtual void ShowAutoFillDialog();
- virtual void Reset();
+ // IPC::Channel::Listener implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message);
// Called by the AutoFillCCInfoBarDelegate when the user interacts with the
// infobar.
@@ -81,6 +73,9 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
// Uploads the form data to the AutoFill server.
void UploadFormData();
+ // Reset cache.
+ void Reset();
+
protected:
// For tests.
AutoFillManager();
@@ -107,6 +102,19 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
void UnpackGUIDs(int id, std::string* cc_guid, std::string* profile_guid);
private:
+ void OnFormSubmitted(const webkit_glue::FormData& form);
+ void OnFormsSeen(const std::vector<webkit_glue::FormData>& forms);
+ void OnQueryFormFieldAutoFill(int query_id,
+ const webkit_glue::FormData& form,
+ const webkit_glue::FormField& field);
+ void OnFillAutoFillFormData(int query_id,
+ const webkit_glue::FormData& form,
+ const webkit_glue::FormField& field,
+ int unique_id);
+ void OnShowAutoFillDialog();
+ void OnDidFillAutoFillFormData();
+ void OnDidShowAutoFillSuggestions();
+
// Fills |host| with the RenderViewHost for this tab.
// Returns false if AutoFill is disabled or if the host is unavailable.
bool GetHost(const std::vector<AutoFillProfile*>& profiles,
@@ -204,6 +212,7 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
std::map<std::string, int> guid_id_map_;
std::map<int, std::string> id_guid_map_;
+ friend class AutoFillManagerTest;
friend class FormStructureBrowserTest;
FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillCreditCardForm);
FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillAddressForm);
@@ -212,6 +221,9 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FillPhoneNumber);
FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FormChangesRemoveField);
FRIEND_TEST_ALL_PREFIXES(AutoFillManagerTest, FormChangesAddField);
+ FRIEND_TEST_ALL_PREFIXES(AutoFillMetricsTest, QualityMetrics);
+ FRIEND_TEST_ALL_PREFIXES(AutoFillMetricsTest,
+ NoQualityMetricsForNonAutoFillableForms);
DISALLOW_COPY_AND_ASSIGN(AutoFillManager);
};
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index b454143..b109441 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -13,6 +13,7 @@
#include "base/stringprintf.h"
#include "base/tuple.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete_history_manager.h"
#include "chrome/browser/autofill/autofill_common_test.h"
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/autofill/autofill_profile.h"
@@ -25,6 +26,7 @@
#include "chrome/common/ipc_test_sink.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
+#include "chrome/test/testing_profile.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -432,6 +434,9 @@ class AutoFillManagerTest : public RenderViewHostTestHarness {
}
virtual void SetUp() {
+ profile_.reset(new TestingProfile());
+ profile_->CreateWebDataService(false);
+
RenderViewHostTestHarness::SetUp();
test_personal_data_ = new TestPersonalDataManager();
autofill_manager_.reset(new TestAutoFillManager(contents(),
@@ -440,6 +445,37 @@ class AutoFillManagerTest : public RenderViewHostTestHarness {
Profile* profile() { return contents()->profile(); }
+ void GetAutoFillSuggestions(int query_id,
+ const webkit_glue::FormData& form,
+ const webkit_glue::FormField& field) {
+ autofill_manager_->OnQueryFormFieldAutoFill(query_id, form, field);
+ }
+
+ void GetAutoFillSuggestions(const webkit_glue::FormData& form,
+ const webkit_glue::FormField& field) {
+ GetAutoFillSuggestions(kDefaultPageID, form, field);
+ }
+
+ void AutocompleteSuggestionsReturned(const std::vector<string16>& result) {
+ autofill_manager_->tab_contents()->autocomplete_history_manager()->
+ SendSuggestions(&result);
+ }
+
+ void FormsSeen(const std::vector<webkit_glue::FormData>& forms) {
+ autofill_manager_->OnFormsSeen(forms);
+ }
+
+ void FormSubmitted(const webkit_glue::FormData& form) {
+ autofill_manager_->OnFormSubmitted(form);
+ }
+
+ void FillAutoFillFormData(int query_id,
+ const webkit_glue::FormData& form,
+ const webkit_glue::FormField& field,
+ int unique_id) {
+ autofill_manager_->OnFillAutoFillFormData(query_id, form, field, unique_id);
+ }
+
bool GetAutoFillSuggestionsMessage(int* page_id,
std::vector<string16>* values,
std::vector<string16>* labels,
@@ -463,6 +499,10 @@ class AutoFillManagerTest : public RenderViewHostTestHarness {
*icons = autofill_param.d;
if (unique_ids)
*unique_ids = autofill_param.e;
+
+ autofill_manager_->tab_contents()->autocomplete_history_manager()->
+ CancelPendingQuery();
+ process()->sink().ClearMessages();
return true;
}
@@ -478,6 +518,8 @@ class AutoFillManagerTest : public RenderViewHostTestHarness {
*page_id = autofill_param.a;
if (results)
*results = autofill_param.b;
+
+ process()->sink().ClearMessages();
return true;
}
@@ -496,15 +538,14 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsEmptyValue) {
FormData form;
CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
const FormField& field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -512,8 +553,8 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsEmptyValue) {
std::vector<string16> labels;
std::vector<string16> icons;
std::vector<int> unique_ids;
- EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
- &unique_ids));
+ GetAutoFillSuggestionsMessage(
+ &page_id, &values, &labels, &icons, &unique_ids);
string16 expected_values[] = {
ASCIIToUTF16("Elvis"),
@@ -539,17 +580,16 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMatchCharacter) {
FormData form;
CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
FormField field;
autofill_test::CreateTestFormField("First Name", "firstname", "E", "text",
&field);
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -592,10 +632,10 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsUnknownFields) {
form.fields.push_back(field);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
+ EXPECT_FALSE(GetAutoFillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL));
}
// Test that we cull duplicate profile suggestions.
@@ -604,7 +644,7 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsWithDuplicates) {
FormData form;
CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
// Add a duplicate profile.
AutoFillProfile* duplicate_profile = static_cast<AutoFillProfile*>(
@@ -612,12 +652,11 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsWithDuplicates) {
autofill_manager_->AddProfile(duplicate_profile);
const FormField& field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -649,14 +688,14 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsAutofillDisabledByUser) {
FormData form;
CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
// Disable AutoFill.
autofill_manager_->set_autofill_enabled(false);
const FormField& field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
+ EXPECT_FALSE(GetAutoFillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL));
}
// Test that we return a warning explaining that autofill suggestions are
@@ -667,15 +706,14 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) {
CreateTestAddressFormData(&form);
form.method = ASCIIToUTF16("GET");
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
const FormField& field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -698,15 +736,13 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) {
// Now add some Autocomplete suggestions. We should return the autocomplete
// suggestions and the warning; these will be culled by the renderer.
- process()->sink().ClearMessages();
const int kPageID2 = 2;
- rvh()->ResetAutoFillState(kPageID2);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(kPageID2, form, field);
std::vector<string16> suggestions;
suggestions.push_back(ASCIIToUTF16("Jay"));
suggestions.push_back(ASCIIToUTF16("Jason"));
- rvh()->AutocompleteSuggestionsReturned(suggestions);
+ AutocompleteSuggestionsReturned(suggestions);
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
@@ -725,7 +761,8 @@ TEST_F(AutoFillManagerTest, GetProfileSuggestionsMethodGet) {
// Now clear the test profiles and try again -- we shouldn't return a warning.
test_personal_data_->ClearAutoFillProfiles();
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
+ EXPECT_FALSE(GetAutoFillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL));
}
// Test that we return all credit card profile suggestions when all form fields
@@ -735,15 +772,14 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsEmptyValue) {
FormData form;
CreateTestCreditCardFormData(&form, true);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
FormField field = form.fields[1];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -779,17 +815,16 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsMatchCharacter) {
FormData form;
CreateTestCreditCardFormData(&form, true);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
FormField field;
autofill_test::CreateTestFormField(
"Card Number", "cardnumber", "4", "text", &field);
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -816,15 +851,14 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonCCNumber) {
FormData form;
CreateTestCreditCardFormData(&form, true);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
const FormField& field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -860,15 +894,14 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
FormData form;
CreateTestCreditCardFormData(&form, false);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
const FormField& field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -891,15 +924,13 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
// Now add some Autocomplete suggestions. We should show the autocomplete
// suggestions and the warning.
- process()->sink().ClearMessages();
const int kPageID2 = 2;
- rvh()->ResetAutoFillState(kPageID2);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(kPageID2, form, field);
std::vector<string16> suggestions;
suggestions.push_back(ASCIIToUTF16("Jay"));
suggestions.push_back(ASCIIToUTF16("Jason"));
- rvh()->AutocompleteSuggestionsReturned(suggestions);
+ AutocompleteSuggestionsReturned(suggestions);
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
&unique_ids));
@@ -917,7 +948,8 @@ TEST_F(AutoFillManagerTest, GetCreditCardSuggestionsNonHTTPS) {
// Clear the test credit cards and try again -- we shouldn't return a warning.
test_personal_data_->ClearCreditCards();
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
+ EXPECT_FALSE(GetAutoFillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL));
}
// Test that we return profile and credit card suggestions for combined forms.
@@ -927,15 +959,14 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) {
CreateTestAddressFormData(&form);
CreateTestCreditCardFormData(&form, true);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
FormField field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right address suggestions to the renderer.
int page_id = 0;
@@ -960,16 +991,14 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestions) {
kDefaultPageID, arraysize(expected_values), expected_values,
expected_labels, expected_icons, expected_unique_ids);
- process()->sink().ClearMessages();
const int kPageID2 = 2;
autofill_test::CreateTestFormField(
"Card Number", "cardnumber", "", "text", &field);
- rvh()->ResetAutoFillState(kPageID2);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(kPageID2, form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the credit card suggestions to the renderer.
page_id = 0;
@@ -1004,15 +1033,14 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
CreateTestAddressFormData(&form);
CreateTestCreditCardFormData(&form, false);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
FormField field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right address suggestions to the renderer.
int page_id = 0;
@@ -1037,16 +1065,14 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
kDefaultPageID, arraysize(expected_values), expected_values,
expected_labels, expected_icons, expected_unique_ids);
- process()->sink().ClearMessages();
autofill_test::CreateTestFormField(
"Card Number", "cardnumber", "", "text", &field);
const int kPageID2 = 2;
- rvh()->ResetAutoFillState(kPageID2);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(kPageID2, form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
EXPECT_TRUE(GetAutoFillSuggestionsMessage(&page_id, &values, &labels, &icons,
@@ -1064,7 +1090,8 @@ TEST_F(AutoFillManagerTest, GetAddressAndCreditCardSuggestionsNonHttps) {
// Clear the test credit cards and try again -- we shouldn't return a warning.
test_personal_data_->ClearCreditCards();
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
+ EXPECT_FALSE(GetAutoFillSuggestionsMessage(NULL, NULL, NULL, NULL, NULL));
}
// Test that we correctly combine autofill and autocomplete suggestions.
@@ -1073,11 +1100,10 @@ TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) {
FormData form;
CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
const FormField& field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// Add some Autocomplete suggestions.
// This triggers the combined message send.
@@ -1086,7 +1112,7 @@ TEST_F(AutoFillManagerTest, GetCombinedAutoFillAndAutocompleteSuggestions) {
// This suggestion is a duplicate, and should be trimmed.
suggestions.push_back(ASCIIToUTF16("Elvis"));
suggestions.push_back(ASCIIToUTF16("Jason"));
- rvh()->AutocompleteSuggestionsReturned(suggestions);
+ AutocompleteSuggestionsReturned(suggestions);
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -1123,17 +1149,16 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsWhenFormIsAutoFilled) {
FormData form;
CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
// Mark one of the fields as filled.
form.fields[2].set_autofilled(true);
const FormField& field = form.fields[0];
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -1166,17 +1191,16 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsForAutocompleteOnly) {
"Some Field", "somefield", "", "text", &field);
form.fields.push_back(field);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_FALSE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// Add some Autocomplete suggestions.
// This triggers the combined message send.
std::vector<string16> suggestions;
suggestions.push_back(ASCIIToUTF16("one"));
suggestions.push_back(ASCIIToUTF16("two"));
- rvh()->AutocompleteSuggestionsReturned(suggestions);
+ AutocompleteSuggestionsReturned(suggestions);
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -1206,7 +1230,7 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsWithDuplicateValues) {
FormData form;
CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
// |profile| will be owned by the mock PersonalDataManager.
AutoFillProfile* profile = new AutoFillProfile;
@@ -1217,12 +1241,11 @@ TEST_F(AutoFillManagerTest, GetFieldSuggestionsWithDuplicateValues) {
FormField& field = form.fields[0];
field.set_autofilled(true);
- rvh()->ResetAutoFillState(kDefaultPageID);
- EXPECT_TRUE(autofill_manager_->GetAutoFillSuggestions(form, field));
+ GetAutoFillSuggestions(form, field);
// No suggestions provided, so send an empty vector as the results.
// This triggers the combined message send.
- rvh()->AutocompleteSuggestionsReturned(std::vector<string16>());
+ AutocompleteSuggestionsReturned(std::vector<string16>());
// Test that we sent the right message to the renderer.
int page_id = 0;
@@ -1251,12 +1274,12 @@ TEST_F(AutoFillManagerTest, FillAddressForm) {
FormData form;
CreateTestAddressFormData(&form);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
kDefaultPageID, form, form.fields[0],
- autofill_manager_->PackGUIDs(std::string(), guid)));
+ autofill_manager_->PackGUIDs(std::string(), guid));
int page_id = 0;
FormData results;
@@ -1270,12 +1293,12 @@ TEST_F(AutoFillManagerTest, FillCreditCardForm) {
FormData form;
CreateTestCreditCardFormData(&form, true);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
std::string guid = autofill_manager_->GetLabeledCreditCard("First")->guid();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
kDefaultPageID, form, *form.fields.begin(),
- autofill_manager_->PackGUIDs(guid, std::string())));
+ autofill_manager_->PackGUIDs(guid, std::string()));
int page_id = 0;
FormData results;
@@ -1290,13 +1313,13 @@ TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) {
CreateTestAddressFormData(&form);
CreateTestCreditCardFormData(&form, true);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
// First fill the address data.
std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
kDefaultPageID, form, form.fields[0],
- autofill_manager_->PackGUIDs(std::string(), guid)));
+ autofill_manager_->PackGUIDs(std::string(), guid));
int page_id = 0;
FormData results;
@@ -1307,12 +1330,11 @@ TEST_F(AutoFillManagerTest, FillAddressAndCreditCardForm) {
}
// Now fill the credit card data.
- process()->sink().ClearMessages();
const int kPageID2 = 2;
guid = autofill_manager_->GetLabeledCreditCard("First")->guid();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
kPageID2, form, form.fields.back(),
- autofill_manager_->PackGUIDs(guid, std::string())));
+ autofill_manager_->PackGUIDs(guid, std::string()));
page_id = 0;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
@@ -1331,13 +1353,13 @@ TEST_F(AutoFillManagerTest, FillAutoFilledForm) {
form.fields[4].set_autofilled(true);
CreateTestCreditCardFormData(&form, true);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
// First fill the address data.
std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
kDefaultPageID, form, *form.fields.begin(),
- autofill_manager_->PackGUIDs(std::string(), guid)));
+ autofill_manager_->PackGUIDs(std::string(), guid));
int page_id = 0;
FormData results;
@@ -1350,12 +1372,11 @@ TEST_F(AutoFillManagerTest, FillAutoFilledForm) {
}
// Now fill the credit card data.
- process()->sink().ClearMessages();
const int kPageID2 = 2;
guid = autofill_manager_->GetLabeledCreditCard("First")->guid();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
kPageID2, form, form.fields.back(),
- autofill_manager_->PackGUIDs(guid, std::string())));
+ autofill_manager_->PackGUIDs(guid, std::string()));
page_id = 0;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
@@ -1372,11 +1393,10 @@ TEST_F(AutoFillManagerTest, FillAutoFilledForm) {
iter->set_autofilled(true);
}
- process()->sink().ClearMessages();
const int kPageID3 = 3;
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
kPageID3, form, *form.fields.rbegin(),
- autofill_manager_->PackGUIDs(guid, std::string())));
+ autofill_manager_->PackGUIDs(guid, std::string()));
page_id = 0;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
@@ -1421,7 +1441,7 @@ TEST_F(AutoFillManagerTest, FillPhoneNumber) {
form.fields.push_back(field);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
AutoFillProfile *work_profile = autofill_manager_->GetLabeledProfile("Work");
ASSERT_TRUE(work_profile != NULL);
@@ -1435,10 +1455,9 @@ TEST_F(AutoFillManagerTest, FillPhoneNumber) {
// The page ID sent to the AutoFillManager from the RenderView, used to send
// an IPC message back to the renderer.
int page_id = 100 - i;
- process()->sink().ClearMessages();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
page_id, form, *form.fields.begin(),
- autofill_manager_->PackGUIDs(std::string(), work_profile->guid())));
+ autofill_manager_->PackGUIDs(std::string(), work_profile->guid()));
page_id = 0;
FormData results;
EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
@@ -1468,15 +1487,15 @@ TEST_F(AutoFillManagerTest, FormChangesRemoveField) {
form.fields.insert(form.fields.begin() + 3, field);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
// Now, after the call to |FormsSeen|, we remove the field before filling.
form.fields.erase(form.fields.begin() + 3);
std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
kDefaultPageID, form, form.fields[0],
- autofill_manager_->PackGUIDs(std::string(), guid)));
+ autofill_manager_->PackGUIDs(std::string(), guid));
int page_id = 0;
FormData results;
@@ -1499,15 +1518,15 @@ TEST_F(AutoFillManagerTest, FormChangesAddField) {
pos = form.fields.erase(pos);
std::vector<FormData> forms(1, form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
// Now, after the call to |FormsSeen|, we restore the field before filling.
form.fields.insert(pos, field);
std::string guid = autofill_manager_->GetLabeledProfile("Home")->guid();
- EXPECT_TRUE(autofill_manager_->FillAutoFillFormData(
+ FillAutoFillFormData(
kDefaultPageID, form, form.fields[0],
- autofill_manager_->PackGUIDs(std::string(), guid)));
+ autofill_manager_->PackGUIDs(std::string(), guid));
int page_id = 0;
FormData results;
@@ -1537,10 +1556,10 @@ TEST_F(AutoFillManagerTest, HiddenFields) {
// Set up our form data.
std::vector<FormData> forms;
forms.push_back(form);
- autofill_manager_->FormsSeen(forms);
+ FormsSeen(forms);
// Submit the form.
- autofill_manager_->FormSubmitted(form);
+ FormSubmitted(form);
// TODO(jhawkins): We can't use the InfoBar anymore to determine if we saved
// fields. Need to query the PDM.
diff --git a/chrome/browser/autofill/autofill_metrics_unittest.cc b/chrome/browser/autofill/autofill_metrics_unittest.cc
index 4521296..ca4dce3 100644
--- a/chrome/browser/autofill/autofill_metrics_unittest.cc
+++ b/chrome/browser/autofill/autofill_metrics_unittest.cc
@@ -189,7 +189,7 @@ TEST_F(AutoFillMetricsTest, QualityMetrics) {
Log(AutoFillMetrics::FIELD_SUBMITTED));
// Simulate form submission.
- EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form));
+ EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
}
// Test that we don't log quality metrics for non-autofillable forms.
@@ -214,7 +214,7 @@ TEST_F(AutoFillMetricsTest, NoQualityMetricsForNonAutoFillableForms) {
// Simulate form submission.
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutoFillMetrics::FIELD_SUBMITTED)).Times(0);
- EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form));
+ EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
// Search forms are not auto-fillable.
form.action = GURL("http://example.com/search?q=Elvis%20Presley");
@@ -225,5 +225,5 @@ TEST_F(AutoFillMetricsTest, NoQualityMetricsForNonAutoFillableForms) {
// Simulate form submission.
EXPECT_CALL(*autofill_manager_->metric_logger(),
Log(AutoFillMetrics::FIELD_SUBMITTED)).Times(0);
- EXPECT_NO_FATAL_FAILURE(autofill_manager_->FormSubmitted(form));
+ EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
}
diff --git a/chrome/browser/autofill/form_structure_browsertest.cc b/chrome/browser/autofill/form_structure_browsertest.cc
index f6bda60..301ff96 100644
--- a/chrome/browser/autofill/form_structure_browsertest.cc
+++ b/chrome/browser/autofill/form_structure_browsertest.cc
@@ -236,7 +236,7 @@ IN_PROC_BROWSER_TEST_F(FormStructureBrowserTest, HTMLFiles) {
VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
AutoFillManager* autofill_manager =
- browser()->GetSelectedTabContents()->GetAutoFillManager();
+ browser()->GetSelectedTabContents()->autofill_manager();
ASSERT_NE(static_cast<AutoFillManager*>(NULL), autofill_manager);
std::vector<FormStructure*> forms = GetFormStructures(*autofill_manager);
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 447745f..5b01cf7 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -121,7 +121,6 @@ RenderViewHost::RenderViewHost(SiteInstance* instance,
sudden_termination_allowed_(false),
session_storage_namespace_(session_storage),
is_extension_process_(false),
- autofill_query_id_(0),
save_accessibility_tree_for_testing_(false),
render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING) {
if (!session_storage_namespace_) {
@@ -795,11 +794,9 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
OnMsgRunBeforeUnloadConfirm)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ShowModalHTMLDialog,
OnMsgShowModalHTMLDialog)
- IPC_MESSAGE_HANDLER(ViewHostMsg_FormsSeen, OnMsgFormsSeen)
IPC_MESSAGE_HANDLER(ViewHostMsg_PasswordFormsFound, OnMsgPasswordFormsFound)
IPC_MESSAGE_HANDLER(ViewHostMsg_PasswordFormsVisible,
OnMsgPasswordFormsVisible)
- IPC_MESSAGE_HANDLER(ViewHostMsg_FormSubmitted, OnMsgFormSubmitted)
IPC_MESSAGE_HANDLER(ViewHostMsg_StartDragging, OnMsgStartDragging)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateDragCursor, OnUpdateDragCursor)
IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus)
@@ -837,18 +834,6 @@ bool RenderViewHost::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_FORWARD(ViewHostMsg_JSOutOfMemory, delegate_,
RenderViewHostDelegate::OnJSOutOfMemory)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK)
- IPC_MESSAGE_HANDLER(ViewHostMsg_QueryFormFieldAutoFill,
- OnQueryFormFieldAutoFill)
- IPC_MESSAGE_HANDLER(ViewHostMsg_DidShowAutoFillSuggestions,
- OnDidShowAutoFillSuggestions)
- IPC_MESSAGE_HANDLER(ViewHostMsg_RemoveAutocompleteEntry,
- OnRemoveAutocompleteEntry)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ShowAutoFillDialog,
- OnShowAutoFillDialog)
- IPC_MESSAGE_HANDLER(ViewHostMsg_FillAutoFillFormData,
- OnFillAutoFillFormData)
- IPC_MESSAGE_HANDLER(ViewHostMsg_DidFillAutoFillFormData,
- OnDidFillAutoFillFormData)
IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDesktopNotification,
OnShowDesktopNotification)
IPC_MESSAGE_HANDLER(ViewHostMsg_CancelDesktopNotification,
@@ -1378,13 +1363,6 @@ void RenderViewHost::MediaPlayerActionAt(const gfx::Point& location,
Send(new ViewMsg_MediaPlayerActionAt(routing_id(), location, action));
}
-void RenderViewHost::OnMsgFormsSeen(const std::vector<FormData>& forms) {
- RenderViewHostDelegate::AutoFill* autofill_delegate =
- delegate_->GetAutoFillDelegate();
- if (autofill_delegate)
- autofill_delegate->FormsSeen(forms);
-}
-
void RenderViewHost::OnMsgPasswordFormsFound(
const std::vector<PasswordForm>& forms) {
delegate_->PasswordFormsFound(forms);
@@ -1395,18 +1373,6 @@ void RenderViewHost::OnMsgPasswordFormsVisible(
delegate_->PasswordFormsVisible(visible_forms);
}
-void RenderViewHost::OnMsgFormSubmitted(const FormData& form) {
- RenderViewHostDelegate::Autocomplete* autocomplete_delegate =
- delegate_->GetAutocompleteDelegate();
- if (autocomplete_delegate)
- autocomplete_delegate->FormSubmitted(form);
-
- RenderViewHostDelegate::AutoFill* autofill_delegate =
- delegate_->GetAutoFillDelegate();
- if (autofill_delegate)
- autofill_delegate->FormSubmitted(form);
-}
-
void RenderViewHost::OnMsgStartDragging(
const WebDropData& drop_data,
WebDragOperationsMask drag_operations_mask,
@@ -1599,136 +1565,6 @@ void RenderViewHost::OnMsgShouldCloseACK(bool proceed) {
}
}
-void RenderViewHost::OnQueryFormFieldAutoFill(int query_id,
- const FormData& form,
- const FormField& field) {
- ResetAutoFillState(query_id);
-
- // We first query the autofill delegate for suggestions. We keep track of the
- // results it gives us, which we will later combine with the autocomplete
- // suggestions.
- RenderViewHostDelegate::AutoFill* autofill_delegate =
- delegate_->GetAutoFillDelegate();
- if (autofill_delegate)
- autofill_delegate->GetAutoFillSuggestions(form, field);
-
- // Now query the Autocomplete delegate for suggestions. These will be combined
- // with the saved autofill suggestions in |AutocompleteSuggestionsReturned()|.
- RenderViewHostDelegate::Autocomplete* autocomplete_delegate =
- delegate_->GetAutocompleteDelegate();
- if (autocomplete_delegate) {
- autocomplete_delegate->GetAutocompleteSuggestions(field.name(),
- field.value());
- } else {
- AutocompleteSuggestionsReturned(std::vector<string16>());
- }
-}
-
-void RenderViewHost::OnDidShowAutoFillSuggestions() {
- NotificationService::current()->Notify(
- NotificationType::AUTOFILL_DID_SHOW_SUGGESTIONS,
- Source<RenderViewHost>(this),
- NotificationService::NoDetails());
-}
-
-void RenderViewHost::OnRemoveAutocompleteEntry(const string16& field_name,
- const string16& value) {
- RenderViewHostDelegate::Autocomplete* autocomplete_delegate =
- delegate_->GetAutocompleteDelegate();
- if (autocomplete_delegate)
- autocomplete_delegate->RemoveAutocompleteEntry(field_name, value);
-}
-
-void RenderViewHost::OnShowAutoFillDialog() {
- if (!CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableTabbedOptions)) {
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
- return;
- browser->ShowOptionsTab(chrome::kAutoFillSubPage);
- } else {
- RenderViewHostDelegate::AutoFill* autofill_delegate =
- delegate_->GetAutoFillDelegate();
- if (!autofill_delegate)
- return;
-
- autofill_delegate->ShowAutoFillDialog();
- }
-}
-
-void RenderViewHost::OnFillAutoFillFormData(int query_id,
- const FormData& form,
- const FormField& field,
- int unique_id) {
- RenderViewHostDelegate::AutoFill* autofill_delegate =
- delegate_->GetAutoFillDelegate();
- if (!autofill_delegate)
- return;
-
- autofill_delegate->FillAutoFillFormData(query_id, form, field, unique_id);
-}
-
-void RenderViewHost::OnDidFillAutoFillFormData() {
- NotificationService::current()->Notify(
- NotificationType::AUTOFILL_DID_FILL_FORM_DATA,
- Source<RenderViewHost>(this),
- NotificationService::NoDetails());
-}
-
-void RenderViewHost::ResetAutoFillState(int query_id) {
- autofill_query_id_ = query_id;
-
- autofill_values_.clear();
- autofill_labels_.clear();
- autofill_icons_.clear();
- autofill_unique_ids_.clear();
-}
-
-void RenderViewHost::AutoFillSuggestionsReturned(
- const std::vector<string16>& values,
- const std::vector<string16>& labels,
- const std::vector<string16>& icons,
- const std::vector<int>& unique_ids) {
- autofill_values_.assign(values.begin(), values.end());
- autofill_labels_.assign(labels.begin(), labels.end());
- autofill_icons_.assign(icons.begin(), icons.end());
- autofill_unique_ids_.assign(unique_ids.begin(), unique_ids.end());
-}
-
-void RenderViewHost::AutocompleteSuggestionsReturned(
- const std::vector<string16>& suggestions) {
- // Combine AutoFill and Autocomplete values into values and labels.
- for (size_t i = 0; i < suggestions.size(); ++i) {
- bool unique = true;
- for (size_t j = 0; j < autofill_values_.size(); ++j) {
- // Don't add duplicate values.
- if (autofill_values_[j] == suggestions[i]) {
- unique = false;
- break;
- }
- }
-
- if (unique) {
- autofill_values_.push_back(suggestions[i]);
- autofill_labels_.push_back(string16());
- autofill_icons_.push_back(string16());
- autofill_unique_ids_.push_back(0); // 0 means no profile.
- }
- }
-
- Send(new ViewMsg_AutoFillSuggestionsReturned(routing_id(),
- autofill_query_id_,
- autofill_values_,
- autofill_labels_,
- autofill_icons_,
- autofill_unique_ids_));
-}
-
-void RenderViewHost::AutoFillFormDataFilled(int query_id,
- const FormData& form) {
- Send(new ViewMsg_AutoFillFormDataFilled(routing_id(), query_id, form));
-}
-
void RenderViewHost::WindowMoveOrResizeStarted() {
Send(new ViewMsg_MoveOrResizeStarted(routing_id()));
}
@@ -1899,15 +1735,6 @@ void RenderViewHost::TranslatePage(int page_id,
const std::string& translate_script,
const std::string& source_lang,
const std::string& target_lang) {
- // Ideally we'd have a better way to uniquely identify form control elements,
- // but we don't have that yet. So before start translation, we clear the
- // current form and re-parse it in AutoFillManager first to get the new
- // labels.
- RenderViewHostDelegate::AutoFill* autofill_delegate =
- delegate_->GetAutoFillDelegate();
- if (autofill_delegate)
- autofill_delegate->Reset();
-
Send(new ViewMsg_TranslatePage(routing_id(), page_id, translate_script,
source_lang, target_lang));
}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index e341daf..8f68cfd 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -423,23 +423,6 @@ class RenderViewHost : public RenderWidgetHost {
// set to false when creating a renderer-initiated window via window.open.
void AllowScriptToClose(bool visible);
- // Resets the stored AutoFill state.
- void ResetAutoFillState(int query_id);
-
- // Called by the AutoFillManager when the list of suggestions is ready.
- void AutoFillSuggestionsReturned(const std::vector<string16>& values,
- const std::vector<string16>& labels,
- const std::vector<string16>& icons,
- const std::vector<int>& unique_ids);
-
- // Called by the AutocompleteHistoryManager when the list of suggestions is
- // ready.
- void AutocompleteSuggestionsReturned(
- const std::vector<string16>& suggestions);
-
- // Called by the AutoFillManager when the FormData has been filled out.
- void AutoFillFormDataFilled(int query_id, const webkit_glue::FormData& form);
-
// Notifies the Renderer that a move or resize of its containing window has
// started (this is used to hide the autocomplete popups if any).
void WindowMoveOrResizeStarted();
@@ -630,13 +613,10 @@ class RenderViewHost : public RenderWidgetHost {
void OnMsgShowModalHTMLDialog(const GURL& url, int width, int height,
const std::string& json_arguments,
IPC::Message* reply_msg);
- void OnMsgFormsSeen(
- const std::vector<webkit_glue::FormData>& forms);
void OnMsgPasswordFormsFound(
const std::vector<webkit_glue::PasswordForm>& forms);
void OnMsgPasswordFormsVisible(
const std::vector<webkit_glue::PasswordForm>& visible_forms);
- void OnMsgFormSubmitted(const webkit_glue::FormData& forms);
void OnMsgStartDragging(const WebDropData& drop_data,
WebKit::WebDragOperationsMask operations_allowed,
const SkBitmap& image,
@@ -677,19 +657,6 @@ class RenderViewHost : public RenderWidgetHost {
void OnDidGetApplicationInfo(int32 page_id, const WebApplicationInfo& info);
void OnInstallApplication(const WebApplicationInfo& info);
void OnMsgShouldCloseACK(bool proceed);
- void OnQueryFormFieldAutoFill(int request_id,
- const webkit_glue::FormData& form,
- const webkit_glue::FormField& field);
- void OnDidShowAutoFillSuggestions();
- void OnRemoveAutocompleteEntry(const string16& field_name,
- const string16& value);
- void OnShowAutoFillDialog();
- void OnFillAutoFillFormData(int query_id,
- const webkit_glue::FormData& form,
- const webkit_glue::FormField& field,
- int unique_id);
- void OnDidFillAutoFillFormData();
-
void OnShowDesktopNotification(
const ViewHostMsg_ShowNotification_Params& params);
void OnCancelDesktopNotification(int notification_id);
@@ -809,15 +776,6 @@ class RenderViewHost : public RenderWidgetHost {
// what process type we use.
bool is_extension_process_;
- // TODO(isherman): Consider splitting these off into a helper class.
- // AutoFill and Autocomplete suggestions. We accumulate these separately and
- // send them back to the renderer together.
- std::vector<string16> autofill_values_;
- std::vector<string16> autofill_labels_;
- std::vector<string16> autofill_icons_;
- std::vector<int> autofill_unique_ids_;
- int autofill_query_id_;
-
// Whether the accessibility tree should be saved, for unit testing.
bool save_accessibility_tree_for_testing_;
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.cc b/chrome/browser/renderer_host/render_view_host_delegate.cc
index a58eea5..4fb6a09 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.cc
+++ b/chrome/browser/renderer_host/render_view_host_delegate.cc
@@ -50,16 +50,6 @@ RenderViewHostDelegate::GetFavIconDelegate() {
return NULL;
}
-RenderViewHostDelegate::Autocomplete*
-RenderViewHostDelegate::GetAutocompleteDelegate() {
- return NULL;
-}
-
-RenderViewHostDelegate::AutoFill*
-RenderViewHostDelegate::GetAutoFillDelegate() {
- return NULL;
-}
-
RenderViewHostDelegate::BookmarkDrag*
RenderViewHostDelegate::GetBookmarkDragDelegate() {
return NULL;
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index 34c206bec..a626030 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -465,73 +465,6 @@ class RenderViewHostDelegate : public IPC::Channel::Listener {
virtual ~FavIcon() {}
};
- // Autocomplete --------------------------------------------------------------
- // Interface for Autocomplete-related functions.
-
- class Autocomplete {
- public:
- // Forms fillable by Autocomplete have been detected in the page.
- virtual void FormSubmitted(const webkit_glue::FormData& form) = 0;
-
- // Called to retrieve a list of suggestions from the web database given
- // the name of the field |field_name| and what the user has already typed
- // in the field |user_text|. Appeals to the database thread to perform the
- // query. When the database thread is finished, the AutocompleteHistory
- // manager retrieves the calling RenderViewHost and then passes the vector
- // of suggestions to RenderViewHost::AutocompleteSuggestionsReturned.
- virtual void GetAutocompleteSuggestions(const string16& field_name,
- const string16& user_text) = 0;
-
- // Called when the user has indicated that she wants to remove the specified
- // Autocomplete suggestion from the database.
- virtual void RemoveAutocompleteEntry(const string16& field_name,
- const string16& value) = 0;
-
- protected:
- virtual ~Autocomplete() {}
- };
-
- // AutoFill ------------------------------------------------------------------
- // Interface for AutoFill-related functions.
-
- class AutoFill {
- public:
- // Called when the user submits a form.
- virtual void FormSubmitted(const webkit_glue::FormData& form) = 0;
-
- // Called when the frame has finished loading and there are forms in the
- // frame.
- virtual void FormsSeen(const std::vector<webkit_glue::FormData>& forms) = 0;
-
- // Called to retrieve a list of AutoFill suggestions for the portion of the
- // |form| containing |field|, given the current state of the |form|.
- // Returns true to indicate that RenderViewHost::AutoFillSuggestionsReturned
- // has been called.
- virtual bool GetAutoFillSuggestions(
- const webkit_glue::FormData& form,
- const webkit_glue::FormField& field) = 0;
-
- // Called to fill the |form| with AutoFill profile information that matches
- // the |unique_id| key. If the portion of the form containing |field| has
- // been autofilled already, only fills |field|.
- // Returns true to indicate that RenderViewHost::AutoFillFormDataFilled
- // has been called.
- virtual bool FillAutoFillFormData(int query_id,
- const webkit_glue::FormData& form,
- const webkit_glue::FormField& field,
- int unique_id) = 0;
-
- // Called when the user selects the 'AutoFill Options...' suggestions in the
- // AutoFill popup.
- virtual void ShowAutoFillDialog() = 0;
-
- // Reset cache in AutoFillManager.
- virtual void Reset() = 0;
-
- protected:
- virtual ~AutoFill() {}
- };
-
// BookmarkDrag --------------------------------------------------------------
// Interface for forwarding bookmark drag and drop to extenstions.
@@ -612,8 +545,7 @@ class RenderViewHostDelegate : public IPC::Channel::Listener {
virtual Save* GetSaveDelegate();
virtual Printing* GetPrintingDelegate();
virtual FavIcon* GetFavIconDelegate();
- virtual Autocomplete* GetAutocompleteDelegate();
- virtual AutoFill* GetAutoFillDelegate();
+
virtual BookmarkDrag* GetBookmarkDragDelegate();
virtual SSL* GetSSLDelegate();
virtual FileSelect* GetFileSelectDelegate();
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 698d691..563279e 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -433,6 +433,11 @@ TabContents::TabContents(Profile* profile,
// Set-up the showing of the omnibox search infobar if applicable.
if (OmniboxSearchHint::IsEnabled(profile))
omnibox_search_hint_.reset(new OmniboxSearchHint(this));
+
+ autofill_manager_.reset(new AutoFillManager(this));
+ message_filters_.push_back(autofill_manager_.get());
+ autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
+ message_filters_.push_back(autocomplete_history_manager_.get());
}
TabContents::~TabContents() {
@@ -552,6 +557,11 @@ void TabContents::RegisterUserPrefs(PrefService* prefs) {
}
bool TabContents::OnMessageReceived(const IPC::Message& message) {
+ for (size_t i = 0; i < message_filters_.size(); ++i) {
+ if (message_filters_[i]->OnMessageReceived(message))
+ return true;
+ }
+
bool handled = true;
bool message_is_ok = true;
IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
@@ -586,12 +596,6 @@ bool TabContents::HostsExtension() const {
return GetURL().SchemeIs(chrome::kExtensionScheme);
}
-AutoFillManager* TabContents::GetAutoFillManager() {
- if (autofill_manager_.get() == NULL)
- autofill_manager_.reset(new AutoFillManager(this));
- return autofill_manager_.get();
-}
-
PluginInstaller* TabContents::GetPluginInstaller() {
if (plugin_installer_.get() == NULL)
plugin_installer_.reset(new PluginInstaller(this));
@@ -1959,8 +1963,7 @@ void TabContents::DidNavigateMainFramePostCommit(
DidNavigateMainFramePostCommit(details, params));
// Clear the cache of forms in AutoFill.
- if (autofill_manager_.get())
- autofill_manager_->Reset();
+ autofill_manager_->Reset();
}
void TabContents::DidNavigateAnyFramePostCommit(
@@ -2415,16 +2418,6 @@ RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
return &fav_icon_helper_;
}
-RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
- if (autocomplete_history_manager_.get() == NULL)
- autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
- return autocomplete_history_manager_.get();
-}
-
-RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
- return GetAutoFillManager();
-}
-
RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
return GetSSLHelper();
}
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 7ef622c..d21095f 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -150,9 +150,6 @@ class TabContents : public PageNavigator,
// Returns true if contains content rendered by an extension.
bool HostsExtension() const;
- // Returns the AutoFillManager, creating it if necessary.
- AutoFillManager* GetAutoFillManager();
-
// Returns the PluginInstaller, creating it if necessary.
PluginInstaller* GetPluginInstaller();
@@ -752,6 +749,11 @@ class TabContents : public PageNavigator,
int content_restrictions() const { return content_restrictions_; }
+ AutocompleteHistoryManager* autocomplete_history_manager() {
+ return autocomplete_history_manager_.get();
+ }
+ AutoFillManager* autofill_manager() { return autofill_manager_.get(); }
+
private:
friend class NavigationController;
// Used to access the child_windows_ (ConstrainedWindowList) for testing
@@ -950,8 +952,6 @@ class TabContents : public PageNavigator,
virtual RenderViewHostDelegate::Save* GetSaveDelegate();
virtual RenderViewHostDelegate::Printing* GetPrintingDelegate();
virtual RenderViewHostDelegate::FavIcon* GetFavIconDelegate();
- virtual RenderViewHostDelegate::Autocomplete* GetAutocompleteDelegate();
- virtual RenderViewHostDelegate::AutoFill* GetAutoFillDelegate();
virtual RenderViewHostDelegate::SSL* GetSSLDelegate();
virtual RenderViewHostDelegate::FileSelect* GetFileSelectDelegate();
virtual AutomationResourceRoutingDelegate*
@@ -1117,10 +1117,10 @@ class TabContents : public PageNavigator,
// SavePackage, lazily created.
scoped_refptr<SavePackage> save_package_;
- // AutocompleteHistoryManager, lazily created.
+ // AutocompleteHistoryManager.
scoped_ptr<AutocompleteHistoryManager> autocomplete_history_manager_;
- // AutoFillManager, lazily created.
+ // AutoFillManager.
scoped_ptr<AutoFillManager> autofill_manager_;
// PluginInstaller, lazily created.
@@ -1340,7 +1340,8 @@ class TabContents : public PageNavigator,
// (full-page plugins for now only) permissions.
int content_restrictions_;
- // ---------------------------------------------------------------------------
+ // All the IPC message filters for this render view.
+ std::vector<IPC::Channel::Listener*> message_filters_;
DISALLOW_COPY_AND_ASSIGN(TabContents);
};
diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc
index 84b576e..40fbae6 100644
--- a/chrome/browser/translate/translate_manager.cc
+++ b/chrome/browser/translate/translate_manager.cc
@@ -11,6 +11,7 @@
#include "base/singleton.h"
#include "base/string_split.h"
#include "base/string_util.h"
+#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service.h"
@@ -510,6 +511,12 @@ void TranslateManager::DoTranslatePage(TabContents* tab,
tab->language_state().set_translation_pending(true);
tab->render_view_host()->TranslatePage(entry->page_id(), translate_script,
source_lang, target_lang);
+
+ // Ideally we'd have a better way to uniquely identify form control elements,
+ // but we don't have that yet. So before start translation, we clear the
+ // current form and re-parse it in AutoFillManager first to get the new
+ // labels.
+ tab->autofill_manager()->Reset();
}
void TranslateManager::PageTranslated(TabContents* tab,