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
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112

content / renderer / pepper / host_globals.h [blame]

// Copyright 2012 The Chromium Authors
// 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_GLOBALS_H_
#define CONTENT_RENDERER_PEPPER_HOST_GLOBALS_H_

#include "content/renderer/pepper/host_var_tracker.h"
#include "ppapi/shared_impl/callback_tracker.h"
#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/resource_tracker.h"
#include "ppapi/shared_impl/var_tracker.h"

namespace content {

class PepperPluginInstanceImpl;
class PluginModule;

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

  HostGlobals(const HostGlobals&) = delete;
  HostGlobals& operator=(const HostGlobals&) = delete;

  ~HostGlobals() override;

  // 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() {
    DCHECK(PpapiGlobals::Get()->IsHostGlobals());
    return static_cast<HostGlobals*>(PpapiGlobals::Get());
  }

  // PpapiGlobals implementation.
  ppapi::ResourceTracker* GetResourceTracker() override;
  ppapi::VarTracker* GetVarTracker() override;
  ppapi::CallbackTracker* GetCallbackTrackerForInstance(
      PP_Instance instance) override;
  ppapi::thunk::PPB_Instance_API* GetInstanceAPI(PP_Instance instance) override;
  ppapi::thunk::ResourceCreationAPI* GetResourceCreationAPI(
      PP_Instance instance) override;
  PP_Module GetModuleForInstance(PP_Instance instance) override;
  void LogWithSource(PP_Instance instance,
                     PP_LogLevel level,
                     const std::string& source,
                     const std::string& value) override;
  void BroadcastLogWithSource(PP_Module module,
                              PP_LogLevel level,
                              const std::string& source,
                              const std::string& value) override;
  ppapi::MessageLoopShared* GetCurrentMessageLoop() override;
  base::TaskRunner* GetFileTaskRunner() override;

  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(PepperPluginInstanceImpl* 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.
  PepperPluginInstanceImpl* GetInstance(PP_Instance instance);

 private:
  // PpapiGlobals overrides.
  bool IsHostGlobals() const override;

  static HostGlobals* host_globals_;

  ppapi::ResourceTracker resource_tracker_;
  HostVarTracker host_var_tracker_;

  // Tracks all live instances and their associated object.
  typedef std::map<PP_Instance, PepperPluginInstanceImpl*> 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_;

  scoped_refptr<base::TaskRunner> file_task_runner_;
};

}  // namespace content

#endif  // CONTENT_RENDERER_PEPPER_HOST_GLOBALS_H_