Chromium Code Reviews| 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 "webkit/forms/password_form_dom_manager.h" | 5 #include "webkit/forms/password_form_dom_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPasswordFormData.h " | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPasswordFormData.h " |
| 10 #include "webkit/forms/form_field.h" | 10 #include "webkit/forms/form_field.h" |
| 11 | 11 |
| 12 using WebKit::WebFormElement; | 12 using WebKit::WebFormElement; |
| 13 using WebKit::WebInputElement; | 13 using WebKit::WebInputElement; |
| 14 using WebKit::WebPasswordFormData; | 14 using WebKit::WebPasswordFormData; |
| 15 | 15 |
| 16 namespace webkit { | 16 namespace webkit { |
| 17 namespace forms { | 17 namespace forms { |
| 18 | 18 |
| 19 PasswordFormFillData::PasswordFormFillData() : wait_for_username(false) { | 19 PasswordFormFillData::PasswordFormFillData() : wait_for_username(false) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 PasswordFormFillData::~PasswordFormFillData() { | 22 PasswordFormFillData::~PasswordFormFillData() { |
| 23 } | 23 } |
| 24 | 24 |
| 25 const FormField& PasswordFormFillData::GetUsernameField() const { | |
| 26 switch (GetDataType()) { | |
| 27 case kUsernameAndPassword: | |
| 28 return basic_data.fields[1]; | |
| 29 break; | |
| 30 case kOnlyPassword: | |
| 31 default: | |
| 32 NOTREACHED(); | |
| 33 } | |
| 34 NOTREACHED(); | |
| 35 // This return expression is to make this function returns a value | |
| 36 // in all paths. | |
| 37 // If there is a path which doesn't return any values, | |
| 38 // most of compiler output a warning or error. | |
| 39 // (ex. Visual C++ compiler outputs C4715 warning.) | |
| 40 return basic_data.fields[0]; | |
| 41 } | |
| 42 | |
| 43 const FormField& PasswordFormFillData::GetPasswordField() const { | |
| 44 switch (GetDataType()) { | |
| 45 case kUsernameAndPassword: | |
| 46 case kOnlyPassword: | |
| 47 return basic_data.fields[0]; | |
| 48 break; | |
| 49 default: | |
| 50 NOTREACHED(); | |
| 51 } | |
| 52 NOTREACHED(); | |
| 53 // This return expression is to make this function returns a value | |
| 54 // in all paths. | |
| 55 // If there is a path which doesn't return any values, | |
| 56 // most of compiler output a warning or error. | |
| 57 // (ex. Visual C++ compiler outputs C4715 warning.) | |
| 58 return basic_data.fields[0]; | |
| 59 } | |
| 60 | |
| 61 PasswordFormFillData::DataType PasswordFormFillData::GetDataType() const { | |
| 62 if (basic_data.fields.size() == 2) { | |
| 63 return kUsernameAndPassword; | |
| 64 } else if (basic_data.fields.size() == 1) { | |
| 65 return kOnlyPassword; | |
| 66 } else { | |
| 67 NOTREACHED(); | |
| 68 } | |
| 69 return kError; | |
| 70 } | |
| 71 | |
| 25 PasswordForm* PasswordFormDomManager::CreatePasswordForm( | 72 PasswordForm* PasswordFormDomManager::CreatePasswordForm( |
| 26 const WebFormElement& webform) { | 73 const WebFormElement& webform) { |
| 27 WebPasswordFormData web_password_form(webform); | 74 WebPasswordFormData web_password_form(webform); |
| 28 if (web_password_form.isValid()) | 75 if (web_password_form.isValid()) |
| 29 return new PasswordForm(web_password_form); | 76 return new PasswordForm(web_password_form); |
| 30 return NULL; | 77 return NULL; |
| 31 } | 78 } |
| 32 | 79 |
| 33 // static | 80 // static |
| 34 void PasswordFormDomManager::InitFillData( | 81 void PasswordFormDomManager::InitFillData( |
| 35 const PasswordForm& form_on_page, | 82 const PasswordForm& form_on_page, |
| 36 const PasswordFormMap& matches, | 83 const PasswordFormMap& matches, |
| 37 const PasswordForm* const preferred_match, | 84 const PasswordForm* const preferred_match, |
| 38 bool wait_for_username_before_autofill, | 85 bool wait_for_username_before_autofill, |
| 39 PasswordFormFillData* result) { | 86 PasswordFormFillData* result) { |
| 40 // Note that many of the |FormField| members are not initialized for | |
| 41 // |username_field| and |password_field| because they are currently not used | |
| 42 // by the password autocomplete code. | |
| 43 FormField username_field; | |
| 44 username_field.name = form_on_page.username_element; | |
| 45 username_field.value = preferred_match->username_value; | |
| 46 FormField password_field; | |
| 47 password_field.name = form_on_page.password_element; | |
| 48 password_field.value = preferred_match->password_value; | |
| 49 | 87 |
| 50 // Fill basic form data. | 88 // Fill basic form data. |
| 51 result->basic_data.origin = form_on_page.origin; | 89 result->basic_data.origin = form_on_page.origin; |
| 52 result->basic_data.action = form_on_page.action; | 90 result->basic_data.action = form_on_page.action; |
| 53 result->basic_data.fields.push_back(username_field); | 91 |
| 92 // Note that many of the |FormField| members are not initialized for | |
| 93 // |username_field| and |password_field| because they are currently not used | |
| 94 // by the password autocomplete code. | |
| 95 FormField password_field; | |
| 96 password_field.name = form_on_page.password_element; | |
| 97 password_field.value = preferred_match->password_value; | |
| 54 result->basic_data.fields.push_back(password_field); | 98 result->basic_data.fields.push_back(password_field); |
| 55 result->wait_for_username = wait_for_username_before_autofill; | 99 result->wait_for_username = wait_for_username_before_autofill; |
|
Ilya Sherman
2012/03/22 16:57:44
nit: Please move this to be immediately after line
Yumikiyo Osanai
2012/03/26 21:23:43
Done.
I've moved it immediately after line 90.
| |
| 56 | 100 |
| 101 // If username_element and preferred_match->username_value are empty string, | |
| 102 // we suppose that there isn't any username field and don't set the username. | |
|
Ilya Sherman
2012/03/22 16:57:44
Do we really need to check both the username_eleme
Yumikiyo Osanai
2012/03/26 21:23:43
As you said, It doesn't need to check both of thos
| |
| 103 string16 none_username; | |
| 104 if (form_on_page.username_element != none_username | |
| 105 && preferred_match->username_value != none_username) { | |
| 106 FormField username_field; | |
| 107 username_field.name = form_on_page.username_element; | |
| 108 username_field.value = preferred_match->username_value; | |
| 109 result->basic_data.fields.push_back(username_field); | |
| 110 } | |
| 111 | |
| 57 // Copy additional username/value pairs. | 112 // Copy additional username/value pairs. |
| 58 PasswordFormMap::const_iterator iter; | 113 PasswordFormMap::const_iterator iter; |
| 59 for (iter = matches.begin(); iter != matches.end(); iter++) { | 114 for (iter = matches.begin(); iter != matches.end(); iter++) { |
| 60 if (iter->second != preferred_match) | 115 if (iter->second != preferred_match) |
| 61 result->additional_logins[iter->first] = iter->second->password_value; | 116 result->additional_logins[iter->first] = iter->second->password_value; |
| 62 } | 117 } |
| 63 } | 118 } |
| 64 | 119 |
| 65 } // namespace forms | 120 } // namespace forms |
| 66 } // namespace webkit | 121 } // namespace webkit |
| OLD | NEW |