Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(910)

Unified Diff: ppapi/examples/scripting/post_message.cc

Issue 8930010: Implement in-process PPB_VarArrayBuffer_Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ppapi_unittests Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/examples/scripting/post_message.cc
diff --git a/ppapi/examples/scripting/post_message.cc b/ppapi/examples/scripting/post_message.cc
index 24f79271bc3ac30e34c0e8947473d8907a0071db..1faa0c1df646cda502013280eb106461ec0f8420 100644
--- a/ppapi/examples/scripting/post_message.cc
+++ b/ppapi/examples/scripting/post_message.cc
@@ -4,6 +4,10 @@
#include <algorithm>
+#include <stdio.h>
+#include <string.h>
+
+#include "ppapi/cpp/dev/var_array_buffer_dev.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
@@ -26,10 +30,17 @@ class MyInstance : public pp::Instance {
void MyInstance::HandleMessage(const pp::Var& message_data) {
if (message_data.is_string()) {
std::string string_copy(message_data.AsString());
- std::reverse(string_copy.begin(), string_copy.end());
- bool is_palindrome(message_data.AsString() == string_copy);
+ pp::VarArrayBuffer_Dev buff(string_copy.size());
+ char* str = static_cast<char*>(buff.Map());
+ memcpy(str, string_copy.c_str(), buff.ByteLength());
- PostMessage(pp::Var(is_palindrome));
+ PostMessage(buff);
+ } else if (message_data.is_array_buffer()) {
+ pp::VarArrayBuffer_Dev buff_var(message_data);
+ char* buff = static_cast<char*>(buff_var.Map());
+ for (size_t i=0; i < buff_var.ByteLength(); ++i)
+ printf("%d ", int(buff[i]));
+ printf("\n");
}
}

Powered by Google App Engine
This is Rietveld 408576698