mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add CefTestServer that supports both HTTP and HTTPS (see issue #3348)
This commit is contained in:
146
libcef_dll/ctocpp/test/test_server_connection_ctocpp.cc
Normal file
146
libcef_dll/ctocpp/test/test_server_connection_ctocpp.cc
Normal file
@@ -0,0 +1,146 @@
|
||||
// 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=7b5fb7ede3a40321b3e077fa1aa1cd09ad2478d0$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/test/test_server_connection_ctocpp.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
#include "libcef_dll/transfer_util.h"
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefTestServerConnectionCToCpp::SendHttp200Response(
|
||||
const CefString& content_type,
|
||||
const void* data,
|
||||
size_t data_size) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_test_server_connection_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, send_http200response))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: content_type; type: string_byref_const
|
||||
DCHECK(!content_type.empty());
|
||||
if (content_type.empty())
|
||||
return;
|
||||
// Verify param: data; type: simple_byaddr
|
||||
DCHECK(data);
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
// Execute
|
||||
_struct->send_http200response(_struct, content_type.GetStruct(), data,
|
||||
data_size);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefTestServerConnectionCToCpp::SendHttp404Response() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_test_server_connection_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, send_http404response))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
_struct->send_http404response(_struct);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefTestServerConnectionCToCpp::SendHttp500Response(
|
||||
const CefString& error_message) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_test_server_connection_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, send_http500response))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: error_message; type: string_byref_const
|
||||
DCHECK(!error_message.empty());
|
||||
if (error_message.empty())
|
||||
return;
|
||||
|
||||
// Execute
|
||||
_struct->send_http500response(_struct, error_message.GetStruct());
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
void CefTestServerConnectionCToCpp::SendHttpResponse(
|
||||
int response_code,
|
||||
const CefString& content_type,
|
||||
const void* data,
|
||||
size_t data_size,
|
||||
const HeaderMap& extra_headers) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_test_server_connection_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, send_http_response))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: content_type; type: string_byref_const
|
||||
DCHECK(!content_type.empty());
|
||||
if (content_type.empty())
|
||||
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
|
||||
cef_string_multimap_t extra_headersMultimap = cef_string_multimap_alloc();
|
||||
DCHECK(extra_headersMultimap);
|
||||
if (extra_headersMultimap)
|
||||
transfer_string_multimap_contents(extra_headers, extra_headersMultimap);
|
||||
|
||||
// Execute
|
||||
_struct->send_http_response(_struct, response_code, content_type.GetStruct(),
|
||||
data, data_size, extra_headersMultimap);
|
||||
|
||||
// Restore param:extra_headers; type: string_map_multi_byref_const
|
||||
if (extra_headersMultimap)
|
||||
cef_string_multimap_free(extra_headersMultimap);
|
||||
}
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefTestServerConnectionCToCpp::CefTestServerConnectionCToCpp() {}
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefTestServerConnectionCToCpp::~CefTestServerConnectionCToCpp() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
}
|
||||
|
||||
template <>
|
||||
cef_test_server_connection_t* CefCToCppRefCounted<
|
||||
CefTestServerConnectionCToCpp,
|
||||
CefTestServerConnection,
|
||||
cef_test_server_connection_t>::UnwrapDerived(CefWrapperType type,
|
||||
CefTestServerConnection* c) {
|
||||
NOTREACHED() << "Unexpected class type: " << type;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <>
|
||||
CefWrapperType CefCToCppRefCounted<CefTestServerConnectionCToCpp,
|
||||
CefTestServerConnection,
|
||||
cef_test_server_connection_t>::kWrapperType =
|
||||
WT_TEST_SERVER_CONNECTION;
|
50
libcef_dll/ctocpp/test/test_server_connection_ctocpp.h
Normal file
50
libcef_dll/ctocpp/test/test_server_connection_ctocpp.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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=f216ade0a1b147a5ec5dce9b7196c6cbaa4cb637$
|
||||
//
|
||||
|
||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_TEST_TEST_SERVER_CONNECTION_CTOCPP_H_
|
||||
#define CEF_LIBCEF_DLL_CTOCPP_TEST_TEST_SERVER_CONNECTION_CTOCPP_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/ctocpp/ctocpp_ref_counted.h"
|
||||
|
||||
// Wrap a C structure with a C++ class.
|
||||
// This class may be instantiated and accessed wrapper-side only.
|
||||
class CefTestServerConnectionCToCpp
|
||||
: public CefCToCppRefCounted<CefTestServerConnectionCToCpp,
|
||||
CefTestServerConnection,
|
||||
cef_test_server_connection_t> {
|
||||
public:
|
||||
CefTestServerConnectionCToCpp();
|
||||
virtual ~CefTestServerConnectionCToCpp();
|
||||
|
||||
// CefTestServerConnection methods.
|
||||
void SendHttp200Response(const CefString& content_type,
|
||||
const void* data,
|
||||
size_t data_size) override;
|
||||
void SendHttp404Response() override;
|
||||
void SendHttp500Response(const CefString& error_message) override;
|
||||
void SendHttpResponse(int response_code,
|
||||
const CefString& content_type,
|
||||
const void* data,
|
||||
size_t data_size,
|
||||
const HeaderMap& extra_headers) override;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_DLL_CTOCPP_TEST_TEST_SERVER_CONNECTION_CTOCPP_H_
|
98
libcef_dll/ctocpp/test/test_server_ctocpp.cc
Normal file
98
libcef_dll/ctocpp/test/test_server_ctocpp.cc
Normal file
@@ -0,0 +1,98 @@
|
||||
// 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=3cb71639ce1fb2986ca0d8ff437b0264d550d784$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/test/test_server_ctocpp.h"
|
||||
#include "libcef_dll/cpptoc/test/test_server_handler_cpptoc.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
|
||||
// STATIC METHODS - Body may be edited by hand.
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
CefRefPtr<CefTestServer> CefTestServer::CreateAndStart(
|
||||
uint16 port,
|
||||
bool https_server,
|
||||
CefRefPtr<CefTestServerHandler> handler) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: handler; type: refptr_diff
|
||||
DCHECK(handler.get());
|
||||
if (!handler.get())
|
||||
return nullptr;
|
||||
|
||||
// Execute
|
||||
cef_test_server_t* _retval = cef_test_server_create_and_start(
|
||||
port, https_server, CefTestServerHandlerCppToC::Wrap(handler));
|
||||
|
||||
// Return type: refptr_same
|
||||
return CefTestServerCToCpp::Wrap(_retval);
|
||||
}
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
NO_SANITIZE("cfi-icall") void CefTestServerCToCpp::Stop() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_test_server_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, stop))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
_struct->stop(_struct);
|
||||
}
|
||||
|
||||
NO_SANITIZE("cfi-icall") CefString CefTestServerCToCpp::GetOrigin() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_test_server_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, get_origin))
|
||||
return CefString();
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Execute
|
||||
cef_string_userfree_t _retval = _struct->get_origin(_struct);
|
||||
|
||||
// Return type: string
|
||||
CefString _retvalStr;
|
||||
_retvalStr.AttachToUserFree(_retval);
|
||||
return _retvalStr;
|
||||
}
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefTestServerCToCpp::CefTestServerCToCpp() {}
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefTestServerCToCpp::~CefTestServerCToCpp() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
}
|
||||
|
||||
template <>
|
||||
cef_test_server_t*
|
||||
CefCToCppRefCounted<CefTestServerCToCpp, CefTestServer, cef_test_server_t>::
|
||||
UnwrapDerived(CefWrapperType type, CefTestServer* c) {
|
||||
NOTREACHED() << "Unexpected class type: " << type;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <>
|
||||
CefWrapperType CefCToCppRefCounted<CefTestServerCToCpp,
|
||||
CefTestServer,
|
||||
cef_test_server_t>::kWrapperType =
|
||||
WT_TEST_SERVER;
|
41
libcef_dll/ctocpp/test/test_server_ctocpp.h
Normal file
41
libcef_dll/ctocpp/test/test_server_ctocpp.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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=19937e8e0f9281513073c78b9152dd4afd3cc233$
|
||||
//
|
||||
|
||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_TEST_TEST_SERVER_CTOCPP_H_
|
||||
#define CEF_LIBCEF_DLL_CTOCPP_TEST_TEST_SERVER_CTOCPP_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/ctocpp/ctocpp_ref_counted.h"
|
||||
|
||||
// Wrap a C structure with a C++ class.
|
||||
// This class may be instantiated and accessed wrapper-side only.
|
||||
class CefTestServerCToCpp : public CefCToCppRefCounted<CefTestServerCToCpp,
|
||||
CefTestServer,
|
||||
cef_test_server_t> {
|
||||
public:
|
||||
CefTestServerCToCpp();
|
||||
virtual ~CefTestServerCToCpp();
|
||||
|
||||
// CefTestServer methods.
|
||||
void Stop() override;
|
||||
CefString GetOrigin() override;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_DLL_CTOCPP_TEST_TEST_SERVER_CTOCPP_H_
|
83
libcef_dll/ctocpp/test/test_server_handler_ctocpp.cc
Normal file
83
libcef_dll/ctocpp/test/test_server_handler_ctocpp.cc
Normal file
@@ -0,0 +1,83 @@
|
||||
// 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=a57c9fca8e9dcf286cde0a82717b046e7e0a1ade$
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/test/test_server_handler_ctocpp.h"
|
||||
#include "libcef_dll/cpptoc/request_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/test/test_server_connection_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/test/test_server_cpptoc.h"
|
||||
#include "libcef_dll/shutdown_checker.h"
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
NO_SANITIZE("cfi-icall")
|
||||
bool CefTestServerHandlerCToCpp::OnTestServerRequest(
|
||||
CefRefPtr<CefTestServer> server,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefTestServerConnection> connection) {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
|
||||
cef_test_server_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_test_server_request))
|
||||
return false;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: server; type: refptr_diff
|
||||
DCHECK(server.get());
|
||||
if (!server.get())
|
||||
return false;
|
||||
// Verify param: request; type: refptr_diff
|
||||
DCHECK(request.get());
|
||||
if (!request.get())
|
||||
return false;
|
||||
// Verify param: connection; type: refptr_diff
|
||||
DCHECK(connection.get());
|
||||
if (!connection.get())
|
||||
return false;
|
||||
|
||||
// Execute
|
||||
int _retval = _struct->on_test_server_request(
|
||||
_struct, CefTestServerCppToC::Wrap(server),
|
||||
CefRequestCppToC::Wrap(request),
|
||||
CefTestServerConnectionCppToC::Wrap(connection));
|
||||
|
||||
// Return type: bool
|
||||
return _retval ? true : false;
|
||||
}
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefTestServerHandlerCToCpp::CefTestServerHandlerCToCpp() {}
|
||||
|
||||
// DESTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefTestServerHandlerCToCpp::~CefTestServerHandlerCToCpp() {
|
||||
shutdown_checker::AssertNotShutdown();
|
||||
}
|
||||
|
||||
template <>
|
||||
cef_test_server_handler_t* CefCToCppRefCounted<
|
||||
CefTestServerHandlerCToCpp,
|
||||
CefTestServerHandler,
|
||||
cef_test_server_handler_t>::UnwrapDerived(CefWrapperType type,
|
||||
CefTestServerHandler* c) {
|
||||
NOTREACHED() << "Unexpected class type: " << type;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <>
|
||||
CefWrapperType CefCToCppRefCounted<CefTestServerHandlerCToCpp,
|
||||
CefTestServerHandler,
|
||||
cef_test_server_handler_t>::kWrapperType =
|
||||
WT_TEST_SERVER_HANDLER;
|
44
libcef_dll/ctocpp/test/test_server_handler_ctocpp.h
Normal file
44
libcef_dll/ctocpp/test/test_server_handler_ctocpp.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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=5e5af6baf4b4a60e2d1569927c2142e1323ca37b$
|
||||
//
|
||||
|
||||
#ifndef CEF_LIBCEF_DLL_CTOCPP_TEST_TEST_SERVER_HANDLER_CTOCPP_H_
|
||||
#define CEF_LIBCEF_DLL_CTOCPP_TEST_TEST_SERVER_HANDLER_CTOCPP_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/ctocpp/ctocpp_ref_counted.h"
|
||||
|
||||
// Wrap a C structure with a C++ class.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefTestServerHandlerCToCpp
|
||||
: public CefCToCppRefCounted<CefTestServerHandlerCToCpp,
|
||||
CefTestServerHandler,
|
||||
cef_test_server_handler_t> {
|
||||
public:
|
||||
CefTestServerHandlerCToCpp();
|
||||
virtual ~CefTestServerHandlerCToCpp();
|
||||
|
||||
// CefTestServerHandler methods.
|
||||
bool OnTestServerRequest(
|
||||
CefRefPtr<CefTestServer> server,
|
||||
CefRefPtr<CefRequest> request,
|
||||
CefRefPtr<CefTestServerConnection> connection) override;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_DLL_CTOCPP_TEST_TEST_SERVER_HANDLER_CTOCPP_H_
|
Reference in New Issue
Block a user