cast_web_contents_observer.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_CAST_WEB_CONTENTS_OBSERVER_H_
  5. #define CHROMECAST_BROWSER_CAST_WEB_CONTENTS_OBSERVER_H_
  6. #include <string>
  7. #include "chromecast/browser/mojom/cast_web_contents.mojom.h"
  8. #include "chromecast/browser/web_types.h"
  9. #include "mojo/public/cpp/bindings/pending_associated_remote.h"
  10. #include "mojo/public/cpp/bindings/pending_remote.h"
  11. #include "mojo/public/cpp/bindings/receiver.h"
  12. #include "ui/gfx/geometry/rect.h"
  13. #include "url/gurl.h"
  14. namespace chromecast {
  15. class CastWebContents;
  16. // Default implementation of mojom::CastWebContentsObserver.
  17. class CastWebContentsObserver : public mojom::CastWebContentsObserver {
  18. public:
  19. CastWebContentsObserver();
  20. // Adds |this| to the CastWebContents observer list. Observe(nullptr) will
  21. // remove |this| from the observer list of the current CastWebContents being
  22. // observed.
  23. void Observe(mojom::CastWebContents* cast_web_contents);
  24. // =========================================================================
  25. // Observer Methods
  26. // =========================================================================
  27. // Advertises page state for the CastWebContents.
  28. void PageStateChanged(PageState page_state) override {}
  29. // Called when the page has stopped. e.g.: A 404 occurred when loading the
  30. // page or if the render process for the main frame crashes. |error_code|
  31. // will return a net::Error describing the failure, or net::OK if the page
  32. // closed intentionally.
  33. //
  34. // After this method, the page state will be one of the following:
  35. // CLOSED: Page was closed as expected and the WebContents exists. The page
  36. // should generally not be reloaded, since the page closure was
  37. // triggered intentionally.
  38. // ERROR: Page is in an error state. It should be reloaded or deleted.
  39. // DESTROYED: Page was closed due to deletion of WebContents. The
  40. // CastWebContents instance is no longer usable and should be deleted.
  41. void PageStopped(PageState page_state, int error_code) override {}
  42. // A new RenderFrame was created for the WebContents. |settings_manager| is
  43. // provided by the frame.
  44. void RenderFrameCreated(int render_process_id, int render_frame_id) override {
  45. }
  46. // A navigation has finished in the WebContents' main frame.
  47. void MainFrameFinishedNavigation() override {}
  48. // These methods are calls forwarded from WebContentsObserver.
  49. void UpdateTitle(const std::string& title) override {}
  50. void UpdateFaviconURL(const GURL& url) override {}
  51. void DidFirstVisuallyNonEmptyPaint() override {}
  52. // Notifies that a resource for the main frame failed to load.
  53. void ResourceLoadFailed() override {}
  54. // Propagates the process information via observer, in particular to
  55. // the underlying OnRendererProcessStarted() method.
  56. void OnRenderProcessReady(int pid) override {}
  57. // Notify media playback state changes for the underlying WebContents.
  58. void MediaPlaybackChanged(bool media_playing) override {}
  59. void InnerContentsCreated(mojo::PendingRemote<mojom::CastWebContents>
  60. pending_inner_contents) override {}
  61. protected:
  62. ~CastWebContentsObserver() override;
  63. mojo::Receiver<mojom::CastWebContentsObserver> receiver_{this};
  64. };
  65. } // namespace chromecast
  66. #endif // CHROMECAST_BROWSER_CAST_WEB_CONTENTS_OBSERVER_H_