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 "ppapi/proxy/websocket_resource.h" | 5 #include "ppapi/proxy/websocket_resource.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/proxy/dispatch_reply_message.h" | 13 #include "ppapi/proxy/dispatch_reply_message.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
15 #include "ppapi/shared_impl/ppapi_globals.h" | 15 #include "ppapi/shared_impl/ppapi_globals.h" |
16 #include "ppapi/shared_impl/var.h" | 16 #include "ppapi/shared_impl/var.h" |
17 #include "ppapi/shared_impl/var_tracker.h" | 17 #include "ppapi/shared_impl/var_tracker.h" |
18 #include "third_party/WebKit/public/web/WebSocket.h" | |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 const uint32_t kMaxReasonSizeInBytes = 123; | 21 const uint32_t kMaxReasonSizeInBytes = 123; |
23 const size_t kBaseFramingOverhead = 2; | 22 const size_t kBaseFramingOverhead = 2; |
24 const size_t kMaskingKeyLength = 4; | 23 const size_t kMaskingKeyLength = 4; |
25 const size_t kMinimumPayloadSizeWithTwoByteExtendedPayloadLength = 126; | 24 const size_t kMinimumPayloadSizeWithTwoByteExtendedPayloadLength = 126; |
26 const size_t kMinimumPayloadSizeWithEightByteExtendedPayloadLength = 0x10000; | 25 const size_t kMinimumPayloadSizeWithEightByteExtendedPayloadLength = 0x10000; |
27 | 26 |
28 uint64_t SaturateAdd(uint64_t a, uint64_t b) { | 27 uint64_t SaturateAdd(uint64_t a, uint64_t b) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 const PP_Var& reason, | 129 const PP_Var& reason, |
131 scoped_refptr<TrackedCallback> callback) { | 130 scoped_refptr<TrackedCallback> callback) { |
132 if (TrackedCallback::IsPending(close_callback_)) | 131 if (TrackedCallback::IsPending(close_callback_)) |
133 return PP_ERROR_INPROGRESS; | 132 return PP_ERROR_INPROGRESS; |
134 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID) | 133 if (state_ == PP_WEBSOCKETREADYSTATE_INVALID) |
135 return PP_ERROR_FAILED; | 134 return PP_ERROR_FAILED; |
136 | 135 |
137 // Validate |code| and |reason|. | 136 // Validate |code| and |reason|. |
138 scoped_refptr<StringVar> reason_string_var; | 137 scoped_refptr<StringVar> reason_string_var; |
139 std::string reason_string; | 138 std::string reason_string; |
140 blink::WebSocket::CloseEventCode event_code = | 139 if (code != PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED) { |
141 static_cast<blink::WebSocket::CloseEventCode>(code); | 140 if ((code != PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE && |
dmichael (off chromium)
2014/03/18 18:02:30
nit: I think you have an extra set of enclosing pa
bbudge
2014/03/18 20:23:31
Done.
| |
142 if (code == PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED) { | 141 (PP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MIN > code || |
dmichael (off chromium)
2014/03/18 18:02:30
nit: now that you negated this, I think it would b
bbudge
2014/03/18 20:23:31
Done. (Just reversed the first, is that what you m
dmichael (off chromium)
2014/03/18 20:38:53
Yes, that's exactly what I meant, thanks!
| |
143 // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED and CloseEventCodeNotSpecified are | 142 code > PP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MAX))) |
144 // assigned to different values. A conversion is needed if | |
145 // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED is specified. | |
146 event_code = blink::WebSocket::CloseEventCodeNotSpecified; | |
147 } else { | |
148 if (!(code == PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE || | |
149 (PP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MIN <= code && | |
150 code <= PP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MAX))) | |
151 // RFC 6455 limits applications to use reserved connection close code in | 143 // RFC 6455 limits applications to use reserved connection close code in |
152 // section 7.4.2.. The WebSocket API (http://www.w3.org/TR/websockets/) | 144 // section 7.4.2.. The WebSocket API (http://www.w3.org/TR/websockets/) |
153 // defines this out of range error as InvalidAccessError in JavaScript. | 145 // defines this out of range error as InvalidAccessError in JavaScript. |
154 return PP_ERROR_NOACCESS; | 146 return PP_ERROR_NOACCESS; |
155 | 147 |
156 // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED or |code| is | 148 // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED or |code| is |
157 // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED. | 149 // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED. |
158 if (reason.type != PP_VARTYPE_UNDEFINED) { | 150 if (reason.type != PP_VARTYPE_UNDEFINED) { |
159 // Validate |reason|. | 151 // Validate |reason|. |
160 reason_string_var = StringVar::FromPPVar(reason); | 152 reason_string_var = StringVar::FromPPVar(reason); |
(...skipping 27 matching lines...) Expand all Loading... | |
188 // Abort ongoing receive. | 180 // Abort ongoing receive. |
189 if (TrackedCallback::IsPending(receive_callback_)) { | 181 if (TrackedCallback::IsPending(receive_callback_)) { |
190 receive_callback_var_ = NULL; | 182 receive_callback_var_ = NULL; |
191 // Need to do a "Post" to avoid reentering the plugin. | 183 // Need to do a "Post" to avoid reentering the plugin. |
192 receive_callback_->PostAbort(); | 184 receive_callback_->PostAbort(); |
193 receive_callback_ = NULL; | 185 receive_callback_ = NULL; |
194 } | 186 } |
195 | 187 |
196 // Close connection. | 188 // Close connection. |
197 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; | 189 state_ = PP_WEBSOCKETREADYSTATE_CLOSING; |
198 PpapiHostMsg_WebSocket_Close msg(static_cast<int32_t>(event_code), | 190 PpapiHostMsg_WebSocket_Close msg(static_cast<int32_t>(code), |
199 reason_string); | 191 reason_string); |
200 Call<PpapiPluginMsg_WebSocket_CloseReply>(RENDERER, msg, | 192 Call<PpapiPluginMsg_WebSocket_CloseReply>(RENDERER, msg, |
201 base::Bind(&WebSocketResource::OnPluginMsgCloseReply, this)); | 193 base::Bind(&WebSocketResource::OnPluginMsgCloseReply, this)); |
202 return PP_OK_COMPLETIONPENDING; | 194 return PP_OK_COMPLETIONPENDING; |
203 } | 195 } |
204 | 196 |
205 int32_t WebSocketResource::ReceiveMessage( | 197 int32_t WebSocketResource::ReceiveMessage( |
206 PP_Var* message, | 198 PP_Var* message, |
207 scoped_refptr<TrackedCallback> callback) { | 199 scoped_refptr<TrackedCallback> callback) { |
208 if (TrackedCallback::IsPending(receive_callback_)) | 200 if (TrackedCallback::IsPending(receive_callback_)) |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 return PP_OK; | 477 return PP_OK; |
486 | 478 |
487 *receive_callback_var_ = received_messages_.front()->GetPPVar(); | 479 *receive_callback_var_ = received_messages_.front()->GetPPVar(); |
488 received_messages_.pop(); | 480 received_messages_.pop(); |
489 receive_callback_var_ = NULL; | 481 receive_callback_var_ = NULL; |
490 return PP_OK; | 482 return PP_OK; |
491 } | 483 } |
492 | 484 |
493 } // namespace proxy | 485 } // namespace proxy |
494 } // namespace ppapi | 486 } // namespace ppapi |
OLD | NEW |