summaryrefslogtreecommitdiffstats
path: root/chromium/content/renderer/pepper/host_resource_var.h
blob: b527696b4c609d814d4aa4a04df638dcff5f95fc (plain)
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
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_PEPPER_HOST_RESOURCE_VAR_H_
#define CONTENT_RENDERER_PEPPER_HOST_RESOURCE_VAR_H_

#include <memory>

#include "base/macros.h"
#include "ipc/ipc_message.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/shared_impl/resource_var.h"
#include "ppapi/shared_impl/var.h"

namespace content {

// Represents a resource var, usable on the host side. Can either have a
// plugin-side resource or a pending resource host.
class HostResourceVar : public ppapi::ResourceVar {
 public:
  // Makes a null resource var.
  HostResourceVar();

  // Makes a resource var with an existing plugin-side resource.
  explicit HostResourceVar(PP_Resource pp_resource);

  // Makes a resource var with a pending resource host.
  // The |pending_renderer_host_id| is a pending resource host ID in the
  // renderer to attach from the plugin. Depending on the type of resource, this
  // may be 0. The |creation_message| contains additional data needed to create
  // the plugin-side resource. Its type depends on the type of resource.
  HostResourceVar(int pending_renderer_host_id,
                  const IPC::Message& creation_message);

  // ResourceVar override.
  PP_Resource GetPPResource() const override;
  int GetPendingRendererHostId() const override;
  int GetPendingBrowserHostId() const override;
  const IPC::Message* GetCreationMessage() const override;
  bool IsPending() const override;

  void set_pending_browser_host_id(int id) { pending_browser_host_id_ = id; }

 protected:
  ~HostResourceVar() override;

 private:
  // Real resource ID in the plugin. 0 if one has not yet been created
  // (indicating that there is a pending resource host).
  PP_Resource pp_resource_;

  // Pending resource host ID in the renderer.
  int pending_renderer_host_id_;

  // Pending resource host ID in the browser.
  int pending_browser_host_id_;

  // If the plugin-side resource has not yet been created, carries a message to
  // create a resource of the specific type on the plugin side. Otherwise, NULL.
  std::unique_ptr<IPC::Message> creation_message_;

  DISALLOW_COPY_AND_ASSIGN(HostResourceVar);
};

}  // namespace content

#endif  // CONTENT_RENDERER_PEPPER_HOST_RESOURCE_VAR_H_