OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ | 5 #ifndef CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ |
6 #define CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ | 6 #define CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 class ContentPasswordManagerDriver; | 31 class ContentPasswordManagerDriver; |
32 } // namespace password_manager | 32 } // namespace password_manager |
33 | 33 |
34 // This is the base implementation for the OS-specific classes that route | 34 // This is the base implementation for the OS-specific classes that route |
35 // authentication info to the net::URLRequest that needs it. These functions | 35 // authentication info to the net::URLRequest that needs it. These functions |
36 // must be implemented in a thread safe manner. | 36 // must be implemented in a thread safe manner. |
37 class LoginHandler : public content::ResourceDispatcherHostLoginDelegate, | 37 class LoginHandler : public content::ResourceDispatcherHostLoginDelegate, |
38 public password_manager::LoginModelObserver, | 38 public password_manager::LoginModelObserver, |
39 public content::NotificationObserver { | 39 public content::NotificationObserver { |
40 public: | 40 public: |
| 41 // The purpose of this struct is to enforce that BuildView receives either |
| 42 // both the login model and the observed form, or none. That is a bit spoiled |
| 43 // by the fact that the model is a pointer to LoginModel, as opposed to a |
| 44 // reference. Having it as a reference would go against the style guide, which |
| 45 // forbids non-const references in arguments, presumably also inside passed |
| 46 // structs, because the guide's rationale still applies. Therefore at least |
| 47 // the constructor DCHECKs that |login_model| is not null. |
| 48 struct LoginModelData { |
| 49 LoginModelData(password_manager::LoginModel* login_model, |
| 50 const autofill::PasswordForm& observed_form); |
| 51 |
| 52 password_manager::LoginModel* const model; |
| 53 const autofill::PasswordForm& form; |
| 54 }; |
| 55 |
41 LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request); | 56 LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request); |
42 | 57 |
43 // Builds the platform specific LoginHandler. Used from within | 58 // Builds the platform specific LoginHandler. Used from within |
44 // CreateLoginPrompt() which creates tasks. | 59 // CreateLoginPrompt() which creates tasks. |
45 static LoginHandler* Create(net::AuthChallengeInfo* auth_info, | 60 static LoginHandler* Create(net::AuthChallengeInfo* auth_info, |
46 net::URLRequest* request); | 61 net::URLRequest* request); |
47 | 62 |
48 // ResourceDispatcherHostLoginDelegate implementation: | 63 // ResourceDispatcherHostLoginDelegate implementation: |
49 void OnRequestCancelled() override; | 64 void OnRequestCancelled() override; |
50 | 65 |
51 // Initializes the underlying platform specific view. | 66 // Implement this to initialize the underlying platform specific view. If |
52 virtual void BuildViewForPasswordManager( | 67 // |login_model_data| is not null, the contained LoginModel and PasswordForm |
53 password_manager::PasswordManager* manager, | 68 // can be used to register the view. |
54 const base::string16& explanation) = 0; | 69 virtual void BuildView(const base::string16& explanation, |
| 70 LoginModelData* login_model_data) = 0; |
55 | 71 |
56 // Sets information about the authentication type (|form|) and the | 72 // Sets information about the authentication type (|form|) and the |
57 // |password_manager| for this profile. | 73 // |password_manager| for this profile. |
58 void SetPasswordForm(const autofill::PasswordForm& form); | 74 void SetPasswordForm(const autofill::PasswordForm& form); |
59 void SetPasswordManager(password_manager::PasswordManager* password_manager); | 75 void SetPasswordManager(password_manager::PasswordManager* password_manager); |
60 | 76 |
61 // Returns the WebContents that needs authentication. | 77 // Returns the WebContents that needs authentication. |
62 content::WebContents* GetWebContentsForLogin() const; | 78 content::WebContents* GetWebContentsForLogin() const; |
63 | 79 |
64 // Returns the PasswordManager for the render frame that needs login. | 80 // Returns the PasswordManager for the web contents that needs login. |
65 password_manager::ContentPasswordManagerDriver* | 81 password_manager::PasswordManager* GetPasswordManagerForLogin(); |
66 GetPasswordManagerDriverForLogin(); | |
67 | 82 |
68 // Resend the request with authentication credentials. | 83 // Resend the request with authentication credentials. |
69 // This function can be called from either thread. | 84 // This function can be called from either thread. |
70 void SetAuth(const base::string16& username, const base::string16& password); | 85 void SetAuth(const base::string16& username, const base::string16& password); |
71 | 86 |
72 // Display the error page without asking for credentials again. | 87 // Display the error page without asking for credentials again. |
73 // This function can be called from either thread. | 88 // This function can be called from either thread. |
74 void CancelAuth(); | 89 void CancelAuth(); |
75 | 90 |
76 // Implements the content::NotificationObserver interface. | 91 // Implements the content::NotificationObserver interface. |
77 // Listens for AUTH_SUPPLIED and AUTH_CANCELLED notifications from other | 92 // Listens for AUTH_SUPPLIED and AUTH_CANCELLED notifications from other |
78 // LoginHandlers so that this LoginHandler has the chance to dismiss itself | 93 // LoginHandlers so that this LoginHandler has the chance to dismiss itself |
79 // if it was waiting for the same authentication. | 94 // if it was waiting for the same authentication. |
80 void Observe(int type, | 95 void Observe(int type, |
81 const content::NotificationSource& source, | 96 const content::NotificationSource& source, |
82 const content::NotificationDetails& details) override; | 97 const content::NotificationDetails& details) override; |
83 | 98 |
84 // Who/where/what asked for the authentication. | 99 // Who/where/what asked for the authentication. |
85 const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); } | 100 const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); } |
86 | 101 |
87 // Returns whether authentication had been handled (SetAuth or CancelAuth). | 102 // Returns whether authentication had been handled (SetAuth or CancelAuth). |
88 bool WasAuthHandled() const; | 103 bool WasAuthHandled() const; |
89 | 104 |
90 protected: | 105 protected: |
91 ~LoginHandler() override; | 106 ~LoginHandler() override; |
92 | 107 |
93 void SetModel(password_manager::LoginModel* model); | 108 // Sets |model_data.model| as |login_model_| and registers |this| as an |
| 109 // observer for |model_data.form|-related events. |
| 110 void SetModel(LoginModelData model_data); |
| 111 |
| 112 // Clear |login_model_| and remove |this| as an observer. |
| 113 void ResetModel(); |
94 | 114 |
95 // Notify observers that authentication is needed. | 115 // Notify observers that authentication is needed. |
96 void NotifyAuthNeeded(); | 116 void NotifyAuthNeeded(); |
97 | 117 |
98 // Performs necessary cleanup before deletion. | 118 // Performs necessary cleanup before deletion. |
99 void ReleaseSoon(); | 119 void ReleaseSoon(); |
100 | 120 |
101 // Closes the native dialog. | 121 // Closes the native dialog. |
102 virtual void CloseDialog() = 0; | 122 virtual void CloseDialog() = 0; |
103 | 123 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // Helper to remove the ref from an net::URLRequest to the LoginHandler. | 241 // Helper to remove the ref from an net::URLRequest to the LoginHandler. |
222 // Should only be called from the IO thread, since it accesses an | 242 // Should only be called from the IO thread, since it accesses an |
223 // net::URLRequest. | 243 // net::URLRequest. |
224 void ResetLoginHandlerForRequest(net::URLRequest* request); | 244 void ResetLoginHandlerForRequest(net::URLRequest* request); |
225 | 245 |
226 // Get the signon_realm under which the identity should be saved. | 246 // Get the signon_realm under which the identity should be saved. |
227 std::string GetSignonRealm(const GURL& url, | 247 std::string GetSignonRealm(const GURL& url, |
228 const net::AuthChallengeInfo& auth_info); | 248 const net::AuthChallengeInfo& auth_info); |
229 | 249 |
230 #endif // CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ | 250 #endif // CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ |
OLD | NEW |