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_generation_agent.h" | 5 #include "components/autofill/content/renderer/password_generation_agent.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "components/autofill/content/common/autofill_messages.h" | 10 #include "components/autofill/content/common/autofill_messages.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 const blink::WebInputElement* element = toWebInputElement(&web_element); | 281 const blink::WebInputElement* element = toWebInputElement(&web_element); |
282 if (!element || *element != generation_element_) | 282 if (!element || *element != generation_element_) |
283 return false; | 283 return false; |
284 | 284 |
285 if (password_is_generated_) { | 285 if (password_is_generated_) { |
286 generation_element_.setShouldRevealPassword(true); | 286 generation_element_.setShouldRevealPassword(true); |
287 ShowEditingPopup(); | 287 ShowEditingPopup(); |
288 return true; | 288 return true; |
289 } | 289 } |
290 | 290 |
291 // Only trigger if the password field is empty. | 291 // Assume that if the password field has less than kMaximumOfferSize |
| 292 // characters then the user is not finished typing their password and display |
| 293 // the password suggestion. |
292 if (!element->isReadOnly() && | 294 if (!element->isReadOnly() && |
293 element->isEnabled() && | 295 element->isEnabled() && |
294 element->value().isEmpty()) { | 296 element->value().length() <= kMaximumOfferSize) { |
295 ShowGenerationPopup(); | 297 ShowGenerationPopup(); |
296 return true; | 298 return true; |
297 } | 299 } |
298 | 300 |
299 return false; | 301 return false; |
300 } | 302 } |
301 | 303 |
302 bool PasswordGenerationAgent::TextDidChangeInTextField( | 304 bool PasswordGenerationAgent::TextDidChangeInTextField( |
303 const blink::WebInputElement& element) { | 305 const blink::WebInputElement& element) { |
304 if (element != generation_element_) | 306 if (element != generation_element_) |
305 return false; | 307 return false; |
306 | 308 |
307 if (element.value().isEmpty()) { | 309 if (element.value().isEmpty()) { |
308 if (password_is_generated_) { | 310 if (password_is_generated_) { |
309 // User generated a password and then deleted it. | 311 // User generated a password and then deleted it. |
310 password_generation::LogPasswordGenerationEvent( | 312 password_generation::LogPasswordGenerationEvent( |
311 password_generation::PASSWORD_DELETED); | 313 password_generation::PASSWORD_DELETED); |
312 } | 314 } |
313 | 315 |
314 // Do not treat the password as generated. | 316 // Do not treat the password as generated. |
315 // TODO(gcasto): Set PasswordForm::type in the browser to TYPE_NORMAL. | 317 // TODO(gcasto): Set PasswordForm::type in the browser to TYPE_NORMAL. |
316 password_is_generated_ = false; | 318 password_is_generated_ = false; |
317 generation_element_.setShouldRevealPassword(false); | 319 generation_element_.setShouldRevealPassword(false); |
318 | 320 |
319 // Offer generation again. | 321 // Offer generation again. |
320 ShowGenerationPopup(); | 322 ShowGenerationPopup(); |
321 } else if (!password_is_generated_) { | 323 } else if (password_is_generated_) { |
322 // User has rejected the feature and has started typing a password. | |
323 HidePopup(); | |
324 } else { | |
325 password_edited_ = true; | 324 password_edited_ = true; |
326 // Mirror edits to any confirmation password fields. | 325 // Mirror edits to any confirmation password fields. |
327 for (std::vector<blink::WebInputElement>::iterator it = | 326 for (std::vector<blink::WebInputElement>::iterator it = |
328 password_elements_.begin(); | 327 password_elements_.begin(); |
329 it != password_elements_.end(); ++it) { | 328 it != password_elements_.end(); ++it) { |
330 it->setValue(element.value()); | 329 it->setValue(element.value()); |
331 } | 330 } |
| 331 } else if (element.value().length() > kMaximumOfferSize) { |
| 332 // User has rejected the feature and has started typing a password. |
| 333 HidePopup(); |
| 334 } else { |
| 335 // Password isn't generated and there are fewer than kMaximumOfferSize |
| 336 // characters typed, so keep offering the password. Note this function |
| 337 // will just keep the previous popup if one is already showing. |
| 338 ShowGenerationPopup(); |
332 } | 339 } |
333 | 340 |
334 return true; | 341 return true; |
335 } | 342 } |
336 | 343 |
337 void PasswordGenerationAgent::ShowGenerationPopup() { | 344 void PasswordGenerationAgent::ShowGenerationPopup() { |
338 gfx::RectF bounding_box_scaled = | 345 gfx::RectF bounding_box_scaled = |
339 GetScaledBoundingBox(render_view_->GetWebView()->pageScaleFactor(), | 346 GetScaledBoundingBox(render_view_->GetWebView()->pageScaleFactor(), |
340 &generation_element_); | 347 &generation_element_); |
341 | 348 |
(...skipping 19 matching lines...) Expand all Loading... |
361 | 368 |
362 password_generation::LogPasswordGenerationEvent( | 369 password_generation::LogPasswordGenerationEvent( |
363 password_generation::EDITING_POPUP_SHOWN); | 370 password_generation::EDITING_POPUP_SHOWN); |
364 } | 371 } |
365 | 372 |
366 void PasswordGenerationAgent::HidePopup() { | 373 void PasswordGenerationAgent::HidePopup() { |
367 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); | 374 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); |
368 } | 375 } |
369 | 376 |
370 } // namespace autofill | 377 } // namespace autofill |
OLD | NEW |