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 
5 #ifndef CONTENT_BROWSER_PICTURE_IN_PICTURE_PICTURE_IN_PICTURE_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_PICTURE_IN_PICTURE_PICTURE_IN_PICTURE_SERVICE_IMPL_H_
7 
8 #include <memory>
9 
10 #include "base/containers/unique_ptr_adapters.h"
11 #include "content/common/content_export.h"
12 #include "content/public/browser/frame_service_base.h"
13 #include "mojo/public/cpp/bindings/pending_receiver.h"
14 #include "mojo/public/cpp/bindings/pending_remote.h"
15 #include "third_party/blink/public/mojom/picture_in_picture/picture_in_picture.mojom.h"
16 
17 namespace content {
18 
19 class PictureInPictureSession;
20 
21 // Receives Picture-in-Picture messages from a given RenderFrame. There is one
22 // PictureInPictureServiceImpl per RenderFrameHost. The service gets a hold of
23 // a PictureInPictureSession to which it delegates most of the interactions with
24 // the rest of the Picture-in-Picture classes such as
25 // PictureInPictureWindowController.
26 class CONTENT_EXPORT PictureInPictureServiceImpl final
27     : public content::FrameServiceBase<blink::mojom::PictureInPictureService> {
28  public:
29   static void Create(
30       RenderFrameHost*,
31       mojo::PendingReceiver<blink::mojom::PictureInPictureService>);
32 
33   static PictureInPictureServiceImpl* CreateForTesting(
34       RenderFrameHost*,
35       mojo::PendingReceiver<blink::mojom::PictureInPictureService>);
36 
37   // PictureInPictureService implementation.
38   void StartSession(
39       uint32_t player_id,
40       const base::Optional<viz::SurfaceId>& surface_id,
41       const gfx::Size& natural_size,
42       bool show_play_pause_button,
43       mojo::PendingRemote<blink::mojom::PictureInPictureSessionObserver>,
44       StartSessionCallback) final;
45 
active_session_for_testing()46   PictureInPictureSession* active_session_for_testing() const {
47     return active_session_.get();
48   }
49 
50  private:
51   friend class PictureInPictureSession;
52 
53   PictureInPictureServiceImpl(
54       RenderFrameHost*,
55       mojo::PendingReceiver<blink::mojom::PictureInPictureService>);
56   ~PictureInPictureServiceImpl() override;
57 
58   RenderFrameHost* render_frame_host_ = nullptr;
59 
60   std::unique_ptr<PictureInPictureSession> active_session_;
61 
62   DISALLOW_COPY_AND_ASSIGN(PictureInPictureServiceImpl);
63 };
64 
65 }  // namespace content
66 
67 #endif  // CONTENT_BROWSER_PICTURE_IN_PICTURE_PICTURE_IN_PICTURE_SERVICE_IMPL_H_
68