summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/var.h
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-15 03:44:13 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-15 03:44:13 +0000
commit859a7f3a9264b3a2174e9625d6cfa20412ac6081 (patch)
treeb9911798925fbff065346fa6c085b254d7fb2e55 /webkit/plugins/ppapi/var.h
parentf615770cd0412b2524b8b4451e6518608af9abed (diff)
downloadchromium_src-859a7f3a9264b3a2174e9625d6cfa20412ac6081.zip
chromium_src-859a7f3a9264b3a2174e9625d6cfa20412ac6081.tar.gz
chromium_src-859a7f3a9264b3a2174e9625d6cfa20412ac6081.tar.bz2
Make PP_Resources associated with the Instance rather than the module. This
adds PP_Instance to the necessary places in the API to make this possible. String and Object vars used to be PP_Resources. But it is not practical to assocaited strings with an instance since then we can't have implicit var constructors and have to litter every string with an instance. So this changes vars to use their own tracking system associated with the module (i.e. keeping the current semantics) and making it no longer a resource. I made the internal Var IDs 32 bits since Neb is about to land his 64->32 change. Now it force-deletes resources associated with an instance when that instance goes away. I added some additional code and tracking in ResourceTracker to do this. I could then remove the Instance::Observer class since the resource can use the (now renamed) StoppedTracking to know that it's being deleted in response to the instance being destroyed. TEST=ppapi ui tests BUG=none git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71544 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi/var.h')
-rw-r--r--webkit/plugins/ppapi/var.h46
1 files changed, 34 insertions, 12 deletions
diff --git a/webkit/plugins/ppapi/var.h b/webkit/plugins/ppapi/var.h
index 8f74733..ef3613f 100644
--- a/webkit/plugins/ppapi/var.h
+++ b/webkit/plugins/ppapi/var.h
@@ -7,7 +7,8 @@
#include <string>
-#include "webkit/plugins/ppapi/resource.h"
+#include "base/compiler_specific.h"
+#include "base/ref_counted.h"
struct PP_Var;
struct PPB_Var;
@@ -19,18 +20,20 @@ typedef void* NPIdentifier;
namespace webkit {
namespace ppapi {
+class ObjectVar;
+class PluginInstance;
+class PluginModule;
+class StringVar;
+
// Var -------------------------------------------------------------------------
// Represents a non-POD var. This is derived from a resource even though it
// isn't a resource from the plugin's perspective. This allows us to re-use
// the refcounting and the association with the module from the resource code.
-class Var : public Resource {
+class Var : public base::RefCounted<Var> {
public:
virtual ~Var();
- // Resource overrides.
- virtual Var* AsVar();
-
// Returns a PP_Var that corresponds to the given NPVariant. The contents of
// the NPVariant will be copied unless the NPVariant corresponds to an
// object. This will handle all Variant types including POD, strings, and
@@ -38,7 +41,7 @@ class Var : public Resource {
//
// The returned PP_Var will have a refcount of 1, this passing ownership of
// the reference to the caller. This is suitable for returning to a plugin.
- static PP_Var NPVariantToPPVar(PluginModule* module,
+ static PP_Var NPVariantToPPVar(PluginInstance* instance,
const NPVariant* variant);
// Returns a NPIdentifier that corresponds to the given PP_Var. The contents
@@ -87,11 +90,26 @@ class Var : public Resource {
// Returns the PPB_Var interface for the plugin to use.
static const PPB_Var* GetInterface();
+ virtual StringVar* AsStringVar();
+ virtual ObjectVar* AsObjectVar();
+
+ PluginModule* module() const { return module_; }
+
+ // Returns the unique ID associated with this string or object. The object
+ // must be a string or an object var, and the return value is guaranteed
+ // nonzero.
+ int32 GetID();
+
protected:
// This can only be constructed as a StringVar or an ObjectVar.
explicit Var(PluginModule* module);
private:
+ PluginModule* module_;
+
+ // This will be 0 if no ID has been assigned (this happens lazily).
+ int32 var_id_;
+
DISALLOW_COPY_AND_ASSIGN(Var);
};
@@ -114,8 +132,8 @@ class StringVar : public Var {
const std::string& value() const { return value_; }
- // Resource overrides.
- virtual StringVar* AsStringVar();
+ // Var override.
+ virtual StringVar* AsStringVar() OVERRIDE;
// Helper function to create a PP_Var of type string that contains a copy of
// the given string. The input data must be valid UTF-8 encoded text, if it
@@ -154,8 +172,8 @@ class ObjectVar : public Var {
public:
virtual ~ObjectVar();
- // Resource overrides.
- virtual ObjectVar* AsObjectVar();
+ // Var overrides.
+ virtual ObjectVar* AsObjectVar() OVERRIDE;
// Returns the underlying NPObject corresponding to this ObjectVar.
// Guaranteed non-NULL.
@@ -172,19 +190,23 @@ class ObjectVar : public Var {
//
// If no ObjectVar currently exists corresponding to the NPObject, one is
// created associated with the given module.
- static PP_Var NPObjectToPPVar(PluginModule* module, NPObject* object);
+ static PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object);
// Helper function that converts a PP_Var to an object. This will return NULL
// if the PP_Var is not of object type or the object is invalid.
static scoped_refptr<ObjectVar> FromPPVar(PP_Var var);
+ PluginInstance* instance() const { return instance_; }
+
protected:
// You should always use FromNPObject to create an ObjectVar. This function
// guarantees that we maintain the 1:1 mapping between NPObject and
// ObjectVar.
- ObjectVar(PluginModule* module, NPObject* np_object);
+ ObjectVar(PluginInstance* instance, NPObject* np_object);
private:
+ PluginInstance* instance_;
+
// Guaranteed non-NULL, this is the underlying object used by WebKit. We
// hold a reference to this object.
NPObject* np_object_;