named_message_port_connector_cast.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2021 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 CHROMECAST_BROWSER_NAMED_MESSAGE_PORT_CONNECTOR_CAST_H_
  5. #define CHROMECAST_BROWSER_NAMED_MESSAGE_PORT_CONNECTOR_CAST_H_
  6. #include "chromecast/browser/cast_web_contents.h"
  7. #include "chromecast/browser/cast_web_contents_observer.h"
  8. #include "components/cast/named_message_port_connector/named_message_port_connector.h"
  9. namespace chromecast {
  10. // Injects and connects to NamedMessagePortConnector services into documents
  11. // hosted by |cast_web_contents|.
  12. class NamedMessagePortConnectorCast
  13. : public cast_api_bindings::NamedMessagePortConnector,
  14. public CastWebContentsObserver {
  15. public:
  16. // |cast_web_contents|: The CastWebContents which will receive port connection
  17. // services. Must outlive |this|.
  18. explicit NamedMessagePortConnectorCast(
  19. chromecast::CastWebContents* cast_web_contents);
  20. ~NamedMessagePortConnectorCast() override;
  21. NamedMessagePortConnectorCast(const NamedMessagePortConnectorCast&) = delete;
  22. void operator=(const NamedMessagePortConnectorCast&) = delete;
  23. private:
  24. // Sends a connection message to |cast_web_contents_|.
  25. // Should be invoked when |cast_web_contents| has finished loading a page,
  26. // and its main frame finished loading with no further pending navigations.
  27. void OnPageLoaded();
  28. // CastWebContentsObserver implementation.
  29. void PageStateChanged(PageState page_state) override;
  30. chromecast::CastWebContents* cast_web_contents_;
  31. };
  32. } // namespace chromecast
  33. #endif // CHROMECAST_BROWSER_NAMED_MESSAGE_PORT_CONNECTOR_CAST_H_