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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 uint64_t GetFrameSize(uint64_t payload_size) { | 61 uint64_t GetFrameSize(uint64_t payload_size) { |
62 uint64_t overhead = kHybiBaseFramingOverhead + kHybiMaskingKeyLength; | 62 uint64_t overhead = kHybiBaseFramingOverhead + kHybiMaskingKeyLength; |
63 if (payload_size > kMinimumPayloadSizeWithEightByteExtendedPayloadLength) | 63 if (payload_size > kMinimumPayloadSizeWithEightByteExtendedPayloadLength) |
64 overhead += 8; | 64 overhead += 8; |
65 else if (payload_size > kMinimumPayloadSizeWithTwoByteExtendedPayloadLength) | 65 else if (payload_size > kMinimumPayloadSizeWithTwoByteExtendedPayloadLength) |
66 overhead += 2; | 66 overhead += 2; |
67 return SaturateAdd(payload_size, overhead); | 67 return SaturateAdd(payload_size, overhead); |
68 } | 68 } |
69 | 69 |
70 bool InValidStateToReceive(PP_WebSocketReadyState_Dev state) { | 70 bool InValidStateToReceive(PP_WebSocketReadyState state) { |
71 return state == PP_WEBSOCKETREADYSTATE_OPEN_DEV || | 71 return state == PP_WEBSOCKETREADYSTATE_OPEN || |
72 state == PP_WEBSOCKETREADYSTATE_CLOSING_DEV; | 72 state == PP_WEBSOCKETREADYSTATE_CLOSING; |
73 } | 73 } |
74 | 74 |
75 } // namespace | 75 } // namespace |
76 | 76 |
77 namespace webkit { | 77 namespace webkit { |
78 namespace ppapi { | 78 namespace ppapi { |
79 | 79 |
80 PPB_WebSocket_Impl::PPB_WebSocket_Impl(PP_Instance instance) | 80 PPB_WebSocket_Impl::PPB_WebSocket_Impl(PP_Instance instance) |
81 : Resource(instance), | 81 : Resource(instance), |
82 state_(PP_WEBSOCKETREADYSTATE_INVALID_DEV), | 82 state_(PP_WEBSOCKETREADYSTATE_INVALID), |
83 binary_type_(WebSocket::BinaryTypeBlob), | |
84 error_was_received_(false), | 83 error_was_received_(false), |
85 receive_callback_var_(NULL), | 84 receive_callback_var_(NULL), |
86 wait_for_receive_(false), | 85 wait_for_receive_(false), |
87 close_code_(0), | 86 close_code_(0), |
88 close_was_clean_(PP_FALSE), | 87 close_was_clean_(PP_FALSE), |
89 empty_string_(new StringVar("", 0)), | 88 empty_string_(new StringVar("", 0)), |
90 buffered_amount_(0), | 89 buffered_amount_(0), |
91 buffered_amount_after_close_(0) { | 90 buffered_amount_after_close_(0) { |
92 } | 91 } |
93 | 92 |
(...skipping 18 matching lines...) Expand all Loading... |
112 PP_CompletionCallback callback) { | 111 PP_CompletionCallback callback) { |
113 // Check mandatory interfaces. | 112 // Check mandatory interfaces. |
114 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | 113 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
115 DCHECK(plugin_instance); | 114 DCHECK(plugin_instance); |
116 if (!plugin_instance) | 115 if (!plugin_instance) |
117 return PP_ERROR_FAILED; | 116 return PP_ERROR_FAILED; |
118 | 117 |
119 // Connect() can be called at most once. | 118 // Connect() can be called at most once. |
120 if (websocket_.get()) | 119 if (websocket_.get()) |
121 return PP_ERROR_INPROGRESS; | 120 return PP_ERROR_INPROGRESS; |
122 if (state_ != PP_WEBSOCKETREADYSTATE_INVALID_DEV) | 121 if (state_ != PP_WEBSOCKETREADYSTATE_INVALID) |
123 return PP_ERROR_INPROGRESS; | 122 return PP_ERROR_INPROGRESS; |
124 state_ = PP_WEBSOCKETREADYSTATE_CLOSED_DEV; | 123 state_ = PP_WEBSOCKETREADYSTATE_CLOSED; |
125 | 124 |
126 // Validate url and convert it to WebURL. | 125 // Validate url and convert it to WebURL. |
127 scoped_refptr<StringVar> url_string = StringVar::FromPPVar(url); | 126 scoped_refptr<StringVar> url_string = StringVar::FromPPVar(url); |
128 if (!url_string) | 127 if (!url_string) |
129 return PP_ERROR_BADARGUMENT; | 128 return PP_ERROR_BADARGUMENT; |
130 GURL gurl(url_string->value()); | 129 GURL gurl(url_string->value()); |
131 url_ = new StringVar(gurl.spec()); | 130 url_ = new StringVar(gurl.spec()); |
132 if (!gurl.is_valid()) | 131 if (!gurl.is_valid()) |
133 return PP_ERROR_BADARGUMENT; | 132 return PP_ERROR_BADARGUMENT; |
134 if (!gurl.SchemeIs("ws") && !gurl.SchemeIs("wss")) | 133 if (!gurl.SchemeIs("ws") && !gurl.SchemeIs("wss")) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return PP_ERROR_BLOCKS_MAIN_THREAD; | 188 return PP_ERROR_BLOCKS_MAIN_THREAD; |
190 | 189 |
191 // Create WebKit::WebSocket object and connect. | 190 // Create WebKit::WebSocket object and connect. |
192 WebDocument document = plugin_instance->container()->element().document(); | 191 WebDocument document = plugin_instance->container()->element().document(); |
193 websocket_.reset(WebSocket::create(document, this)); | 192 websocket_.reset(WebSocket::create(document, this)); |
194 DCHECK(websocket_.get()); | 193 DCHECK(websocket_.get()); |
195 if (!websocket_.get()) | 194 if (!websocket_.get()) |
196 return PP_ERROR_NOTSUPPORTED; | 195 return PP_ERROR_NOTSUPPORTED; |
197 | 196 |
198 // Set receiving binary object type. | 197 // Set receiving binary object type. |
199 websocket_->setBinaryType(binary_type_); | 198 websocket_->setBinaryType(WebSocket::BinaryTypeArrayBuffer); |
200 | 199 |
201 websocket_->connect(web_url, web_protocols); | 200 websocket_->connect(web_url, web_protocols); |
202 state_ = PP_WEBSOCKETREADYSTATE_CONNECTING_DEV; | 201 state_ = PP_WEBSOCKETREADYSTATE_CONNECTING; |
203 | 202 |
204 // Install callback. | 203 // Install callback. |
205 connect_callback_ = new TrackedCallback(this, callback); | 204 connect_callback_ = new TrackedCallback(this, callback); |
206 | 205 |
207 return PP_OK_COMPLETIONPENDING; | 206 return PP_OK_COMPLETIONPENDING; |
208 } | 207 } |
209 | 208 |
210 int32_t PPB_WebSocket_Impl::Close(uint16_t code, | 209 int32_t PPB_WebSocket_Impl::Close(uint16_t code, |
211 PP_Var reason, | 210 PP_Var reason, |
212 PP_CompletionCallback callback) { | 211 PP_CompletionCallback callback) { |
(...skipping 14 matching lines...) Expand all Loading... |
227 } | 226 } |
228 | 227 |
229 // Validate |reason|. | 228 // Validate |reason|. |
230 // TODO(toyoshim): Returns PP_ERROR_BADARGUMENT if |reason| contains any | 229 // TODO(toyoshim): Returns PP_ERROR_BADARGUMENT if |reason| contains any |
231 // surrogates. | 230 // surrogates. |
232 scoped_refptr<StringVar> reason_string = StringVar::FromPPVar(reason); | 231 scoped_refptr<StringVar> reason_string = StringVar::FromPPVar(reason); |
233 if (!reason_string || reason_string->value().size() > kMaxReasonSizeInBytes) | 232 if (!reason_string || reason_string->value().size() > kMaxReasonSizeInBytes) |
234 return PP_ERROR_BADARGUMENT; | 233 return PP_ERROR_BADARGUMENT; |
235 | 234 |
236 // Check state. | 235 // Check state. |
237 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING_DEV || | 236 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING || |
238 state_ == PP_WEBSOCKETREADYSTATE_CLOSED_DEV) | 237 state_ == PP_WEBSOCKETREADYSTATE_CLOSED) |
239 return PP_ERROR_INPROGRESS; | 238 return PP_ERROR_INPROGRESS; |
240 | 239 |
241 // Validate |callback| (Doesn't support blocking callback) | 240 // Validate |callback| (Doesn't support blocking callback) |
242 if (!callback.func) | 241 if (!callback.func) |
243 return PP_ERROR_BLOCKS_MAIN_THREAD; | 242 return PP_ERROR_BLOCKS_MAIN_THREAD; |
244 | 243 |
245 // Install |callback|. | 244 // Install |callback|. |
246 close_callback_ = new TrackedCallback(this, callback); | 245 close_callback_ = new TrackedCallback(this, callback); |
247 | 246 |
248 // Abort ongoing connect. | 247 // Abort ongoing connect. |
249 if (state_ == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) { | 248 if (state_ == PP_WEBSOCKETREADYSTATE_CONNECTING) { |
250 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; | 249 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; |
251 // Need to do a "Post" to avoid reentering the plugin. | 250 // Need to do a "Post" to avoid reentering the plugin. |
252 connect_callback_->PostAbort(); | 251 connect_callback_->PostAbort(); |
253 connect_callback_ = NULL; | 252 connect_callback_ = NULL; |
254 websocket_->fail( | 253 websocket_->fail( |
255 "WebSocket was closed before the connection was established."); | 254 "WebSocket was closed before the connection was established."); |
256 return PP_OK_COMPLETIONPENDING; | 255 return PP_OK_COMPLETIONPENDING; |
257 } | 256 } |
258 | 257 |
259 // Abort ongoing receive. | 258 // Abort ongoing receive. |
260 if (wait_for_receive_) { | 259 if (wait_for_receive_) { |
261 wait_for_receive_ = false; | 260 wait_for_receive_ = false; |
262 receive_callback_var_ = NULL; | 261 receive_callback_var_ = NULL; |
263 | 262 |
264 // Need to do a "Post" to avoid reentering the plugin. | 263 // Need to do a "Post" to avoid reentering the plugin. |
265 receive_callback_->PostAbort(); | 264 receive_callback_->PostAbort(); |
266 receive_callback_ = NULL; | 265 receive_callback_ = NULL; |
267 } | 266 } |
268 | 267 |
269 // Close connection. | 268 // Close connection. |
270 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; | 269 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; |
271 WebString web_reason = WebString::fromUTF8(reason_string->value()); | 270 WebString web_reason = WebString::fromUTF8(reason_string->value()); |
272 websocket_->close(code, web_reason); | 271 websocket_->close(code, web_reason); |
273 | 272 |
274 return PP_OK_COMPLETIONPENDING; | 273 return PP_OK_COMPLETIONPENDING; |
275 } | 274 } |
276 | 275 |
277 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, | 276 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, |
278 PP_CompletionCallback callback) { | 277 PP_CompletionCallback callback) { |
279 // Check state. | 278 // Check state. |
280 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID_DEV || | 279 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID || |
281 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) | 280 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING) |
282 return PP_ERROR_BADARGUMENT; | 281 return PP_ERROR_BADARGUMENT; |
283 | 282 |
284 // Just return received message if any received message is queued. | 283 // Just return received message if any received message is queued. |
285 if (!received_messages_.empty()) { | 284 if (!received_messages_.empty()) { |
286 receive_callback_var_ = message; | 285 receive_callback_var_ = message; |
287 return DoReceive(); | 286 return DoReceive(); |
288 } | 287 } |
289 | 288 |
290 // Check state again. In CLOSED state, no more messages will be received. | 289 // Check state again. In CLOSED state, no more messages will be received. |
291 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED_DEV) | 290 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED) |
292 return PP_ERROR_BADARGUMENT; | 291 return PP_ERROR_BADARGUMENT; |
293 | 292 |
294 // Returns PP_ERROR_FAILED after an error is received and received messages | 293 // Returns PP_ERROR_FAILED after an error is received and received messages |
295 // is exhausted. | 294 // is exhausted. |
296 if (error_was_received_) | 295 if (error_was_received_) |
297 return PP_ERROR_FAILED; | 296 return PP_ERROR_FAILED; |
298 | 297 |
299 // Validate |callback| (Doesn't support blocking callback) | 298 // Validate |callback| (Doesn't support blocking callback) |
300 if (!callback.func) | 299 if (!callback.func) |
301 return PP_ERROR_BLOCKS_MAIN_THREAD; | 300 return PP_ERROR_BLOCKS_MAIN_THREAD; |
302 | 301 |
303 // Or retain |message| as buffer to store and install |callback|. | 302 // Or retain |message| as buffer to store and install |callback|. |
304 wait_for_receive_ = true; | 303 wait_for_receive_ = true; |
305 receive_callback_var_ = message; | 304 receive_callback_var_ = message; |
306 receive_callback_ = new TrackedCallback(this, callback); | 305 receive_callback_ = new TrackedCallback(this, callback); |
307 | 306 |
308 return PP_OK_COMPLETIONPENDING; | 307 return PP_OK_COMPLETIONPENDING; |
309 } | 308 } |
310 | 309 |
311 int32_t PPB_WebSocket_Impl::SendMessage(PP_Var message) { | 310 int32_t PPB_WebSocket_Impl::SendMessage(PP_Var message) { |
312 // Check mandatory interfaces. | 311 // Check mandatory interfaces. |
313 if (!websocket_.get()) | 312 if (!websocket_.get()) |
314 return PP_ERROR_FAILED; | 313 return PP_ERROR_FAILED; |
315 | 314 |
316 // Check state. | 315 // Check state. |
317 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID_DEV || | 316 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID || |
318 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) | 317 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING) |
319 return PP_ERROR_BADARGUMENT; | 318 return PP_ERROR_BADARGUMENT; |
320 | 319 |
321 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING_DEV || | 320 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING || |
322 state_ == PP_WEBSOCKETREADYSTATE_CLOSED_DEV) { | 321 state_ == PP_WEBSOCKETREADYSTATE_CLOSED) { |
323 // Handle buffered_amount_after_close_. | 322 // Handle buffered_amount_after_close_. |
324 uint64_t payload_size = 0; | 323 uint64_t payload_size = 0; |
325 if (message.type == PP_VARTYPE_STRING) { | 324 if (message.type == PP_VARTYPE_STRING) { |
326 scoped_refptr<StringVar> message_string = StringVar::FromPPVar(message); | 325 scoped_refptr<StringVar> message_string = StringVar::FromPPVar(message); |
327 if (message_string) | 326 if (message_string) |
328 payload_size += message_string->value().length(); | 327 payload_size += message_string->value().length(); |
329 } else if (message.type == PP_VARTYPE_ARRAY_BUFFER) { | 328 } else if (message.type == PP_VARTYPE_ARRAY_BUFFER) { |
330 scoped_refptr<ArrayBufferVar> message_array_buffer = | 329 scoped_refptr<ArrayBufferVar> message_array_buffer = |
331 ArrayBufferVar::FromPPVar(message); | 330 ArrayBufferVar::FromPPVar(message); |
332 if (message_array_buffer) | 331 if (message_array_buffer) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 395 |
397 PP_Var PPB_WebSocket_Impl::GetProtocol() { | 396 PP_Var PPB_WebSocket_Impl::GetProtocol() { |
398 // Check mandatory interfaces. | 397 // Check mandatory interfaces. |
399 if (!websocket_.get()) | 398 if (!websocket_.get()) |
400 return empty_string_->GetPPVar(); | 399 return empty_string_->GetPPVar(); |
401 | 400 |
402 std::string protocol = websocket_->subprotocol().utf8(); | 401 std::string protocol = websocket_->subprotocol().utf8(); |
403 return StringVar::StringToPPVar(protocol); | 402 return StringVar::StringToPPVar(protocol); |
404 } | 403 } |
405 | 404 |
406 PP_WebSocketReadyState_Dev PPB_WebSocket_Impl::GetReadyState() { | 405 PP_WebSocketReadyState PPB_WebSocket_Impl::GetReadyState() { |
407 return state_; | 406 return state_; |
408 } | 407 } |
409 | 408 |
410 PP_Var PPB_WebSocket_Impl::GetURL() { | 409 PP_Var PPB_WebSocket_Impl::GetURL() { |
411 if (!url_) | 410 if (!url_) |
412 return empty_string_->GetPPVar(); | 411 return empty_string_->GetPPVar(); |
413 return url_->GetPPVar(); | 412 return url_->GetPPVar(); |
414 } | 413 } |
415 | 414 |
416 PP_Bool PPB_WebSocket_Impl::SetBinaryType( | |
417 PP_WebSocketBinaryType_Dev binary_type) { | |
418 switch (binary_type) { | |
419 case PP_WEBSOCKETBINARYTYPE_BLOB_DEV: | |
420 binary_type_ = WebSocket::BinaryTypeBlob; | |
421 break; | |
422 case PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV: | |
423 binary_type_ = WebSocket::BinaryTypeArrayBuffer; | |
424 break; | |
425 default: | |
426 return PP_FALSE; | |
427 } | |
428 // WebKit API setBinaryType() is called when Connect() is called. | |
429 // If the websocket_ contains an object; it means Connect() is already | |
430 // called, call WebKit API here to reflect the setting as soon as possible. | |
431 if (websocket_.get()) | |
432 websocket_->setBinaryType(binary_type_); | |
433 return PP_TRUE; | |
434 } | |
435 | |
436 PP_WebSocketBinaryType_Dev PPB_WebSocket_Impl::GetBinaryType() { | |
437 switch (binary_type_) { | |
438 case WebSocket::BinaryTypeBlob: | |
439 return PP_WEBSOCKETBINARYTYPE_BLOB_DEV; | |
440 case WebSocket::BinaryTypeArrayBuffer: | |
441 return PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV; | |
442 default: | |
443 NOTREACHED(); | |
444 return PP_WEBSOCKETBINARYTYPE_INVALID; | |
445 } | |
446 } | |
447 | |
448 void PPB_WebSocket_Impl::didConnect() { | 415 void PPB_WebSocket_Impl::didConnect() { |
449 DCHECK_EQ(PP_WEBSOCKETREADYSTATE_CONNECTING_DEV, state_); | 416 DCHECK_EQ(PP_WEBSOCKETREADYSTATE_CONNECTING, state_); |
450 state_ = PP_WEBSOCKETREADYSTATE_OPEN_DEV; | 417 state_ = PP_WEBSOCKETREADYSTATE_OPEN; |
451 TrackedCallback::ClearAndRun(&connect_callback_, PP_OK); | 418 TrackedCallback::ClearAndRun(&connect_callback_, PP_OK); |
452 } | 419 } |
453 | 420 |
454 void PPB_WebSocket_Impl::didReceiveMessage(const WebString& message) { | 421 void PPB_WebSocket_Impl::didReceiveMessage(const WebString& message) { |
455 // Dispose packets after receiving an error or in invalid state. | 422 // Dispose packets after receiving an error or in invalid state. |
456 if (error_was_received_ || !InValidStateToReceive(state_)) | 423 if (error_was_received_ || !InValidStateToReceive(state_)) |
457 return; | 424 return; |
458 | 425 |
459 // Append received data to queue. | 426 // Append received data to queue. |
460 std::string string = message.utf8(); | 427 std::string string = message.utf8(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 | 463 |
497 // But, if no messages are queued and ReceiveMessage() is now on going. | 464 // But, if no messages are queued and ReceiveMessage() is now on going. |
498 // We must invoke the callback with error code here. | 465 // We must invoke the callback with error code here. |
499 wait_for_receive_ = false; | 466 wait_for_receive_ = false; |
500 receive_callback_var_ = NULL; | 467 receive_callback_var_ = NULL; |
501 TrackedCallback::ClearAndRun(&receive_callback_, PP_ERROR_FAILED); | 468 TrackedCallback::ClearAndRun(&receive_callback_, PP_ERROR_FAILED); |
502 } | 469 } |
503 | 470 |
504 void PPB_WebSocket_Impl::didUpdateBufferedAmount( | 471 void PPB_WebSocket_Impl::didUpdateBufferedAmount( |
505 unsigned long buffered_amount) { | 472 unsigned long buffered_amount) { |
506 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED_DEV) | 473 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED) |
507 return; | 474 return; |
508 buffered_amount_ = buffered_amount; | 475 buffered_amount_ = buffered_amount; |
509 } | 476 } |
510 | 477 |
511 void PPB_WebSocket_Impl::didStartClosingHandshake() { | 478 void PPB_WebSocket_Impl::didStartClosingHandshake() { |
512 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; | 479 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; |
513 } | 480 } |
514 | 481 |
515 void PPB_WebSocket_Impl::didClose(unsigned long unhandled_buffered_amount, | 482 void PPB_WebSocket_Impl::didClose(unsigned long unhandled_buffered_amount, |
516 ClosingHandshakeCompletionStatus status, | 483 ClosingHandshakeCompletionStatus status, |
517 unsigned short code, | 484 unsigned short code, |
518 const WebString& reason) { | 485 const WebString& reason) { |
519 // Store code and reason. | 486 // Store code and reason. |
520 close_code_ = code; | 487 close_code_ = code; |
521 std::string reason_string = reason.utf8(); | 488 std::string reason_string = reason.utf8(); |
522 close_reason_ = new StringVar(reason_string); | 489 close_reason_ = new StringVar(reason_string); |
523 | 490 |
524 // Set close_was_clean_. | 491 // Set close_was_clean_. |
525 bool was_clean = | 492 bool was_clean = |
526 state_ == PP_WEBSOCKETREADYSTATE_CLOSING_DEV && | 493 state_ == PP_WEBSOCKETREADYSTATE_CLOSING && |
527 !unhandled_buffered_amount && | 494 !unhandled_buffered_amount && |
528 status == WebSocketClient::ClosingHandshakeComplete; | 495 status == WebSocketClient::ClosingHandshakeComplete; |
529 close_was_clean_ = was_clean ? PP_TRUE : PP_FALSE; | 496 close_was_clean_ = was_clean ? PP_TRUE : PP_FALSE; |
530 | 497 |
531 // Update buffered_amount_. | 498 // Update buffered_amount_. |
532 buffered_amount_ = unhandled_buffered_amount; | 499 buffered_amount_ = unhandled_buffered_amount; |
533 | 500 |
534 // Handle state transition and invoking callback. | 501 // Handle state transition and invoking callback. |
535 DCHECK_NE(PP_WEBSOCKETREADYSTATE_CLOSED_DEV, state_); | 502 DCHECK_NE(PP_WEBSOCKETREADYSTATE_CLOSED, state_); |
536 PP_WebSocketReadyState_Dev state = state_; | 503 PP_WebSocketReadyState state = state_; |
537 state_ = PP_WEBSOCKETREADYSTATE_CLOSED_DEV; | 504 state_ = PP_WEBSOCKETREADYSTATE_CLOSED; |
538 | 505 |
539 if (state == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) | 506 if (state == PP_WEBSOCKETREADYSTATE_CONNECTING) |
540 TrackedCallback::ClearAndRun(&connect_callback_, PP_ERROR_FAILED); | 507 TrackedCallback::ClearAndRun(&connect_callback_, PP_ERROR_FAILED); |
541 | 508 |
542 if (wait_for_receive_) { | 509 if (wait_for_receive_) { |
543 wait_for_receive_ = false; | 510 wait_for_receive_ = false; |
544 receive_callback_var_ = NULL; | 511 receive_callback_var_ = NULL; |
545 TrackedCallback::ClearAndAbort(&receive_callback_); | 512 TrackedCallback::ClearAndAbort(&receive_callback_); |
546 } | 513 } |
547 | 514 |
548 if (state == PP_WEBSOCKETREADYSTATE_CLOSING_DEV) | 515 if (state == PP_WEBSOCKETREADYSTATE_CLOSING) |
549 TrackedCallback::ClearAndRun(&close_callback_, PP_OK); | 516 TrackedCallback::ClearAndRun(&close_callback_, PP_OK); |
550 | 517 |
551 // Disconnect. | 518 // Disconnect. |
552 if (websocket_.get()) | 519 if (websocket_.get()) |
553 websocket_->disconnect(); | 520 websocket_->disconnect(); |
554 } | 521 } |
555 | 522 |
556 int32_t PPB_WebSocket_Impl::DoReceive() { | 523 int32_t PPB_WebSocket_Impl::DoReceive() { |
557 if (!receive_callback_var_) | 524 if (!receive_callback_var_) |
558 return PP_OK; | 525 return PP_OK; |
559 | 526 |
560 *receive_callback_var_ = received_messages_.front()->GetPPVar(); | 527 *receive_callback_var_ = received_messages_.front()->GetPPVar(); |
561 received_messages_.pop(); | 528 received_messages_.pop(); |
562 receive_callback_var_ = NULL; | 529 receive_callback_var_ = NULL; |
563 wait_for_receive_ = false; | 530 wait_for_receive_ = false; |
564 return PP_OK; | 531 return PP_OK; |
565 } | 532 } |
566 | 533 |
567 } // namespace ppapi | 534 } // namespace ppapi |
568 } // namespace webkit | 535 } // namespace webkit |
OLD | NEW |