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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 return FindLoginInfo(node, &input, &password); | 326 return FindLoginInfo(node, &input, &password); |
326 } | 327 } |
327 | 328 |
328 bool PasswordAutofillManager::DidClearAutofillSelection( | 329 bool PasswordAutofillManager::DidClearAutofillSelection( |
329 const WebKit::WebNode& node) { | 330 const WebKit::WebNode& node) { |
330 WebKit::WebInputElement input; | 331 WebKit::WebInputElement input; |
331 PasswordInfo password; | 332 PasswordInfo password; |
332 return FindLoginInfo(node, &input, &password); | 333 return FindLoginInfo(node, &input, &password); |
333 } | 334 } |
334 | 335 |
| 336 void PasswordAutofillManager::HandleKeyDown(const WebKit::WebInputElement& node, |
| 337 int key_code) { |
| 338 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(node); |
| 339 if (iter == login_to_password_info_.end()) { |
| 340 // The browser code should only send this message when it knows we have a |
| 341 // match. |
| 342 NOTREACHED(); |
| 343 return; |
| 344 } |
| 345 |
| 346 iter->second.backspace_pressed_last = |
| 347 (key_code == ui::VKEY_BACK || key_code == ui::VKEY_DELETE); |
| 348 } |
| 349 |
335 void PasswordAutofillManager::SendPasswordForms(WebKit::WebFrame* frame, | 350 void PasswordAutofillManager::SendPasswordForms(WebKit::WebFrame* frame, |
336 bool only_visible) { | 351 bool only_visible) { |
337 // Make sure that this security origin is allowed to use password manager. | 352 // Make sure that this security origin is allowed to use password manager. |
338 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); | 353 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); |
339 if (!origin.canAccessPasswordManager()) | 354 if (!origin.canAccessPasswordManager()) |
340 return; | 355 return; |
341 | 356 |
342 WebKit::WebVector<WebKit::WebFormElement> forms; | 357 WebKit::WebVector<WebKit::WebFormElement> forms; |
343 frame->document().forms(forms); | 358 frame->document().forms(forms); |
344 | 359 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 // We might have already filled this form if there are two <form> elements | 451 // We might have already filled this form if there are two <form> elements |
437 // with identical markup. | 452 // with identical markup. |
438 if (login_to_password_info_.find(username_element) != | 453 if (login_to_password_info_.find(username_element) != |
439 login_to_password_info_.end()) | 454 login_to_password_info_.end()) |
440 continue; | 455 continue; |
441 | 456 |
442 PasswordInfo password_info; | 457 PasswordInfo password_info; |
443 password_info.fill_data = form_data; | 458 password_info.fill_data = form_data; |
444 password_info.password_field = password_element; | 459 password_info.password_field = password_element; |
445 login_to_password_info_[username_element] = password_info; | 460 login_to_password_info_[username_element] = password_info; |
| 461 |
| 462 webkit::forms::FormData form; |
| 463 webkit::forms::FormField field; |
| 464 FindFormAndFieldForInputElement( |
| 465 username_element, &form, &field, REQUIRE_NONE); |
| 466 Send(new AutofillHostMsg_FillPasswordForm( |
| 467 routing_id(), |
| 468 field, |
| 469 form_data, |
| 470 username_element.document().frame()->identifier())); |
446 } | 471 } |
447 } | 472 } |
448 | 473 |
449 //////////////////////////////////////////////////////////////////////////////// | 474 //////////////////////////////////////////////////////////////////////////////// |
450 // PasswordAutofillManager, private: | 475 // PasswordAutofillManager, private: |
451 | 476 |
452 void PasswordAutofillManager::GetSuggestions( | 477 void PasswordAutofillManager::GetSuggestions( |
453 const webkit::forms::PasswordFormFillData& fill_data, | 478 const webkit::forms::PasswordFormFillData& fill_data, |
454 const string16& input, | 479 const string16& input, |
455 std::vector<string16>* suggestions) { | 480 std::vector<string16>* suggestions) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 } | 587 } |
563 | 588 |
564 void PasswordAutofillManager::FrameClosing(const WebKit::WebFrame* frame) { | 589 void PasswordAutofillManager::FrameClosing(const WebKit::WebFrame* frame) { |
565 for (LoginToPasswordInfoMap::iterator iter = login_to_password_info_.begin(); | 590 for (LoginToPasswordInfoMap::iterator iter = login_to_password_info_.begin(); |
566 iter != login_to_password_info_.end();) { | 591 iter != login_to_password_info_.end();) { |
567 if (iter->first.document().frame() == frame) | 592 if (iter->first.document().frame() == frame) |
568 login_to_password_info_.erase(iter++); | 593 login_to_password_info_.erase(iter++); |
569 else | 594 else |
570 ++iter; | 595 ++iter; |
571 } | 596 } |
| 597 |
| 598 // Inform the Browser-side Password Manager of the closing frame. |
| 599 Send(new AutofillHostMsg_FrameClosing(routing_id(), frame->identifier())); |
572 } | 600 } |
573 | 601 |
574 bool PasswordAutofillManager::FindLoginInfo( | 602 bool PasswordAutofillManager::FindLoginInfo( |
575 const WebKit::WebNode& node, | 603 const WebKit::WebNode& node, |
576 WebKit::WebInputElement* found_input, | 604 WebKit::WebInputElement* found_input, |
577 PasswordInfo* found_password) { | 605 PasswordInfo* found_password) { |
578 if (!node.isElementNode()) | 606 if (!node.isElementNode()) |
579 return false; | 607 return false; |
580 | 608 |
581 WebKit::WebElement element = node.toConst<WebKit::WebElement>(); | 609 WebKit::WebElement element = node.toConst<WebKit::WebElement>(); |
582 if (!element.hasTagName("input")) | 610 if (!element.hasTagName("input")) |
583 return false; | 611 return false; |
584 | 612 |
585 WebKit::WebInputElement input = element.to<WebKit::WebInputElement>(); | 613 WebKit::WebInputElement input = element.to<WebKit::WebInputElement>(); |
586 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 614 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
587 if (iter == login_to_password_info_.end()) | 615 if (iter == login_to_password_info_.end()) |
588 return false; | 616 return false; |
589 | 617 |
590 *found_input = input; | 618 *found_input = input; |
591 *found_password = iter->second; | 619 *found_password = iter->second; |
592 return true; | 620 return true; |
593 } | 621 } |
594 | 622 |
595 } // namespace autofill | 623 } // namespace autofill |
OLD | NEW |