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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); | 282 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); |
283 } | 283 } |
284 | 284 |
285 void AutofillAgent::setIgnoreTextChanges(bool ignore) { | 285 void AutofillAgent::setIgnoreTextChanges(bool ignore) { |
286 ignore_text_changes_ = ignore; | 286 ignore_text_changes_ = ignore; |
287 } | 287 } |
288 | 288 |
289 void AutofillAgent::InputElementClicked(const WebInputElement& element, | 289 void AutofillAgent::InputElementClicked(const WebInputElement& element, |
290 bool was_focused, | 290 bool was_focused, |
291 bool is_focused) { | 291 bool is_focused) { |
292 if (was_focused) | 292 ShowSuggestions(element, true, false, true, false, true); |
Garrett Casto
2014/02/19 21:20:19
Ilya, are you okay with Autofill also showing on f
jww
2014/02/19 21:56:48
I'm worried that would be hard-to-understand behav
jww
2014/02/19 22:14:39
Obviously we're still waiting for comments on the
jww
2014/02/21 02:43:28
My bad. I misunderstood your point in a similar wa
| |
293 ShowSuggestions(element, true, false, true, false); | |
294 } | 293 } |
295 | 294 |
296 void AutofillAgent::InputElementLostFocus() { | 295 void AutofillAgent::InputElementLostFocus() { |
297 HideAutofillUI(); | 296 HideAutofillUI(); |
298 } | 297 } |
299 | 298 |
300 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { | 299 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { |
301 password_autofill_agent_->TextFieldDidEndEditing(element); | 300 password_autofill_agent_->TextFieldDidEndEditing(element); |
302 has_shown_autofill_popup_for_current_edit_ = false; | 301 has_shown_autofill_popup_for_current_edit_ = false; |
303 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); | 302 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); |
(...skipping 28 matching lines...) Expand all Loading... | |
332 if (password_generation_agent_ && | 331 if (password_generation_agent_ && |
333 password_generation_agent_->TextDidChangeInTextField(element)) { | 332 password_generation_agent_->TextDidChangeInTextField(element)) { |
334 return; | 333 return; |
335 } | 334 } |
336 | 335 |
337 if (password_autofill_agent_->TextDidChangeInTextField(element)) { | 336 if (password_autofill_agent_->TextDidChangeInTextField(element)) { |
338 element_ = element; | 337 element_ = element; |
339 return; | 338 return; |
340 } | 339 } |
341 | 340 |
342 ShowSuggestions(element, false, true, false, false); | 341 ShowSuggestions(element, false, true, false, false, false); |
343 | 342 |
344 FormData form; | 343 FormData form; |
345 FormFieldData field; | 344 FormFieldData field; |
346 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { | 345 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { |
347 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, | 346 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, |
348 base::TimeTicks::Now())); | 347 base::TimeTicks::Now())); |
349 } | 348 } |
350 } | 349 } |
351 | 350 |
352 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, | 351 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, |
353 const WebKeyboardEvent& event) { | 352 const WebKeyboardEvent& event) { |
354 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { | 353 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { |
355 element_ = element; | 354 element_ = element; |
356 return; | 355 return; |
357 } | 356 } |
358 | 357 |
359 if (event.windowsKeyCode == ui::VKEY_DOWN || | 358 if (event.windowsKeyCode == ui::VKEY_DOWN || |
360 event.windowsKeyCode == ui::VKEY_UP) | 359 event.windowsKeyCode == ui::VKEY_UP) |
361 ShowSuggestions(element, true, true, true, false); | 360 ShowSuggestions(element, true, true, true, false, false); |
362 } | 361 } |
363 | 362 |
364 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { | 363 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { |
365 ShowSuggestions(element, true, false, false, true); | 364 ShowSuggestions(element, true, false, false, true, false); |
366 } | 365 } |
367 | 366 |
368 void AutofillAgent::AcceptDataListSuggestion( | 367 void AutofillAgent::AcceptDataListSuggestion( |
369 const base::string16& suggested_value) { | 368 const base::string16& suggested_value) { |
370 base::string16 new_value = suggested_value; | 369 base::string16 new_value = suggested_value; |
371 // If this element takes multiple values then replace the last part with | 370 // If this element takes multiple values then replace the last part with |
372 // the suggestion. | 371 // the suggestion. |
373 if (element_.isMultiple() && | 372 if (element_.isMultiple() && |
374 element_.formControlType() == WebString::fromUTF8("email")) { | 373 element_.formControlType() == WebString::fromUTF8("email")) { |
375 std::vector<base::string16> parts; | 374 std::vector<base::string16> parts; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 in_flight_request_form_.reset(); | 485 in_flight_request_form_.reset(); |
487 } | 486 } |
488 | 487 |
489 void AutofillAgent::OnPageShown() { | 488 void AutofillAgent::OnPageShown() { |
490 } | 489 } |
491 | 490 |
492 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 491 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
493 bool autofill_on_empty_values, | 492 bool autofill_on_empty_values, |
494 bool requires_caret_at_end, | 493 bool requires_caret_at_end, |
495 bool display_warning_if_disabled, | 494 bool display_warning_if_disabled, |
496 bool datalist_only) { | 495 bool datalist_only, |
496 bool show_all) { | |
497 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || | 497 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || |
498 element.isPasswordField()) | 498 element.isPasswordField()) |
499 return; | 499 return; |
500 if (!datalist_only && !element.suggestedValue().isEmpty()) | 500 if (!datalist_only && !element.suggestedValue().isEmpty()) |
501 return; | 501 return; |
502 | 502 |
503 // Don't attempt to autofill with values that are too large or if filling | 503 // Don't attempt to autofill with values that are too large or if filling |
504 // criteria are not met. | 504 // criteria are not met. |
505 WebString value = element.editingValue(); | 505 WebString value = element.editingValue(); |
506 if (!datalist_only && | 506 if (!datalist_only && |
507 (value.length() > kMaxDataLength || | 507 (value.length() > kMaxDataLength || |
508 (!autofill_on_empty_values && value.isEmpty()) || | 508 (!autofill_on_empty_values && value.isEmpty()) || |
509 (requires_caret_at_end && | 509 (requires_caret_at_end && |
510 (element.selectionStart() != element.selectionEnd() || | 510 (element.selectionStart() != element.selectionEnd() || |
511 element.selectionEnd() != static_cast<int>(value.length()))))) { | 511 element.selectionEnd() != static_cast<int>(value.length()))))) { |
512 // Any popup currently showing is obsolete. | 512 // Any popup currently showing is obsolete. |
513 HideAutofillUI(); | 513 HideAutofillUI(); |
514 return; | 514 return; |
515 } | 515 } |
516 | 516 |
517 element_ = element; | 517 element_ = element; |
518 if (password_autofill_agent_->ShowSuggestions(element)) | 518 if (password_autofill_agent_->ShowSuggestions(element, show_all)) |
519 return; | 519 return; |
520 | 520 |
521 // If autocomplete is disabled at the field level, ensure that the native | 521 // 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 | 522 // 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() | 523 // 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 | 524 // as it does not allow us to distinguish the case where autocomplete is |
525 // disabled for *both* the element and for the form. | 525 // disabled for *both* the element and for the form. |
526 const base::string16 autocomplete_attribute = | 526 const base::string16 autocomplete_attribute = |
527 element.getAttribute("autocomplete"); | 527 element.getAttribute("autocomplete"); |
528 if (LowerCaseEqualsASCII(autocomplete_attribute, "off")) | 528 if (LowerCaseEqualsASCII(autocomplete_attribute, "off")) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 // Only monitors dynamic forms created in the top frame. Dynamic forms | 630 // Only monitors dynamic forms created in the top frame. Dynamic forms |
631 // inserted in iframes are not captured yet. | 631 // inserted in iframes are not captured yet. |
632 if (!frame->parent()) { | 632 if (!frame->parent()) { |
633 password_autofill_agent_->OnDynamicFormsSeen(frame); | 633 password_autofill_agent_->OnDynamicFormsSeen(frame); |
634 return; | 634 return; |
635 } | 635 } |
636 } | 636 } |
637 } | 637 } |
638 | 638 |
639 } // namespace autofill | 639 } // namespace autofill |
OLD | NEW |