Move cookie load/save callbacks to CefCookieAccessFilter (see issue #2622).

This change allows the NetworkService to handle cookie load/save in cases where
cookies will not be filtered (CefResourceRequestHandler::GetCookieAccessFilter
returns null) and the request will be handled by the default network loader.
This represents a minor performance improvement by reducing the volume of cross-
process messaging in the default (no filtering or custom handing) case. Cookie
load/save still needs to be routed through the browser process if a filter is
returned, or if a CefResourceHandler is used for the request.

To test: Test expectations are unchanged.
This commit is contained in:
Marshall Greenblatt 2019-04-26 13:02:47 -04:00
parent edd9efd1b3
commit 2ace33f8b7
16 changed files with 750 additions and 337 deletions

View File

@ -8,7 +8,7 @@
# by hand. See the translator.README.txt file in the tools directory for
# more information.
#
# $hash=ce19444fe9b2ed5ae2a614f3d00ca3262d75ca98$
# $hash=a8e80ae73a0d30776c2e6aaceaf9dbd4031f6c74$
#
{
@ -242,6 +242,8 @@
'libcef_dll/ctocpp/context_menu_handler_ctocpp.h',
'libcef_dll/cpptoc/context_menu_params_cpptoc.cc',
'libcef_dll/cpptoc/context_menu_params_cpptoc.h',
'libcef_dll/ctocpp/cookie_access_filter_ctocpp.cc',
'libcef_dll/ctocpp/cookie_access_filter_ctocpp.h',
'libcef_dll/cpptoc/cookie_manager_cpptoc.cc',
'libcef_dll/cpptoc/cookie_manager_cpptoc.h',
'libcef_dll/ctocpp/cookie_visitor_ctocpp.cc',
@ -532,6 +534,8 @@
'libcef_dll/cpptoc/context_menu_handler_cpptoc.h',
'libcef_dll/ctocpp/context_menu_params_ctocpp.cc',
'libcef_dll/ctocpp/context_menu_params_ctocpp.h',
'libcef_dll/cpptoc/cookie_access_filter_cpptoc.cc',
'libcef_dll/cpptoc/cookie_access_filter_cpptoc.h',
'libcef_dll/ctocpp/cookie_manager_ctocpp.cc',
'libcef_dll/ctocpp/cookie_manager_ctocpp.h',
'libcef_dll/cpptoc/cookie_visitor_cpptoc.cc',

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=af361d45eb9009a2cbca2024d2ede6d43d8d440f$
// $hash=07e185ca89ea4b4db129a5d3650a55311e582fc4$
//
#ifndef CEF_INCLUDE_CAPI_CEF_RESOURCE_REQUEST_HANDLER_CAPI_H_
@ -54,6 +54,8 @@
extern "C" {
#endif
struct _cef_cookie_access_filter_t;
///
// Implement this structure to handle events related to browser requests. The
// functions of this structure will be called on the IO thread unless otherwise
@ -65,6 +67,19 @@ typedef struct _cef_resource_request_handler_t {
///
cef_base_ref_counted_t base;
///
// Called on the IO thread before a resource request is loaded. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. To optionally filter cookies for
// the request return a cef_cookie_access_filter_t object. The |request|
// object cannot not be modified in this callback.
///
struct _cef_cookie_access_filter_t*(CEF_CALLBACK* get_cookie_access_filter)(
struct _cef_resource_request_handler_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_request_t* request);
///
// Called on the IO thread before a resource request is loaded. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
@ -89,7 +104,7 @@ typedef struct _cef_resource_request_handler_t {
// requests originating from service workers. To allow the resource to load
// using the default network loader return NULL. To specify a handler for the
// resource return a cef_resource_handler_t object. The |request| object
// should not be modified in this callback.
// cannot not be modified in this callback.
///
struct _cef_resource_handler_t*(CEF_CALLBACK* get_resource_handler)(
struct _cef_resource_request_handler_t* self,
@ -167,7 +182,7 @@ typedef struct _cef_resource_request_handler_t {
///
// Called on the IO thread to handle requests for URLs with an unknown
// protocol component. The |browser| and |frame| values represent the source
// protocol component. The |browser| and |frame| values represent the source
// of the request, and may be NULL for requests originating from service
// workers. |request| cannot be modified in this callback. Set
// |allow_os_execution| to true (1) to attempt execution via the registered OS
@ -181,33 +196,47 @@ typedef struct _cef_resource_request_handler_t {
struct _cef_frame_t* frame,
struct _cef_request_t* request,
int* allow_os_execution);
///
// Called on the IO thread before a resource request is sent. Return true (1)
// if the specified cookie can be sent with the request or false (0)
// otherwise.
///
int(CEF_CALLBACK* can_send_cookie)(
struct _cef_resource_request_handler_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_request_t* request,
const struct _cef_cookie_t* cookie);
///
// Called on the IO thread after a resource response is received. Return true
// (1) if the specified cookie returned with the response can be saved or
// false (0) otherwise.
///
int(CEF_CALLBACK* can_save_cookie)(
struct _cef_resource_request_handler_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_request_t* request,
struct _cef_response_t* response,
const struct _cef_cookie_t* cookie);
} cef_resource_request_handler_t;
///
// Implement this structure to filter cookies that may be sent or received from
// resource requests. The functions of this structure will be called on the IO
// thread unless otherwise indicated.
///
typedef struct _cef_cookie_access_filter_t {
///
// Base structure.
///
cef_base_ref_counted_t base;
///
// Called on the IO thread before a resource request is sent. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. |request| cannot be modified in
// this callback. Return true (1) if the specified cookie can be sent with the
// request or false (0) otherwise.
///
int(CEF_CALLBACK* can_send_cookie)(struct _cef_cookie_access_filter_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_request_t* request,
const struct _cef_cookie_t* cookie);
///
// Called on the IO thread after a resource response is received. The
// |browser| and |frame| values represent the source of the request, and may
// be NULL for requests originating from service workers. |request| cannot be
// modified in this callback. Return true (1) if the specified cookie returned
// with the response can be saved or false (0) otherwise.
///
int(CEF_CALLBACK* can_save_cookie)(struct _cef_cookie_access_filter_t* self,
struct _cef_browser_t* browser,
struct _cef_frame_t* frame,
struct _cef_request_t* request,
struct _cef_response_t* response,
const struct _cef_cookie_t* cookie);
} cef_cookie_access_filter_t;
#ifdef __cplusplus
}
#endif

View File

@ -34,7 +34,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=a16054629e5a769bd6a1fe5f49ca798dd945639c$
// $hash=9d23feaba9aac41aff230ff51bb08a5f18ddda48$
//
#ifndef CEF_INCLUDE_API_HASH_H_
@ -47,13 +47,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "611213d46fd8a3299500c43cdea741eea7454a4f"
#define CEF_API_HASH_UNIVERSAL "02918155c74c1f12406114bce5f668fba5fb8b8a"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "6c42e6a3ed0cf99eca56ccfc46e0014c45bdd3fe"
#define CEF_API_HASH_PLATFORM "d331dc982255599b7a6929cc38fdf133e58c16e6"
#elif defined(OS_MACOSX)
#define CEF_API_HASH_PLATFORM "f8cd3ac6e74bfeb4466a4dd79b2dd19a63eddc8a"
#define CEF_API_HASH_PLATFORM "8ab0117e584d529145dee6aac2409a0d523fae95"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "29fddb1f16808049dbfd747a2ddc91ee001dbcdf"
#define CEF_API_HASH_PLATFORM "6663ec2c35cbc01eec7a1bd939fcb7bf45203a42"
#endif
#ifdef __cplusplus

View File

@ -48,6 +48,8 @@
#include "include/cef_response_filter.h"
#include "include/internal/cef_types_wrappers.h"
class CefCookieAccessFilter;
///
// Implement this interface to handle events related to browser requests. The
// methods of this class will be called on the IO thread unless otherwise
@ -59,6 +61,21 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
typedef cef_return_value_t ReturnValue;
typedef cef_urlrequest_status_t URLRequestStatus;
///
// Called on the IO thread before a resource request is loaded. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. To optionally filter cookies for
// the request return a CefCookieAccessFilter object. The |request| object
// cannot not be modified in this callback.
///
/*--cef(optional_param=browser,optional_param=frame)--*/
virtual CefRefPtr<CefCookieAccessFilter> GetCookieAccessFilter(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
return NULL;
}
///
// Called on the IO thread before a resource request is loaded. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
@ -85,7 +102,7 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
// |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. To allow the resource to load
// using the default network loader return NULL. To specify a handler for the
// resource return a CefResourceHandler object. The |request| object should
// resource return a CefResourceHandler object. The |request| object cannot
// not be modified in this callback.
///
/*--cef(optional_param=browser,optional_param=frame)--*/
@ -167,7 +184,7 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
///
// Called on the IO thread to handle requests for URLs with an unknown
// protocol component. The |browser| and |frame| values represent the source
// protocol component. The |browser| and |frame| values represent the source
// of the request, and may be NULL for requests originating from service
// workers. |request| cannot be modified in this callback. Set
// |allow_os_execution| to true to attempt execution via the registered OS
@ -180,10 +197,22 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool& allow_os_execution) {}
};
///
// Implement this interface to filter cookies that may be sent or received from
// resource requests. The methods of this class will be called on the IO thread
// unless otherwise indicated.
///
/*--cef(source=client)--*/
class CefCookieAccessFilter : public virtual CefBaseRefCounted {
public:
///
// Called on the IO thread before a resource request is sent. Return true if
// the specified cookie can be sent with the request or false otherwise.
// Called on the IO thread before a resource request is sent. The |browser|
// and |frame| values represent the source of the request, and may be NULL for
// requests originating from service workers. |request| cannot be modified in
// this callback. Return true if the specified cookie can be sent with the
// request or false otherwise.
///
/*--cef(optional_param=browser,optional_param=frame)--*/
virtual bool CanSendCookie(CefRefPtr<CefBrowser> browser,
@ -194,9 +223,11 @@ class CefResourceRequestHandler : public virtual CefBaseRefCounted {
}
///
// Called on the IO thread after a resource response is received. Return true
// if the specified cookie returned with the response can be saved or false
// otherwise.
// Called on the IO thread after a resource response is received. The
// |browser| and |frame| values represent the source of the request, and may
// be NULL for requests originating from service workers. |request| cannot be
// modified in this callback. Return true if the specified cookie returned
// with the response can be saved or false otherwise.
///
/*--cef(optional_param=browser,optional_param=frame)--*/
virtual bool CanSaveCookie(CefRefPtr<CefBrowser> browser,

View File

@ -454,13 +454,19 @@ bool CefNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
if (!handler)
return true;
CefRefPtr<CefCookieAccessFilter> cookie_filter =
handler->GetCookieAccessFilter(browser, frame, requestPtr.get());
if (!cookie_filter)
return true;
bool cookie_blocked = false;
for (const auto& cookie : cookie_list) {
CefCookie cef_cookie;
if (!net_service::MakeCefCookie(cookie, cef_cookie))
continue;
if (!handler->CanSendCookie(browser, frame, requestPtr.get(), cef_cookie)) {
if (!cookie_filter->CanSendCookie(browser, frame, requestPtr.get(),
cef_cookie)) {
if (!cookie_blocked)
cookie_blocked = true;
}
@ -486,6 +492,11 @@ bool CefNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
if (!handler)
return true;
CefRefPtr<CefCookieAccessFilter> cookie_filter =
handler->GetCookieAccessFilter(browser, frame, requestPtr.get());
if (!cookie_filter)
return true;
CefCookie cef_cookie;
if (!net_service::MakeCefCookie(cookie, cef_cookie))
return true;
@ -494,8 +505,8 @@ bool CefNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
responsePtr->Set(&request);
responsePtr->SetReadOnly(true);
return handler->CanSaveCookie(browser, frame, requestPtr.get(),
responsePtr.get(), cef_cookie);
return cookie_filter->CanSaveCookie(browser, frame, requestPtr.get(),
responsePtr.get(), cef_cookie);
}
bool CefNetworkDelegate::OnCanAccessFile(

View File

@ -96,16 +96,20 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
bool request_was_redirected) {
handler_ = handler;
scheme_factory_ = scheme_factory;
cookie_filter_ = nullptr;
pending_request_ = request;
pending_response_ = nullptr;
request_was_redirected_ = request_was_redirected;
was_custom_handled_ = false;
}
CefRefPtr<CefResourceRequestHandler> handler_;
CefRefPtr<CefSchemeHandlerFactory> scheme_factory_;
CefRefPtr<CefCookieAccessFilter> cookie_filter_;
CefRefPtr<CefRequestImpl> pending_request_;
CefRefPtr<CefResponseImpl> pending_response_;
bool request_was_redirected_ = false;
bool was_custom_handled_ = false;
};
struct PendingRequest {
@ -221,6 +225,11 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
// May have a handler and/or scheme factory.
state->Reset(handler, scheme_factory, requestPtr, request_was_redirected);
if (handler) {
state->cookie_filter_ = handler->GetCookieAccessFilter(
GetBrowser(), frame_, requestPtr.get());
}
auto exec_callback = base::BindOnce(
std::move(callback), handler || scheme_factory /* intercept_request */,
is_external_ ? true : intercept_only);
@ -233,6 +242,8 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
base::OnceClosure callback) {
CEF_REQUIRE_IOT();
// We need to load/save cookies ourselves for custom-handled requests, or
// if we're using a cookie filter.
auto allow_cookie_callback =
base::BindRepeating(&InterceptedRequestHandlerWrapper::AllowCookieLoad,
weak_ptr_factory_.GetWeakPtr(), state);
@ -248,9 +259,14 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
bool* allow) {
CEF_REQUIRE_IOT();
if (!state->cookie_filter_) {
*allow = true;
return;
}
CefCookie cef_cookie;
if (net_service::MakeCefCookie(cookie, cef_cookie)) {
*allow = state->handler_->CanSendCookie(
*allow = state->cookie_filter_->CanSendCookie(
GetBrowser(), frame_, state->pending_request_.get(), cef_cookie);
}
}
@ -262,24 +278,23 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
net::CookieList allowed_cookies) {
CEF_REQUIRE_IOT();
if (state->handler_) {
// Add the Cookie header ourselves instead of letting the NetworkService
// do it.
request->load_flags |= net::LOAD_DO_NOT_SEND_COOKIES;
if (!allowed_cookies.empty()) {
const std::string& cookie_line =
net::CanonicalCookie::BuildCookieLine(allowed_cookies);
request->headers.SetHeader(net::HttpRequestHeaders::kCookie,
cookie_line);
if (state->cookie_filter_) {
// Also add/save cookies ourselves for default-handled network requests
// so that we can filter them. This will be a no-op for custom-handled
// requests.
request->load_flags |=
net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES;
}
state->pending_request_->SetReadOnly(false);
state->pending_request_->SetHeaderByName(
net::HttpRequestHeaders::kCookie, cookie_line, true);
state->pending_request_->SetReadOnly(true);
}
if (!allowed_cookies.empty()) {
const std::string& cookie_line =
net::CanonicalCookie::BuildCookieLine(allowed_cookies);
request->headers.SetHeader(net::HttpRequestHeaders::kCookie, cookie_line);
// Save cookies ourselves instead of letting the NetworkService do it.
request->load_flags |= net::LOAD_DO_NOT_SAVE_COOKIES;
state->pending_request_->SetReadOnly(false);
state->pending_request_->SetHeaderByName(net::HttpRequestHeaders::kCookie,
cookie_line, true);
state->pending_request_->SetReadOnly(true);
}
std::move(callback).Run();
@ -382,6 +397,8 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
std::unique_ptr<ResourceResponse> resource_response;
if (resource_handler) {
resource_response = CreateResourceResponse(id, resource_handler);
DCHECK(resource_response);
state->was_custom_handled_ = true;
}
// Continue the request.
@ -427,17 +444,16 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
DCHECK(state->pending_request_);
DCHECK(state->pending_response_);
// This flag should always be set.
DCHECK(request->load_flags | net::LOAD_DO_NOT_SAVE_COOKIES);
if (redirect_info.has_value()) {
HandleRedirect(state, *redirect_info, std::move(callback));
HandleRedirect(state, request, head, *redirect_info, std::move(callback));
} else {
HandleResponse(state, request, head, std::move(callback));
}
}
void HandleRedirect(RequestState* state,
network::ResourceRequest* request,
const network::ResourceResponseHead& head,
const net::RedirectInfo& redirect_info,
OnRequestResponseResultCallback callback) {
GURL new_url = redirect_info.new_url;
@ -464,7 +480,10 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
}
state->pending_request_->SetReadOnly(true);
std::move(callback).Run(ResponseMode::CONTINUE, nullptr, new_url);
auto exec_callback = base::BindOnce(
std::move(callback), ResponseMode::CONTINUE, nullptr, new_url);
MaybeSaveCookies(state, request, head, std::move(exec_callback));
}
void HandleResponse(RequestState* state,
@ -507,7 +526,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
base::BindOnce(std::move(callback), response_mode, nullptr, new_url);
if (response_mode == ResponseMode::RESTART) {
// Continue without saving cookies. We'll get them after the restart.
// Get any cookies after the restart.
std::move(exec_callback).Run();
return;
}
@ -521,6 +540,14 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
base::OnceClosure callback) {
CEF_REQUIRE_IOT();
if (!state->cookie_filter_ && !state->was_custom_handled_) {
// The NetworkService saves the cookies for default-handled requests.
std::move(callback).Run();
return;
}
// We need to load/save cookies ourselves for custom-handled requests, or
// if we're using a cookie filter.
auto allow_cookie_callback =
base::BindRepeating(&InterceptedRequestHandlerWrapper::AllowCookieSave,
weak_ptr_factory_.GetWeakPtr(), state);
@ -537,9 +564,14 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler {
bool* allow) {
CEF_REQUIRE_IOT();
if (!state->cookie_filter_) {
*allow = true;
return;
}
CefCookie cef_cookie;
if (net_service::MakeCefCookie(cookie, cef_cookie)) {
*allow = state->handler_->CanSaveCookie(
*allow = state->cookie_filter_->CanSaveCookie(
GetBrowser(), frame_, state->pending_request_.get(),
state->pending_response_.get(), cef_cookie);
}

View File

@ -0,0 +1,135 @@
// Copyright (c) 2019 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.
//
// $hash=c9c6c2cd02b565596a1173e95654655da80e1ef2$
//
#include "libcef_dll/cpptoc/cookie_access_filter_cpptoc.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
#include "libcef_dll/ctocpp/frame_ctocpp.h"
#include "libcef_dll/ctocpp/request_ctocpp.h"
#include "libcef_dll/ctocpp/response_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
int CEF_CALLBACK
cookie_access_filter_can_send_cookie(struct _cef_cookie_access_filter_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
const struct _cef_cookie_t* cookie) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return 0;
// Verify param: cookie; type: struct_byref_const
DCHECK(cookie);
if (!cookie)
return 0;
// Unverified params: browser, frame
// Translate param: cookie; type: struct_byref_const
CefCookie cookieObj;
if (cookie)
cookieObj.Set(*cookie, false);
// Execute
bool _retval = CefCookieAccessFilterCppToC::Get(self)->CanSendCookie(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), cookieObj);
// Return type: bool
return _retval;
}
int CEF_CALLBACK
cookie_access_filter_can_save_cookie(struct _cef_cookie_access_filter_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
struct _cef_response_t* response,
const struct _cef_cookie_t* cookie) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return 0;
// Verify param: response; type: refptr_diff
DCHECK(response);
if (!response)
return 0;
// Verify param: cookie; type: struct_byref_const
DCHECK(cookie);
if (!cookie)
return 0;
// Unverified params: browser, frame
// Translate param: cookie; type: struct_byref_const
CefCookie cookieObj;
if (cookie)
cookieObj.Set(*cookie, false);
// Execute
bool _retval = CefCookieAccessFilterCppToC::Get(self)->CanSaveCookie(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), CefResponseCToCpp::Wrap(response),
cookieObj);
// Return type: bool
return _retval;
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefCookieAccessFilterCppToC::CefCookieAccessFilterCppToC() {
GetStruct()->can_send_cookie = cookie_access_filter_can_send_cookie;
GetStruct()->can_save_cookie = cookie_access_filter_can_save_cookie;
}
// DESTRUCTOR - Do not edit by hand.
CefCookieAccessFilterCppToC::~CefCookieAccessFilterCppToC() {
shutdown_checker::AssertNotShutdown();
}
template <>
CefRefPtr<CefCookieAccessFilter> CefCppToCRefCounted<
CefCookieAccessFilterCppToC,
CefCookieAccessFilter,
cef_cookie_access_filter_t>::UnwrapDerived(CefWrapperType type,
cef_cookie_access_filter_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return NULL;
}
template <>
CefWrapperType CefCppToCRefCounted<CefCookieAccessFilterCppToC,
CefCookieAccessFilter,
cef_cookie_access_filter_t>::kWrapperType =
WT_COOKIE_ACCESS_FILTER;

View File

@ -0,0 +1,38 @@
// Copyright (c) 2019 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.
//
// $hash=c9e81bc87eea97cc704058c506a7908d9b73d4d7$
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_COOKIE_ACCESS_FILTER_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_COOKIE_ACCESS_FILTER_CPPTOC_H_
#pragma once
#if !defined(WRAPPING_CEF_SHARED)
#error This file can be included wrapper-side only
#endif
#include "include/capi/cef_resource_request_handler_capi.h"
#include "include/cef_resource_request_handler.h"
#include "libcef_dll/cpptoc/cpptoc_ref_counted.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed wrapper-side only.
class CefCookieAccessFilterCppToC
: public CefCppToCRefCounted<CefCookieAccessFilterCppToC,
CefCookieAccessFilter,
cef_cookie_access_filter_t> {
public:
CefCookieAccessFilterCppToC();
virtual ~CefCookieAccessFilterCppToC();
};
#endif // CEF_LIBCEF_DLL_CPPTOC_COOKIE_ACCESS_FILTER_CPPTOC_H_

View File

@ -9,10 +9,11 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=d923eabb6aa1e7a54966da940db39e308a71763f$
// $hash=533f1f8905a3079efe14fba7cb4e20ab59ea667f$
//
#include "libcef_dll/cpptoc/resource_request_handler_cpptoc.h"
#include "libcef_dll/cpptoc/cookie_access_filter_cpptoc.h"
#include "libcef_dll/cpptoc/resource_handler_cpptoc.h"
#include "libcef_dll/cpptoc/response_filter_cpptoc.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
@ -26,6 +27,35 @@ namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
struct _cef_cookie_access_filter_t* CEF_CALLBACK
resource_request_handler_get_cookie_access_filter(
struct _cef_resource_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return NULL;
// Unverified params: browser, frame
// Execute
CefRefPtr<CefCookieAccessFilter> _retval =
CefResourceRequestHandlerCppToC::Get(self)->GetCookieAccessFilter(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request));
// Return type: refptr_same
return CefCookieAccessFilterCppToC::Wrap(_retval);
}
cef_return_value_t CEF_CALLBACK
resource_request_handler_on_before_resource_load(
struct _cef_resource_request_handler_t* self,
@ -263,91 +293,13 @@ void CEF_CALLBACK resource_request_handler_on_protocol_execution(
*allow_os_execution = allow_os_executionBool ? true : false;
}
int CEF_CALLBACK resource_request_handler_can_send_cookie(
struct _cef_resource_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
const struct _cef_cookie_t* cookie) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return 0;
// Verify param: cookie; type: struct_byref_const
DCHECK(cookie);
if (!cookie)
return 0;
// Unverified params: browser, frame
// Translate param: cookie; type: struct_byref_const
CefCookie cookieObj;
if (cookie)
cookieObj.Set(*cookie, false);
// Execute
bool _retval = CefResourceRequestHandlerCppToC::Get(self)->CanSendCookie(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), cookieObj);
// Return type: bool
return _retval;
}
int CEF_CALLBACK resource_request_handler_can_save_cookie(
struct _cef_resource_request_handler_t* self,
cef_browser_t* browser,
cef_frame_t* frame,
cef_request_t* request,
struct _cef_response_t* response,
const struct _cef_cookie_t* cookie) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return 0;
// Verify param: response; type: refptr_diff
DCHECK(response);
if (!response)
return 0;
// Verify param: cookie; type: struct_byref_const
DCHECK(cookie);
if (!cookie)
return 0;
// Unverified params: browser, frame
// Translate param: cookie; type: struct_byref_const
CefCookie cookieObj;
if (cookie)
cookieObj.Set(*cookie, false);
// Execute
bool _retval = CefResourceRequestHandlerCppToC::Get(self)->CanSaveCookie(
CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame),
CefRequestCToCpp::Wrap(request), CefResponseCToCpp::Wrap(response),
cookieObj);
// Return type: bool
return _retval;
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefResourceRequestHandlerCppToC::CefResourceRequestHandlerCppToC() {
GetStruct()->get_cookie_access_filter =
resource_request_handler_get_cookie_access_filter;
GetStruct()->on_before_resource_load =
resource_request_handler_on_before_resource_load;
GetStruct()->get_resource_handler =
@ -362,8 +314,6 @@ CefResourceRequestHandlerCppToC::CefResourceRequestHandlerCppToC() {
resource_request_handler_on_resource_load_complete;
GetStruct()->on_protocol_execution =
resource_request_handler_on_protocol_execution;
GetStruct()->can_send_cookie = resource_request_handler_can_send_cookie;
GetStruct()->can_save_cookie = resource_request_handler_can_save_cookie;
}
// DESTRUCTOR - Do not edit by hand.

View File

@ -0,0 +1,110 @@
// Copyright (c) 2019 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.
//
// $hash=f79e09e667e0fd7447f63a5b02c17ba6f287d8d9$
//
#include "libcef_dll/ctocpp/cookie_access_filter_ctocpp.h"
#include "libcef_dll/cpptoc/browser_cpptoc.h"
#include "libcef_dll/cpptoc/frame_cpptoc.h"
#include "libcef_dll/cpptoc/request_cpptoc.h"
#include "libcef_dll/cpptoc/response_cpptoc.h"
#include "libcef_dll/shutdown_checker.h"
// VIRTUAL METHODS - Body may be edited by hand.
NO_SANITIZE("cfi-icall")
bool CefCookieAccessFilterCToCpp::CanSendCookie(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
const CefCookie& cookie) {
shutdown_checker::AssertNotShutdown();
cef_cookie_access_filter_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, can_send_cookie))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: request; type: refptr_diff
DCHECK(request.get());
if (!request.get())
return false;
// Unverified params: browser, frame
// Execute
int _retval = _struct->can_send_cookie(
_struct, CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
CefRequestCppToC::Wrap(request), &cookie);
// Return type: bool
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall")
bool CefCookieAccessFilterCToCpp::CanSaveCookie(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response,
const CefCookie& cookie) {
shutdown_checker::AssertNotShutdown();
cef_cookie_access_filter_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, can_save_cookie))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: request; type: refptr_diff
DCHECK(request.get());
if (!request.get())
return false;
// Verify param: response; type: refptr_diff
DCHECK(response.get());
if (!response.get())
return false;
// Unverified params: browser, frame
// Execute
int _retval = _struct->can_save_cookie(
_struct, CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
CefRequestCppToC::Wrap(request), CefResponseCppToC::Wrap(response),
&cookie);
// Return type: bool
return _retval ? true : false;
}
// CONSTRUCTOR - Do not edit by hand.
CefCookieAccessFilterCToCpp::CefCookieAccessFilterCToCpp() {}
// DESTRUCTOR - Do not edit by hand.
CefCookieAccessFilterCToCpp::~CefCookieAccessFilterCToCpp() {
shutdown_checker::AssertNotShutdown();
}
template <>
cef_cookie_access_filter_t* CefCToCppRefCounted<
CefCookieAccessFilterCToCpp,
CefCookieAccessFilter,
cef_cookie_access_filter_t>::UnwrapDerived(CefWrapperType type,
CefCookieAccessFilter* c) {
NOTREACHED() << "Unexpected class type: " << type;
return NULL;
}
template <>
CefWrapperType CefCToCppRefCounted<CefCookieAccessFilterCToCpp,
CefCookieAccessFilter,
cef_cookie_access_filter_t>::kWrapperType =
WT_COOKIE_ACCESS_FILTER;

View File

@ -0,0 +1,49 @@
// Copyright (c) 2019 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.
//
// $hash=f558b7741c406d8185d638eebb1fae9249f9a6f6$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_COOKIE_ACCESS_FILTER_CTOCPP_H_
#define CEF_LIBCEF_DLL_CTOCPP_COOKIE_ACCESS_FILTER_CTOCPP_H_
#pragma once
#if !defined(BUILDING_CEF_SHARED)
#error This file can be included DLL-side only
#endif
#include "include/capi/cef_resource_request_handler_capi.h"
#include "include/cef_resource_request_handler.h"
#include "libcef_dll/ctocpp/ctocpp_ref_counted.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed DLL-side only.
class CefCookieAccessFilterCToCpp
: public CefCToCppRefCounted<CefCookieAccessFilterCToCpp,
CefCookieAccessFilter,
cef_cookie_access_filter_t> {
public:
CefCookieAccessFilterCToCpp();
virtual ~CefCookieAccessFilterCToCpp();
// CefCookieAccessFilter methods.
bool CanSendCookie(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
const CefCookie& cookie) override;
bool CanSaveCookie(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response,
const CefCookie& cookie) override;
};
#endif // CEF_LIBCEF_DLL_CTOCPP_COOKIE_ACCESS_FILTER_CTOCPP_H_

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=c3f205b1da3b2dc0651ca836dee242588068ceff$
// $hash=217e200e9197054500554d62765c3c145bebfea7$
//
#include "libcef_dll/ctocpp/resource_request_handler_ctocpp.h"
@ -18,12 +18,42 @@
#include "libcef_dll/cpptoc/request_callback_cpptoc.h"
#include "libcef_dll/cpptoc/request_cpptoc.h"
#include "libcef_dll/cpptoc/response_cpptoc.h"
#include "libcef_dll/ctocpp/cookie_access_filter_ctocpp.h"
#include "libcef_dll/ctocpp/resource_handler_ctocpp.h"
#include "libcef_dll/ctocpp/response_filter_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
// VIRTUAL METHODS - Body may be edited by hand.
NO_SANITIZE("cfi-icall")
CefRefPtr<CefCookieAccessFilter>
CefResourceRequestHandlerCToCpp::GetCookieAccessFilter(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
shutdown_checker::AssertNotShutdown();
cef_resource_request_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_cookie_access_filter))
return NULL;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: request; type: refptr_diff
DCHECK(request.get());
if (!request.get())
return NULL;
// Unverified params: browser, frame
// Execute
cef_cookie_access_filter_t* _retval = _struct->get_cookie_access_filter(
_struct, CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
CefRequestCppToC::Wrap(request));
// Return type: refptr_same
return CefCookieAccessFilterCToCpp::Wrap(_retval);
}
NO_SANITIZE("cfi-icall")
CefResourceRequestHandler::ReturnValue
CefResourceRequestHandlerCToCpp::OnBeforeResourceLoad(
@ -252,70 +282,6 @@ void CefResourceRequestHandlerCToCpp::OnProtocolExecution(
allow_os_execution = allow_os_executionInt ? true : false;
}
NO_SANITIZE("cfi-icall")
bool CefResourceRequestHandlerCToCpp::CanSendCookie(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
const CefCookie& cookie) {
shutdown_checker::AssertNotShutdown();
cef_resource_request_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, can_send_cookie))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: request; type: refptr_diff
DCHECK(request.get());
if (!request.get())
return false;
// Unverified params: browser, frame
// Execute
int _retval = _struct->can_send_cookie(
_struct, CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
CefRequestCppToC::Wrap(request), &cookie);
// Return type: bool
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall")
bool CefResourceRequestHandlerCToCpp::CanSaveCookie(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response,
const CefCookie& cookie) {
shutdown_checker::AssertNotShutdown();
cef_resource_request_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, can_save_cookie))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: request; type: refptr_diff
DCHECK(request.get());
if (!request.get())
return false;
// Verify param: response; type: refptr_diff
DCHECK(response.get());
if (!response.get())
return false;
// Unverified params: browser, frame
// Execute
int _retval = _struct->can_save_cookie(
_struct, CefBrowserCppToC::Wrap(browser), CefFrameCppToC::Wrap(frame),
CefRequestCppToC::Wrap(request), CefResponseCppToC::Wrap(response),
&cookie);
// Return type: bool
return _retval ? true : false;
}
// CONSTRUCTOR - Do not edit by hand.
CefResourceRequestHandlerCToCpp::CefResourceRequestHandlerCToCpp() {}

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=544c856b8f70d9339c976863f77951d29a09c7e8$
// $hash=6e56582a287f701c84376a154e4f01247a4914f6$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_RESOURCE_REQUEST_HANDLER_CTOCPP_H_
@ -35,6 +35,10 @@ class CefResourceRequestHandlerCToCpp
virtual ~CefResourceRequestHandlerCToCpp();
// CefResourceRequestHandler methods.
CefRefPtr<CefCookieAccessFilter> GetCookieAccessFilter(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) override;
ReturnValue OnBeforeResourceLoad(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
@ -68,15 +72,6 @@ class CefResourceRequestHandlerCToCpp
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool& allow_os_execution) override;
bool CanSendCookie(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
const CefCookie& cookie) override;
bool CanSaveCookie(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response,
const CefCookie& cookie) override;
};
#endif // CEF_LIBCEF_DLL_CTOCPP_RESOURCE_REQUEST_HANDLER_CTOCPP_H_

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=7e25b74bd376dbed878c6b477ad89960c82f6cb1$
// $hash=98cdfe3302019e8169a9db0371a64ec7b3ad419b$
//
#ifndef CEF_LIBCEF_DLL_WRAPPER_TYPES_H_
@ -39,6 +39,7 @@ enum CefWrapperType {
WT_COMPLETION_CALLBACK,
WT_CONTEXT_MENU_HANDLER,
WT_CONTEXT_MENU_PARAMS,
WT_COOKIE_ACCESS_FILTER,
WT_COOKIE_MANAGER,
WT_COOKIE_VISITOR,
WT_DOMDOCUMENT,

View File

@ -1055,7 +1055,7 @@ class CookieAccessSchemeHandler : public CefResourceHandler {
bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback) override {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_IO_THREAD();
CefRequest::HeaderMap headerMap;
request->GetHeaderMap(headerMap);
@ -1070,7 +1070,7 @@ class CookieAccessSchemeHandler : public CefResourceHandler {
void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) override {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_IO_THREAD();
response->SetStatus(data_->response->GetStatus());
response->SetStatusText(data_->response->GetStatusText());
@ -1087,7 +1087,7 @@ class CookieAccessSchemeHandler : public CefResourceHandler {
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefCallback> callback) override {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_IO_THREAD();
bool has_data = false;
bytes_read = 0;
@ -1107,7 +1107,7 @@ class CookieAccessSchemeHandler : public CefResourceHandler {
return has_data;
}
void Cancel() override { EXPECT_TRUE(CefCurrentlyOn(TID_IO)); }
void Cancel() override { EXPECT_IO_THREAD(); }
private:
static void TestCookie(const CefCookie& cookie,
@ -1143,7 +1143,7 @@ class CookieAccessSchemeHandlerFactory : public CefSchemeHandlerFactory,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request) override {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_IO_THREAD();
const std::string& url = request->GetURL();
ResponseDataMap::const_iterator it = data_map_.find(url);
if (it != data_map_.end()) {
@ -1449,17 +1449,30 @@ class CookieAccessServerHandler : public CefServerHandler,
DISALLOW_COPY_AND_ASSIGN(CookieAccessServerHandler);
};
class CookieAccessTestHandler : public RoutingTestHandler {
class CookieAccessTestHandler : public RoutingTestHandler,
public CefCookieAccessFilter {
public:
enum TestMode {
ALLOW = 0,
BLOCK_READ = 1 << 0,
BLOCK_WRITE = 1 << 1,
BLOCK_READ_WRITE = BLOCK_READ | BLOCK_WRITE,
ALLOW_NO_FILTER = 1 << 2,
};
CookieAccessTestHandler(TestMode test_mode, bool server_backend)
: test_mode_(test_mode), server_backend_(server_backend) {}
enum TestBackend {
// Test an HTTP server backend.
SERVER,
// Test a custom scheme handler backend.
SCHEME_HANDLER,
// Test that GetResourceHandler behaves the same as a custom scheme handler.
RESOURCE_HANDLER,
};
CookieAccessTestHandler(TestMode test_mode, TestBackend test_backend)
: test_mode_(test_mode), test_backend_(test_backend) {}
void RunTest() override {
cookie_manager_ = CefCookieManager::GetGlobalManager(nullptr);
@ -1488,17 +1501,22 @@ class CookieAccessTestHandler : public RoutingTestHandler {
EXPECT_FALSE(got_cookie_manager_);
// Get 1 call to CanSaveCookie for the 1st network request due to the
// network cookie.
EXPECT_EQ(1, can_save_cookie1_ct_);
if (test_mode_ & BLOCK_WRITE) {
// Get 1 calls to CanSendCookie for the 2nd network request due to the
// JS cookie (network cookie is blocked).
EXPECT_EQ(1, can_send_cookie2_ct_);
if (test_mode_ == ALLOW_NO_FILTER) {
EXPECT_EQ(0, can_save_cookie1_ct_);
EXPECT_EQ(0, can_send_cookie2_ct_);
} else {
// Get 2 calls to CanSendCookie for the 2nd network request due to the
// network cookie + JS cookie.
EXPECT_EQ(2, can_send_cookie2_ct_);
// Get 1 call to CanSaveCookie for the 1st network request due to the
// network cookie.
EXPECT_EQ(1, can_save_cookie1_ct_);
if (test_mode_ & BLOCK_WRITE) {
// Get 1 calls to CanSendCookie for the 2nd network request due to the
// JS cookie (network cookie is blocked).
EXPECT_EQ(1, can_send_cookie2_ct_);
} else {
// Get 2 calls to CanSendCookie for the 2nd network request due to the
// network cookie + JS cookie.
EXPECT_EQ(2, can_send_cookie2_ct_);
}
}
// Always get the JS cookie via JS.
@ -1539,14 +1557,38 @@ class CookieAccessTestHandler : public RoutingTestHandler {
TestHandler::DestroyTest();
}
CefRefPtr<CefCookieAccessFilter> GetCookieAccessFilter(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) override {
EXPECT_IO_THREAD();
if (test_mode_ == ALLOW_NO_FILTER)
return nullptr;
return this;
}
CefRefPtr<CefResourceHandler> GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) override {
if (test_backend_ == RESOURCE_HANDLER) {
return scheme_factory_->Create(browser, frame, kCookieAccessScheme,
request);
}
return nullptr;
}
bool CanSendCookie(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
const CefCookie& cookie) override {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_IO_THREAD();
const std::string& url = request->GetURL();
if (url == GetCookieAccessUrl2(server_backend_)) {
if (url == GetCookieAccessUrl2(test_backend_ == SERVER)) {
can_send_cookie2_ct_++;
} else {
ADD_FAILURE() << "Unexpected url: " << url;
@ -1560,14 +1602,14 @@ class CookieAccessTestHandler : public RoutingTestHandler {
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response,
const CefCookie& cookie) override {
EXPECT_TRUE(CefCurrentlyOn(TID_IO));
EXPECT_IO_THREAD();
// Expecting the network cookie only.
EXPECT_STREQ("name_net", CefString(&cookie.name).ToString().c_str());
EXPECT_STREQ("value_net", CefString(&cookie.value).ToString().c_str());
const std::string& url = request->GetURL();
if (url == GetCookieAccessUrl1(server_backend_)) {
if (url == GetCookieAccessUrl1(test_backend_ == SERVER)) {
can_save_cookie1_ct_++;
} else {
ADD_FAILURE() << "Unexpected url: " << url;
@ -1584,10 +1626,11 @@ class CookieAccessTestHandler : public RoutingTestHandler {
CefRefPtr<Callback> callback) override {
const std::string& url = frame->GetURL();
const std::string& cookie_str = request.ToString();
if (url == GetCookieAccessUrl1(server_backend_)) {
if (url == GetCookieAccessUrl1(test_backend_ == SERVER)) {
TestCookieString(cookie_str, got_cookie_js1_, got_cookie_net1_);
browser->GetMainFrame()->LoadURL(GetCookieAccessUrl2(server_backend_));
} else if (url == GetCookieAccessUrl2(server_backend_)) {
browser->GetMainFrame()->LoadURL(
GetCookieAccessUrl2(test_backend_ == SERVER));
} else if (url == GetCookieAccessUrl2(test_backend_ == SERVER)) {
TestCookieString(cookie_str, got_cookie_js2_, got_cookie_net2_);
FinishTest();
} else {
@ -1619,7 +1662,8 @@ class CookieAccessTestHandler : public RoutingTestHandler {
"</script>"
"</head><body>COOKIE ACCESS TEST 1</body></html>";
handler->AddResponse(GetCookieAccessUrl1(server_backend_), &data1_);
handler->AddResponse(GetCookieAccessUrl1(test_backend_ == SERVER),
&data1_);
}
// 2nd request retrieves the cookies via JS.
@ -1636,12 +1680,13 @@ class CookieAccessTestHandler : public RoutingTestHandler {
"</script>"
"</head><body>COOKIE ACCESS TEST 2</body></html>";
handler->AddResponse(GetCookieAccessUrl2(server_backend_), &data2_);
handler->AddResponse(GetCookieAccessUrl2(test_backend_ == SERVER),
&data2_);
}
}
void StartBackend(const base::Closure& complete_callback) {
if (server_backend_) {
if (test_backend_ == SERVER) {
StartServer(complete_callback);
} else {
StartSchemeHandler(complete_callback);
@ -1660,12 +1705,14 @@ class CookieAccessTestHandler : public RoutingTestHandler {
// Add the factory registration.
scheme_factory_ = new CookieAccessSchemeHandlerFactory();
AddResponses(scheme_factory_.get());
if (context_) {
context_->RegisterSchemeHandlerFactory(
kCookieAccessScheme, kCookieAccessDomain, scheme_factory_.get());
} else {
CefRegisterSchemeHandlerFactory(kCookieAccessScheme, kCookieAccessDomain,
scheme_factory_.get());
if (test_backend_ == SCHEME_HANDLER) {
if (context_) {
context_->RegisterSchemeHandlerFactory(
kCookieAccessScheme, kCookieAccessDomain, scheme_factory_.get());
} else {
CefRegisterSchemeHandlerFactory(
kCookieAccessScheme, kCookieAccessDomain, scheme_factory_.get());
}
}
complete_callback.Run();
@ -1678,7 +1725,7 @@ class CookieAccessTestHandler : public RoutingTestHandler {
return;
}
CreateBrowser(GetCookieAccessUrl1(server_backend_), context_);
CreateBrowser(GetCookieAccessUrl1(test_backend_ == SERVER), context_);
}
void FinishTest() {
@ -1722,7 +1769,7 @@ class CookieAccessTestHandler : public RoutingTestHandler {
}
void ShutdownBackend(const base::Closure& complete_callback) {
if (server_backend_) {
if (test_backend_ == SERVER) {
ShutdownServer(complete_callback);
} else {
ShutdownSchemeHandler(complete_callback);
@ -1739,19 +1786,21 @@ class CookieAccessTestHandler : public RoutingTestHandler {
void ShutdownSchemeHandler(const base::Closure& complete_callback) {
EXPECT_TRUE(scheme_factory_);
if (context_) {
context_->RegisterSchemeHandlerFactory(kCookieAccessScheme,
kCookieAccessDomain, nullptr);
} else {
CefRegisterSchemeHandlerFactory(kCookieAccessScheme, kCookieAccessDomain,
nullptr);
if (test_backend_ == SCHEME_HANDLER) {
if (context_) {
context_->RegisterSchemeHandlerFactory(kCookieAccessScheme,
kCookieAccessDomain, nullptr);
} else {
CefRegisterSchemeHandlerFactory(kCookieAccessScheme,
kCookieAccessDomain, nullptr);
}
}
scheme_factory_->Shutdown(complete_callback);
scheme_factory_ = nullptr;
}
TestMode test_mode_;
bool server_backend_;
const TestMode test_mode_;
const TestBackend test_backend_;
CefRefPtr<CefRequestContext> context_;
CefRefPtr<CefCookieManager> cookie_manager_;
@ -1783,69 +1832,25 @@ class CookieAccessTestHandler : public RoutingTestHandler {
} // namespace
// Allow reading and writing of cookies with server backend.
TEST(CookieTest, AccessServerAllow) {
CefRefPtr<CookieAccessTestHandler> handler =
new CookieAccessTestHandler(CookieAccessTestHandler::ALLOW, true);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
#define ACCESS_TEST(name, test_mode, backend_mode) \
TEST(CookieTest, Access##name) { \
CefRefPtr<CookieAccessTestHandler> handler = \
new CookieAccessTestHandler(CookieAccessTestHandler::test_mode, \
CookieAccessTestHandler::backend_mode); \
handler->ExecuteTest(); \
ReleaseAndWaitForDestructor(handler); \
}
// Block reading of cookies with server backend.
TEST(CookieTest, AccessServerBlockRead) {
CefRefPtr<CookieAccessTestHandler> handler =
new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_READ, true);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
#define ACCESS_TEST_ALL_MODES(name, backend_mode) \
ACCESS_TEST(name##Allow, ALLOW, backend_mode) \
ACCESS_TEST(name##AllowNoFilter, ALLOW_NO_FILTER, backend_mode) \
ACCESS_TEST(name##BlockRead, BLOCK_READ, backend_mode) \
ACCESS_TEST(name##BlockWrite, BLOCK_WRITE, backend_mode) \
ACCESS_TEST(name##BlockReadWrite, BLOCK_READ_WRITE, backend_mode)
// Block writing of cookies with server backend.
TEST(CookieTest, AccessServerBlockWrite) {
CefRefPtr<CookieAccessTestHandler> handler =
new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_WRITE, true);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
// Block reading and writing of cookies with server backend.
TEST(CookieTest, AccessServerBlockReadWrite) {
CefRefPtr<CookieAccessTestHandler> handler = new CookieAccessTestHandler(
CookieAccessTestHandler::BLOCK_READ_WRITE, true);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
// Allow reading and writing of cookies with scheme handler backend.
TEST(CookieTest, AccessSchemeAllow) {
CefRefPtr<CookieAccessTestHandler> handler =
new CookieAccessTestHandler(CookieAccessTestHandler::ALLOW, false);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
// Block reading of cookies with scheme handler backend.
TEST(CookieTest, AccessSchemeBlockRead) {
CefRefPtr<CookieAccessTestHandler> handler =
new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_READ, false);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
// Block writing of cookies with scheme handler backend.
TEST(CookieTest, AccessSchemeBlockWrite) {
CefRefPtr<CookieAccessTestHandler> handler =
new CookieAccessTestHandler(CookieAccessTestHandler::BLOCK_WRITE, false);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
// Block reading and writing of cookies with scheme handler backend.
TEST(CookieTest, AccessSchemeBlockReadWrite) {
CefRefPtr<CookieAccessTestHandler> handler = new CookieAccessTestHandler(
CookieAccessTestHandler::BLOCK_READ_WRITE, false);
handler->ExecuteTest();
ReleaseAndWaitForDestructor(handler);
}
ACCESS_TEST_ALL_MODES(Server, SERVER)
ACCESS_TEST_ALL_MODES(Scheme, SCHEME_HANDLER)
ACCESS_TEST_ALL_MODES(Resource, RESOURCE_HANDLER)
// Entry point for registering custom schemes.
// Called from client_app_delegates.cc.

View File

@ -129,6 +129,21 @@ class BasicResponseTest : public TestHandler {
return this;
}
CefRefPtr<CefCookieAccessFilter> GetCookieAccessFilter(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) override {
EXPECT_IO_THREAD();
EXPECT_EQ(browser_id_, browser->GetIdentifier());
EXPECT_TRUE(frame->IsMain());
VerifyState(kGetCookieAccessFilter, request, nullptr);
get_cookie_access_filter_ct_++;
return NULL;
}
cef_return_value_t OnBeforeResourceLoad(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
@ -355,13 +370,17 @@ class BasicResponseTest : public TestHandler {
get_resource_response_filter_ct_ +
on_resource_load_complete_ct_,
get_resource_request_handler_ct_);
// Only called at the time we handle cookies.
EXPECT_EQ(0, get_cookie_access_filter_ct_);
}
if (mode_ == LOAD || mode_ == MODIFY_BEFORE_RESOURCE_LOAD) {
EXPECT_EQ(1, on_before_browse_ct_);
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(1, get_resource_request_handler_ct_);
EXPECT_EQ(1, get_cookie_access_filter_ct_);
}
EXPECT_EQ(1, on_before_browse_ct_);
EXPECT_EQ(1, on_before_resource_load_ct_);
EXPECT_EQ(1, get_resource_handler_ct_);
EXPECT_EQ(0, on_resource_redirect_ct_);
@ -377,11 +396,10 @@ class BasicResponseTest : public TestHandler {
else
EXPECT_EQ(1, on_resource_response_ct_);
} else if (mode_ == RESTART_RESOURCE_RESPONSE) {
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(2, get_resource_request_handler_ct_);
}
EXPECT_EQ(1, on_before_browse_ct_);
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(2, get_resource_request_handler_ct_);
EXPECT_EQ(2, get_cookie_access_filter_ct_);
EXPECT_EQ(2, on_before_resource_load_ct_);
} else {
// This seems like a bug in the old network implementation.
@ -402,10 +420,14 @@ class BasicResponseTest : public TestHandler {
else
EXPECT_EQ(2, on_resource_response_ct_);
} else if (IsRedirect()) {
EXPECT_EQ(2, on_before_browse_ct_);
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(2, get_resource_request_handler_ct_);
EXPECT_EQ(2, get_cookie_access_filter_ct_);
} else {
// Called at the time that we handle cookies.
EXPECT_EQ(0, get_cookie_access_filter_ct_);
}
EXPECT_EQ(2, on_before_browse_ct_);
EXPECT_EQ(2, on_before_resource_load_ct_);
if (mode_ == REDIRECT_BEFORE_RESOURCE_LOAD)
EXPECT_EQ(1, get_resource_handler_ct_);
@ -553,6 +575,7 @@ class BasicResponseTest : public TestHandler {
enum Callback {
kOnBeforeBrowse,
kGetResourceRequestHandler,
kGetCookieAccessFilter,
kOnBeforeResourceLoad,
kGetResourceHandler,
kOnResourceRedirect,
@ -699,6 +722,7 @@ class BasicResponseTest : public TestHandler {
int get_resource_request_handler_ct_ = 0;
int on_before_resource_load_ct_ = 0;
int get_cookie_access_filter_ct_ = 0;
int get_resource_handler_ct_ = 0;
int on_resource_redirect_ct_ = 0;
int on_resource_response_ct_ = 0;
@ -898,6 +922,31 @@ class SubresourceResponseTest : public RoutingTestHandler {
return this;
}
CefRefPtr<CefCookieAccessFilter> GetCookieAccessFilter(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) override {
EXPECT_IO_THREAD();
EXPECT_EQ(browser_id_, browser->GetIdentifier());
if (IsMainURL(request->GetURL())) {
EXPECT_TRUE(frame->IsMain());
return NULL;
} else if (IsSubURL(request->GetURL())) {
EXPECT_FALSE(frame->IsMain());
EXPECT_TRUE(subframe_);
return NULL;
}
VerifyFrame(kGetCookieAccessFilter, frame);
VerifyState(kGetCookieAccessFilter, request, nullptr);
get_cookie_access_filter_ct_++;
return NULL;
}
cef_return_value_t OnBeforeResourceLoad(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
@ -1216,6 +1265,9 @@ class SubresourceResponseTest : public RoutingTestHandler {
get_resource_response_filter_ct_ +
on_resource_load_complete_ct_,
get_resource_request_handler_ct_);
// Only called at the time we handle cookies.
EXPECT_EQ(0, get_cookie_access_filter_ct_);
}
// Only called for the main and/or sub frame load.
@ -1227,6 +1279,7 @@ class SubresourceResponseTest : public RoutingTestHandler {
if (mode_ == LOAD || mode_ == MODIFY_BEFORE_RESOURCE_LOAD) {
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(1, get_resource_request_handler_ct_);
EXPECT_EQ(1, get_cookie_access_filter_ct_);
}
EXPECT_EQ(1, on_before_resource_load_ct_);
EXPECT_EQ(1, get_resource_handler_ct_);
@ -1247,6 +1300,7 @@ class SubresourceResponseTest : public RoutingTestHandler {
EXPECT_EQ(2, get_resource_request_handler_ct_);
}
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(2, get_cookie_access_filter_ct_);
EXPECT_EQ(2, on_before_resource_load_ct_);
} else {
// This seems like a bug in the old network implementation.
@ -1269,6 +1323,7 @@ class SubresourceResponseTest : public RoutingTestHandler {
} else if (IsRedirect()) {
if (IsNetworkServiceEnabled()) {
EXPECT_EQ(2, get_resource_request_handler_ct_);
EXPECT_EQ(2, get_cookie_access_filter_ct_);
}
EXPECT_EQ(2, on_before_resource_load_ct_);
if (mode_ == REDIRECT_BEFORE_RESOURCE_LOAD)
@ -1502,6 +1557,7 @@ class SubresourceResponseTest : public RoutingTestHandler {
// Resource-related callbacks.
enum Callback {
kGetResourceRequestHandler,
kGetCookieAccessFilter,
kOnBeforeResourceLoad,
kGetResourceHandler,
kOnResourceRedirect,
@ -1671,6 +1727,7 @@ class SubresourceResponseTest : public RoutingTestHandler {
int on_query_ct_ = 0;
int get_resource_request_handler_ct_ = 0;
int get_cookie_access_filter_ct_ = 0;
int on_before_resource_load_ct_ = 0;
int get_resource_handler_ct_ = 0;
int on_resource_redirect_ct_ = 0;