| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 } // namespace | 97 } // namespace |
| 98 | 98 |
| 99 PasswordGenerationAgent::PasswordGenerationAgent( | 99 PasswordGenerationAgent::PasswordGenerationAgent( |
| 100 content::RenderView* render_view) | 100 content::RenderView* render_view) |
| 101 : content::RenderViewObserver(render_view), | 101 : content::RenderViewObserver(render_view), |
| 102 render_view_(render_view), | 102 render_view_(render_view), |
| 103 password_is_generated_(false), | 103 password_is_generated_(false), |
| 104 password_edited_(false), | 104 password_edited_(false), |
| 105 generation_popup_shown_(false), |
| 106 editing_popup_shown_(false), |
| 105 enabled_(password_generation::IsPasswordGenerationEnabled()) { | 107 enabled_(password_generation::IsPasswordGenerationEnabled()) { |
| 106 DVLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled"); | 108 DVLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled"); |
| 107 } | 109 } |
| 108 PasswordGenerationAgent::~PasswordGenerationAgent() {} | 110 PasswordGenerationAgent::~PasswordGenerationAgent() {} |
| 109 | 111 |
| 110 void PasswordGenerationAgent::DidFinishDocumentLoad( | 112 void PasswordGenerationAgent::DidFinishDocumentLoad( |
| 111 blink::WebLocalFrame* frame) { | 113 blink::WebLocalFrame* frame) { |
| 112 // In every navigation, the IPC message sent by the password autofill manager | 114 // In every navigation, the IPC message sent by the password autofill manager |
| 113 // to query whether the current form is blacklisted or not happens when the | 115 // to query whether the current form is blacklisted or not happens when the |
| 114 // document load finishes, so we need to clear previous states here before we | 116 // document load finishes, so we need to clear previous states here before we |
| 115 // hear back from the browser. We only clear this state on main frame load | 117 // hear back from the browser. We only clear this state on main frame load |
| 116 // as we don't want subframe loads to clear state that we have received from | 118 // as we don't want subframe loads to clear state that we have received from |
| 117 // the main frame. Note that we assume there is only one account creation | 119 // the main frame. Note that we assume there is only one account creation |
| 118 // form, but there could be multiple password forms in each frame. | 120 // form, but there could be multiple password forms in each frame. |
| 119 if (!frame->parent()) { | 121 if (!frame->parent()) { |
| 120 not_blacklisted_password_form_origins_.clear(); | 122 not_blacklisted_password_form_origins_.clear(); |
| 121 generation_enabled_forms_.clear(); | 123 generation_enabled_forms_.clear(); |
| 122 generation_element_.reset(); | 124 generation_element_.reset(); |
| 123 possible_account_creation_form_.reset(new PasswordForm()); | 125 possible_account_creation_form_.reset(new PasswordForm()); |
| 124 password_elements_.clear(); | 126 password_elements_.clear(); |
| 125 password_is_generated_ = false; | 127 password_is_generated_ = false; |
| 126 if (password_edited_) { | 128 if (password_edited_) { |
| 127 password_generation::LogPasswordGenerationEvent( | 129 password_generation::LogPasswordGenerationEvent( |
| 128 password_generation::PASSWORD_EDITED); | 130 password_generation::PASSWORD_EDITED); |
| 129 } | 131 } |
| 130 password_edited_ = false; | 132 password_edited_ = false; |
| 133 |
| 134 if (generation_popup_shown_) { |
| 135 password_generation::LogPasswordGenerationEvent( |
| 136 password_generation::GENERATION_POPUP_SHOWN); |
| 137 } |
| 138 generation_popup_shown_ = false; |
| 139 |
| 140 if (editing_popup_shown_) { |
| 141 password_generation::LogPasswordGenerationEvent( |
| 142 password_generation::EDITING_POPUP_SHOWN); |
| 143 } |
| 144 editing_popup_shown_ = false; |
| 131 } | 145 } |
| 132 } | 146 } |
| 133 | 147 |
| 134 void PasswordGenerationAgent::DidFinishLoad(blink::WebLocalFrame* frame) { | 148 void PasswordGenerationAgent::DidFinishLoad(blink::WebLocalFrame* frame) { |
| 135 if (!enabled_) | 149 if (!enabled_) |
| 136 return; | 150 return; |
| 137 | 151 |
| 138 // We don't want to generate passwords if the browser won't store or sync | 152 // We don't want to generate passwords if the browser won't store or sync |
| 139 // them. | 153 // them. |
| 140 if (!ShouldAnalyzeDocument(frame->document())) | 154 if (!ShouldAnalyzeDocument(frame->document())) |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 gfx::RectF bounding_box_scaled = | 359 gfx::RectF bounding_box_scaled = |
| 346 GetScaledBoundingBox(render_view_->GetWebView()->pageScaleFactor(), | 360 GetScaledBoundingBox(render_view_->GetWebView()->pageScaleFactor(), |
| 347 &generation_element_); | 361 &generation_element_); |
| 348 | 362 |
| 349 Send(new AutofillHostMsg_ShowPasswordGenerationPopup( | 363 Send(new AutofillHostMsg_ShowPasswordGenerationPopup( |
| 350 routing_id(), | 364 routing_id(), |
| 351 bounding_box_scaled, | 365 bounding_box_scaled, |
| 352 generation_element_.maxLength(), | 366 generation_element_.maxLength(), |
| 353 *possible_account_creation_form_)); | 367 *possible_account_creation_form_)); |
| 354 | 368 |
| 355 password_generation::LogPasswordGenerationEvent( | 369 generation_popup_shown_ = true; |
| 356 password_generation::GENERATION_POPUP_SHOWN); | |
| 357 } | 370 } |
| 358 | 371 |
| 359 void PasswordGenerationAgent::ShowEditingPopup() { | 372 void PasswordGenerationAgent::ShowEditingPopup() { |
| 360 gfx::RectF bounding_box_scaled = | 373 gfx::RectF bounding_box_scaled = |
| 361 GetScaledBoundingBox(render_view_->GetWebView()->pageScaleFactor(), | 374 GetScaledBoundingBox(render_view_->GetWebView()->pageScaleFactor(), |
| 362 &generation_element_); | 375 &generation_element_); |
| 363 | 376 |
| 364 Send(new AutofillHostMsg_ShowPasswordEditingPopup( | 377 Send(new AutofillHostMsg_ShowPasswordEditingPopup( |
| 365 routing_id(), | 378 routing_id(), |
| 366 bounding_box_scaled, | 379 bounding_box_scaled, |
| 367 *possible_account_creation_form_)); | 380 *possible_account_creation_form_)); |
| 368 | 381 |
| 369 password_generation::LogPasswordGenerationEvent( | 382 editing_popup_shown_ = true; |
| 370 password_generation::EDITING_POPUP_SHOWN); | |
| 371 } | 383 } |
| 372 | 384 |
| 373 void PasswordGenerationAgent::HidePopup() { | 385 void PasswordGenerationAgent::HidePopup() { |
| 374 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); | 386 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); |
| 375 } | 387 } |
| 376 | 388 |
| 377 } // namespace autofill | 389 } // namespace autofill |
| OLD | NEW |