| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 PasswordGenerationAgent::AccountCreationFormData::~AccountCreationFormData() {} | 100 PasswordGenerationAgent::AccountCreationFormData::~AccountCreationFormData() {} |
| 101 | 101 |
| 102 PasswordGenerationAgent::PasswordGenerationAgent( | 102 PasswordGenerationAgent::PasswordGenerationAgent( |
| 103 content::RenderFrame* render_frame) | 103 content::RenderFrame* render_frame) |
| 104 : content::RenderFrameObserver(render_frame), | 104 : content::RenderFrameObserver(render_frame), |
| 105 password_is_generated_(false), | 105 password_is_generated_(false), |
| 106 password_edited_(false), | 106 password_edited_(false), |
| 107 generation_popup_shown_(false), | 107 generation_popup_shown_(false), |
| 108 editing_popup_shown_(false), | 108 editing_popup_shown_(false), |
| 109 enabled_(password_generation::IsPasswordGenerationEnabled()) { | 109 enabled_(password_generation::IsPasswordGenerationEnabled()) { |
| 110 DVLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled"); | 110 VLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled"); |
| 111 } | 111 } |
| 112 PasswordGenerationAgent::~PasswordGenerationAgent() {} | 112 PasswordGenerationAgent::~PasswordGenerationAgent() {} |
| 113 | 113 |
| 114 void PasswordGenerationAgent::DidFinishDocumentLoad() { | 114 void PasswordGenerationAgent::DidFinishDocumentLoad() { |
| 115 if (render_frame()->GetWebFrame()->parent()) | 115 if (render_frame()->GetWebFrame()->parent()) |
| 116 return; | 116 return; |
| 117 | 117 |
| 118 // In every navigation, the IPC message sent by the password autofill manager | 118 // In every navigation, the IPC message sent by the password autofill manager |
| 119 // to query whether the current form is blacklisted or not happens when the | 119 // to query whether the current form is blacklisted or not happens when the |
| 120 // document load finishes, so we need to clear previous states here before we | 120 // document load finishes, so we need to clear previous states here before we |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 render_frame()->GetWebFrame()->document().forms(forms); | 182 render_frame()->GetWebFrame()->document().forms(forms); |
| 183 for (size_t i = 0; i < forms.size(); ++i) { | 183 for (size_t i = 0; i < forms.size(); ++i) { |
| 184 if (forms[i].isNull()) | 184 if (forms[i].isNull()) |
| 185 continue; | 185 continue; |
| 186 | 186 |
| 187 // If we can't get a valid PasswordForm, we skip this form because the | 187 // If we can't get a valid PasswordForm, we skip this form because the |
| 188 // the password won't get saved even if we generate it. | 188 // the password won't get saved even if we generate it. |
| 189 scoped_ptr<PasswordForm> password_form( | 189 scoped_ptr<PasswordForm> password_form( |
| 190 CreatePasswordForm(forms[i], nullptr)); | 190 CreatePasswordForm(forms[i], nullptr)); |
| 191 if (!password_form.get()) { | 191 if (!password_form.get()) { |
| 192 DVLOG(2) << "Skipping form as it would not be saved"; | 192 VLOG(2) << "Skipping form as it would not be saved"; |
| 193 continue; | 193 continue; |
| 194 } | 194 } |
| 195 | 195 |
| 196 // Do not generate password for GAIA since it is used to retrieve the | 196 // Do not generate password for GAIA since it is used to retrieve the |
| 197 // generated paswords. | 197 // generated paswords. |
| 198 GURL realm(password_form->signon_realm); | 198 GURL realm(password_form->signon_realm); |
| 199 if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm()) | 199 if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm()) |
| 200 continue; | 200 continue; |
| 201 | 201 |
| 202 std::vector<blink::WebInputElement> passwords; | 202 std::vector<blink::WebInputElement> passwords; |
| 203 if (GetAccountCreationPasswordFields(forms[i], &passwords)) { | 203 if (GetAccountCreationPasswordFields(forms[i], &passwords)) { |
| 204 AccountCreationFormData ac_form_data( | 204 AccountCreationFormData ac_form_data( |
| 205 make_linked_ptr(password_form.release()), passwords); | 205 make_linked_ptr(password_form.release()), passwords); |
| 206 possible_account_creation_forms_.push_back(ac_form_data); | 206 possible_account_creation_forms_.push_back(ac_form_data); |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| 210 if (!possible_account_creation_forms_.empty()) { | 210 if (!possible_account_creation_forms_.empty()) { |
| 211 DVLOG(2) << possible_account_creation_forms_.size() | 211 VLOG(2) << possible_account_creation_forms_.size() |
| 212 << " possible account creation forms deteceted"; | 212 << " possible account creation forms deteceted"; |
| 213 DetermineGenerationElement(); | 213 DetermineGenerationElement(); |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool PasswordGenerationAgent::ShouldAnalyzeDocument() const { | 217 bool PasswordGenerationAgent::ShouldAnalyzeDocument() const { |
| 218 // Make sure that this security origin is allowed to use password manager. | 218 // Make sure that this security origin is allowed to use password manager. |
| 219 // Generating a password that can't be saved is a bad idea. | 219 // Generating a password that can't be saved is a bad idea. |
| 220 blink::WebSecurityOrigin origin = | 220 blink::WebSecurityOrigin origin = |
| 221 render_frame()->GetWebFrame()->document().securityOrigin(); | 221 render_frame()->GetWebFrame()->document().securityOrigin(); |
| 222 if (!origin.canAccessPasswordManager()) { | 222 if (!origin.canAccessPasswordManager()) { |
| 223 DVLOG(1) << "No PasswordManager access"; | 223 VLOG(1) << "No PasswordManager access"; |
| 224 return false; | 224 return false; |
| 225 } | 225 } |
| 226 | 226 |
| 227 return true; | 227 return true; |
| 228 } | 228 } |
| 229 | 229 |
| 230 bool PasswordGenerationAgent::OnMessageReceived(const IPC::Message& message) { | 230 bool PasswordGenerationAgent::OnMessageReceived(const IPC::Message& message) { |
| 231 bool handled = true; | 231 bool handled = true; |
| 232 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationAgent, message) | 232 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationAgent, message) |
| 233 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted, | 233 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 262 | 262 |
| 263 void PasswordGenerationAgent::OnAccountCreationFormsDetected( | 263 void PasswordGenerationAgent::OnAccountCreationFormsDetected( |
| 264 const std::vector<autofill::FormData>& forms) { | 264 const std::vector<autofill::FormData>& forms) { |
| 265 generation_enabled_forms_.insert( | 265 generation_enabled_forms_.insert( |
| 266 generation_enabled_forms_.end(), forms.begin(), forms.end()); | 266 generation_enabled_forms_.end(), forms.begin(), forms.end()); |
| 267 DetermineGenerationElement(); | 267 DetermineGenerationElement(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void PasswordGenerationAgent::DetermineGenerationElement() { | 270 void PasswordGenerationAgent::DetermineGenerationElement() { |
| 271 if (generation_form_data_) { | 271 if (generation_form_data_) { |
| 272 DVLOG(2) << "Account creation form already found"; | 272 VLOG(2) << "Account creation form already found"; |
| 273 return; | 273 return; |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Make sure local heuristics have identified a possible account creation | 276 // Make sure local heuristics have identified a possible account creation |
| 277 // form. | 277 // form. |
| 278 if (possible_account_creation_forms_.empty()) { | 278 if (possible_account_creation_forms_.empty()) { |
| 279 DVLOG(2) << "Local hueristics have not detected a possible account " | 279 VLOG(2) << "Local hueristics have not detected a possible account " |
| 280 << "creation form"; | 280 << "creation form"; |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 | 283 |
| 284 for (auto& possible_form_data : possible_account_creation_forms_) { | 284 for (auto& possible_form_data : possible_account_creation_forms_) { |
| 285 PasswordForm* possible_password_form = possible_form_data.form.get(); | 285 PasswordForm* possible_password_form = possible_form_data.form.get(); |
| 286 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 286 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 287 switches::kLocalHeuristicsOnlyForPasswordGeneration)) { | 287 switches::kLocalHeuristicsOnlyForPasswordGeneration)) { |
| 288 DVLOG(2) << "Bypassing additional checks."; | 288 VLOG(2) << "Bypassing additional checks."; |
| 289 } else if (!ContainsURL(not_blacklisted_password_form_origins_, | 289 } else if (!ContainsURL(not_blacklisted_password_form_origins_, |
| 290 possible_password_form->origin)) { | 290 possible_password_form->origin)) { |
| 291 DVLOG(2) << "Have not received confirmation that password form isn't " | 291 VLOG(2) << "Have not received confirmation that password form isn't " |
| 292 << "blacklisted"; | 292 << "blacklisted"; |
| 293 continue; | 293 continue; |
| 294 } else if (!ContainsForm(generation_enabled_forms_, | 294 } else if (!ContainsForm(generation_enabled_forms_, |
| 295 *possible_password_form)) { | 295 *possible_password_form)) { |
| 296 // Note that this message will never be sent if this feature is disabled | 296 // Note that this message will never be sent if this feature is disabled |
| 297 // (e.g. Password saving is disabled). | 297 // (e.g. Password saving is disabled). |
| 298 DVLOG(2) << "Have not received confirmation from Autofill that form is " | 298 VLOG(2) << "Have not received confirmation from Autofill that form is " |
| 299 << "used for account creation"; | 299 << "used for account creation"; |
| 300 continue; | 300 continue; |
| 301 } | 301 } |
| 302 | 302 |
| 303 DVLOG(2) << "Password generation eligible form found"; | 303 VLOG(2) << "Password generation eligible form found"; |
| 304 generation_form_data_.reset( | 304 generation_form_data_.reset( |
| 305 new AccountCreationFormData(possible_form_data.form, | 305 new AccountCreationFormData(possible_form_data.form, |
| 306 possible_form_data.password_elements)); | 306 possible_form_data.password_elements)); |
| 307 generation_element_ = generation_form_data_->password_elements[0]; | 307 generation_element_ = generation_form_data_->password_elements[0]; |
| 308 generation_element_.setAttribute("aria-autocomplete", "list"); | 308 generation_element_.setAttribute("aria-autocomplete", "list"); |
| 309 password_generation::LogPasswordGenerationEvent( | 309 password_generation::LogPasswordGenerationEvent( |
| 310 password_generation::GENERATION_AVAILABLE); | 310 password_generation::GENERATION_AVAILABLE); |
| 311 possible_account_creation_forms_.clear(); | 311 possible_account_creation_forms_.clear(); |
| 312 return; | 312 return; |
| 313 } | 313 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 *generation_form_data_->form)); | 412 *generation_form_data_->form)); |
| 413 | 413 |
| 414 editing_popup_shown_ = true; | 414 editing_popup_shown_ = true; |
| 415 } | 415 } |
| 416 | 416 |
| 417 void PasswordGenerationAgent::HidePopup() { | 417 void PasswordGenerationAgent::HidePopup() { |
| 418 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); | 418 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); |
| 419 } | 419 } |
| 420 | 420 |
| 421 } // namespace autofill | 421 } // namespace autofill |
| OLD | NEW |