Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: chrome/renderer/autofill/password_autofill_manager.cc

Issue 9600038: Add Password Autofill Manager to New Autofill (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixing final nits Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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
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
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 bool is_focused) { 424 bool is_focused) {
419 // TODO(jcivelli): http://crbug.com/51644 Implement behavior. 425 // TODO(jcivelli): http://crbug.com/51644 Implement behavior.
420 return false; 426 return false;
421 } 427 }
422 428
423 bool PasswordAutofillManager::InputElementLostFocus() { 429 bool PasswordAutofillManager::InputElementLostFocus() {
424 return false; 430 return false;
425 } 431 }
426 432
427 void PasswordAutofillManager::OnFillPasswordForm( 433 void PasswordAutofillManager::OnFillPasswordForm(
428 const webkit::forms::PasswordFormFillData& form_data) { 434 const webkit::forms::PasswordFormFillData& form_data,
435 bool disable_popup) {
436 disable_popup_ = disable_popup;
437
429 FormElementsList forms; 438 FormElementsList forms;
430 // We own the FormElements* in forms. 439 // We own the FormElements* in forms.
431 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms); 440 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms);
432 FormElementsList::iterator iter; 441 FormElementsList::iterator iter;
433 for (iter = forms.begin(); iter != forms.end(); ++iter) { 442 for (iter = forms.begin(); iter != forms.end(); ++iter) {
434 scoped_ptr<FormElements> form_elements(*iter); 443 scoped_ptr<FormElements> form_elements(*iter);
435 444
436 // If wait_for_username is true, we don't want to initially fill the form 445 // If wait_for_username is true, we don't want to initially fill the form
437 // until the user types in a valid username. 446 // until the user types in a valid username.
438 if (!form_data.wait_for_username) 447 if (!form_data.wait_for_username)
(...skipping 12 matching lines...) Expand all
451 // We might have already filled this form if there are two <form> elements 460 // We might have already filled this form if there are two <form> elements
452 // with identical markup. 461 // with identical markup.
453 if (login_to_password_info_.find(username_element) != 462 if (login_to_password_info_.find(username_element) !=
454 login_to_password_info_.end()) 463 login_to_password_info_.end())
455 continue; 464 continue;
456 465
457 PasswordInfo password_info; 466 PasswordInfo password_info;
458 password_info.fill_data = form_data; 467 password_info.fill_data = form_data;
459 password_info.password_field = password_element; 468 password_info.password_field = password_element;
460 login_to_password_info_[username_element] = password_info; 469 login_to_password_info_[username_element] = password_info;
470
471 webkit::forms::FormData form;
472 webkit::forms::FormField field;
473 FindFormAndFieldForInputElement(
474 username_element, &form, &field, REQUIRE_NONE);
475 Send(new AutofillHostMsg_AddPasswordFormMapping(
476 routing_id(),
477 field,
478 form_data));
461 } 479 }
462 } 480 }
463 481
464 //////////////////////////////////////////////////////////////////////////////// 482 ////////////////////////////////////////////////////////////////////////////////
465 // PasswordAutofillManager, private: 483 // PasswordAutofillManager, private:
466 484
467 void PasswordAutofillManager::GetSuggestions( 485 void PasswordAutofillManager::GetSuggestions(
468 const webkit::forms::PasswordFormFillData& fill_data, 486 const webkit::forms::PasswordFormFillData& fill_data,
469 const string16& input, 487 const string16& input,
470 std::vector<string16>* suggestions) { 488 std::vector<string16>* suggestions) {
(...skipping 14 matching lines...) Expand all
485 WebKit::WebFrame* frame = user_input.document().frame(); 503 WebKit::WebFrame* frame = user_input.document().frame();
486 if (!frame) 504 if (!frame)
487 return false; 505 return false;
488 506
489 WebKit::WebView* webview = frame->view(); 507 WebKit::WebView* webview = frame->view();
490 if (!webview) 508 if (!webview)
491 return false; 509 return false;
492 510
493 std::vector<string16> suggestions; 511 std::vector<string16> suggestions;
494 GetSuggestions(fill_data, user_input.value(), &suggestions); 512 GetSuggestions(fill_data, user_input.value(), &suggestions);
513
514 if (disable_popup_) {
515 webkit::forms::FormData form;
516 webkit::forms::FormField field;
517 FindFormAndFieldForInputElement(
518 user_input, &form, &field, REQUIRE_NONE);
519
520 WebKit::WebInputElement selected_element = user_input;
521 gfx::Rect bounding_box(selected_element.boundsInViewportSpace());
522 Send(new AutofillHostMsg_ShowPasswordSuggestions(routing_id(),
523 field,
524 bounding_box,
525 suggestions));
526 return !suggestions.empty();
527 }
528
529
495 if (suggestions.empty()) { 530 if (suggestions.empty()) {
496 webview->hidePopups(); 531 webview->hidePopups();
497 return false; 532 return false;
498 } 533 }
499 534
500 std::vector<string16> labels(suggestions.size()); 535 std::vector<string16> labels(suggestions.size());
501 std::vector<string16> icons(suggestions.size()); 536 std::vector<string16> icons(suggestions.size());
502 std::vector<int> ids(suggestions.size(), 0); 537 std::vector<int> ids(suggestions.size(), 0);
503 webview->applyAutofillSuggestions( 538 webview->applyAutofillSuggestions(
504 user_input, suggestions, labels, icons, ids, -1); 539 user_input, suggestions, labels, icons, ids, -1);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); 636 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input);
602 if (iter == login_to_password_info_.end()) 637 if (iter == login_to_password_info_.end())
603 return false; 638 return false;
604 639
605 *found_input = input; 640 *found_input = input;
606 *found_password = iter->second; 641 *found_password = iter->second;
607 return true; 642 return true;
608 } 643 }
609 644
610 } // namespace autofill 645 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698