Chromium Code Reviews| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 // 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 |
| 117 // 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 |
| 118 // 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 |
| 119 // 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 |
| 120 // form, but there could be multiple password forms in each frame. | 120 // form, but there could be multiple password forms in each frame. |
| 121 if (!frame->parent()) { | 121 if (!frame->parent()) { |
| 122 not_blacklisted_password_form_origins_.clear(); | 122 not_blacklisted_password_form_origins_.clear(); |
| 123 generation_enabled_forms_.clear(); | 123 generation_enabled_forms_.clear(); |
| 124 generation_element_.reset(); | 124 generation_element_.reset(); |
| 125 possible_account_creation_form_.reset(new PasswordForm()); | 125 possible_account_creation_form_.reset(new PasswordForm()); |
| 126 if (password_elements_.empty()) { | |
|
vabr (Chromium)
2014/10/16 07:46:15
If I understand correctly, this logs the event fro
Garrett Casto
2014/10/16 19:14:06
I think that happens rarely enough not to worry ab
| |
| 127 password_generation::LogPasswordGenerationEvent( | |
| 128 password_generation::NO_SIGN_UP_DETECTED); | |
| 129 } else { | |
| 130 password_generation::LogPasswordGenerationEvent( | |
| 131 password_generation::SIGN_UP_DETECTED); | |
| 132 } | |
| 126 password_elements_.clear(); | 133 password_elements_.clear(); |
| 127 password_is_generated_ = false; | 134 password_is_generated_ = false; |
| 128 if (password_edited_) { | 135 if (password_edited_) { |
| 129 password_generation::LogPasswordGenerationEvent( | 136 password_generation::LogPasswordGenerationEvent( |
| 130 password_generation::PASSWORD_EDITED); | 137 password_generation::PASSWORD_EDITED); |
| 131 } | 138 } |
| 132 password_edited_ = false; | 139 password_edited_ = false; |
| 133 | 140 |
| 134 if (generation_popup_shown_) { | 141 if (generation_popup_shown_) { |
| 135 password_generation::LogPasswordGenerationEvent( | 142 password_generation::LogPasswordGenerationEvent( |
| 136 password_generation::GENERATION_POPUP_SHOWN); | 143 password_generation::GENERATION_POPUP_SHOWN); |
| 137 } | 144 } |
| 138 generation_popup_shown_ = false; | 145 generation_popup_shown_ = false; |
| 139 | 146 |
| 140 if (editing_popup_shown_) { | 147 if (editing_popup_shown_) { |
| 141 password_generation::LogPasswordGenerationEvent( | 148 password_generation::LogPasswordGenerationEvent( |
| 142 password_generation::EDITING_POPUP_SHOWN); | 149 password_generation::EDITING_POPUP_SHOWN); |
| 143 } | 150 } |
| 144 editing_popup_shown_ = false; | 151 editing_popup_shown_ = false; |
| 145 } | 152 } |
| 146 } | 153 } |
| 147 | 154 |
| 155 void PasswordGenerationAgent::OnDynamicFormsSeen(blink::WebLocalFrame* frame) { | |
| 156 FindPossibleGenerationForm(frame); | |
| 157 } | |
| 158 | |
| 148 void PasswordGenerationAgent::DidFinishLoad(blink::WebLocalFrame* frame) { | 159 void PasswordGenerationAgent::DidFinishLoad(blink::WebLocalFrame* frame) { |
| 160 FindPossibleGenerationForm(frame); | |
| 161 } | |
| 162 | |
| 163 void PasswordGenerationAgent::FindPossibleGenerationForm( | |
| 164 blink::WebLocalFrame* frame) { | |
| 149 if (!enabled_) | 165 if (!enabled_) |
| 150 return; | 166 return; |
| 151 | 167 |
| 152 // We don't want to generate passwords if the browser won't store or sync | 168 // We don't want to generate passwords if the browser won't store or sync |
| 153 // them. | 169 // them. |
| 154 if (!ShouldAnalyzeDocument(frame->document())) | 170 if (!ShouldAnalyzeDocument(frame->document())) |
| 155 return; | 171 return; |
| 156 | 172 |
| 173 // If we have already found a signup form for this page, no need to continue. | |
| 174 if (!password_elements_.empty()) | |
| 175 return; | |
| 176 | |
| 157 blink::WebVector<blink::WebFormElement> forms; | 177 blink::WebVector<blink::WebFormElement> forms; |
| 158 frame->document().forms(forms); | 178 frame->document().forms(forms); |
| 159 for (size_t i = 0; i < forms.size(); ++i) { | 179 for (size_t i = 0; i < forms.size(); ++i) { |
| 160 if (forms[i].isNull()) | 180 if (forms[i].isNull()) |
| 161 continue; | 181 continue; |
| 162 | 182 |
| 163 // If we can't get a valid PasswordForm, we skip this form because the | 183 // If we can't get a valid PasswordForm, we skip this form because the |
| 164 // the password won't get saved even if we generate it. | 184 // the password won't get saved even if we generate it. |
| 165 scoped_ptr<PasswordForm> password_form( | 185 scoped_ptr<PasswordForm> password_form( |
| 166 CreatePasswordForm(forms[i])); | 186 CreatePasswordForm(forms[i])); |
| 167 if (!password_form.get()) { | 187 if (!password_form.get()) { |
| 168 DVLOG(2) << "Skipping form as it would not be saved"; | 188 DVLOG(2) << "Skipping form as it would not be saved"; |
| 169 continue; | 189 continue; |
| 170 } | 190 } |
| 171 | 191 |
| 172 // Do not generate password for GAIA since it is used to retrieve the | 192 // Do not generate password for GAIA since it is used to retrieve the |
| 173 // generated paswords. | 193 // generated paswords. |
| 174 GURL realm(password_form->signon_realm); | 194 GURL realm(password_form->signon_realm); |
| 175 if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm()) | 195 if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm()) |
| 176 continue; | 196 continue; |
| 177 | 197 |
| 178 std::vector<blink::WebInputElement> passwords; | 198 std::vector<blink::WebInputElement> passwords; |
| 179 if (GetAccountCreationPasswordFields(forms[i], &passwords)) { | 199 if (GetAccountCreationPasswordFields(forms[i], &passwords)) { |
| 180 DVLOG(2) << "Account creation form detected"; | 200 DVLOG(2) << "Account creation form detected"; |
| 181 password_generation::LogPasswordGenerationEvent( | |
| 182 password_generation::SIGN_UP_DETECTED); | |
| 183 password_elements_ = passwords; | 201 password_elements_ = passwords; |
| 184 possible_account_creation_form_.swap(password_form); | 202 possible_account_creation_form_.swap(password_form); |
| 185 DetermineGenerationElement(); | 203 DetermineGenerationElement(); |
| 186 // We assume that there is only one account creation field per URL. | 204 // We assume that there is only one account creation field per URL. |
| 187 return; | 205 return; |
| 188 } | 206 } |
| 189 } | 207 } |
| 190 password_generation::LogPasswordGenerationEvent( | |
| 191 password_generation::NO_SIGN_UP_DETECTED); | |
| 192 } | 208 } |
| 193 | 209 |
| 194 bool PasswordGenerationAgent::ShouldAnalyzeDocument( | 210 bool PasswordGenerationAgent::ShouldAnalyzeDocument( |
| 195 const blink::WebDocument& document) const { | 211 const blink::WebDocument& document) const { |
| 196 // Make sure that this security origin is allowed to use password manager. | 212 // Make sure that this security origin is allowed to use password manager. |
| 197 // Generating a password that can't be saved is a bad idea. | 213 // Generating a password that can't be saved is a bad idea. |
| 198 blink::WebSecurityOrigin origin = document.securityOrigin(); | 214 blink::WebSecurityOrigin origin = document.securityOrigin(); |
| 199 if (!origin.canAccessPasswordManager()) { | 215 if (!origin.canAccessPasswordManager()) { |
| 200 DVLOG(1) << "No PasswordManager access"; | 216 DVLOG(1) << "No PasswordManager access"; |
| 201 return false; | 217 return false; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 *possible_account_creation_form_)); | 396 *possible_account_creation_form_)); |
| 381 | 397 |
| 382 editing_popup_shown_ = true; | 398 editing_popup_shown_ = true; |
| 383 } | 399 } |
| 384 | 400 |
| 385 void PasswordGenerationAgent::HidePopup() { | 401 void PasswordGenerationAgent::HidePopup() { |
| 386 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); | 402 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); |
| 387 } | 403 } |
| 388 | 404 |
| 389 } // namespace autofill | 405 } // namespace autofill |
| OLD | NEW |