OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/renderer/password_autofill_agent.h" | 5 #include "components/autofill/content/renderer/password_autofill_agent.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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 const blink::WebFormElement& form) { | 233 const blink::WebFormElement& form) { |
234 logger->LogHTMLForm(message_id, | 234 logger->LogHTMLForm(message_id, |
235 form.name().utf8(), | 235 form.name().utf8(), |
236 GURL(form.action().utf8())); | 236 GURL(form.action().utf8())); |
237 } | 237 } |
238 | 238 |
239 bool FillDataContainsUsername(const PasswordFormFillData& fill_data) { | 239 bool FillDataContainsUsername(const PasswordFormFillData& fill_data) { |
240 return !fill_data.basic_data.fields[0].name.empty(); | 240 return !fill_data.basic_data.fields[0].name.empty(); |
241 } | 241 } |
242 | 242 |
243 // This function attempts to fill |suggestions| and |realms| form |fill_data| | 243 // Sets |suggestions_present| to true if there are any suggestions to be derived |
244 // based on |current_username|. Returns true when |suggestions| gets filled | 244 // from |fill_data|. Unless |show_all| is true, only considers suggestions with |
245 // from |fill_data.other_possible_usernames|, else returns false. | 245 // usernames having |current_username| as a prefix. Returns true if a username |
246 bool GetSuggestions(const PasswordFormFillData& fill_data, | 246 // from the |fill_data.other_possible_usernames| would be included in the |
247 const base::string16& current_username, | 247 // suggestions. |
248 std::vector<base::string16>* suggestions, | 248 bool GetSuggestionsStats(const PasswordFormFillData& fill_data, |
249 std::vector<base::string16>* realms, | 249 const base::string16& current_username, |
250 bool show_all) { | 250 bool show_all, |
251 bool other_possible_username_shown = false; | 251 bool* suggestions_present) { |
252 if (show_all || | 252 *suggestions_present = false; |
253 StartsWith( | 253 // First, check the other possible usernames. |
254 fill_data.basic_data.fields[0].value, current_username, false)) { | 254 for (const auto& usernames : fill_data.other_possible_usernames) { |
255 suggestions->push_back(fill_data.basic_data.fields[0].value); | 255 for (size_t i = 0; i < usernames.second.size(); ++i) { |
256 realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm)); | 256 if (show_all || |
257 } | 257 StartsWith(usernames.second[i], current_username, false)) { |
258 | 258 *suggestions_present = true; |
259 for (PasswordFormFillData::LoginCollection::const_iterator iter = | 259 return true; |
260 fill_data.additional_logins.begin(); | 260 } |
261 iter != fill_data.additional_logins.end(); | |
262 ++iter) { | |
263 if (show_all || StartsWith(iter->first, current_username, false)) { | |
264 suggestions->push_back(iter->first); | |
265 realms->push_back(base::UTF8ToUTF16(iter->second.realm)); | |
266 } | 261 } |
267 } | 262 } |
268 | 263 |
269 for (PasswordFormFillData::UsernamesCollection::const_iterator iter = | 264 // No other possible usernames, but perhaps at least some suggestion? |
Garrett Casto
2014/10/30 22:33:29
Nit: Personally I don't think that these comments
vabr (Chromium)
2014/10/31 08:54:12
Done, by removing, also the one on line 253.
I'm s
| |
270 fill_data.other_possible_usernames.begin(); | 265 if (show_all || StartsWith(fill_data.basic_data.fields[0].value, |
271 iter != fill_data.other_possible_usernames.end(); | 266 current_username, false)) { |
272 ++iter) { | 267 *suggestions_present = true; |
273 for (size_t i = 0; i < iter->second.size(); ++i) { | 268 return false; |
274 if (show_all || StartsWith(iter->second[i], current_username, false)) { | 269 } |
275 other_possible_username_shown = true; | 270 |
276 suggestions->push_back(iter->second[i]); | 271 for (const auto& login : fill_data.additional_logins) { |
277 realms->push_back(base::UTF8ToUTF16(iter->first.realm)); | 272 if (show_all || StartsWith(login.first, current_username, false)) { |
278 } | 273 *suggestions_present = true; |
274 return false; | |
279 } | 275 } |
280 } | 276 } |
281 return other_possible_username_shown; | 277 |
278 return false; | |
282 } | 279 } |
283 | 280 |
284 // This function attempts to fill |username_element| and |password_element| | 281 // This function attempts to fill |username_element| and |password_element| |
285 // with values from |fill_data|. The |password_element| will only have the | 282 // with values from |fill_data|. The |password_element| will only have the |
286 // |suggestedValue| set, and will be registered for copying that to the real | 283 // |suggestedValue| set, and will be registered for copying that to the real |
287 // value through |registration_callback|. The function returns true when | 284 // value through |registration_callback|. The function returns true when |
288 // selected username comes from |fill_data.other_possible_usernames|. | 285 // selected username comes from |fill_data.other_possible_usernames|. |
289 bool FillUserNameAndPassword( | 286 bool FillUserNameAndPassword( |
290 blink::WebInputElement* username_element, | 287 blink::WebInputElement* username_element, |
291 blink::WebInputElement* password_element, | 288 blink::WebInputElement* password_element, |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 const blink::WebInputElement& user_input, | 1098 const blink::WebInputElement& user_input, |
1102 bool show_all) { | 1099 bool show_all) { |
1103 blink::WebFrame* frame = user_input.document().frame(); | 1100 blink::WebFrame* frame = user_input.document().frame(); |
1104 if (!frame) | 1101 if (!frame) |
1105 return false; | 1102 return false; |
1106 | 1103 |
1107 blink::WebView* webview = frame->view(); | 1104 blink::WebView* webview = frame->view(); |
1108 if (!webview) | 1105 if (!webview) |
1109 return false; | 1106 return false; |
1110 | 1107 |
1111 std::vector<base::string16> suggestions; | |
1112 std::vector<base::string16> realms; | |
1113 if (GetSuggestions( | |
1114 fill_data, user_input.value(), &suggestions, &realms, show_all)) { | |
1115 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; | |
1116 } | |
1117 | |
1118 DCHECK_EQ(suggestions.size(), realms.size()); | |
1119 | |
1120 FormData form; | 1108 FormData form; |
1121 FormFieldData field; | 1109 FormFieldData field; |
1122 FindFormAndFieldForFormControlElement( | 1110 FindFormAndFieldForFormControlElement( |
1123 user_input, &form, &field, REQUIRE_NONE); | 1111 user_input, &form, &field, REQUIRE_NONE); |
1124 | 1112 |
1125 blink::WebInputElement selected_element = user_input; | 1113 blink::WebInputElement selected_element = user_input; |
1126 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); | 1114 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); |
1127 | 1115 |
1128 float scale = web_view_->pageScaleFactor(); | 1116 float scale = web_view_->pageScaleFactor(); |
1129 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, | 1117 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, |
1130 bounding_box.y() * scale, | 1118 bounding_box.y() * scale, |
1131 bounding_box.width() * scale, | 1119 bounding_box.width() * scale, |
1132 bounding_box.height() * scale); | 1120 bounding_box.height() * scale); |
1133 Send(new AutofillHostMsg_ShowPasswordSuggestions( | 1121 Send(new AutofillHostMsg_ShowPasswordSuggestions( |
1134 routing_id(), field, bounding_box_scaled, suggestions, realms)); | 1122 routing_id(), field, user_input.value(), show_all, bounding_box_scaled)); |
1135 return !suggestions.empty(); | 1123 |
1124 bool suggestions_present = false; | |
1125 if (GetSuggestionsStats(fill_data, user_input.value(), show_all, | |
1126 &suggestions_present)) { | |
1127 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; | |
1128 } | |
1129 return suggestions_present; | |
1136 } | 1130 } |
1137 | 1131 |
1138 void PasswordAutofillAgent::PerformInlineAutocomplete( | 1132 void PasswordAutofillAgent::PerformInlineAutocomplete( |
1139 const blink::WebInputElement& username_input, | 1133 const blink::WebInputElement& username_input, |
1140 const blink::WebInputElement& password_input, | 1134 const blink::WebInputElement& password_input, |
1141 const PasswordFormFillData& fill_data) { | 1135 const PasswordFormFillData& fill_data) { |
1142 DCHECK(!fill_data.wait_for_username); | 1136 DCHECK(!fill_data.wait_for_username); |
1143 | 1137 |
1144 // We need non-const versions of the username and password inputs. | 1138 // We need non-const versions of the username and password inputs. |
1145 blink::WebInputElement username = username_input; | 1139 blink::WebInputElement username = username_input; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); | 1237 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); |
1244 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && | 1238 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && |
1245 password_form->password_value.empty() && | 1239 password_form->password_value.empty() && |
1246 password_form->new_password_value.empty())) { | 1240 password_form->new_password_value.empty())) { |
1247 return; | 1241 return; |
1248 } | 1242 } |
1249 provisionally_saved_forms_[frame].reset(password_form.release()); | 1243 provisionally_saved_forms_[frame].reset(password_form.release()); |
1250 } | 1244 } |
1251 | 1245 |
1252 } // namespace autofill | 1246 } // namespace autofill |
OLD | NEW |