Index: content/renderer/pepper/host_var_tracker.h |
diff --git a/content/renderer/pepper/host_var_tracker.h b/content/renderer/pepper/host_var_tracker.h |
index a5518c8033805904a182d9001353a0540ee654ea..8d8176a7c6eb2846b6000451b89dfa4b2d3b0940 100644 |
--- a/content/renderer/pepper/host_var_tracker.h |
+++ b/content/renderer/pepper/host_var_tracker.h |
@@ -20,30 +20,52 @@ |
#include "ppapi/shared_impl/var_tracker.h" |
#include "v8/include/v8.h" |
+typedef struct NPObject NPObject; |
+ |
namespace ppapi { |
class ArrayBufferVar; |
+class NPObjectVar; |
class V8ObjectVar; |
class Var; |
} |
namespace content { |
+// Adds NPObject var tracking to the standard PPAPI VarTracker for use in the |
+// renderer. |
class HostVarTracker : public ppapi::VarTracker { |
public: |
HostVarTracker(); |
virtual ~HostVarTracker(); |
+ // Tracks all live NPObjectVar. This is so we can map between instance + |
+ // NPObject and get the NPObjectVar corresponding to it. This Add/Remove |
+ // function is called by the NPObjectVar when it is created and |
+ // destroyed. |
+ void AddNPObjectVar(ppapi::NPObjectVar* object_var); |
+ void RemoveNPObjectVar(ppapi::NPObjectVar* object_var); |
+ |
+ // Looks up a previously registered NPObjectVar for the given NPObject and |
+ // instance. Returns NULL if there is no NPObjectVar corresponding to the |
+ // given NPObject for the given instance. See AddNPObjectVar above. |
+ ppapi::NPObjectVar* NPObjectVarForNPObject(PP_Instance instance, |
+ NPObject* np_object); |
+ |
+ // Returns the number of NPObjectVar's associated with the given instance. |
+ // Returns 0 if the instance isn't known. |
+ CONTENT_EXPORT int GetLiveNPObjectVarsForInstance(PP_Instance instance) const; |
+ |
// Tracks all live V8ObjectVar. This is so we can map between instance + |
// V8Object and get the V8ObjectVar corresponding to it. This Add/Remove |
// function is called by the V8ObjectVar when it is created and destroyed. |
- void AddV8ObjectVar(ppapi::V8ObjectVar* object_var); |
- void RemoveV8ObjectVar(ppapi::V8ObjectVar* object_var); |
+ void AddV8ObjectVar(ppapi::V8ObjectVar* object_var) { NOTIMPLEMENTED(); } |
+ void RemoveV8ObjectVar(ppapi::V8ObjectVar* object_var) { NOTIMPLEMENTED(); } |
// Creates or retrieves a V8ObjectVar. |
PP_Var V8ObjectVarForV8Object(PP_Instance instance, |
- v8::Handle<v8::Object> object); |
- // Returns the number of V8ObjectVars associated with the given instance. |
- // Returns 0 if the instance isn't known. |
- CONTENT_EXPORT int GetLiveV8ObjectVarsForTest(PP_Instance instance); |
+ v8::Handle<v8::Object> object) { |
+ NOTIMPLEMENTED(); |
+ return PP_MakeUndefined(); |
+ } |
// VarTracker public implementation. |
virtual PP_Var MakeResourcePPVarFromMessage( |
@@ -52,7 +74,7 @@ |
int pending_renderer_id, |
int pending_browser_id) OVERRIDE; |
virtual ppapi::ResourceVar* MakeResourceVar(PP_Resource pp_resource) OVERRIDE; |
- virtual void DidDeleteInstance(PP_Instance pp_instance) OVERRIDE; |
+ virtual void DidDeleteInstance(PP_Instance instance) OVERRIDE; |
virtual int TrackSharedMemoryHandle(PP_Instance instance, |
base::SharedMemoryHandle file, |
@@ -72,30 +94,20 @@ |
// Clear the reference count of the given object and remove it from |
// live_vars_. |
- void ForceReleaseV8Object(ppapi::V8ObjectVar* object_var); |
+ void ForceReleaseNPObject(ppapi::NPObjectVar* object_var); |
- // A non-unique, ordered key for a V8ObjectVar. Contains the hash of the v8 |
- // and the instance it is associated with. |
- struct V8ObjectVarKey { |
- explicit V8ObjectVarKey(ppapi::V8ObjectVar* object_var); |
- V8ObjectVarKey(PP_Instance i, v8::Handle<v8::Object> object); |
- ~V8ObjectVarKey(); |
+ typedef std::map<NPObject*, ppapi::NPObjectVar*> NPObjectToNPObjectVarMap; |
- bool operator<(const V8ObjectVarKey& other) const; |
- |
- PP_Instance instance; |
- int hash; |
- }; |
- typedef std::multimap<V8ObjectVarKey, ppapi::V8ObjectVar*> ObjectMap; |
- |
- // Returns an iterator into |object_map| which points to V8Object which |
- // is associated with the given instance and object. |
- ObjectMap::iterator GetForV8Object(PP_Instance instance, |
- v8::Handle<v8::Object> object); |
- |
- |
- // A multimap of V8ObjectVarKey -> ObjectMap. |
- ObjectMap object_map_; |
+ // Lists all known NPObjects, first indexed by the corresponding instance, |
+ // then by the NPObject*. This allows us to look up an NPObjectVar given |
+ // these two pieces of information. |
+ // |
+ // The instance map is lazily managed, so we'll add the |
+ // NPObjectToNPObjectVarMap lazily when the first NPObject var is created, |
+ // and delete it when it's empty. |
+ typedef std::map<PP_Instance, linked_ptr<NPObjectToNPObjectVarMap> > |
+ InstanceMap; |
+ InstanceMap instance_map_; |
// Tracks all shared memory handles used for transmitting array buffers. |
struct SharedMemoryMapEntry { |