Add CefTestServer that supports both HTTP and HTTPS (see issue #3348)

This commit is contained in:
Marshall Greenblatt
2022-07-29 12:34:30 -04:00
parent ce18bb98ab
commit f24dd61329
25 changed files with 2637 additions and 7 deletions

View File

@ -0,0 +1,152 @@
// Copyright (c) 2022 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=4015c7179f87d58159252275559c0a11ee9958c7$
//
#include "libcef_dll/cpptoc/test/test_server_connection_cpptoc.h"
#include "libcef_dll/shutdown_checker.h"
#include "libcef_dll/transfer_util.h"
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
void CEF_CALLBACK test_server_connection_send_http200response(
struct _cef_test_server_connection_t* self,
const cef_string_t* content_type,
const void* data,
size_t data_size) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: content_type; type: string_byref_const
DCHECK(content_type);
if (!content_type)
return;
// Verify param: data; type: simple_byaddr
DCHECK(data);
if (!data)
return;
// Execute
CefTestServerConnectionCppToC::Get(self)->SendHttp200Response(
CefString(content_type), data, data_size);
}
void CEF_CALLBACK test_server_connection_send_http404response(
struct _cef_test_server_connection_t* self) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Execute
CefTestServerConnectionCppToC::Get(self)->SendHttp404Response();
}
void CEF_CALLBACK test_server_connection_send_http500response(
struct _cef_test_server_connection_t* self,
const cef_string_t* error_message) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: error_message; type: string_byref_const
DCHECK(error_message);
if (!error_message)
return;
// Execute
CefTestServerConnectionCppToC::Get(self)->SendHttp500Response(
CefString(error_message));
}
void CEF_CALLBACK test_server_connection_send_http_response(
struct _cef_test_server_connection_t* self,
int response_code,
const cef_string_t* content_type,
const void* data,
size_t data_size,
cef_string_multimap_t extra_headers) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: content_type; type: string_byref_const
DCHECK(content_type);
if (!content_type)
return;
// Verify param: data; type: simple_byaddr
DCHECK(data);
if (!data)
return;
// Unverified params: extra_headers
// Translate param: extra_headers; type: string_map_multi_byref_const
std::multimap<CefString, CefString> extra_headersMultimap;
transfer_string_multimap_contents(extra_headers, extra_headersMultimap);
// Execute
CefTestServerConnectionCppToC::Get(self)->SendHttpResponse(
response_code, CefString(content_type), data, data_size,
extra_headersMultimap);
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefTestServerConnectionCppToC::CefTestServerConnectionCppToC() {
GetStruct()->send_http200response =
test_server_connection_send_http200response;
GetStruct()->send_http404response =
test_server_connection_send_http404response;
GetStruct()->send_http500response =
test_server_connection_send_http500response;
GetStruct()->send_http_response = test_server_connection_send_http_response;
}
// DESTRUCTOR - Do not edit by hand.
CefTestServerConnectionCppToC::~CefTestServerConnectionCppToC() {
shutdown_checker::AssertNotShutdown();
}
template <>
CefRefPtr<CefTestServerConnection> CefCppToCRefCounted<
CefTestServerConnectionCppToC,
CefTestServerConnection,
cef_test_server_connection_t>::UnwrapDerived(CefWrapperType type,
cef_test_server_connection_t*
s) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCppToCRefCounted<CefTestServerConnectionCppToC,
CefTestServerConnection,
cef_test_server_connection_t>::kWrapperType =
WT_TEST_SERVER_CONNECTION;

View File

@ -0,0 +1,38 @@
// Copyright (c) 2022 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=253d69f93a8637dad0b6d90f8993617694d40732$
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_TEST_TEST_SERVER_CONNECTION_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_TEST_TEST_SERVER_CONNECTION_CPPTOC_H_
#pragma once
#if !defined(BUILDING_CEF_SHARED)
#error This file can be included DLL-side only
#endif
#include "include/capi/test/cef_test_server_capi.h"
#include "include/test/cef_test_server.h"
#include "libcef_dll/cpptoc/cpptoc_ref_counted.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed DLL-side only.
class CefTestServerConnectionCppToC
: public CefCppToCRefCounted<CefTestServerConnectionCppToC,
CefTestServerConnection,
cef_test_server_connection_t> {
public:
CefTestServerConnectionCppToC();
virtual ~CefTestServerConnectionCppToC();
};
#endif // CEF_LIBCEF_DLL_CPPTOC_TEST_TEST_SERVER_CONNECTION_CPPTOC_H_

View File

@ -0,0 +1,104 @@
// Copyright (c) 2022 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=ff1da376e035d2eda9050f4d68b39b9e7e7d368e$
//
#include "libcef_dll/cpptoc/test/test_server_cpptoc.h"
#include "libcef_dll/ctocpp/test/test_server_handler_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
// GLOBAL FUNCTIONS - Body may be edited by hand.
CEF_EXPORT cef_test_server_t* cef_test_server_create_and_start(
uint16 port,
int https_server,
struct _cef_test_server_handler_t* handler) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: handler; type: refptr_diff
DCHECK(handler);
if (!handler)
return NULL;
// Execute
CefRefPtr<CefTestServer> _retval =
CefTestServer::CreateAndStart(port, https_server ? true : false,
CefTestServerHandlerCToCpp::Wrap(handler));
// Return type: refptr_same
return CefTestServerCppToC::Wrap(_retval);
}
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
void CEF_CALLBACK test_server_stop(struct _cef_test_server_t* self) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Execute
CefTestServerCppToC::Get(self)->Stop();
}
cef_string_userfree_t CEF_CALLBACK
test_server_get_origin(struct _cef_test_server_t* self) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return NULL;
// Execute
CefString _retval = CefTestServerCppToC::Get(self)->GetOrigin();
// Return type: string
return _retval.DetachToUserFree();
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefTestServerCppToC::CefTestServerCppToC() {
GetStruct()->stop = test_server_stop;
GetStruct()->get_origin = test_server_get_origin;
}
// DESTRUCTOR - Do not edit by hand.
CefTestServerCppToC::~CefTestServerCppToC() {
shutdown_checker::AssertNotShutdown();
}
template <>
CefRefPtr<CefTestServer>
CefCppToCRefCounted<CefTestServerCppToC, CefTestServer, cef_test_server_t>::
UnwrapDerived(CefWrapperType type, cef_test_server_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCppToCRefCounted<CefTestServerCppToC,
CefTestServer,
cef_test_server_t>::kWrapperType =
WT_TEST_SERVER;

View File

@ -0,0 +1,37 @@
// Copyright (c) 2022 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=bd5e875346e2fe779bdfda2e9e3caad228689ac1$
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_TEST_TEST_SERVER_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_TEST_TEST_SERVER_CPPTOC_H_
#pragma once
#if !defined(BUILDING_CEF_SHARED)
#error This file can be included DLL-side only
#endif
#include "include/capi/test/cef_test_server_capi.h"
#include "include/test/cef_test_server.h"
#include "libcef_dll/cpptoc/cpptoc_ref_counted.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed DLL-side only.
class CefTestServerCppToC : public CefCppToCRefCounted<CefTestServerCppToC,
CefTestServer,
cef_test_server_t> {
public:
CefTestServerCppToC();
virtual ~CefTestServerCppToC();
};
#endif // CEF_LIBCEF_DLL_CPPTOC_TEST_TEST_SERVER_CPPTOC_H_

View File

@ -0,0 +1,88 @@
// Copyright (c) 2022 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=7cd3cda97645c531a682b0dfefe33c4c94802dc9$
//
#include "libcef_dll/cpptoc/test/test_server_handler_cpptoc.h"
#include "libcef_dll/ctocpp/request_ctocpp.h"
#include "libcef_dll/ctocpp/test/test_server_connection_ctocpp.h"
#include "libcef_dll/ctocpp/test/test_server_ctocpp.h"
#include "libcef_dll/shutdown_checker.h"
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
int CEF_CALLBACK test_server_handler_on_test_server_request(
struct _cef_test_server_handler_t* self,
cef_test_server_t* server,
cef_request_t* request,
struct _cef_test_server_connection_t* connection) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Verify param: server; type: refptr_diff
DCHECK(server);
if (!server)
return 0;
// Verify param: request; type: refptr_diff
DCHECK(request);
if (!request)
return 0;
// Verify param: connection; type: refptr_diff
DCHECK(connection);
if (!connection)
return 0;
// Execute
bool _retval = CefTestServerHandlerCppToC::Get(self)->OnTestServerRequest(
CefTestServerCToCpp::Wrap(server), CefRequestCToCpp::Wrap(request),
CefTestServerConnectionCToCpp::Wrap(connection));
// Return type: bool
return _retval;
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefTestServerHandlerCppToC::CefTestServerHandlerCppToC() {
GetStruct()->on_test_server_request =
test_server_handler_on_test_server_request;
}
// DESTRUCTOR - Do not edit by hand.
CefTestServerHandlerCppToC::~CefTestServerHandlerCppToC() {
shutdown_checker::AssertNotShutdown();
}
template <>
CefRefPtr<CefTestServerHandler> CefCppToCRefCounted<
CefTestServerHandlerCppToC,
CefTestServerHandler,
cef_test_server_handler_t>::UnwrapDerived(CefWrapperType type,
cef_test_server_handler_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCppToCRefCounted<CefTestServerHandlerCppToC,
CefTestServerHandler,
cef_test_server_handler_t>::kWrapperType =
WT_TEST_SERVER_HANDLER;

View File

@ -0,0 +1,38 @@
// Copyright (c) 2022 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=c1e57c3ad143ac617900ced69827b02e19f9234e$
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_TEST_TEST_SERVER_HANDLER_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_TEST_TEST_SERVER_HANDLER_CPPTOC_H_
#pragma once
#if !defined(WRAPPING_CEF_SHARED)
#error This file can be included wrapper-side only
#endif
#include "include/capi/test/cef_test_server_capi.h"
#include "include/test/cef_test_server.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 CefTestServerHandlerCppToC
: public CefCppToCRefCounted<CefTestServerHandlerCppToC,
CefTestServerHandler,
cef_test_server_handler_t> {
public:
CefTestServerHandlerCppToC();
virtual ~CefTestServerHandlerCppToC();
};
#endif // CEF_LIBCEF_DLL_CPPTOC_TEST_TEST_SERVER_HANDLER_CPPTOC_H_