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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); | 285 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void AutofillAgent::setIgnoreTextChanges(bool ignore) { | 288 void AutofillAgent::setIgnoreTextChanges(bool ignore) { |
| 289 ignore_text_changes_ = ignore; | 289 ignore_text_changes_ = ignore; |
| 290 } | 290 } |
| 291 | 291 |
| 292 void AutofillAgent::InputElementClicked(const WebInputElement& element, | 292 void AutofillAgent::InputElementClicked(const WebInputElement& element, |
| 293 bool was_focused, | 293 bool was_focused, |
| 294 bool is_focused) { | 294 bool is_focused) { |
| 295 if (was_focused) | 295 bool show_full_suggestion_list = (element.isAutofilled() && !was_focused) || |
| 296 ShowSuggestions(element, true, false, true, false); | 296 (!element.isAutofilled() && was_focused); |
|
Garrett Casto
2014/03/12 06:50:45
This seems overly complicated to me. If the elemen
jww
2014/03/19 01:08:02
This is for the case you argue for later, not crea
Garrett Casto
2014/03/19 20:54:41
Ahh, my fault. For some reason I thought that we w
jww
2014/06/20 18:43:46
So I've actually had a bit of a change of heart on
| |
| 297 bool show_password_suggestions_only = !was_focused; | |
| 298 ShowSuggestions(element, | |
| 299 true, | |
| 300 false, | |
| 301 true, | |
| 302 false, | |
| 303 show_full_suggestion_list, | |
| 304 show_password_suggestions_only); | |
| 297 } | 305 } |
| 298 | 306 |
| 299 void AutofillAgent::InputElementLostFocus() { | 307 void AutofillAgent::InputElementLostFocus() { |
| 300 HidePopup(); | 308 HidePopup(); |
| 301 } | 309 } |
| 302 | 310 |
| 303 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { | 311 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { |
| 304 password_autofill_agent_->TextFieldDidEndEditing(element); | 312 password_autofill_agent_->TextFieldDidEndEditing(element); |
| 305 has_shown_autofill_popup_for_current_edit_ = false; | 313 has_shown_autofill_popup_for_current_edit_ = false; |
| 306 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); | 314 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 335 if (password_generation_agent_ && | 343 if (password_generation_agent_ && |
| 336 password_generation_agent_->TextDidChangeInTextField(element)) { | 344 password_generation_agent_->TextDidChangeInTextField(element)) { |
| 337 return; | 345 return; |
| 338 } | 346 } |
| 339 | 347 |
| 340 if (password_autofill_agent_->TextDidChangeInTextField(element)) { | 348 if (password_autofill_agent_->TextDidChangeInTextField(element)) { |
| 341 element_ = element; | 349 element_ = element; |
| 342 return; | 350 return; |
| 343 } | 351 } |
| 344 | 352 |
| 345 ShowSuggestions(element, false, true, false, false); | 353 ShowSuggestions(element, false, true, false, false, false, false); |
| 346 | 354 |
| 347 FormData form; | 355 FormData form; |
| 348 FormFieldData field; | 356 FormFieldData field; |
| 349 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { | 357 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { |
| 350 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, | 358 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, |
| 351 base::TimeTicks::Now())); | 359 base::TimeTicks::Now())); |
| 352 } | 360 } |
| 353 } | 361 } |
| 354 | 362 |
| 355 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, | 363 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, |
| 356 const WebKeyboardEvent& event) { | 364 const WebKeyboardEvent& event) { |
| 357 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { | 365 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { |
| 358 element_ = element; | 366 element_ = element; |
| 359 return; | 367 return; |
| 360 } | 368 } |
| 361 | 369 |
| 362 if (event.windowsKeyCode == ui::VKEY_DOWN || | 370 if (event.windowsKeyCode == ui::VKEY_DOWN || |
| 363 event.windowsKeyCode == ui::VKEY_UP) | 371 event.windowsKeyCode == ui::VKEY_UP) |
| 364 ShowSuggestions(element, true, true, true, false); | 372 ShowSuggestions(element, true, true, true, false, false, false); |
| 365 } | 373 } |
| 366 | 374 |
| 367 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { | 375 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { |
| 368 ShowSuggestions(element, true, false, false, true); | 376 ShowSuggestions(element, true, false, false, true, false, false); |
| 369 } | 377 } |
| 370 | 378 |
| 371 void AutofillAgent::AcceptDataListSuggestion( | 379 void AutofillAgent::AcceptDataListSuggestion( |
| 372 const base::string16& suggested_value) { | 380 const base::string16& suggested_value) { |
| 373 base::string16 new_value = suggested_value; | 381 base::string16 new_value = suggested_value; |
| 374 // If this element takes multiple values then replace the last part with | 382 // If this element takes multiple values then replace the last part with |
| 375 // the suggestion. | 383 // the suggestion. |
| 376 if (element_.isMultiple() && | 384 if (element_.isMultiple() && |
| 377 element_.formControlType() == WebString::fromUTF8("email")) { | 385 element_.formControlType() == WebString::fromUTF8("email")) { |
| 378 std::vector<base::string16> parts; | 386 std::vector<base::string16> parts; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 in_flight_request_form_.reset(); | 497 in_flight_request_form_.reset(); |
| 490 } | 498 } |
| 491 | 499 |
| 492 void AutofillAgent::OnPageShown() { | 500 void AutofillAgent::OnPageShown() { |
| 493 } | 501 } |
| 494 | 502 |
| 495 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 503 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
| 496 bool autofill_on_empty_values, | 504 bool autofill_on_empty_values, |
| 497 bool requires_caret_at_end, | 505 bool requires_caret_at_end, |
| 498 bool display_warning_if_disabled, | 506 bool display_warning_if_disabled, |
| 499 bool datalist_only) { | 507 bool datalist_only, |
| 508 bool show_full_suggestion_list, | |
| 509 bool show_password_suggestions_only) { | |
| 500 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || | 510 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || |
| 501 element.isPasswordField()) | 511 element.isPasswordField()) |
| 502 return; | 512 return; |
| 503 if (!datalist_only && !element.suggestedValue().isEmpty()) | 513 if (!datalist_only && !element.suggestedValue().isEmpty()) |
| 504 return; | 514 return; |
| 505 | 515 |
| 506 // Don't attempt to autofill with values that are too large or if filling | 516 // Don't attempt to autofill with values that are too large or if filling |
| 507 // criteria are not met. | 517 // criteria are not met. |
| 508 WebString value = element.editingValue(); | 518 WebString value = element.editingValue(); |
| 509 if (!datalist_only && | 519 if (!datalist_only && |
| 510 (value.length() > kMaxDataLength || | 520 (value.length() > kMaxDataLength || |
| 511 (!autofill_on_empty_values && value.isEmpty()) || | 521 (!autofill_on_empty_values && value.isEmpty()) || |
| 512 (requires_caret_at_end && | 522 (requires_caret_at_end && |
| 513 (element.selectionStart() != element.selectionEnd() || | 523 (element.selectionStart() != element.selectionEnd() || |
| 514 element.selectionEnd() != static_cast<int>(value.length()))))) { | 524 element.selectionEnd() != static_cast<int>(value.length()))))) { |
| 515 // Any popup currently showing is obsolete. | 525 // Any popup currently showing is obsolete. |
| 516 HidePopup(); | 526 HidePopup(); |
| 517 return; | 527 return; |
| 518 } | 528 } |
| 519 | 529 |
| 520 element_ = element; | 530 element_ = element; |
| 521 if (password_autofill_agent_->ShowSuggestions(element)) { | 531 if (password_autofill_agent_->ShowSuggestions(element, |
| 532 show_full_suggestion_list) || | |
| 533 show_password_suggestions_only) { | |
| 522 is_popup_possibly_visible_ = true; | 534 is_popup_possibly_visible_ = true; |
| 523 return; | 535 return; |
| 524 } | 536 } |
| 525 | 537 |
| 526 // If autocomplete is disabled at the field level, ensure that the native | 538 // If autocomplete is disabled at the field level, ensure that the native |
| 527 // UI won't try to show a warning, since that may conflict with a custom | 539 // UI won't try to show a warning, since that may conflict with a custom |
| 528 // popup. Note that we cannot use the WebKit method element.autoComplete() | 540 // popup. Note that we cannot use the WebKit method element.autoComplete() |
| 529 // as it does not allow us to distinguish the case where autocomplete is | 541 // as it does not allow us to distinguish the case where autocomplete is |
| 530 // disabled for *both* the element and for the form. | 542 // disabled for *both* the element and for the form. |
| 531 const base::string16 autocomplete_attribute = | 543 const base::string16 autocomplete_attribute = |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 // Only monitors dynamic forms created in the top frame. Dynamic forms | 649 // Only monitors dynamic forms created in the top frame. Dynamic forms |
| 638 // inserted in iframes are not captured yet. | 650 // inserted in iframes are not captured yet. |
| 639 if (!frame->parent()) { | 651 if (!frame->parent()) { |
| 640 password_autofill_agent_->OnDynamicFormsSeen(frame); | 652 password_autofill_agent_->OnDynamicFormsSeen(frame); |
| 641 return; | 653 return; |
| 642 } | 654 } |
| 643 } | 655 } |
| 644 } | 656 } |
| 645 | 657 |
| 646 } // namespace autofill | 658 } // namespace autofill |
| OLD | NEW |