diff options
author | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-12 11:11:20 +0000 |
---|---|---|
committer | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-12 11:11:20 +0000 |
commit | 424bf6b47ba02d4000ea75ff1cb1a0bc4f9e118c (patch) | |
tree | b0082e3c27d47ac7efb831798ad60d62d7b1177a /ppapi | |
parent | cb1e98ad27d7a51a8eff148872767795305453cf (diff) | |
download | chromium_src-424bf6b47ba02d4000ea75ff1cb1a0bc4f9e118c.zip chromium_src-424bf6b47ba02d4000ea75ff1cb1a0bc4f9e118c.tar.gz chromium_src-424bf6b47ba02d4000ea75ff1cb1a0bc4f9e118c.tar.bz2 |
[PPAPI] Added PP_VARTYPE_RESOURCE as a PP_VarType enum value.
This type is not yet useful. There is currently no way to generate one
of these. If the plugin manually builds one and sends it in a message,
it will currently check-fail, crashing the plugin.
BUG=177017
Review URL: https://chromiumcodereview.appspot.com/18599005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222759 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/api/pp_var.idl | 21 | ||||
-rw-r--r-- | ppapi/c/pp_var.h | 22 | ||||
-rw-r--r-- | ppapi/proxy/raw_var_data.cc | 5 | ||||
-rw-r--r-- | ppapi/shared_impl/resource_var.cc | 17 | ||||
-rw-r--r-- | ppapi/shared_impl/unittest_utils.cc | 34 | ||||
-rw-r--r-- | ppapi/shared_impl/var.cc | 15 | ||||
-rw-r--r-- | ppapi/shared_impl/var_value_conversions.cc | 3 |
7 files changed, 96 insertions, 21 deletions
diff --git a/ppapi/api/pp_var.idl b/ppapi/api/pp_var.idl index aeeb7bf..425d99b 100644 --- a/ppapi/api/pp_var.idl +++ b/ppapi/api/pp_var.idl @@ -81,7 +81,14 @@ enum PP_VarType { * ArrayBuffer vars. These objects are reference counted, so AddRef and * Release must be used properly to avoid memory leaks. */ - PP_VARTYPE_ARRAY_BUFFER = 9 + PP_VARTYPE_ARRAY_BUFFER = 9, + + /** + * Resources are not currently supported but will be added in the future + * These objects are reference counted, so AddRef and Release must be used + * properly to avoid memory leaks. + */ + PP_VARTYPE_RESOURCE = 10 }; @@ -113,12 +120,12 @@ enum PP_VarType { /** * If <code>type</code> is <code>PP_VARTYPE_STRING</code>, - * <code>PP_VARTYPE_OBJECT</code>, <code>PP_VARTYPE_ARRAY</code>, or - * <code>PP_VARTYPE_DICTIONARY</code>, - * <code>as_id</code> represents the value of this <code>PP_Var</code> as - * an opaque handle assigned by the browser. This handle is guaranteed - * never to be 0, so a module can initialize this ID to 0 to indicate a - * "NULL handle." + * <code>PP_VARTYPE_OBJECT</code>, <code>PP_VARTYPE_ARRAY</code>, + * <code>PP_VARTYPE_DICTIONARY</code>, <code>PP_VARTYPE_ARRAY_BUFFER</code>, + * or <code>PP_VARTYPE_RESOURCE</code>, <code>as_id</code> represents the + * value of this <code>PP_Var</code> as an opaque handle assigned by the + * browser. This handle is guaranteed never to be 0, so a module can + * initialize this ID to 0 to indicate a "NULL handle." */ int64_t as_id; }; diff --git a/ppapi/c/pp_var.h b/ppapi/c/pp_var.h index f492fbb..0648c65 100644 --- a/ppapi/c/pp_var.h +++ b/ppapi/c/pp_var.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From pp_var.idl modified Wed Sep 4 10:11:31 2013. */ +/* From pp_var.idl modified Thu Sep 12 16:41:36 2013. */ #ifndef PPAPI_C_PP_VAR_H_ #define PPAPI_C_PP_VAR_H_ @@ -86,7 +86,13 @@ typedef enum { * ArrayBuffer vars. These objects are reference counted, so AddRef and * Release must be used properly to avoid memory leaks. */ - PP_VARTYPE_ARRAY_BUFFER = 9 + PP_VARTYPE_ARRAY_BUFFER = 9, + /** + * Resources are not currently supported but will be added in the future + * These objects are reference counted, so AddRef and Release must be used + * properly to avoid memory leaks. + */ + PP_VARTYPE_RESOURCE = 10 } PP_VarType; PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); /** @@ -122,12 +128,12 @@ union PP_VarValue { double as_double; /** * If <code>type</code> is <code>PP_VARTYPE_STRING</code>, - * <code>PP_VARTYPE_OBJECT</code>, <code>PP_VARTYPE_ARRAY</code>, or - * <code>PP_VARTYPE_DICTIONARY</code>, - * <code>as_id</code> represents the value of this <code>PP_Var</code> as - * an opaque handle assigned by the browser. This handle is guaranteed - * never to be 0, so a module can initialize this ID to 0 to indicate a - * "NULL handle." + * <code>PP_VARTYPE_OBJECT</code>, <code>PP_VARTYPE_ARRAY</code>, + * <code>PP_VARTYPE_DICTIONARY</code>, <code>PP_VARTYPE_ARRAY_BUFFER</code>, + * or <code>PP_VARTYPE_RESOURCE</code>, <code>as_id</code> represents the + * value of this <code>PP_Var</code> as an opaque handle assigned by the + * browser. This handle is guaranteed never to be 0, so a module can + * initialize this ID to 0 to indicate a "NULL handle." */ int64_t as_id; }; diff --git a/ppapi/proxy/raw_var_data.cc b/ppapi/proxy/raw_var_data.cc index a550c3f..b413048 100644 --- a/ppapi/proxy/raw_var_data.cc +++ b/ppapi/proxy/raw_var_data.cc @@ -240,6 +240,11 @@ RawVarData* RawVarData::Create(PP_VarType type) { return new ArrayRawVarData(); case PP_VARTYPE_DICTIONARY: return new DictionaryRawVarData(); + case PP_VARTYPE_RESOURCE: + // TODO(mgiuca): Add ResourceRawVarData. (http://crbug.com/177017) + // This path will be reached if a NaCl module attempts to pass a + // PP_VARTYPE_RESOURCE in a message. + break; } NOTREACHED(); return NULL; diff --git a/ppapi/shared_impl/resource_var.cc b/ppapi/shared_impl/resource_var.cc index 61709119..7936e70 100644 --- a/ppapi/shared_impl/resource_var.cc +++ b/ppapi/shared_impl/resource_var.cc @@ -4,6 +4,9 @@ #include "ppapi/shared_impl/resource_var.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/var_tracker.h" + namespace ppapi { ResourceVar::ResourceVar() : pp_resource_(0) {} @@ -21,16 +24,18 @@ ResourceVar* ResourceVar::AsResourceVar() { } PP_VarType ResourceVar::GetType() const { - // TODO(mgiuca): Return PP_VARTYPE_RESOURCE, once that is a valid enum value. - NOTREACHED(); - return PP_VARTYPE_UNDEFINED; + return PP_VARTYPE_RESOURCE; } // static ResourceVar* ResourceVar::FromPPVar(PP_Var var) { - // TODO(mgiuca): Implement this function, once PP_VARTYPE_RESOURCE is - // introduced. - return NULL; + if (var.type != PP_VARTYPE_RESOURCE) + return NULL; + scoped_refptr<Var> var_object( + PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); + if (!var_object.get()) + return NULL; + return var_object->AsResourceVar(); } } // namespace ppapi diff --git a/ppapi/shared_impl/unittest_utils.cc b/ppapi/shared_impl/unittest_utils.cc index f5d064b..f613882 100644 --- a/ppapi/shared_impl/unittest_utils.cc +++ b/ppapi/shared_impl/unittest_utils.cc @@ -10,6 +10,7 @@ #include "base/logging.h" #include "ppapi/shared_impl/array_var.h" #include "ppapi/shared_impl/dictionary_var.h" +#include "ppapi/shared_impl/resource_var.h" #include "ppapi/shared_impl/var.h" #include "ppapi/shared_impl/var_tracker.h" @@ -151,6 +152,39 @@ bool Equals(const PP_Var& expected, } return true; } + case PP_VARTYPE_RESOURCE: { + ResourceVar* expected_var = ResourceVar::FromPPVar(expected); + ResourceVar* actual_var = ResourceVar::FromPPVar(actual); + DCHECK(expected_var && actual_var); + if (expected_var->pp_resource() != actual_var->pp_resource()) { + LOG(ERROR) << "expected: " << expected_var->pp_resource() << " actual: " + << actual_var->pp_resource(); + return false; + } + IPC::Message actual_message(actual_var->creation_message()); + const IPC::Message& expected_message = expected_var->creation_message(); + if (expected_message.size() != actual_message.size()) { + LOG(ERROR) << "expected creation message size: " + << expected_message.size() << " actual: " + << actual_message.size(); + return false; + } + + // Set the upper 24 bits of actual creation_message flags to the same as + // expected. This is an unpredictable reference number that changes + // between serialization/deserialization, and we do not want it to cause + // the comparison to fail. + actual_message.SetHeaderValues(actual_message.routing_id(), + actual_message.type(), + (expected_message.flags() & 0xffffff00) | + (actual_message.flags() & 0xff)); + if (memcmp(expected_message.data(), actual_message.data(), + expected_message.size()) != 0) { + LOG(ERROR) << "expected creation message does not match actual."; + return false; + } + return true; + } } NOTREACHED(); return false; diff --git a/ppapi/shared_impl/var.cc b/ppapi/shared_impl/var.cc index e311b3c..f173701 100644 --- a/ppapi/shared_impl/var.cc +++ b/ppapi/shared_impl/var.cc @@ -9,8 +9,10 @@ #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" +#include "base/strings/stringprintf.h" #include "ppapi/c/pp_var.h" #include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/resource_var.h" #include "ppapi/shared_impl/var_tracker.h" namespace ppapi { @@ -62,6 +64,19 @@ std::string Var::PPVarToLogString(PP_Var var) { return "[Dictionary]"; case PP_VARTYPE_ARRAY_BUFFER: return "[Array buffer]"; + case PP_VARTYPE_RESOURCE: { + ResourceVar* resource(ResourceVar::FromPPVar(var)); + if (!resource) + return "[Invalid resource]"; + + if (resource->pp_resource()) { + return base::StringPrintf("[Resource %d]", resource->pp_resource()); + } else if (resource->creation_message().type() != 0) { + return base::StringPrintf("[Pending resource]"); + } else { + return "[Null resource]"; + } + } default: return "[Invalid var]"; } diff --git a/ppapi/shared_impl/var_value_conversions.cc b/ppapi/shared_impl/var_value_conversions.cc index 46f3161..e3a5bdd 100644 --- a/ppapi/shared_impl/var_value_conversions.cc +++ b/ppapi/shared_impl/var_value_conversions.cc @@ -131,6 +131,9 @@ bool CreateValueFromVarHelper(const std::set<int64_t>& parent_ids, value->reset(binary_value); return true; } + case PP_VARTYPE_RESOURCE: { + return false; + } } NOTREACHED(); return false; |