fuchsia_web_debug_proxy.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2022 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 FUCHSIA_WEB_WEBINSTANCE_HOST_FUCHSIA_WEB_DEBUG_PROXY_H_
  5. #define FUCHSIA_WEB_WEBINSTANCE_HOST_FUCHSIA_WEB_DEBUG_PROXY_H_
  6. #include <fuchsia/web/cpp/fidl.h>
  7. #include <lib/fidl/cpp/binding_set.h>
  8. #include <lib/fidl/cpp/interface_ptr_set.h>
  9. // Proxies the fuchsia.web.Debug protocol to one or more registered
  10. // fuchsia.web.Debug implementations, allowing clients to use a single
  11. // fuchsia.web.Debug instance to observe DevTools availability across
  12. // multiple components (e.g. multiple web instances).
  13. class FuchsiaWebDebugProxy final : public fuchsia::web::Debug,
  14. public fuchsia::web::DevToolsListener {
  15. public:
  16. explicit FuchsiaWebDebugProxy();
  17. ~FuchsiaWebDebugProxy() override;
  18. // Returns true if one or more clients are active.
  19. bool has_clients() const { return devtools_listeners_.size() != 0u; }
  20. // Registers a new fuchsia.web.Debug protocol to be proxied.
  21. void RegisterInstance(fidl::InterfaceHandle<fuchsia::web::Debug> debug);
  22. // fuchsia::web::Debug implementation.
  23. void EnableDevTools(
  24. fidl::InterfaceHandle<fuchsia::web::DevToolsListener> listener,
  25. EnableDevToolsCallback callback) override;
  26. private:
  27. // fuchsia::web::DevToolsListener implementation.
  28. void OnContextDevToolsAvailable(
  29. fidl::InterfaceRequest<fuchsia::web::DevToolsPerContextListener> request)
  30. override;
  31. // DevToolsListeners registered by clients via the Debug interface.
  32. fidl::InterfacePtrSet<fuchsia::web::DevToolsListener> devtools_listeners_;
  33. // DevToolsListener bindings, connected to active web instances.
  34. fidl::BindingSet<fuchsia::web::DevToolsListener> instance_bindings_;
  35. };
  36. #endif // FUCHSIA_WEB_WEBINSTANCE_HOST_FUCHSIA_WEB_DEBUG_PROXY_H_