diff --git a/cef_paths.gypi b/cef_paths.gypi index e3ba4f4a9..5456837f0 100644 --- a/cef_paths.gypi +++ b/cef_paths.gypi @@ -126,8 +126,6 @@ 'include/capi/cef_zip_reader_capi.h', ], 'autogen_library_side': [ - 'libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.cc', - 'libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.h', 'libcef_dll/ctocpp/app_ctocpp.cc', 'libcef_dll/ctocpp/app_ctocpp.h', 'libcef_dll/cpptoc/auth_callback_cpptoc.cc', @@ -228,8 +226,6 @@ 'libcef_dll/cpptoc/print_settings_cpptoc.h', 'libcef_dll/cpptoc/process_message_cpptoc.cc', 'libcef_dll/cpptoc/process_message_cpptoc.h', - 'libcef_dll/cpptoc/quota_callback_cpptoc.cc', - 'libcef_dll/cpptoc/quota_callback_cpptoc.h', 'libcef_dll/ctocpp/read_handler_ctocpp.cc', 'libcef_dll/ctocpp/read_handler_ctocpp.h', 'libcef_dll/ctocpp/render_handler_ctocpp.cc', @@ -238,6 +234,8 @@ 'libcef_dll/ctocpp/render_process_handler_ctocpp.h', 'libcef_dll/cpptoc/request_cpptoc.cc', 'libcef_dll/cpptoc/request_cpptoc.h', + 'libcef_dll/cpptoc/request_callback_cpptoc.cc', + 'libcef_dll/cpptoc/request_callback_cpptoc.h', 'libcef_dll/cpptoc/request_context_cpptoc.cc', 'libcef_dll/cpptoc/request_context_cpptoc.h', 'libcef_dll/ctocpp/request_context_handler_ctocpp.cc', @@ -302,8 +300,6 @@ 'libcef_dll/cpptoc/zip_reader_cpptoc.h', ], 'autogen_client_side': [ - 'libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.cc', - 'libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.h', 'libcef_dll/cpptoc/app_cpptoc.cc', 'libcef_dll/cpptoc/app_cpptoc.h', 'libcef_dll/ctocpp/auth_callback_ctocpp.cc', @@ -404,8 +400,6 @@ 'libcef_dll/ctocpp/print_settings_ctocpp.h', 'libcef_dll/ctocpp/process_message_ctocpp.cc', 'libcef_dll/ctocpp/process_message_ctocpp.h', - 'libcef_dll/ctocpp/quota_callback_ctocpp.cc', - 'libcef_dll/ctocpp/quota_callback_ctocpp.h', 'libcef_dll/cpptoc/read_handler_cpptoc.cc', 'libcef_dll/cpptoc/read_handler_cpptoc.h', 'libcef_dll/cpptoc/render_handler_cpptoc.cc', @@ -414,6 +408,8 @@ 'libcef_dll/cpptoc/render_process_handler_cpptoc.h', 'libcef_dll/ctocpp/request_ctocpp.cc', 'libcef_dll/ctocpp/request_ctocpp.h', + 'libcef_dll/ctocpp/request_callback_ctocpp.cc', + 'libcef_dll/ctocpp/request_callback_ctocpp.h', 'libcef_dll/ctocpp/request_context_ctocpp.cc', 'libcef_dll/ctocpp/request_context_ctocpp.h', 'libcef_dll/cpptoc/request_context_handler_cpptoc.cc', diff --git a/include/capi/cef_request_handler_capi.h b/include/capi/cef_request_handler_capi.h index 72be00916..9cb486827 100644 --- a/include/capi/cef_request_handler_capi.h +++ b/include/capi/cef_request_handler_capi.h @@ -54,32 +54,9 @@ extern "C" { /// -// Callback structure used for asynchronous continuation of quota requests. +// Callback structure used for asynchronous continuation of url requests. /// -typedef struct _cef_quota_callback_t { - /// - // Base structure. - /// - cef_base_t base; - - /// - // Continue the quota request. If |allow| is true (1) the request will be - // allowed. Otherwise, the request will be denied. - /// - void (CEF_CALLBACK *cont)(struct _cef_quota_callback_t* self, int allow); - - /// - // Cancel the quota request. - /// - void (CEF_CALLBACK *cancel)(struct _cef_quota_callback_t* self); -} cef_quota_callback_t; - - -/// -// Callback structure used for asynchronous continuation of url requests when -// invalid SSL certificates are encountered. -/// -typedef struct _cef_allow_certificate_error_callback_t { +typedef struct _cef_request_callback_t { /// // Base structure. /// @@ -89,9 +66,13 @@ typedef struct _cef_allow_certificate_error_callback_t { // Continue the url request. If |allow| is true (1) the request will be // continued. Otherwise, the request will be canceled. /// - void (CEF_CALLBACK *cont)( - struct _cef_allow_certificate_error_callback_t* self, int allow); -} cef_allow_certificate_error_callback_t; + void (CEF_CALLBACK *cont)(struct _cef_request_callback_t* self, int allow); + + /// + // Cancel the url request. + /// + void (CEF_CALLBACK *cancel)(struct _cef_request_callback_t* self); +} cef_request_callback_t; /// @@ -120,12 +101,16 @@ typedef struct _cef_request_handler_t { /// // Called on the IO thread before a resource request is loaded. The |request| - // object may be modified. To cancel the request return true (1) otherwise - // return false (0). + // object may be modified. Return RV_CONTINUE to continue the request + // immediately. Return RV_CONTINUE_ASYNC and call cef_request_tCallback:: + // cont() at a later time to continue or cancel the request asynchronously. + // Return RV_CANCEL to cancel the request immediately. + // /// - int (CEF_CALLBACK *on_before_resource_load)( + cef_return_value_t (CEF_CALLBACK *on_before_resource_load)( struct _cef_request_handler_t* self, struct _cef_browser_t* browser, - struct _cef_frame_t* frame, struct _cef_request_t* request); + struct _cef_frame_t* frame, struct _cef_request_t* request, + struct _cef_request_callback_t* callback); /// // Called on the IO thread before a resource is loaded. To allow the resource @@ -150,8 +135,9 @@ typedef struct _cef_request_handler_t { // 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. + // the request and call cef_auth_callback_t::cont() either in this function or + // at a later time when the authentication information is available. Return + // false (0) to cancel the request immediately. /// int (CEF_CALLBACK *get_auth_credentials)(struct _cef_request_handler_t* self, struct _cef_browser_t* browser, struct _cef_frame_t* frame, int isProxy, @@ -162,13 +148,14 @@ typedef struct _cef_request_handler_t { // Called on the IO thread when JavaScript requests a specific storage quota // size via the webkitStorageInfo.requestQuota function. |origin_url| is the // origin of the page making the request. |new_size| is the requested quota - // size in bytes. Return true (1) and call cef_quota_callback_t::cont() either - // in this function or at a later time to grant or deny the request. Return - // false (0) to cancel the request. + // size in bytes. Return true (1) to continue the request and call + // cef_request_tCallback::cont() either in this function or at a later time to + // grant or deny the request. Return false (0) to cancel the request + // immediately. /// int (CEF_CALLBACK *on_quota_request)(struct _cef_request_handler_t* self, struct _cef_browser_t* browser, const cef_string_t* origin_url, - int64 new_size, struct _cef_quota_callback_t* callback); + int64 new_size, struct _cef_request_callback_t* callback); /// // Called on the UI thread to handle requests for URLs with an unknown @@ -183,18 +170,17 @@ typedef struct _cef_request_handler_t { /// // Called on the UI thread to handle requests for URLs with an invalid SSL - // certificate. Return true (1) and call - // cef_allow_certificate_error_callback_t:: cont() either in this function or - // at a later time to continue or cancel the request. Return false (0) to - // cancel the request immediately. If |callback| is NULL the error cannot be - // recovered from and the request will be canceled automatically. If - // CefSettings.ignore_certificate_errors is set all invalid certificates will - // be accepted without calling this function. + // certificate. Return true (1) and call cef_request_tCallback::cont() either + // in this function or at a later time to continue or cancel the request. + // Return false (0) to cancel the request immediately. If |callback| is NULL + // the error cannot be recovered from and the request will be canceled + // automatically. If CefSettings.ignore_certificate_errors is set all invalid + // certificates will be accepted without calling this function. /// int (CEF_CALLBACK *on_certificate_error)(struct _cef_request_handler_t* self, struct _cef_browser_t* browser, cef_errorcode_t cert_error, const cef_string_t* request_url, struct _cef_sslinfo_t* ssl_info, - struct _cef_allow_certificate_error_callback_t* callback); + struct _cef_request_callback_t* callback); /// // Called on the browser process IO thread before a plugin is loaded. Return diff --git a/include/cef_request_handler.h b/include/cef_request_handler.h index 12a99c8a8..9ad7249e6 100644 --- a/include/cef_request_handler.h +++ b/include/cef_request_handler.h @@ -48,43 +48,28 @@ #include "include/cef_ssl_info.h" #include "include/cef_web_plugin.h" + /// -// Callback interface used for asynchronous continuation of quota requests. +// Callback interface used for asynchronous continuation of url requests. /// /*--cef(source=library)--*/ -class CefQuotaCallback : public virtual CefBase { +class CefRequestCallback : public virtual CefBase { public: /// - // Continue the quota request. If |allow| is true the request will be - // allowed. Otherwise, the request will be denied. + // Continue the url request. If |allow| is true the request will be continued. + // Otherwise, the request will be canceled. /// /*--cef(capi_name=cont)--*/ virtual void Continue(bool allow) =0; /// - // Cancel the quota request. + // Cancel the url request. /// /*--cef()--*/ virtual void Cancel() =0; }; -/// -// Callback interface used for asynchronous continuation of url requests when -// invalid SSL certificates are encountered. -/// -/*--cef(source=library)--*/ -class CefAllowCertificateErrorCallback : public virtual CefBase { - public: - /// - // Continue the url request. If |allow| is true the request will be - // continued. Otherwise, the request will be canceled. - /// - /*--cef(capi_name=cont)--*/ - virtual void Continue(bool allow) =0; -}; - - /// // Implement this interface to handle events related to browser requests. The // methods of this class will be called on the thread indicated. @@ -92,6 +77,7 @@ class CefAllowCertificateErrorCallback : public virtual CefBase { /*--cef(source=client)--*/ class CefRequestHandler : public virtual CefBase { public: + typedef cef_return_value_t ReturnValue; typedef cef_termination_status_t TerminationStatus; /// @@ -114,14 +100,19 @@ class CefRequestHandler : public virtual CefBase { /// // Called on the IO thread before a resource request is loaded. The |request| - // object may be modified. To cancel the request return true otherwise return - // false. + // object may be modified. Return RV_CONTINUE to continue the request + // immediately. Return RV_CONTINUE_ASYNC and call CefRequestCallback:: + // Continue() at a later time to continue or cancel the request + // asynchronously. Return RV_CANCEL to cancel the request immediately. + // /// - /*--cef()--*/ - virtual bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) { - return false; + /*--cef(default_retval=RV_CONTINUE)--*/ + virtual ReturnValue OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) { + return RV_CONTINUE; } /// @@ -153,8 +144,9 @@ class CefRequestHandler : public virtual CefBase { // 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. + // request and call CefAuthCallback::Continue() either in this method or + // at a later time when the authentication information is available. Return + // false to cancel the request immediately. /// /*--cef(optional_param=realm)--*/ virtual bool GetAuthCredentials(CefRefPtr browser, @@ -172,15 +164,15 @@ class CefRequestHandler : public virtual CefBase { // Called on the IO thread when JavaScript requests a specific storage quota // size via the webkitStorageInfo.requestQuota function. |origin_url| is the // origin of the page making the request. |new_size| is the requested quota - // size in bytes. Return true and call CefQuotaCallback::Continue() either in - // this method or at a later time to grant or deny the request. Return false - // to cancel the request. + // size in bytes. Return true to continue the request and call + // CefRequestCallback::Continue() either in this method or at a later time to + // grant or deny the request. Return false to cancel the request immediately. /// /*--cef()--*/ virtual bool OnQuotaRequest(CefRefPtr browser, const CefString& origin_url, int64 new_size, - CefRefPtr callback) { + CefRefPtr callback) { return false; } @@ -198,12 +190,12 @@ class CefRequestHandler : public virtual CefBase { /// // Called on the UI thread to handle requests for URLs with an invalid - // SSL certificate. Return true and call CefAllowCertificateErrorCallback:: - // Continue() either in this method or at a later time to continue or cancel - // the request. Return false to cancel the request immediately. If |callback| - // is empty the error cannot be recovered from and the request will be - // canceled automatically. If CefSettings.ignore_certificate_errors is set - // all invalid certificates will be accepted without calling this method. + // SSL certificate. Return true and call CefRequestCallback::Continue() either + // in this method or at a later time to continue or cancel the request. Return + // false to cancel the request immediately. If |callback| is empty the error + // cannot be recovered from and the request will be canceled automatically. + // If CefSettings.ignore_certificate_errors is set all invalid certificates + // will be accepted without calling this method. /// /*--cef()--*/ virtual bool OnCertificateError( @@ -211,7 +203,7 @@ class CefRequestHandler : public virtual CefBase { cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr ssl_info, - CefRefPtr callback) { + CefRefPtr callback) { return false; } diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index d16886bff..20cf164f4 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -565,6 +565,26 @@ typedef struct _cef_browser_settings_t { cef_color_t background_color; } cef_browser_settings_t; +/// +// Return value types. +/// +typedef enum { + /// + // Cancel immediately. + /// + RV_CANCEL = 0, + + /// + // Continue immediately. + /// + RV_CONTINUE, + + /// + // Continue asynchronously (usually via a callback). + /// + RV_CONTINUE_ASYNC, +} cef_return_value_t; + /// // URL component parts. /// diff --git a/libcef/browser/content_browser_client.cc b/libcef/browser/content_browser_client.cc index 779df3981..a73698e95 100644 --- a/libcef/browser/content_browser_client.cc +++ b/libcef/browser/content_browser_client.cc @@ -85,7 +85,7 @@ class CefAccessTokenStore : public content::AccessTokenStore { DISALLOW_COPY_AND_ASSIGN(CefAccessTokenStore); }; -class CefQuotaCallbackImpl : public CefQuotaCallback { +class CefQuotaCallbackImpl : public CefRequestCallback { public: explicit CefQuotaCallbackImpl( const content::QuotaPermissionContext::PermissionCallback& callback) @@ -96,10 +96,10 @@ class CefQuotaCallbackImpl : public CefQuotaCallback { if (!callback_.is_null()) { // The callback is still pending. Cancel it now. if (CEF_CURRENTLY_ON_IOT()) { - CancelNow(callback_); + RunNow(callback_, false); } else { CEF_POST_TASK(CEF_IOT, - base::Bind(&CefQuotaCallbackImpl::CancelNow, callback_)); + base::Bind(&CefQuotaCallbackImpl::RunNow, callback_, false)); } } } @@ -107,9 +107,7 @@ class CefQuotaCallbackImpl : public CefQuotaCallback { void Continue(bool allow) override { if (CEF_CURRENTLY_ON_IOT()) { if (!callback_.is_null()) { - callback_.Run(allow ? - content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW : - content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_DISALLOW); + RunNow(callback_, allow); callback_.Reset(); } } else { @@ -119,14 +117,7 @@ class CefQuotaCallbackImpl : public CefQuotaCallback { } void Cancel() override { - if (CEF_CURRENTLY_ON_IOT()) { - if (!callback_.is_null()) { - CancelNow(callback_); - callback_.Reset(); - } - } else { - CEF_POST_TASK(CEF_IOT, base::Bind(&CefQuotaCallbackImpl::Cancel, this)); - } + Continue(false); } void Disconnect() { @@ -134,11 +125,13 @@ class CefQuotaCallbackImpl : public CefQuotaCallback { } private: - static void CancelNow( - const content::QuotaPermissionContext::PermissionCallback& callback) { + static void RunNow( + const content::QuotaPermissionContext::PermissionCallback& callback, + bool allow) { CEF_REQUIRE_IOT(); - callback.Run( - content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_CANCELLED); + callback.Run(allow ? + content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_ALLOW : + content::QuotaPermissionContext::QUOTA_PERMISSION_RESPONSE_DISALLOW); } content::QuotaPermissionContext::PermissionCallback callback_; @@ -147,8 +140,7 @@ class CefQuotaCallbackImpl : public CefQuotaCallback { DISALLOW_COPY_AND_ASSIGN(CefQuotaCallbackImpl); }; -class CefAllowCertificateErrorCallbackImpl - : public CefAllowCertificateErrorCallback { +class CefAllowCertificateErrorCallbackImpl : public CefRequestCallback { public: typedef base::Callback // NOLINT(readability/function) CallbackType; @@ -157,24 +149,46 @@ class CefAllowCertificateErrorCallbackImpl : callback_(callback) { } + ~CefAllowCertificateErrorCallbackImpl() { + if (!callback_.is_null()) { + // The callback is still pending. Cancel it now. + if (CEF_CURRENTLY_ON_UIT()) { + RunNow(callback_, false); + } else { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefAllowCertificateErrorCallbackImpl::RunNow, + callback_, false)); + } + } + } + void Continue(bool allow) override { if (CEF_CURRENTLY_ON_UIT()) { if (!callback_.is_null()) { - callback_.Run(allow); + RunNow(callback_, allow); callback_.Reset(); } } else { CEF_POST_TASK(CEF_UIT, base::Bind(&CefAllowCertificateErrorCallbackImpl::Continue, - this, allow)); + this, allow)); } } + void Cancel() override { + Continue(false); + } + void Disconnect() { callback_.Reset(); } private: + static void RunNow(const CallbackType& callback, bool allow) { + CEF_REQUIRE_IOT(); + callback.Run(allow); + } + CallbackType callback_; IMPLEMENT_REFCOUNTING(CefAllowCertificateErrorCallbackImpl); @@ -211,11 +225,6 @@ class CefGeolocationCallbackImpl : public CefGeolocationCallback { } private: - static void Run(const CallbackType& callback, bool allow) { - CEF_REQUIRE_UIT(); - callback.Run(allow); - } - CallbackType callback_; IMPLEMENT_REFCOUNTING(CefGeolocationCallbackImpl); diff --git a/libcef/browser/url_network_delegate.cc b/libcef/browser/url_network_delegate.cc index df7916a62..b8936a978 100644 --- a/libcef/browser/url_network_delegate.cc +++ b/libcef/browser/url_network_delegate.cc @@ -17,6 +17,132 @@ namespace { +class CefBeforeResourceLoadCallbackImpl : public CefRequestCallback { + public: + typedef net::CompletionCallback CallbackType; + + CefBeforeResourceLoadCallbackImpl( + CefRefPtr cef_request, + GURL* new_url, + net::URLRequest* url_request, + const CallbackType& callback) + : cef_request_(cef_request), + new_url_(new_url), + url_request_(url_request), + callback_(callback) { + DCHECK(new_url); + DCHECK(url_request_); + + // Add an association between the URLRequest and this object. + url_request_->SetUserData(UserDataKey(), new Disconnector(this)); + } + + ~CefBeforeResourceLoadCallbackImpl() { + if (!callback_.is_null()) { + // The callback is still pending. Cancel it now. + if (CEF_CURRENTLY_ON_IOT()) { + RunNow(cef_request_, new_url_, url_request_, callback_, false); + } else { + CEF_POST_TASK(CEF_IOT, + base::Bind(&CefBeforeResourceLoadCallbackImpl::RunNow, + cef_request_, new_url_, url_request_, callback_, false)); + } + } + } + + void Continue(bool allow) override { + // Always continue asynchronously. + CEF_POST_TASK(CEF_IOT, + base::Bind(&CefBeforeResourceLoadCallbackImpl::ContinueNow, + this, allow)); + } + + void Cancel() override { + Continue(false); + } + + void ContinueNow(bool allow) { + CEF_REQUIRE_IOT(); + if (!callback_.is_null()) { + RunNow(cef_request_, new_url_, url_request_, callback_, allow); + Disconnect(); + } + } + + void Disconnect() { + CEF_REQUIRE_IOT(); + cef_request_ = nullptr; + new_url_ = nullptr; + url_request_ = nullptr; + callback_.Reset(); + } + + private: + // Used to disconnect the callback when the associated URLRequest is + // destroyed. + class Disconnector : public base::SupportsUserData::Data { + public: + explicit Disconnector(CefBeforeResourceLoadCallbackImpl* callback) + : callback_(callback) { + } + ~Disconnector() override { + if (callback_) + callback_->Disconnect(); + } + + void Disconnect() { + callback_ = NULL; + } + + private: + CefBeforeResourceLoadCallbackImpl* callback_; + }; + + static void RunNow(CefRefPtr cef_request, + GURL* new_url, + net::URLRequest* request, + const CallbackType& callback, + bool allow) { + CEF_REQUIRE_IOT(); + + if (allow) { + const GURL& old_url = request->url(); + GURL url = GURL(cef_request->GetURL().ToString()); + if (old_url != url) + new_url->Swap(&url); + + cef_request->Get(request); + } + + // Remove the association between the URLRequest and this object. + Disconnector* disconnector = + static_cast(request->GetUserData(UserDataKey())); + DCHECK(disconnector); + disconnector->Disconnect(); + request->RemoveUserData(UserDataKey()); + + callback.Run(allow ? net::OK : net::ERR_ABORTED); + } + + static inline void* UserDataKey() { + return &kLocatorKey; + } + + CefRefPtr cef_request_; + const GURL old_url_; + GURL* new_url_; + net::URLRequest* url_request_; + CallbackType callback_; + + // The user data key. + static int kLocatorKey; + + IMPLEMENT_REFCOUNTING(CefBeforeResourceLoadCallbackImpl); + DISALLOW_COPY_AND_ASSIGN(CefBeforeResourceLoadCallbackImpl); +}; + +int CefBeforeResourceLoadCallbackImpl::kLocatorKey = 0; + class CefAuthCallbackImpl : public CefAuthCallback { public: CefAuthCallbackImpl(const net::NetworkDelegate::AuthCallback& callback, @@ -98,27 +224,32 @@ int CefNetworkDelegate::OnBeforeURLRequest( if (handler.get()) { CefRefPtr frame = browser->GetFrameForRequest(request); - GURL old_url = request->url(); - // Populate the request data. CefRefPtr requestPtr(new CefRequestImpl()); requestPtr->Set(request); - // Give the client an opportunity to cancel the request. - if (handler->OnBeforeResourceLoad(browser.get(), frame, - requestPtr.get())) { - return net::ERR_ABORTED; + CefRefPtr callbackImpl( + new CefBeforeResourceLoadCallbackImpl(requestPtr, new_url, request, + callback)); + + // Give the client an opportunity to evaluate the request. + cef_return_value_t retval = handler->OnBeforeResourceLoad( + browser.get(), frame, requestPtr.get(), callbackImpl.get()); + if (retval == RV_CANCEL) { + // Cancel the request. + callbackImpl->Continue(false); + } else if (retval == RV_CONTINUE) { + // Continue the request. + callbackImpl->Continue(true); } - GURL url = GURL(std::string(requestPtr->GetURL())); - if (old_url != url) - new_url ->Swap(&url); - - requestPtr->Get(request); + // Continue or cancel the request asynchronously. + return net::ERR_IO_PENDING; } } } + // Continue the request immediately. return net::OK; } diff --git a/libcef/browser/url_network_delegate.h b/libcef/browser/url_network_delegate.h index bfb32d210..cbd32b88b 100644 --- a/libcef/browser/url_network_delegate.h +++ b/libcef/browser/url_network_delegate.h @@ -26,7 +26,7 @@ class CefNetworkDelegate : public net::NetworkDelegateImpl { const AuthCallback& callback, net::AuthCredentials* credentials) override; bool OnCanAccessFile(const net::URLRequest& request, - const base::FilePath& path) const; + const base::FilePath& path) const override; DISALLOW_COPY_AND_ASSIGN(CefNetworkDelegate); }; diff --git a/libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.cc b/libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.cc deleted file mode 100644 index a7899c0c3..000000000 --- a/libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. -// -// --------------------------------------------------------------------------- -// -// This file was generated by the CEF translator tool. If making changes by -// hand only do so within the body of existing method and function -// implementations. See the translator.README.txt file in the tools directory -// for more information. -// - -#include "libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.h" - - -// MEMBER FUNCTIONS - Body may be edited by hand. - -void CEF_CALLBACK allow_certificate_error_callback_cont( - struct _cef_allow_certificate_error_callback_t* self, int allow) { - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - DCHECK(self); - if (!self) - return; - - // Execute - CefAllowCertificateErrorCallbackCppToC::Get(self)->Continue( - allow?true:false); -} - - -// CONSTRUCTOR - Do not edit by hand. - -CefAllowCertificateErrorCallbackCppToC::CefAllowCertificateErrorCallbackCppToC( - CefAllowCertificateErrorCallback* cls) - : CefCppToC(cls) { - struct_.struct_.cont = allow_certificate_error_callback_cont; -} - -#ifndef NDEBUG -template<> base::AtomicRefCount CefCppToC::DebugObjCt = 0; -#endif - diff --git a/libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.h b/libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.h deleted file mode 100644 index afb21832a..000000000 --- a/libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. -// -// --------------------------------------------------------------------------- -// -// This file was generated by the CEF translator tool. If making changes by -// hand only do so within the body of existing method and function -// implementations. See the translator.README.txt file in the tools directory -// for more information. -// - -#ifndef CEF_LIBCEF_DLL_CPPTOC_ALLOW_CERTIFICATE_ERROR_CALLBACK_CPPTOC_H_ -#define CEF_LIBCEF_DLL_CPPTOC_ALLOW_CERTIFICATE_ERROR_CALLBACK_CPPTOC_H_ -#pragma once - -#ifndef BUILDING_CEF_SHARED -#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 "libcef_dll/cpptoc/cpptoc.h" - -// Wrap a C++ class with a C structure. -// This class may be instantiated and accessed DLL-side only. -class CefAllowCertificateErrorCallbackCppToC - : public CefCppToC { - public: - explicit CefAllowCertificateErrorCallbackCppToC( - CefAllowCertificateErrorCallback* cls); -}; - -#endif // BUILDING_CEF_SHARED -#endif // CEF_LIBCEF_DLL_CPPTOC_ALLOW_CERTIFICATE_ERROR_CALLBACK_CPPTOC_H_ - diff --git a/libcef_dll/cpptoc/quota_callback_cpptoc.cc b/libcef_dll/cpptoc/request_callback_cpptoc.cc similarity index 56% rename from libcef_dll/cpptoc/quota_callback_cpptoc.cc rename to libcef_dll/cpptoc/request_callback_cpptoc.cc index 21fcd0acf..18828c684 100644 --- a/libcef_dll/cpptoc/quota_callback_cpptoc.cc +++ b/libcef_dll/cpptoc/request_callback_cpptoc.cc @@ -10,12 +10,12 @@ // for more information. // -#include "libcef_dll/cpptoc/quota_callback_cpptoc.h" +#include "libcef_dll/cpptoc/request_callback_cpptoc.h" // MEMBER FUNCTIONS - Body may be edited by hand. -void CEF_CALLBACK quota_callback_cont(struct _cef_quota_callback_t* self, +void CEF_CALLBACK request_callback_cont(struct _cef_request_callback_t* self, int allow) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING @@ -24,11 +24,12 @@ void CEF_CALLBACK quota_callback_cont(struct _cef_quota_callback_t* self, return; // Execute - CefQuotaCallbackCppToC::Get(self)->Continue( + CefRequestCallbackCppToC::Get(self)->Continue( allow?true:false); } -void CEF_CALLBACK quota_callback_cancel(struct _cef_quota_callback_t* self) { +void CEF_CALLBACK request_callback_cancel( + struct _cef_request_callback_t* self) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); @@ -36,21 +37,21 @@ void CEF_CALLBACK quota_callback_cancel(struct _cef_quota_callback_t* self) { return; // Execute - CefQuotaCallbackCppToC::Get(self)->Cancel(); + CefRequestCallbackCppToC::Get(self)->Cancel(); } // CONSTRUCTOR - Do not edit by hand. -CefQuotaCallbackCppToC::CefQuotaCallbackCppToC(CefQuotaCallback* cls) - : CefCppToC( - cls) { - struct_.struct_.cont = quota_callback_cont; - struct_.struct_.cancel = quota_callback_cancel; +CefRequestCallbackCppToC::CefRequestCallbackCppToC(CefRequestCallback* cls) + : CefCppToC(cls) { + struct_.struct_.cont = request_callback_cont; + struct_.struct_.cancel = request_callback_cancel; } #ifndef NDEBUG -template<> base::AtomicRefCount CefCppToC::DebugObjCt = 0; +template<> base::AtomicRefCount CefCppToC::DebugObjCt = 0; #endif diff --git a/libcef_dll/cpptoc/quota_callback_cpptoc.h b/libcef_dll/cpptoc/request_callback_cpptoc.h similarity index 71% rename from libcef_dll/cpptoc/quota_callback_cpptoc.h rename to libcef_dll/cpptoc/request_callback_cpptoc.h index 1d660d268..2303d011b 100644 --- a/libcef_dll/cpptoc/quota_callback_cpptoc.h +++ b/libcef_dll/cpptoc/request_callback_cpptoc.h @@ -10,8 +10,8 @@ // for more information. // -#ifndef CEF_LIBCEF_DLL_CPPTOC_QUOTA_CALLBACK_CPPTOC_H_ -#define CEF_LIBCEF_DLL_CPPTOC_QUOTA_CALLBACK_CPPTOC_H_ +#ifndef CEF_LIBCEF_DLL_CPPTOC_REQUEST_CALLBACK_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_REQUEST_CALLBACK_CPPTOC_H_ #pragma once #ifndef BUILDING_CEF_SHARED @@ -24,13 +24,13 @@ // Wrap a C++ class with a C structure. // This class may be instantiated and accessed DLL-side only. -class CefQuotaCallbackCppToC - : public CefCppToC { +class CefRequestCallbackCppToC + : public CefCppToC { public: - explicit CefQuotaCallbackCppToC(CefQuotaCallback* cls); + explicit CefRequestCallbackCppToC(CefRequestCallback* cls); }; #endif // BUILDING_CEF_SHARED -#endif // CEF_LIBCEF_DLL_CPPTOC_QUOTA_CALLBACK_CPPTOC_H_ +#endif // CEF_LIBCEF_DLL_CPPTOC_REQUEST_CALLBACK_CPPTOC_H_ diff --git a/libcef_dll/cpptoc/request_handler_cpptoc.cc b/libcef_dll/cpptoc/request_handler_cpptoc.cc index 985dbf726..bf8a8049a 100644 --- a/libcef_dll/cpptoc/request_handler_cpptoc.cc +++ b/libcef_dll/cpptoc/request_handler_cpptoc.cc @@ -12,12 +12,11 @@ #include "libcef_dll/cpptoc/request_handler_cpptoc.h" #include "libcef_dll/cpptoc/resource_handler_cpptoc.h" -#include "libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.h" #include "libcef_dll/ctocpp/auth_callback_ctocpp.h" #include "libcef_dll/ctocpp/browser_ctocpp.h" #include "libcef_dll/ctocpp/frame_ctocpp.h" -#include "libcef_dll/ctocpp/quota_callback_ctocpp.h" #include "libcef_dll/ctocpp/request_ctocpp.h" +#include "libcef_dll/ctocpp/request_callback_ctocpp.h" #include "libcef_dll/ctocpp/sslinfo_ctocpp.h" #include "libcef_dll/ctocpp/web_plugin_info_ctocpp.h" @@ -56,34 +55,41 @@ int CEF_CALLBACK request_handler_on_before_browse( return _retval; } -int CEF_CALLBACK request_handler_on_before_resource_load( +cef_return_value_t CEF_CALLBACK request_handler_on_before_resource_load( struct _cef_request_handler_t* self, cef_browser_t* browser, - cef_frame_t* frame, cef_request_t* request) { + cef_frame_t* frame, cef_request_t* request, + cef_request_callback_t* callback) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); if (!self) - return 0; + return RV_CONTINUE; // Verify param: browser; type: refptr_diff DCHECK(browser); if (!browser) - return 0; + return RV_CONTINUE; // Verify param: frame; type: refptr_diff DCHECK(frame); if (!frame) - return 0; + return RV_CONTINUE; // Verify param: request; type: refptr_diff DCHECK(request); if (!request) - return 0; + return RV_CONTINUE; + // Verify param: callback; type: refptr_diff + DCHECK(callback); + if (!callback) + return RV_CONTINUE; // Execute - bool _retval = CefRequestHandlerCppToC::Get(self)->OnBeforeResourceLoad( + cef_return_value_t _retval = CefRequestHandlerCppToC::Get( + self)->OnBeforeResourceLoad( CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), - CefRequestCToCpp::Wrap(request)); + CefRequestCToCpp::Wrap(request), + CefRequestCallbackCToCpp::Wrap(callback)); - // Return type: bool + // Return type: simple return _retval; } @@ -205,7 +211,7 @@ int CEF_CALLBACK request_handler_get_auth_credentials( int CEF_CALLBACK request_handler_on_quota_request( struct _cef_request_handler_t* self, cef_browser_t* browser, const cef_string_t* origin_url, int64 new_size, - cef_quota_callback_t* callback) { + cef_request_callback_t* callback) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); @@ -229,7 +235,7 @@ int CEF_CALLBACK request_handler_on_quota_request( CefBrowserCToCpp::Wrap(browser), CefString(origin_url), new_size, - CefQuotaCallbackCToCpp::Wrap(callback)); + CefRequestCallbackCToCpp::Wrap(callback)); // Return type: bool return _retval; @@ -274,8 +280,7 @@ void CEF_CALLBACK request_handler_on_protocol_execution( int CEF_CALLBACK request_handler_on_certificate_error( struct _cef_request_handler_t* self, cef_browser_t* browser, cef_errorcode_t cert_error, const cef_string_t* request_url, - struct _cef_sslinfo_t* ssl_info, - cef_allow_certificate_error_callback_t* callback) { + struct _cef_sslinfo_t* ssl_info, cef_request_callback_t* callback) { // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING DCHECK(self); @@ -304,7 +309,7 @@ int CEF_CALLBACK request_handler_on_certificate_error( cert_error, CefString(request_url), CefSSLInfoCToCpp::Wrap(ssl_info), - CefAllowCertificateErrorCallbackCToCpp::Wrap(callback)); + CefRequestCallbackCToCpp::Wrap(callback)); // Return type: bool return _retval; diff --git a/libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.cc b/libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.cc deleted file mode 100644 index 9cf77f041..000000000 --- a/libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. -// -// --------------------------------------------------------------------------- -// -// This file was generated by the CEF translator tool. If making changes by -// hand only do so within the body of existing method and function -// implementations. See the translator.README.txt file in the tools directory -// for more information. -// - -#include "libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.h" - - -// VIRTUAL METHODS - Body may be edited by hand. - -void CefAllowCertificateErrorCallbackCToCpp::Continue(bool allow) { - if (CEF_MEMBER_MISSING(struct_, cont)) - return; - - // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING - - // Execute - struct_->cont(struct_, - allow); -} - - -#ifndef NDEBUG -template<> base::AtomicRefCount CefCToCpp::DebugObjCt = 0; -#endif - diff --git a/libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.h b/libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.h deleted file mode 100644 index 17f1c2357..000000000 --- a/libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights -// reserved. Use of this source code is governed by a BSD-style license that -// can be found in the LICENSE file. -// -// --------------------------------------------------------------------------- -// -// This file was generated by the CEF translator tool. If making changes by -// hand only do so within the body of existing method and function -// implementations. See the translator.README.txt file in the tools directory -// for more information. -// - -#ifndef CEF_LIBCEF_DLL_CTOCPP_ALLOW_CERTIFICATE_ERROR_CALLBACK_CTOCPP_H_ -#define CEF_LIBCEF_DLL_CTOCPP_ALLOW_CERTIFICATE_ERROR_CALLBACK_CTOCPP_H_ -#pragma once - -#ifndef USING_CEF_SHARED -#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 "libcef_dll/ctocpp/ctocpp.h" - -// Wrap a C structure with a C++ class. -// This class may be instantiated and accessed wrapper-side only. -class CefAllowCertificateErrorCallbackCToCpp - : public CefCToCpp { - public: - explicit CefAllowCertificateErrorCallbackCToCpp( - cef_allow_certificate_error_callback_t* str) - : CefCToCpp(str) {} - - // CefAllowCertificateErrorCallback methods - virtual void Continue(bool allow) OVERRIDE; -}; - -#endif // USING_CEF_SHARED -#endif // CEF_LIBCEF_DLL_CTOCPP_ALLOW_CERTIFICATE_ERROR_CALLBACK_CTOCPP_H_ - diff --git a/libcef_dll/ctocpp/quota_callback_ctocpp.cc b/libcef_dll/ctocpp/request_callback_ctocpp.cc similarity index 76% rename from libcef_dll/ctocpp/quota_callback_ctocpp.cc rename to libcef_dll/ctocpp/request_callback_ctocpp.cc index 51fa06161..94319de6b 100644 --- a/libcef_dll/ctocpp/quota_callback_ctocpp.cc +++ b/libcef_dll/ctocpp/request_callback_ctocpp.cc @@ -10,12 +10,12 @@ // for more information. // -#include "libcef_dll/ctocpp/quota_callback_ctocpp.h" +#include "libcef_dll/ctocpp/request_callback_ctocpp.h" // VIRTUAL METHODS - Body may be edited by hand. -void CefQuotaCallbackCToCpp::Continue(bool allow) { +void CefRequestCallbackCToCpp::Continue(bool allow) { if (CEF_MEMBER_MISSING(struct_, cont)) return; @@ -26,7 +26,7 @@ void CefQuotaCallbackCToCpp::Continue(bool allow) { allow); } -void CefQuotaCallbackCToCpp::Cancel() { +void CefRequestCallbackCToCpp::Cancel() { if (CEF_MEMBER_MISSING(struct_, cancel)) return; @@ -38,7 +38,7 @@ void CefQuotaCallbackCToCpp::Cancel() { #ifndef NDEBUG -template<> base::AtomicRefCount CefCToCpp::DebugObjCt = 0; +template<> base::AtomicRefCount CefCToCpp::DebugObjCt = 0; #endif diff --git a/libcef_dll/ctocpp/quota_callback_ctocpp.h b/libcef_dll/ctocpp/request_callback_ctocpp.h similarity index 66% rename from libcef_dll/ctocpp/quota_callback_ctocpp.h rename to libcef_dll/ctocpp/request_callback_ctocpp.h index 80cf63004..b5876ecb6 100644 --- a/libcef_dll/ctocpp/quota_callback_ctocpp.h +++ b/libcef_dll/ctocpp/request_callback_ctocpp.h @@ -10,8 +10,8 @@ // for more information. // -#ifndef CEF_LIBCEF_DLL_CTOCPP_QUOTA_CALLBACK_CTOCPP_H_ -#define CEF_LIBCEF_DLL_CTOCPP_QUOTA_CALLBACK_CTOCPP_H_ +#ifndef CEF_LIBCEF_DLL_CTOCPP_REQUEST_CALLBACK_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_REQUEST_CALLBACK_CTOCPP_H_ #pragma once #ifndef USING_CEF_SHARED @@ -24,19 +24,19 @@ // Wrap a C structure with a C++ class. // This class may be instantiated and accessed wrapper-side only. -class CefQuotaCallbackCToCpp - : public CefCToCpp { +class CefRequestCallbackCToCpp + : public CefCToCpp { public: - explicit CefQuotaCallbackCToCpp(cef_quota_callback_t* str) - : CefCToCpp(str) {} + explicit CefRequestCallbackCToCpp(cef_request_callback_t* str) + : CefCToCpp(str) {} - // CefQuotaCallback methods + // CefRequestCallback methods virtual void Continue(bool allow) OVERRIDE; virtual void Cancel() OVERRIDE; }; #endif // USING_CEF_SHARED -#endif // CEF_LIBCEF_DLL_CTOCPP_QUOTA_CALLBACK_CTOCPP_H_ +#endif // CEF_LIBCEF_DLL_CTOCPP_REQUEST_CALLBACK_CTOCPP_H_ diff --git a/libcef_dll/ctocpp/request_handler_ctocpp.cc b/libcef_dll/ctocpp/request_handler_ctocpp.cc index f3475da36..b187e29b9 100644 --- a/libcef_dll/ctocpp/request_handler_ctocpp.cc +++ b/libcef_dll/ctocpp/request_handler_ctocpp.cc @@ -10,12 +10,11 @@ // for more information. // -#include "libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.h" #include "libcef_dll/cpptoc/auth_callback_cpptoc.h" #include "libcef_dll/cpptoc/browser_cpptoc.h" #include "libcef_dll/cpptoc/frame_cpptoc.h" -#include "libcef_dll/cpptoc/quota_callback_cpptoc.h" #include "libcef_dll/cpptoc/request_cpptoc.h" +#include "libcef_dll/cpptoc/request_callback_cpptoc.h" #include "libcef_dll/cpptoc/sslinfo_cpptoc.h" #include "libcef_dll/cpptoc/web_plugin_info_cpptoc.h" #include "libcef_dll/ctocpp/request_handler_ctocpp.h" @@ -56,35 +55,40 @@ bool CefRequestHandlerCToCpp::OnBeforeBrowse(CefRefPtr browser, return _retval?true:false; } -bool CefRequestHandlerCToCpp::OnBeforeResourceLoad( +CefRequestHandler::ReturnValue CefRequestHandlerCToCpp::OnBeforeResourceLoad( CefRefPtr browser, CefRefPtr frame, - CefRefPtr request) { + CefRefPtr request, CefRefPtr callback) { if (CEF_MEMBER_MISSING(struct_, on_before_resource_load)) - return false; + return RV_CONTINUE; // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // Verify param: browser; type: refptr_diff DCHECK(browser.get()); if (!browser.get()) - return false; + return RV_CONTINUE; // Verify param: frame; type: refptr_diff DCHECK(frame.get()); if (!frame.get()) - return false; + return RV_CONTINUE; // Verify param: request; type: refptr_diff DCHECK(request.get()); if (!request.get()) - return false; + return RV_CONTINUE; + // Verify param: callback; type: refptr_diff + DCHECK(callback.get()); + if (!callback.get()) + return RV_CONTINUE; // Execute - int _retval = struct_->on_before_resource_load(struct_, + cef_return_value_t _retval = struct_->on_before_resource_load(struct_, CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame), - CefRequestCppToC::Wrap(request)); + CefRequestCppToC::Wrap(request), + CefRequestCallbackCppToC::Wrap(callback)); - // Return type: bool - return _retval?true:false; + // Return type: simple + return _retval; } CefRefPtr CefRequestHandlerCToCpp::GetResourceHandler( @@ -194,7 +198,7 @@ bool CefRequestHandlerCToCpp::GetAuthCredentials(CefRefPtr browser, bool CefRequestHandlerCToCpp::OnQuotaRequest(CefRefPtr browser, const CefString& origin_url, int64 new_size, - CefRefPtr callback) { + CefRefPtr callback) { if (CEF_MEMBER_MISSING(struct_, on_quota_request)) return false; @@ -218,7 +222,7 @@ bool CefRequestHandlerCToCpp::OnQuotaRequest(CefRefPtr browser, CefBrowserCppToC::Wrap(browser), origin_url.GetStruct(), new_size, - CefQuotaCallbackCppToC::Wrap(callback)); + CefRequestCallbackCppToC::Wrap(callback)); // Return type: bool return _retval?true:false; @@ -255,8 +259,7 @@ void CefRequestHandlerCToCpp::OnProtocolExecution(CefRefPtr browser, bool CefRequestHandlerCToCpp::OnCertificateError(CefRefPtr browser, cef_errorcode_t cert_error, const CefString& request_url, - CefRefPtr ssl_info, - CefRefPtr callback) { + CefRefPtr ssl_info, CefRefPtr callback) { if (CEF_MEMBER_MISSING(struct_, on_certificate_error)) return false; @@ -285,7 +288,7 @@ bool CefRequestHandlerCToCpp::OnCertificateError(CefRefPtr browser, cert_error, request_url.GetStruct(), CefSSLInfoCppToC::Wrap(ssl_info), - CefAllowCertificateErrorCallbackCppToC::Wrap(callback)); + CefRequestCallbackCppToC::Wrap(callback)); // Return type: bool return _retval?true:false; diff --git a/libcef_dll/ctocpp/request_handler_ctocpp.h b/libcef_dll/ctocpp/request_handler_ctocpp.h index 50b0f7a58..61a824f6b 100644 --- a/libcef_dll/ctocpp/request_handler_ctocpp.h +++ b/libcef_dll/ctocpp/request_handler_ctocpp.h @@ -35,8 +35,9 @@ class CefRequestHandlerCToCpp // CefRequestHandler methods bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, bool is_redirect) override; - bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, CefRefPtr request) override; + ReturnValue OnBeforeResourceLoad(CefRefPtr browser, + CefRefPtr frame, CefRefPtr request, + CefRefPtr callback) override; CefRefPtr GetResourceHandler( CefRefPtr browser, CefRefPtr frame, CefRefPtr request) override; @@ -49,13 +50,13 @@ class CefRequestHandlerCToCpp CefRefPtr callback) override; bool OnQuotaRequest(CefRefPtr browser, const CefString& origin_url, int64 new_size, - CefRefPtr callback) override; + CefRefPtr callback) override; void OnProtocolExecution(CefRefPtr browser, const CefString& url, bool& allow_os_execution) override; bool OnCertificateError(CefRefPtr browser, cef_errorcode_t cert_error, const CefString& request_url, CefRefPtr ssl_info, - CefRefPtr callback) override; + CefRefPtr callback) override; bool OnBeforePluginLoad(CefRefPtr browser, const CefString& url, const CefString& policy_url, CefRefPtr info) override; void OnPluginCrashed(CefRefPtr browser, diff --git a/libcef_dll/libcef_dll.cc b/libcef_dll/libcef_dll.cc index 10a906711..e128f6ed6 100644 --- a/libcef_dll/libcef_dll.cc +++ b/libcef_dll/libcef_dll.cc @@ -32,7 +32,6 @@ #include "include/capi/cef_v8_capi.h" #include "include/cef_web_plugin.h" #include "include/capi/cef_web_plugin_capi.h" -#include "libcef_dll/cpptoc/allow_certificate_error_callback_cpptoc.h" #include "libcef_dll/cpptoc/auth_callback_cpptoc.h" #include "libcef_dll/cpptoc/before_download_callback_cpptoc.h" #include "libcef_dll/cpptoc/binary_value_cpptoc.h" @@ -58,7 +57,7 @@ #include "libcef_dll/cpptoc/print_job_callback_cpptoc.h" #include "libcef_dll/cpptoc/print_settings_cpptoc.h" #include "libcef_dll/cpptoc/process_message_cpptoc.h" -#include "libcef_dll/cpptoc/quota_callback_cpptoc.h" +#include "libcef_dll/cpptoc/request_callback_cpptoc.h" #include "libcef_dll/cpptoc/sslcert_principal_cpptoc.h" #include "libcef_dll/cpptoc/sslinfo_cpptoc.h" #include "libcef_dll/cpptoc/scheme_registrar_cpptoc.h" @@ -184,8 +183,6 @@ CEF_EXPORT void cef_shutdown() { #ifndef NDEBUG // Check that all wrapper objects have been destroyed - DCHECK(base::AtomicRefCountIsZero( - &CefAllowCertificateErrorCallbackCppToC::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefAuthCallbackCppToC::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero( &CefBeforeDownloadCallbackCppToC::DebugObjCt)); @@ -235,11 +232,11 @@ CEF_EXPORT void cef_shutdown() { DCHECK(base::AtomicRefCountIsZero(&CefPrintJobCallbackCppToC::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefPrintSettingsCppToC::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefProcessMessageCppToC::DebugObjCt)); - DCHECK(base::AtomicRefCountIsZero(&CefQuotaCallbackCppToC::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefReadHandlerCToCpp::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefRenderHandlerCToCpp::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero( &CefRenderProcessHandlerCToCpp::DebugObjCt)); + DCHECK(base::AtomicRefCountIsZero(&CefRequestCallbackCppToC::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefRequestHandlerCToCpp::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero( &CefResourceBundleHandlerCToCpp::DebugObjCt)); diff --git a/libcef_dll/wrapper/libcef_dll_wrapper.cc b/libcef_dll/wrapper/libcef_dll_wrapper.cc index ddfcb4262..362ab7493 100644 --- a/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -70,7 +70,6 @@ #include "libcef_dll/cpptoc/web_plugin_info_visitor_cpptoc.h" #include "libcef_dll/cpptoc/web_plugin_unstable_callback_cpptoc.h" #include "libcef_dll/cpptoc/write_handler_cpptoc.h" -#include "libcef_dll/ctocpp/allow_certificate_error_callback_ctocpp.h" #include "libcef_dll/ctocpp/auth_callback_ctocpp.h" #include "libcef_dll/ctocpp/before_download_callback_ctocpp.h" #include "libcef_dll/ctocpp/binary_value_ctocpp.h" @@ -96,7 +95,7 @@ #include "libcef_dll/ctocpp/print_job_callback_ctocpp.h" #include "libcef_dll/ctocpp/print_settings_ctocpp.h" #include "libcef_dll/ctocpp/process_message_ctocpp.h" -#include "libcef_dll/ctocpp/quota_callback_ctocpp.h" +#include "libcef_dll/ctocpp/request_callback_ctocpp.h" #include "libcef_dll/ctocpp/sslcert_principal_ctocpp.h" #include "libcef_dll/ctocpp/sslinfo_ctocpp.h" #include "libcef_dll/ctocpp/scheme_registrar_ctocpp.h" @@ -176,8 +175,6 @@ CEF_GLOBAL void CefShutdown() { #ifndef NDEBUG // Check that all wrapper objects have been destroyed - DCHECK(base::AtomicRefCountIsZero( - &CefAllowCertificateErrorCallbackCToCpp::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefAuthCallbackCToCpp::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero( &CefBeforeDownloadCallbackCToCpp::DebugObjCt)); @@ -227,11 +224,11 @@ CEF_GLOBAL void CefShutdown() { DCHECK(base::AtomicRefCountIsZero(&CefPrintJobCallbackCToCpp::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefPrintSettingsCToCpp::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefProcessMessageCToCpp::DebugObjCt)); - DCHECK(base::AtomicRefCountIsZero(&CefQuotaCallbackCToCpp::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefReadHandlerCppToC::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefRenderHandlerCppToC::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero( &CefRenderProcessHandlerCppToC::DebugObjCt)); + DCHECK(base::AtomicRefCountIsZero(&CefRequestCallbackCToCpp::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero(&CefRequestHandlerCppToC::DebugObjCt)); DCHECK(base::AtomicRefCountIsZero( &CefResourceBundleHandlerCppToC::DebugObjCt)); diff --git a/tests/cefclient/client_handler.cc b/tests/cefclient/client_handler.cc index 0dacba299..66203fd6e 100644 --- a/tests/cefclient/client_handler.cc +++ b/tests/cefclient/client_handler.cc @@ -542,7 +542,7 @@ CefRefPtr ClientHandler::GetResourceHandler( bool ClientHandler::OnQuotaRequest(CefRefPtr browser, const CefString& origin_url, int64 new_size, - CefRefPtr callback) { + CefRefPtr callback) { CEF_REQUIRE_IO_THREAD(); static const int64 max_size = 1024 * 1024 * 20; // 20mb. @@ -569,7 +569,7 @@ bool ClientHandler::OnCertificateError( ErrorCode cert_error, const CefString& request_url, CefRefPtr ssl_info, - CefRefPtr callback) { + CefRefPtr callback) { CEF_REQUIRE_UI_THREAD(); CefRefPtr subject = ssl_info->GetSubject(); diff --git a/tests/cefclient/client_handler.h b/tests/cefclient/client_handler.h index 53031e256..c73adb372 100644 --- a/tests/cefclient/client_handler.h +++ b/tests/cefclient/client_handler.h @@ -183,7 +183,7 @@ class ClientHandler : public CefClient, bool OnQuotaRequest(CefRefPtr browser, const CefString& origin_url, int64 new_size, - CefRefPtr callback) OVERRIDE; + CefRefPtr callback) OVERRIDE; void OnProtocolExecution(CefRefPtr browser, const CefString& url, bool& allow_os_execution) OVERRIDE; @@ -192,7 +192,7 @@ class ClientHandler : public CefClient, ErrorCode cert_error, const CefString& request_url, CefRefPtr ssl_info, - CefRefPtr callback) OVERRIDE; + CefRefPtr callback) OVERRIDE; void OnRenderProcessTerminated(CefRefPtr browser, TerminationStatus status) OVERRIDE; diff --git a/tests/unittests/navigation_unittest.cc b/tests/unittests/navigation_unittest.cc index 3d21f8c0d..37481e08a 100644 --- a/tests/unittests/navigation_unittest.cc +++ b/tests/unittests/navigation_unittest.cc @@ -443,9 +443,11 @@ class HistoryNavTestHandler : public TestHandler { return false; } - bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { + cef_return_value_t OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override { const NavListItem& item = kHNavList[nav_]; EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType()); @@ -460,7 +462,7 @@ class HistoryNavTestHandler : public TestHandler { if (url == item.target) got_correct_target_[nav_].yes(); - return false; + return RV_CONTINUE; } void OnLoadingStateChange(CefRefPtr browser, @@ -736,9 +738,11 @@ class RedirectTestHandler : public TestHandler { SetTestTimeout(); } - bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { + cef_return_value_t OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override { // Should be called for all but the second URL. std::string url = request->GetURL(); @@ -755,7 +759,7 @@ class RedirectTestHandler : public TestHandler { got_invalid_before_resource_load_.yes(); } - return false; + return RV_CONTINUE; } void OnResourceRedirect(CefRefPtr browser, @@ -1302,9 +1306,11 @@ class OrderNavTestHandler : public TestHandler { return false; } - bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { + cef_return_value_t OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override { EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType()); if (browser->IsPopup()) { @@ -1317,7 +1323,7 @@ class OrderNavTestHandler : public TestHandler { EXPECT_EQ(browser_id_main_, browser->GetIdentifier()); } - return false; + return RV_CONTINUE; } void OnLoadingStateChange(CefRefPtr browser, @@ -1687,16 +1693,18 @@ class CrossOriginNavTestHandler : public TestHandler { return false; } - bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { + cef_return_value_t OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override { EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType()); EXPECT_EQ(TT_EXPLICIT, request->GetTransitionType()); EXPECT_GT(browser_id_current_, 0); EXPECT_EQ(browser_id_current_, browser->GetIdentifier()); - return false; + return RV_CONTINUE; } void OnLoadStart(CefRefPtr browser, diff --git a/tests/unittests/request_handler_unittest.cc b/tests/unittests/request_handler_unittest.cc index 37c97e147..78f8e655e 100644 --- a/tests/unittests/request_handler_unittest.cc +++ b/tests/unittests/request_handler_unittest.cc @@ -130,9 +130,11 @@ class NetNotifyTestHandler : public TestHandler { SetTestTimeout(); } - bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { + cef_return_value_t OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override { EXPECT_TRUE(CefCurrentlyOn(TID_IO)); const std::string& url = request->GetURL(); @@ -143,7 +145,7 @@ class NetNotifyTestHandler : public TestHandler { else EXPECT_TRUE(false); // Not reached - return false; + return RV_CONTINUE; } CefRefPtr GetResourceHandler( @@ -503,6 +505,174 @@ TEST(RequestHandlerTest, NotificationsCrossOriginDelayedBrowser) { } +namespace { + +const char kResourceTestHtml[] = "http://test.com/resource.html"; +const char kResourceTestHtml2[] = "http://test.com/resource2.html"; + +class BeforeResourceLoadTest : public TestHandler { + public: + enum TestMode { + CANCEL, + CANCEL_ASYNC, + CANCEL_NAV, + CONTINUE, + CONTINUE_ASYNC, + }; + + explicit BeforeResourceLoadTest(TestMode mode) + : test_mode_(mode) { + } + + void RunTest() override { + AddResource(kResourceTestHtml, "Test", + "text/html"); + AddResource(kResourceTestHtml2, "Test2", + "text/html"); + CreateBrowser(kResourceTestHtml); + SetTestTimeout(); + } + + cef_return_value_t OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override { + EXPECT_IO_THREAD(); + + // Allow the 2nd navigation to continue. + const std::string& url = request->GetURL(); + if (url == kResourceTestHtml2) { + got_before_resource_load2_.yes(); + EXPECT_EQ(CANCEL_NAV, test_mode_); + return RV_CONTINUE; + } + + EXPECT_FALSE(got_before_resource_load_); + got_before_resource_load_.yes(); + + if (test_mode_ == CANCEL) { + // Cancel immediately. + return RV_CANCEL; + } else if (test_mode_ == CONTINUE) { + // Continue immediately. + return RV_CONTINUE; + } else { + if (test_mode_ == CANCEL_NAV) { + // Cancel the request by navigating to a new URL. + browser->GetMainFrame()->LoadURL(kResourceTestHtml2); + } else { + // Continue or cancel asynchronously. + CefPostTask(TID_UI, + base::Bind(&CefRequestCallback::Continue, callback.get(), + test_mode_ == CONTINUE_ASYNC)); + } + return RV_CONTINUE_ASYNC; + } + } + + void OnLoadEnd(CefRefPtr browser, + CefRefPtr frame, + int httpStatusCode) override { + EXPECT_UI_THREAD(); + + EXPECT_FALSE(got_load_end_); + got_load_end_.yes(); + + const std::string& url = frame->GetURL(); + if (test_mode_ == CANCEL_NAV) + EXPECT_STREQ(kResourceTestHtml2, url.data()); + else + EXPECT_STREQ(kResourceTestHtml, url.data()); + + TestHandler::OnLoadEnd(browser, frame, httpStatusCode); + DestroyTest(); + } + + void OnLoadError(CefRefPtr browser, + CefRefPtr frame, + ErrorCode errorCode, + const CefString& errorText, + const CefString& failedUrl) override { + EXPECT_UI_THREAD(); + + EXPECT_FALSE(got_load_error_); + got_load_error_.yes(); + + const std::string& url = failedUrl; + EXPECT_STREQ(kResourceTestHtml, url.data()); + + TestHandler::OnLoadError(browser, frame, errorCode, errorText, failedUrl); + if (test_mode_ != CANCEL_NAV) + DestroyTest(); + } + + void DestroyTest() override { + EXPECT_TRUE(got_before_resource_load_); + + if (test_mode_ == CANCEL_NAV) + EXPECT_TRUE(got_before_resource_load2_); + else + EXPECT_FALSE(got_before_resource_load2_); + + if (test_mode_ == CONTINUE || test_mode_ == CONTINUE_ASYNC) { + EXPECT_TRUE(got_load_end_); + EXPECT_FALSE(got_load_error_); + } else if (test_mode_ == CANCEL || test_mode_ == CANCEL_ASYNC) { + EXPECT_FALSE(got_load_end_); + EXPECT_TRUE(got_load_error_); + } + + TestHandler::DestroyTest(); + } + + private: + const TestMode test_mode_; + + TrackCallback got_before_resource_load_; + TrackCallback got_before_resource_load2_; + TrackCallback got_load_end_; + TrackCallback got_load_error_; +}; + +} // namespace + +TEST(RequestHandlerTest, BeforeResourceLoadCancel) { + CefRefPtr handler = + new BeforeResourceLoadTest(BeforeResourceLoadTest::CANCEL); + handler->ExecuteTest(); + ReleaseAndWaitForDestructor(handler); +} + +TEST(RequestHandlerTest, BeforeResourceLoadCancelAsync) { + CefRefPtr handler = + new BeforeResourceLoadTest(BeforeResourceLoadTest::CANCEL_ASYNC); + handler->ExecuteTest(); + ReleaseAndWaitForDestructor(handler); +} + +TEST(RequestHandlerTest, BeforeResourceLoadCancelNav) { + CefRefPtr handler = + new BeforeResourceLoadTest(BeforeResourceLoadTest::CANCEL_NAV); + handler->ExecuteTest(); + ReleaseAndWaitForDestructor(handler); +} + +TEST(RequestHandlerTest, BeforeResourceLoadContinue) { + CefRefPtr handler = + new BeforeResourceLoadTest(BeforeResourceLoadTest::CONTINUE); + handler->ExecuteTest(); + ReleaseAndWaitForDestructor(handler); +} + +TEST(RequestHandlerTest, BeforeResourceLoadContinueAsync) { + CefRefPtr handler = + new BeforeResourceLoadTest(BeforeResourceLoadTest::CONTINUE_ASYNC); + handler->ExecuteTest(); + ReleaseAndWaitForDestructor(handler); +} + + // Entry point for creating request handler browser test objects. // Called from client_app_delegates.cc. void CreateRequestHandlerBrowserTests( diff --git a/tests/unittests/request_unittest.cc b/tests/unittests/request_unittest.cc index 2755bc1ac..78cf75c14 100644 --- a/tests/unittests/request_unittest.cc +++ b/tests/unittests/request_unittest.cc @@ -160,9 +160,11 @@ class RequestSendRecvTestHandler : public TestHandler { browser->GetMainFrame()->LoadRequest(request_); } - bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { + cef_return_value_t OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override { // Verify that the request is the same TestRequestEqual(request_, request, true); EXPECT_EQ(RT_MAIN_FRAME, request->GetResourceType()); @@ -170,7 +172,7 @@ class RequestSendRecvTestHandler : public TestHandler { got_before_resource_load_.yes(); - return false; + return RV_CONTINUE; } CefRefPtr GetResourceHandler( @@ -454,12 +456,14 @@ class TypeTestHandler : public TestHandler { return false; } - bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { + cef_return_value_t OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override { load_expectations_.GotRequest(request); - return false; + return RV_CONTINUE; } CefRefPtr GetResourceHandler( diff --git a/tests/unittests/scheme_handler_unittest.cc b/tests/unittests/scheme_handler_unittest.cc index 800708f83..33aa51911 100644 --- a/tests/unittests/scheme_handler_unittest.cc +++ b/tests/unittests/scheme_handler_unittest.cc @@ -100,9 +100,11 @@ class TestSchemeHandler : public TestHandler { TestHandler::DestroyTest(); } - bool OnBeforeResourceLoad(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request) override { + cef_return_value_t OnBeforeResourceLoad( + CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + CefRefPtr callback) override { std::string newUrl = request->GetURL(); if (!test_results_->exit_url.empty() && newUrl.find(test_results_->exit_url) != std::string::npos) { @@ -110,7 +112,7 @@ class TestSchemeHandler : public TestHandler { if (newUrl.find("SUCCESS") != std::string::npos) test_results_->got_sub_success.yes(); DestroyTest(); - return true; + return RV_CANCEL; } if (!test_results_->sub_redirect_url.empty() && @@ -130,7 +132,7 @@ class TestSchemeHandler : public TestHandler { test_results_->redirect_url.clear(); } - return false; + return RV_CONTINUE; } void OnLoadEnd(CefRefPtr browser,