OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/renderer/autofill/password_autofill_manager.h" | 5 #include "chrome/renderer/autofill/password_autofill_manager.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.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/common/autofill_messages.h" | 10 #include "chrome/common/autofill_messages.h" |
| 11 #include "chrome/renderer/autofill/form_autofill_util.h" |
11 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
20 #include "ui/base/keycodes/keyboard_codes.h" | 21 #include "ui/base/keycodes/keyboard_codes.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } // namespace | 198 } // namespace |
198 | 199 |
199 namespace autofill { | 200 namespace autofill { |
200 | 201 |
201 //////////////////////////////////////////////////////////////////////////////// | 202 //////////////////////////////////////////////////////////////////////////////// |
202 // PasswordAutofillManager, public: | 203 // PasswordAutofillManager, public: |
203 | 204 |
204 PasswordAutofillManager::PasswordAutofillManager( | 205 PasswordAutofillManager::PasswordAutofillManager( |
205 content::RenderView* render_view) | 206 content::RenderView* render_view) |
206 : content::RenderViewObserver(render_view), | 207 : content::RenderViewObserver(render_view), |
| 208 disable_popup_(false), |
207 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 209 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
208 } | 210 } |
209 | 211 |
210 PasswordAutofillManager::~PasswordAutofillManager() { | 212 PasswordAutofillManager::~PasswordAutofillManager() { |
211 } | 213 } |
212 | 214 |
213 bool PasswordAutofillManager::TextFieldDidEndEditing( | 215 bool PasswordAutofillManager::TextFieldDidEndEditing( |
214 const WebKit::WebInputElement& element) { | 216 const WebKit::WebInputElement& element) { |
215 LoginToPasswordInfoMap::const_iterator iter = | 217 LoginToPasswordInfoMap::const_iterator iter = |
216 login_to_password_info_.find(element); | 218 login_to_password_info_.find(element); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 bool is_focused) { | 405 bool is_focused) { |
404 // TODO(jcivelli): http://crbug.com/51644 Implement behavior. | 406 // TODO(jcivelli): http://crbug.com/51644 Implement behavior. |
405 return false; | 407 return false; |
406 } | 408 } |
407 | 409 |
408 bool PasswordAutofillManager::InputElementLostFocus() { | 410 bool PasswordAutofillManager::InputElementLostFocus() { |
409 return false; | 411 return false; |
410 } | 412 } |
411 | 413 |
412 void PasswordAutofillManager::OnFillPasswordForm( | 414 void PasswordAutofillManager::OnFillPasswordForm( |
413 const webkit::forms::PasswordFormFillData& form_data) { | 415 const webkit::forms::PasswordFormFillData& form_data, |
| 416 bool disable_popup) { |
| 417 disable_popup_ = disable_popup; |
| 418 |
414 FormElementsList forms; | 419 FormElementsList forms; |
415 // We own the FormElements* in forms. | 420 // We own the FormElements* in forms. |
416 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms); | 421 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms); |
417 FormElementsList::iterator iter; | 422 FormElementsList::iterator iter; |
418 for (iter = forms.begin(); iter != forms.end(); ++iter) { | 423 for (iter = forms.begin(); iter != forms.end(); ++iter) { |
419 scoped_ptr<FormElements> form_elements(*iter); | 424 scoped_ptr<FormElements> form_elements(*iter); |
420 | 425 |
421 // If wait_for_username is true, we don't want to initially fill the form | 426 // If wait_for_username is true, we don't want to initially fill the form |
422 // until the user types in a valid username. | 427 // until the user types in a valid username. |
423 if (!form_data.wait_for_username) | 428 if (!form_data.wait_for_username) |
(...skipping 12 matching lines...) Expand all Loading... |
436 // We might have already filled this form if there are two <form> elements | 441 // We might have already filled this form if there are two <form> elements |
437 // with identical markup. | 442 // with identical markup. |
438 if (login_to_password_info_.find(username_element) != | 443 if (login_to_password_info_.find(username_element) != |
439 login_to_password_info_.end()) | 444 login_to_password_info_.end()) |
440 continue; | 445 continue; |
441 | 446 |
442 PasswordInfo password_info; | 447 PasswordInfo password_info; |
443 password_info.fill_data = form_data; | 448 password_info.fill_data = form_data; |
444 password_info.password_field = password_element; | 449 password_info.password_field = password_element; |
445 login_to_password_info_[username_element] = password_info; | 450 login_to_password_info_[username_element] = password_info; |
| 451 |
| 452 webkit::forms::FormData form; |
| 453 webkit::forms::FormField field; |
| 454 FindFormAndFieldForInputElement( |
| 455 username_element, &form, &field, REQUIRE_NONE); |
| 456 Send(new AutofillHostMsg_AddPasswordFormMapping( |
| 457 routing_id(), |
| 458 field, |
| 459 form_data)); |
446 } | 460 } |
447 } | 461 } |
448 | 462 |
449 //////////////////////////////////////////////////////////////////////////////// | 463 //////////////////////////////////////////////////////////////////////////////// |
450 // PasswordAutofillManager, private: | 464 // PasswordAutofillManager, private: |
451 | 465 |
452 void PasswordAutofillManager::GetSuggestions( | 466 void PasswordAutofillManager::GetSuggestions( |
453 const webkit::forms::PasswordFormFillData& fill_data, | 467 const webkit::forms::PasswordFormFillData& fill_data, |
454 const string16& input, | 468 const string16& input, |
455 std::vector<string16>* suggestions) { | 469 std::vector<string16>* suggestions) { |
456 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) | 470 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) |
457 suggestions->push_back(fill_data.basic_data.fields[0].value); | 471 suggestions->push_back(fill_data.basic_data.fields[0].value); |
458 | 472 |
459 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; | 473 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; |
460 for (iter = fill_data.additional_logins.begin(); | 474 for (iter = fill_data.additional_logins.begin(); |
461 iter != fill_data.additional_logins.end(); ++iter) { | 475 iter != fill_data.additional_logins.end(); ++iter) { |
462 if (StartsWith(iter->first, input, false)) | 476 if (StartsWith(iter->first, input, false)) |
463 suggestions->push_back(iter->first); | 477 suggestions->push_back(iter->first); |
464 } | 478 } |
465 } | 479 } |
466 | 480 |
467 bool PasswordAutofillManager::ShowSuggestionPopup( | 481 bool PasswordAutofillManager::ShowSuggestionPopup( |
468 const webkit::forms::PasswordFormFillData& fill_data, | 482 const webkit::forms::PasswordFormFillData& fill_data, |
469 const WebKit::WebInputElement& user_input) { | 483 const WebKit::WebInputElement& user_input) { |
| 484 if (disable_popup_) |
| 485 return false; |
| 486 |
470 WebKit::WebFrame* frame = user_input.document().frame(); | 487 WebKit::WebFrame* frame = user_input.document().frame(); |
471 if (!frame) | 488 if (!frame) |
472 return false; | 489 return false; |
473 | 490 |
474 WebKit::WebView* webview = frame->view(); | 491 WebKit::WebView* webview = frame->view(); |
475 if (!webview) | 492 if (!webview) |
476 return false; | 493 return false; |
477 | 494 |
478 std::vector<string16> suggestions; | 495 std::vector<string16> suggestions; |
479 GetSuggestions(fill_data, user_input.value(), &suggestions); | 496 GetSuggestions(fill_data, user_input.value(), &suggestions); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 603 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
587 if (iter == login_to_password_info_.end()) | 604 if (iter == login_to_password_info_.end()) |
588 return false; | 605 return false; |
589 | 606 |
590 *found_input = input; | 607 *found_input = input; |
591 *found_password = iter->second; | 608 *found_password = iter->second; |
592 return true; | 609 return true; |
593 } | 610 } |
594 | 611 |
595 } // namespace autofill | 612 } // namespace autofill |
OLD | NEW |