| 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/cpp/websocket.h" | 5 #include "ppapi/cpp/websocket.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/pp_macros.h" | 8 #include "ppapi/c/pp_macros.h" |
| 9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
| 10 #include "ppapi/cpp/instance_handle.h" | 10 #include "ppapi/cpp/instance_handle.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 WebSocket::~WebSocket() { | 32 WebSocket::~WebSocket() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 int32_t WebSocket::Connect(const Var& url, const Var protocols[], | 35 int32_t WebSocket::Connect(const Var& url, const Var protocols[], |
| 36 uint32_t protocol_count, const CompletionCallback& callback) { | 36 uint32_t protocol_count, const CompletionCallback& callback) { |
| 37 if (!has_interface<PPB_WebSocket_1_0>()) | 37 if (!has_interface<PPB_WebSocket_1_0>()) |
| 38 return PP_ERROR_BADRESOURCE; | 38 return PP_ERROR_BADRESOURCE; |
| 39 | 39 |
| 40 // Convert protocols to C interface. | 40 // Convert protocols to C interface. |
| 41 PP_Var *c_protocols = NULL; | 41 PP_Var *c_protocols = NULL; |
| 42 if (protocol_count) { | 42 if (protocol_count) |
| 43 c_protocols = new PP_Var[protocol_count]; | 43 c_protocols = new PP_Var[protocol_count]; |
| 44 if (!c_protocols) | |
| 45 return PP_ERROR_NOMEMORY; | |
| 46 } | |
| 47 for (uint32_t i = 0; i < protocol_count; ++i) | 44 for (uint32_t i = 0; i < protocol_count; ++i) |
| 48 c_protocols[i] = protocols[i].pp_var(); | 45 c_protocols[i] = protocols[i].pp_var(); |
| 49 | 46 |
| 50 int32_t result = get_interface<PPB_WebSocket_1_0>()->Connect( | 47 int32_t result = get_interface<PPB_WebSocket_1_0>()->Connect( |
| 51 pp_resource(), url.pp_var(), c_protocols, protocol_count, | 48 pp_resource(), url.pp_var(), c_protocols, protocol_count, |
| 52 callback.pp_completion_callback()); | 49 callback.pp_completion_callback()); |
| 53 if (c_protocols) | 50 if (c_protocols) |
| 54 delete[] c_protocols; | 51 delete[] c_protocols; |
| 55 return result; | 52 return result; |
| 56 } | 53 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 140 |
| 144 Var WebSocket::GetURL() { | 141 Var WebSocket::GetURL() { |
| 145 if (!has_interface<PPB_WebSocket_1_0>()) | 142 if (!has_interface<PPB_WebSocket_1_0>()) |
| 146 return Var(); | 143 return Var(); |
| 147 | 144 |
| 148 return Var(PASS_REF, | 145 return Var(PASS_REF, |
| 149 get_interface<PPB_WebSocket_1_0>()->GetURL(pp_resource())); | 146 get_interface<PPB_WebSocket_1_0>()->GetURL(pp_resource())); |
| 150 } | 147 } |
| 151 | 148 |
| 152 } // namespace pp | 149 } // namespace pp |
| OLD | NEW |