diff --git a/cef.gyp b/cef.gyp index 021781a14..6e64da7a6 100644 --- a/cef.gyp +++ b/cef.gyp @@ -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', diff --git a/cef_paths.gypi b/cef_paths.gypi index c1936eed7..4f3e9cb2d 100644 --- a/cef_paths.gypi +++ b/cef_paths.gypi @@ -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', diff --git a/include/capi/cef_auth_callback_capi.h b/include/capi/cef_auth_callback_capi.h new file mode 100644 index 000000000..649a75ec8 --- /dev/null +++ b/include/capi/cef_auth_callback_capi.h @@ -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_ diff --git a/include/capi/cef_request_handler_capi.h b/include/capi/cef_request_handler_capi.h index a9b4199b5..1e7328168 100644 --- a/include/capi/cef_request_handler_capi.h +++ b/include/capi/cef_request_handler_capi.h @@ -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. /// diff --git a/include/capi/cef_urlrequest_capi.h b/include/capi/cef_urlrequest_capi.h index 23100feeb..882372530 100644 --- a/include/capi/cef_urlrequest_capi.h +++ b/include/capi/cef_urlrequest_capi.h @@ -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; diff --git a/include/cef_auth_callback.h b/include/cef_auth_callback.h new file mode 100644 index 000000000..b5c695320 --- /dev/null +++ b/include/cef_auth_callback.h @@ -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_ diff --git a/include/cef_request_handler.h b/include/cef_request_handler.h index 641e16b74..3f3ff0e07 100644 --- a/include/cef_request_handler.h +++ b/include/cef_request_handler.h @@ -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. /// diff --git a/include/cef_urlrequest.h b/include/cef_urlrequest.h index 069d2668c..ad78b4e8e 100644 --- a/include/cef_urlrequest.h +++ b/include/cef_urlrequest.h @@ -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 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 callback) =0; }; #endif // CEF_INCLUDE_CEF_URLREQUEST_H_ diff --git a/libcef/browser/browser_urlrequest_impl.cc b/libcef/browser/browser_urlrequest_impl.cc index cdf3932a7..2c060e0f9 100644 --- a/libcef/browser/browser_urlrequest_impl.cc +++ b/libcef/browser/browser_urlrequest_impl.cc @@ -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 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; diff --git a/libcef/browser/url_network_delegate.cc b/libcef/browser/url_network_delegate.cc index cb52bad80..16615421e 100644 --- a/libcef/browser/url_network_delegate.cc +++ b/libcef/browser/url_network_delegate.cc @@ -6,8 +6,10 @@ #include +#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 client = user_data->GetClient(); + if (client.get()) { + CefRefPtr 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; } diff --git a/libcef/browser/url_request_user_data.cc b/libcef/browser/url_request_user_data.cc new file mode 100644 index 000000000..dc23ad0f8 --- /dev/null +++ b/libcef/browser/url_request_user_data.cc @@ -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 client) + : client_(client) {} + +CefURLRequestUserData::~CefURLRequestUserData() {} + +CefRefPtr CefURLRequestUserData::GetClient() { + return client_; +} + +// static +const void* CefURLRequestUserData::kUserDataKey = + static_cast(&CefURLRequestUserData::kUserDataKey); diff --git a/libcef/browser/url_request_user_data.h b/libcef/browser/url_request_user_data.h new file mode 100644 index 000000000..ea02c3c68 --- /dev/null +++ b/libcef/browser/url_request_user_data.h @@ -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 client); + virtual ~CefURLRequestUserData(); + + CefRefPtr GetClient(); + static const void* kUserDataKey; + +private: + CefRefPtr client_; +}; + +#endif // CEF_LIBCEF_BROWSER_URL_REQUEST_USER_DATA_H_ diff --git a/libcef_dll/cpptoc/auth_callback_cpptoc.h b/libcef_dll/cpptoc/auth_callback_cpptoc.h index ba5ebdbe1..15a5a50a8 100644 --- a/libcef_dll/cpptoc/auth_callback_cpptoc.h +++ b/libcef_dll/cpptoc/auth_callback_cpptoc.h @@ -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. diff --git a/libcef_dll/cpptoc/urlrequest_client_cpptoc.cc b/libcef_dll/cpptoc/urlrequest_client_cpptoc.cc index 086129203..85df61959 100644 --- a/libcef_dll/cpptoc/urlrequest_client_cpptoc.cc +++ b/libcef_dll/cpptoc/urlrequest_client_cpptoc.cc @@ -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 diff --git a/libcef_dll/ctocpp/auth_callback_ctocpp.h b/libcef_dll/ctocpp/auth_callback_ctocpp.h index 08ae159c9..0d144341b 100644 --- a/libcef_dll/ctocpp/auth_callback_ctocpp.h +++ b/libcef_dll/ctocpp/auth_callback_ctocpp.h @@ -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. diff --git a/libcef_dll/ctocpp/urlrequest_client_ctocpp.cc b/libcef_dll/ctocpp/urlrequest_client_ctocpp.cc index b468f23bd..d2a973ab4 100644 --- a/libcef_dll/ctocpp/urlrequest_client_ctocpp.cc +++ b/libcef_dll/ctocpp/urlrequest_client_ctocpp.cc @@ -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 request, data_length); } +bool CefURLRequestClientCToCpp::GetAuthCredentials(bool isProxy, + const CefString& host, int port, const CefString& realm, + const CefString& scheme, CefRefPtr 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 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 callback) OVERRIDE; }; #endif // BUILDING_CEF_SHARED diff --git a/tests/unittests/urlrequest_unittest.cc b/tests/unittests/urlrequest_unittest.cc index ff9cc15ee..a690e69d5 100644 --- a/tests/unittests/urlrequest_unittest.cc +++ b/tests/unittests/urlrequest_unittest.cc @@ -447,6 +447,15 @@ class RequestClient : public CefURLRequestClient { download_data_ += std::string(static_cast(data), data_length); } + virtual bool GetAuthCredentials(bool isProxy, + const CefString& host, + int port, + const CefString& realm, + const CefString& scheme, + CefRefPtr callback) OVERRIDE { + return false; + } + private: explicit RequestClient(Delegate* delegate) : delegate_(delegate),