#include "chrome/test/chromedriver/chrome/devtools_client_impl.h"
#include <cstring>
#include <memory>
#include <sstream>
#include <utility>
#include "base/check.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/types/optional_util.h"
#include "chrome/test/chromedriver/chrome/devtools_event_listener.h"
#include "chrome/test/chromedriver/chrome/log.h"
#include "chrome/test/chromedriver/chrome/status.h"
#include "chrome/test/chromedriver/chrome/util.h"
#include "chrome/test/chromedriver/chrome/web_view_impl.h"
#include "chrome/test/chromedriver/net/sync_websocket.h"
#include "chrome/test/chromedriver/net/timeout.h"
namespace {
const char kInspectorDefaultContextError[] = …;
const char kInspectorContextError[] = …;
const char kInspectorInvalidURL[] = …;
const char kInspectorInsecureContext[] = …;
const char kInspectorOpaqueOrigins[] = …;
const char kInspectorPushPermissionError[] = …;
const char kInspectorNoSuchFrameError[] = …;
const char kNoTargetWithGivenIdError[] = …;
const char kUniqueContextIdNotFoundError[] = …;
const char kNoNodeForBackendNodeIdError[] = …;
const char kNoNodeWithGivenIdFoundError[] = …;
const char kExecutionContextWasDestroyed[] = …;
const char kInspectedTargetNavigatedOrClosed[] = …;
static constexpr int kSessionNotFoundInspectorCode = …;
static constexpr int kCdpMethodNotFoundCode = …;
static constexpr int kInvalidParamsInspectorCode = …;
class ScopedIncrementer { … };
Status ConditionIsMet(bool* is_condition_met) { … }
struct SessionId { … };
std::ostream& operator<<(std::ostream& os, const SessionId& ses_manip) { … }
Status IsBidiMessage(const std::string& method,
const base::Value::Dict& params,
bool& is_bidi_message) { … }
Status DeserializePayload(const base::Value::Dict& params,
base::Value::Dict* result) { … }
Status WrapCdpCommandInBidiCommand(base::Value::Dict cdp_cmd,
base::Value::Dict* bidi_cmd) { … }
Status WrapBidiCommandInMapperCdpCommand(int cdp_cmd_id,
const base::Value::Dict& bidi_cmd,
std::string mapper_session_id,
base::Value::Dict* cmd) { … }
bool ParseCdpTunnelMessage(base::Value::Dict payload,
std::string& session_id,
internal::InspectorMessageType& type,
InspectorEvent& event,
InspectorCommandResponse& command_response) { … }
}
const char DevToolsClientImpl::kBrowserwideDevToolsClientId[] = …;
const char DevToolsClientImpl::kCdpTunnelChannel[] = …;
const char DevToolsClientImpl::kBidiChannelSuffix[] = …;
DevToolsClientImpl::DevToolsClientImpl(const std::string& id,
const std::string& session_id)
: … { … }
DevToolsClientImpl::~DevToolsClientImpl() { … }
void DevToolsClientImpl::SetParserFuncForTesting(
const ParserFunc& parser_func) { … }
const std::string& DevToolsClientImpl::GetId() { … }
const std::string& DevToolsClientImpl::SessionId() const { … }
const std::string& DevToolsClientImpl::TunnelSessionId() const { … }
Status DevToolsClientImpl::SetTunnelSessionId(std::string session_id) { … }
Status DevToolsClientImpl::StartBidiServer(std::string bidi_mapper_script) { … }
Status DevToolsClientImpl::StartBidiServer(
std::string bidi_mapper_script,
const Timeout& timeout) { … }
Status DevToolsClientImpl::AppointAsBidiServerForTesting() { … }
bool DevToolsClientImpl::WasCrashed() { … }
bool DevToolsClientImpl::IsNull() const { … }
bool DevToolsClientImpl::IsConnected() const { … }
Status DevToolsClientImpl::AttachTo(DevToolsClient* parent) { … }
void DevToolsClientImpl::RegisterSessionHandler(const std::string& session_id,
DevToolsClient* client) { … }
void DevToolsClientImpl::UnregisterSessionHandler(
const std::string& session_id) { … }
Status DevToolsClientImpl::SetSocket(std::unique_ptr<SyncWebSocket> socket) { … }
Status DevToolsClientImpl::OnConnected() { … }
Status DevToolsClientImpl::SetUpDevTools() { … }
Status DevToolsClientImpl::PostBidiCommand(base::Value::Dict command) { … }
Status DevToolsClientImpl::SendCommand(const std::string& method,
const base::Value::Dict& params) { … }
Status DevToolsClientImpl::SendCommandFromWebSocket(
const std::string& method,
const base::Value::Dict& params,
int client_command_id) { … }
Status DevToolsClientImpl::SendCommandWithTimeout(
const std::string& method,
const base::Value::Dict& params,
const Timeout* timeout) { … }
Status DevToolsClientImpl::SendAsyncCommand(const std::string& method,
const base::Value::Dict& params) { … }
Status DevToolsClientImpl::SendCommandAndGetResult(
const std::string& method,
const base::Value::Dict& params,
base::Value::Dict* result) { … }
Status DevToolsClientImpl::SendCommandAndGetResultWithTimeout(
const std::string& method,
const base::Value::Dict& params,
const Timeout* timeout,
base::Value::Dict* result) { … }
Status DevToolsClientImpl::SendCommandAndIgnoreResponse(
const std::string& method,
const base::Value::Dict& params) { … }
void DevToolsClientImpl::AddListener(DevToolsEventListener* listener) { … }
void DevToolsClientImpl::RemoveListener(DevToolsEventListener* listener) { … }
Status DevToolsClientImpl::HandleReceivedEvents() { … }
Status DevToolsClientImpl::HandleEventsUntil(
const ConditionalFunc& conditional_func, const Timeout& timeout) { … }
void DevToolsClientImpl::SetDetached() { … }
void DevToolsClientImpl::SetOwner(WebViewImpl* owner) { … }
WebViewImpl* DevToolsClientImpl::GetOwner() const { … }
DevToolsClientImpl::ResponseInfo::ResponseInfo(const std::string& method)
: … { … }
DevToolsClientImpl::ResponseInfo::~ResponseInfo() = default;
DevToolsClient* DevToolsClientImpl::GetParentClient() const { … }
bool DevToolsClientImpl::IsMainPage() const { … }
void DevToolsClientImpl::SetMainPage(bool value) { … }
int DevToolsClientImpl::NextMessageId() const { … }
int DevToolsClientImpl::AdvanceNextMessageId() { … }
Status DevToolsClientImpl::PostBidiCommandInternal(std::string channel,
base::Value::Dict command) { … }
Status DevToolsClientImpl::SendRaw(const std::string& message) { … }
bool DevToolsClientImpl::HasMessageForAnySession() const { … }
Status DevToolsClientImpl::SendCommandInternal(const std::string& method,
const base::Value::Dict& params,
const std::string& session_id,
base::Value::Dict* result,
bool expect_response,
bool wait_for_response,
const int client_command_id,
const Timeout* timeout) { … }
Status DevToolsClientImpl::ProcessNextMessage(int expected_id,
bool log_timeout,
const Timeout& timeout,
DevToolsClient* caller) { … }
Status DevToolsClientImpl::HandleMessage(int expected_id,
const std::string& message,
DevToolsClient* caller) { … }
Status DevToolsClientImpl::HandleDialogOpening(
const base::Value::Dict& params) { … }
Status DevToolsClientImpl::HandleDialogClosed(const base::Value::Dict& params) { … }
Status DevToolsClientImpl::ProcessEvent(InspectorEvent event) { … }
Status DevToolsClientImpl::ProcessCommandResponse(
InspectorCommandResponse response) { … }
Status DevToolsClientImpl::EnsureListenersNotifiedOfConnect() { … }
Status DevToolsClientImpl::EnsureListenersNotifiedOfEvent() { … }
Status DevToolsClientImpl::EnsureListenersNotifiedOfCommandResponse() { … }
void DevToolsClientImpl::EnableEventTunnelingForTesting() { … }
bool DevToolsClientImpl::IsDialogOpen() const { … }
bool DevToolsClientImpl::AutoAcceptsBeforeunload() const { … }
void DevToolsClientImpl::SetAutoAcceptBeforeunload(bool value) { … }
Status DevToolsClientImpl::GetDialogMessage(std::string& message) const { … }
Status DevToolsClientImpl::GetTypeOfDialog(std::string& type) const { … }
Status DevToolsClientImpl::HandleDialog(
bool accept,
const std::optional<std::string>& text) { … }
namespace internal {
bool ParseInspectorMessage(const std::string& message,
int expected_id,
std::string& session_id,
InspectorMessageType& type,
InspectorEvent& event,
InspectorCommandResponse& command_response) { … }
Status ParseInspectorError(const std::string& error_json) { … }
}