summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-06 00:09:55 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-06 00:09:55 +0000
commit07527716f66bd893be3d3ae4d6d015bae2b701d2 (patch)
tree88824882b5311d718cbb0638b28ad9ded9c7aede /ppapi
parent647b168bee6edbd4667200497a9d7ca45fc01c91 (diff)
downloadchromium_src-07527716f66bd893be3d3ae4d6d015bae2b701d2.zip
chromium_src-07527716f66bd893be3d3ae4d6d015bae2b701d2.tar.gz
chromium_src-07527716f66bd893be3d3ae4d6d015bae2b701d2.tar.bz2
Proxy PPB_ArrayBuffer_Dev, make them work over Messaging
BUG=103435 TEST= Review URL: http://codereview.chromium.org/9022021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116594 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h45
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc9
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h5
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc79
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc7
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h4
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc4
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc57
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.h6
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/proxy_var_cache.h8
-rw-r--r--ppapi/native_client/src/shared/ppapi_proxy/string_proxy_var.h4
-rw-r--r--ppapi/tests/test_post_message.cc113
12 files changed, 265 insertions, 76 deletions
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h b/ppapi/native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h
new file mode 100644
index 0000000..b84914f
--- /dev/null
+++ b/ppapi/native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h
@@ -0,0 +1,45 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_ARRAY_BUFFER_PROXY_VAR_H_
+#define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_ARRAY_BUFFER_PROXY_VAR_H_
+
+#include "native_client/src/include/nacl_memory.h"
+#include "native_client/src/shared/ppapi_proxy/proxy_var.h"
+
+#include <vector>
+
+namespace ppapi_proxy {
+
+// Subclass of ProxyVar that handles ArrayBuffer objects.
+class ArrayBufferProxyVar : public ProxyVar {
+ public:
+ explicit ArrayBufferProxyVar(uint32_t size_in_bytes)
+ : ProxyVar(PP_VARTYPE_ARRAY_BUFFER), buffer_(size_in_bytes, 0) {}
+
+ void* buffer() { return buffer_.empty() ? NULL : &buffer_[0]; }
+ uint32_t buffer_length() const { return buffer_.size(); }
+
+ // Convenience function to do type checking and down-casting. This returns a
+ // scoped_refptr<>, so you don't have to down-cast the raw pointer.
+ static scoped_refptr<ArrayBufferProxyVar> CastFromProxyVar(
+ SharedProxyVar proxy_var) {
+ if (proxy_var == NULL ||
+ proxy_var->pp_var_type() != PP_VARTYPE_ARRAY_BUFFER) {
+ scoped_refptr<ArrayBufferProxyVar> null_ptr;
+ return null_ptr;
+ }
+ return scoped_refptr<ArrayBufferProxyVar>(
+ static_cast<ArrayBufferProxyVar*>(proxy_var.get()));
+ }
+
+ private:
+ std::vector<uint8_t> buffer_;
+};
+
+typedef scoped_refptr<ArrayBufferProxyVar> SharedArrayBufferProxyVar;
+
+} // namespace ppapi_proxy
+
+#endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_ARRAY_BUFFER_PROXY_VAR_H_
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc
index 5167dce..87e170e 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -311,6 +311,13 @@ const PPB_Var* PPBVarInterface() {
return ppb;
}
+const PPB_VarArrayBuffer_Dev* PPBVarArrayBufferInterface() {
+ static const PPB_VarArrayBuffer_Dev* ppb =
+ static_cast<const PPB_VarArrayBuffer_Dev*>(
+ GetBrowserInterfaceSafe(PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE));
+ return ppb;
+}
+
const PPB_WheelInputEvent* PPBWheelInputEventInterface() {
static const PPB_WheelInputEvent* ppb =
static_cast<const PPB_WheelInputEvent*>(
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h
index 122119e5..12d09aa 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h
+++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,7 +11,7 @@
#include "ppapi/c/dev/ppb_memory_dev.h"
#include "ppapi/c/dev/ppb_scrollbar_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
-#include "ppapi/c/dev/ppb_var_deprecated.h"
+#include "ppapi/c/dev/ppb_var_array_buffer_dev.h"
#include "ppapi/c/dev/ppb_widget_dev.h"
#include "ppapi/c/dev/ppb_zoom_dev.h"
#include "ppapi/c/pp_instance.h"
@@ -125,6 +125,7 @@ const PPB_URLLoader* PPBURLLoaderInterface();
const PPB_URLRequestInfo* PPBURLRequestInfoInterface();
const PPB_URLResponseInfo* PPBURLResponseInfoInterface();
const PPB_Var* PPBVarInterface(); // shared
+const PPB_VarArrayBuffer_Dev* PPBVarArrayBufferInterface(); // shared
const PPB_View* PPBViewInterface();
const PPB_WheelInputEvent* PPBWheelInputEventInterface();
const PPB_Widget_Dev* PPBWidgetInterface();
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc b/ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc
index 620058e..6edf78c 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/object_serialize.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 The Chromium Authors. All rights reserved.
+ * Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -42,7 +42,7 @@ struct SerializedFixed {
bool boolean_value;
// PP_VARTYPE_INT32 uses this.
int32_t int32_value;
- // PP_VARTYPE_STRING uses this.
+ // PP_VARTYPE_STRING and PP_VARTYPE_ARRAY_BUFFER use this.
uint32_t string_length;
} u;
// The size of this structure should be 8 bytes on all platforms.
@@ -54,8 +54,7 @@ struct SerializedDouble {
double double_value;
};
-// The structure used for PP_VARTYPE_STRING.
-
+// The structure used for PP_VARTYPE_STRING and PP_VARTYPE_ARRAYBUFFER.
struct SerializedString {
struct SerializedFixed fixed;
char string_bytes[kStringFixedBytes];
@@ -72,6 +71,10 @@ struct SerializedString {
ASSERT_TYPE_SIZE(SerializedFixed, 8);
ASSERT_TYPE_SIZE(SerializedDouble, 16);
ASSERT_TYPE_SIZE(SerializedString, 16);
+// IMPORTANT NOTE: SerializePpVar below assumes these sizes are multiples of 8,
+// otherwise the reinterpret_casts could cause alignment issues. New SerializedX
+// types should also be multiples of 8 bytes, or the SerializePpVar function
+// must be updated to enforce appropriate alignment.
//
// We currently use offsetof to find the start of string storage.
@@ -93,7 +96,7 @@ bool AddWouldOverflow(size_t value1, size_t value2) {
if (value1 > std::numeric_limits<size_t>::max() - value2) {
return true;
}
- size_t sum = value1 + value2;
+ uint64_t sum = static_cast<uint64_t>(value1) + value2;
return sum > std::numeric_limits<uint32_t>::max();
}
@@ -118,8 +121,7 @@ uint32_t PpVarSize(const PP_Var& var) {
uint32_t string_length;
(void) PPBVarInterface()->VarToUtf8(var, &string_length);
string_length = RoundedStringBytes(string_length);
- if (std::numeric_limits<uint32_t>::max() == string_length ||
- AddWouldOverflow(string_length,
+ if (AddWouldOverflow(string_length,
NACL_OFFSETOF(SerializedString, string_bytes))) {
// Adding the length to the fixed portion would overflow.
return 0;
@@ -128,10 +130,21 @@ uint32_t PpVarSize(const PP_Var& var) {
+ string_length);
break;
}
+ case PP_VARTYPE_ARRAY_BUFFER: {
+ uint32_t buffer_length = PPBVarArrayBufferInterface()->ByteLength(var);
+ buffer_length = RoundedStringBytes(buffer_length);
+ if (AddWouldOverflow(buffer_length,
+ NACL_OFFSETOF(SerializedString, string_bytes))) {
+ // Adding the length to the fixed portion would overflow.
+ return 0;
+ }
+ return static_cast<uint32_t>(NACL_OFFSETOF(SerializedString, string_bytes)
+ + buffer_length);
+ break;
+ }
case PP_VARTYPE_OBJECT:
case PP_VARTYPE_ARRAY:
case PP_VARTYPE_DICTIONARY:
- case PP_VARTYPE_ARRAY_BUFFER:
NACL_NOTREACHED();
break;
}
@@ -213,10 +226,24 @@ bool SerializePpVar(const PP_Var* vars,
+ RoundedStringBytes(string_length);
break;
}
+ case PP_VARTYPE_ARRAY_BUFFER: {
+ uint32_t buffer_length =
+ PPBVarArrayBufferInterface()->ByteLength(vars[i]);
+ SerializedString* ss = reinterpret_cast<SerializedString*>(p);
+ ss->fixed.u.string_length = buffer_length;
+ memcpy(reinterpret_cast<void*>(ss->string_bytes),
+ PPBVarArrayBufferInterface()->Map(vars[i]),
+ buffer_length);
+ // Fill padding bytes with zeros.
+ memset(reinterpret_cast<void*>(ss->string_bytes + buffer_length), 0,
+ RoundedStringBytes(buffer_length) - buffer_length);
+ element_size = NACL_OFFSETOF(SerializedString, string_bytes)
+ + RoundedStringBytes(buffer_length);
+ break;
+ }
case PP_VARTYPE_OBJECT:
case PP_VARTYPE_ARRAY:
case PP_VARTYPE_DICTIONARY:
- case PP_VARTYPE_ARRAY_BUFFER:
NACL_NOTREACHED();
default:
return false;
@@ -239,7 +266,8 @@ uint32_t DeserializeStringSize(char* p, uint32_t length) {
return std::numeric_limits<uint32_t>::max();
}
SerializedString* ss = reinterpret_cast<SerializedString*>(p);
- if (PP_VARTYPE_STRING != ss->fixed.type) {
+ if (PP_VARTYPE_STRING != ss->fixed.type &&
+ PP_VARTYPE_ARRAY_BUFFER != ss->fixed.type) {
return std::numeric_limits<uint32_t>::max();
}
uint32_t string_length = ss->fixed.u.string_length;
@@ -302,13 +330,18 @@ uint32_t DeserializePpVarSize(char* p,
return std::numeric_limits<uint32_t>::max();
}
break;
+ case PP_VARTYPE_ARRAY_BUFFER:
+ expected_element_size = DeserializeStringSize(p, length);
+ if (std::numeric_limits<uint32_t>::max() == expected_element_size) {
+ return std::numeric_limits<uint32_t>::max();
+ }
+ break;
// NB: No default case to trigger -Wswitch-enum, so changes to
// PP_VarType w/o corresponding changes here will cause a
// compile-time error.
case PP_VARTYPE_OBJECT:
case PP_VARTYPE_ARRAY:
case PP_VARTYPE_DICTIONARY:
- case PP_VARTYPE_ARRAY_BUFFER:
NACL_NOTREACHED();
break;
}
@@ -339,6 +372,24 @@ bool DeserializeString(char* p,
return true;
}
+//
+// This should be invoked only if DeserializePpVarSize succeeds, i.e.,
+// there are enough bytes at p.
+//
+bool DeserializeArrayBuffer(char* p,
+ PP_Var* var) {
+ SerializedString* ss = reinterpret_cast<SerializedString*>(p);
+ uint32_t buffer_length = ss->fixed.u.string_length;
+ // VarFromUtf8 creates a buffer of size string_length using the browser-side
+ // memory allocation function, and copies string_length bytes from
+ // ss->string_bytes in to that buffer. The ref count of the returned var is
+ // 1.
+ *var = PPBVarArrayBufferInterface()->Create(buffer_length);
+ void* var_buffer = PPBVarArrayBufferInterface()->Map(*var);
+ memcpy(var_buffer, ss->string_bytes, buffer_length);
+ return true;
+}
+
bool DeserializePpVar(char* bytes,
uint32_t length,
PP_Var* vars,
@@ -374,10 +425,14 @@ bool DeserializePpVar(char* bytes,
return false;
}
break;
+ case PP_VARTYPE_ARRAY_BUFFER:
+ if (!DeserializeArrayBuffer(p, &vars[i])) {
+ return false;
+ }
+ break;
case PP_VARTYPE_OBJECT:
case PP_VARTYPE_ARRAY:
case PP_VARTYPE_DICTIONARY:
- case PP_VARTYPE_ARRAY_BUFFER:
NACL_NOTREACHED();
default:
return false;
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc
index cc4ce3c..5416468 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -85,6 +85,11 @@ const PPB_Var* PPBVarInterface() {
GetBrowserInterfaceSafe(PPB_VAR_INTERFACE));
}
+const PPB_VarArrayBuffer_Dev* PPBVarArrayBufferInterface() {
+ return static_cast<const PPB_VarArrayBuffer_Dev*>(
+ GetBrowserInterfaceSafe(PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE));
+}
+
// Plugin interface helpers
const void* GetPluginInterface(const char* interface_name) {
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h
index 08cacff..bfec43c 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h
+++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,6 +6,7 @@
#define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_GLOBALS_H_
#include "ppapi/c/dev/ppb_memory_dev.h"
+#include "ppapi/c/dev/ppb_var_array_buffer_dev.h"
#include "ppapi/c/dev/ppp_find_dev.h"
#include "ppapi/c/dev/ppp_printing_dev.h"
#include "ppapi/c/dev/ppp_scrollbar_dev.h"
@@ -53,6 +54,7 @@ const void* GetBrowserInterfaceSafe(const char* interface_name);
const PPB_Core* PPBCoreInterface(); // shared
const PPB_Memory_Dev* PPBMemoryInterface(); // shared
const PPB_Var* PPBVarInterface(); // shared
+const PPB_VarArrayBuffer_Dev* PPBVarArrayBufferInterface(); // shared
// Support for getting PPP_ plugin interfaces.
// Safe version CHECK's for NULL.
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc
index 5afd37d..b5ebc75 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -92,6 +92,8 @@ InterfaceMapElement interface_map[] = {
{ PPB_URLREQUESTINFO_INTERFACE, PluginURLRequestInfo::GetInterface(), true },
{ PPB_URLRESPONSEINFO_INTERFACE, PluginURLResponseInfo::GetInterface(),
true },
+ { PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE, PluginVar::GetArrayBufferInterface(),
+ true },
{ PPB_VAR_INTERFACE, PluginVar::GetInterface(), true },
{ PPB_VAR_INTERFACE_1_0, PluginVar::GetInterface1_0(), true },
{ PPB_VIEW_INTERFACE, PluginView::GetInterface(), true },
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc
index 65823c8..6315c51 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc
+++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,6 +13,7 @@
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/include/portability.h"
#include "native_client/src/include/portability_io.h"
+#include "native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h"
#include "native_client/src/shared/ppapi_proxy/proxy_var_cache.h"
#include "native_client/src/shared/ppapi_proxy/string_proxy_var.h"
#include "native_client/src/shared/ppapi_proxy/utility.h"
@@ -83,6 +84,41 @@ int64_t GetVarId(PP_Var var) {
}
}
+PP_Var CreateArrayBuffer(uint32_t size_in_bytes) {
+ DebugPrintf("PPB_VarArrayBuffer::Create: size_in_bytes=%"NACL_PRIu32"\n",
+ size_in_bytes);
+ SharedProxyVar proxy_var(new ArrayBufferProxyVar(size_in_bytes));
+ ProxyVarCache::GetInstance().RetainSharedProxyVar(proxy_var);
+ PP_Var var;
+ var.type = PP_VARTYPE_ARRAY_BUFFER;
+ var.value.as_id = proxy_var->id();
+ // Increment the reference count for the return to the caller.
+ AddRef(var);
+ DebugPrintf("PPB_VarArrayBuffer::Create: as_id=%"NACL_PRId64"\n",
+ var.value.as_id);
+ return var;
+}
+
+uint32_t ByteLength(PP_Var var) {
+ DebugPrintf("PPB_VarArrayBuffer::ByteLength: var=PPB_Var(%s)\n",
+ PluginVar::DebugString(var).c_str());
+ SharedArrayBufferProxyVar buffer_var = ArrayBufferProxyVar::CastFromProxyVar(
+ ProxyVarCache::GetInstance().SharedProxyVarForVar(var));
+ uint32_t len = buffer_var->buffer_length();
+ DebugPrintf("PPB_VarArrayBuffer::ByteLength: length=%"NACL_PRIu32"\n", len);
+ return len;
+}
+
+void* Map(PP_Var var) {
+ DebugPrintf("PPB_VarArrayBuffer::Map: var=PPB_Var(%s)\n",
+ PluginVar::DebugString(var).c_str());
+ SharedArrayBufferProxyVar buffer_var = ArrayBufferProxyVar::CastFromProxyVar(
+ ProxyVarCache::GetInstance().SharedProxyVarForVar(var));
+ void* data = buffer_var->buffer();
+ DebugPrintf("PPB_VarArrayBuffer::Map: buffer=%p\n", data);
+ return data;
+}
+
} // namespace
const PPB_Var* PluginVar::GetInterface() {
@@ -105,6 +141,15 @@ const PPB_Var_1_0* PluginVar::GetInterface1_0() {
return &var_interface;
}
+const PPB_VarArrayBuffer_Dev* PluginVar::GetArrayBufferInterface() {
+ static const PPB_VarArrayBuffer_Dev interface = {
+ CreateArrayBuffer,
+ ByteLength,
+ Map
+ };
+ return &interface;
+}
+
std::string PluginVar::DebugString(const PP_Var& var) {
switch (var.type) {
case PP_VARTYPE_UNDEFINED:
@@ -137,12 +182,18 @@ std::string PluginVar::DebugString(const PP_Var& var) {
{
char buf[32];
const size_t kBufSize = sizeof(buf);
- SNPRINTF(buf, kBufSize, "%"NACL_PRIu64"", GetVarId(var));
+ SNPRINTF(buf, kBufSize, "%"NACL_PRId64"", GetVarId(var));
return std::string("##OBJECT##") + buf + "##";
}
+ case PP_VARTYPE_ARRAY_BUFFER:
+ {
+ char buf[32];
+ const size_t kBufSize = sizeof(buf);
+ SNPRINTF(buf, kBufSize, "%"NACL_PRId64"", GetVarId(var));
+ return std::string("##ARRAYBUFFER##") + buf + "##";
+ }
case PP_VARTYPE_ARRAY:
case PP_VARTYPE_DICTIONARY:
- case PP_VARTYPE_ARRAY_BUFFER:
NACL_NOTREACHED();
break;
}
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.h
index 3f60946..d6cb40e 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.h
+++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_var.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,6 +9,7 @@
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/include/portability.h"
+#include "ppapi/c/dev/ppb_var_array_buffer_dev.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppb_var.h"
@@ -24,6 +25,9 @@ class PluginVar {
// Returns the 1.0 interface to support backwards-compatibility.
static const PPB_Var_1_0* GetInterface1_0();
+ // Returns an interface pointer for the PPB_VarArrayBuffer_Dev interface.
+ static const PPB_VarArrayBuffer_Dev* GetArrayBufferInterface();
+
// String helpers.
static PP_Var StringToPPVar(const std::string& str);
static std::string PPVarToString(const PP_Var& var);
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/proxy_var_cache.h b/ppapi/native_client/src/shared/ppapi_proxy/proxy_var_cache.h
index 6cec6d4..2058f2a 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/proxy_var_cache.h
+++ b/ppapi/native_client/src/shared/ppapi_proxy/proxy_var_cache.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -54,12 +54,8 @@ class ProxyVarCache {
private:
// Return whether or not a var type is cached.
- // Note to implementers: be sure to add to this function when adding new
- // cached types.
- // TODO(dspringer): When all the complex var types are handled, this
- // test can turn into something like var.type >= PP_VARTYPE_STRING.
bool IsCachedType(const PP_Var& var) {
- return var.type == PP_VARTYPE_STRING || var.type == PP_VARTYPE_OBJECT;
+ return var.type >= PP_VARTYPE_STRING;
}
// The cache of these objects. The value is a shared pointer so that
diff --git a/ppapi/native_client/src/shared/ppapi_proxy/string_proxy_var.h b/ppapi/native_client/src/shared/ppapi_proxy/string_proxy_var.h
index 1f53301..1c1b598 100644
--- a/ppapi/native_client/src/shared/ppapi_proxy/string_proxy_var.h
+++ b/ppapi/native_client/src/shared/ppapi_proxy/string_proxy_var.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -37,8 +37,6 @@ class StringProxyVar : public ProxyVar {
private:
std::string contents_;
-
- StringProxyVar(); // Not implemented, do not use.
};
typedef scoped_refptr<StringProxyVar> SharedStringProxyVar;
diff --git a/ppapi/tests/test_post_message.cc b/ppapi/tests/test_post_message.cc
index 6edd422..5054a6a 100644
--- a/ppapi/tests/test_post_message.cc
+++ b/ppapi/tests/test_post_message.cc
@@ -1,10 +1,11 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/tests/test_post_message.h"
#include <algorithm>
+#include <sstream>
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/pp_var.h"
@@ -250,57 +251,79 @@ std::string TestPostMessage::TestSendingArrayBuffer() {
WaitForMessages();
ASSERT_TRUE(ClearListeners());
- // Create a 100-byte array buffer with test_data[i] == i.
- pp::VarArrayBuffer_Dev test_data(100u);
- ASSERT_NE(NULL, test_data.Map());
- ASSERT_EQ(100u, test_data.ByteLength());
- unsigned char* buff = static_cast<unsigned char*>(test_data.Map());
- for (size_t i = 0; i < test_data.ByteLength(); ++i)
- buff[i] = i;
-
- // Have the listener test some properties of the ArrayBuffer.
- const char* const properties_to_check[] = {
- "message_event.data.constructor.name === 'ArrayBuffer'",
- "message_event.data.byteLength === 100",
- "(new DataView(message_event.data)).getInt8(0) == 0",
- "(new DataView(message_event.data)).getInt8(99) == 99",
- NULL};
- for (size_t i = 0; properties_to_check[i]; ++i) {
- ASSERT_TRUE(AddEchoingListener(properties_to_check[i]));
+ // TODO(dmichael): Add testing of longer array buffers when crbug.com/106266
+ // is fixed.
+ uint32_t sizes[] = { 0, 100, 1000 };
+ for (size_t i = 0; i < sizeof(sizes)/sizeof(sizes[i]); ++i) {
+ std::ostringstream size_stream;
+ size_stream << sizes[i];
+ const std::string kSizeAsString(size_stream.str());
+
+ // Create an appropriately sized array buffer with test_data[i] == i.
+ pp::VarArrayBuffer_Dev test_data(sizes[i]);
+ if (sizes[i] > 0)
+ ASSERT_NE(NULL, test_data.Map());
+ ASSERT_EQ(sizes[i], test_data.ByteLength());
+ unsigned char* buff = static_cast<unsigned char*>(test_data.Map());
+ const uint32_t kByteLength = test_data.ByteLength();
+ for (size_t j = 0; j < kByteLength; ++j)
+ buff[j] = static_cast<uint8_t>(j % 256u);
+
+ // Have the listener test some properties of the ArrayBuffer.
+ std::vector<std::string> properties_to_check;
+ properties_to_check.push_back(
+ "message_event.data.constructor.name === 'ArrayBuffer'");
+ properties_to_check.push_back(
+ std::string("message_event.data.byteLength === ") + kSizeAsString);
+ if (sizes[i] > 0) {
+ properties_to_check.push_back(
+ "(new DataView(message_event.data)).getUint8(0) == 0");
+ // Checks that the last element has the right value: (byteLength-1)%256.
+ std::string received_byte("(new DataView(message_event.data)).getUint8("
+ " message_event.data.byteLength-1)");
+ std::string expected_byte("(message_event.data.byteLength-1)%256");
+ properties_to_check.push_back(received_byte + " == " + expected_byte);
+ }
+ for (std::vector<std::string>::iterator iter = properties_to_check.begin();
+ iter != properties_to_check.end();
+ ++iter) {
+ ASSERT_TRUE(AddEchoingListener(*iter));
+ message_data_.clear();
+ instance_->PostMessage(test_data);
+ ASSERT_EQ(message_data_.size(), 0);
+ ASSERT_EQ(WaitForMessages(), 1);
+ ASSERT_TRUE(message_data_.back().is_bool());
+ if (!message_data_.back().AsBool())
+ return std::string("Failed: ") + *iter + ", size: " + kSizeAsString;
+ ASSERT_TRUE(message_data_.back().AsBool());
+ ASSERT_TRUE(ClearListeners());
+ }
+
+ // Set up the JavaScript message event listener to echo the data part of the
+ // message event back to us.
+ ASSERT_TRUE(AddEchoingListener("message_event.data"));
message_data_.clear();
instance_->PostMessage(test_data);
+ // PostMessage is asynchronous, so we should not receive a response yet.
ASSERT_EQ(message_data_.size(), 0);
ASSERT_EQ(WaitForMessages(), 1);
- ASSERT_TRUE(message_data_.back().is_bool());
- if (!message_data_.back().AsBool())
- return std::string("Failed: ") + properties_to_check[i];
- ASSERT_TRUE(message_data_.back().AsBool());
+ ASSERT_TRUE(message_data_.back().is_array_buffer());
+ pp::VarArrayBuffer_Dev received(message_data_.back());
+ message_data_.clear();
+ ASSERT_EQ(test_data.ByteLength(), received.ByteLength());
+ unsigned char* received_buff = static_cast<unsigned char*>(received.Map());
+ // The buffer should be copied, so this should be a distinct buffer. When
+ // 'transferrables' are implemented for PPAPI, we'll also want to test that
+ // we get the _same_ buffer back when it's transferred.
+ if (sizes[i] > 0)
+ ASSERT_NE(buff, received_buff);
+ for (size_t i = 0; i < test_data.ByteLength(); ++i)
+ ASSERT_EQ(buff[i], received_buff[i]);
+
+ message_data_.clear();
ASSERT_TRUE(ClearListeners());
}
- // Set up the JavaScript message event listener to echo the data part of the
- // message event back to us.
- ASSERT_TRUE(AddEchoingListener("message_event.data"));
- message_data_.clear();
- instance_->PostMessage(test_data);
- // PostMessage is asynchronous, so we should not receive a response yet.
- ASSERT_EQ(message_data_.size(), 0);
- ASSERT_EQ(WaitForMessages(), 1);
- ASSERT_TRUE(message_data_.back().is_array_buffer());
- pp::VarArrayBuffer_Dev received(message_data_.back());
- message_data_.clear();
- ASSERT_EQ(test_data.ByteLength(), received.ByteLength());
- unsigned char* received_buff = static_cast<unsigned char*>(received.Map());
- // The buffer should be copied, so this should be a distinct buffer. When
- // 'transferrables' are implemented for PPAPI, we'll also want to test that
- // we get the _same_ buffer back when it's transferred.
- ASSERT_NE(buff, received_buff);
- for (size_t i = 0; i < test_data.ByteLength(); ++i)
- ASSERT_EQ(buff[i], received_buff[i]);
-
- message_data_.clear();
- ASSERT_TRUE(ClearListeners());
-
PASS();
}