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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 password_is_generated_(false), | 111 password_is_generated_(false), |
112 password_edited_(false), | 112 password_edited_(false), |
113 generation_popup_shown_(false), | 113 generation_popup_shown_(false), |
114 editing_popup_shown_(false), | 114 editing_popup_shown_(false), |
115 enabled_(password_generation::IsPasswordGenerationEnabled()) { | 115 enabled_(password_generation::IsPasswordGenerationEnabled()) { |
116 VLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled"); | 116 VLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled"); |
117 } | 117 } |
118 PasswordGenerationAgent::~PasswordGenerationAgent() {} | 118 PasswordGenerationAgent::~PasswordGenerationAgent() {} |
119 | 119 |
120 void PasswordGenerationAgent::DidFinishDocumentLoad() { | 120 void PasswordGenerationAgent::DidFinishDocumentLoad() { |
121 if (render_frame()->GetWebFrame()->parent()) | 121 // Update stats for main frame navigation. |
122 return; | 122 if (!render_frame()->GetWebFrame()->parent()) { |
| 123 // In every navigation, the IPC message sent by the password autofill |
| 124 // manager to query whether the current form is blacklisted or not happens |
| 125 // when the document load finishes, so we need to clear previous states |
| 126 // here before we hear back from the browser. We only clear this state on |
| 127 // main frame load as we don't want subframe loads to clear state that we |
| 128 // have received from the main frame. Note that we assume there is only one |
| 129 // account creation form, but there could be multiple password forms in |
| 130 // each frame. |
| 131 not_blacklisted_password_form_origins_.clear(); |
| 132 generation_enabled_forms_.clear(); |
| 133 generation_element_.reset(); |
| 134 possible_account_creation_forms_.clear(); |
123 | 135 |
124 // In every navigation, the IPC message sent by the password autofill manager | 136 // Log statistics after navigation so that we only log once per page. |
125 // to query whether the current form is blacklisted or not happens when the | 137 if (generation_form_data_ && |
126 // document load finishes, so we need to clear previous states here before we | 138 generation_form_data_->password_elements.empty()) { |
127 // hear back from the browser. We only clear this state on main frame load | 139 password_generation::LogPasswordGenerationEvent( |
128 // as we don't want subframe loads to clear state that we have received from | 140 password_generation::NO_SIGN_UP_DETECTED); |
129 // the main frame. Note that we assume there is only one account creation | 141 } else { |
130 // form, but there could be multiple password forms in each frame. | 142 password_generation::LogPasswordGenerationEvent( |
131 not_blacklisted_password_form_origins_.clear(); | 143 password_generation::SIGN_UP_DETECTED); |
132 generation_enabled_forms_.clear(); | 144 } |
133 generation_element_.reset(); | 145 generation_form_data_.reset(); |
134 possible_account_creation_forms_.clear(); | 146 password_is_generated_ = false; |
| 147 if (password_edited_) { |
| 148 password_generation::LogPasswordGenerationEvent( |
| 149 password_generation::PASSWORD_EDITED); |
| 150 } |
| 151 password_edited_ = false; |
135 | 152 |
136 // Log statistics after navigation so that we only log once per page. | 153 if (generation_popup_shown_) { |
137 if (generation_form_data_ && | 154 password_generation::LogPasswordGenerationEvent( |
138 generation_form_data_->password_elements.empty()) { | 155 password_generation::GENERATION_POPUP_SHOWN); |
139 password_generation::LogPasswordGenerationEvent( | 156 } |
140 password_generation::NO_SIGN_UP_DETECTED); | 157 generation_popup_shown_ = false; |
141 } else { | 158 |
142 password_generation::LogPasswordGenerationEvent( | 159 if (editing_popup_shown_) { |
143 password_generation::SIGN_UP_DETECTED); | 160 password_generation::LogPasswordGenerationEvent( |
| 161 password_generation::EDITING_POPUP_SHOWN); |
| 162 } |
| 163 editing_popup_shown_ = false; |
144 } | 164 } |
145 generation_form_data_.reset(); | |
146 password_is_generated_ = false; | |
147 if (password_edited_) { | |
148 password_generation::LogPasswordGenerationEvent( | |
149 password_generation::PASSWORD_EDITED); | |
150 } | |
151 password_edited_ = false; | |
152 | |
153 if (generation_popup_shown_) { | |
154 password_generation::LogPasswordGenerationEvent( | |
155 password_generation::GENERATION_POPUP_SHOWN); | |
156 } | |
157 generation_popup_shown_ = false; | |
158 | |
159 if (editing_popup_shown_) { | |
160 password_generation::LogPasswordGenerationEvent( | |
161 password_generation::EDITING_POPUP_SHOWN); | |
162 } | |
163 editing_popup_shown_ = false; | |
164 | 165 |
165 FindPossibleGenerationForm(); | 166 FindPossibleGenerationForm(); |
166 } | 167 } |
167 | 168 |
168 void PasswordGenerationAgent::OnDynamicFormsSeen() { | 169 void PasswordGenerationAgent::OnDynamicFormsSeen() { |
169 FindPossibleGenerationForm(); | 170 FindPossibleGenerationForm(); |
170 } | 171 } |
171 | 172 |
172 void PasswordGenerationAgent::FindPossibleGenerationForm() { | 173 void PasswordGenerationAgent::FindPossibleGenerationForm() { |
173 if (!enabled_) | 174 if (!enabled_) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 std::vector<blink::WebInputElement> passwords; | 207 std::vector<blink::WebInputElement> passwords; |
207 if (GetAccountCreationPasswordFields(forms[i], &passwords)) { | 208 if (GetAccountCreationPasswordFields(forms[i], &passwords)) { |
208 AccountCreationFormData ac_form_data( | 209 AccountCreationFormData ac_form_data( |
209 make_linked_ptr(password_form.release()), passwords); | 210 make_linked_ptr(password_form.release()), passwords); |
210 possible_account_creation_forms_.push_back(ac_form_data); | 211 possible_account_creation_forms_.push_back(ac_form_data); |
211 } | 212 } |
212 } | 213 } |
213 | 214 |
214 if (!possible_account_creation_forms_.empty()) { | 215 if (!possible_account_creation_forms_.empty()) { |
215 VLOG(2) << possible_account_creation_forms_.size() | 216 VLOG(2) << possible_account_creation_forms_.size() |
216 << " possible account creation forms deteceted"; | 217 << " possible account creation forms deteceted"; |
217 DetermineGenerationElement(); | 218 DetermineGenerationElement(); |
218 } | 219 } |
219 } | 220 } |
220 | 221 |
221 bool PasswordGenerationAgent::ShouldAnalyzeDocument() const { | 222 bool PasswordGenerationAgent::ShouldAnalyzeDocument() const { |
222 // Make sure that this security origin is allowed to use password manager. | 223 // Make sure that this security origin is allowed to use password manager. |
223 // Generating a password that can't be saved is a bad idea. | 224 // Generating a password that can't be saved is a bad idea. |
224 blink::WebSecurityOrigin origin = | 225 blink::WebSecurityOrigin origin = |
225 render_frame()->GetWebFrame()->document().securityOrigin(); | 226 render_frame()->GetWebFrame()->document().securityOrigin(); |
226 if (!origin.canAccessPasswordManager()) { | 227 if (!origin.canAccessPasswordManager()) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 *generation_form_data_->form)); | 424 *generation_form_data_->form)); |
424 | 425 |
425 editing_popup_shown_ = true; | 426 editing_popup_shown_ = true; |
426 } | 427 } |
427 | 428 |
428 void PasswordGenerationAgent::HidePopup() { | 429 void PasswordGenerationAgent::HidePopup() { |
429 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); | 430 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); |
430 } | 431 } |
431 | 432 |
432 } // namespace autofill | 433 } // namespace autofill |
OLD | NEW |