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. (Issue 28910.) | |
Ilya Sherman
2013/07/27 01:09:48
nit: Could you make the bug reference into an http
Garrett Casto
2013/08/03 00:38:42
Done.
| |
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 provisional_forms_[frame].reset(content::CreatePasswordForm(form).release()); | |
Ilya Sherman
2013/07/27 01:09:48
Is there a guarantee that we will free elements fr
Garrett Casto
2013/08/03 00:38:42
I was actually thinking about this earlier, and I
| |
439 } | |
440 | |
441 void PasswordAutofillAgent::WillSubmitForm(WebKit::WebFrame* frame, | |
442 const WebKit::WebFormElement& form) { | |
443 scoped_ptr<content::PasswordForm> submitted_form = | |
444 content::CreatePasswordForm(form); | |
445 | |
446 // If there is a provisionally saved password, copy over the previous | |
447 // password value so we get the users typed password, not the value that | |
Ilya Sherman
2013/07/27 01:09:48
nit: "users" -> "user's"
Garrett Casto
2013/08/03 00:38:42
Done.
| |
448 // may have been transformed for submit. | |
449 // TODO(gcasto): Do we need to have this action equality check? Is it trying | |
450 // to prevent accidentally copying over passwords from a different form? | |
451 if (submitted_form.get()) { | |
Ilya Sherman
2013/07/27 01:09:48
nit: No need for .get()
Garrett Casto
2013/08/03 00:38:42
Done.
| |
452 if (provisional_forms_[frame].get() && | |
Ilya Sherman
2013/07/27 01:09:48
nit: Ditto
Garrett Casto
2013/08/03 00:38:42
linked_ptr<> aren't convertible to bool, so this d
| |
453 submitted_form->action == provisional_forms_[frame]->action) { | |
454 submitted_form->password_value = | |
455 provisional_forms_[frame]->password_value; | |
456 } | |
Ilya Sherman
2013/07/27 01:09:48
nit: Please leave a blank line after this one.
Garrett Casto
2013/08/03 00:38:42
Done.
| |
457 // Some observers depend on sending this information now instead of when | |
458 // the frame starts loading. If there are redirects that cause a new | |
459 // RenderView to be instantiated (such as redirects to the WebStore) | |
460 // we will never get to finish the load. | |
461 Send(new AutofillHostMsg_PasswordFormSubmitted(routing_id(), | |
462 *submitted_form.get())); | |
Ilya Sherman
2013/07/27 01:09:48
nit: No need for .get()
Garrett Casto
2013/08/03 00:38:42
Done.
| |
463 // Remove reference since we have already submitted this form. | |
464 provisional_forms_.erase(frame); | |
465 } | |
466 } | |
467 | |
468 void PasswordAutofillAgent::DidStartProvisionalLoad(WebKit::WebFrame* frame) { | |
469 // If the navigation is not triggered by a user gesture, e.g. by some ajax | |
470 // callback, then inherit the submitted password form from the previous | |
471 // state. This fixes the no password save issue for ajax login, tracked in | |
472 // [http://crbug/43219]. Note that there are still some sites that this | |
473 // fails for because they use some element other than a submit button to | |
474 // trigger submission (which means WillSendSubmitEvent will not be called). | |
475 if (!frame->parent() && | |
476 !WebKit::WebUserGestureIndicator::isProcessingUserGesture() && | |
477 provisional_forms_[frame].get()) { | |
Ilya Sherman
2013/07/27 01:09:48
nit: No need for .get()
Garrett Casto
2013/08/03 00:38:42
Doesn't work.
| |
478 Send(new AutofillHostMsg_PasswordFormSubmitted( | |
479 routing_id(), | |
480 *provisional_forms_[frame].get())); | |
Ilya Sherman
2013/07/27 01:09:48
nit: No need for .get()
Garrett Casto
2013/08/03 00:38:42
Done.
Garrett Casto
2013/08/03 00:38:42
Done.
| |
481 } | |
482 provisional_forms_.erase(frame); | |
Ilya Sherman
2013/07/27 01:09:48
Can we clear the whole map if the |frame| is a top
Garrett Casto
2013/08/03 00:38:42
Sure.
| |
483 } | |
484 | |
430 void PasswordAutofillAgent::OnFillPasswordForm( | 485 void PasswordAutofillAgent::OnFillPasswordForm( |
431 const PasswordFormFillData& form_data) { | 486 const PasswordFormFillData& form_data) { |
432 if (usernames_usage_ == NOTHING_TO_AUTOFILL) { | 487 if (usernames_usage_ == NOTHING_TO_AUTOFILL) { |
433 if (form_data.other_possible_usernames.size()) | 488 if (form_data.other_possible_usernames.size()) |
434 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT; | 489 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_PRESENT; |
435 else if (usernames_usage_ == NOTHING_TO_AUTOFILL) | 490 else if (usernames_usage_ == NOTHING_TO_AUTOFILL) |
436 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT; | 491 usernames_usage_ = OTHER_POSSIBLE_USERNAMES_ABSENT; |
437 } | 492 } |
438 | 493 |
439 FormElementsList forms; | 494 FormElementsList forms; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 723 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
669 if (iter == login_to_password_info_.end()) | 724 if (iter == login_to_password_info_.end()) |
670 return false; | 725 return false; |
671 | 726 |
672 *found_input = input; | 727 *found_input = input; |
673 *found_password = iter->second; | 728 *found_password = iter->second; |
674 return true; | 729 return true; |
675 } | 730 } |
676 | 731 |
677 } // namespace autofill | 732 } // namespace autofill |
OLD | NEW |