Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(229)

Side by Side Diff: components/autofill/content/renderer/password_generation_agent.cc

Issue 2073143002: [Password Generation] Run the form classifier only if AutofillMetadata is enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pg_classifier_votes
Patch Set: Removed unnecessary ';' Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory> 7 #include <memory>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 PasswordGenerationAgent::PasswordGenerationAgent( 119 PasswordGenerationAgent::PasswordGenerationAgent(
120 content::RenderFrame* render_frame, 120 content::RenderFrame* render_frame,
121 PasswordAutofillAgent* password_agent) 121 PasswordAutofillAgent* password_agent)
122 : content::RenderFrameObserver(render_frame), 122 : content::RenderFrameObserver(render_frame),
123 password_is_generated_(false), 123 password_is_generated_(false),
124 is_manually_triggered_(false), 124 is_manually_triggered_(false),
125 password_edited_(false), 125 password_edited_(false),
126 generation_popup_shown_(false), 126 generation_popup_shown_(false),
127 editing_popup_shown_(false), 127 editing_popup_shown_(false),
128 enabled_(password_generation::IsPasswordGenerationEnabled()), 128 enabled_(password_generation::IsPasswordGenerationEnabled()),
129 form_classifier_enabled_(false),
129 password_agent_(password_agent) { 130 password_agent_(password_agent) {
130 VLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled"); 131 VLOG(2) << "Password Generation is " << (enabled_ ? "Enabled" : "Disabled");
131 } 132 }
132 PasswordGenerationAgent::~PasswordGenerationAgent() {} 133 PasswordGenerationAgent::~PasswordGenerationAgent() {}
133 134
134 void PasswordGenerationAgent::DidFinishDocumentLoad() { 135 void PasswordGenerationAgent::DidFinishDocumentLoad() {
135 // Update stats for main frame navigation. 136 // Update stats for main frame navigation.
136 if (!render_frame()->GetWebFrame()->parent()) { 137 if (!render_frame()->GetWebFrame()->parent()) {
137 // In every navigation, the IPC message sent by the password autofill 138 // In every navigation, the IPC message sent by the password autofill
138 // manager to query whether the current form is blacklisted or not happens 139 // manager to query whether the current form is blacklisted or not happens
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 189 }
189 190
190 void PasswordGenerationAgent::OnDestruct() { 191 void PasswordGenerationAgent::OnDestruct() {
191 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 192 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
192 } 193 }
193 194
194 void PasswordGenerationAgent::OnDynamicFormsSeen() { 195 void PasswordGenerationAgent::OnDynamicFormsSeen() {
195 FindPossibleGenerationForm(); 196 FindPossibleGenerationForm();
196 } 197 }
197 198
199 void PasswordGenerationAgent::OnAllowToRunFormClassifier() {
200 form_classifier_enabled_ = true;
201 }
202
198 void PasswordGenerationAgent::RunFormClassifierAndSaveVote( 203 void PasswordGenerationAgent::RunFormClassifierAndSaveVote(
199 const blink::WebFormElement& web_form, 204 const blink::WebFormElement& web_form,
200 const PasswordForm& form) { 205 const PasswordForm& form) {
206 DCHECK(form_classifier_enabled_);
207
201 base::string16 generation_field; 208 base::string16 generation_field;
202 ClassifyFormAndFindGenerationField(web_form, &generation_field); 209 ClassifyFormAndFindGenerationField(web_form, &generation_field);
203 Send(new AutofillHostMsg_SaveGenerationFieldDetectedByClassifier( 210 Send(new AutofillHostMsg_SaveGenerationFieldDetectedByClassifier(
204 routing_id(), form, generation_field)); 211 routing_id(), form, generation_field));
205 } 212 }
206 213
207 void PasswordGenerationAgent::FindPossibleGenerationForm() { 214 void PasswordGenerationAgent::FindPossibleGenerationForm() {
208 if (!enabled_ || !render_frame()) 215 if (!enabled_ || !render_frame())
209 return; 216 return;
210 217
(...skipping 24 matching lines...) Expand all
235 // Do not generate password for GAIA since it is used to retrieve the 242 // Do not generate password for GAIA since it is used to retrieve the
236 // generated paswords. 243 // generated paswords.
237 GURL realm(password_form->signon_realm); 244 GURL realm(password_form->signon_realm);
238 if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm()) 245 if (realm == GaiaUrls::GetInstance()->gaia_login_form_realm())
239 continue; 246 continue;
240 247
241 std::vector<blink::WebInputElement> passwords; 248 std::vector<blink::WebInputElement> passwords;
242 if (GetAccountCreationPasswordFields( 249 if (GetAccountCreationPasswordFields(
243 form_util::ExtractAutofillableElementsInForm(forms[i]), 250 form_util::ExtractAutofillableElementsInForm(forms[i]),
244 &passwords)) { 251 &passwords)) {
245 RunFormClassifierAndSaveVote(forms[i], *password_form); 252 if (form_classifier_enabled_)
253 RunFormClassifierAndSaveVote(forms[i], *password_form);
246 AccountCreationFormData ac_form_data( 254 AccountCreationFormData ac_form_data(
247 make_linked_ptr(password_form.release()), passwords); 255 make_linked_ptr(password_form.release()), passwords);
248 possible_account_creation_forms_.push_back(ac_form_data); 256 possible_account_creation_forms_.push_back(ac_form_data);
249 } 257 }
250 } 258 }
251 259
252 if (!possible_account_creation_forms_.empty()) { 260 if (!possible_account_creation_forms_.empty()) {
253 VLOG(2) << possible_account_creation_forms_.size() 261 VLOG(2) << possible_account_creation_forms_.size()
254 << " possible account creation forms deteceted"; 262 << " possible account creation forms deteceted";
255 DetermineGenerationElement(); 263 DetermineGenerationElement();
(...skipping 20 matching lines...) Expand all
276 bool handled = true; 284 bool handled = true;
277 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationAgent, message) 285 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationAgent, message)
278 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted, 286 IPC_MESSAGE_HANDLER(AutofillMsg_FormNotBlacklisted,
279 OnFormNotBlacklisted) 287 OnFormNotBlacklisted)
280 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted, 288 IPC_MESSAGE_HANDLER(AutofillMsg_GeneratedPasswordAccepted,
281 OnPasswordAccepted) 289 OnPasswordAccepted)
282 IPC_MESSAGE_HANDLER(AutofillMsg_FoundFormsEligibleForGeneration, 290 IPC_MESSAGE_HANDLER(AutofillMsg_FoundFormsEligibleForGeneration,
283 OnFormsEligibleForGenerationFound); 291 OnFormsEligibleForGenerationFound);
284 IPC_MESSAGE_HANDLER(AutofillMsg_UserTriggeredGeneratePassword, 292 IPC_MESSAGE_HANDLER(AutofillMsg_UserTriggeredGeneratePassword,
285 OnUserTriggeredGeneratePassword); 293 OnUserTriggeredGeneratePassword);
294 IPC_MESSAGE_HANDLER(AutofillMsg_AllowToRunFormClassifier,
295 OnAllowToRunFormClassifier);
286 IPC_MESSAGE_UNHANDLED(handled = false) 296 IPC_MESSAGE_UNHANDLED(handled = false)
287 IPC_END_MESSAGE_MAP() 297 IPC_END_MESSAGE_MAP()
288 return handled; 298 return handled;
289 } 299 }
290 300
291 void PasswordGenerationAgent::OnFormNotBlacklisted(const PasswordForm& form) { 301 void PasswordGenerationAgent::OnFormNotBlacklisted(const PasswordForm& form) {
292 not_blacklisted_password_form_origins_.push_back(form.origin); 302 not_blacklisted_password_form_origins_.push_back(form.origin);
293 DetermineGenerationElement(); 303 DetermineGenerationElement();
294 } 304 }
295 305
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 GetAccountCreationPasswordFields(control_elements, &password_elements); 575 GetAccountCreationPasswordFields(control_elements, &password_elements);
566 password_elements = FindPasswordElementsForGeneration( 576 password_elements = FindPasswordElementsForGeneration(
567 password_elements, last_focused_password_element_.nameForAutofill()); 577 password_elements, last_focused_password_element_.nameForAutofill());
568 generation_form_data_.reset(new AccountCreationFormData( 578 generation_form_data_.reset(new AccountCreationFormData(
569 make_linked_ptr(password_form.release()), password_elements)); 579 make_linked_ptr(password_form.release()), password_elements));
570 is_manually_triggered_ = true; 580 is_manually_triggered_ = true;
571 ShowGenerationPopup(); 581 ShowGenerationPopup();
572 } 582 }
573 583
574 } // namespace autofill 584 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/password_generation_agent.h ('k') | components/autofill/core/browser/form_structure.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698