Chromium Code Reviews| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 | 197 |
| 198 websocket_->connect(web_url, web_protocols); | 198 websocket_->connect(web_url, web_protocols); |
| 199 state_ = PP_WEBSOCKETREADYSTATE_CONNECTING; | 199 state_ = PP_WEBSOCKETREADYSTATE_CONNECTING; |
| 200 | 200 |
| 201 // Install callback. | 201 // Install callback. |
| 202 connect_callback_ = new TrackedCallback(this, callback); | 202 connect_callback_ = new TrackedCallback(this, callback); |
| 203 | 203 |
| 204 return PP_OK_COMPLETIONPENDING; | 204 return PP_OK_COMPLETIONPENDING; |
| 205 } | 205 } |
| 206 | 206 |
| 207 int32_t PPB_WebSocket_Impl::Close(uint16_t code, | 207 int32_t PPB_WebSocket_Impl::Close(uint16_t code, |
|
dmichael (off chromium)
2012/05/14 16:10:49
I think this should have changed to enum once the
Takashi Toyoshima
2012/05/15 10:55:28
I see. SRC handles the code as int32_t, so we can
| |
| 208 PP_Var reason, | 208 PP_Var reason, |
| 209 PP_CompletionCallback callback) { | 209 PP_CompletionCallback callback) { |
| 210 // Check mandarory interfaces. | 210 // Check mandarory interfaces. |
| 211 if (!websocket_.get()) | 211 if (!websocket_.get()) |
| 212 return PP_ERROR_FAILED; | 212 return PP_ERROR_FAILED; |
| 213 | 213 |
| 214 // Validate |code|. Need to cast |CloseEventCodeNotSpecified| which is -1 to | 214 // Validate |code| and |reason|. Need to cast |CloseEventCodeNotSpecified| |
| 215 // uint16_t for the comparison to work. | 215 // which is -1 to uint16_t for the comparison to work. |reason| is valid only |
| 216 // when |code| is not PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED. | |
| 217 scoped_refptr<StringVar> reason_string; | |
| 218 WebString web_reason; | |
| 216 if (code != static_cast<uint16_t>(WebSocket::CloseEventCodeNotSpecified)) { | 219 if (code != static_cast<uint16_t>(WebSocket::CloseEventCodeNotSpecified)) { |
| 217 if (!(code == WebSocket::CloseEventCodeNormalClosure || | 220 if (!(code == WebSocket::CloseEventCodeNormalClosure || |
| 218 (WebSocket::CloseEventCodeMinimumUserDefined <= code && | 221 (WebSocket::CloseEventCodeMinimumUserDefined <= code && |
| 219 code <= WebSocket::CloseEventCodeMaximumUserDefined))) | 222 code <= WebSocket::CloseEventCodeMaximumUserDefined))) |
| 220 // RFC 6455 limits applications to use reserved connection close code in | 223 // 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/) | 224 // section 7.4.2.. The WebSocket API (http://www.w3.org/TR/websockets/) |
| 222 // defines this out of range error as InvalidAccessError in JavaScript. | 225 // defines this out of range error as InvalidAccessError in JavaScript. |
| 223 return PP_ERROR_NOACCESS; | 226 return PP_ERROR_NOACCESS; |
| 224 } | |
| 225 | 227 |
| 226 scoped_refptr<StringVar> reason_string; | 228 // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED. |
|
Takashi Toyoshima
2012/05/14 12:05:04
I moved reason handling code inside of 'code != no
| |
| 227 WebString web_reason; | 229 if (reason.type != PP_VARTYPE_UNDEFINED) { |
| 228 // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED. | 230 // Validate |reason|. |
| 229 if (reason.type != PP_VARTYPE_UNDEFINED) { | 231 reason_string = StringVar::FromPPVar(reason); |
| 230 // Validate |reason|. | 232 if (!reason_string || |
| 231 reason_string = StringVar::FromPPVar(reason); | 233 reason_string->value().size() > kMaxReasonSizeInBytes) |
| 232 if (!reason_string || | 234 return PP_ERROR_BADARGUMENT; |
| 233 reason_string->value().size() > kMaxReasonSizeInBytes) | 235 web_reason = WebString::fromUTF8(reason_string->value()); |
| 234 return PP_ERROR_BADARGUMENT; | 236 } |
| 235 web_reason = WebString::fromUTF8(reason_string->value()); | |
| 236 } | 237 } |
| 237 | 238 |
| 238 // Check state. | 239 // Check state. |
| 239 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING) | 240 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING) |
| 240 return PP_ERROR_INPROGRESS; | 241 return PP_ERROR_INPROGRESS; |
| 241 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED) | 242 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED) |
| 242 return PP_OK; | 243 return PP_OK; |
| 243 | 244 |
| 244 // Validate |callback| (Doesn't support blocking callback) | 245 // Validate |callback| (Doesn't support blocking callback) |
| 245 if (!callback.func) | 246 if (!callback.func) |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 | 530 |
| 530 *receive_callback_var_ = received_messages_.front()->GetPPVar(); | 531 *receive_callback_var_ = received_messages_.front()->GetPPVar(); |
| 531 received_messages_.pop(); | 532 received_messages_.pop(); |
| 532 receive_callback_var_ = NULL; | 533 receive_callback_var_ = NULL; |
| 533 wait_for_receive_ = false; | 534 wait_for_receive_ = false; |
| 534 return PP_OK; | 535 return PP_OK; |
| 535 } | 536 } |
| 536 | 537 |
| 537 } // namespace ppapi | 538 } // namespace ppapi |
| 538 } // namespace webkit | 539 } // namespace webkit |
| OLD | NEW |