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); | |
349 } | |
350 | |
351 void PasswordAutofillManager::DisablePopup() { | |
352 disable_popup_ = true; | |
353 } | |
354 | |
335 void PasswordAutofillManager::SendPasswordForms(WebKit::WebFrame* frame, | 355 void PasswordAutofillManager::SendPasswordForms(WebKit::WebFrame* frame, |
336 bool only_visible) { | 356 bool only_visible) { |
337 // Make sure that this security origin is allowed to use password manager. | 357 // Make sure that this security origin is allowed to use password manager. |
338 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); | 358 WebKit::WebSecurityOrigin origin = frame->document().securityOrigin(); |
339 if (!origin.canAccessPasswordManager()) | 359 if (!origin.canAccessPasswordManager()) |
340 return; | 360 return; |
341 | 361 |
342 WebKit::WebVector<WebKit::WebFormElement> forms; | 362 WebKit::WebVector<WebKit::WebFormElement> forms; |
343 frame->document().forms(forms); | 363 frame->document().forms(forms); |
344 | 364 |
(...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 | 456 // We might have already filled this form if there are two <form> elements |
437 // with identical markup. | 457 // with identical markup. |
438 if (login_to_password_info_.find(username_element) != | 458 if (login_to_password_info_.find(username_element) != |
439 login_to_password_info_.end()) | 459 login_to_password_info_.end()) |
440 continue; | 460 continue; |
441 | 461 |
442 PasswordInfo password_info; | 462 PasswordInfo password_info; |
443 password_info.fill_data = form_data; | 463 password_info.fill_data = form_data; |
444 password_info.password_field = password_element; | 464 password_info.password_field = password_element; |
445 login_to_password_info_[username_element] = password_info; | 465 login_to_password_info_[username_element] = password_info; |
466 | |
467 webkit::forms::FormData form; | |
468 webkit::forms::FormField field; | |
469 FindFormAndFieldForInputElement( | |
470 username_element, &form, &field, REQUIRE_NONE); | |
471 Send(new AutofillHostMsg_FillPasswordForm( | |
Ilya Sherman
2012/03/08 23:22:14
If I'm now understanding the code correctly, this
csharp
2012/03/09 16:20:19
Yes. Changed the name to try and be a bit clearer.
Ilya Sherman
2012/03/09 22:00:26
Ok. The current approach should be fine -- I'm ju
| |
472 routing_id(), | |
473 field, | |
474 form_data, | |
475 username_element.document().frame()->identifier())); | |
446 } | 476 } |
447 } | 477 } |
448 | 478 |
449 //////////////////////////////////////////////////////////////////////////////// | 479 //////////////////////////////////////////////////////////////////////////////// |
450 // PasswordAutofillManager, private: | 480 // PasswordAutofillManager, private: |
451 | 481 |
452 void PasswordAutofillManager::GetSuggestions( | 482 void PasswordAutofillManager::GetSuggestions( |
453 const webkit::forms::PasswordFormFillData& fill_data, | 483 const webkit::forms::PasswordFormFillData& fill_data, |
454 const string16& input, | 484 const string16& input, |
455 std::vector<string16>* suggestions) { | 485 std::vector<string16>* suggestions) { |
456 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) | 486 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) |
457 suggestions->push_back(fill_data.basic_data.fields[0].value); | 487 suggestions->push_back(fill_data.basic_data.fields[0].value); |
458 | 488 |
459 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; | 489 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; |
460 for (iter = fill_data.additional_logins.begin(); | 490 for (iter = fill_data.additional_logins.begin(); |
461 iter != fill_data.additional_logins.end(); ++iter) { | 491 iter != fill_data.additional_logins.end(); ++iter) { |
462 if (StartsWith(iter->first, input, false)) | 492 if (StartsWith(iter->first, input, false)) |
463 suggestions->push_back(iter->first); | 493 suggestions->push_back(iter->first); |
464 } | 494 } |
465 } | 495 } |
466 | 496 |
467 bool PasswordAutofillManager::ShowSuggestionPopup( | 497 bool PasswordAutofillManager::ShowSuggestionPopup( |
468 const webkit::forms::PasswordFormFillData& fill_data, | 498 const webkit::forms::PasswordFormFillData& fill_data, |
469 const WebKit::WebInputElement& user_input) { | 499 const WebKit::WebInputElement& user_input) { |
500 if (disable_popup_) | |
501 return false; | |
502 | |
470 WebKit::WebFrame* frame = user_input.document().frame(); | 503 WebKit::WebFrame* frame = user_input.document().frame(); |
471 if (!frame) | 504 if (!frame) |
472 return false; | 505 return false; |
473 | 506 |
474 WebKit::WebView* webview = frame->view(); | 507 WebKit::WebView* webview = frame->view(); |
475 if (!webview) | 508 if (!webview) |
476 return false; | 509 return false; |
477 | 510 |
478 std::vector<string16> suggestions; | 511 std::vector<string16> suggestions; |
479 GetSuggestions(fill_data, user_input.value(), &suggestions); | 512 GetSuggestions(fill_data, user_input.value(), &suggestions); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 } | 595 } |
563 | 596 |
564 void PasswordAutofillManager::FrameClosing(const WebKit::WebFrame* frame) { | 597 void PasswordAutofillManager::FrameClosing(const WebKit::WebFrame* frame) { |
565 for (LoginToPasswordInfoMap::iterator iter = login_to_password_info_.begin(); | 598 for (LoginToPasswordInfoMap::iterator iter = login_to_password_info_.begin(); |
566 iter != login_to_password_info_.end();) { | 599 iter != login_to_password_info_.end();) { |
567 if (iter->first.document().frame() == frame) | 600 if (iter->first.document().frame() == frame) |
568 login_to_password_info_.erase(iter++); | 601 login_to_password_info_.erase(iter++); |
569 else | 602 else |
570 ++iter; | 603 ++iter; |
571 } | 604 } |
605 | |
606 // Inform the Browser-side Password Manager of the closing frame. | |
607 Send(new AutofillHostMsg_FrameClosing(routing_id(), frame->identifier())); | |
572 } | 608 } |
573 | 609 |
574 bool PasswordAutofillManager::FindLoginInfo( | 610 bool PasswordAutofillManager::FindLoginInfo( |
575 const WebKit::WebNode& node, | 611 const WebKit::WebNode& node, |
576 WebKit::WebInputElement* found_input, | 612 WebKit::WebInputElement* found_input, |
577 PasswordInfo* found_password) { | 613 PasswordInfo* found_password) { |
578 if (!node.isElementNode()) | 614 if (!node.isElementNode()) |
579 return false; | 615 return false; |
580 | 616 |
581 WebKit::WebElement element = node.toConst<WebKit::WebElement>(); | 617 WebKit::WebElement element = node.toConst<WebKit::WebElement>(); |
582 if (!element.hasTagName("input")) | 618 if (!element.hasTagName("input")) |
583 return false; | 619 return false; |
584 | 620 |
585 WebKit::WebInputElement input = element.to<WebKit::WebInputElement>(); | 621 WebKit::WebInputElement input = element.to<WebKit::WebInputElement>(); |
586 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); | 622 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
587 if (iter == login_to_password_info_.end()) | 623 if (iter == login_to_password_info_.end()) |
588 return false; | 624 return false; |
589 | 625 |
590 *found_input = input; | 626 *found_input = input; |
591 *found_password = iter->second; | 627 *found_password = iter->second; |
592 return true; | 628 return true; |
593 } | 629 } |
594 | 630 |
595 } // namespace autofill | 631 } // namespace autofill |
OLD | NEW |