[PPAPI] It is now valid to store PP_Resource 0 in a ResourceVar.
Making a resource var from PP_Resource 0 results in an empty resource
var, instead of a null var. Fixed handling of NULL Resources in
PluginResourceVar.
BUG=177017
Review URL: https://codereview.chromium.org/26273008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228835 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ppapi/proxy/plugin_resource_var.cc b/ppapi/proxy/plugin_resource_var.cc
index 0ccff74..be4eec5b 100644
--- a/ppapi/proxy/plugin_resource_var.cc
+++ b/ppapi/proxy/plugin_resource_var.cc
@@ -10,7 +10,7 @@
: resource_(resource) {}
PP_Resource PluginResourceVar::GetPPResource() const {
- return resource_->pp_resource();
+ return resource_ ? resource_->pp_resource() : 0;
}
bool PluginResourceVar::IsPending() const {
diff --git a/ppapi/proxy/plugin_resource_var.h b/ppapi/proxy/plugin_resource_var.h
index b02718b6..42be66d2 100644
--- a/ppapi/proxy/plugin_resource_var.h
+++ b/ppapi/proxy/plugin_resource_var.h
@@ -31,6 +31,7 @@
virtual ~PluginResourceVar();
private:
+ // If NULL, this represents the PP_Resource 0.
scoped_refptr<ppapi::Resource> resource_;
DISALLOW_COPY_AND_ASSIGN(PluginResourceVar);
diff --git a/ppapi/proxy/plugin_var_tracker.cc b/ppapi/proxy/plugin_var_tracker.cc
index d4ab09d..0788b99 100644
--- a/ppapi/proxy/plugin_var_tracker.cc
+++ b/ppapi/proxy/plugin_var_tracker.cc
@@ -155,8 +155,13 @@
}
ResourceVar* PluginVarTracker::MakeResourceVar(PP_Resource pp_resource) {
+ // The resource 0 returns a null resource var.
+ if (!pp_resource)
+ return new PluginResourceVar();
+
ResourceTracker* resource_tracker = PpapiGlobals::Get()->GetResourceTracker();
ppapi::Resource* resource = resource_tracker->GetResource(pp_resource);
+ // A non-existant resource other than 0 returns NULL.
if (!resource)
return NULL;
return new PluginResourceVar(resource);
diff --git a/ppapi/shared_impl/var_tracker.h b/ppapi/shared_impl/var_tracker.h
index 379f645b..168fcb99 100644
--- a/ppapi/shared_impl/var_tracker.h
+++ b/ppapi/shared_impl/var_tracker.h
@@ -87,11 +87,17 @@
// Creates a new resource var that points to a given resource ID. Returns a
// PP_Var that references it and has an initial reference count of 1.
+ // If |pp_resource| is 0, returns a valid, empty resource var. On the plugin
+ // side (where it is possible to tell which resources exist), if |pp_resource|
+ // does not exist, returns a null var.
PP_Var MakeResourcePPVar(PP_Resource pp_resource);
// Creates a new resource var that points to a given resource ID. This is
// implemented by the host and plugin tracker separately, because the plugin
// keeps a reference to the resource, and the host does not.
+ // If |pp_resource| is 0, returns a valid, empty resource var. On the plugin
+ // side (where it is possible to tell which resources exist), if |pp_resource|
+ // does not exist, returns NULL.
virtual ResourceVar* MakeResourceVar(PP_Resource pp_resource) = 0;
// Return a vector containing all PP_Vars that are in the tracker. This is