Add CefHandler::HandleAuthenticationRequest for handling authentication requests (issue #150).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@158 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2011-01-07 01:24:17 +00:00
parent c7959e2106
commit 874c73b1e1
8 changed files with 110 additions and 1 deletions

View File

@ -651,6 +651,19 @@ public:
int64 contentLength,
CefRefPtr<CefDownloadHandler>& handler) =0;
// Called when the browser needs credentials from the user. |isProxy|
// indicates whether the host is a proxy server. |host| contains the hostname
// and port number. Set |username| and |password| and return RV_HANDLED to
// handle the request. Return RV_CONTINUE to cancel the request.
/*--cef()--*/
virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser,
bool isProxy,
const CefString& host,
const CefString& realm,
const CefString& scheme,
CefString& username,
CefString& password) =0;
// Structure representing menu information.
typedef cef_handler_menuinfo_t MenuInfo;

View File

@ -460,6 +460,16 @@ typedef struct _cef_handler_t
const cef_string_t* mimeType, const cef_string_t* fileName,
int64 contentLength, struct _cef_download_handler_t** handler);
// Called when the browser needs credentials from the user. |isProxy|
// indicates whether the host is a proxy server. |host| contains the hostname
// and port number. Set |username| and |password| and return RV_HANDLED to
// handle the request. Return RV_CONTINUE to cancel the request.
enum cef_retval_t (CEF_CALLBACK *handle_authentication_request)(
struct _cef_handler_t* self, struct _cef_browser_t* browser, int isProxy,
const cef_string_t* host, const cef_string_t* realm,
const cef_string_t* scheme, cef_string_t* username,
cef_string_t* password);
// Event called before a context menu is displayed. To cancel display of the
// default context menu return RV_HANDLED.
enum cef_retval_t (CEF_CALLBACK *handle_before_menu)(

View File

@ -54,6 +54,7 @@
#include "base/timer.h"
#include "base/thread.h"
#include "base/waitable_event.h"
#include "net/base/auth.h"
#include "net/base/cookie_store.h"
#include "net/base/file_stream.h"
#include "net/base/io_buffer.h"
@ -552,6 +553,26 @@ class RequestProxy : public net::URLRequest::Delegate,
}
}
virtual void OnAuthRequired(net::URLRequest* request,
net::AuthChallengeInfo* auth_info) {
if (browser_.get()) {
CefRefPtr<CefHandler> handler = browser_->GetHandler();
if(handler.get()) {
CefString username, password;
CefHandler::RetVal rv = handler->HandleAuthenticationRequest(
browser_, auth_info->is_proxy,
auth_info->host_and_port, auth_info->realm,
auth_info->scheme, username, password);
if (rv == RV_HANDLED) {
request->SetAuth(username, password);
return;
}
}
}
request->CancelAuth();
}
virtual void OnSSLCertificateError(net::URLRequest* request,
int cert_error,
net::X509Certificate* cert) {

View File

@ -237,6 +237,27 @@ enum cef_retval_t CEF_CALLBACK handler_handle_download_response(
return rv;
}
enum cef_retval_t CEF_CALLBACK handler_handle_authentication_request(
struct _cef_handler_t* self, cef_browser_t* browser, int isProxy,
const cef_string_t* host, const cef_string_t* realm,
const cef_string_t* scheme, cef_string_t* username,
cef_string_t* password)
{
DCHECK(self);
DCHECK(browser);
DCHECK(username && password);
if (!self || !browser || !username || !password)
return RV_CONTINUE;
CefString usernameStr(username);
CefString passwordStr(password);
return CefHandlerCppToC::Get(self)->
HandleAuthenticationRequest(CefBrowserCToCpp::Wrap(browser),
(isProxy ? true : false), CefString(host), CefString(realm),
CefString(scheme), usernameStr, passwordStr);
}
enum cef_retval_t CEF_CALLBACK handler_handle_before_menu(
struct _cef_handler_t* self, cef_browser_t* browser,
const cef_handler_menuinfo_t* menuInfo)
@ -511,6 +532,8 @@ CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls)
struct_.struct_.handle_before_resource_load =
handler_handle_before_resource_load;
struct_.struct_.handle_download_response = handler_handle_download_response;
struct_.struct_.handle_authentication_request =
handler_handle_authentication_request;
struct_.struct_.handle_before_menu = handler_handle_before_menu;
struct_.struct_.handle_get_menu_label = handler_handle_get_menu_label;
struct_.struct_.handle_menu_action = handler_handle_menu_action;

View File

@ -178,6 +178,20 @@ CefHandler::RetVal CefHandlerCToCpp::HandleDownloadResponse(
return rv;
}
CefHandler::RetVal CefHandlerCToCpp::HandleAuthenticationRequest(
CefRefPtr<CefBrowser> browser, bool isProxy, const CefString& host,
const CefString& realm, const CefString& scheme, CefString& username,
CefString& password)
{
if(CEF_MEMBER_MISSING(struct_, handle_authentication_request))
return RV_CONTINUE;
return struct_->handle_authentication_request(struct_,
CefBrowserCppToC::Wrap(browser), isProxy,
host.GetStruct(), realm.GetStruct(), scheme.GetStruct(),
username.GetWritableStruct(), password.GetWritableStruct());
}
CefHandler::RetVal CefHandlerCToCpp::HandleBeforeMenu(
CefRefPtr<CefBrowser> browser, const MenuInfo& menuInfo)
{

View File

@ -57,6 +57,9 @@ public:
virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser,
const CefString& mimeType, const CefString& fileName,
int64 contentLength, CefRefPtr<CefDownloadHandler>& handler);
virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser,
bool isProxy, const CefString& host, const CefString& realm,
const CefString& scheme, CefString& username, CefString& password);
virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,
const MenuInfo& menuInfo);
virtual RetVal HandleGetMenuLabel(CefRefPtr<CefBrowser> browser,

View File

@ -120,13 +120,27 @@ public:
// no size was provided. Set |handler| to the CefDownloadHandler instance that
// will recieve the file contents. Return RV_CONTINUE to download the file
// or RV_HANDLED to cancel the file download.
/*--cef()--*/
virtual RetVal HandleDownloadResponse(CefRefPtr<CefBrowser> browser,
const CefString& mimeType,
const CefString& fileName,
int64 contentLength,
CefRefPtr<CefDownloadHandler>& handler);
// Called when the browser needs credentials from the user. |isProxy|
// indicates whether the host is a proxy server. |host| contains the hostname
// and port number. Set |username| and |password| and return RV_HANDLED to
// handle the request. Return RV_CONTINUE to cancel the request.
virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser,
bool isProxy,
const CefString& host,
const CefString& realm,
const CefString& scheme,
CefString& username,
CefString& password)
{
return RV_CONTINUE;
}
// Event called before a context menu is displayed. To cancel display of the
// default context menu return RV_HANDLED.
virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,

View File

@ -121,6 +121,17 @@ public:
return RV_CONTINUE;
}
virtual RetVal HandleAuthenticationRequest(CefRefPtr<CefBrowser> browser,
bool isProxy,
const CefString& host,
const CefString& realm,
const CefString& scheme,
CefString& username,
CefString& password)
{
return RV_CONTINUE;
}
virtual RetVal HandleBeforeMenu(CefRefPtr<CefBrowser> browser,
const MenuInfo& menuInfo)
{