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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 return; | 275 return; |
276 } | 276 } |
277 | 277 |
278 DVLOG(2) << "Password generation eligible form found"; | 278 DVLOG(2) << "Password generation eligible form found"; |
279 generation_element_ = password_elements_[0]; | 279 generation_element_ = password_elements_[0]; |
280 password_generation::LogPasswordGenerationEvent( | 280 password_generation::LogPasswordGenerationEvent( |
281 password_generation::GENERATION_AVAILABLE); | 281 password_generation::GENERATION_AVAILABLE); |
282 } | 282 } |
283 | 283 |
284 void PasswordGenerationAgent::FocusedNodeChanged(const blink::WebNode& node) { | 284 void PasswordGenerationAgent::FocusedNodeChanged(const blink::WebNode& node) { |
285 // TODO(gcasto): Re-hide generation_element text. | 285 if (!generation_element_.isNull()) |
| 286 generation_element_.setShouldRevealPassword(false); |
| 287 |
286 if (node.isNull() || !node.isElementNode()) | 288 if (node.isNull() || !node.isElementNode()) |
287 return; | 289 return; |
288 | 290 |
289 const blink::WebElement web_element = node.toConst<blink::WebElement>(); | 291 const blink::WebElement web_element = node.toConst<blink::WebElement>(); |
290 if (!web_element.document().frame()) | 292 if (!web_element.document().frame()) |
291 return; | 293 return; |
292 | 294 |
293 const blink::WebInputElement* element = toWebInputElement(&web_element); | 295 const blink::WebInputElement* element = toWebInputElement(&web_element); |
294 if (!element || *element != generation_element_) | 296 if (!element || *element != generation_element_) |
295 return; | 297 return; |
296 | 298 |
297 if (password_is_generated_) { | 299 if (password_is_generated_) { |
298 // TODO(gcasto): Make characters visible. | 300 generation_element_.setShouldRevealPassword(true); |
299 ShowEditingPopup(); | 301 ShowEditingPopup(); |
300 } | 302 } |
301 | 303 |
302 // Only trigger if the password field is empty. | 304 // Only trigger if the password field is empty. |
303 if (!element->isReadOnly() && | 305 if (!element->isReadOnly() && |
304 element->isEnabled() && | 306 element->isEnabled() && |
305 element->value().isEmpty()) { | 307 element->value().isEmpty()) { |
306 ShowGenerationPopup(); | 308 ShowGenerationPopup(); |
307 } | 309 } |
308 } | 310 } |
309 | 311 |
310 bool PasswordGenerationAgent::TextDidChangeInTextField( | 312 bool PasswordGenerationAgent::TextDidChangeInTextField( |
311 const blink::WebInputElement& element) { | 313 const blink::WebInputElement& element) { |
312 if (element != generation_element_) | 314 if (element != generation_element_) |
313 return false; | 315 return false; |
314 | 316 |
315 if (element.value().isEmpty()) { | 317 if (element.value().isEmpty()) { |
316 if (password_is_generated_) { | 318 if (password_is_generated_) { |
317 // User generated a password and then deleted it. | 319 // User generated a password and then deleted it. |
318 password_generation::LogPasswordGenerationEvent( | 320 password_generation::LogPasswordGenerationEvent( |
319 password_generation::PASSWORD_DELETED); | 321 password_generation::PASSWORD_DELETED); |
320 } | 322 } |
321 | 323 |
| 324 // Do not treat the password as generated. |
322 // TODO(gcasto): Set PasswordForm::type in the browser to TYPE_NORMAL. | 325 // TODO(gcasto): Set PasswordForm::type in the browser to TYPE_NORMAL. |
323 password_is_generated_ = false; | 326 password_is_generated_ = false; |
| 327 generation_element_.setShouldRevealPassword(false); |
| 328 |
324 // Offer generation again. | 329 // Offer generation again. |
325 ShowGenerationPopup(); | 330 ShowGenerationPopup(); |
326 } else if (!password_is_generated_) { | 331 } else if (!password_is_generated_) { |
327 // User has rejected the feature and has started typing a password. | 332 // User has rejected the feature and has started typing a password. |
328 HidePopup(); | 333 HidePopup(); |
329 } else { | 334 } else { |
330 password_edited_ = true; | 335 password_edited_ = true; |
331 // Mirror edits to any confirmation password fields. | 336 // Mirror edits to any confirmation password fields. |
332 for (std::vector<blink::WebInputElement>::iterator it = | 337 for (std::vector<blink::WebInputElement>::iterator it = |
333 password_elements_.begin(); | 338 password_elements_.begin(); |
(...skipping 18 matching lines...) Expand all Loading... |
352 | 357 |
353 password_generation::LogPasswordGenerationEvent( | 358 password_generation::LogPasswordGenerationEvent( |
354 password_generation::GENERATION_POPUP_SHOWN); | 359 password_generation::GENERATION_POPUP_SHOWN); |
355 } | 360 } |
356 | 361 |
357 void PasswordGenerationAgent::ShowEditingPopup() { | 362 void PasswordGenerationAgent::ShowEditingPopup() { |
358 gfx::RectF bounding_box_scaled = | 363 gfx::RectF bounding_box_scaled = |
359 GetScaledBoundingBox(render_view_->GetWebView()->pageScaleFactor(), | 364 GetScaledBoundingBox(render_view_->GetWebView()->pageScaleFactor(), |
360 &generation_element_); | 365 &generation_element_); |
361 | 366 |
362 Send(new AutofillHostMsg_ShowPasswordEditingPopup(routing_id(), | 367 Send(new AutofillHostMsg_ShowPasswordEditingPopup( |
363 bounding_box_scaled)); | 368 routing_id(), |
| 369 bounding_box_scaled, |
| 370 *possible_account_creation_form_)); |
364 | 371 |
365 password_generation::LogPasswordGenerationEvent( | 372 password_generation::LogPasswordGenerationEvent( |
366 password_generation::EDITING_POPUP_SHOWN); | 373 password_generation::EDITING_POPUP_SHOWN); |
367 } | 374 } |
368 | 375 |
369 void PasswordGenerationAgent::HidePopup() { | 376 void PasswordGenerationAgent::HidePopup() { |
370 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); | 377 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); |
371 } | 378 } |
372 | 379 |
373 } // namespace autofill | 380 } // namespace autofill |
OLD | NEW |