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

Side by Side Diff: components/autofill/content/renderer/autofill_agent.cc

Issue 140093005: Add supports that allow Autofill to be initiated from textarea field (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update code as per Ilya's 3rd set of review comments - all comments addressed Created 6 years, 10 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 23 matching lines...) Expand all
34 #include "third_party/WebKit/public/platform/WebURLRequest.h" 34 #include "third_party/WebKit/public/platform/WebURLRequest.h"
35 #include "third_party/WebKit/public/web/WebDataSource.h" 35 #include "third_party/WebKit/public/web/WebDataSource.h"
36 #include "third_party/WebKit/public/web/WebDocument.h" 36 #include "third_party/WebKit/public/web/WebDocument.h"
37 #include "third_party/WebKit/public/web/WebElementCollection.h" 37 #include "third_party/WebKit/public/web/WebElementCollection.h"
38 #include "third_party/WebKit/public/web/WebFormControlElement.h" 38 #include "third_party/WebKit/public/web/WebFormControlElement.h"
39 #include "third_party/WebKit/public/web/WebFormElement.h" 39 #include "third_party/WebKit/public/web/WebFormElement.h"
40 #include "third_party/WebKit/public/web/WebFrame.h" 40 #include "third_party/WebKit/public/web/WebFrame.h"
41 #include "third_party/WebKit/public/web/WebInputEvent.h" 41 #include "third_party/WebKit/public/web/WebInputEvent.h"
42 #include "third_party/WebKit/public/web/WebNode.h" 42 #include "third_party/WebKit/public/web/WebNode.h"
43 #include "third_party/WebKit/public/web/WebOptionElement.h" 43 #include "third_party/WebKit/public/web/WebOptionElement.h"
44 #include "third_party/WebKit/public/web/WebTextAreaElement.h"
44 #include "third_party/WebKit/public/web/WebView.h" 45 #include "third_party/WebKit/public/web/WebView.h"
45 #include "ui/base/l10n/l10n_util.h" 46 #include "ui/base/l10n/l10n_util.h"
46 #include "ui/events/keycodes/keyboard_codes.h" 47 #include "ui/events/keycodes/keyboard_codes.h"
47 48
48 using blink::WebAutofillClient; 49 using blink::WebAutofillClient;
50 using blink::WebElementCollection;
49 using blink::WebFormControlElement; 51 using blink::WebFormControlElement;
50 using blink::WebFormElement; 52 using blink::WebFormElement;
51 using blink::WebFrame; 53 using blink::WebFrame;
52 using blink::WebInputElement; 54 using blink::WebInputElement;
53 using blink::WebKeyboardEvent; 55 using blink::WebKeyboardEvent;
54 using blink::WebNode; 56 using blink::WebNode;
55 using blink::WebElementCollection;
56 using blink::WebOptionElement; 57 using blink::WebOptionElement;
57 using blink::WebString; 58 using blink::WebString;
59 using blink::WebTextAreaElement;
58 60
59 namespace autofill { 61 namespace autofill {
60 62
61 namespace { 63 namespace {
62 64
63 // Gets all the data list values (with corresponding label) for the given 65 // Gets all the data list values (with corresponding label) for the given
64 // element. 66 // element.
65 void GetDataListSuggestions(const blink::WebInputElement& element, 67 void GetDataListSuggestions(const blink::WebInputElement& element,
66 bool ignore_current_value, 68 bool ignore_current_value,
67 std::vector<base::string16>* values, 69 std::vector<base::string16>* values,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 HidePopup(); 282 HidePopup();
281 283
282 in_flight_request_form_ = form; 284 in_flight_request_form_ = form;
283 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); 285 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url));
284 } 286 }
285 287
286 void AutofillAgent::setIgnoreTextChanges(bool ignore) { 288 void AutofillAgent::setIgnoreTextChanges(bool ignore) {
287 ignore_text_changes_ = ignore; 289 ignore_text_changes_ = ignore;
288 } 290 }
289 291
290 void AutofillAgent::InputElementClicked(const WebInputElement& element, 292 void AutofillAgent::FormControlElementClicked(
291 bool was_focused, 293 const WebFormControlElement& element,
292 bool is_focused) { 294 bool was_focused) {
295 const WebInputElement* input_element = toWebInputElement(&element);
296 if (!IsAutofillableInputElement(input_element) &&
297 !IsTextAreaElement(element))
298 return;
299
293 if (was_focused) 300 if (was_focused)
294 ShowSuggestions(element, true, false, true, false); 301 ShowSuggestions(element, true, false, true, false);
295 } 302 }
296 303
297 void AutofillAgent::InputElementLostFocus() { 304 void AutofillAgent::FormControlElementLostFocus() {
298 HidePopup(); 305 HidePopup();
299 } 306 }
300 307
301 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { 308 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
302 password_autofill_agent_->TextFieldDidEndEditing(element); 309 password_autofill_agent_->TextFieldDidEndEditing(element);
303 has_shown_autofill_popup_for_current_edit_ = false; 310 has_shown_autofill_popup_for_current_edit_ = false;
304 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); 311 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id()));
305 } 312 }
306 313
314 // TODO(ziran.sun): This function is to be removed once next Blink roll is done
307 void AutofillAgent::textFieldDidChange(const WebInputElement& element) { 315 void AutofillAgent::textFieldDidChange(const WebInputElement& element) {
316 const WebFormControlElement control_element =
317 element.toConst<WebFormControlElement>();
318 textFieldDidChange(control_element);
319 }
320
321 void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) {
308 if (ignore_text_changes_) 322 if (ignore_text_changes_)
309 return; 323 return;
310 324
325 const WebInputElement* input_element = toWebInputElement(&element);
326 if (input_element)
327 DCHECK(IsAutofillableInputElement(input_element));
328 else
329 DCHECK(IsTextAreaElement(element));
Ilya Sherman 2014/03/01 02:50:53 nit: You can shorten these five lines to DCHECK(I
ziran.sun 2014/03/03 19:23:32 Done.
330
311 if (did_set_node_text_) { 331 if (did_set_node_text_) {
312 did_set_node_text_ = false; 332 did_set_node_text_ = false;
313 return; 333 return;
314 } 334 }
315 335
316 // We post a task for doing the Autofill as the caret position is not set 336 // We post a task for doing the Autofill as the caret position is not set
317 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and 337 // properly at this point (http://bugs.webkit.org/show_bug.cgi?id=16976) and
318 // it is needed to trigger autofill. 338 // it is needed to trigger autofill.
319 weak_ptr_factory_.InvalidateWeakPtrs(); 339 weak_ptr_factory_.InvalidateWeakPtrs();
320 base::MessageLoop::current()->PostTask( 340 base::MessageLoop::current()->PostTask(
321 FROM_HERE, 341 FROM_HERE,
322 base::Bind(&AutofillAgent::TextFieldDidChangeImpl, 342 base::Bind(&AutofillAgent::TextFieldDidChangeImpl,
323 weak_ptr_factory_.GetWeakPtr(), 343 weak_ptr_factory_.GetWeakPtr(),
324 element)); 344 element));
325 } 345 }
326 346
327 void AutofillAgent::TextFieldDidChangeImpl(const WebInputElement& element) { 347 void AutofillAgent::TextFieldDidChangeImpl(
348 const WebFormControlElement& element) {
328 // If the element isn't focused then the changes don't matter. This check is 349 // If the element isn't focused then the changes don't matter. This check is
329 // required to properly handle IME interactions. 350 // required to properly handle IME interactions.
330 if (!element.focused()) 351 if (!element.focused())
331 return; 352 return;
332 353
333 if (password_generation_agent_ && 354 const WebInputElement* input_element = toWebInputElement(&element);
334 password_generation_agent_->TextDidChangeInTextField(element)) { 355 if (IsAutofillableInputElement(input_element)) {
335 return; 356 if (password_generation_agent_ &&
336 } 357 password_generation_agent_->TextDidChangeInTextField(*input_element)) {
358 return;
359 }
337 360
338 if (password_autofill_agent_->TextDidChangeInTextField(element)) { 361 if (password_autofill_agent_->TextDidChangeInTextField(*input_element)) {
339 element_ = element; 362 element_ = element;
340 return; 363 return;
364 }
341 } 365 }
342 366
343 ShowSuggestions(element, false, true, false, false); 367 ShowSuggestions(element, false, true, false, false);
344 368
345 FormData form; 369 FormData form;
346 FormFieldData field; 370 FormFieldData field;
347 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { 371 if (FindFormAndFieldForFormControlElement(element,
372 &form,
373 &field,
374 REQUIRE_NONE)) {
348 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, 375 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field,
349 base::TimeTicks::Now())); 376 base::TimeTicks::Now()));
350 } 377 }
351 } 378 }
352 379
353 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, 380 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element,
354 const WebKeyboardEvent& event) { 381 const WebKeyboardEvent& event) {
355 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { 382 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) {
356 element_ = element; 383 element_ = element;
357 return; 384 return;
358 } 385 }
359 386
360 if (event.windowsKeyCode == ui::VKEY_DOWN || 387 if (event.windowsKeyCode == ui::VKEY_DOWN ||
361 event.windowsKeyCode == ui::VKEY_UP) 388 event.windowsKeyCode == ui::VKEY_UP)
362 ShowSuggestions(element, true, true, true, false); 389 ShowSuggestions(element, true, true, true, false);
363 } 390 }
364 391
365 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { 392 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) {
366 ShowSuggestions(element, true, false, false, true); 393 ShowSuggestions(element, true, false, false, true);
367 } 394 }
368 395
369 void AutofillAgent::AcceptDataListSuggestion( 396 void AutofillAgent::AcceptDataListSuggestion(
370 const base::string16& suggested_value) { 397 const base::string16& suggested_value) {
398 WebInputElement* input_element = toWebInputElement(&element_);
399 DCHECK(IsAutofillableInputElement(input_element));
371 base::string16 new_value = suggested_value; 400 base::string16 new_value = suggested_value;
372 // If this element takes multiple values then replace the last part with 401 // If this element takes multiple values then replace the last part with
373 // the suggestion. 402 // the suggestion.
374 if (element_.isMultiple() && 403 if (input_element->isMultiple() &&
375 element_.formControlType() == WebString::fromUTF8("email")) { 404 input_element->formControlType() == WebString::fromUTF8("email")) {
376 std::vector<base::string16> parts; 405 std::vector<base::string16> parts;
377 406
378 base::SplitStringDontTrim(element_.editingValue(), ',', &parts); 407 base::SplitStringDontTrim(input_element->editingValue(), ',', &parts);
379 if (parts.size() == 0) 408 if (parts.size() == 0)
380 parts.push_back(base::string16()); 409 parts.push_back(base::string16());
381 410
382 base::string16 last_part = parts.back(); 411 base::string16 last_part = parts.back();
383 // We want to keep just the leading whitespace. 412 // We want to keep just the leading whitespace.
384 for (size_t i = 0; i < last_part.size(); ++i) { 413 for (size_t i = 0; i < last_part.size(); ++i) {
385 if (!IsWhitespace(last_part[i])) { 414 if (!IsWhitespace(last_part[i])) {
386 last_part = last_part.substr(0, i); 415 last_part = last_part.substr(0, i);
387 break; 416 break;
388 } 417 }
389 } 418 }
390 last_part.append(suggested_value); 419 last_part.append(suggested_value);
391 parts[parts.size() - 1] = last_part; 420 parts[parts.size() - 1] = last_part;
392 421
393 new_value = JoinString(parts, ','); 422 new_value = JoinString(parts, ',');
394 } 423 }
395 SetNodeText(new_value, &element_); 424 SetNodeText(new_value, input_element);
396 } 425 }
397 426
398 void AutofillAgent::OnFormDataFilled(int query_id, 427 void AutofillAgent::OnFormDataFilled(int query_id,
399 const FormData& form) { 428 const FormData& form) {
400 if (!render_view()->GetWebView() || query_id != autofill_query_id_) 429 if (!render_view()->GetWebView() || query_id != autofill_query_id_)
401 return; 430 return;
402 431
403 was_query_node_autofilled_ = element_.isAutofilled(); 432 was_query_node_autofilled_ = element_.isAutofilled();
404 433
405 switch (autofill_action_) { 434 switch (autofill_action_) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 // TODO(isherman): There seem to be rare cases where this code *is* 476 // TODO(isherman): There seem to be rare cases where this code *is*
448 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would 477 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would
449 // understand those cases and fix the code to avoid them. However, so far I 478 // understand those cases and fix the code to avoid them. However, so far I
450 // have been unable to reproduce such a case locally. If you hit this 479 // have been unable to reproduce such a case locally. If you hit this
451 // NOTREACHED(), please file a bug against me. 480 // NOTREACHED(), please file a bug against me.
452 NOTREACHED(); 481 NOTREACHED();
453 } 482 }
454 } 483 }
455 484
456 void AutofillAgent::OnSetNodeText(const base::string16& value) { 485 void AutofillAgent::OnSetNodeText(const base::string16& value) {
457 SetNodeText(value, &element_); 486 WebInputElement* input_element = toWebInputElement(&element_);
487 DCHECK(IsAutofillableInputElement(input_element));
488
489 SetNodeText(value, input_element);
458 } 490 }
459 491
460 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { 492 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) {
461 AcceptDataListSuggestion(value); 493 AcceptDataListSuggestion(value);
462 } 494 }
463 495
464 void AutofillAgent::OnAcceptPasswordAutofillSuggestion( 496 void AutofillAgent::OnAcceptPasswordAutofillSuggestion(
465 const base::string16& username) { 497 const base::string16& username) {
466 // We need to make sure this is handled here because the browser process 498 // We need to make sure this is handled here because the browser process
467 // skipped it handling because it believed it would be handled here. If it 499 // skipped it handling because it believed it would be handled here. If it
(...skipping 15 matching lines...) Expand all
483 result = WebFormElement::AutocompleteResultErrorInvalid; 515 result = WebFormElement::AutocompleteResultErrorInvalid;
484 } 516 }
485 517
486 in_flight_request_form_.finishRequestAutocomplete(result); 518 in_flight_request_form_.finishRequestAutocomplete(result);
487 in_flight_request_form_.reset(); 519 in_flight_request_form_.reset();
488 } 520 }
489 521
490 void AutofillAgent::OnPageShown() { 522 void AutofillAgent::OnPageShown() {
491 } 523 }
492 524
493 void AutofillAgent::ShowSuggestions(const WebInputElement& element, 525 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element,
494 bool autofill_on_empty_values, 526 bool autofill_on_empty_values,
495 bool requires_caret_at_end, 527 bool requires_caret_at_end,
496 bool display_warning_if_disabled, 528 bool display_warning_if_disabled,
497 bool datalist_only) { 529 bool datalist_only) {
498 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || 530 if (!element.isEnabled() || element.isReadOnly())
499 element.isPasswordField())
500 return;
501 if (!datalist_only && !element.suggestedValue().isEmpty())
502 return; 531 return;
503 532
533 const WebInputElement* input_element = toWebInputElement(&element);
534 if (IsAutofillableInputElement(input_element)) {
535 if (!input_element->isTextField() || input_element->isPasswordField())
536 return;
537 if (!datalist_only && !input_element->suggestedValue().isEmpty())
538 return;
539 } else if (IsTextAreaElement(element)) {
Ilya Sherman 2014/03/01 02:50:53 nit: Can this be a DCHECK rather than an if?
ziran.sun 2014/03/03 19:23:32 Done.
540 if (!element.toConst<WebTextAreaElement>().suggestedValue().isEmpty())
541 return;
542 }
543
544 WebString value;
545 int selectionStart;
546 int selectionEnd;
547 if (IsAutofillableInputElement(input_element)) {
548 value = input_element->editingValue();
549 selectionStart = input_element->selectionStart();
550 selectionEnd = input_element->selectionEnd();
551 } else {
552 DCHECK(IsTextAreaElement(element));
553 const WebTextAreaElement textarea_element =
554 element.toConst<WebTextAreaElement>();
555 value = textarea_element.editingValue();
556 selectionStart = textarea_element.selectionStart();
557 selectionEnd = textarea_element.selectionEnd();
558 }
504 // Don't attempt to autofill with values that are too large or if filling 559 // Don't attempt to autofill with values that are too large or if filling
505 // criteria are not met. 560 // criteria are not met.
506 WebString value = element.editingValue();
507 if (!datalist_only && 561 if (!datalist_only &&
508 (value.length() > kMaxDataLength || 562 (value.length() > kMaxDataLength ||
509 (!autofill_on_empty_values && value.isEmpty()) || 563 (!autofill_on_empty_values && value.isEmpty()) ||
510 (requires_caret_at_end && 564 (requires_caret_at_end &&
511 (element.selectionStart() != element.selectionEnd() || 565 (selectionStart != selectionEnd ||
512 element.selectionEnd() != static_cast<int>(value.length()))))) { 566 selectionEnd != static_cast<int>(value.length()))))) {
513 // Any popup currently showing is obsolete. 567 // Any popup currently showing is obsolete.
514 HidePopup(); 568 HidePopup();
515 return; 569 return;
516 } 570 }
517 571
518 element_ = element; 572 element_ = element;
519 if (password_autofill_agent_->ShowSuggestions(element)) { 573 if (IsAutofillableInputElement(input_element) &&
520 is_popup_possibly_visible_ = true; 574 password_autofill_agent_->ShowSuggestions(*input_element))
Ilya Sherman 2014/03/01 02:50:53 Please preserve the line "is_popup_possibly_visibl
ziran.sun 2014/03/03 19:23:32 Done.
521 return; 575 return;
522 }
523 576
524 // If autocomplete is disabled at the field level, ensure that the native 577 // If autocomplete is disabled at the field level, ensure that the native
525 // UI won't try to show a warning, since that may conflict with a custom 578 // UI won't try to show a warning, since that may conflict with a custom
526 // popup. Note that we cannot use the WebKit method element.autoComplete() 579 // popup. Note that we cannot use the WebKit method element.autoComplete()
527 // as it does not allow us to distinguish the case where autocomplete is 580 // as it does not allow us to distinguish the case where autocomplete is
528 // disabled for *both* the element and for the form. 581 // disabled for *both* the element and for the form.
529 const base::string16 autocomplete_attribute = 582 const base::string16 autocomplete_attribute =
530 element.getAttribute("autocomplete"); 583 element.getAttribute("autocomplete");
531 if (LowerCaseEqualsASCII(autocomplete_attribute, "off")) 584 if (LowerCaseEqualsASCII(autocomplete_attribute, "off"))
532 display_warning_if_disabled = false; 585 display_warning_if_disabled = false;
533 586
534 QueryAutofillSuggestions(element, 587 QueryAutofillSuggestions(element,
535 display_warning_if_disabled, 588 display_warning_if_disabled,
536 datalist_only); 589 datalist_only);
537 } 590 }
538 591
539 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, 592 void AutofillAgent::QueryAutofillSuggestions(
540 bool display_warning_if_disabled, 593 const WebFormControlElement& element,
541 bool datalist_only) { 594 bool display_warning_if_disabled,
595 bool datalist_only) {
542 if (!element.document().frame()) 596 if (!element.document().frame())
543 return; 597 return;
544 598
545 static int query_counter = 0; 599 static int query_counter = 0;
546 autofill_query_id_ = query_counter++; 600 autofill_query_id_ = query_counter++;
547 display_warning_if_disabled_ = display_warning_if_disabled; 601 display_warning_if_disabled_ = display_warning_if_disabled;
548 602
549 // If autocomplete is disabled at the form level, we want to see if there 603 // If autocomplete is disabled at the form level, we want to see if there
550 // would have been any suggestions were it enabled, so that we can show a 604 // would have been any suggestions were it enabled, so that we can show a
551 // warning. Otherwise, we want to ignore fields that disable autocomplete, so 605 // warning. Otherwise, we want to ignore fields that disable autocomplete, so
552 // that the suggestions list does not include suggestions for these form 606 // that the suggestions list does not include suggestions for these form
553 // fields -- see comment 1 on http://crbug.com/69914 607 // fields -- see comment 1 on http://crbug.com/69914
554 const RequirementsMask requirements = 608 RequirementsMask requirements = REQUIRE_NONE;
555 element.autoComplete() ? REQUIRE_AUTOCOMPLETE : REQUIRE_NONE; 609 const WebInputElement* input_element = toWebInputElement(&element);
610 if (IsAutofillableInputElement(input_element)) {
611 requirements =
612 input_element->autoComplete() ? REQUIRE_AUTOCOMPLETE : REQUIRE_NONE;
613 } else {
614 DCHECK(IsTextAreaElement(element));
615 const WebTextAreaElement textarea_element =
616 element.toConst<WebTextAreaElement>();
617 requirements =
618 textarea_element.autoComplete() ? REQUIRE_AUTOCOMPLETE : REQUIRE_NONE;
619 }
556 620
557 FormData form; 621 FormData form;
558 FormFieldData field; 622 FormFieldData field;
559 if (!FindFormAndFieldForInputElement(element, &form, &field, requirements)) { 623 if (!FindFormAndFieldForFormControlElement(element, &form, &field,
624 requirements)) {
560 // If we didn't find the cached form, at least let autocomplete have a shot 625 // If we didn't find the cached form, at least let autocomplete have a shot
561 // at providing suggestions. 626 // at providing suggestions.
562 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); 627 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field);
563 } 628 }
564 if (datalist_only) 629 if (datalist_only)
565 field.should_autocomplete = false; 630 field.should_autocomplete = false;
566 631
567 gfx::RectF bounding_box_scaled = 632 gfx::RectF bounding_box_scaled =
568 GetScaledBoundingBox(web_view_->pageScaleFactor(), &element_); 633 GetScaledBoundingBox(web_view_->pageScaleFactor(), &element_);
569 634
570 // Find the datalist values and send them to the browser process. 635 if (IsAutofillableInputElement(input_element)) {
571 std::vector<base::string16> data_list_values; 636 // Find the datalist values and send them to the browser process.
572 std::vector<base::string16> data_list_labels; 637 std::vector<base::string16> data_list_values;
573 GetDataListSuggestions(element_, 638 std::vector<base::string16> data_list_labels;
574 datalist_only, 639 GetDataListSuggestions(*input_element,
575 &data_list_values, 640 datalist_only,
576 &data_list_labels); 641 &data_list_values,
577 TrimStringVectorForIPC(&data_list_values); 642 &data_list_labels);
578 TrimStringVectorForIPC(&data_list_labels); 643 TrimStringVectorForIPC(&data_list_values);
644 TrimStringVectorForIPC(&data_list_labels);
645
646 Send(new AutofillHostMsg_SetDataList(routing_id(),
647 data_list_values,
648 data_list_labels));
649 }
579 650
580 is_popup_possibly_visible_ = true; 651 is_popup_possibly_visible_ = true;
581 Send(new AutofillHostMsg_SetDataList(routing_id(),
582 data_list_values,
583 data_list_labels));
584
585 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(), 652 Send(new AutofillHostMsg_QueryFormFieldAutofill(routing_id(),
586 autofill_query_id_, 653 autofill_query_id_,
587 form, 654 form,
588 field, 655 field,
589 bounding_box_scaled, 656 bounding_box_scaled,
590 display_warning_if_disabled)); 657 display_warning_if_disabled));
591 } 658 }
592 659
593 void AutofillAgent::FillAutofillFormData(const WebNode& node, 660 void AutofillAgent::FillAutofillFormData(const WebNode& node,
594 int unique_id, 661 int unique_id,
595 AutofillAction action) { 662 AutofillAction action) {
596 DCHECK_GT(unique_id, 0); 663 DCHECK_GT(unique_id, 0);
597 664
598 static int query_counter = 0; 665 static int query_counter = 0;
599 autofill_query_id_ = query_counter++; 666 autofill_query_id_ = query_counter++;
600 667
601 FormData form; 668 FormData form;
602 FormFieldData field; 669 FormFieldData field;
603 if (!FindFormAndFieldForInputElement(node.toConst<WebInputElement>(), &form, 670 if (!FindFormAndFieldForFormControlElement(
604 &field, REQUIRE_AUTOCOMPLETE)) { 671 node.toConst<WebFormControlElement>(),
672 &form,
673 &field,
674 REQUIRE_AUTOCOMPLETE)) {
605 return; 675 return;
606 } 676 }
607 677
608 autofill_action_ = action; 678 autofill_action_ = action;
609 Send(new AutofillHostMsg_FillAutofillFormData( 679 Send(new AutofillHostMsg_FillAutofillFormData(
610 routing_id(), autofill_query_id_, form, field, unique_id)); 680 routing_id(), autofill_query_id_, form, field, unique_id));
611 } 681 }
612 682
613 void AutofillAgent::SetNodeText(const base::string16& value, 683 void AutofillAgent::SetNodeText(const base::string16& value,
614 blink::WebInputElement* node) { 684 blink::WebInputElement* node) {
(...skipping 20 matching lines...) Expand all
635 // Only monitors dynamic forms created in the top frame. Dynamic forms 705 // Only monitors dynamic forms created in the top frame. Dynamic forms
636 // inserted in iframes are not captured yet. 706 // inserted in iframes are not captured yet.
637 if (!frame->parent()) { 707 if (!frame->parent()) {
638 password_autofill_agent_->OnDynamicFormsSeen(frame); 708 password_autofill_agent_->OnDynamicFormsSeen(frame);
639 return; 709 return;
640 } 710 }
641 } 711 }
642 } 712 }
643 713
644 } // namespace autofill 714 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698