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