InspectorBackendDispatcher.h [plain text]
#pragma once
#include "InspectorFrontendRouter.h"
#include "InspectorProtocolTypes.h"
#include <wtf/DeprecatedOptional.h>
#include <wtf/Optional.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
namespace Inspector {
class BackendDispatcher;
typedef String ErrorString;
class JS_EXPORT_PRIVATE SupplementalBackendDispatcher : public RefCounted<SupplementalBackendDispatcher> {
public:
SupplementalBackendDispatcher(BackendDispatcher&);
virtual ~SupplementalBackendDispatcher();
virtual void dispatch(long requestId, const String& method, Ref<InspectorObject>&& message) = 0;
protected:
Ref<BackendDispatcher> m_backendDispatcher;
};
class JS_EXPORT_PRIVATE BackendDispatcher : public RefCounted<BackendDispatcher> {
public:
static Ref<BackendDispatcher> create(Ref<FrontendRouter>&&);
class JS_EXPORT_PRIVATE CallbackBase : public RefCounted<CallbackBase> {
public:
CallbackBase(Ref<BackendDispatcher>&&, long requestId);
bool isActive() const;
void disable() { m_alreadySent = true; }
void sendSuccess(RefPtr<InspectorObject>&&);
void sendFailure(const ErrorString&);
private:
Ref<BackendDispatcher> m_backendDispatcher;
long m_requestId;
bool m_alreadySent { false };
};
bool isActive() const;
bool hasProtocolErrors() const { return m_protocolErrors.size() > 0; }
enum CommonErrorCode {
ParseError = 0,
InvalidRequest,
MethodNotFound,
InvalidParams,
InternalError,
ServerError
};
void registerDispatcherForDomain(const String& domain, SupplementalBackendDispatcher*);
void dispatch(const String& message);
void sendResponse(long requestId, RefPtr<InspectorObject>&& result);
void sendPendingErrors();
void reportProtocolError(CommonErrorCode, const String& errorMessage);
void reportProtocolError(std::optional<long> relatedRequestId, CommonErrorCode, const String& errorMessage);
template<typename T>
WTF_HIDDEN_DECLARATION
T getPropertyValue(InspectorObject*, const String& name, bool* out_optionalValueFound, T defaultValue, std::function<bool(InspectorValue&, T&)>, const char* typeName);
int getInteger(InspectorObject*, const String& name, bool* valueFound);
double getDouble(InspectorObject*, const String& name, bool* valueFound);
String getString(InspectorObject*, const String& name, bool* valueFound);
bool getBoolean(InspectorObject*, const String& name, bool* valueFound);
RefPtr<InspectorValue> getValue(InspectorObject*, const String& name, bool* valueFound);
RefPtr<InspectorObject> getObject(InspectorObject*, const String& name, bool* valueFound);
RefPtr<InspectorArray> getArray(InspectorObject*, const String& name, bool* valueFound);
private:
BackendDispatcher(Ref<FrontendRouter>&&);
#if PLATFORM(MAC)
void reportProtocolError(WTF::DeprecatedOptional<long> relatedRequestId, CommonErrorCode, const String& errorMessage);
#endif
Ref<FrontendRouter> m_frontendRouter;
HashMap<String, SupplementalBackendDispatcher*> m_dispatchers;
Vector<std::tuple<CommonErrorCode, String>> m_protocolErrors;
std::optional<long> m_currentRequestId { std::nullopt };
};
}