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

Unified Diff: components/autofill/content/renderer/autofill_agent.cc

Issue 2007473004: [Autofill] Migrate ContentAutofillDriver<-->AutofillAgent IPCs to mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Name getter/setter functions properly Created 4 years, 6 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/content/renderer/autofill_agent.cc
diff --git a/components/autofill/content/renderer/autofill_agent.cc b/components/autofill/content/renderer/autofill_agent.cc
index 1254112a0bfd50123d9be23201775e211ee12810..ad5fb7725354d1357bb33b9a86eea96585af3b57 100644
--- a/components/autofill/content/renderer/autofill_agent.cc
+++ b/components/autofill/content/renderer/autofill_agent.cc
@@ -42,6 +42,7 @@
#include "content/public/common/url_constants.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h"
+#include "mojo/common/common_type_converters.h"
#include "net/cert/cert_status_flags.h"
#include "services/shell/public/cpp/interface_provider.h"
#include "services/shell/public/cpp/interface_registry.h"
@@ -179,8 +180,10 @@ AutofillAgent::AutofillAgent(content::RenderFrame* render_frame,
ignore_text_changes_(false),
is_popup_possibly_visible_(false),
is_generation_popup_possibly_visible_(false),
+ binding_(this),
weak_ptr_factory_(this) {
render_frame->GetWebFrame()->setAutofillClient(this);
+ password_autofill_agent->SetAutofillAgent(this);
// AutofillAgent is guaranteed to outlive |render_frame|.
render_frame->GetInterfaceRegistry()->AddInterface(
@@ -196,7 +199,7 @@ AutofillAgent::AutofillAgent(content::RenderFrame* render_frame,
AutofillAgent::~AutofillAgent() {}
void AutofillAgent::BindRequest(mojom::AutofillAgentRequest request) {
- bindings_.AddBinding(this, std::move(request));
+ binding_.Bind(std::move(request));
}
bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs,
@@ -205,31 +208,6 @@ bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs,
std::tie(rhs.name, rhs.origin, rhs.action, rhs.is_form_tag);
}
-bool AutofillAgent::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message)
- IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm)
- IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm)
- IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable,
- OnFieldTypePredictionsAvailable)
- IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm)
- IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm)
- IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue)
- IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue,
- OnPreviewFieldWithValue)
- IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion,
- OnAcceptDataListSuggestion)
- IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordSuggestion,
- OnFillPasswordSuggestion)
- IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion,
- OnPreviewPasswordSuggestion)
- IPC_MESSAGE_HANDLER(AutofillMsg_ShowInitialPasswordAccountSuggestions,
- OnShowInitialPasswordAccountSuggestions);
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation,
bool is_same_page_navigation) {
blink::WebFrame* frame = render_frame()->GetWebFrame();
@@ -275,7 +253,7 @@ void AutofillAgent::FocusedNodeChanged(const WebNode& node) {
if (!last_interacted_form_.isNull()) {
// Focus moved away from the last interacted form to somewhere else on
// the page.
- Send(new AutofillHostMsg_FocusNoLongerOnForm(routing_id()));
+ GetMojoAutofillDriver()->FocusNoLongerOnForm();
}
return;
}
@@ -287,7 +265,7 @@ void AutofillAgent::FocusedNodeChanged(const WebNode& node) {
(!element || last_interacted_form_ != element->form())) {
// The focused element is not part of the last interacted form (could be
// in a different form).
- Send(new AutofillHostMsg_FocusNoLongerOnForm(routing_id()));
+ GetMojoAutofillDriver()->FocusNoLongerOnForm();
return;
}
@@ -318,13 +296,13 @@ void AutofillAgent::FireHostSubmitEvents(const FormData& form_data,
// because forms with a submit handler may fire both WillSendSubmitEvent
// and WillSubmitForm, and we don't want duplicate messages.
if (!submitted_forms_.count(form_data)) {
- Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data,
- base::TimeTicks::Now()));
+ GetMojoAutofillDriver()->WillSubmitForm(form_data, base::TimeTicks::Now());
submitted_forms_.insert(form_data);
}
- if (form_submitted)
- Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data));
+ if (form_submitted) {
+ GetMojoAutofillDriver()->FormSubmitted(form_data);
+ }
}
void AutofillAgent::Shutdown() {
@@ -376,7 +354,7 @@ void AutofillAgent::FormControlElementClicked(
void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
password_autofill_agent_->TextFieldDidEndEditing(element);
- Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id()));
+ GetMojoAutofillDriver()->DidEndTextFieldEditing();
}
void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) {
@@ -441,8 +419,8 @@ void AutofillAgent::TextFieldDidChangeImpl(
FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element, &form,
&field)) {
- Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field,
- base::TimeTicks::Now()));
+ GetMojoAutofillDriver()->TextFieldDidChange(form, field,
+ base::TimeTicks::Now());
}
}
@@ -473,11 +451,10 @@ void AutofillAgent::dataListOptionsChanged(const WebInputElement& element) {
void AutofillAgent::firstUserGestureObserved() {
password_autofill_agent_->FirstUserGestureObserved();
- ConnectToMojoAutofillDriverIfNeeded();
- mojo_autofill_driver_->FirstUserGestureObserved();
+ GetMojoAutofillDriver()->FirstUserGestureObserved();
}
-void AutofillAgent::AcceptDataListSuggestion(
+void AutofillAgent::DoAcceptDataListSuggestion(
const base::string16& suggested_value) {
WebInputElement* input_element = toWebInputElement(&element_);
DCHECK(input_element);
@@ -504,18 +481,16 @@ void AutofillAgent::AcceptDataListSuggestion(
new_value = base::JoinString(parts, base::ASCIIToUTF16(","));
}
- FillFieldWithValue(new_value, input_element);
+ DoFillFieldWithValue(new_value, input_element);
}
-void AutofillAgent::OnFieldTypePredictionsAvailable(
- const std::vector<FormDataPredictions>& forms) {
- for (size_t i = 0; i < forms.size(); ++i) {
- form_cache_.ShowPredictions(forms[i]);
- }
+// mojom::AutofillAgent:
+void AutofillAgent::FirstUserGestureObservedInTab() {
+ password_autofill_agent_->FirstUserGestureObserved();
}
-void AutofillAgent::OnFillForm(int query_id, const FormData& form) {
- if (query_id != autofill_query_id_)
+void AutofillAgent::FillForm(int32_t id, const FormData& form) {
+ if (id != autofill_query_id_)
return;
was_query_node_autofilled_ = element_.isAutofilled();
@@ -523,33 +498,36 @@ void AutofillAgent::OnFillForm(int query_id, const FormData& form) {
if (!element_.form().isNull())
last_interacted_form_ = element_.form();
- Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), form,
- base::TimeTicks::Now()));
+ GetMojoAutofillDriver()->DidFillAutofillFormData(form,
+ base::TimeTicks::Now());
}
-// mojom::AutofillAgent:
-void AutofillAgent::FirstUserGestureObservedInTab() {
- password_autofill_agent_->FirstUserGestureObserved();
+void AutofillAgent::PreviewForm(int32_t id, const FormData& form) {
+ if (id != autofill_query_id_)
+ return;
+
+ was_query_node_autofilled_ = element_.isAutofilled();
+ form_util::PreviewForm(form, element_);
+
+ GetMojoAutofillDriver()->DidPreviewAutofillFormData();
}
void AutofillAgent::OnPing() {
- Send(new AutofillHostMsg_PingAck(routing_id()));
+ GetMojoAutofillDriver()->PingAck();
}
-void AutofillAgent::OnPreviewForm(int query_id, const FormData& form) {
- if (query_id != autofill_query_id_)
- return;
-
- was_query_node_autofilled_ = element_.isAutofilled();
- form_util::PreviewForm(form, element_);
- Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id()));
+void AutofillAgent::FieldTypePredictionsAvailable(
+ mojo::Array<FormDataPredictions> forms) {
+ for (size_t i = 0; i < forms.size(); ++i) {
+ form_cache_.ShowPredictions(forms[i]);
+ }
}
-void AutofillAgent::OnClearForm() {
+void AutofillAgent::ClearForm() {
form_cache_.ClearFormWithElement(element_);
}
-void AutofillAgent::OnClearPreviewedForm() {
+void AutofillAgent::ClearPreviewedForm() {
if (!element_.isNull()) {
if (password_autofill_agent_->DidClearAutofillSelection(element_))
return;
@@ -566,45 +544,40 @@ void AutofillAgent::OnClearPreviewedForm() {
}
}
-void AutofillAgent::OnFillFieldWithValue(const base::string16& value) {
+void AutofillAgent::FillFieldWithValue(const mojo::String& value) {
WebInputElement* input_element = toWebInputElement(&element_);
if (input_element) {
- FillFieldWithValue(value, input_element);
+ DoFillFieldWithValue(value.To<base::string16>(), input_element);
input_element->setAutofilled(true);
}
}
-void AutofillAgent::OnPreviewFieldWithValue(const base::string16& value) {
+void AutofillAgent::PreviewFieldWithValue(const mojo::String& value) {
WebInputElement* input_element = toWebInputElement(&element_);
if (input_element)
- PreviewFieldWithValue(value, input_element);
+ DoPreviewFieldWithValue(value.To<base::string16>(), input_element);
}
-void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) {
- AcceptDataListSuggestion(value);
+void AutofillAgent::AcceptDataListSuggestion(const mojo::String& value) {
+ DoAcceptDataListSuggestion(value.To<base::string16>());
}
-void AutofillAgent::OnFillPasswordSuggestion(const base::string16& username,
- const base::string16& password) {
+void AutofillAgent::FillPasswordSuggestion(const mojo::String& username,
+ const mojo::String& password) {
bool handled = password_autofill_agent_->FillSuggestion(
- element_,
- username,
- password);
+ element_, username.To<base::string16>(), password.To<base::string16>());
DCHECK(handled);
}
-void AutofillAgent::OnPreviewPasswordSuggestion(
- const base::string16& username,
- const base::string16& password) {
+void AutofillAgent::PreviewPasswordSuggestion(const mojo::String& username,
+ const mojo::String& password) {
bool handled = password_autofill_agent_->PreviewSuggestion(
- element_,
- username,
- password);
+ element_, username.To<base::string16>(), password.To<base::string16>());
DCHECK(handled);
}
-void AutofillAgent::OnShowInitialPasswordAccountSuggestions(
- int key,
+void AutofillAgent::ShowInitialPasswordAccountSuggestions(
+ int32_t key,
const PasswordFormFillData& form_data) {
std::vector<blink::WebInputElement> elements;
std::unique_ptr<RendererSavePasswordProgressLogger> logger;
@@ -764,26 +737,23 @@ void AutofillAgent::QueryAutofillSuggestions(
}
is_popup_possibly_visible_ = true;
- Send(new AutofillHostMsg_SetDataList(routing_id(),
- data_list_values,
- data_list_labels));
- Send(new AutofillHostMsg_QueryFormFieldAutofill(
- routing_id(),
- autofill_query_id_,
- form,
- field,
- render_frame()->GetRenderView()->ElementBoundsInWindow(element_)));
+ GetMojoAutofillDriver()->SetDataList(
+ mojo::Array<mojo::String>::From(data_list_values),
+ mojo::Array<mojo::String>::From(data_list_labels));
+ GetMojoAutofillDriver()->QueryFormFieldAutofill(
+ autofill_query_id_, form, field,
+ render_frame()->GetRenderView()->ElementBoundsInWindow(element_));
}
-void AutofillAgent::FillFieldWithValue(const base::string16& value,
- WebInputElement* node) {
+void AutofillAgent::DoFillFieldWithValue(const base::string16& value,
+ WebInputElement* node) {
base::AutoReset<bool> auto_reset(&ignore_text_changes_, true);
node->setEditingValue(value.substr(0, node->maxLength()));
}
-void AutofillAgent::PreviewFieldWithValue(const base::string16& value,
- WebInputElement* node) {
+void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value,
+ WebInputElement* node) {
was_query_node_autofilled_ = element_.isAutofilled();
node->setSuggestedValue(value.substr(0, node->maxLength()));
node->setAutofilled(true);
@@ -800,8 +770,7 @@ void AutofillAgent::ProcessForms() {
// Always communicate to browser process for topmost frame.
if (!forms.empty() || !frame->parent()) {
- Send(new AutofillHostMsg_FormsSeen(routing_id(), forms,
- forms_seen_timestamp));
+ GetMojoAutofillDriver()->FormsSeen(std::move(forms), forms_seen_timestamp);
}
}
@@ -810,7 +779,8 @@ void AutofillAgent::HidePopup() {
return;
is_popup_possibly_visible_ = false;
is_generation_popup_possibly_visible_ = false;
- Send(new AutofillHostMsg_HidePopup(routing_id()));
+
+ GetMojoAutofillDriver()->HidePopup();
}
bool AutofillAgent::IsUserGesture() const {
@@ -839,12 +809,14 @@ void AutofillAgent::ajaxSucceeded() {
password_autofill_agent_->AJAXSucceeded();
}
-void AutofillAgent::ConnectToMojoAutofillDriverIfNeeded() {
- if (mojo_autofill_driver_.is_bound() &&
- !mojo_autofill_driver_.encountered_error())
- return;
+const mojom::AutofillDriverPtr& AutofillAgent::GetMojoAutofillDriver() {
+ if (!mojo_autofill_driver_.is_bound() ||
+ mojo_autofill_driver_.encountered_error()) {
+ render_frame()->GetRemoteInterfaces()->GetInterface(
+ mojo::GetProxy(&mojo_autofill_driver_));
+ }
- render_frame()->GetRemoteInterfaces()->GetInterface(&mojo_autofill_driver_);
+ return mojo_autofill_driver_;
}
// LegacyAutofillAgent ---------------------------------------------------------

Powered by Google App Engine
This is Rietveld 408576698