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

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

Issue 2334543003: [Password Generation] Move canonical action computation from rendered to browser part (Closed)
Patch Set: 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
« no previous file with comments | « components/autofill/content/renderer/password_generation_agent.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
17 PasswordGenerationManager::PasswordGenerationManager( 35 PasswordGenerationManager::PasswordGenerationManager(
18 PasswordManagerClient* client, 36 PasswordManagerClient* client,
19 PasswordManagerDriver* driver) 37 PasswordManagerDriver* driver)
20 : client_(client), driver_(driver) { 38 : client_(client), driver_(driver) {
21 } 39 }
22 40
23 PasswordGenerationManager::~PasswordGenerationManager() { 41 PasswordGenerationManager::~PasswordGenerationManager() {
24 } 42 }
25 43
26 void PasswordGenerationManager::DetectFormsEligibleForGeneration( 44 void PasswordGenerationManager::DetectFormsEligibleForGeneration(
27 const std::vector<autofill::FormStructure*>& forms) { 45 const std::vector<autofill::FormStructure*>& forms) {
28 if (!IsGenerationEnabled()) 46 if (!IsGenerationEnabled())
29 return; 47 return;
30 48
31 std::vector<autofill::PasswordFormGenerationData> 49 std::vector<autofill::PasswordFormGenerationData>
32 forms_eligible_for_generation; 50 forms_eligible_for_generation;
33 for (std::vector<autofill::FormStructure*>::const_iterator form_it = 51 for (std::vector<autofill::FormStructure*>::const_iterator form_it =
34 forms.begin(); 52 forms.begin();
35 form_it != forms.end(); ++form_it) { 53 form_it != forms.end(); ++form_it) {
36 autofill::FormStructure* form = *form_it; 54 autofill::FormStructure* form = *form_it;
37 for (std::vector<autofill::AutofillField*>::const_iterator field_it = 55 for (std::vector<autofill::AutofillField*>::const_iterator field_it =
38 form->begin(); 56 form->begin();
39 field_it != form->end(); ++field_it) { 57 field_it != form->end(); ++field_it) {
40 autofill::AutofillField* field = *field_it; 58 autofill::AutofillField* field = *field_it;
41 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD || 59 if (field->server_type() == autofill::ACCOUNT_CREATION_PASSWORD ||
42 field->server_type() == autofill::NEW_PASSWORD) { 60 field->server_type() == autofill::NEW_PASSWORD) {
43 forms_eligible_for_generation.push_back( 61 forms_eligible_for_generation.push_back(
44 autofill::PasswordFormGenerationData{form->form_name(), 62 autofill::PasswordFormGenerationData{
45 form->target_url(), *field}); 63 form->form_name(),
64 GetCanonicalAction(form->source_url(), form->target_url()),
65 *field});
46 break; 66 break;
47 } 67 }
48 } 68 }
49 } 69 }
50 if (!forms_eligible_for_generation.empty()) 70 if (!forms_eligible_for_generation.empty())
51 driver_->FormsEligibleForGenerationFound(forms_eligible_for_generation); 71 driver_->FormsEligibleForGenerationFound(forms_eligible_for_generation);
52 } 72 }
53 73
54 // In order for password generation to be enabled, we need to make sure: 74 // In order for password generation to be enabled, we need to make sure:
55 // (1) Password sync is enabled, and 75 // (1) Password sync is enabled, and
(...skipping 14 matching lines...) Expand all
70 90
71 return true; 91 return true;
72 } 92 }
73 93
74 void PasswordGenerationManager::CheckIfFormClassifierShouldRun() { 94 void PasswordGenerationManager::CheckIfFormClassifierShouldRun() {
75 if (autofill::FormStructure::IsAutofillFieldMetadataEnabled()) 95 if (autofill::FormStructure::IsAutofillFieldMetadataEnabled())
76 driver_->AllowToRunFormClassifier(); 96 driver_->AllowToRunFormClassifier();
77 } 97 }
78 98
79 } // namespace password_manager 99 } // namespace password_manager
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/password_generation_agent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698