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

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

Issue 10332138: WebSocket Pepper API: allow to close connection without code and reason (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reuse 1005 Created 8 years, 7 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
« ppapi/api/ppb_websocket.idl ('K') | « ppapi/tests/test_websocket.cc ('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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
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|.
215 // uint16_t for the comparison to work.
216 if (code != static_cast<uint16_t>(WebSocket::CloseEventCodeNotSpecified)) {
217 if (!(code == WebSocket::CloseEventCodeNormalClosure ||
218 (WebSocket::CloseEventCodeMinimumUserDefined <= code &&
219 code <= WebSocket::CloseEventCodeMaximumUserDefined)))
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/)
222 // defines this out of range error as InvalidAccessError in JavaScript.
223 return PP_ERROR_NOACCESS;
224 }
225
226 scoped_refptr<StringVar> reason_string; 215 scoped_refptr<StringVar> reason_string;
227 WebString web_reason; 216 WebString web_reason;
228 // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED. 217 WebSocket::CloseEventCode event_code =
229 if (reason.type != PP_VARTYPE_UNDEFINED) { 218 static_cast<WebSocket::CloseEventCode>(code);
230 // Validate |reason|. 219 if (code == PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED) {
231 reason_string = StringVar::FromPPVar(reason); 220 // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED and CloseEventCodeNotSpecified are
232 if (!reason_string || 221 // assigned to different values. A conversion is needed if
233 reason_string->value().size() > kMaxReasonSizeInBytes) 222 // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED is specified.
234 return PP_ERROR_BADARGUMENT; 223 event_code = WebSocket::CloseEventCodeNotSpecified;
235 web_reason = WebString::fromUTF8(reason_string->value()); 224 } else {
225 if (!(code == PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE ||
226 (PP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MIN <= code &&
227 code <= PP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MAX)))
228 // RFC 6455 limits applications to use reserved connection close code in
229 // section 7.4.2.. The WebSocket API (http://www.w3.org/TR/websockets/)
230 // defines this out of range error as InvalidAccessError in JavaScript.
231 return PP_ERROR_NOACCESS;
232
233 // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED or |code| is
234 // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED.
235 if (reason.type != PP_VARTYPE_UNDEFINED) {
236 // Validate |reason|.
237 reason_string = StringVar::FromPPVar(reason);
238 if (!reason_string ||
239 reason_string->value().size() > kMaxReasonSizeInBytes)
240 return PP_ERROR_BADARGUMENT;
241 web_reason = WebString::fromUTF8(reason_string->value());
242 }
236 } 243 }
237 244
238 // Check state. 245 // Check state.
239 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING) 246 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSING)
240 return PP_ERROR_INPROGRESS; 247 return PP_ERROR_INPROGRESS;
241 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED) 248 if (state_ == PP_WEBSOCKETREADYSTATE_CLOSED)
242 return PP_OK; 249 return PP_OK;
243 250
244 // Validate |callback| (Doesn't support blocking callback) 251 // Validate |callback| (Doesn't support blocking callback)
245 if (!callback.func) 252 if (!callback.func)
(...skipping 18 matching lines...) Expand all
264 wait_for_receive_ = false; 271 wait_for_receive_ = false;
265 receive_callback_var_ = NULL; 272 receive_callback_var_ = NULL;
266 273
267 // Need to do a "Post" to avoid reentering the plugin. 274 // Need to do a "Post" to avoid reentering the plugin.
268 receive_callback_->PostAbort(); 275 receive_callback_->PostAbort();
269 receive_callback_ = NULL; 276 receive_callback_ = NULL;
270 } 277 }
271 278
272 // Close connection. 279 // Close connection.
273 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; 280 state_ = PP_WEBSOCKETREADYSTATE_CLOSING;
274 websocket_->close(code, web_reason); 281 websocket_->close(event_code, web_reason);
275 282
276 return PP_OK_COMPLETIONPENDING; 283 return PP_OK_COMPLETIONPENDING;
277 } 284 }
278 285
279 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, 286 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message,
280 PP_CompletionCallback callback) { 287 PP_CompletionCallback callback) {
281 // Check state. 288 // Check state.
282 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID || 289 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID ||
283 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING) 290 state_ == PP_WEBSOCKETREADYSTATE_CONNECTING)
284 return PP_ERROR_BADARGUMENT; 291 return PP_ERROR_BADARGUMENT;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 536
530 *receive_callback_var_ = received_messages_.front()->GetPPVar(); 537 *receive_callback_var_ = received_messages_.front()->GetPPVar();
531 received_messages_.pop(); 538 received_messages_.pop();
532 receive_callback_var_ = NULL; 539 receive_callback_var_ = NULL;
533 wait_for_receive_ = false; 540 wait_for_receive_ = false;
534 return PP_OK; 541 return PP_OK;
535 } 542 }
536 543
537 } // namespace ppapi 544 } // namespace ppapi
538 } // namespace webkit 545 } // namespace webkit
OLDNEW
« ppapi/api/ppb_websocket.idl ('K') | « ppapi/tests/test_websocket.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698