content_capture_consumer.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 COMPONENTS_CONTENT_CAPTURE_BROWSER_CONTENT_CAPTURE_CONSUMER_H_
  5. #define COMPONENTS_CONTENT_CAPTURE_BROWSER_CONTENT_CAPTURE_CONSUMER_H_
  6. #include <vector>
  7. #include "components/content_capture/browser/content_capture_frame.h"
  8. class GURL;
  9. namespace content_capture {
  10. // The interface for the embedder to get onscreen content.
  11. //
  12. // The embedder shall call OnscreenContentProvider::AddConsumer() to add
  13. // itself as consumer.
  14. //
  15. // OnscreenContentProvider* provider =
  16. // OnscreenContentProvider::FromWebContents(web_contents);
  17. // if (!provider)
  18. // provider = OnscreenContentProvider::Create(web_contents);
  19. // provider->AddConsumer(*this);
  20. //
  21. // The embedder might remove itself when the onscreen content is no longer
  22. // needed.
  23. // // Keep the weak reference
  24. // onscreen_content_provider_ = provider->GetWeakPtr();
  25. //
  26. // // Remove from the consumers
  27. // if (auto* provider = onscreen_content_provider_.get())
  28. // provider->RemoveConsumer(*this);
  29. class ContentCaptureConsumer {
  30. public:
  31. virtual ~ContentCaptureConsumer() = default;
  32. // Invoked when the captured content |data| from the |parent_session| was
  33. // received.
  34. virtual void DidCaptureContent(const ContentCaptureSession& parent_session,
  35. const ContentCaptureFrame& data) = 0;
  36. // Invoked when the updated content |data| from the |parent_session| was
  37. // received.
  38. virtual void DidUpdateContent(const ContentCaptureSession& parent_session,
  39. const ContentCaptureFrame& data) = 0;
  40. // Invoked when the list of content |ids| of the given |session| was removed.
  41. virtual void DidRemoveContent(const ContentCaptureSession& session,
  42. const std::vector<int64_t>& ids) = 0;
  43. // Invoked when the given |session| was removed because
  44. // - the corresponding frame is deleted,
  45. // - or the corresponding WebContents is deleted.
  46. // - or the consumer removes itself from OnscreenContentProvider, only
  47. // main session will be notified in this case.
  48. virtual void DidRemoveSession(const ContentCaptureSession& session) = 0;
  49. // Invoked when the given |main_frame|'s title updated.
  50. virtual void DidUpdateTitle(const ContentCaptureFrame& main_frame) = 0;
  51. // Invoked when the given |main_frame|'s favicon updated.
  52. virtual void DidUpdateFavicon(const ContentCaptureFrame& main_frame) = 0;
  53. // Return if the |url| shall be captured. Even return false, the content might
  54. // still be streamed because of the other consumers require it. Consumer can
  55. // ignore the content upon it arrives.
  56. virtual bool ShouldCapture(const GURL& url) = 0;
  57. };
  58. } // namespace content_capture
  59. #endif // COMPONENTS_CONTENT_CAPTURE_BROWSER_CONTENT_CAPTURE_CONSUMER_H_