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

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

Issue 6633001: Convert autofill messages to use the new IPC macros (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
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/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "chrome/common/autofill_messages.h" 9 #include "chrome/common/autofill_messages.h"
10 #include "chrome/renderer/render_view.h" 10 #include "chrome/renderer/render_view.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // Helper to search the given form element for the specified input elements 45 // Helper to search the given form element for the specified input elements
46 // in |data|, and add results to |result|. 46 // in |data|, and add results to |result|.
47 static bool FindFormInputElements(WebKit::WebFormElement* fe, 47 static bool FindFormInputElements(WebKit::WebFormElement* fe,
48 const webkit_glue::FormData& data, 48 const webkit_glue::FormData& data,
49 FormElements* result) { 49 FormElements* result) {
50 // Loop through the list of elements we need to find on the form in order to 50 // Loop through the list of elements we need to find on the form in order to
51 // autofill it. If we don't find any one of them, abort processing this 51 // autofill it. If we don't find any one of them, abort processing this
52 // form; it can't be the right one. 52 // form; it can't be the right one.
53 for (size_t j = 0; j < data.fields.size(); j++) { 53 for (size_t j = 0; j < data.fields.size(); j++) {
54 WebKit::WebVector<WebKit::WebNode> temp_elements; 54 WebKit::WebVector<WebKit::WebNode> temp_elements;
55 fe->getNamedElements(data.fields[j].name(), temp_elements); 55 fe->getNamedElements(data.fields[j].name, temp_elements);
56 56
57 // Match the first input element, if any. 57 // Match the first input element, if any.
58 // |getNamedElements| may return non-input elements where the names match, 58 // |getNamedElements| may return non-input elements where the names match,
59 // so the results are filtered for input elements. 59 // so the results are filtered for input elements.
60 // If more than one match is made, then we have ambiguity (due to misuse 60 // If more than one match is made, then we have ambiguity (due to misuse
61 // of "name" attribute) so is it considered not found. 61 // of "name" attribute) so is it considered not found.
62 bool found_input = false; 62 bool found_input = false;
63 for (size_t i = 0; i < temp_elements.size(); ++i) { 63 for (size_t i = 0; i < temp_elements.size(); ++i) {
64 if (temp_elements[i].to<WebKit::WebElement>().hasTagName("input")) { 64 if (temp_elements[i].to<WebKit::WebElement>().hasTagName("input")) {
65 // Check for a non-unique match. 65 // Check for a non-unique match.
66 if (found_input) { 66 if (found_input) {
67 found_input = false; 67 found_input = false;
68 break; 68 break;
69 } 69 }
70 70
71 // This element matched, add it to our temporary result. It's possible 71 // This element matched, add it to our temporary result. It's possible
72 // there are multiple matches, but for purposes of identifying the form 72 // there are multiple matches, but for purposes of identifying the form
73 // one suffices and if some function needs to deal with multiple 73 // one suffices and if some function needs to deal with multiple
74 // matching elements it can get at them through the FormElement*. 74 // matching elements it can get at them through the FormElement*.
75 // Note: This assignment adds a reference to the InputElement. 75 // Note: This assignment adds a reference to the InputElement.
76 result->input_elements[data.fields[j].name()] = 76 result->input_elements[data.fields[j].name] =
77 temp_elements[i].to<WebKit::WebInputElement>(); 77 temp_elements[i].to<WebKit::WebInputElement>();
78 found_input = true; 78 found_input = true;
79 } 79 }
80 } 80 }
81 81
82 // A required element was not found. This is not the right form. 82 // A required element was not found. This is not the right form.
83 // Make sure no input elements from a partially matched form in this 83 // Make sure no input elements from a partially matched form in this
84 // iteration remain in the result set. 84 // iteration remain in the result set.
85 // Note: clear will remove a reference from each InputElement. 85 // Note: clear will remove a reference from each InputElement.
86 if (!found_input) { 86 if (!found_input) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 } 137 }
138 } 138 }
139 139
140 bool FillForm(FormElements* fe, const webkit_glue::FormData& data) { 140 bool FillForm(FormElements* fe, const webkit_glue::FormData& data) {
141 if (!fe->form_element.autoComplete()) 141 if (!fe->form_element.autoComplete())
142 return false; 142 return false;
143 143
144 std::map<string16, string16> data_map; 144 std::map<string16, string16> data_map;
145 for (size_t i = 0; i < data.fields.size(); i++) 145 for (size_t i = 0; i < data.fields.size(); i++)
146 data_map[data.fields[i].name()] = data.fields[i].value(); 146 data_map[data.fields[i].name] = data.fields[i].value;
147 147
148 for (FormInputElementMap::iterator it = fe->input_elements.begin(); 148 for (FormInputElementMap::iterator it = fe->input_elements.begin();
149 it != fe->input_elements.end(); ++it) { 149 it != fe->input_elements.end(); ++it) {
150 WebKit::WebInputElement element = it->second; 150 WebKit::WebInputElement element = it->second;
151 // Don't fill a form that has pre-filled values. 151 // Don't fill a form that has pre-filled values.
152 if (!element.value().isEmpty()) 152 if (!element.value().isEmpty())
153 return false; 153 return false;
154 } 154 }
155 155
156 for (FormInputElementMap::iterator it = fe->input_elements.begin(); 156 for (FormInputElementMap::iterator it = fe->input_elements.begin();
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 scoped_ptr<FormElements> form_elements(*iter); 402 scoped_ptr<FormElements> form_elements(*iter);
403 403
404 // If wait_for_username is true, we don't want to initially fill the form 404 // If wait_for_username is true, we don't want to initially fill the form
405 // until the user types in a valid username. 405 // until the user types in a valid username.
406 if (!form_data.wait_for_username) 406 if (!form_data.wait_for_username)
407 FillForm(form_elements.get(), form_data.basic_data); 407 FillForm(form_elements.get(), form_data.basic_data);
408 408
409 // Attach autocomplete listener to enable selecting alternate logins. 409 // Attach autocomplete listener to enable selecting alternate logins.
410 // First, get pointers to username element. 410 // First, get pointers to username element.
411 WebKit::WebInputElement username_element = 411 WebKit::WebInputElement username_element =
412 form_elements->input_elements[form_data.basic_data.fields[0].name()]; 412 form_elements->input_elements[form_data.basic_data.fields[0].name];
413 413
414 // Get pointer to password element. (We currently only support single 414 // Get pointer to password element. (We currently only support single
415 // password forms). 415 // password forms).
416 WebKit::WebInputElement password_element = 416 WebKit::WebInputElement password_element =
417 form_elements->input_elements[form_data.basic_data.fields[1].name()]; 417 form_elements->input_elements[form_data.basic_data.fields[1].name];
418 418
419 DCHECK(login_to_password_info_.find(username_element) == 419 DCHECK(login_to_password_info_.find(username_element) ==
420 login_to_password_info_.end()); 420 login_to_password_info_.end());
421 PasswordInfo password_info; 421 PasswordInfo password_info;
422 password_info.fill_data = form_data; 422 password_info.fill_data = form_data;
423 password_info.password_field = password_element; 423 password_info.password_field = password_element;
424 login_to_password_info_[username_element] = password_info; 424 login_to_password_info_[username_element] = password_info;
425 } 425 }
426 } 426 }
427 427
428 //////////////////////////////////////////////////////////////////////////////// 428 ////////////////////////////////////////////////////////////////////////////////
429 // PasswordAutofillManager, private: 429 // PasswordAutofillManager, private:
430 430
431 void PasswordAutofillManager::GetSuggestions( 431 void PasswordAutofillManager::GetSuggestions(
432 const webkit_glue::PasswordFormFillData& fill_data, 432 const webkit_glue::PasswordFormFillData& fill_data,
433 const string16& input, 433 const string16& input,
434 std::vector<string16>* suggestions) { 434 std::vector<string16>* suggestions) {
435 if (StartsWith(fill_data.basic_data.fields[0].value(), input, false)) 435 if (StartsWith(fill_data.basic_data.fields[0].value, input, false))
436 suggestions->push_back(fill_data.basic_data.fields[0].value()); 436 suggestions->push_back(fill_data.basic_data.fields[0].value);
437 437
438 webkit_glue::PasswordFormFillData::LoginCollection::const_iterator iter; 438 webkit_glue::PasswordFormFillData::LoginCollection::const_iterator iter;
439 for (iter = fill_data.additional_logins.begin(); 439 for (iter = fill_data.additional_logins.begin();
440 iter != fill_data.additional_logins.end(); ++iter) { 440 iter != fill_data.additional_logins.end(); ++iter) {
441 if (StartsWith(iter->first, input, false)) 441 if (StartsWith(iter->first, input, false))
442 suggestions->push_back(iter->first); 442 suggestions->push_back(iter->first);
443 } 443 }
444 } 444 }
445 445
446 bool PasswordAutofillManager::ShowSuggestionPopup( 446 bool PasswordAutofillManager::ShowSuggestionPopup(
(...skipping 23 matching lines...) Expand all
470 WebKit::WebInputElement* password_element, 470 WebKit::WebInputElement* password_element,
471 const webkit_glue::PasswordFormFillData& fill_data, 471 const webkit_glue::PasswordFormFillData& fill_data,
472 bool exact_username_match, 472 bool exact_username_match,
473 bool set_selection) { 473 bool set_selection) {
474 string16 current_username = username_element->value(); 474 string16 current_username = username_element->value();
475 // username and password will contain the match found if any. 475 // username and password will contain the match found if any.
476 string16 username; 476 string16 username;
477 string16 password; 477 string16 password;
478 478
479 // Look for any suitable matches to current field text. 479 // Look for any suitable matches to current field text.
480 if (DoUsernamesMatch(fill_data.basic_data.fields[0].value(), current_username, 480 if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, current_username,
481 exact_username_match)) { 481 exact_username_match)) {
482 username = fill_data.basic_data.fields[0].value(); 482 username = fill_data.basic_data.fields[0].value;
483 password = fill_data.basic_data.fields[1].value(); 483 password = fill_data.basic_data.fields[1].value;
484 } else { 484 } else {
485 // Scan additional logins for a match. 485 // Scan additional logins for a match.
486 webkit_glue::PasswordFormFillData::LoginCollection::const_iterator iter; 486 webkit_glue::PasswordFormFillData::LoginCollection::const_iterator iter;
487 for (iter = fill_data.additional_logins.begin(); 487 for (iter = fill_data.additional_logins.begin();
488 iter != fill_data.additional_logins.end(); ++iter) { 488 iter != fill_data.additional_logins.end(); ++iter) {
489 if (DoUsernamesMatch(iter->first, current_username, 489 if (DoUsernamesMatch(iter->first, current_username,
490 exact_username_match)) { 490 exact_username_match)) {
491 username = iter->first; 491 username = iter->first;
492 password = iter->second; 492 password = iter->second;
493 break; 493 break;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); 561 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input);
562 if (iter == login_to_password_info_.end()) 562 if (iter == login_to_password_info_.end())
563 return false; 563 return false;
564 564
565 *found_input = input; 565 *found_input = input;
566 *found_password = iter->second; 566 *found_password = iter->second;
567 return true; 567 return true;
568 } 568 }
569 569
570 } // namespace autofill 570 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/form_manager_browsertest.cc ('k') | content/browser/renderer_host/render_view_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698