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 // TODO(toyoshim): Returns PP_ERROR_BADARGUMENT if |reason| contains any |
232 // surrogates. | |
dmichael (off chromium)
2012/04/23 15:14:46
I'm not sure what you mean here, but I'm guessing
Takashi Toyoshima
2012/04/24 06:44:57
Thank you.
I check VarFromUTF8 implementation. As
| |
233 reason_string = StringVar::FromPPVar(reason); | |
234 if (!reason_string || | |
235 reason_string->value().size() > kMaxReasonSizeInBytes) | |
236 return PP_ERROR_BADARGUMENT; | |
237 web_reason = WebString::fromUTF8(reason_string->value()); | |
238 } | |
232 | 239 |
233 // Check state. | 240 // Check state. |
234 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING || | 241 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING || |
235 state_ == PP_WEBSOCKETREADYSTATE_CLOSED) | 242 state_ == PP_WEBSOCKETREADYSTATE_CLOSED) |
236 return PP_ERROR_INPROGRESS; | 243 return PP_ERROR_INPROGRESS; |
237 | 244 |
238 // Validate |callback| (Doesn't support blocking callback) | 245 // Validate |callback| (Doesn't support blocking callback) |
239 if (!callback.func) | 246 if (!callback.func) |
240 return PP_ERROR_BLOCKS_MAIN_THREAD; | 247 return PP_ERROR_BLOCKS_MAIN_THREAD; |
241 | 248 |
(...skipping 16 matching lines...) Expand all Loading... | |
258 wait_for_receive_ = false; | 265 wait_for_receive_ = false; |
259 receive_callback_var_ = NULL; | 266 receive_callback_var_ = NULL; |
260 | 267 |
261 // Need to do a "Post" to avoid reentering the plugin. | 268 // Need to do a "Post" to avoid reentering the plugin. |
262 receive_callback_->PostAbort(); | 269 receive_callback_->PostAbort(); |
263 receive_callback_ = NULL; | 270 receive_callback_ = NULL; |
264 } | 271 } |
265 | 272 |
266 // Close connection. | 273 // Close connection. |
267 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; | 274 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; |
268 WebString web_reason = WebString::fromUTF8(reason_string->value()); | |
269 websocket_->close(code, web_reason); | 275 websocket_->close(code, web_reason); |
270 | 276 |
271 return PP_OK_COMPLETIONPENDING; | 277 return PP_OK_COMPLETIONPENDING; |
272 } | 278 } |
273 | 279 |
274 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, | 280 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, |
275 PP_CompletionCallback callback) { | 281 PP_CompletionCallback callback) { |
276 // Check state. | 282 // Check state. |
277 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID || | 283 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID || |
278 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING) | 284 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING) |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 | 530 |
525 *receive_callback_var_ = received_messages_.front()->GetPPVar(); | 531 *receive_callback_var_ = received_messages_.front()->GetPPVar(); |
526 received_messages_.pop(); | 532 received_messages_.pop(); |
527 receive_callback_var_ = NULL; | 533 receive_callback_var_ = NULL; |
528 wait_for_receive_ = false; | 534 wait_for_receive_ = false; |
529 return PP_OK; | 535 return PP_OK; |
530 } | 536 } |
531 | 537 |
532 } // namespace ppapi | 538 } // namespace ppapi |
533 } // namespace webkit | 539 } // namespace webkit |
OLD | NEW |