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

Side by Side 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: gn, gyp, test codes all done Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/content/renderer/autofill_agent.h" 5 #include "components/autofill/content/renderer/autofill_agent.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <tuple> 9 #include <tuple>
10 10
(...skipping 24 matching lines...) Expand all
35 #include "components/autofill/core/common/form_data_predictions.h" 35 #include "components/autofill/core/common/form_data_predictions.h"
36 #include "components/autofill/core/common/form_field_data.h" 36 #include "components/autofill/core/common/form_field_data.h"
37 #include "components/autofill/core/common/password_form.h" 37 #include "components/autofill/core/common/password_form.h"
38 #include "components/autofill/core/common/password_form_fill_data.h" 38 #include "components/autofill/core/common/password_form_fill_data.h"
39 #include "components/autofill/core/common/save_password_progress_logger.h" 39 #include "components/autofill/core/common/save_password_progress_logger.h"
40 #include "content/public/common/content_switches.h" 40 #include "content/public/common/content_switches.h"
41 #include "content/public/common/ssl_status.h" 41 #include "content/public/common/ssl_status.h"
42 #include "content/public/common/url_constants.h" 42 #include "content/public/common/url_constants.h"
43 #include "content/public/renderer/render_frame.h" 43 #include "content/public/renderer/render_frame.h"
44 #include "content/public/renderer/render_view.h" 44 #include "content/public/renderer/render_view.h"
45 #include "mojo/common/common_type_converters.h"
45 #include "net/cert/cert_status_flags.h" 46 #include "net/cert/cert_status_flags.h"
46 #include "services/shell/public/cpp/interface_provider.h" 47 #include "services/shell/public/cpp/interface_provider.h"
47 #include "services/shell/public/cpp/interface_registry.h" 48 #include "services/shell/public/cpp/interface_registry.h"
48 #include "third_party/WebKit/public/platform/WebURLRequest.h" 49 #include "third_party/WebKit/public/platform/WebURLRequest.h"
49 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 50 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
50 #include "third_party/WebKit/public/web/WebDataSource.h" 51 #include "third_party/WebKit/public/web/WebDataSource.h"
51 #include "third_party/WebKit/public/web/WebDocument.h" 52 #include "third_party/WebKit/public/web/WebDocument.h"
52 #include "third_party/WebKit/public/web/WebElementCollection.h" 53 #include "third_party/WebKit/public/web/WebElementCollection.h"
53 #include "third_party/WebKit/public/web/WebFormControlElement.h" 54 #include "third_party/WebKit/public/web/WebFormControlElement.h"
54 #include "third_party/WebKit/public/web/WebFormElement.h" 55 #include "third_party/WebKit/public/web/WebFormElement.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 : content::RenderFrameObserver(render_frame), 173 : content::RenderFrameObserver(render_frame),
173 form_cache_(*render_frame->GetWebFrame()), 174 form_cache_(*render_frame->GetWebFrame()),
174 password_autofill_agent_(password_autofill_agent), 175 password_autofill_agent_(password_autofill_agent),
175 password_generation_agent_(password_generation_agent), 176 password_generation_agent_(password_generation_agent),
176 legacy_(render_frame->GetRenderView(), this), 177 legacy_(render_frame->GetRenderView(), this),
177 autofill_query_id_(0), 178 autofill_query_id_(0),
178 was_query_node_autofilled_(false), 179 was_query_node_autofilled_(false),
179 ignore_text_changes_(false), 180 ignore_text_changes_(false),
180 is_popup_possibly_visible_(false), 181 is_popup_possibly_visible_(false),
181 is_generation_popup_possibly_visible_(false), 182 is_generation_popup_possibly_visible_(false),
183 binding_(this),
182 weak_ptr_factory_(this) { 184 weak_ptr_factory_(this) {
183 render_frame->GetWebFrame()->setAutofillClient(this); 185 render_frame->GetWebFrame()->setAutofillClient(this);
186 password_autofill_agent->SetAutofillAgent(this);
184 187
185 // AutofillAgent is guaranteed to outlive |render_frame|. 188 // AutofillAgent is guaranteed to outlive |render_frame|.
186 render_frame->GetInterfaceRegistry()->AddInterface( 189 render_frame->GetInterfaceRegistry()->AddInterface(
187 base::Bind(&AutofillAgent::BindRequest, base::Unretained(this))); 190 base::Bind(&AutofillAgent::BindRequest, base::Unretained(this)));
188 191
189 // This owns itself, and will delete itself when |render_frame| is destructed 192 // This owns itself, and will delete itself when |render_frame| is destructed
190 // (same as AutofillAgent). This object must be constructed after 193 // (same as AutofillAgent). This object must be constructed after
191 // AutofillAgent so that password generation UI is shown before password 194 // AutofillAgent so that password generation UI is shown before password
192 // manager UI (see https://crbug.com/498545). 195 // manager UI (see https://crbug.com/498545).
193 new PageClickTracker(render_frame, this); 196 new PageClickTracker(render_frame, this);
194 } 197 }
195 198
196 AutofillAgent::~AutofillAgent() {} 199 AutofillAgent::~AutofillAgent() {}
197 200
198 void AutofillAgent::BindRequest(mojom::AutofillAgentRequest request) { 201 void AutofillAgent::BindRequest(mojom::AutofillAgentRequest request) {
199 bindings_.AddBinding(this, std::move(request)); 202 binding_.Bind(std::move(request));
200 } 203 }
201 204
202 bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs, 205 bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs,
203 const FormData& rhs) const { 206 const FormData& rhs) const {
204 return std::tie(lhs.name, lhs.origin, lhs.action, lhs.is_form_tag) < 207 return std::tie(lhs.name, lhs.origin, lhs.action, lhs.is_form_tag) <
205 std::tie(rhs.name, rhs.origin, rhs.action, rhs.is_form_tag); 208 std::tie(rhs.name, rhs.origin, rhs.action, rhs.is_form_tag);
206 } 209 }
207 210
208 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) {
209 bool handled = true;
210 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message)
211 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm)
212 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm)
213 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable,
214 OnFieldTypePredictionsAvailable)
215 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm)
216 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm)
217 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue)
218 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue,
219 OnPreviewFieldWithValue)
220 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion,
221 OnAcceptDataListSuggestion)
222 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordSuggestion,
223 OnFillPasswordSuggestion)
224 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion,
225 OnPreviewPasswordSuggestion)
226 IPC_MESSAGE_HANDLER(AutofillMsg_ShowInitialPasswordAccountSuggestions,
227 OnShowInitialPasswordAccountSuggestions);
228 IPC_MESSAGE_UNHANDLED(handled = false)
229 IPC_END_MESSAGE_MAP()
230 return handled;
231 }
232
233 void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation, 211 void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation,
234 bool is_same_page_navigation) { 212 bool is_same_page_navigation) {
235 blink::WebFrame* frame = render_frame()->GetWebFrame(); 213 blink::WebFrame* frame = render_frame()->GetWebFrame();
236 // TODO(dvadym): check if we need to check if it is main frame navigation 214 // TODO(dvadym): check if we need to check if it is main frame navigation
237 // http://crbug.com/443155 215 // http://crbug.com/443155
238 if (frame->parent()) 216 if (frame->parent())
239 return; // Not a top-level navigation. 217 return; // Not a top-level navigation.
240 218
241 if (is_same_page_navigation) { 219 if (is_same_page_navigation) {
242 OnSamePageNavigationCompleted(); 220 OnSamePageNavigationCompleted();
(...skipping 24 matching lines...) Expand all
267 HidePopup(); 245 HidePopup();
268 } 246 }
269 247
270 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { 248 void AutofillAgent::FocusedNodeChanged(const WebNode& node) {
271 HidePopup(); 249 HidePopup();
272 250
273 if (node.isNull() || !node.isElementNode()) { 251 if (node.isNull() || !node.isElementNode()) {
274 if (!last_interacted_form_.isNull()) { 252 if (!last_interacted_form_.isNull()) {
275 // Focus moved away from the last interacted form to somewhere else on 253 // Focus moved away from the last interacted form to somewhere else on
276 // the page. 254 // the page.
277 Send(new AutofillHostMsg_FocusNoLongerOnForm(routing_id())); 255 GetMojoAutofillDriver()->FocusNoLongerOnForm();
278 } 256 }
279 return; 257 return;
280 } 258 }
281 259
282 WebElement web_element = node.toConst<WebElement>(); 260 WebElement web_element = node.toConst<WebElement>();
283 const WebInputElement* element = toWebInputElement(&web_element); 261 const WebInputElement* element = toWebInputElement(&web_element);
284 262
285 if (!last_interacted_form_.isNull() && 263 if (!last_interacted_form_.isNull() &&
286 (!element || last_interacted_form_ != element->form())) { 264 (!element || last_interacted_form_ != element->form())) {
287 // The focused element is not part of the last interacted form (could be 265 // The focused element is not part of the last interacted form (could be
288 // in a different form). 266 // in a different form).
289 Send(new AutofillHostMsg_FocusNoLongerOnForm(routing_id())); 267 GetMojoAutofillDriver()->FocusNoLongerOnForm();
290 return; 268 return;
291 } 269 }
292 270
293 if (!element || !element->isEnabled() || element->isReadOnly() || 271 if (!element || !element->isEnabled() || element->isReadOnly() ||
294 !element->isTextField()) 272 !element->isTextField())
295 return; 273 return;
296 274
297 element_ = *element; 275 element_ = *element;
298 } 276 }
299 277
(...skipping 10 matching lines...) Expand all
310 288
311 FireHostSubmitEvents(form_data, form_submitted); 289 FireHostSubmitEvents(form_data, form_submitted);
312 } 290 }
313 291
314 void AutofillAgent::FireHostSubmitEvents(const FormData& form_data, 292 void AutofillAgent::FireHostSubmitEvents(const FormData& form_data,
315 bool form_submitted) { 293 bool form_submitted) {
316 // We remember when we have fired this IPC for this form in this frame load, 294 // We remember when we have fired this IPC for this form in this frame load,
317 // because forms with a submit handler may fire both WillSendSubmitEvent 295 // because forms with a submit handler may fire both WillSendSubmitEvent
318 // and WillSubmitForm, and we don't want duplicate messages. 296 // and WillSubmitForm, and we don't want duplicate messages.
319 if (!submitted_forms_.count(form_data)) { 297 if (!submitted_forms_.count(form_data)) {
320 Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data, 298 GetMojoAutofillDriver()->WillSubmitForm(form_data, base::TimeTicks::Now());
321 base::TimeTicks::Now()));
322 submitted_forms_.insert(form_data); 299 submitted_forms_.insert(form_data);
323 } 300 }
324 301
325 if (form_submitted) 302 if (form_submitted) {
326 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data)); 303 GetMojoAutofillDriver()->FormSubmitted(form_data);
304 }
327 } 305 }
328 306
329 void AutofillAgent::Shutdown() { 307 void AutofillAgent::Shutdown() {
330 legacy_.Shutdown(); 308 legacy_.Shutdown();
331 weak_ptr_factory_.InvalidateWeakPtrs(); 309 weak_ptr_factory_.InvalidateWeakPtrs();
332 } 310 }
333 311
334 void AutofillAgent::FocusChangeComplete() { 312 void AutofillAgent::FocusChangeComplete() {
335 WebDocument doc = render_frame()->GetWebFrame()->document(); 313 WebDocument doc = render_frame()->GetWebFrame()->document();
336 WebElement focused_element; 314 WebElement focused_element;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // the initial click (not focused yet), only show password suggestions. 346 // the initial click (not focused yet), only show password suggestions.
369 options.show_full_suggestion_list = 347 options.show_full_suggestion_list =
370 options.show_full_suggestion_list || was_focused; 348 options.show_full_suggestion_list || was_focused;
371 options.show_password_suggestions_only = !was_focused; 349 options.show_password_suggestions_only = !was_focused;
372 } 350 }
373 ShowSuggestions(element, options); 351 ShowSuggestions(element, options);
374 } 352 }
375 353
376 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { 354 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
377 password_autofill_agent_->TextFieldDidEndEditing(element); 355 password_autofill_agent_->TextFieldDidEndEditing(element);
378 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); 356 GetMojoAutofillDriver()->DidEndTextFieldEditing();
379 } 357 }
380 358
381 void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) { 359 void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) {
382 DCHECK(toWebInputElement(&element) || form_util::IsTextAreaElement(element)); 360 DCHECK(toWebInputElement(&element) || form_util::IsTextAreaElement(element));
383 361
384 if (ignore_text_changes_) 362 if (ignore_text_changes_)
385 return; 363 return;
386 364
387 // Disregard text changes that aren't caused by user gestures or pastes. Note 365 // Disregard text changes that aren't caused by user gestures or pastes. Note
388 // that pastes aren't necessarily user gestures because Blink's conception of 366 // that pastes aren't necessarily user gestures because Blink's conception of
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 408 }
431 409
432 ShowSuggestionsOptions options; 410 ShowSuggestionsOptions options;
433 options.requires_caret_at_end = true; 411 options.requires_caret_at_end = true;
434 ShowSuggestions(element, options); 412 ShowSuggestions(element, options);
435 413
436 FormData form; 414 FormData form;
437 FormFieldData field; 415 FormFieldData field;
438 if (form_util::FindFormAndFieldForFormControlElement(element, &form, 416 if (form_util::FindFormAndFieldForFormControlElement(element, &form,
439 &field)) { 417 &field)) {
440 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, 418 GetMojoAutofillDriver()->TextFieldDidChange(form, field,
441 base::TimeTicks::Now())); 419 base::TimeTicks::Now());
442 } 420 }
443 } 421 }
444 422
445 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, 423 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element,
446 const WebKeyboardEvent& event) { 424 const WebKeyboardEvent& event) {
447 if (event.windowsKeyCode == ui::VKEY_DOWN || 425 if (event.windowsKeyCode == ui::VKEY_DOWN ||
448 event.windowsKeyCode == ui::VKEY_UP) { 426 event.windowsKeyCode == ui::VKEY_UP) {
449 ShowSuggestionsOptions options; 427 ShowSuggestionsOptions options;
450 options.autofill_on_empty_values = true; 428 options.autofill_on_empty_values = true;
451 options.requires_caret_at_end = true; 429 options.requires_caret_at_end = true;
(...skipping 10 matching lines...) Expand all
462 void AutofillAgent::dataListOptionsChanged(const WebInputElement& element) { 440 void AutofillAgent::dataListOptionsChanged(const WebInputElement& element) {
463 if (!is_popup_possibly_visible_ || !element.focused()) 441 if (!is_popup_possibly_visible_ || !element.focused())
464 return; 442 return;
465 443
466 TextFieldDidChangeImpl(element); 444 TextFieldDidChangeImpl(element);
467 } 445 }
468 446
469 void AutofillAgent::firstUserGestureObserved() { 447 void AutofillAgent::firstUserGestureObserved() {
470 password_autofill_agent_->FirstUserGestureObserved(); 448 password_autofill_agent_->FirstUserGestureObserved();
471 449
472 ConnectToMojoAutofillDriverIfNeeded(); 450 GetMojoAutofillDriver()->FirstUserGestureObserved();
473 mojo_autofill_driver_->FirstUserGestureObserved();
474 } 451 }
475 452
476 void AutofillAgent::AcceptDataListSuggestion( 453 void AutofillAgent::DoAcceptDataListSuggestion(
477 const base::string16& suggested_value) { 454 const base::string16& suggested_value) {
478 WebInputElement* input_element = toWebInputElement(&element_); 455 WebInputElement* input_element = toWebInputElement(&element_);
479 DCHECK(input_element); 456 DCHECK(input_element);
480 base::string16 new_value = suggested_value; 457 base::string16 new_value = suggested_value;
481 // If this element takes multiple values then replace the last part with 458 // If this element takes multiple values then replace the last part with
482 // the suggestion. 459 // the suggestion.
483 if (input_element->isMultiple() && input_element->isEmailField()) { 460 if (input_element->isMultiple() && input_element->isEmailField()) {
484 std::vector<base::string16> parts = base::SplitString( 461 std::vector<base::string16> parts = base::SplitString(
485 base::StringPiece16(input_element->editingValue()), 462 base::StringPiece16(input_element->editingValue()),
486 base::ASCIIToUTF16(","), base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); 463 base::ASCIIToUTF16(","), base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
487 if (parts.size() == 0) 464 if (parts.size() == 0)
488 parts.push_back(base::string16()); 465 parts.push_back(base::string16());
489 466
490 base::string16 last_part = parts.back(); 467 base::string16 last_part = parts.back();
491 // We want to keep just the leading whitespace. 468 // We want to keep just the leading whitespace.
492 for (size_t i = 0; i < last_part.size(); ++i) { 469 for (size_t i = 0; i < last_part.size(); ++i) {
493 if (!base::IsUnicodeWhitespace(last_part[i])) { 470 if (!base::IsUnicodeWhitespace(last_part[i])) {
494 last_part = last_part.substr(0, i); 471 last_part = last_part.substr(0, i);
495 break; 472 break;
496 } 473 }
497 } 474 }
498 last_part.append(suggested_value); 475 last_part.append(suggested_value);
499 parts[parts.size() - 1] = last_part; 476 parts[parts.size() - 1] = last_part;
500 477
501 new_value = base::JoinString(parts, base::ASCIIToUTF16(",")); 478 new_value = base::JoinString(parts, base::ASCIIToUTF16(","));
502 } 479 }
503 FillFieldWithValue(new_value, input_element); 480 DoFillFieldWithValue(new_value, input_element);
504 } 481 }
505 482
506 void AutofillAgent::OnFieldTypePredictionsAvailable( 483 // mojom::AutofillAgent:
507 const std::vector<FormDataPredictions>& forms) { 484 void AutofillAgent::FirstUserGestureObservedInTab() {
508 for (size_t i = 0; i < forms.size(); ++i) { 485 password_autofill_agent_->FirstUserGestureObserved();
509 form_cache_.ShowPredictions(forms[i]);
510 }
511 } 486 }
512 487
513 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { 488 void AutofillAgent::FillForm(int32_t id, const FormData& form) {
514 if (query_id != autofill_query_id_) 489 if (id != autofill_query_id_)
515 return; 490 return;
516 491
517 was_query_node_autofilled_ = element_.isAutofilled(); 492 was_query_node_autofilled_ = element_.isAutofilled();
518 form_util::FillForm(form, element_); 493 form_util::FillForm(form, element_);
519 if (!element_.form().isNull()) 494 if (!element_.form().isNull())
520 last_interacted_form_ = element_.form(); 495 last_interacted_form_ = element_.form();
521 496
522 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), form, 497 GetMojoAutofillDriver()->DidFillAutofillFormData(form,
523 base::TimeTicks::Now())); 498 base::TimeTicks::Now());
524 } 499 }
525 500
526 // mojom::AutofillAgent: 501 void AutofillAgent::PreviewForm(int32_t id, const FormData& form) {
527 void AutofillAgent::FirstUserGestureObservedInTab() { 502 if (id != autofill_query_id_)
528 password_autofill_agent_->FirstUserGestureObserved();
529 }
530
531 void AutofillAgent::OnPing() {
532 Send(new AutofillHostMsg_PingAck(routing_id()));
533 }
534
535 void AutofillAgent::OnPreviewForm(int query_id, const FormData& form) {
536 if (query_id != autofill_query_id_)
537 return; 503 return;
538 504
539 was_query_node_autofilled_ = element_.isAutofilled(); 505 was_query_node_autofilled_ = element_.isAutofilled();
540 form_util::PreviewForm(form, element_); 506 form_util::PreviewForm(form, element_);
541 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); 507
508 GetMojoAutofillDriver()->DidPreviewAutofillFormData();
542 } 509 }
543 510
544 void AutofillAgent::OnClearForm() { 511 void AutofillAgent::OnPing() {
512 GetMojoAutofillDriver()->PingAck();
513 }
514
515 void AutofillAgent::FieldTypePredictionsAvailable(
516 mojo::Array<FormDataPredictions> forms) {
517 for (size_t i = 0; i < forms.size(); ++i) {
518 form_cache_.ShowPredictions(forms[i]);
519 }
520 }
521
522 void AutofillAgent::ClearForm() {
545 form_cache_.ClearFormWithElement(element_); 523 form_cache_.ClearFormWithElement(element_);
546 } 524 }
547 525
548 void AutofillAgent::OnClearPreviewedForm() { 526 void AutofillAgent::ClearPreviewedForm() {
549 if (!element_.isNull()) { 527 if (!element_.isNull()) {
550 if (password_autofill_agent_->DidClearAutofillSelection(element_)) 528 if (password_autofill_agent_->DidClearAutofillSelection(element_))
551 return; 529 return;
552 530
553 form_util::ClearPreviewedFormWithElement(element_, 531 form_util::ClearPreviewedFormWithElement(element_,
554 was_query_node_autofilled_); 532 was_query_node_autofilled_);
555 } else { 533 } else {
556 // TODO(isherman): There seem to be rare cases where this code *is* 534 // TODO(isherman): There seem to be rare cases where this code *is*
557 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would 535 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would
558 // understand those cases and fix the code to avoid them. However, so far I 536 // understand those cases and fix the code to avoid them. However, so far I
559 // have been unable to reproduce such a case locally. If you hit this 537 // have been unable to reproduce such a case locally. If you hit this
560 // NOTREACHED(), please file a bug against me. 538 // NOTREACHED(), please file a bug against me.
561 NOTREACHED(); 539 NOTREACHED();
562 } 540 }
563 } 541 }
564 542
565 void AutofillAgent::OnFillFieldWithValue(const base::string16& value) { 543 void AutofillAgent::FillFieldWithValue(const mojo::String& value) {
566 WebInputElement* input_element = toWebInputElement(&element_); 544 WebInputElement* input_element = toWebInputElement(&element_);
567 if (input_element) { 545 if (input_element) {
568 FillFieldWithValue(value, input_element); 546 DoFillFieldWithValue(value.To<base::string16>(), input_element);
569 input_element->setAutofilled(true); 547 input_element->setAutofilled(true);
570 } 548 }
571 } 549 }
572 550
573 void AutofillAgent::OnPreviewFieldWithValue(const base::string16& value) { 551 void AutofillAgent::PreviewFieldWithValue(const mojo::String& value) {
574 WebInputElement* input_element = toWebInputElement(&element_); 552 WebInputElement* input_element = toWebInputElement(&element_);
575 if (input_element) 553 if (input_element)
576 PreviewFieldWithValue(value, input_element); 554 DoPreviewFieldWithValue(value.To<base::string16>(), input_element);
577 } 555 }
578 556
579 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { 557 void AutofillAgent::AcceptDataListSuggestion(const mojo::String& value) {
580 AcceptDataListSuggestion(value); 558 DoAcceptDataListSuggestion(value.To<base::string16>());
581 } 559 }
582 560
583 void AutofillAgent::OnFillPasswordSuggestion(const base::string16& username, 561 void AutofillAgent::FillPasswordSuggestion(const mojo::String& username,
584 const base::string16& password) { 562 const mojo::String& password) {
585 bool handled = password_autofill_agent_->FillSuggestion( 563 bool handled = password_autofill_agent_->FillSuggestion(
586 element_, 564 element_, username.To<base::string16>(), password.To<base::string16>());
587 username,
588 password);
589 DCHECK(handled); 565 DCHECK(handled);
590 } 566 }
591 567
592 void AutofillAgent::OnPreviewPasswordSuggestion( 568 void AutofillAgent::PreviewPasswordSuggestion(const mojo::String& username,
593 const base::string16& username, 569 const mojo::String& password) {
594 const base::string16& password) {
595 bool handled = password_autofill_agent_->PreviewSuggestion( 570 bool handled = password_autofill_agent_->PreviewSuggestion(
596 element_, 571 element_, username.To<base::string16>(), password.To<base::string16>());
597 username,
598 password);
599 DCHECK(handled); 572 DCHECK(handled);
600 } 573 }
601 574
602 void AutofillAgent::OnShowInitialPasswordAccountSuggestions( 575 void AutofillAgent::ShowInitialPasswordAccountSuggestions(
603 int key, 576 int32_t key,
604 const PasswordFormFillData& form_data) { 577 const PasswordFormFillData& form_data) {
605 std::vector<blink::WebInputElement> elements; 578 std::vector<blink::WebInputElement> elements;
606 std::unique_ptr<RendererSavePasswordProgressLogger> logger; 579 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
607 if (password_autofill_agent_->logging_state_active()) { 580 if (password_autofill_agent_->logging_state_active()) {
608 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 581 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id()));
609 logger->LogMessage(SavePasswordProgressLogger:: 582 logger->LogMessage(SavePasswordProgressLogger::
610 STRING_ON_SHOW_INITIAL_PASSWORD_ACCOUNT_SUGGESTIONS); 583 STRING_ON_SHOW_INITIAL_PASSWORD_ACCOUNT_SUGGESTIONS);
611 } 584 }
612 password_autofill_agent_->GetFillableElementFromFormData( 585 password_autofill_agent_->GetFillableElementFromFormData(
613 key, form_data, logger.get(), &elements); 586 key, form_data, logger.get(), &elements);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 if (input_element) { 690 if (input_element) {
718 // Find the datalist values and send them to the browser process. 691 // Find the datalist values and send them to the browser process.
719 GetDataListSuggestions(*input_element, 692 GetDataListSuggestions(*input_element,
720 &data_list_values, 693 &data_list_values,
721 &data_list_labels); 694 &data_list_labels);
722 TrimStringVectorForIPC(&data_list_values); 695 TrimStringVectorForIPC(&data_list_values);
723 TrimStringVectorForIPC(&data_list_labels); 696 TrimStringVectorForIPC(&data_list_labels);
724 } 697 }
725 698
726 is_popup_possibly_visible_ = true; 699 is_popup_possibly_visible_ = true;
727 Send(new AutofillHostMsg_SetDataList(routing_id(),
728 data_list_values,
729 data_list_labels));
730 700
731 Send(new AutofillHostMsg_QueryFormFieldAutofill( 701 GetMojoAutofillDriver()->SetDataList(
732 routing_id(), 702 mojo::Array<mojo::String>::From(data_list_values),
733 autofill_query_id_, 703 mojo::Array<mojo::String>::From(data_list_labels));
734 form, 704 GetMojoAutofillDriver()->QueryFormFieldAutofill(
735 field, 705 autofill_query_id_, form, field,
736 render_frame()->GetRenderView()->ElementBoundsInWindow(element_))); 706 render_frame()->GetRenderView()->ElementBoundsInWindow(element_));
737 } 707 }
738 708
739 void AutofillAgent::FillFieldWithValue(const base::string16& value, 709 void AutofillAgent::DoFillFieldWithValue(const base::string16& value,
740 WebInputElement* node) { 710 WebInputElement* node) {
741 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true); 711 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true);
742 node->setEditingValue(value.substr(0, node->maxLength())); 712 node->setEditingValue(value.substr(0, node->maxLength()));
743 } 713 }
744 714
745 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, 715 void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value,
746 WebInputElement* node) { 716 WebInputElement* node) {
747 was_query_node_autofilled_ = element_.isAutofilled(); 717 was_query_node_autofilled_ = element_.isAutofilled();
748 node->setSuggestedValue(value.substr(0, node->maxLength())); 718 node->setSuggestedValue(value.substr(0, node->maxLength()));
749 node->setAutofilled(true); 719 node->setAutofilled(true);
750 form_util::PreviewSuggestion(node->suggestedValue(), node->value(), node); 720 form_util::PreviewSuggestion(node->suggestedValue(), node->value(), node);
751 } 721 }
752 722
753 void AutofillAgent::ProcessForms() { 723 void AutofillAgent::ProcessForms() {
754 // Record timestamp of when the forms are first seen. This is used to 724 // Record timestamp of when the forms are first seen. This is used to
755 // measure the overhead of the Autofill feature. 725 // measure the overhead of the Autofill feature.
756 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); 726 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now();
757 727
758 WebLocalFrame* frame = render_frame()->GetWebFrame(); 728 WebLocalFrame* frame = render_frame()->GetWebFrame();
759 std::vector<FormData> forms = form_cache_.ExtractNewForms(); 729 std::vector<FormData> forms = form_cache_.ExtractNewForms();
760 730
761 // Always communicate to browser process for topmost frame. 731 // Always communicate to browser process for topmost frame.
762 if (!forms.empty() || !frame->parent()) { 732 if (!forms.empty() || !frame->parent()) {
763 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, 733 GetMojoAutofillDriver()->FormsSeen(std::move(forms), forms_seen_timestamp);
764 forms_seen_timestamp));
765 } 734 }
766 } 735 }
767 736
768 void AutofillAgent::HidePopup() { 737 void AutofillAgent::HidePopup() {
769 if (!is_popup_possibly_visible_) 738 if (!is_popup_possibly_visible_)
770 return; 739 return;
771 is_popup_possibly_visible_ = false; 740 is_popup_possibly_visible_ = false;
772 is_generation_popup_possibly_visible_ = false; 741 is_generation_popup_possibly_visible_ = false;
773 Send(new AutofillHostMsg_HidePopup(routing_id())); 742
743 GetMojoAutofillDriver()->HidePopup();
774 } 744 }
775 745
776 bool AutofillAgent::IsUserGesture() const { 746 bool AutofillAgent::IsUserGesture() const {
777 return WebUserGestureIndicator::isProcessingUserGesture(); 747 return WebUserGestureIndicator::isProcessingUserGesture();
778 } 748 }
779 749
780 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { 750 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) {
781 for (size_t i = 0; i < nodes.size(); ++i) { 751 for (size_t i = 0; i < nodes.size(); ++i) {
782 WebLocalFrame* frame = nodes[i].document().frame(); 752 WebLocalFrame* frame = nodes[i].document().frame();
783 // Only monitors dynamic forms created in the top frame. Dynamic forms 753 // Only monitors dynamic forms created in the top frame. Dynamic forms
784 // inserted in iframes are not captured yet. Frame is only processed 754 // inserted in iframes are not captured yet. Frame is only processed
785 // if it has finished loading, otherwise you can end up with a partially 755 // if it has finished loading, otherwise you can end up with a partially
786 // parsed form. 756 // parsed form.
787 if (frame && !frame->isLoading()) { 757 if (frame && !frame->isLoading()) {
788 ProcessForms(); 758 ProcessForms();
789 password_autofill_agent_->OnDynamicFormsSeen(); 759 password_autofill_agent_->OnDynamicFormsSeen();
790 if (password_generation_agent_) 760 if (password_generation_agent_)
791 password_generation_agent_->OnDynamicFormsSeen(); 761 password_generation_agent_->OnDynamicFormsSeen();
792 return; 762 return;
793 } 763 }
794 } 764 }
795 } 765 }
796 766
797 void AutofillAgent::ajaxSucceeded() { 767 void AutofillAgent::ajaxSucceeded() {
798 OnSamePageNavigationCompleted(); 768 OnSamePageNavigationCompleted();
799 password_autofill_agent_->AJAXSucceeded(); 769 password_autofill_agent_->AJAXSucceeded();
800 } 770 }
801 771
802 void AutofillAgent::ConnectToMojoAutofillDriverIfNeeded() { 772 const mojom::AutofillDriverPtr& AutofillAgent::GetMojoAutofillDriver() {
803 if (mojo_autofill_driver_.is_bound() && 773 if (!mojo_autofill_driver_.is_bound() ||
804 !mojo_autofill_driver_.encountered_error()) 774 mojo_autofill_driver_.encountered_error()) {
805 return; 775 render_frame()->GetRemoteInterfaces()->GetInterface(
776 mojo::GetProxy(&mojo_autofill_driver_));
777 }
806 778
807 render_frame()->GetRemoteInterfaces()->GetInterface(&mojo_autofill_driver_); 779 return mojo_autofill_driver_;
808 } 780 }
809 781
810 // LegacyAutofillAgent --------------------------------------------------------- 782 // LegacyAutofillAgent ---------------------------------------------------------
811 783
812 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent( 784 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent(
813 content::RenderView* render_view, 785 content::RenderView* render_view,
814 AutofillAgent* agent) 786 AutofillAgent* agent)
815 : content::RenderViewObserver(render_view), agent_(agent) { 787 : content::RenderViewObserver(render_view), agent_(agent) {
816 } 788 }
817 789
818 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() { 790 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() {
819 } 791 }
820 792
821 void AutofillAgent::LegacyAutofillAgent::Shutdown() { 793 void AutofillAgent::LegacyAutofillAgent::Shutdown() {
822 agent_ = nullptr; 794 agent_ = nullptr;
823 } 795 }
824 796
825 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { 797 void AutofillAgent::LegacyAutofillAgent::OnDestruct() {
826 // No-op. Don't delete |this|. 798 // No-op. Don't delete |this|.
827 } 799 }
828 800
829 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { 801 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() {
830 if (agent_) 802 if (agent_)
831 agent_->FocusChangeComplete(); 803 agent_->FocusChangeComplete();
832 } 804 }
833 805
834 } // namespace autofill 806 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698