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