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/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "components/autofill/content/renderer/form_autofill_util.h" | 12 #include "components/autofill/content/renderer/form_autofill_util.h" |
13 #include "components/autofill/core/common/autofill_messages.h" | 13 #include "components/autofill/core/common/autofill_messages.h" |
14 #include "components/autofill/core/common/form_field_data.h" | 14 #include "components/autofill/core/common/form_field_data.h" |
15 #include "components/autofill/core/common/password_form_fill_data.h" | 15 #include "components/autofill/core/common/password_form_fill_data.h" |
16 #include "content/public/common/password_form.h" | 16 #include "content/public/common/password_form.h" |
17 #include "content/public/renderer/password_form_conversion_utils.h" | 17 #include "content/public/renderer/password_form_conversion_utils.h" |
18 #include "content/public/renderer/render_view.h" | 18 #include "content/public/renderer/render_view.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
20 #include "third_party/WebKit/public/web/WebAutofillClient.h" | 20 #include "third_party/WebKit/public/web/WebAutofillClient.h" |
21 #include "third_party/WebKit/public/web/WebDocument.h" | 21 #include "third_party/WebKit/public/web/WebDocument.h" |
22 #include "third_party/WebKit/public/web/WebElement.h" | 22 #include "third_party/WebKit/public/web/WebElement.h" |
23 #include "third_party/WebKit/public/web/WebFormElement.h" | 23 #include "third_party/WebKit/public/web/WebFormElement.h" |
24 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebFrame.h" |
25 #include "third_party/WebKit/public/web/WebInputEvent.h" | 25 #include "third_party/WebKit/public/web/WebInputEvent.h" |
26 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 26 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 27 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
27 #include "third_party/WebKit/public/web/WebView.h" | 28 #include "third_party/WebKit/public/web/WebView.h" |
28 #include "ui/base/keycodes/keyboard_codes.h" | 29 #include "ui/base/keycodes/keyboard_codes.h" |
29 | 30 |
30 namespace autofill { | 31 namespace autofill { |
31 namespace { | 32 namespace { |
32 | 33 |
33 // The size above which we stop triggering autocomplete. | 34 // The size above which we stop triggering autocomplete. |
34 static const size_t kMaximumTextSizeForAutocomplete = 1000; | 35 static const size_t kMaximumTextSizeForAutocomplete = 1000; |
35 | 36 |
36 // Maps element names to the actual elements to simplify form filling. | 37 // Maps element names to the actual elements to simplify form filling. |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 } | 421 } |
421 | 422 |
422 void PasswordAutofillAgent::FrameDetached(WebKit::WebFrame* frame) { | 423 void PasswordAutofillAgent::FrameDetached(WebKit::WebFrame* frame) { |
423 FrameClosing(frame); | 424 FrameClosing(frame); |
424 } | 425 } |
425 | 426 |
426 void PasswordAutofillAgent::FrameWillClose(WebKit::WebFrame* frame) { | 427 void PasswordAutofillAgent::FrameWillClose(WebKit::WebFrame* frame) { |
427 FrameClosing(frame); | 428 FrameClosing(frame); |
428 } | 429 } |
429 | 430 |
| 431 void PasswordAutofillAgent::WillSendSubmitEvent( |
| 432 WebKit::WebFrame* frame, |
| 433 const WebKit::WebFormElement& form) { |
| 434 // Some login forms have onSubmit handlers that put a hash of the password |
| 435 // into a hidden field and then clear the password (http://crbug.com/28910). |
| 436 // This method gets called before any of those handlers run, so save away |
| 437 // a copy of the password in case it gets lost. |
| 438 provisionally_saved_forms_[frame].reset( |
| 439 content::CreatePasswordForm(form).release()); |
| 440 } |
| 441 |
| 442 void PasswordAutofillAgent::WillSubmitForm(WebKit::WebFrame* frame, |
| 443 const WebKit::WebFormElement& form) { |
| 444 scoped_ptr<content::PasswordForm> submitted_form = |
| 445 content::CreatePasswordForm(form); |
| 446 |
| 447 // If there is a provisionally saved password, copy over the previous |
| 448 // password value so we get the user's typed password, not the value that |
| 449 // may have been transformed for submit. |
| 450 // TODO(gcasto): Do we need to have this action equality check? Is it trying |
| 451 // to prevent accidentally copying over passwords from a different form? |
| 452 if (submitted_form) { |
| 453 if (provisionally_saved_forms_[frame].get() && |
| 454 submitted_form->action == provisionally_saved_forms_[frame]->action) { |
| 455 submitted_form->password_value = |
| 456 provisionally_saved_forms_[frame]->password_value; |
| 457 } |
| 458 |
| 459 // Some observers depend on sending this information now instead of when |
| 460 // the frame starts loading. If there are redirects that cause a new |
| 461 // RenderView to be instantiated (such as redirects to the WebStore) |
| 462 // we will never get to finish the load. |
| 463 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), |
| 464 *submitted_form)); |
| 465 // Remove reference since we have already submitted this form. |
| 466 provisionally_saved_forms_.erase(frame); |
| 467 } |
| 468 } |
| 469 |
| 470 void PasswordAutofillAgent::DidStartProvisionalLoad(WebKit::WebFrame* frame) { |
| 471 if (!frame->parent()) { |
| 472 // If the navigation is not triggered by a user gesture, e.g. by some ajax |
| 473 // callback, then inherit the submitted password form from the previous |
| 474 // state. This fixes the no password save issue for ajax login, tracked in |
| 475 // [http://crbug/43219]. Note that there are still some sites that this |
| 476 // fails for because they use some element other than a submit button to |
| 477 // trigger submission (which means WillSendSubmitEvent will not be called). |
| 478 if (!WebKit::WebUserGestureIndicator::isProcessingUserGesture() && |
| 479 provisionally_saved_forms_[frame].get()) { |
| 480 Send(new AutofillHostMsg_PasswordFormSubmitted( |
| 481 routing_id(), |
| 482 *provisionally_saved_forms_[frame])); |
| 483 provisionally_saved_forms_.erase(frame); |
| 484 } |
| 485 // Clear the whole map during main frame navigation. |
| 486 provisionally_saved_forms_.clear(); |
| 487 } |
| 488 } |
| 489 |
430 void PasswordAutofillAgent::OnFillPasswordForm( | 490 void PasswordAutofillAgent::OnFillPasswordForm( |
431 const PasswordFormFillData& form_data) { | 491 const PasswordFormFillData& form_data) { |
432 if (usernames_usage_ == NOTHING_TO_AUTOFILL) { | 492 if (usernames_usage_ == NOTHING_TO_AUTOFILL) { |
433 if (form_data.other_possible_usernames.size()) | 493 if (form_data.other_possible_usernames.size()) |
434 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT; | 494 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT; |
435 else if (usernames_usage_ == NOTHING_TO_AUTOFILL) | 495 else if (usernames_usage_ == NOTHING_TO_AUTOFILL) |
436 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT; | 496 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT; |
437 } | 497 } |
438 | 498 |
439 FormElementsList forms; | 499 FormElementsList forms; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 730 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
671 if (iter == login_to_password_info_.end()) | 731 if (iter == login_to_password_info_.end()) |
672 return false; | 732 return false; |
673 | 733 |
674 *found_input = input; | 734 *found_input = input; |
675 *found_password = iter->second; | 735 *found_password = iter->second; |
676 return true; | 736 return true; |
677 } | 737 } |
678 | 738 |
679 } // namespace autofill | 739 } // namespace autofill |
OLD | NEW |