| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/plugins/ppapi/ppb_websocket_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_websocket_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 if (code != static_cast<uint16_t>(WebSocket::CloseEventCodeNotSpecified)) { | 216 if (code != static_cast<uint16_t>(WebSocket::CloseEventCodeNotSpecified)) { |
| 217 if (!(code == WebSocket::CloseEventCodeNormalClosure || | 217 if (!(code == WebSocket::CloseEventCodeNormalClosure || |
| 218 (WebSocket::CloseEventCodeMinimumUserDefined <= code && | 218 (WebSocket::CloseEventCodeMinimumUserDefined <= code && |
| 219 code <= WebSocket::CloseEventCodeMaximumUserDefined))) | 219 code <= WebSocket::CloseEventCodeMaximumUserDefined))) |
| 220 // RFC 6455 limits applications to use reserved connection close code in | 220 // RFC 6455 limits applications to use reserved connection close code in |
| 221 // section 7.4.2.. The WebSocket API (http://www.w3.org/TR/websockets/) | 221 // section 7.4.2.. The WebSocket API (http://www.w3.org/TR/websockets/) |
| 222 // defines this out of range error as InvalidAccessError in JavaScript. | 222 // defines this out of range error as InvalidAccessError in JavaScript. |
| 223 return PP_ERROR_NOACCESS; | 223 return PP_ERROR_NOACCESS; |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Validate |reason|. | 226 scoped_refptr<StringVar> reason_string; |
| 227 // TODO(toyoshim): Returns PP_ERROR_BADARGUMENT if |reason| contains any | 227 WebString web_reason; |
| 228 // surrogates. | 228 // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED. |
| 229 scoped_refptr<StringVar> reason_string = StringVar::FromPPVar(reason); | 229 if (reason.type != PP_VARTYPE_UNDEFINED) { |
| 230 if (!reason_string || reason_string->value().size() > kMaxReasonSizeInBytes) | 230 // Validate |reason|. |
| 231 return PP_ERROR_BADARGUMENT; | 231 reason_string = StringVar::FromPPVar(reason); |
| 232 if (!reason_string || |
| 233 reason_string->value().size() > kMaxReasonSizeInBytes) |
| 234 return PP_ERROR_BADARGUMENT; |
| 235 web_reason = WebString::fromUTF8(reason_string->value()); |
| 236 } |
| 232 | 237 |
| 233 // Check state. | 238 // Check state. |
| 234 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING || | 239 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING || |
| 235 state_ == PP_WEBSOCKETREADYSTATE_CLOSED) | 240 state_ == PP_WEBSOCKETREADYSTATE_CLOSED) |
| 236 return PP_ERROR_INPROGRESS; | 241 return PP_ERROR_INPROGRESS; |
| 237 | 242 |
| 238 // Validate |callback| (Doesn't support blocking callback) | 243 // Validate |callback| (Doesn't support blocking callback) |
| 239 if (!callback.func) | 244 if (!callback.func) |
| 240 return PP_ERROR_BLOCKS_MAIN_THREAD; | 245 return PP_ERROR_BLOCKS_MAIN_THREAD; |
| 241 | 246 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 258 wait_for_receive_ = false; | 263 wait_for_receive_ = false; |
| 259 receive_callback_var_ = NULL; | 264 receive_callback_var_ = NULL; |
| 260 | 265 |
| 261 // Need to do a "Post" to avoid reentering the plugin. | 266 // Need to do a "Post" to avoid reentering the plugin. |
| 262 receive_callback_->PostAbort(); | 267 receive_callback_->PostAbort(); |
| 263 receive_callback_ = NULL; | 268 receive_callback_ = NULL; |
| 264 } | 269 } |
| 265 | 270 |
| 266 // Close connection. | 271 // Close connection. |
| 267 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; | 272 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; |
| 268 WebString web_reason = WebString::fromUTF8(reason_string->value()); | |
| 269 websocket_->close(code, web_reason); | 273 websocket_->close(code, web_reason); |
| 270 | 274 |
| 271 return PP_OK_COMPLETIONPENDING; | 275 return PP_OK_COMPLETIONPENDING; |
| 272 } | 276 } |
| 273 | 277 |
| 274 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, | 278 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, |
| 275 PP_CompletionCallback callback) { | 279 PP_CompletionCallback callback) { |
| 276 // Check state. | 280 // Check state. |
| 277 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID || | 281 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID || |
| 278 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING) | 282 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING) |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 528 |
| 525 *receive_callback_var_ = received_messages_.front()->GetPPVar(); | 529 *receive_callback_var_ = received_messages_.front()->GetPPVar(); |
| 526 received_messages_.pop(); | 530 received_messages_.pop(); |
| 527 receive_callback_var_ = NULL; | 531 receive_callback_var_ = NULL; |
| 528 wait_for_receive_ = false; | 532 wait_for_receive_ = false; |
| 529 return PP_OK; | 533 return PP_OK; |
| 530 } | 534 } |
| 531 | 535 |
| 532 } // namespace ppapi | 536 } // namespace ppapi |
| 533 } // namespace webkit | 537 } // namespace webkit |
| OLD | NEW |