#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/browser/devtools/devtools_pipe_handler.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include <io.h>
#include <stdlib.h>
#else
#include <sys/socket.h>
#endif
#include <stdio.h>
#include <cstdlib>
#include <memory>
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_pump_type.h"
#include "base/strings/string_util.h"
#include "base/synchronization/atomic_flag.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/common/content_switches.h"
#include "net/server/http_connection.h"
#include "third_party/inspector_protocol/crdtp/cbor.h"
const size_t kReceiveBufferSizeForDevTools = …;
const size_t kWritePacketSize = …;
namespace content {
namespace {
class PipeIOBase { … };
#if BUILDFLAG(IS_WIN)
class ScopedInvalidParameterHandlerOverride {
public:
ScopedInvalidParameterHandlerOverride()
: prev_invalid_parameter_handler_(
_set_thread_local_invalid_parameter_handler(
InvalidParameterHandler)) {}
ScopedInvalidParameterHandlerOverride(
const ScopedInvalidParameterHandlerOverride&) = delete;
ScopedInvalidParameterHandlerOverride& operator=(
const ScopedInvalidParameterHandlerOverride&) = delete;
~ScopedInvalidParameterHandlerOverride() {
_set_thread_local_invalid_parameter_handler(
prev_invalid_parameter_handler_);
}
private:
static void InvalidParameterHandler(const wchar_t* expression,
const wchar_t* function,
const wchar_t* file,
unsigned int line,
uintptr_t reserved) {}
const _invalid_parameter_handler prev_invalid_parameter_handler_;
};
#endif
}
class PipeReaderBase : public PipeIOBase { … };
class PipeWriterBase : public PipeIOBase { … };
namespace {
class PipeWriterASCIIZ : public PipeWriterBase { … };
class PipeWriterCBOR : public PipeWriterBase { … };
class PipeReaderASCIIZ : public PipeReaderBase { … };
class PipeReaderCBOR : public PipeReaderBase { … };
}
DevToolsPipeHandler::DevToolsPipeHandler(int read_fd,
int write_fd,
base::OnceClosure on_disconnect)
: … { … }
void DevToolsPipeHandler::Shutdown() { … }
DevToolsPipeHandler::~DevToolsPipeHandler() { … }
void DevToolsPipeHandler::HandleMessage(std::vector<uint8_t> message) { … }
void DevToolsPipeHandler::OnDisconnect() { … }
void DevToolsPipeHandler::DispatchProtocolMessage(
DevToolsAgentHost* agent_host,
base::span<const uint8_t> message) { … }
void DevToolsPipeHandler::AgentHostClosed(DevToolsAgentHost* agent_host) { … }
bool DevToolsPipeHandler::UsesBinaryProtocol() { … }
bool DevToolsPipeHandler::AllowUnsafeOperations() { … }
std::string DevToolsPipeHandler::GetTypeForMetrics() { … }
}