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

@@ -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.