blob: d4b902cfb2122058c4877613b45d160f95d97ae9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_
#define CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "components/autofill/core/common/password_form.h"
#include "components/password_manager/core/browser/password_store_change.h"
#include "components/password_manager/core/common/credential_manager_types.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "url/gurl.h"
namespace password_manager {
struct CredentialInfo;
class PasswordFormManager;
class PasswordManagerClient;
}
// ManagePasswordsState keeps the current state for ManagePasswordsUIController
// as well as up-to-date data for this state.
class ManagePasswordsState {
public:
using CredentialsCallback =
base::Callback<void(const password_manager::CredentialInfo&)>;
ManagePasswordsState();
~ManagePasswordsState();
// The embedder of this class has to set the client for logging.
void set_client(password_manager::PasswordManagerClient* client) {
client_ = client;
}
// The methods below discard the current state/data of the object and move it
// to the specified state.
// Move to PENDING_PASSWORD_STATE.
void OnPendingPassword(
scoped_ptr<password_manager::PasswordFormManager> form_manager);
// Move to PENDING_PASSWORD_UPDATE_STATE.
void OnUpdatePassword(
scoped_ptr<password_manager::PasswordFormManager> form_manager);
// Move to CREDENTIAL_REQUEST_STATE.
void OnRequestCredentials(
ScopedVector<autofill::PasswordForm> local_credentials,
ScopedVector<autofill::PasswordForm> federated_credentials,
const GURL& origin);
// Move to AUTO_SIGNIN_STATE. |local_forms| can't be empty.
void OnAutoSignin(ScopedVector<autofill::PasswordForm> local_forms,
const GURL& origin);
// Move to CONFIRMATION_STATE.
void OnAutomaticPasswordSave(
scoped_ptr<password_manager::PasswordFormManager> form_manager);
// Move to MANAGE_STATE or INACTIVE_STATE for PSL matched passwords.
// |password_form_map| contains best matches from the password store for the
// form which was autofilled, |origin| is an origin of the form which was
// autofilled. In addition, |federated_matches|, if not null, contains stored
// federated credentials to show to the user as well.
void OnPasswordAutofilled(
const autofill::PasswordFormMap& password_form_map,
const GURL& origin,
const std::vector<scoped_ptr<autofill::PasswordForm>>* federated_matches);
// Move to INACTIVE_STATE.
void OnInactive();
// Moves the object to |state| without resetting the internal data. Allowed:
// * -> MANAGE_STATE
void TransitionToState(password_manager::ui::State state);
// Updates the internal state applying |changes|.
void ProcessLoginsChanged(
const password_manager::PasswordStoreChangeList& changes);
// Called when the user chooses a credential. Using data from |form| and
// |credential_type| it constructs the object which next is passed to the
// credentials callback. Method should be called in the
// CREDENTIAL_REQUEST_STATE state.
void ChooseCredential(const autofill::PasswordForm& form,
password_manager::CredentialType credential_type);
password_manager::ui::State state() const { return state_; }
const GURL& origin() const { return origin_; }
password_manager::PasswordFormManager* form_manager() const {
return form_manager_.get();
}
const CredentialsCallback& credentials_callback() {
return credentials_callback_;
}
void set_credentials_callback(const CredentialsCallback& callback) {
credentials_callback_ = callback;
}
// Current local forms. ManagePasswordsState is responsible for the forms.
const std::vector<const autofill::PasswordForm*>& GetCurrentForms() const {
return form_manager_ ? current_forms_weak_ : local_credentials_forms_.get();
}
// Current federated forms.
const std::vector<const autofill::PasswordForm*>&
federated_credentials_forms() const {
return federated_credentials_forms_.get();
}
private:
// Removes all the PasswordForms stored in this object.
void ClearData();
// Add |form| to the internal state.
void AddForm(const autofill::PasswordForm& form);
// Updates |form| in the internal state.
bool UpdateForm(const autofill::PasswordForm& form);
// Removes |form| from the internal state.
void DeleteForm(const autofill::PasswordForm& form);
void SetState(password_manager::ui::State state);
// The origin of the current page for which the state is stored. It's used to
// determine which PasswordStore changes are applicable to the internal state.
GURL origin_;
// Contains the password that was submitted.
scoped_ptr<password_manager::PasswordFormManager> form_manager_;
// Weak references to the passwords for the current status. The hard pointers
// are scattered between |form_manager_| and |local_credentials_forms_|. If
// |form_manager_| is nullptr then all the forms are stored in
// |local_credentials_forms_|. |current_forms_weak_| remains empty.
std::vector<const autofill::PasswordForm*> current_forms_weak_;
// If |form_manager_| is nullptr then |local_credentials_forms_| contains all
// the current forms. Otherwise, it's a container for the new forms coming
// from the PasswordStore.
ScopedVector<const autofill::PasswordForm> local_credentials_forms_;
// Federated credentials for the CREDENTIAL_REQUEST_STATE.
ScopedVector<const autofill::PasswordForm> federated_credentials_forms_;
// A callback to be invoked when user selects a credential.
CredentialsCallback credentials_callback_;
// The current state of the password manager UI.
password_manager::ui::State state_;
// The client used for logging.
password_manager::PasswordManagerClient* client_;
DISALLOW_COPY_AND_ASSIGN(ManagePasswordsState);
};
#endif // CHROME_BROWSER_UI_PASSWORDS_MANAGE_PASSWORDS_STATE_H_
|