summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 06:22:51 +0000
committertoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-19 06:22:51 +0000
commit8778b63e6ab02be9c2feef92a13fdca3f2ae4f28 (patch)
treeae9746f8f453754bc870bd39d8a1d139d0848989
parenta189a701d7fefe3c26b76efa529dc3e956e28c30 (diff)
downloadchromium_src-8778b63e6ab02be9c2feef92a13fdca3f2ae4f28.zip
chromium_src-8778b63e6ab02be9c2feef92a13fdca3f2ae4f28.tar.gz
chromium_src-8778b63e6ab02be9c2feef92a13fdca3f2ae4f28.tar.bz2
WebSocket Pepper API: WebArrayBuffer support
- support SetBinaryType() - support WebArrayBuffer and stop supporting WebData - use Var instead of PP_Var to hold received messages - Add C++ interfaces to handle binary types BUG=87310 TEST=ui_test --gtest_filter='PPAPITest.WebSocket_*' Review URL: http://codereview.chromium.org/9026007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118258 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ppapi/api/dev/ppb_websocket_dev.idl8
-rw-r--r--ppapi/c/dev/ppb_websocket_dev.h10
-rw-r--r--ppapi/cpp/dev/websocket_dev.cc15
-rw-r--r--ppapi/cpp/dev/websocket_dev.h29
-rw-r--r--ppapi/tests/test_websocket.cc6
-rw-r--r--webkit/plugins/ppapi/ppb_websocket_impl.cc79
-rw-r--r--webkit/plugins/ppapi/ppb_websocket_impl.h13
7 files changed, 105 insertions, 55 deletions
diff --git a/ppapi/api/dev/ppb_websocket_dev.idl b/ppapi/api/dev/ppb_websocket_dev.idl
index 31c44a6..0836038 100644
--- a/ppapi/api/dev/ppb_websocket_dev.idl
+++ b/ppapi/api/dev/ppb_websocket_dev.idl
@@ -336,7 +336,7 @@ interface PPB_WebSocket_Dev {
* @param[in] web_socket A <code>PP_Resource</code> corresponding to a
* WebSocket.
*
- * @param[in] binary_type Binary object type for receibing binary frames
+ * @param[in] binary_type Binary object type for receiving binary frames
* representation.
*
* @return Returns <code>PP_FALSE</code> if the specified type is not
@@ -347,13 +347,13 @@ interface PPB_WebSocket_Dev {
[in] PP_WebSocketBinaryType_Dev binary_type);
/**
- * GetBinaryType() returns currently specified binary object type for
- * receiving binary frames representation.
+ * GetBinaryType() returns the currently specified binary object type for
+ * receiving binary frames.
*
* @param[in] web_socket A <code>PP_Resource</code> corresponding to a
* WebSocket.
*
- * @return Returns <code>PP_WebSocketBinaryType_Dev</code> represents
+ * @return Returns <code>PP_WebSocketBinaryType_Dev</code> represents the
* current binary object type.
*/
[version=0.9]
diff --git a/ppapi/c/dev/ppb_websocket_dev.h b/ppapi/c/dev/ppb_websocket_dev.h
index e9e524f..e138f2b 100644
--- a/ppapi/c/dev/ppb_websocket_dev.h
+++ b/ppapi/c/dev/ppb_websocket_dev.h
@@ -3,7 +3,7 @@
* found in the LICENSE file.
*/
-/* From dev/ppb_websocket_dev.idl modified Wed Jan 11 14:21:33 2012. */
+/* From dev/ppb_websocket_dev.idl modified Wed Jan 18 20:17:45 2012. */
#ifndef PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_
#define PPAPI_C_DEV_PPB_WEBSOCKET_DEV_H_
@@ -341,7 +341,7 @@ struct PPB_WebSocket_Dev_0_9 {
* @param[in] web_socket A <code>PP_Resource</code> corresponding to a
* WebSocket.
*
- * @param[in] binary_type Binary object type for receibing binary frames
+ * @param[in] binary_type Binary object type for receiving binary frames
* representation.
*
* @return Returns <code>PP_FALSE</code> if the specified type is not
@@ -350,13 +350,13 @@ struct PPB_WebSocket_Dev_0_9 {
PP_Bool (*SetBinaryType)(PP_Resource web_socket,
PP_WebSocketBinaryType_Dev binary_type);
/**
- * GetBinaryType() returns currently specified binary object type for
- * receiving binary frames representation.
+ * GetBinaryType() returns the currently specified binary object type for
+ * receiving binary frames.
*
* @param[in] web_socket A <code>PP_Resource</code> corresponding to a
* WebSocket.
*
- * @return Returns <code>PP_WebSocketBinaryType_Dev</code> represents
+ * @return Returns <code>PP_WebSocketBinaryType_Dev</code> represents the
* current binary object type.
*/
PP_WebSocketBinaryType_Dev (*GetBinaryType)(PP_Resource web_socket);
diff --git a/ppapi/cpp/dev/websocket_dev.cc b/ppapi/cpp/dev/websocket_dev.cc
index 52ffdba..4cc7f8a 100644
--- a/ppapi/cpp/dev/websocket_dev.cc
+++ b/ppapi/cpp/dev/websocket_dev.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.
@@ -145,4 +145,17 @@ Var WebSocket_Dev::GetURL() {
get_interface<PPB_WebSocket_Dev>()->GetURL(pp_resource()));
}
+bool WebSocket_Dev::SetBinaryType(PP_WebSocketBinaryType_Dev binary_type) {
+ if (!has_interface<PPB_WebSocket_Dev>())
+ return false;
+ return PP_ToBool(get_interface<PPB_WebSocket_Dev>()->SetBinaryType(
+ pp_resource(), binary_type));
+}
+
+PP_WebSocketBinaryType_Dev WebSocket_Dev::GetBinaryType() {
+ if (!has_interface<PPB_WebSocket_Dev>())
+ return PP_WEBSOCKETBINARYTYPE_INVALID;
+ return get_interface<PPB_WebSocket_Dev>()->GetBinaryType(pp_resource());
+}
+
} // namespace pp
diff --git a/ppapi/cpp/dev/websocket_dev.h b/ppapi/cpp/dev/websocket_dev.h
index 42981f6..2c55d51 100644
--- a/ppapi/cpp/dev/websocket_dev.h
+++ b/ppapi/cpp/dev/websocket_dev.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.
@@ -176,6 +176,33 @@ class WebSocket_Dev : public Resource {
/// @return Returns a <code>Var</code> of string type. If called before the
/// connection is established, it contains the empty string.
Var GetURL();
+
+ /// SetBinaryType() specifies the binary object type for receiving binary
+ /// frames representation. Receiving text frames are always mapped to
+ /// <PP_VARTYPE_STRING</code> var regardless of this attribute.
+ /// This function should be called before Connect() to ensure receiving all
+ /// incoming binary frames as the specified binary object type.
+ /// Default type is <code>PP_WEBSOCKETBINARYTYPE_BLOB_DEV</code>.
+ ///
+ /// Currently, Blob bindings is not supported in Pepper, so receiving binary
+ /// type is always ArrayBuffer. To ensure backward compatibility, you must
+ /// call this function with
+ /// <code>PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV</code> to use binary frames.
+ ///
+ /// @param[in] binary_type Binary object type for receiving binary frames
+ /// representation.
+ ///
+ /// @return Returns <code>false</code> if the specified type is not
+ /// supported. Otherwise, returns <code>true</code>.
+ ///
+ bool SetBinaryType(PP_WebSocketBinaryType_Dev binary_type);
+
+ /// GetBinaryType() returns the currently specified binary object type for
+ /// receiving binary frames.
+ ///
+ /// @return Returns <code>PP_WebSocketBinaryType_Dev</code> represents the
+ /// current binary object type.
+ PP_WebSocketBinaryType_Dev GetBinaryType();
};
} // namespace pp
diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc
index da09d82..34b56b0 100644
--- a/ppapi/tests/test_websocket.cc
+++ b/ppapi/tests/test_websocket.cc
@@ -197,6 +197,10 @@ std::string TestWebSocket::TestUninitializedPropertiesAccess() {
ASSERT_TRUE(AreEqualWithString(url, ""));
ReleaseVar(url);
+ PP_WebSocketBinaryType_Dev binary_type =
+ websocket_interface_->GetBinaryType(ws);
+ ASSERT_EQ(PP_WEBSOCKETBINARYTYPE_BLOB_DEV, binary_type);
+
core_interface_->ReleaseResource(ws);
PASS();
@@ -564,6 +568,7 @@ std::string TestWebSocket::TestCcInterfaces() {
ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), ""));
// Check communication interfaces (connect, send, receive, and close).
+ ws.SetBinaryType(PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV);
TestCompletionCallback connect_callback(instance_->pp_instance());
int32_t result = ws.Connect(pp::Var(std::string(kCloseServerURL)), NULL, 0U,
connect_callback);
@@ -617,6 +622,7 @@ std::string TestWebSocket::TestCcInterfaces() {
ASSERT_TRUE(AreEqualWithString(ws.GetProtocol().pp_var(), ""));
ASSERT_EQ(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, ws.GetReadyState());
ASSERT_TRUE(AreEqualWithString(ws.GetURL().pp_var(), kCloseServerURL));
+ ASSERT_EQ(PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV, ws.GetBinaryType());
PASS();
}
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.cc b/webkit/plugins/ppapi/ppb_websocket_impl.cc
index 00dd7f5..a7fc973 100644
--- a/webkit/plugins/ppapi/ppb_websocket_impl.cc
+++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc
@@ -18,13 +18,14 @@
#include "ppapi/c/ppb_var.h"
#include "ppapi/shared_impl/var.h"
#include "ppapi/shared_impl/var_tracker.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebArrayBuffer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSocket.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
+#include "webkit/plugins/ppapi/host_array_buffer_var.h"
#include "webkit/plugins/ppapi/host_globals.h"
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "webkit/plugins/ppapi/resource_helper.h"
@@ -34,8 +35,9 @@ using ppapi::PpapiGlobals;
using ppapi::StringVar;
using ppapi::thunk::PPB_WebSocket_API;
using ppapi::TrackedCallback;
+using ppapi::Var;
using ppapi::VarTracker;
-using WebKit::WebData;
+using WebKit::WebArrayBuffer;
using WebKit::WebDocument;
using WebKit::WebString;
using WebKit::WebSocket;
@@ -75,12 +77,10 @@ bool InValidStateToReceive(PP_WebSocketReadyState_Dev state) {
namespace webkit {
namespace ppapi {
-// TODO(toyoshim): Default value of binary_type_ must be
-// PP_WEBSOCKETBINARYTYPE_BLOB_DEV after supporting Blob.
PPB_WebSocket_Impl::PPB_WebSocket_Impl(PP_Instance instance)
: Resource(instance),
state_(PP_WEBSOCKETREADYSTATE_INVALID_DEV),
- binary_type_(PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV),
+ binary_type_(WebSocket::BinaryTypeBlob),
error_was_received_(false),
receive_callback_var_(NULL),
wait_for_receive_(false),
@@ -94,14 +94,6 @@ PPB_WebSocket_Impl::PPB_WebSocket_Impl(PP_Instance instance)
PPB_WebSocket_Impl::~PPB_WebSocket_Impl() {
if (websocket_.get())
websocket_->disconnect();
-
- // Clean up received and unread messages
- VarTracker* var_tracker = PpapiGlobals::Get()->GetVarTracker();
- while (!received_messages_.empty()) {
- PP_Var var = received_messages_.front();
- received_messages_.pop();
- var_tracker->ReleaseVar(var);
- }
}
// static
@@ -203,6 +195,9 @@ int32_t PPB_WebSocket_Impl::Connect(PP_Var url,
if (!websocket_.get())
return PP_ERROR_NOTSUPPORTED;
+ // Set receiving binary object type.
+ websocket_->setBinaryType(binary_type_);
+
websocket_->connect(web_url, web_protocols);
state_ = PP_WEBSOCKETREADYSTATE_CONNECTING_DEV;
@@ -357,17 +352,13 @@ int32_t PPB_WebSocket_Impl::SendMessage(PP_Var message) {
if (!websocket_->sendText(web_message))
return PP_ERROR_BADARGUMENT;
} else if (message.type == PP_VARTYPE_ARRAY_BUFFER) {
- // Convert message to WebData.
- // TODO(toyoshim): Must add a WebKit interface which handles WebArrayBuffer
- // directly.
- scoped_refptr<ArrayBufferVar> message_array_buffer =
- ArrayBufferVar::FromPPVar(message);
- if (!message_array_buffer)
+ // Convert message to WebArrayBuffer.
+ scoped_refptr<HostArrayBufferVar> host_message =
+ static_cast<HostArrayBufferVar*>(ArrayBufferVar::FromPPVar(message));
+ if (!host_message)
return PP_ERROR_BADARGUMENT;
- WebData web_message = WebData(
- static_cast<const char*>(message_array_buffer->Map()),
- static_cast<size_t>(message_array_buffer->ByteLength()));
- if (!websocket_->sendBinary(web_message))
+ WebArrayBuffer& web_message = host_message->webkit_buffer();
+ if (!websocket_->sendArrayBuffer(web_message))
return PP_ERROR_BADARGUMENT;
} else {
// TODO(toyoshim): Support Blob.
@@ -424,12 +415,32 @@ PP_Var PPB_WebSocket_Impl::GetURL() {
PP_Bool PPB_WebSocket_Impl::SetBinaryType(
PP_WebSocketBinaryType_Dev binary_type) {
- // TODO(toyoshim): Use WebKit new API to set the receiving binary type.
- return PP_FALSE;
+ switch (binary_type) {
+ case PP_WEBSOCKETBINARYTYPE_BLOB_DEV:
+ binary_type_ = WebSocket::BinaryTypeBlob;
+ break;
+ case PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV:
+ binary_type_ = WebSocket::BinaryTypeArrayBuffer;
+ break;
+ default:
+ return PP_FALSE;
+ }
+ if (!websocket_.get())
+ return PP_FALSE;
+ websocket_->setBinaryType(binary_type_);
+ return PP_TRUE;
}
PP_WebSocketBinaryType_Dev PPB_WebSocket_Impl::GetBinaryType() {
- return binary_type_;
+ switch (binary_type_) {
+ case WebSocket::BinaryTypeBlob:
+ return PP_WEBSOCKETBINARYTYPE_BLOB_DEV;
+ case WebSocket::BinaryTypeArrayBuffer:
+ return PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV;
+ default:
+ NOTREACHED();
+ return PP_WEBSOCKETBINARYTYPE_INVALID;
+ }
}
void PPB_WebSocket_Impl::didConnect() {
@@ -445,8 +456,7 @@ void PPB_WebSocket_Impl::didReceiveMessage(const WebString& message) {
// Append received data to queue.
std::string string = message.utf8();
- PP_Var var = StringVar::StringToPPVar(string);
- received_messages_.push(var);
+ received_messages_.push(scoped_refptr<Var>(new StringVar(string)));
if (!wait_for_receive_)
return;
@@ -454,18 +464,15 @@ void PPB_WebSocket_Impl::didReceiveMessage(const WebString& message) {
TrackedCallback::ClearAndRun(&receive_callback_, DoReceive());
}
-void PPB_WebSocket_Impl::didReceiveBinaryData(const WebData& binaryData) {
+void PPB_WebSocket_Impl::didReceiveArrayBuffer(
+ const WebArrayBuffer& binaryData) {
// Dispose packets after receiving an error or in invalid state.
if (error_was_received_ || !InValidStateToReceive(state_))
return;
// Append received data to queue.
- PP_Var var = PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
- binaryData.size());
- scoped_refptr<ArrayBufferVar> arraybuffer = ArrayBufferVar::FromPPVar(var);
- void* data = arraybuffer->Map();
- memcpy(data, binaryData.data(), binaryData.size());
- received_messages_.push(var);
+ received_messages_.push(
+ scoped_refptr<Var>(new HostArrayBufferVar(binaryData)));
if (!wait_for_receive_)
return;
@@ -548,7 +555,7 @@ int32_t PPB_WebSocket_Impl::DoReceive() {
if (!receive_callback_var_)
return PP_OK;
- *receive_callback_var_ = received_messages_.front();
+ *receive_callback_var_ = received_messages_.front()->GetPPVar();
received_messages_.pop();
receive_callback_var_ = NULL;
wait_for_receive_ = false;
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.h b/webkit/plugins/ppapi/ppb_websocket_impl.h
index 3177c7b..bd6f6c8 100644
--- a/webkit/plugins/ppapi/ppb_websocket_impl.h
+++ b/webkit/plugins/ppapi/ppb_websocket_impl.h
@@ -11,14 +11,12 @@
#include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/tracked_callback.h"
#include "ppapi/thunk/ppb_websocket_api.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebSocket.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSocketClient.h"
namespace ppapi {
class StringVar;
-}
-
-namespace WebKit {
-class WebSocket;
+class Var;
}
namespace webkit {
@@ -64,7 +62,7 @@ class PPB_WebSocket_Impl : public ::ppapi::Resource,
// WebSocketClient implementation.
virtual void didConnect();
virtual void didReceiveMessage(const WebKit::WebString& message);
- virtual void didReceiveBinaryData(const WebKit::WebData& binaryData);
+ virtual void didReceiveArrayBuffer(const WebKit::WebArrayBuffer& binaryData);
virtual void didReceiveMessageError();
virtual void didUpdateBufferedAmount(unsigned long buffered_amount);
virtual void didStartClosingHandshake();
@@ -77,7 +75,7 @@ class PPB_WebSocket_Impl : public ::ppapi::Resource,
scoped_ptr<WebKit::WebSocket> websocket_;
PP_WebSocketReadyState_Dev state_;
- PP_WebSocketBinaryType_Dev binary_type_;
+ WebKit::WebSocket::BinaryType binary_type_;
bool error_was_received_;
scoped_refptr< ::ppapi::TrackedCallback> connect_callback_;
@@ -85,8 +83,7 @@ class PPB_WebSocket_Impl : public ::ppapi::Resource,
scoped_refptr< ::ppapi::TrackedCallback> receive_callback_;
PP_Var* receive_callback_var_;
bool wait_for_receive_;
- // TODO(toyoshim): Use std::queue<Var> when it supports binary.
- std::queue<PP_Var> received_messages_;
+ std::queue< scoped_refptr< ::ppapi::Var> > received_messages_;
scoped_refptr< ::ppapi::TrackedCallback> close_callback_;
uint16_t close_code_;