electron/atom/browser/login_handler.h

56 lines
1.6 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_
2015-10-28 19:34:01 +08:00
#include "base/strings/string16.h"
2015-10-28 15:34:41 +08:00
#include "content/public/browser/resource_dispatcher_host_login_delegate.h"
namespace net {
class AuthChallengeInfo;
class URLRequest;
}
namespace atom {
2015-10-28 19:34:01 +08:00
// Handles the HTTP basic auth, must be created on IO thread.
2015-10-28 15:34:41 +08:00
class LoginHandler : public content::ResourceDispatcherHostLoginDelegate {
public:
LoginHandler(net::AuthChallengeInfo* auth_info, net::URLRequest* request);
2015-10-28 19:34:01 +08:00
// The auth is cancelled, must be called on UI thread.
void CancelAuth();
// Login with |username| and |password|, must be called on UI thread.
void Login(const base::string16& username, const base::string16& password);
const net::AuthChallengeInfo* auth_info() const { return auth_info_.get(); }
const net::URLRequest* request() const { return request_; }
2015-10-28 15:34:41 +08:00
protected:
~LoginHandler() override;
// content::ResourceDispatcherHostLoginDelegate:
void OnRequestCancelled() override;
private:
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);
2015-10-28 15:34:41 +08:00
// Who/where/what asked for the authentication.
scoped_refptr<net::AuthChallengeInfo> auth_info_;
// The request that wants login data.
// This should only be accessed on the IO loop.
net::URLRequest* request_;
DISALLOW_COPY_AND_ASSIGN(LoginHandler);
};
} // namespace atom
#endif // ATOM_BROWSER_LOGIN_HANDLER_H_