• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CONTENT_SHELL_BROWSER_SHELL_LOGIN_DIALOG_H_
6 #define CONTENT_SHELL_BROWSER_SHELL_LOGIN_DIALOG_H_
7 
8 #include "base/compiler_specific.h"
9 #include "base/strings/string16.h"
10 #include "content/public/browser/resource_dispatcher_host_login_delegate.h"
11 
12 #if defined(TOOLKIT_GTK)
13 #include "ui/base/gtk/gtk_signal.h"
14 #endif
15 
16 #if defined(OS_MACOSX)
17 #if __OBJC__
18 @class ShellLoginDialogHelper;
19 #else
20 class ShellLoginDialogHelper;
21 #endif  // __OBJC__
22 #endif  // defined(OS_MACOSX)
23 
24 namespace net {
25 class AuthChallengeInfo;
26 class URLRequest;
27 }
28 
29 namespace content {
30 
31 // This class provides a dialog box to ask the user for credentials. Useful in
32 // ResourceDispatcherHostDelegate::CreateLoginDelegate.
33 class ShellLoginDialog : public ResourceDispatcherHostLoginDelegate {
34  public:
35   // Threading: IO thread.
36   ShellLoginDialog(net::AuthChallengeInfo* auth_info, net::URLRequest* request);
37 
38   // ResourceDispatcherHostLoginDelegate implementation:
39   // Threading: IO thread.
40   virtual void OnRequestCancelled() OVERRIDE;
41 
42   // Called by the platform specific code when the user responds. Public because
43   // the aforementioned platform specific code may not have access to private
44   // members. Not to be called from client code.
45   // Threading: UI thread.
46   void UserAcceptedAuth(const base::string16& username,
47                         const base::string16& password);
48   void UserCancelledAuth();
49 
50  protected:
51   // Threading: any
52   virtual ~ShellLoginDialog();
53 
54  private:
55   // All the methods that begin with Platform need to be implemented by the
56   // platform specific LoginDialog implementation.
57   // Creates the dialog.
58   // Threading: UI thread.
59   void PlatformCreateDialog(const base::string16& message);
60   // Called from the destructor to let each platform do any necessary cleanup.
61   // Threading: UI thread.
62   void PlatformCleanUp();
63   // Called from OnRequestCancelled if the request was cancelled.
64   // Threading: UI thread.
65   void PlatformRequestCancelled();
66 
67   // Sets up dialog creation.
68   // Threading: UI thread.
69   void PrepDialog(const base::string16& host, const base::string16& realm);
70 
71   // Sends the authentication to the requester.
72   // Threading: IO thread.
73   void SendAuthToRequester(bool success,
74                            const base::string16& username,
75                            const base::string16& password);
76 
77   // Who/where/what asked for the authentication.
78   // Threading: IO thread.
79   scoped_refptr<net::AuthChallengeInfo> auth_info_;
80 
81   // The request that wants login data.
82   // Threading: IO thread.
83   net::URLRequest* request_;
84 
85 #if defined(OS_MACOSX)
86   // Threading: UI thread.
87   ShellLoginDialogHelper* helper_;  // owned
88 #elif defined(TOOLKIT_GTK)
89   GtkWidget* username_entry_;
90   GtkWidget* password_entry_;
91   GtkWidget* root_;
92   CHROMEGTK_CALLBACK_1(ShellLoginDialog, void, OnResponse, int);
93 #endif
94 };
95 
96 }  // namespace content
97 
98 #endif  // CONTENT_SHELL_BROWSER_SHELL_LOGIN_DIALOG_H_
99