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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 return FindLoginInfo(node, &input, &password); | 327 return FindLoginInfo(node, &input, &password); |
| 326 } | 328 } |
| 327 | 329 |
| 328 bool PasswordAutofillManager::DidClearAutofillSelection( | 330 bool PasswordAutofillManager::DidClearAutofillSelection( |
| 329 const WebKit::WebNode& node) { | 331 const WebKit::WebNode& node) { |
| 330 WebKit::WebInputElement input; | 332 WebKit::WebInputElement input; |
| 331 PasswordInfo password; | 333 PasswordInfo password; |
| 332 return FindLoginInfo(node, &input, &password); | 334 return FindLoginInfo(node, &input, &password); |
| 333 } | 335 } |
| 334 | 336 |
| 337 void PasswordAutofillManager::HandleKeyDown(const WebKit::WebInputElement& node, | |
| 338 int key_code) { | |
| 339 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(node); | |
| 340 if (iter == login_to_password_info_.end()) { | |
| 341 // The browser code should only send this message when it knows we have a | |
| 342 // match. | |
| 343 NOTREACHED(); | |
| 344 return; | |
| 345 } | |
| 346 | |
| 347 iter->second.backspace_pressed_last = | |
| 348 (key_code == ui::VKEY_BACK || key_code == ui::VKEY_DELETE); | |
|
Ilya Sherman
2012/03/12 23:46:13
Hmm, I thought we were letting the event bubble na
csharp
2012/03/13 18:31:14
This code was from when I was handling it in the b
| |
| 349 } | |
| 350 | |
| 335 void PasswordAutofillManager::SendPasswordForms(WebKit::WebFrame* frame, | 351 void PasswordAutofillManager::SendPasswordForms(WebKit::WebFrame* frame, |
| 336 bool only_visible) { | 352 bool only_visible) { |
| 337 // Make sure that this security origin is allowed to use password manager. | 353 // Make sure that this security origin is allowed to use password manager. |
| 338 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); | 354 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); |
| 339 if (!origin.canAccessPasswordManager()) | 355 if (!origin.canAccessPasswordManager()) |
| 340 return; | 356 return; |
| 341 | 357 |
| 342 WebKit::WebVector<WebKit::WebFormElement> forms; | 358 WebKit::WebVector<WebKit::WebFormElement> forms; |
| 343 frame->document().forms(forms); | 359 frame->document().forms(forms); |
| 344 | 360 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 bool is_focused) { | 419 bool is_focused) { |
| 404 // TODO(jcivelli): http://crbug.com/51644 Implement behavior. | 420 // TODO(jcivelli): http://crbug.com/51644 Implement behavior. |
| 405 return false; | 421 return false; |
| 406 } | 422 } |
| 407 | 423 |
| 408 bool PasswordAutofillManager::InputElementLostFocus() { | 424 bool PasswordAutofillManager::InputElementLostFocus() { |
| 409 return false; | 425 return false; |
| 410 } | 426 } |
| 411 | 427 |
| 412 void PasswordAutofillManager::OnFillPasswordForm( | 428 void PasswordAutofillManager::OnFillPasswordForm( |
| 413 const webkit::forms::PasswordFormFillData& form_data) { | 429 const webkit::forms::PasswordFormFillData& form_data, |
| 430 bool disable_popup) { | |
| 431 disable_popup_ = disable_popup; | |
| 432 | |
| 414 FormElementsList forms; | 433 FormElementsList forms; |
| 415 // We own the FormElements* in forms. | 434 // We own the FormElements* in forms. |
| 416 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms); | 435 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms); |
| 417 FormElementsList::iterator iter; | 436 FormElementsList::iterator iter; |
| 418 for (iter = forms.begin(); iter != forms.end(); ++iter) { | 437 for (iter = forms.begin(); iter != forms.end(); ++iter) { |
| 419 scoped_ptr<FormElements> form_elements(*iter); | 438 scoped_ptr<FormElements> form_elements(*iter); |
| 420 | 439 |
| 421 // If wait_for_username is true, we don't want to initially fill the form | 440 // If wait_for_username is true, we don't want to initially fill the form |
| 422 // until the user types in a valid username. | 441 // until the user types in a valid username. |
| 423 if (!form_data.wait_for_username) | 442 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 | 455 // We might have already filled this form if there are two <form> elements |
| 437 // with identical markup. | 456 // with identical markup. |
| 438 if (login_to_password_info_.find(username_element) != | 457 if (login_to_password_info_.find(username_element) != |
| 439 login_to_password_info_.end()) | 458 login_to_password_info_.end()) |
| 440 continue; | 459 continue; |
| 441 | 460 |
| 442 PasswordInfo password_info; | 461 PasswordInfo password_info; |
| 443 password_info.fill_data = form_data; | 462 password_info.fill_data = form_data; |
| 444 password_info.password_field = password_element; | 463 password_info.password_field = password_element; |
| 445 login_to_password_info_[username_element] = password_info; | 464 login_to_password_info_[username_element] = password_info; |
| 465 | |
| 466 webkit::forms::FormData form; | |
| 467 webkit::forms::FormField field; | |
| 468 FindFormAndFieldForInputElement( | |
| 469 username_element, &form, &field, REQUIRE_NONE); | |
| 470 Send(new AutofillHostMsg_AddPasswordFormMapping( | |
| 471 routing_id(), | |
| 472 field, | |
| 473 form_data)); | |
| 446 } | 474 } |
| 447 } | 475 } |
| 448 | 476 |
| 449 //////////////////////////////////////////////////////////////////////////////// | 477 //////////////////////////////////////////////////////////////////////////////// |
| 450 // PasswordAutofillManager, private: | 478 // PasswordAutofillManager, private: |
| 451 | 479 |
| 452 void PasswordAutofillManager::GetSuggestions( | 480 void PasswordAutofillManager::GetSuggestions( |
| 453 const webkit::forms::PasswordFormFillData& fill_data, | 481 const webkit::forms::PasswordFormFillData& fill_data, |
| 454 const string16& input, | 482 const string16& input, |
| 455 std::vector<string16>* suggestions) { | 483 std::vector<string16>* suggestions) { |
| 456 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) | 484 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) |
| 457 suggestions->push_back(fill_data.basic_data.fields[0].value); | 485 suggestions->push_back(fill_data.basic_data.fields[0].value); |
| 458 | 486 |
| 459 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; | 487 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; |
| 460 for (iter = fill_data.additional_logins.begin(); | 488 for (iter = fill_data.additional_logins.begin(); |
| 461 iter != fill_data.additional_logins.end(); ++iter) { | 489 iter != fill_data.additional_logins.end(); ++iter) { |
| 462 if (StartsWith(iter->first, input, false)) | 490 if (StartsWith(iter->first, input, false)) |
| 463 suggestions->push_back(iter->first); | 491 suggestions->push_back(iter->first); |
| 464 } | 492 } |
| 465 } | 493 } |
| 466 | 494 |
| 467 bool PasswordAutofillManager::ShowSuggestionPopup( | 495 bool PasswordAutofillManager::ShowSuggestionPopup( |
| 468 const webkit::forms::PasswordFormFillData& fill_data, | 496 const webkit::forms::PasswordFormFillData& fill_data, |
| 469 const WebKit::WebInputElement& user_input) { | 497 const WebKit::WebInputElement& user_input) { |
| 498 if (disable_popup_) | |
| 499 return false; | |
| 500 | |
| 470 WebKit::WebFrame* frame = user_input.document().frame(); | 501 WebKit::WebFrame* frame = user_input.document().frame(); |
| 471 if (!frame) | 502 if (!frame) |
| 472 return false; | 503 return false; |
| 473 | 504 |
| 474 WebKit::WebView* webview = frame->view(); | 505 WebKit::WebView* webview = frame->view(); |
| 475 if (!webview) | 506 if (!webview) |
| 476 return false; | 507 return false; |
| 477 | 508 |
| 478 std::vector<string16> suggestions; | 509 std::vector<string16> suggestions; |
| 479 GetSuggestions(fill_data, user_input.value(), &suggestions); | 510 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); | 617 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
| 587 if (iter == login_to_password_info_.end()) | 618 if (iter == login_to_password_info_.end()) |
| 588 return false; | 619 return false; |
| 589 | 620 |
| 590 *found_input = input; | 621 *found_input = input; |
| 591 *found_password = iter->second; | 622 *found_password = iter->second; |
| 592 return true; | 623 return true; |
| 593 } | 624 } |
| 594 | 625 |
| 595 } // namespace autofill | 626 } // namespace autofill |
| OLD | NEW |