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

Unified Diff: webkit/forms/password_form_dom_manager.cc

Issue 9625026: Save password without an associated username. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Delete a unintentional spaces Created 8 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 side-by-side diff with in-line comments
Download patch
Index: webkit/forms/password_form_dom_manager.cc
===================================================================
--- webkit/forms/password_form_dom_manager.cc (revision 127980)
+++ webkit/forms/password_form_dom_manager.cc (working copy)
@@ -22,6 +22,53 @@
PasswordFormFillData::~PasswordFormFillData() {
}
+const FormField& PasswordFormFillData::GetUsernameField() const {
+ switch (GetDataType()) {
+ case kUsernameAndPassword:
+ return basic_data.fields[1];
+ break;
+ case kOnlyPassword:
+ default:
+ NOTREACHED();
+ }
+ NOTREACHED();
+ // This return expression is to make this function returns a value
+ // in all paths.
+ // If there is a path which doesn't return any values,
+ // most of compiler output a warning or error.
+ // (ex. Visual C++ compiler outputs C4715 warning.)
+ return basic_data.fields[0];
+}
+
+const FormField& PasswordFormFillData::GetPasswordField() const {
+ switch (GetDataType()) {
+ case kUsernameAndPassword:
+ case kOnlyPassword:
+ return basic_data.fields[0];
+ break;
+ default:
+ NOTREACHED();
+ }
+ NOTREACHED();
+ // This return expression is to make this function returns a value
+ // in all paths.
+ // If there is a path which doesn't return any values,
+ // most of compiler output a warning or error.
+ // (ex. Visual C++ compiler outputs C4715 warning.)
+ return basic_data.fields[0];
+}
+
+PasswordFormFillData::DataType PasswordFormFillData::GetDataType() const {
+ if (basic_data.fields.size() == 2) {
+ return kUsernameAndPassword;
+ } else if (basic_data.fields.size() == 1) {
+ return kOnlyPassword;
+ } else {
+ NOTREACHED();
+ }
+ return kError;
+}
+
PasswordForm* PasswordFormDomManager::CreatePasswordForm(
const WebFormElement& webform) {
WebPasswordFormData web_password_form(webform);
@@ -37,23 +84,31 @@
const PasswordForm* const preferred_match,
bool wait_for_username_before_autofill,
PasswordFormFillData* result) {
+
+ // Fill basic form data.
+ result->basic_data.origin = form_on_page.origin;
+ result->basic_data.action = form_on_page.action;
+
// Note that many of the |FormField| members are not initialized for
// |username_field| and |password_field| because they are currently not used
// by the password autocomplete code.
- FormField username_field;
- username_field.name = form_on_page.username_element;
- username_field.value = preferred_match->username_value;
FormField password_field;
password_field.name = form_on_page.password_element;
password_field.value = preferred_match->password_value;
-
- // Fill basic form data.
- result->basic_data.origin = form_on_page.origin;
- result->basic_data.action = form_on_page.action;
- result->basic_data.fields.push_back(username_field);
result->basic_data.fields.push_back(password_field);
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.
+ // If username_element and preferred_match->username_value are empty string,
+ // 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
+ string16 none_username;
+ if (form_on_page.username_element != none_username
+ && preferred_match->username_value != none_username) {
+ FormField username_field;
+ username_field.name = form_on_page.username_element;
+ username_field.value = preferred_match->username_value;
+ result->basic_data.fields.push_back(username_field);
+ }
+
// Copy additional username/value pairs.
PasswordFormMap::const_iterator iter;
for (iter = matches.begin(); iter != matches.end(); iter++) {
« webkit/forms/password_form_dom_manager.h ('K') | « webkit/forms/password_form_dom_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698