paint_preview_recorder_impl.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2019 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_PAINT_PREVIEW_RENDERER_PAINT_PREVIEW_RECORDER_IMPL_H_
  5. #define COMPONENTS_PAINT_PREVIEW_RENDERER_PAINT_PREVIEW_RECORDER_IMPL_H_
  6. #include <stdint.h>
  7. #include "base/memory/weak_ptr.h"
  8. #include "components/paint_preview/common/mojom/paint_preview_recorder.mojom.h"
  9. #include "components/paint_preview/common/paint_preview_tracker.h"
  10. #include "content/public/renderer/render_frame_observer.h"
  11. #include "mojo/public/cpp/bindings/associated_receiver.h"
  12. #include "mojo/public/cpp/bindings/pending_associated_receiver.h"
  13. namespace content {
  14. class RenderFrame;
  15. } // namespace content
  16. namespace paint_preview {
  17. // PaintPreviewRecorderImpl handles the majority of the grunt work for capturing
  18. // a paint preview of a RenderFrame.
  19. class PaintPreviewRecorderImpl : public content::RenderFrameObserver,
  20. mojom::PaintPreviewRecorder {
  21. public:
  22. PaintPreviewRecorderImpl(content::RenderFrame* render_frame);
  23. ~PaintPreviewRecorderImpl() override;
  24. void CapturePaintPreview(mojom::PaintPreviewCaptureParamsPtr params,
  25. CapturePaintPreviewCallback callback) override;
  26. private:
  27. // RenderFrameObserver implementation --------------------------------------
  28. void OnDestruct() override;
  29. // Helpers ------------------------------------------------------------------
  30. void BindPaintPreviewRecorder(
  31. mojo::PendingAssociatedReceiver<mojom::PaintPreviewRecorder> receiver);
  32. // Handles the bulk of the capture.
  33. void CapturePaintPreviewInternal(
  34. const mojom::PaintPreviewCaptureParamsPtr& params,
  35. mojom::PaintPreviewCaptureResponsePtr region,
  36. CapturePaintPreviewCallback callback);
  37. bool is_painting_preview_;
  38. const bool is_main_frame_;
  39. mojo::AssociatedReceiver<mojom::PaintPreviewRecorder>
  40. paint_preview_recorder_receiver_{this};
  41. base::WeakPtrFactory<PaintPreviewRecorderImpl> weak_ptr_factory_{this};
  42. PaintPreviewRecorderImpl(const PaintPreviewRecorderImpl&) = delete;
  43. PaintPreviewRecorderImpl& operator=(const PaintPreviewRecorderImpl&) = delete;
  44. };
  45. } // namespace paint_preview
  46. #endif // COMPONENTS_PAINT_PREVIEW_RENDERER_PAINT_PREVIEW_RECORDER_IMPL_H_