1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97

content / browser / renderer_host / render_frame_host_impl_ppapi_support.h [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_FRAME_HOST_IMPL_PPAPI_SUPPORT_H_
#define CONTENT_BROWSER_RENDERER_HOST_RENDER_FRAME_HOST_IMPL_PPAPI_SUPPORT_H_

#include <stdint.h>

#include <map>
#include <memory>

#include "base/files/file_path.h"
#include "base/memory/raw_ref.h"
#include "content/common/pepper_plugin.mojom.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"

namespace content {

class PepperPluginInstanceHost;
class RenderFrameHostImpl;
class RenderProcessHostImpl;

class RenderFrameHostImplPpapiSupport : public mojom::PepperHost,
                                        public mojom::PepperHungDetectorHost {
 public:
  explicit RenderFrameHostImplPpapiSupport(RenderFrameHostImpl& frame_host);
  ~RenderFrameHostImplPpapiSupport() override;

  void Bind(mojo::PendingAssociatedReceiver<mojom::PepperHost> receiver);
  void SetVolume(int32_t instance_id, double volume);

  // mojom::PepperHost overrides:
  void InstanceCreated(
      int32_t instance_id,
      mojo::PendingAssociatedRemote<mojom::PepperPluginInstance> instance,
      mojo::PendingAssociatedReceiver<mojom::PepperPluginInstanceHost> host)
      override;
  void BindHungDetectorHost(
      mojo::PendingReceiver<mojom::PepperHungDetectorHost> hung_host,
      int32_t plugin_child_id,
      const base::FilePath& path) override;
  void GetPluginInfo(const GURL& url,
                     const std::string& mime_type,
                     GetPluginInfoCallback callback) override;
  void DidCreateInProcessInstance(int32_t instance,
                                  int32_t render_frame_id,
                                  const GURL& document_url,
                                  const GURL& plugin_url) override;
  void DidDeleteInProcessInstance(int32_t instance) override;
  void DidCreateOutOfProcessPepperInstance(
      int32_t plugin_child_id,
      int32_t pp_instance,
      bool is_external,
      int32_t render_frame_id,
      const GURL& document_url,
      const GURL& plugin_url,
      bool is_priviledged_context,
      DidCreateOutOfProcessPepperInstanceCallback callback) override;
  void DidDeleteOutOfProcessPepperInstance(int32_t plugin_child_id,
                                           int32_t pp_instance,
                                           bool is_external) override;
  void OpenChannelToPepperPlugin(
      const url::Origin& embedder_origin,
      const base::FilePath& path,
      const std::optional<url::Origin>& origin_lock,
      OpenChannelToPepperPluginCallback callback) override;

  // mojom::PepperHungDetectorHost overrides:
  void PluginHung(bool is_hung) override;

 private:
  void InstanceClosed(int32_t instance_id);

  RenderFrameHostImpl& render_frame_host() { return *render_frame_host_; }
  RenderProcessHostImpl* GetProcess();

  const raw_ref<RenderFrameHostImpl> render_frame_host_;

  mojo::AssociatedReceiver<mojom::PepperHost> receiver_{this};

  std::map<int32_t, std::unique_ptr<PepperPluginInstanceHost>>
      pepper_plugin_instances_;

  struct HungDetectorContext {
    int32_t plugin_child_id;
    const base::FilePath plugin_path;
  };
  mojo::ReceiverSet<mojom::PepperHungDetectorHost, HungDetectorContext>
      pepper_hung_detectors_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_FRAME_HOST_IMPL_PPAPI_SUPPORT_H_