OLD | NEW |
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 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_MODEL_H_ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_MODEL_H_ |
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_MODEL_H_ | 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_MODEL_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
8 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "components/autofill/core/common/password_form.h" |
9 | 13 |
10 namespace password_manager { | 14 namespace password_manager { |
11 | 15 |
12 // Simple Model & Observer interfaces for a LoginView to facilitate exchanging | 16 // A base class for the http-auth UI to communicate with the provider of stored |
13 // information. | 17 // credentials. |
14 class LoginModelObserver { | 18 class LoginModelObserver { |
15 public: | 19 public: |
16 // Called by the model when a username,password pair has been identified | 20 LoginModelObserver(); |
17 // as a match for the pending login prompt. | 21 |
18 virtual void OnAutofillDataAvailable(const base::string16& username, | 22 // Called by the model when |credentials| has been identified as a match for |
19 const base::string16& password) = 0; | 23 // the pending login prompt. Checks that the realm matches, and passes |
| 24 // |credentials| to OnAutofillDataAvailableInternal. |
| 25 void OnAutofillDataAvailable(const autofill::PasswordForm& credentials); |
20 | 26 |
21 virtual void OnLoginModelDestroying() = 0; | 27 virtual void OnLoginModelDestroying() = 0; |
22 | 28 |
| 29 // To be called by the model during AddObserverAndDeliverCredentials. |
| 30 void set_signon_realm(const std::string& signon_realm) { |
| 31 signon_realm_ = signon_realm; |
| 32 } |
| 33 |
23 protected: | 34 protected: |
24 virtual ~LoginModelObserver() {} | 35 virtual ~LoginModelObserver(); |
| 36 |
| 37 virtual void OnAutofillDataAvailableInternal( |
| 38 const base::string16& username, |
| 39 const base::string16& password) = 0; |
| 40 |
| 41 private: |
| 42 // Signon realm for which this observer wishes to receive credentials. |
| 43 std::string signon_realm_; |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(LoginModelObserver); |
25 }; | 46 }; |
26 | 47 |
| 48 // Corresponding Model interface to be inherited by the provider of stored |
| 49 // passwords. |
27 class LoginModel { | 50 class LoginModel { |
28 public: | 51 public: |
29 // Add an observer interested in the data from the model. | 52 LoginModel(); |
30 virtual void AddObserver(LoginModelObserver* observer) = 0; | 53 |
| 54 // Add an observer interested in the data from the model. Also, requests that |
| 55 // the model sends a callback to |observer| with stored credentials for |
| 56 // |observed_form|. |
| 57 virtual void AddObserverAndDeliverCredentials( |
| 58 LoginModelObserver* observer, |
| 59 const autofill::PasswordForm& observed_form) = 0; |
| 60 |
31 // Remove an observer from the model. | 61 // Remove an observer from the model. |
32 virtual void RemoveObserver(LoginModelObserver* observer) = 0; | 62 virtual void RemoveObserver(LoginModelObserver* observer) = 0; |
33 | 63 |
34 protected: | 64 protected: |
35 virtual ~LoginModel() {} | 65 virtual ~LoginModel(); |
| 66 |
| 67 private: |
| 68 DISALLOW_COPY_AND_ASSIGN(LoginModel); |
36 }; | 69 }; |
37 | 70 |
38 } // namespace password_manager | 71 } // namespace password_manager |
39 | 72 |
40 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_MODEL_H_ | 73 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_MODEL_H_ |
OLD | NEW |