summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/host_globals.h
blob: 51b782717a01f6e6709b20381c8d8224a558c068 (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
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
98
99
100
101
// Copyright (c) 2011 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 WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_
#define WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_

#include "base/compiler_specific.h"
#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/var_tracker.h"
#include "webkit/plugins/ppapi/host_resource_tracker.h"
#include "webkit/plugins/ppapi/host_var_tracker.h"
#include "webkit/plugins/webkit_plugins_export.h"

namespace webkit {
namespace ppapi {

class PluginInstance;
class PluginModule;

class HostGlobals : public ::ppapi::PpapiGlobals {
 public:
  HostGlobals();
  virtual ~HostGlobals();

  // Getter for the global singleton. Generally, you should use
  // PpapiGlobals::Get() when possible. Use this only when you need some
  // host-specific functionality.
  inline static HostGlobals* Get() { return host_globals_; }

  // PpapiGlobals implementation.
  virtual ::ppapi::ResourceTracker* GetResourceTracker() OVERRIDE;
  virtual ::ppapi::VarTracker* GetVarTracker() OVERRIDE;
  virtual ::ppapi::FunctionGroupBase* GetFunctionAPI(
      PP_Instance inst,
      ::ppapi::ApiID id) OVERRIDE;
  virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE;

  HostResourceTracker* host_resource_tracker() {
    return &host_resource_tracker_;
  }
  HostVarTracker* host_var_tracker() {
    return &host_var_tracker_;
  }

  // PP_Modules ----------------------------------------------------------------

  // Adds a new plugin module to the list of tracked module, and returns a new
  // module handle to identify it.
  PP_Module AddModule(PluginModule* module);

  // Called when a plugin modulde was deleted and should no longer be tracked.
  // The given handle should be one generated by AddModule.
  void ModuleDeleted(PP_Module module);

  // Returns a pointer to the plugin modulde object associated with the given
  // modulde handle. The return value will be NULL if the handle is invalid.
  PluginModule* GetModule(PP_Module module);

  // PP_Instances --------------------------------------------------------------

  // Adds a new plugin instance to the list of tracked instances, and returns a
  // new instance handle to identify it.
  PP_Instance AddInstance(PluginInstance* instance);

  // Called when a plugin instance was deleted and should no longer be tracked.
  // The given handle should be one generated by AddInstance.
  void InstanceDeleted(PP_Instance instance);

  void InstanceCrashed(PP_Instance instance);

  // Returns a pointer to the plugin instance object associated with the given
  // instance handle. The return value will be NULL if the handle is invalid or
  // if the instance has crashed.
  WEBKIT_PLUGINS_EXPORT PluginInstance* GetInstance(PP_Instance instance);

 private:
  // Per-instance data we track.
  struct InstanceData;

  WEBKIT_PLUGINS_EXPORT static HostGlobals* host_globals_;

  HostResourceTracker host_resource_tracker_;
  HostVarTracker host_var_tracker_;

  // Tracks all live instances and their associated data.
  typedef std::map<PP_Instance, linked_ptr<InstanceData> > InstanceMap;
  InstanceMap instance_map_;

  // Tracks all live modules. The pointers are non-owning, the PluginModule
  // destructor will notify us when the module is deleted.
  typedef std::map<PP_Module, PluginModule*> ModuleMap;
  ModuleMap module_map_;

  DISALLOW_COPY_AND_ASSIGN(HostGlobals);
};

}  // namespace ppapi
}  // namespace webkit

#endif   // WEBKIT_PLUGINS_PPAPI_HOST_GLOBALS_H_