| 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 "content/renderer/pepper/pepper_websocket_host.h" | 5 #include "content/renderer/pepper/pepper_websocket_host.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "content/public/renderer/renderer_ppapi_host.h" | 9 #include "content/public/renderer/renderer_ppapi_host.h" |
| 10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "third_party/WebKit/public/web/WebSocket.h" | 23 #include "third_party/WebKit/public/web/WebSocket.h" |
| 24 | 24 |
| 25 using blink::WebArrayBuffer; | 25 using blink::WebArrayBuffer; |
| 26 using blink::WebDocument; | 26 using blink::WebDocument; |
| 27 using blink::WebString; | 27 using blink::WebString; |
| 28 using blink::WebSocket; | 28 using blink::WebSocket; |
| 29 using blink::WebURL; | 29 using blink::WebURL; |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 #define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, np_name) \ |
| 34 COMPILE_ASSERT(static_cast<int>(WebSocket::webkit_name) \ |
| 35 == static_cast<int>(np_name), \ |
| 36 mismatching_enums) |
| 37 |
| 38 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeNormalClosure, |
| 39 PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE); |
| 40 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeGoingAway, |
| 41 PP_WEBSOCKETSTATUSCODE_GOING_AWAY); |
| 42 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeProtocolError, |
| 43 PP_WEBSOCKETSTATUSCODE_PROTOCOL_ERROR); |
| 44 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeUnsupportedData, |
| 45 PP_WEBSOCKETSTATUSCODE_UNSUPPORTED_DATA); |
| 46 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeNoStatusRcvd, |
| 47 PP_WEBSOCKETSTATUSCODE_NO_STATUS_RECEIVED); |
| 48 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeAbnormalClosure, |
| 49 PP_WEBSOCKETSTATUSCODE_ABNORMAL_CLOSURE); |
| 50 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeInvalidFramePayloadData, |
| 51 PP_WEBSOCKETSTATUSCODE_INVALID_FRAME_PAYLOAD_DATA); |
| 52 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodePolicyViolation, |
| 53 PP_WEBSOCKETSTATUSCODE_POLICY_VIOLATION); |
| 54 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeMessageTooBig, |
| 55 PP_WEBSOCKETSTATUSCODE_MESSAGE_TOO_BIG); |
| 56 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeMandatoryExt, |
| 57 PP_WEBSOCKETSTATUSCODE_MANDATORY_EXTENSION); |
| 58 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeInternalError, |
| 59 PP_WEBSOCKETSTATUSCODE_INTERNAL_SERVER_ERROR); |
| 60 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeTLSHandshake, |
| 61 PP_WEBSOCKETSTATUSCODE_TLS_HANDSHAKE); |
| 62 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeMinimumUserDefined, |
| 63 PP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MIN); |
| 64 COMPILE_ASSERT_MATCHING_ENUM(CloseEventCodeMaximumUserDefined, |
| 65 PP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MAX); |
| 66 |
| 33 PepperWebSocketHost::PepperWebSocketHost( | 67 PepperWebSocketHost::PepperWebSocketHost( |
| 34 RendererPpapiHost* host, | 68 RendererPpapiHost* host, |
| 35 PP_Instance instance, | 69 PP_Instance instance, |
| 36 PP_Resource resource) | 70 PP_Resource resource) |
| 37 : ResourceHost(host->GetPpapiHost(), instance, resource), | 71 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 38 renderer_ppapi_host_(host), | 72 renderer_ppapi_host_(host), |
| 39 connecting_(false), | 73 connecting_(false), |
| 40 initiating_close_(false), | 74 initiating_close_(false), |
| 41 accepting_close_(false), | 75 accepting_close_(false), |
| 42 error_was_received_(false) { | 76 error_was_received_(false) { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 280 } |
| 247 | 281 |
| 248 int32_t PepperWebSocketHost::OnHostMsgClose( | 282 int32_t PepperWebSocketHost::OnHostMsgClose( |
| 249 ppapi::host::HostMessageContext* context, | 283 ppapi::host::HostMessageContext* context, |
| 250 int32_t code, | 284 int32_t code, |
| 251 const std::string& reason) { | 285 const std::string& reason) { |
| 252 if (!websocket_) | 286 if (!websocket_) |
| 253 return PP_ERROR_FAILED; | 287 return PP_ERROR_FAILED; |
| 254 close_reply_ = context->MakeReplyMessageContext(); | 288 close_reply_ = context->MakeReplyMessageContext(); |
| 255 initiating_close_ = true; | 289 initiating_close_ = true; |
| 290 |
| 291 blink::WebSocket::CloseEventCode event_code = |
| 292 static_cast<blink::WebSocket::CloseEventCode>(code); |
| 293 if (code == PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED) { |
| 294 // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED and CloseEventCodeNotSpecified are |
| 295 // assigned to different values. A conversion is needed if |
| 296 // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED is specified. |
| 297 event_code = blink::WebSocket::CloseEventCodeNotSpecified; |
| 298 } |
| 299 |
| 256 WebString web_reason = WebString::fromUTF8(reason); | 300 WebString web_reason = WebString::fromUTF8(reason); |
| 257 websocket_->close(code, web_reason); | 301 websocket_->close(event_code, web_reason); |
| 258 return PP_OK_COMPLETIONPENDING; | 302 return PP_OK_COMPLETIONPENDING; |
| 259 } | 303 } |
| 260 | 304 |
| 261 int32_t PepperWebSocketHost::OnHostMsgSendText( | 305 int32_t PepperWebSocketHost::OnHostMsgSendText( |
| 262 ppapi::host::HostMessageContext* context, | 306 ppapi::host::HostMessageContext* context, |
| 263 const std::string& message) { | 307 const std::string& message) { |
| 264 if (websocket_) { | 308 if (websocket_) { |
| 265 WebString web_message = WebString::fromUTF8(message); | 309 WebString web_message = WebString::fromUTF8(message); |
| 266 websocket_->sendText(web_message); | 310 websocket_->sendText(web_message); |
| 267 } | 311 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 281 | 325 |
| 282 int32_t PepperWebSocketHost::OnHostMsgFail( | 326 int32_t PepperWebSocketHost::OnHostMsgFail( |
| 283 ppapi::host::HostMessageContext* context, | 327 ppapi::host::HostMessageContext* context, |
| 284 const std::string& message) { | 328 const std::string& message) { |
| 285 if (websocket_) | 329 if (websocket_) |
| 286 websocket_->fail(WebString::fromUTF8(message)); | 330 websocket_->fail(WebString::fromUTF8(message)); |
| 287 return PP_OK; | 331 return PP_OK; |
| 288 } | 332 } |
| 289 | 333 |
| 290 } // namespace content | 334 } // namespace content |
| OLD | NEW |