summaryrefslogtreecommitdiffstats
path: root/chrome/browser/login_prompt.h
blob: 9cfa264d760c0f943b5256408ed3b470755dd532 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_LOGIN_PROMPT_H_
#define CHROME_BROWSER_LOGIN_PROMPT_H_

#include <string>

#include "base/basictypes.h"

namespace net {
class AuthChallengeInfo;
}

namespace webkit_glue {
struct PasswordForm;
}

class ConstrainedWindow;
class GURL;
class PasswordManager;
class TabContents;
class URLRequest;

// This is the interface for the class that routes authentication info to
// the URLRequest that needs it.  Used by the automation proxy for testing.
// These functions should be (and are, in LoginHandlerImpl) implemented in
// a thread safe manner.
//
// TODO(erg): Refactor the common code from all LoginHandler subclasses into a
// common controller class. All the methods below have the same copy/pasted
// implementation. This is more difficult then it should be because all these
// subclasses are also base::RefCountedThreadSafe<> and I'm not sure how to get
// ownership correct.  http://crbug.com/14909
class LoginHandler {
 public:
  // Builds the platform specific LoginHandler. Used from within
  // CreateLoginPrompt() which creates tasks.
  static LoginHandler* Create(URLRequest* request);

  // Initializes the underlying platform specific view.
  virtual void BuildViewForPasswordManager(PasswordManager* manager,
                                           std::wstring explanation) = 0;

  // Sets information about the authentication type (|form|) and the
  // |password_manager| for this profile.
  virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) = 0;
  virtual void SetPasswordManager(PasswordManager* password_manager) = 0;

  // Returns the TabContents that needs authentication.
  virtual TabContents* GetTabContentsForLogin() = 0;

  // Resend the request with authentication credentials.
  // This function can be called from either thread.
  virtual void SetAuth(const std::wstring& username,
                       const std::wstring& password) = 0;

  // Display the error page without asking for credentials again.
  // This function can be called from either thread.
  virtual void CancelAuth() = 0;

  // Notify the handler that the request was cancelled.
  // This function can only be called from the IO thread.
  virtual void OnRequestCancelled() = 0;
};

// Details to provide the NotificationObserver.  Used by the automation proxy
// for testing.
class LoginNotificationDetails {
 public:
  explicit LoginNotificationDetails(LoginHandler* handler)
      : handler_(handler) {}
  LoginHandler* handler() const { return handler_; }

 private:
  LoginNotificationDetails() {}

  LoginHandler* handler_;  // Where to send the response.

  DISALLOW_COPY_AND_ASSIGN(LoginNotificationDetails);
};

// Prompts the user for their username and password.  This is designed to
// be called on the background (I/O) thread, in response to
// URLRequest::Delegate::OnAuthRequired.  The prompt will be created
// on the main UI thread via a call to UI loop's InvokeLater, and will send the
// credentials back to the URLRequest on the calling thread.
// A LoginHandler object (which lives on the calling thread) is returned,
// which can be used to set or cancel authentication programmatically.  The
// caller must invoke OnRequestCancelled() on this LoginHandler before
// destroying the URLRequest.
LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info,
                                URLRequest* request);

// Helper to remove the ref from an URLRequest to the LoginHandler.
// Should only be called from the IO thread, since it accesses an URLRequest.
void ResetLoginHandlerForRequest(URLRequest* request);

// Get the signon_realm under which the identity should be saved.
std::string GetSignonRealm(const GURL& url,
                           const net::AuthChallengeInfo& auth_info);

#endif  // CHROME_BROWSER_LOGIN_PROMPT_H_