| 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" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "components/password_manager/core/browser/password_manager.h" | 12 #include "components/password_manager/core/browser/password_manager.h" |
| 13 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 14 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
| 15 | 15 |
| 16 class GURL; | 16 class GURL; |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class RenderViewHostDelegate; | 19 class RenderViewHostDelegate; |
| 20 class NotificationRegistrar; | 20 class NotificationRegistrar; |
| 21 class WebContents; | 21 class WebContents; |
| 22 } // namespace content | 22 } // namespace content |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 class AuthChallengeInfo; | 25 class AuthChallengeInfo; |
| 26 class HttpNetworkSession; | 26 class HttpNetworkSession; |
| 27 class URLRequest; | 27 class URLRequest; |
| 28 } // namespace net | 28 } // namespace net |
| 29 | 29 |
| 30 namespace password_manager { | |
| 31 class ContentPasswordManagerDriver; | |
| 32 } // namespace password_manager | |
| 33 | |
| 34 // This is the base implementation for the OS-specific classes that route | 30 // This is the base implementation for the OS-specific classes that route |
| 35 // authentication info to the net::URLRequest that needs it. These functions | 31 // authentication info to the net::URLRequest that needs it. These functions |
| 36 // must be implemented in a thread safe manner. | 32 // must be implemented in a thread safe manner. |
| 37 class LoginHandler : public content::ResourceDispatcherHostLoginDelegate, | 33 class LoginHandler : public content::ResourceDispatcherHostLoginDelegate, |
| 38 public password_manager::LoginModelObserver, | 34 public password_manager::LoginModelObserver, |
| 39 public content::NotificationObserver { | 35 public content::NotificationObserver { |
| 40 public: | 36 public: |
| 41 // The purpose of this struct is to enforce that BuildView receives either | 37 // The purpose of this struct is to enforce that BuildViewImpl receives either |
| 42 // both the login model and the observed form, or none. That is a bit spoiled | 38 // 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 | 39 // 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 | 40 // reference. Having it as a reference would go against the style guide, which |
| 45 // forbids non-const references in arguments, presumably also inside passed | 41 // forbids non-const references in arguments, presumably also inside passed |
| 46 // structs, because the guide's rationale still applies. Therefore at least | 42 // structs, because the guide's rationale still applies. Therefore at least |
| 47 // the constructor DCHECKs that |login_model| is not null. | 43 // the constructor DCHECKs that |login_model| is not null. |
| 48 struct LoginModelData { | 44 struct LoginModelData { |
| 49 LoginModelData(password_manager::LoginModel* login_model, | 45 LoginModelData(password_manager::LoginModel* login_model, |
| 50 const autofill::PasswordForm& observed_form); | 46 const autofill::PasswordForm& observed_form); |
| 51 | 47 |
| 52 password_manager::LoginModel* const model; | 48 password_manager::LoginModel* const model; |
| 53 const autofill::PasswordForm& form; | 49 const autofill::PasswordForm& form; |
| 54 }; | 50 }; |
| 55 | 51 |
| 56 LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request); | 52 LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request); |
| 57 | 53 |
| 58 // Builds the platform specific LoginHandler. Used from within | 54 // Builds the platform specific LoginHandler. Used from within |
| 59 // CreateLoginPrompt() which creates tasks. | 55 // CreateLoginPrompt() which creates tasks. |
| 60 static LoginHandler* Create(net::AuthChallengeInfo* auth_info, | 56 static LoginHandler* Create(net::AuthChallengeInfo* auth_info, |
| 61 net::URLRequest* request); | 57 net::URLRequest* request); |
| 62 | 58 |
| 63 // ResourceDispatcherHostLoginDelegate implementation: | 59 // ResourceDispatcherHostLoginDelegate implementation: |
| 64 void OnRequestCancelled() override; | 60 void OnRequestCancelled() override; |
| 65 | 61 |
| 66 // Implement this to initialize the underlying platform specific view. If | 62 // Use this to build a view with password manager support. |password_manager| |
| 67 // |login_model_data| is not null, the contained LoginModel and PasswordForm | 63 // must not be null. |
| 68 // can be used to register the view. | 64 void BuildViewWithPasswordManager( |
| 69 virtual void BuildView(const base::string16& explanation, | 65 const base::string16& explanation, |
| 70 LoginModelData* login_model_data) = 0; | 66 password_manager::PasswordManager* password_manager, |
| 67 const autofill::PasswordForm& observed_form); |
| 68 |
| 69 // Use this to build a view without password manager support. |
| 70 void BuildViewWithoutPasswordManager(const base::string16& explanation); |
| 71 | 71 |
| 72 // Sets information about the authentication type (|form|) and the | 72 // Sets information about the authentication type (|form|) and the |
| 73 // |password_manager| for this profile. | 73 // |password_manager| for this profile. |
| 74 void SetPasswordForm(const autofill::PasswordForm& form); | 74 void SetPasswordForm(const autofill::PasswordForm& form); |
| 75 void SetPasswordManager(password_manager::PasswordManager* password_manager); | 75 void SetPasswordManager(password_manager::PasswordManager* password_manager); |
| 76 | 76 |
| 77 // Returns the WebContents that needs authentication. | 77 // Returns the WebContents that needs authentication. |
| 78 content::WebContents* GetWebContentsForLogin() const; | 78 content::WebContents* GetWebContentsForLogin() const; |
| 79 | 79 |
| 80 // Returns the PasswordManager for the web contents that needs login. | 80 // Returns the PasswordManager for the web contents that needs login. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 98 | 98 |
| 99 // Who/where/what asked for the authentication. | 99 // Who/where/what asked for the authentication. |
| 100 const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); } | 100 const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); } |
| 101 | 101 |
| 102 // Returns whether authentication had been handled (SetAuth or CancelAuth). | 102 // Returns whether authentication had been handled (SetAuth or CancelAuth). |
| 103 bool WasAuthHandled() const; | 103 bool WasAuthHandled() const; |
| 104 | 104 |
| 105 protected: | 105 protected: |
| 106 ~LoginHandler() override; | 106 ~LoginHandler() override; |
| 107 | 107 |
| 108 // Implement this to initialize the underlying platform specific view. If |
| 109 // |login_model_data| is not null, the contained LoginModel and PasswordForm |
| 110 // can be used to register the view. |
| 111 virtual void BuildViewImpl(const base::string16& explanation, |
| 112 LoginModelData* login_model_data) = 0; |
| 113 |
| 108 // Sets |model_data.model| as |login_model_| and registers |this| as an | 114 // Sets |model_data.model| as |login_model_| and registers |this| as an |
| 109 // observer for |model_data.form|-related events. | 115 // observer for |model_data.form|-related events. |
| 110 void SetModel(LoginModelData model_data); | 116 void SetModel(LoginModelData model_data); |
| 111 | 117 |
| 112 // Clear |login_model_| and remove |this| as an observer. | 118 // Clears |login_model_| and removes |this| as an observer. |
| 113 void ResetModel(); | 119 void ResetModel(); |
| 114 | 120 |
| 115 // Notify observers that authentication is needed. | 121 // Notify observers that authentication is needed. |
| 116 void NotifyAuthNeeded(); | 122 void NotifyAuthNeeded(); |
| 117 | 123 |
| 118 // Performs necessary cleanup before deletion. | 124 // Performs necessary cleanup before deletion. |
| 119 void ReleaseSoon(); | 125 void ReleaseSoon(); |
| 120 | 126 |
| 121 // Closes the native dialog. | 127 // Closes the native dialog. |
| 122 virtual void CloseDialog() = 0; | 128 virtual void CloseDialog() = 0; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // net::URLRequest::Delegate::OnAuthRequired. The prompt will be created | 237 // net::URLRequest::Delegate::OnAuthRequired. The prompt will be created |
| 232 // on the main UI thread via a call to UI loop's InvokeLater, and will send the | 238 // on the main UI thread via a call to UI loop's InvokeLater, and will send the |
| 233 // credentials back to the net::URLRequest on the calling thread. | 239 // credentials back to the net::URLRequest on the calling thread. |
| 234 // A LoginHandler object (which lives on the calling thread) is returned, | 240 // A LoginHandler object (which lives on the calling thread) is returned, |
| 235 // which can be used to set or cancel authentication programmatically. The | 241 // which can be used to set or cancel authentication programmatically. The |
| 236 // caller must invoke OnRequestCancelled() on this LoginHandler before | 242 // caller must invoke OnRequestCancelled() on this LoginHandler before |
| 237 // destroying the net::URLRequest. | 243 // destroying the net::URLRequest. |
| 238 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 244 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
| 239 net::URLRequest* request); | 245 net::URLRequest* request); |
| 240 | 246 |
| 241 // Helper to remove the ref from an net::URLRequest to the LoginHandler. | |
| 242 // Should only be called from the IO thread, since it accesses an | |
| 243 // net::URLRequest. | |
| 244 void ResetLoginHandlerForRequest(net::URLRequest* request); | |
| 245 | |
| 246 // Get the signon_realm under which the identity should be saved. | 247 // Get the signon_realm under which the identity should be saved. |
| 247 std::string GetSignonRealm(const GURL& url, | 248 std::string GetSignonRealm(const GURL& url, |
| 248 const net::AuthChallengeInfo& auth_info); | 249 const net::AuthChallengeInfo& auth_info); |
| 249 | 250 |
| 250 #endif // CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ | 251 #endif // CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ |
| OLD | NEW |