Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / pepper / host_globals.h
blob9ce071cc0b1d78bdb895501c881d588ea2bc7d1d
1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_RENDERER_PEPPER_HOST_GLOBALS_H_
6 #define CONTENT_RENDERER_PEPPER_HOST_GLOBALS_H_
8 #include "base/compiler_specific.h"
9 #include "content/renderer/pepper/host_var_tracker.h"
10 #include "ppapi/shared_impl/callback_tracker.h"
11 #include "ppapi/shared_impl/ppapi_globals.h"
12 #include "ppapi/shared_impl/resource_tracker.h"
13 #include "ppapi/shared_impl/var_tracker.h"
15 namespace content {
17 class PepperPluginInstanceImpl;
18 class PluginModule;
20 class HostGlobals : public ppapi::PpapiGlobals {
21 public:
22 HostGlobals();
23 ~HostGlobals() override;
25 // Getter for the global singleton. Generally, you should use
26 // PpapiGlobals::Get() when possible. Use this only when you need some
27 // host-specific functionality.
28 inline static HostGlobals* Get() {
29 DCHECK(PpapiGlobals::Get()->IsHostGlobals());
30 return static_cast<HostGlobals*>(PpapiGlobals::Get());
33 // PpapiGlobals implementation.
34 ppapi::ResourceTracker* GetResourceTracker() override;
35 ppapi::VarTracker* GetVarTracker() override;
36 ppapi::CallbackTracker* GetCallbackTrackerForInstance(
37 PP_Instance instance) override;
38 ppapi::thunk::PPB_Instance_API* GetInstanceAPI(PP_Instance instance) override;
39 ppapi::thunk::ResourceCreationAPI* GetResourceCreationAPI(
40 PP_Instance instance) override;
41 PP_Module GetModuleForInstance(PP_Instance instance) override;
42 std::string GetCmdLine() override;
43 void PreCacheFontForFlash(const void* logfontw) override;
44 void LogWithSource(PP_Instance instance,
45 PP_LogLevel level,
46 const std::string& source,
47 const std::string& value) override;
48 void BroadcastLogWithSource(PP_Module module,
49 PP_LogLevel level,
50 const std::string& source,
51 const std::string& value) override;
52 ppapi::MessageLoopShared* GetCurrentMessageLoop() override;
53 base::TaskRunner* GetFileTaskRunner() override;
55 HostVarTracker* host_var_tracker() { return &host_var_tracker_; }
57 // PP_Modules ----------------------------------------------------------------
59 // Adds a new plugin module to the list of tracked module, and returns a new
60 // module handle to identify it.
61 PP_Module AddModule(PluginModule* module);
63 // Called when a plugin modulde was deleted and should no longer be tracked.
64 // The given handle should be one generated by AddModule.
65 void ModuleDeleted(PP_Module module);
67 // Returns a pointer to the plugin modulde object associated with the given
68 // modulde handle. The return value will be NULL if the handle is invalid.
69 PluginModule* GetModule(PP_Module module);
71 // PP_Instances --------------------------------------------------------------
73 // Adds a new plugin instance to the list of tracked instances, and returns a
74 // new instance handle to identify it.
75 PP_Instance AddInstance(PepperPluginInstanceImpl* instance);
77 // Called when a plugin instance was deleted and should no longer be tracked.
78 // The given handle should be one generated by AddInstance.
79 void InstanceDeleted(PP_Instance instance);
81 void InstanceCrashed(PP_Instance instance);
83 // Returns a pointer to the plugin instance object associated with the given
84 // instance handle. The return value will be NULL if the handle is invalid or
85 // if the instance has crashed.
86 PepperPluginInstanceImpl* GetInstance(PP_Instance instance);
88 private:
89 // PpapiGlobals overrides.
90 bool IsHostGlobals() const override;
92 static HostGlobals* host_globals_;
94 ppapi::ResourceTracker resource_tracker_;
95 HostVarTracker host_var_tracker_;
97 // Tracks all live instances and their associated object.
98 typedef std::map<PP_Instance, PepperPluginInstanceImpl*> InstanceMap;
99 InstanceMap instance_map_;
101 // Tracks all live modules. The pointers are non-owning, the PluginModule
102 // destructor will notify us when the module is deleted.
103 typedef std::map<PP_Module, PluginModule*> ModuleMap;
104 ModuleMap module_map_;
106 DISALLOW_COPY_AND_ASSIGN(HostGlobals);
109 } // namespace content
111 #endif // CONTENT_RENDERER_PEPPER_HOST_GLOBALS_H_