Merge revision 1415 changes:

- Add CefURLRequestClient::GetAuthCredentials callback (issue #975).

git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1547@1417 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2013-08-27 18:59:50 +00:00
parent 1ac1250005
commit 65694f4b3b
18 changed files with 345 additions and 51 deletions

View File

@ -872,6 +872,8 @@
'libcef/browser/url_request_context_proxy.h',
'libcef/browser/url_request_interceptor.cc',
'libcef/browser/url_request_interceptor.h',
'libcef/browser/url_request_user_data.cc',
'libcef/browser/url_request_user_data.h',
'libcef/browser/web_contents_view_osr.cc',
'libcef/browser/web_contents_view_osr.h',
'libcef/browser/web_plugin_impl.cc',

View File

@ -13,6 +13,7 @@
'variables': {
'autogen_cpp_includes': [
'include/cef_app.h',
'include/cef_auth_callback.h',
'include/cef_browser.h',
'include/cef_browser_process_handler.h',
'include/cef_callback.h',
@ -62,6 +63,7 @@
],
'autogen_capi_includes': [
'include/capi/cef_app_capi.h',
'include/capi/cef_auth_callback_capi.h',
'include/capi/cef_browser_capi.h',
'include/capi/cef_browser_process_handler_capi.h',
'include/capi/cef_callback_capi.h',

View File

@ -0,0 +1,75 @@
// Copyright (c) 2013 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool and should not edited
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
#ifndef CEF_INCLUDE_CAPI_CEF_AUTH_CALLBACK_CAPI_H_
#define CEF_INCLUDE_CAPI_CEF_AUTH_CALLBACK_CAPI_H_
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "include/capi/cef_base_capi.h"
///
// Callback structure used for asynchronous continuation of authentication
// requests.
///
typedef struct _cef_auth_callback_t {
///
// Base structure.
///
cef_base_t base;
///
// Continue the authentication request.
///
void (CEF_CALLBACK *cont)(struct _cef_auth_callback_t* self,
const cef_string_t* username, const cef_string_t* password);
///
// Cancel the authentication request.
///
void (CEF_CALLBACK *cancel)(struct _cef_auth_callback_t* self);
} cef_auth_callback_t;
#ifdef __cplusplus
}
#endif
#endif // CEF_INCLUDE_CAPI_CEF_AUTH_CALLBACK_CAPI_H_

View File

@ -45,29 +45,6 @@ extern "C" {
#include "include/capi/cef_base_capi.h"
///
// Callback structure used for asynchronous continuation of authentication
// requests.
///
typedef struct _cef_auth_callback_t {
///
// Base structure.
///
cef_base_t base;
///
// Continue the authentication request.
///
void (CEF_CALLBACK *cont)(struct _cef_auth_callback_t* self,
const cef_string_t* username, const cef_string_t* password);
///
// Cancel the authentication request.
///
void (CEF_CALLBACK *cancel)(struct _cef_auth_callback_t* self);
} cef_auth_callback_t;
///
// Callback structure used for asynchronous continuation of quota requests.
///

View File

@ -111,7 +111,7 @@ CEF_EXPORT cef_urlrequest_t* cef_urlrequest_create(
///
// Structure that should be implemented by the cef_urlrequest_t client. The
// functions of this structure will be called on the same thread that created
// the request.
// the request unless otherwise documented.
///
typedef struct _cef_urlrequest_client_t {
///
@ -154,6 +154,20 @@ typedef struct _cef_urlrequest_client_t {
void (CEF_CALLBACK *on_download_data)(struct _cef_urlrequest_client_t* self,
struct _cef_urlrequest_t* request, const void* data,
size_t data_length);
///
// Called on the IO thread when the browser needs credentials from the user.
// |isProxy| indicates whether the host is a proxy server. |host| contains the
// hostname and |port| contains the port number. Return true (1) to continue
// the request and call cef_auth_callback_t::cont() when the authentication
// information is available. Return false (0) to cancel the request. This
// function will only be called for requests initiated from the browser
// process.
///
int (CEF_CALLBACK *get_auth_credentials)(
struct _cef_urlrequest_client_t* self, int isProxy,
const cef_string_t* host, int port, const cef_string_t* realm,
const cef_string_t* scheme, struct _cef_auth_callback_t* callback);
} cef_urlrequest_client_t;

View File

@ -0,0 +1,64 @@
// Copyright (c) 2013 Marshall A. Greenblatt. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the name Chromium Embedded
// Framework nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ---------------------------------------------------------------------------
//
// The contents of this file must follow a specific format in order to
// support the CEF translator tool. See the translator.README.txt file in the
// tools directory for more information.
//
#ifndef CEF_INCLUDE_CEF_AUTH_CALLBACK_H_
#define CEF_INCLUDE_CEF_AUTH_CALLBACK_H_
#pragma once
#include "include/cef_base.h"
///
// Callback interface used for asynchronous continuation of authentication
// requests.
///
/*--cef(source=library)--*/
class CefAuthCallback : public virtual CefBase {
public:
///
// Continue the authentication request.
///
/*--cef(capi_name=cont)--*/
virtual void Continue(const CefString& username,
const CefString& password) =0;
///
// Cancel the authentication request.
///
/*--cef()--*/
virtual void Cancel() =0;
};
#endif // CEF_INCLUDE_CEF_AUTH_CALLBACK_H_

View File

@ -38,6 +38,7 @@
#define CEF_INCLUDE_CEF_REQUEST_HANDLER_H_
#pragma once
#include "include/cef_auth_callback.h"
#include "include/cef_base.h"
#include "include/cef_browser.h"
#include "include/cef_cookie.h"
@ -47,28 +48,6 @@
#include "include/cef_request.h"
#include "include/cef_web_plugin.h"
///
// Callback interface used for asynchronous continuation of authentication
// requests.
///
/*--cef(source=library)--*/
class CefAuthCallback : public virtual CefBase {
public:
///
// Continue the authentication request.
///
/*--cef(capi_name=cont)--*/
virtual void Continue(const CefString& username,
const CefString& password) =0;
///
// Cancel the authentication request.
///
/*--cef()--*/
virtual void Cancel() =0;
};
///
// Callback interface used for asynchronous continuation of quota requests.
///

View File

@ -38,6 +38,7 @@
#define CEF_INCLUDE_CEF_URLREQUEST_H_
#pragma once
#include "include/cef_auth_callback.h"
#include "include/cef_base.h"
#include "include/cef_request.h"
#include "include/cef_response.h"
@ -111,7 +112,7 @@ class CefURLRequest : public virtual CefBase {
///
// Interface that should be implemented by the CefURLRequest client. The
// methods of this class will be called on the same thread that created the
// request.
// request unless otherwise documented.
///
/*--cef(source=client)--*/
class CefURLRequestClient : public virtual CefBase {
@ -154,6 +155,22 @@ class CefURLRequestClient : public virtual CefBase {
virtual void OnDownloadData(CefRefPtr<CefURLRequest> request,
const void* data,
size_t data_length) =0;
///
// Called on the IO thread when the browser needs credentials from the user.
// |isProxy| indicates whether the host is a proxy server. |host| contains the
// hostname and |port| contains the port number. Return true to continue the
// request and call CefAuthCallback::Continue() when the authentication
// information is available. Return false to cancel the request. This method
// will only be called for requests initiated from the browser process.
///
/*--cef(optional_param=realm)--*/
virtual bool GetAuthCredentials(bool isProxy,
const CefString& host,
int port,
const CefString& realm,
const CefString& scheme,
CefRefPtr<CefAuthCallback> callback) =0;
};
#endif // CEF_INCLUDE_CEF_URLREQUEST_H_

View File

@ -9,6 +9,7 @@
#include "libcef/browser/browser_context.h"
#include "libcef/browser/context.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_user_data.h"
#include "libcef/common/http_header_utils.h"
#include "libcef/common/request_impl.h"
#include "libcef/common/response_impl.h"
@ -50,6 +51,11 @@ class CefURLFetcherDelegate : public net::URLFetcherDelegate {
int request_flags_;
};
base::SupportsUserData::Data* CreateURLRequestUserData(
CefRefPtr<CefURLRequestClient> client) {
return new CefURLRequestUserData(client);
}
} // namespace
@ -208,6 +214,10 @@ class CefBrowserURLRequest::Context
fetcher_->SetExtraRequestHeaders(
HttpHeaderUtils::GenerateHeaders(headerMap));
fetcher_->SetURLRequestUserData(
CefURLRequestUserData::kUserDataKey,
base::Bind(&CreateURLRequestUserData, client_));
fetcher_->Start();
return true;

View File

@ -6,8 +6,10 @@
#include <string>
#include "include/cef_urlrequest.h"
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/url_request_user_data.h"
#include "libcef/common/request_impl.h"
#include "net/base/net_errors.h"
@ -193,6 +195,27 @@ net::NetworkDelegate::AuthRequiredResponse CefNetworkDelegate::OnAuthRequired(
}
}
CefURLRequestUserData* user_data =
(CefURLRequestUserData*)request->GetUserData(
CefURLRequestUserData::kUserDataKey);
if (user_data) {
CefRefPtr<CefURLRequestClient> client = user_data->GetClient();
if (client.get()) {
CefRefPtr<CefAuthCallbackImpl> callbackPtr(
new CefAuthCallbackImpl(callback, credentials));
if (client->GetAuthCredentials(auth_info.is_proxy,
auth_info.challenger.host(),
auth_info.challenger.port(),
auth_info.realm,
auth_info.scheme,
callbackPtr.get())) {
return AUTH_REQUIRED_RESPONSE_IO_PENDING;
} else {
callbackPtr->Disconnect();
}
}
}
return AUTH_REQUIRED_RESPONSE_NO_ACTION;
}

View File

@ -0,0 +1,18 @@
// Copyright (c) 2012 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.
#include "libcef/browser/url_request_user_data.h"
CefURLRequestUserData::CefURLRequestUserData(CefRefPtr<CefURLRequestClient> client)
: client_(client) {}
CefURLRequestUserData::~CefURLRequestUserData() {}
CefRefPtr<CefURLRequestClient> CefURLRequestUserData::GetClient() {
return client_;
}
// static
const void* CefURLRequestUserData::kUserDataKey =
static_cast<const void*>(&CefURLRequestUserData::kUserDataKey);

View File

@ -0,0 +1,27 @@
// Copyright (c) 2012 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 CEF_LIBCEF_BROWSER_URL_REQUEST_USER_DATA_H_
#define CEF_LIBCEF_BROWSER_URL_REQUEST_USER_DATA_H_
#include "include/cef_base.h"
#include "base/supports_user_data.h"
#include "include/cef_urlrequest.h"
// Used to annotate all URLRequests for which the request can be associated
// with the CefURLRequestClient.
class CefURLRequestUserData : public base::SupportsUserData::Data {
public:
CefURLRequestUserData(CefRefPtr<CefURLRequestClient> client);
virtual ~CefURLRequestUserData();
CefRefPtr<CefURLRequestClient> GetClient();
static const void* kUserDataKey;
private:
CefRefPtr<CefURLRequestClient> client_;
};
#endif // CEF_LIBCEF_BROWSER_URL_REQUEST_USER_DATA_H_

View File

@ -18,8 +18,8 @@
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "include/cef_request_handler.h"
#include "include/capi/cef_request_handler_capi.h"
#include "include/cef_auth_callback.h"
#include "include/capi/cef_auth_callback_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.

View File

@ -11,6 +11,7 @@
//
#include "libcef_dll/cpptoc/urlrequest_client_cpptoc.h"
#include "libcef_dll/ctocpp/auth_callback_ctocpp.h"
#include "libcef_dll/ctocpp/urlrequest_ctocpp.h"
@ -97,6 +98,42 @@ void CEF_CALLBACK urlrequest_client_on_download_data(
data_length);
}
int CEF_CALLBACK urlrequest_client_get_auth_credentials(
struct _cef_urlrequest_client_t* self, int isProxy,
const cef_string_t* host, int port, const cef_string_t* realm,
const cef_string_t* scheme, cef_auth_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: host; type: string_byref_const
DCHECK(host);
if (!host)
return 0;
// Verify param: scheme; type: string_byref_const
DCHECK(scheme);
if (!scheme)
return 0;
// Verify param: callback; type: refptr_diff
DCHECK(callback);
if (!callback)
return 0;
// Unverified params: realm
// Execute
bool _retval = CefURLRequestClientCppToC::Get(self)->GetAuthCredentials(
isProxy?true:false,
CefString(host),
port,
CefString(realm),
CefString(scheme),
CefAuthCallbackCToCpp::Wrap(callback));
// Return type: bool
return _retval;
}
// CONSTRUCTOR - Do not edit by hand.
@ -107,6 +144,7 @@ CefURLRequestClientCppToC::CefURLRequestClientCppToC(CefURLRequestClient* cls)
struct_.struct_.on_upload_progress = urlrequest_client_on_upload_progress;
struct_.struct_.on_download_progress = urlrequest_client_on_download_progress;
struct_.struct_.on_download_data = urlrequest_client_on_download_data;
struct_.struct_.get_auth_credentials = urlrequest_client_get_auth_credentials;
}
#ifndef NDEBUG

View File

@ -18,8 +18,8 @@
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "include/cef_request_handler.h"
#include "include/capi/cef_request_handler_capi.h"
#include "include/cef_auth_callback.h"
#include "include/capi/cef_auth_callback_capi.h"
#include "libcef_dll/ctocpp/ctocpp.h"
// Wrap a C structure with a C++ class.

View File

@ -10,6 +10,7 @@
// for more information.
//
#include "libcef_dll/cpptoc/auth_callback_cpptoc.h"
#include "libcef_dll/cpptoc/urlrequest_cpptoc.h"
#include "libcef_dll/ctocpp/urlrequest_client_ctocpp.h"
@ -94,6 +95,41 @@ void CefURLRequestClientCToCpp::OnDownloadData(CefRefPtr<CefURLRequest> request,
data_length);
}
bool CefURLRequestClientCToCpp::GetAuthCredentials(bool isProxy,
const CefString& host, int port, const CefString& realm,
const CefString& scheme, CefRefPtr<CefAuthCallback> callback) {
if (CEF_MEMBER_MISSING(struct_, get_auth_credentials))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: host; type: string_byref_const
DCHECK(!host.empty());
if (host.empty())
return false;
// Verify param: scheme; type: string_byref_const
DCHECK(!scheme.empty());
if (scheme.empty())
return false;
// Verify param: callback; type: refptr_diff
DCHECK(callback.get());
if (!callback.get())
return false;
// Unverified params: realm
// Execute
int _retval = struct_->get_auth_credentials(struct_,
isProxy,
host.GetStruct(),
port,
realm.GetStruct(),
scheme.GetStruct(),
CefAuthCallbackCppToC::Wrap(callback));
// Return type: bool
return _retval?true:false;
}
#ifndef NDEBUG
template<> long CefCToCpp<CefURLRequestClientCToCpp, CefURLRequestClient,

View File

@ -41,6 +41,9 @@ class CefURLRequestClientCToCpp
uint64 current, uint64 total) OVERRIDE;
virtual void OnDownloadData(CefRefPtr<CefURLRequest> request,
const void* data, size_t data_length) OVERRIDE;
virtual bool GetAuthCredentials(bool isProxy, const CefString& host, int port,
const CefString& realm, const CefString& scheme,
CefRefPtr<CefAuthCallback> callback) OVERRIDE;
};
#endif // BUILDING_CEF_SHARED

View File

@ -447,6 +447,15 @@ class RequestClient : public CefURLRequestClient {
download_data_ += std::string(static_cast<const char*>(data), data_length);
}
virtual bool GetAuthCredentials(bool isProxy,
const CefString& host,
int port,
const CefString& realm,
const CefString& scheme,
CefRefPtr<CefAuthCallback> callback) OVERRIDE {
return false;
}
private:
explicit RequestClient(Delegate* delegate)
: delegate_(delegate),