electron/atom/browser/login_handler.h

76 lines
2.3 KiB
C
Raw Normal View History

2015-10-28 15:34:41 +08:00
// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_BROWSER_LOGIN_HANDLER_H_
#define ATOM_BROWSER_LOGIN_HANDLER_H_
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner_helpers.h"
2015-10-28 19:34:01 +08:00
#include "base/strings/string16.h"
2018-04-12 15:18:26 +05:30
#include "content/public/browser/resource_request_info.h"
#include "net/base/network_delegate.h"
2015-10-28 15:34:41 +08:00
namespace content {
class WebContents;
}
2015-10-28 15:34:41 +08:00
namespace atom {
2015-10-28 19:34:01 +08:00
// Handles the HTTP basic auth, must be created on IO thread.
class LoginHandler : public base::RefCountedThreadSafe<LoginHandler> {
2015-10-28 15:34:41 +08:00
public:
LoginHandler(net::URLRequest* request,
const net::AuthChallengeInfo& auth_info,
net::NetworkDelegate::AuthCallback callback,
net::AuthCredentials* credentials,
content::ResourceRequestInfo* resource_request_info);
2015-10-28 19:34:01 +08:00
// The auth is cancelled, must be called on UI thread.
void CancelAuth();
// The URLRequest associated with the auth is destroyed.
void NotifyRequestDestroyed();
2015-10-28 19:34:01 +08:00
// Login with |username| and |password|, must be called on UI thread.
void Login(const base::string16& username, const base::string16& password);
// Returns the WebContents associated with the request, must be called on UI
// thread.
content::WebContents* GetWebContents() const;
2015-10-28 15:34:41 +08:00
const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); }
2015-10-28 15:34:41 +08:00
private:
friend class base::RefCountedThreadSafe<LoginHandler>;
friend class base::DeleteHelper<LoginHandler>;
~LoginHandler();
2015-10-28 19:34:01 +08:00
// Must be called on IO thread.
void DoCancelAuth();
void DoLogin(const base::string16& username, const base::string16& password);
// Credentials to be used for the auth.
net::AuthCredentials* credentials_;
2015-10-28 21:20:08 +08:00
2015-10-28 15:34:41 +08:00
// Who/where/what asked for the authentication.
scoped_refptr<const net::AuthChallengeInfo> auth_info_;
2015-10-28 15:34:41 +08:00
// WebContents associated with the login request.
content::ResourceRequestInfo::WebContentsGetter web_contents_getter_;
2015-10-28 15:34:41 +08:00
// Called with preferred value of net::NetworkDelegate::AuthRequiredResponse.
net::NetworkDelegate::AuthCallback auth_callback_;
base::WeakPtrFactory<LoginHandler> weak_factory_;
2015-10-28 15:34:41 +08:00
DISALLOW_COPY_AND_ASSIGN(LoginHandler);
};
} // namespace atom
#endif // ATOM_BROWSER_LOGIN_HANDLER_H_