| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_LOGIN_PROMPT_H_ | 5 #ifndef CHROME_BROWSER_LOGIN_PROMPT_H_ |
| 6 #define CHROME_BROWSER_LOGIN_PROMPT_H_ | 6 #define CHROME_BROWSER_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/lock.h" |
| 12 #include "chrome/browser/password_manager/password_manager.h" |
| 11 | 13 |
| 12 namespace net { | 14 namespace net { |
| 13 class AuthChallengeInfo; | 15 class AuthChallengeInfo; |
| 14 } | 16 } |
| 15 | 17 |
| 16 namespace webkit_glue { | |
| 17 struct PasswordForm; | |
| 18 } | |
| 19 | |
| 20 class ConstrainedWindow; | 18 class ConstrainedWindow; |
| 21 class GURL; | 19 class GURL; |
| 22 class PasswordManager; | |
| 23 class TabContents; | 20 class TabContents; |
| 24 class URLRequest; | 21 class URLRequest; |
| 25 | 22 |
| 26 // This is the interface for the class that routes authentication info to | 23 // This is the base implementation for the OS-specific classes that route |
| 27 // the URLRequest that needs it. Used by the automation proxy for testing. | 24 // authentication info to the URLRequest that needs it. These functions must |
| 28 // These functions should be (and are, in LoginHandlerImpl) implemented in | 25 // be implemented in a thread safe manner. |
| 29 // a thread safe manner. | 26 class LoginHandler : public base::RefCountedThreadSafe<LoginHandler>, |
| 30 // | 27 public LoginModelObserver { |
| 31 // TODO(erg): Refactor the common code from all LoginHandler subclasses into a | |
| 32 // common controller class. All the methods below have the same copy/pasted | |
| 33 // implementation. This is more difficult then it should be because all these | |
| 34 // subclasses are also base::RefCountedThreadSafe<> and I'm not sure how to get | |
| 35 // ownership correct. http://crbug.com/14909 | |
| 36 class LoginHandler { | |
| 37 public: | 28 public: |
| 29 explicit LoginHandler(URLRequest* request); |
| 30 virtual ~LoginHandler(); |
| 31 |
| 38 // Builds the platform specific LoginHandler. Used from within | 32 // Builds the platform specific LoginHandler. Used from within |
| 39 // CreateLoginPrompt() which creates tasks. | 33 // CreateLoginPrompt() which creates tasks. |
| 40 static LoginHandler* Create(URLRequest* request); | 34 static LoginHandler* Create(URLRequest* request); |
| 41 | 35 |
| 42 // Initializes the underlying platform specific view. | 36 // Initializes the underlying platform specific view. |
| 43 virtual void BuildViewForPasswordManager(PasswordManager* manager, | 37 virtual void BuildViewForPasswordManager(PasswordManager* manager, |
| 44 std::wstring explanation) = 0; | 38 std::wstring explanation) = 0; |
| 45 | 39 |
| 46 // Sets information about the authentication type (|form|) and the | 40 // Sets information about the authentication type (|form|) and the |
| 47 // |password_manager| for this profile. | 41 // |password_manager| for this profile. |
| 48 virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) = 0; | 42 void SetPasswordForm(const webkit_glue::PasswordForm& form); |
| 49 virtual void SetPasswordManager(PasswordManager* password_manager) = 0; | 43 void SetPasswordManager(PasswordManager* password_manager); |
| 50 | 44 |
| 51 // Returns the TabContents that needs authentication. | 45 // Returns the TabContents that needs authentication. |
| 52 virtual TabContents* GetTabContentsForLogin() = 0; | 46 TabContents* GetTabContentsForLogin() const; |
| 53 | 47 |
| 54 // Resend the request with authentication credentials. | 48 // Resend the request with authentication credentials. |
| 55 // This function can be called from either thread. | 49 // This function can be called from either thread. |
| 56 virtual void SetAuth(const std::wstring& username, | 50 void SetAuth(const std::wstring& username, const std::wstring& password); |
| 57 const std::wstring& password) = 0; | |
| 58 | 51 |
| 59 // Display the error page without asking for credentials again. | 52 // Display the error page without asking for credentials again. |
| 60 // This function can be called from either thread. | 53 // This function can be called from either thread. |
| 61 virtual void CancelAuth() = 0; | 54 void CancelAuth(); |
| 62 | 55 |
| 63 // Notify the handler that the request was cancelled. | 56 // Notify the handler that the request was cancelled. |
| 64 // This function can only be called from the IO thread. | 57 // This function can only be called from the IO thread. |
| 65 virtual void OnRequestCancelled() = 0; | 58 void OnRequestCancelled(); |
| 66 | 59 |
| 67 protected: | 60 protected: |
| 68 virtual ~LoginHandler() {} | 61 |
| 62 void SetModel(LoginModel* model); |
| 63 |
| 64 void SetDialog(ConstrainedWindow* dialog); |
| 65 |
| 66 // Notify observers that authentication is needed or received. The automation |
| 67 // proxy uses this for testing. |
| 68 void SendNotifications(); |
| 69 |
| 70 void ReleaseSoon(); |
| 71 |
| 72 private: |
| 73 |
| 74 // Returns whether authentication had been handled (SetAuth or CancelAuth). |
| 75 // If |set_handled| is true, it will mark authentication as handled. |
| 76 bool WasAuthHandled(bool set_handled); |
| 77 |
| 78 // Calls SetAuth from the IO loop. |
| 79 void SetAuthDeferred(const std::wstring& username, |
| 80 const std::wstring& password); |
| 81 |
| 82 // Calls CancelAuth from the IO loop. |
| 83 void CancelAuthDeferred(); |
| 84 |
| 85 // Closes the view_contents from the UI loop. |
| 86 void CloseContentsDeferred(); |
| 87 |
| 88 // True if we've handled auth (SetAuth or CancelAuth has been called). |
| 89 bool handled_auth_; |
| 90 Lock handled_auth_lock_; |
| 91 |
| 92 // The ConstrainedWindow that is hosting our LoginView. |
| 93 // This should only be accessed on the UI loop. |
| 94 ConstrainedWindow* dialog_; |
| 95 |
| 96 // The request that wants login data. |
| 97 // This should only be accessed on the IO loop. |
| 98 URLRequest* request_; |
| 99 |
| 100 // The PasswordForm sent to the PasswordManager. This is so we can refer to it |
| 101 // when later notifying the password manager if the credentials were accepted |
| 102 // or rejected. |
| 103 // This should only be accessed on the UI loop. |
| 104 webkit_glue::PasswordForm password_form_; |
| 105 |
| 106 // Points to the password manager owned by the TabContents requesting auth. |
| 107 // Can be null if the TabContents is not a TabContents. |
| 108 // This should only be accessed on the UI loop. |
| 109 PasswordManager* password_manager_; |
| 110 |
| 111 // Cached from the URLRequest, in case it goes NULL on us. |
| 112 int render_process_host_id_; |
| 113 int tab_contents_id_; |
| 114 |
| 115 // If not null, points to a model we need to notify of our own destruction |
| 116 // so it doesn't try and access this when its too late. |
| 117 LoginModel* login_model_; |
| 69 }; | 118 }; |
| 70 | 119 |
| 71 // Details to provide the NotificationObserver. Used by the automation proxy | 120 // Details to provide the NotificationObserver. Used by the automation proxy |
| 72 // for testing. | 121 // for testing. |
| 73 class LoginNotificationDetails { | 122 class LoginNotificationDetails { |
| 74 public: | 123 public: |
| 75 explicit LoginNotificationDetails(LoginHandler* handler) | 124 explicit LoginNotificationDetails(LoginHandler* handler) |
| 76 : handler_(handler) {} | 125 : handler_(handler) {} |
| 77 LoginHandler* handler() const { return handler_; } | 126 LoginHandler* handler() const { return handler_; } |
| 78 | 127 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 98 | 147 |
| 99 // Helper to remove the ref from an URLRequest to the LoginHandler. | 148 // Helper to remove the ref from an URLRequest to the LoginHandler. |
| 100 // Should only be called from the IO thread, since it accesses an URLRequest. | 149 // Should only be called from the IO thread, since it accesses an URLRequest. |
| 101 void ResetLoginHandlerForRequest(URLRequest* request); | 150 void ResetLoginHandlerForRequest(URLRequest* request); |
| 102 | 151 |
| 103 // Get the signon_realm under which the identity should be saved. | 152 // Get the signon_realm under which the identity should be saved. |
| 104 std::string GetSignonRealm(const GURL& url, | 153 std::string GetSignonRealm(const GURL& url, |
| 105 const net::AuthChallengeInfo& auth_info); | 154 const net::AuthChallengeInfo& auth_info); |
| 106 | 155 |
| 107 #endif // CHROME_BROWSER_LOGIN_PROMPT_H_ | 156 #endif // CHROME_BROWSER_LOGIN_PROMPT_H_ |
| OLD | NEW |