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. 4 5 #ifndef CONTENT_RENDERER_PEPPER_HOST_GLOBALS_H_ 6 #define CONTENT_RENDERER_PEPPER_HOST_GLOBALS_H_ 7 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" 14 15 namespace content { 16 17 class PepperPluginInstanceImpl; 18 class PluginModule; 19 20 class HostGlobals : public ppapi::PpapiGlobals { 21 public: 22 HostGlobals(); 23 virtual ~HostGlobals(); 24 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()); 31 } 32 33 // PpapiGlobals implementation. 34 virtual ppapi::ResourceTracker* GetResourceTracker() OVERRIDE; 35 virtual ppapi::VarTracker* GetVarTracker() OVERRIDE; 36 virtual ppapi::CallbackTracker* GetCallbackTrackerForInstance( 37 PP_Instance instance) OVERRIDE; 38 virtual ppapi::thunk::PPB_Instance_API* GetInstanceAPI( 39 PP_Instance instance) OVERRIDE; 40 virtual ppapi::thunk::ResourceCreationAPI* GetResourceCreationAPI( 41 PP_Instance instance) OVERRIDE; 42 virtual PP_Module GetModuleForInstance(PP_Instance instance) OVERRIDE; 43 virtual std::string GetCmdLine() OVERRIDE; 44 virtual void PreCacheFontForFlash(const void* logfontw) OVERRIDE; 45 virtual void LogWithSource(PP_Instance instance, 46 PP_LogLevel level, 47 const std::string& source, 48 const std::string& value) OVERRIDE; 49 virtual void BroadcastLogWithSource(PP_Module module, 50 PP_LogLevel level, 51 const std::string& source, 52 const std::string& value) OVERRIDE; 53 virtual ppapi::MessageLoopShared* GetCurrentMessageLoop() OVERRIDE; 54 virtual base::TaskRunner* GetFileTaskRunner() OVERRIDE; 55 56 HostVarTracker* host_var_tracker() { 57 return &host_var_tracker_; 58 } 59 60 // PP_Modules ---------------------------------------------------------------- 61 62 // Adds a new plugin module to the list of tracked module, and returns a new 63 // module handle to identify it. 64 PP_Module AddModule(PluginModule* module); 65 66 // Called when a plugin modulde was deleted and should no longer be tracked. 67 // The given handle should be one generated by AddModule. 68 void ModuleDeleted(PP_Module module); 69 70 // Returns a pointer to the plugin modulde object associated with the given 71 // modulde handle. The return value will be NULL if the handle is invalid. 72 PluginModule* GetModule(PP_Module module); 73 74 // PP_Instances -------------------------------------------------------------- 75 76 // Adds a new plugin instance to the list of tracked instances, and returns a 77 // new instance handle to identify it. 78 PP_Instance AddInstance(PepperPluginInstanceImpl* instance); 79 80 // Called when a plugin instance was deleted and should no longer be tracked. 81 // The given handle should be one generated by AddInstance. 82 void InstanceDeleted(PP_Instance instance); 83 84 void InstanceCrashed(PP_Instance instance); 85 86 // Returns a pointer to the plugin instance object associated with the given 87 // instance handle. The return value will be NULL if the handle is invalid or 88 // if the instance has crashed. 89 PepperPluginInstanceImpl* GetInstance(PP_Instance instance); 90 91 private: 92 // PpapiGlobals overrides. 93 virtual bool IsHostGlobals() const OVERRIDE; 94 95 static HostGlobals* host_globals_; 96 97 ppapi::ResourceTracker resource_tracker_; 98 HostVarTracker host_var_tracker_; 99 100 // Tracks all live instances and their associated object. 101 typedef std::map<PP_Instance, PepperPluginInstanceImpl*> InstanceMap; 102 InstanceMap instance_map_; 103 104 // Tracks all live modules. The pointers are non-owning, the PluginModule 105 // destructor will notify us when the module is deleted. 106 typedef std::map<PP_Module, PluginModule*> ModuleMap; 107 ModuleMap module_map_; 108 109 DISALLOW_COPY_AND_ASSIGN(HostGlobals); 110 }; 111 112 } // namespace content 113 114 #endif // CONTENT_RENDERER_PEPPER_HOST_GLOBALS_H_ 115