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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 FROM_HERE, | 288 FROM_HERE, |
287 base::Bind(&PasswordAutofillManager::PerformInlineAutocomplete, | 289 base::Bind(&PasswordAutofillManager::PerformInlineAutocomplete, |
288 weak_ptr_factory_.GetWeakPtr(), | 290 weak_ptr_factory_.GetWeakPtr(), |
289 element, password, iter->second.fill_data)); | 291 element, password, iter->second.fill_data)); |
290 return true; | 292 return true; |
291 } | 293 } |
292 | 294 |
293 bool PasswordAutofillManager::TextFieldHandlingKeyDown( | 295 bool PasswordAutofillManager::TextFieldHandlingKeyDown( |
294 const WebKit::WebInputElement& element, | 296 const WebKit::WebInputElement& element, |
295 const WebKit::WebKeyboardEvent& event) { | 297 const WebKit::WebKeyboardEvent& event) { |
| 298 // If using the new Autofill UI that lives in the browser, it will handle |
| 299 // keypresses before this function. This is not currently an issue but if |
| 300 // the keys handled there or here change, this issue may appear. |
| 301 |
296 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(element); | 302 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(element); |
297 if (iter == login_to_password_info_.end()) | 303 if (iter == login_to_password_info_.end()) |
298 return false; | 304 return false; |
299 | 305 |
300 int win_key_code = event.windowsKeyCode; | 306 int win_key_code = event.windowsKeyCode; |
301 iter->second.backspace_pressed_last = | 307 iter->second.backspace_pressed_last = |
302 (win_key_code == ui::VKEY_BACK || win_key_code == ui::VKEY_DELETE); | 308 (win_key_code == ui::VKEY_BACK || win_key_code == ui::VKEY_DELETE); |
303 return true; | 309 return true; |
304 } | 310 } |
305 | 311 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 bool is_focused) { | 409 bool is_focused) { |
404 // TODO(jcivelli): http://crbug.com/51644 Implement behavior. | 410 // TODO(jcivelli): http://crbug.com/51644 Implement behavior. |
405 return false; | 411 return false; |
406 } | 412 } |
407 | 413 |
408 bool PasswordAutofillManager::InputElementLostFocus() { | 414 bool PasswordAutofillManager::InputElementLostFocus() { |
409 return false; | 415 return false; |
410 } | 416 } |
411 | 417 |
412 void PasswordAutofillManager::OnFillPasswordForm( | 418 void PasswordAutofillManager::OnFillPasswordForm( |
413 const webkit::forms::PasswordFormFillData& form_data) { | 419 const webkit::forms::PasswordFormFillData& form_data, |
| 420 bool disable_popup) { |
| 421 disable_popup_ = disable_popup; |
| 422 |
414 FormElementsList forms; | 423 FormElementsList forms; |
415 // We own the FormElements* in forms. | 424 // We own the FormElements* in forms. |
416 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms); | 425 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms); |
417 FormElementsList::iterator iter; | 426 FormElementsList::iterator iter; |
418 for (iter = forms.begin(); iter != forms.end(); ++iter) { | 427 for (iter = forms.begin(); iter != forms.end(); ++iter) { |
419 scoped_ptr<FormElements> form_elements(*iter); | 428 scoped_ptr<FormElements> form_elements(*iter); |
420 | 429 |
421 // If wait_for_username is true, we don't want to initially fill the form | 430 // If wait_for_username is true, we don't want to initially fill the form |
422 // until the user types in a valid username. | 431 // until the user types in a valid username. |
423 if (!form_data.wait_for_username) | 432 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 | 445 // We might have already filled this form if there are two <form> elements |
437 // with identical markup. | 446 // with identical markup. |
438 if (login_to_password_info_.find(username_element) != | 447 if (login_to_password_info_.find(username_element) != |
439 login_to_password_info_.end()) | 448 login_to_password_info_.end()) |
440 continue; | 449 continue; |
441 | 450 |
442 PasswordInfo password_info; | 451 PasswordInfo password_info; |
443 password_info.fill_data = form_data; | 452 password_info.fill_data = form_data; |
444 password_info.password_field = password_element; | 453 password_info.password_field = password_element; |
445 login_to_password_info_[username_element] = password_info; | 454 login_to_password_info_[username_element] = password_info; |
| 455 |
| 456 webkit::forms::FormData form; |
| 457 webkit::forms::FormField field; |
| 458 FindFormAndFieldForInputElement( |
| 459 username_element, &form, &field, REQUIRE_NONE); |
| 460 Send(new AutofillHostMsg_AddPasswordFormMapping( |
| 461 routing_id(), |
| 462 field, |
| 463 form_data)); |
446 } | 464 } |
447 } | 465 } |
448 | 466 |
449 //////////////////////////////////////////////////////////////////////////////// | 467 //////////////////////////////////////////////////////////////////////////////// |
450 // PasswordAutofillManager, private: | 468 // PasswordAutofillManager, private: |
451 | 469 |
452 void PasswordAutofillManager::GetSuggestions( | 470 void PasswordAutofillManager::GetSuggestions( |
453 const webkit::forms::PasswordFormFillData& fill_data, | 471 const webkit::forms::PasswordFormFillData& fill_data, |
454 const string16& input, | 472 const string16& input, |
455 std::vector<string16>* suggestions) { | 473 std::vector<string16>* suggestions) { |
(...skipping 14 matching lines...) Expand all Loading... |
470 WebKit::WebFrame* frame = user_input.document().frame(); | 488 WebKit::WebFrame* frame = user_input.document().frame(); |
471 if (!frame) | 489 if (!frame) |
472 return false; | 490 return false; |
473 | 491 |
474 WebKit::WebView* webview = frame->view(); | 492 WebKit::WebView* webview = frame->view(); |
475 if (!webview) | 493 if (!webview) |
476 return false; | 494 return false; |
477 | 495 |
478 std::vector<string16> suggestions; | 496 std::vector<string16> suggestions; |
479 GetSuggestions(fill_data, user_input.value(), &suggestions); | 497 GetSuggestions(fill_data, user_input.value(), &suggestions); |
| 498 |
| 499 if (disable_popup_) { |
| 500 WebKit::WebInputElement selected_element = user_input; |
| 501 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); |
| 502 Send(new AutofillHostMsg_ShowPasswordSuggestions(routing_id(), |
| 503 bounding_box, |
| 504 suggestions)); |
| 505 return !suggestions.empty(); |
| 506 } |
| 507 |
| 508 |
480 if (suggestions.empty()) { | 509 if (suggestions.empty()) { |
481 webview->hidePopups(); | 510 webview->hidePopups(); |
482 return false; | 511 return false; |
483 } | 512 } |
484 | 513 |
485 std::vector<string16> labels(suggestions.size()); | 514 std::vector<string16> labels(suggestions.size()); |
486 std::vector<string16> icons(suggestions.size()); | 515 std::vector<string16> icons(suggestions.size()); |
487 std::vector<int> ids(suggestions.size(), 0); | 516 std::vector<int> ids(suggestions.size(), 0); |
488 webview->applyAutofillSuggestions( | 517 webview->applyAutofillSuggestions( |
489 user_input, suggestions, labels, icons, ids, -1); | 518 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); | 615 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); |
587 if (iter == login_to_password_info_.end()) | 616 if (iter == login_to_password_info_.end()) |
588 return false; | 617 return false; |
589 | 618 |
590 *found_input = input; | 619 *found_input = input; |
591 *found_password = iter->second; | 620 *found_password = iter->second; |
592 return true; | 621 return true; |
593 } | 622 } |
594 | 623 |
595 } // namespace autofill | 624 } // namespace autofill |
OLD | NEW |