| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
| 14 #include "chrome/browser/password_manager/password_manager.h" | 13 #include "chrome/browser/password_manager/password_manager.h" |
| 14 #include "content/browser/renderer_host/resource_dispatcher_host_login_delegate.
h" |
| 15 #include "content/common/notification_observer.h" | 15 #include "content/common/notification_observer.h" |
| 16 #include "content/common/notification_registrar.h" | 16 #include "content/common/notification_registrar.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 class AuthChallengeInfo; | 19 class AuthChallengeInfo; |
| 20 class URLRequest; | 20 class URLRequest; |
| 21 } // namespace net | 21 } // namespace net |
| 22 | 22 |
| 23 class ConstrainedWindow; | 23 class ConstrainedWindow; |
| 24 class GURL; | 24 class GURL; |
| 25 class RenderViewHostDelegate; | 25 class RenderViewHostDelegate; |
| 26 | 26 |
| 27 // This is the base implementation for the OS-specific classes that route | 27 // This is the base implementation for the OS-specific classes that route |
| 28 // authentication info to the net::URLRequest that needs it. These functions | 28 // authentication info to the net::URLRequest that needs it. These functions |
| 29 // must be implemented in a thread safe manner. | 29 // must be implemented in a thread safe manner. |
| 30 class LoginHandler : public base::RefCountedThreadSafe<LoginHandler>, | 30 class LoginHandler : public ResourceDispatcherHostLoginDelegate, |
| 31 public LoginModelObserver, | 31 public LoginModelObserver, |
| 32 public NotificationObserver { | 32 public NotificationObserver { |
| 33 public: | 33 public: |
| 34 LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request); | 34 LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request); |
| 35 virtual ~LoginHandler(); | 35 virtual ~LoginHandler(); |
| 36 | 36 |
| 37 // Builds the platform specific LoginHandler. Used from within | 37 // Builds the platform specific LoginHandler. Used from within |
| 38 // CreateLoginPrompt() which creates tasks. | 38 // CreateLoginPrompt() which creates tasks. |
| 39 static LoginHandler* Create(net::AuthChallengeInfo* auth_info, | 39 static LoginHandler* Create(net::AuthChallengeInfo* auth_info, |
| 40 net::URLRequest* request); | 40 net::URLRequest* request); |
| 41 | 41 |
| 42 // ResourceDispatcherHostLoginDelegate implementation: |
| 43 virtual void OnRequestCancelled(); |
| 44 |
| 42 // Initializes the underlying platform specific view. | 45 // Initializes the underlying platform specific view. |
| 43 virtual void BuildViewForPasswordManager(PasswordManager* manager, | 46 virtual void BuildViewForPasswordManager(PasswordManager* manager, |
| 44 const string16& explanation) = 0; | 47 const string16& explanation) = 0; |
| 45 | 48 |
| 46 // Sets information about the authentication type (|form|) and the | 49 // Sets information about the authentication type (|form|) and the |
| 47 // |password_manager| for this profile. | 50 // |password_manager| for this profile. |
| 48 void SetPasswordForm(const webkit_glue::PasswordForm& form); | 51 void SetPasswordForm(const webkit_glue::PasswordForm& form); |
| 49 void SetPasswordManager(PasswordManager* password_manager); | 52 void SetPasswordManager(PasswordManager* password_manager); |
| 50 | 53 |
| 51 // Returns the TabContents that needs authentication. | 54 // Returns the TabContents that needs authentication. |
| 52 TabContents* GetTabContentsForLogin() const; | 55 TabContents* GetTabContentsForLogin() const; |
| 53 | 56 |
| 54 // Returns the RenderViewHostDelegate for the page that needs authentication. | 57 // Returns the RenderViewHostDelegate for the page that needs authentication. |
| 55 RenderViewHostDelegate* GetRenderViewHostDelegate() const; | 58 RenderViewHostDelegate* GetRenderViewHostDelegate() const; |
| 56 | 59 |
| 57 // Resend the request with authentication credentials. | 60 // Resend the request with authentication credentials. |
| 58 // This function can be called from either thread. | 61 // This function can be called from either thread. |
| 59 void SetAuth(const string16& username, const string16& password); | 62 void SetAuth(const string16& username, const string16& password); |
| 60 | 63 |
| 61 // Display the error page without asking for credentials again. | 64 // Display the error page without asking for credentials again. |
| 62 // This function can be called from either thread. | 65 // This function can be called from either thread. |
| 63 void CancelAuth(); | 66 void CancelAuth(); |
| 64 | 67 |
| 65 // Notify the handler that the request was cancelled. | |
| 66 // This function can only be called from the IO thread. | |
| 67 void OnRequestCancelled(); | |
| 68 | |
| 69 // Implements the NotificationObserver interface. | 68 // Implements the NotificationObserver interface. |
| 70 // Listens for AUTH_SUPPLIED and AUTH_CANCELLED notifications from other | 69 // Listens for AUTH_SUPPLIED and AUTH_CANCELLED notifications from other |
| 71 // LoginHandlers so that this LoginHandler has the chance to dismiss itself | 70 // LoginHandlers so that this LoginHandler has the chance to dismiss itself |
| 72 // if it was waiting for the same authentication. | 71 // if it was waiting for the same authentication. |
| 73 virtual void Observe(NotificationType type, | 72 virtual void Observe(NotificationType type, |
| 74 const NotificationSource& source, | 73 const NotificationSource& source, |
| 75 const NotificationDetails& details); | 74 const NotificationDetails& details); |
| 76 | 75 |
| 77 // Who/where/what asked for the authentication. | 76 // Who/where/what asked for the authentication. |
| 78 const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); } | 77 const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // Helper to remove the ref from an net::URLRequest to the LoginHandler. | 211 // Helper to remove the ref from an net::URLRequest to the LoginHandler. |
| 213 // Should only be called from the IO thread, since it accesses an | 212 // Should only be called from the IO thread, since it accesses an |
| 214 // net::URLRequest. | 213 // net::URLRequest. |
| 215 void ResetLoginHandlerForRequest(net::URLRequest* request); | 214 void ResetLoginHandlerForRequest(net::URLRequest* request); |
| 216 | 215 |
| 217 // Get the signon_realm under which the identity should be saved. | 216 // Get the signon_realm under which the identity should be saved. |
| 218 std::string GetSignonRealm(const GURL& url, | 217 std::string GetSignonRealm(const GURL& url, |
| 219 const net::AuthChallengeInfo& auth_info); | 218 const net::AuthChallengeInfo& auth_info); |
| 220 | 219 |
| 221 #endif // CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ | 220 #endif // CHROME_BROWSER_UI_LOGIN_LOGIN_PROMPT_H_ |
| OLD | NEW |