Chromium Code Reviews| 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) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 470 WebKit::WebFrame* frame = user_input.document().frame(); | 484 WebKit::WebFrame* frame = user_input.document().frame(); |
| 471 if (!frame) | 485 if (!frame) |
| 472 return false; | 486 return false; |
| 473 | 487 |
| 474 WebKit::WebView* webview = frame->view(); | 488 WebKit::WebView* webview = frame->view(); |
| 475 if (!webview) | 489 if (!webview) |
| 476 return false; | 490 return false; |
| 477 | 491 |
| 478 std::vector<string16> suggestions; | 492 std::vector<string16> suggestions; |
| 479 GetSuggestions(fill_data, user_input.value(), &suggestions); | 493 GetSuggestions(fill_data, user_input.value(), &suggestions); |
| 494 | |
| 495 if (disable_popup_) { | |
| 496 WebKit::WebInputElement selected_element = user_input; | |
| 497 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); | |
| 498 Send(new AutofillHostMsg_ShowPasswordSuggestions(routing_id(), | |
| 499 bounding_box, | |
| 500 suggestions)); | |
|
Ilya Sherman
2012/03/20 00:58:55
Hmm, I really don't like that the PasswordAutofill
csharp
2012/03/21 14:10:31
I didn't look much into if we could refactor to sh
| |
| 501 return !suggestions.empty(); | |
| 502 } | |
| 503 | |
| 504 | |
| 480 if (suggestions.empty()) { | 505 if (suggestions.empty()) { |
| 481 webview->hidePopups(); | 506 webview->hidePopups(); |
| 482 return false; | 507 return false; |
| 483 } | 508 } |
| 484 | 509 |
| 485 std::vector<string16> labels(suggestions.size()); | 510 std::vector<string16> labels(suggestions.size()); |
| 486 std::vector<string16> icons(suggestions.size()); | 511 std::vector<string16> icons(suggestions.size()); |
| 487 std::vector<int> ids(suggestions.size(), 0); | 512 std::vector<int> ids(suggestions.size(), 0); |
| 488 webview->applyAutofillSuggestions( | 513 webview->applyAutofillSuggestions( |
| 489 user_input, suggestions, labels, icons, ids, -1); | 514 user_input, suggestions, labels, icons, ids, -1); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 611 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
| 587 if (iter == login_to_password_info_.end()) | 612 if (iter == login_to_password_info_.end()) |
| 588 return false; | 613 return false; |
| 589 | 614 |
| 590 *found_input = input; | 615 *found_input = input; |
| 591 *found_password = iter->second; | 616 *found_password = iter->second; |
| 592 return true; | 617 return true; |
| 593 } | 618 } |
| 594 | 619 |
| 595 } // namespace autofill | 620 } // namespace autofill |
| OLD | NEW |