Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: webkit/plugins/ppapi/ppb_websocket_impl.cc

Issue 9296001: WebSocket Pepper API: Remove binary type handling interfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppb_websocket_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_DEV),
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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_DEV;
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
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 PP_WebSocketReadyState_Dev PPB_WebSocket_Impl::GetReadyState() { 405 PP_WebSocketReadyState_Dev 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_DEV, state_);
450 state_ = PP_WEBSOCKETREADYSTATE_OPEN_DEV; 417 state_ = PP_WEBSOCKETREADYSTATE_OPEN_DEV;
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;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_websocket_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698