| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/c/pp_errors.h" | 5 #include "ppapi/c/pp_errors.h" |
| 6 #include "ppapi/c/pp_var.h" | 6 #include "ppapi/c/pp_var.h" |
| 7 #include "ppapi/thunk/common.h" |
| 7 #include "ppapi/thunk/thunk.h" | 8 #include "ppapi/thunk/thunk.h" |
| 8 #include "ppapi/thunk/enter.h" | 9 #include "ppapi/thunk/enter.h" |
| 9 #include "ppapi/thunk/ppb_websocket_api.h" | 10 #include "ppapi/thunk/ppb_websocket_api.h" |
| 10 #include "ppapi/thunk/resource_creation_api.h" | 11 #include "ppapi/thunk/resource_creation_api.h" |
| 11 | 12 |
| 12 namespace ppapi { | 13 namespace ppapi { |
| 13 namespace thunk { | 14 namespace thunk { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 PP_Resource Create(PP_Instance instance) { | 18 PP_Resource Create(PP_Instance instance) { |
| 18 EnterFunction<ResourceCreationAPI> enter(instance, true); | 19 EnterFunction<ResourceCreationAPI> enter(instance, true); |
| 19 if (enter.failed()) | 20 if (enter.failed()) |
| 20 return 0; | 21 return 0; |
| 21 return enter.functions()->CreateWebSocket(instance); | 22 return enter.functions()->CreateWebSocket(instance); |
| 22 } | 23 } |
| 23 | 24 |
| 24 PP_Bool IsWebSocket(PP_Resource resource) { | 25 PP_Bool IsWebSocket(PP_Resource resource) { |
| 25 EnterResource<PPB_WebSocket_API> enter(resource, false); | 26 EnterResource<PPB_WebSocket_API> enter(resource, false); |
| 26 return PP_FromBool(enter.succeeded()); | 27 return PP_FromBool(enter.succeeded()); |
| 27 } | 28 } |
| 28 | 29 |
| 29 int32_t Connect(PP_Resource resource, | 30 int32_t Connect(PP_Resource resource, |
| 30 PP_Var url, | 31 PP_Var url, |
| 31 const PP_Var protocols[], | 32 const PP_Var protocols[], |
| 32 uint32_t protocol_count, | 33 uint32_t protocol_count, |
| 33 PP_CompletionCallback callback) { | 34 PP_CompletionCallback callback) { |
| 34 EnterResource<PPB_WebSocket_API> enter(resource, false); | 35 EnterResource<PPB_WebSocket_API> enter(resource, false); |
| 35 if (enter.failed()) | 36 if (enter.failed()) |
| 36 return PP_ERROR_BADRESOURCE; | 37 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); |
| 37 return enter.object()->Connect(url, protocols, protocol_count, callback); | 38 int32_t result = |
| 39 enter.object()->Connect(url, protocols, protocol_count, callback); |
| 40 return MayForceCallback(callback, result); |
| 38 } | 41 } |
| 39 | 42 |
| 40 int32_t Close(PP_Resource resource, | 43 int32_t Close(PP_Resource resource, |
| 41 uint16_t code, | 44 uint16_t code, |
| 42 PP_Var reason, | 45 PP_Var reason, |
| 43 PP_CompletionCallback callback) { | 46 PP_CompletionCallback callback) { |
| 44 EnterResource<PPB_WebSocket_API> enter(resource, false); | 47 EnterResource<PPB_WebSocket_API> enter(resource, false); |
| 45 if (enter.failed()) | 48 if (enter.failed()) |
| 46 return PP_ERROR_BADRESOURCE; | 49 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); |
| 47 return enter.object()->Close(code, reason, callback); | 50 int32_t result = enter.object()->Close(code, reason, callback); |
| 51 return MayForceCallback(callback, result); |
| 48 } | 52 } |
| 49 | 53 |
| 50 int32_t ReceiveMessage(PP_Resource resource, | 54 int32_t ReceiveMessage(PP_Resource resource, |
| 51 PP_Var* message, | 55 PP_Var* message, |
| 52 PP_CompletionCallback callback) { | 56 PP_CompletionCallback callback) { |
| 53 EnterResource<PPB_WebSocket_API> enter(resource, false); | 57 EnterResource<PPB_WebSocket_API> enter(resource, false); |
| 54 if (enter.failed()) | 58 if (enter.failed()) |
| 55 return PP_ERROR_BADRESOURCE; | 59 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); |
| 56 return enter.object()->ReceiveMessage(message, callback); | 60 int32_t result = enter.object()->ReceiveMessage(message, callback); |
| 61 return MayForceCallback(callback, result); |
| 57 } | 62 } |
| 58 | 63 |
| 59 int32_t SendMessage(PP_Resource resource, PP_Var message) { | 64 int32_t SendMessage(PP_Resource resource, PP_Var message) { |
| 60 EnterResource<PPB_WebSocket_API> enter(resource, false); | 65 EnterResource<PPB_WebSocket_API> enter(resource, false); |
| 61 if (enter.failed()) | 66 if (enter.failed()) |
| 62 return PP_ERROR_BADRESOURCE; | 67 return PP_ERROR_BADRESOURCE; |
| 63 return enter.object()->SendMessage(message); | 68 return enter.object()->SendMessage(message); |
| 64 } | 69 } |
| 65 | 70 |
| 66 uint64_t GetBufferedAmount(PP_Resource resource) { | 71 uint64_t GetBufferedAmount(PP_Resource resource) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 }; | 143 }; |
| 139 | 144 |
| 140 } // namespace | 145 } // namespace |
| 141 | 146 |
| 142 const PPB_WebSocket_Dev* GetPPB_WebSocket_Dev_Thunk() { | 147 const PPB_WebSocket_Dev* GetPPB_WebSocket_Dev_Thunk() { |
| 143 return &g_ppb_websocket_thunk; | 148 return &g_ppb_websocket_thunk; |
| 144 } | 149 } |
| 145 | 150 |
| 146 } // namespace thunk | 151 } // namespace thunk |
| 147 } // namespace ppapi | 152 } // namespace ppapi |
| OLD | NEW |