devtools_client.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_UI_DEVTOOLS_DEVTOOLS_CLIENT_H_
  5. #define COMPONENTS_UI_DEVTOOLS_DEVTOOLS_CLIENT_H_
  6. #include <string>
  7. #include "components/ui_devtools/devtools_base_agent.h"
  8. #include "components/ui_devtools/devtools_export.h"
  9. #include "components/ui_devtools/dom.h"
  10. #include "components/ui_devtools/forward.h"
  11. #include "components/ui_devtools/protocol.h"
  12. namespace ui_devtools {
  13. class UiDevToolsServer;
  14. // Every UI component that wants to be inspectable must instantiate
  15. // this class and attach the corresponding backends/frontends (i.e: DOM, CSS,
  16. // etc). This client is then attached to the UiDevToolsServer and all messages
  17. // from this client are sent over the web socket owned by the server.
  18. class UI_DEVTOOLS_EXPORT UiDevToolsClient : public protocol::FrontendChannel {
  19. public:
  20. static const int kNotConnected = -1;
  21. UiDevToolsClient(const std::string& name, UiDevToolsServer* server);
  22. UiDevToolsClient(const UiDevToolsClient&) = delete;
  23. UiDevToolsClient& operator=(const UiDevToolsClient&) = delete;
  24. ~UiDevToolsClient() override;
  25. void AddAgent(std::unique_ptr<UiDevToolsAgent> agent);
  26. void Disconnect();
  27. void Dispatch(const std::string& json);
  28. bool connected() const;
  29. void set_connection_id(int connection_id);
  30. const std::string& name() const;
  31. private:
  32. void DisableAllAgents();
  33. void MaybeSendProtocolResponseOrNotification(
  34. std::unique_ptr<protocol::Serializable> message);
  35. // protocol::FrontendChannel
  36. void SendProtocolResponse(
  37. int callId,
  38. std::unique_ptr<protocol::Serializable> message) override;
  39. void SendProtocolNotification(
  40. std::unique_ptr<protocol::Serializable> message) override;
  41. void FlushProtocolNotifications() override;
  42. void FallThrough(int call_id,
  43. crdtp::span<uint8_t> method,
  44. crdtp::span<uint8_t> message) override;
  45. std::string name_;
  46. int connection_id_;
  47. std::vector<std::unique_ptr<UiDevToolsAgent>> agents_;
  48. protocol::UberDispatcher dispatcher_;
  49. UiDevToolsServer* server_;
  50. };
  51. } // namespace ui_devtools
  52. #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_CLIENT_H_