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

Side by Side 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: Modify the errors from Lint 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 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 "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[0];
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 return basic_data.fields[1];
47 break;
48 case kOnlyPassword:
49 return basic_data.fields[0];
50 break;
51 default:
52 NOTREACHED();
53 }
54 NOTREACHED();
55 // This return expression is to make this function returns a value
56 // in all paths.
57 // If there is a path which doesn't return any values,
58 // most of compiler output a warning or error.
59 // (ex. Visual C++ compiler outputs C4715 warning.)
60 return basic_data.fields[0];
61 }
62
63 PasswordFormFillData::DataType PasswordFormFillData::GetDataType() const {
64 if (basic_data.fields.size() == 2) {
65 return kUsernameAndPassword;
66 } else if (basic_data.fields.size() == 1) {
67 return kOnlyPassword;
68 } else {
69 NOTREACHED();
70 }
71 return kError;
72 }
73
25 PasswordForm* PasswordFormDomManager::CreatePasswordForm( 74 PasswordForm* PasswordFormDomManager::CreatePasswordForm(
26 const WebFormElement& webform) { 75 const WebFormElement& webform) {
27 WebPasswordFormData web_password_form(webform); 76 WebPasswordFormData web_password_form(webform);
28 if (web_password_form.isValid()) 77 if (web_password_form.isValid())
29 return new PasswordForm(web_password_form); 78 return new PasswordForm(web_password_form);
30 return NULL; 79 return NULL;
31 } 80 }
32 81
33 // static 82 // static
34 void PasswordFormDomManager::InitFillData( 83 void PasswordFormDomManager::InitFillData(
35 const PasswordForm& form_on_page, 84 const PasswordForm& form_on_page,
36 const PasswordFormMap& matches, 85 const PasswordFormMap& matches,
37 const PasswordForm* const preferred_match, 86 const PasswordForm* const preferred_match,
38 bool wait_for_username_before_autofill, 87 bool wait_for_username_before_autofill,
39 PasswordFormFillData* result) { 88 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 89
50 // Fill basic form data. 90 // Fill basic form data.
51 result->basic_data.origin = form_on_page.origin; 91 result->basic_data.origin = form_on_page.origin;
52 result->basic_data.action = form_on_page.action; 92 result->basic_data.action = form_on_page.action;
53 result->basic_data.fields.push_back(username_field); 93
94 // Note that many of the |FormField| members are not initialized for
95 // |username_field| and |password_field| because they are currently not used
96 // by the password autocomplete code.
97
98 // If username_element and preferred_match->username_value are empty string,
99 // we suppose that there isn't any username field and don't set the username.
100 string16 none_username;
101 if (form_on_page.username_element != none_username
102 && preferred_match->username_value != none_username) {
103 FormField username_field;
104 username_field.name = form_on_page.username_element;
105 username_field.value = preferred_match->username_value;
106 result->basic_data.fields.push_back(username_field);
107 }
108 FormField password_field;
109 password_field.name = form_on_page.password_element;
110 password_field.value = preferred_match->password_value;
54 result->basic_data.fields.push_back(password_field); 111 result->basic_data.fields.push_back(password_field);
55 result->wait_for_username = wait_for_username_before_autofill; 112 result->wait_for_username = wait_for_username_before_autofill;
56 113
57 // Copy additional username/value pairs. 114 // Copy additional username/value pairs.
58 PasswordFormMap::const_iterator iter; 115 PasswordFormMap::const_iterator iter;
59 for (iter = matches.begin(); iter != matches.end(); iter++) { 116 for (iter = matches.begin(); iter != matches.end(); iter++) {
60 if (iter->second != preferred_match) 117 if (iter->second != preferred_match)
61 result->additional_logins[iter->first] = iter->second->password_value; 118 result->additional_logins[iter->first] = iter->second->password_value;
62 } 119 }
63 } 120 }
64 121
65 } // namespace forms 122 } // namespace forms
66 } // namespace webkit 123 } // namespace webkit
OLDNEW
« 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