OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 state_ == PP_WEBSOCKETREADYSTATE_CLOSED_DEV) | 227 state_ == PP_WEBSOCKETREADYSTATE_CLOSED_DEV) |
228 return PP_ERROR_INPROGRESS; | 228 return PP_ERROR_INPROGRESS; |
229 | 229 |
230 // Validate |callback| (Doesn't support blocking callback) | 230 // Validate |callback| (Doesn't support blocking callback) |
231 if (!callback.func) | 231 if (!callback.func) |
232 return PP_ERROR_BLOCKS_MAIN_THREAD; | 232 return PP_ERROR_BLOCKS_MAIN_THREAD; |
233 | 233 |
234 // Install |callback|. | 234 // Install |callback|. |
235 close_callback_ = callback; | 235 close_callback_ = callback; |
236 | 236 |
| 237 // Abort ongoing connect. |
237 if (state_ == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) { | 238 if (state_ == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) { |
238 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; | 239 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; |
239 PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_ABORTED); | 240 PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_ABORTED); |
240 websocket_->fail( | 241 websocket_->fail( |
241 "WebSocket was closed before the connection was established."); | 242 "WebSocket was closed before the connection was established."); |
242 return PP_OK_COMPLETIONPENDING; | 243 return PP_OK_COMPLETIONPENDING; |
243 } | 244 } |
244 | 245 |
| 246 // Abort ongoing receive. |
| 247 if (wait_for_receive_) { |
| 248 wait_for_receive_ = false; |
| 249 receive_callback_var_ = NULL; |
| 250 PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_ABORTED); |
| 251 } |
| 252 |
245 // Close connection. | 253 // Close connection. |
246 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; | 254 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; |
247 WebString web_reason = WebString::fromUTF8(reason_string->value()); | 255 WebString web_reason = WebString::fromUTF8(reason_string->value()); |
248 websocket_->close(code, web_reason); | 256 websocket_->close(code, web_reason); |
249 | 257 |
250 return PP_OK_COMPLETIONPENDING; | 258 return PP_OK_COMPLETIONPENDING; |
251 } | 259 } |
252 | 260 |
253 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, | 261 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, |
254 PP_CompletionCallback callback) { | 262 PP_CompletionCallback callback) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 // Records the error, then stops receiving any frames after this error. | 415 // Records the error, then stops receiving any frames after this error. |
408 // The error will be notified after all queued messages are read via | 416 // The error will be notified after all queued messages are read via |
409 // ReceiveMessage(). | 417 // ReceiveMessage(). |
410 error_was_received_ = true; | 418 error_was_received_ = true; |
411 if (!wait_for_receive_) | 419 if (!wait_for_receive_) |
412 return; | 420 return; |
413 | 421 |
414 // But, if no messages are queued and ReceiveMessage() is now on going. | 422 // But, if no messages are queued and ReceiveMessage() is now on going. |
415 // We must invoke the callback with error code here. | 423 // We must invoke the callback with error code here. |
416 wait_for_receive_ = false; | 424 wait_for_receive_ = false; |
| 425 receive_callback_var_ = NULL; |
417 PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_FAILED); | 426 PP_RunAndClearCompletionCallback(&receive_callback_, PP_ERROR_FAILED); |
418 } | 427 } |
419 | 428 |
420 void PPB_WebSocket_Impl::didUpdateBufferedAmount( | 429 void PPB_WebSocket_Impl::didUpdateBufferedAmount( |
421 unsigned long buffered_amount) { | 430 unsigned long buffered_amount) { |
422 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED_DEV) | 431 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED_DEV) |
423 return; | 432 return; |
424 buffered_amount_ = buffered_amount; | 433 buffered_amount_ = buffered_amount; |
425 } | 434 } |
426 | 435 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 479 |
471 *receive_callback_var_ = received_messages_.front(); | 480 *receive_callback_var_ = received_messages_.front(); |
472 received_messages_.pop(); | 481 received_messages_.pop(); |
473 receive_callback_var_ = NULL; | 482 receive_callback_var_ = NULL; |
474 wait_for_receive_ = false; | 483 wait_for_receive_ = false; |
475 return PP_OK; | 484 return PP_OK; |
476 } | 485 } |
477 | 486 |
478 } // namespace ppapi | 487 } // namespace ppapi |
479 } // namespace webkit | 488 } // namespace webkit |
OLD | NEW |