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

Side by Side Diff: components/password_manager/core/browser/password_generation_manager.cc

Issue 2318533002: [Password Generation] Use signatures for form matching (Closed)
Patch Set: Rebase Created 4 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/password_manager/core/browser/password_generation_manager.h " 5 #include "components/password_manager/core/browser/password_generation_manager.h "
6 6
7 #include "components/autofill/core/browser/autofill_field.h" 7 #include "components/autofill/core/browser/autofill_field.h"
8 #include "components/autofill/core/browser/field_types.h" 8 #include "components/autofill/core/browser/field_types.h"
9 #include "components/autofill/core/browser/form_structure.h" 9 #include "components/autofill/core/browser/form_structure.h"
10 #include "components/autofill/core/common/password_form_generation_data.h" 10 #include "components/autofill/core/common/password_form_generation_data.h"
11 #include "components/password_manager/core/browser/password_manager.h" 11 #include "components/password_manager/core/browser/password_manager.h"
12 #include "components/password_manager/core/browser/password_manager_client.h" 12 #include "components/password_manager/core/browser/password_manager_client.h"
13 #include "components/password_manager/core/browser/password_manager_driver.h" 13 #include "components/password_manager/core/browser/password_manager_driver.h"
14 14
15 namespace password_manager { 15 namespace password_manager {
16 16
17 namespace {
18
19 // Helper function that returns canonical action based on |target_url| and
20 // |source_url|.
21 GURL GetCanonicalAction(const GURL& source_url, const GURL& target_url) {
22 GURL action = target_url;
23 if (action.is_empty())
24 action = source_url;
25 GURL::Replacements rep;
26 rep.ClearUsername();
27 rep.ClearPassword();
28 rep.ClearQuery();
29 rep.ClearRef();
30 return action.ReplaceComponents(rep);
31 }
32
33 } // namespace
34
35 PasswordGenerationManager::PasswordGenerationManager( 17 PasswordGenerationManager::PasswordGenerationManager(
36 PasswordManagerClient* client, 18 PasswordManagerClient* client,
37 PasswordManagerDriver* driver) 19 PasswordManagerDriver* driver)
38 : client_(client), driver_(driver) { 20 : client_(client), driver_(driver) {
39 } 21 }
40 22
41 PasswordGenerationManager::~PasswordGenerationManager() { 23 PasswordGenerationManager::~PasswordGenerationManager() {
42 } 24 }
43 25
44 void PasswordGenerationManager::DetectFormsEligibleForGeneration( 26 void PasswordGenerationManager::DetectFormsEligibleForGeneration(
45 const std::vector<autofill::FormStructure*>& forms) { 27 const std::vector<autofill::FormStructure*>& forms) {
46 if (!IsGenerationEnabled()) 28 if (!IsGenerationEnabled())
47 return; 29 return;
48 30
49 std::vector<autofill::PasswordFormGenerationData> 31 std::vector<autofill::PasswordFormGenerationData>
50 forms_eligible_for_generation; 32 forms_eligible_for_generation;
51 for (std::vector<autofill::FormStructure*>::const_iterator form_it = 33 for (std::vector<autofill::FormStructure*>::const_iterator form_it =
52 forms.begin(); 34 forms.begin();
53 form_it != forms.end(); ++form_it) { 35 form_it != forms.end(); ++form_it) {
54 autofill::FormStructure* form = *form_it; 36 autofill::FormStructure* form = *form_it;
55 for (std::vector<autofill::AutofillField*>::const_iterator field_it = 37 for (std::vector<autofill::AutofillField*>::const_iterator field_it =
56 form->begin(); 38 form->begin();
57 field_it != form->end(); ++field_it) { 39 field_it != form->end(); ++field_it) {
58 autofill::AutofillField* field = *field_it; 40 autofill::AutofillField* field = *field_it;
59 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD || 41 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD ||
60 field->server_type() == autofill::NEW_PASSWORD) { 42 field->server_type() == autofill::NEW_PASSWORD) {
61 forms_eligible_for_generation.push_back( 43 forms_eligible_for_generation.push_back(
62 autofill::PasswordFormGenerationData{ 44 autofill::PasswordFormGenerationData{form->form_signature(),
63 form->form_name(), 45 field->GetFieldSignature()});
64 GetCanonicalAction(form->source_url(), form->target_url()),
65 *field});
66 break; 46 break;
67 } 47 }
68 } 48 }
69 } 49 }
70 if (!forms_eligible_for_generation.empty()) 50 if (!forms_eligible_for_generation.empty())
71 driver_->FormsEligibleForGenerationFound(forms_eligible_for_generation); 51 driver_->FormsEligibleForGenerationFound(forms_eligible_for_generation);
72 } 52 }
73 53
74 // In order for password generation to be enabled, we need to make sure: 54 // In order for password generation to be enabled, we need to make sure:
75 // (1) Password sync is enabled, and 55 // (1) Password sync is enabled, and
(...skipping 14 matching lines...) Expand all
90 70
91 return true; 71 return true;
92 } 72 }
93 73
94 void PasswordGenerationManager::CheckIfFormClassifierShouldRun() { 74 void PasswordGenerationManager::CheckIfFormClassifierShouldRun() {
95 if (autofill::FormStructure::IsAutofillFieldMetadataEnabled()) 75 if (autofill::FormStructure::IsAutofillFieldMetadataEnabled())
96 driver_->AllowToRunFormClassifier(); 76 driver_->AllowToRunFormClassifier();
97 } 77 }
98 78
99 } // namespace password_manager 79 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698