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

Side by Side Diff: ppapi/cpp/dev/websocket_dev.cc

Issue 8821010: WebSocket Pepper API: C++ bindings implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nits and rebase Created 9 years 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
« no previous file with comments | « ppapi/cpp/dev/websocket_dev.h ('k') | ppapi/ppapi_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/cpp/dev/websocket_dev.h"
6
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/pp_macros.h"
9 #include "ppapi/cpp/completion_callback.h"
10 #include "ppapi/cpp/instance.h"
11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/module_impl.h"
13 #include "ppapi/cpp/var.h"
14
15 namespace pp {
16
17 namespace {
18
19 template <> const char* interface_name<PPB_WebSocket_Dev>() {
20 return PPB_WEBSOCKET_DEV_INTERFACE;
21 }
22
23 } // namespace
24
25 WebSocket_Dev::WebSocket_Dev(Instance* instance) {
26 if (!has_interface<PPB_WebSocket_Dev>())
27 return;
28 PassRefFromConstructor(get_interface<PPB_WebSocket_Dev>()->Create(
29 instance->pp_instance()));
30 }
31
32 WebSocket_Dev::~WebSocket_Dev() {
33 }
34
35 int32_t WebSocket_Dev::Connect(const Var& url, const Var protocols[],
36 uint32_t protocol_count, const CompletionCallback& callback) {
37 if (!has_interface<PPB_WebSocket_Dev>())
38 return PP_ERROR_BADRESOURCE;
39
40 // Convert protocols to C interface.
41 PP_Var *c_protocols = NULL;
42 if (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)
48 c_protocols[i] = protocols[i].pp_var();
49
50 int32_t result = get_interface<PPB_WebSocket_Dev>()->Connect(
51 pp_resource(), url.pp_var(), c_protocols, protocol_count,
52 callback.pp_completion_callback());
53 if (c_protocols)
54 delete[] c_protocols;
55 return result;
56 }
57
58 int32_t WebSocket_Dev::Close(uint16_t code, const Var& reason,
59 const CompletionCallback& callback) {
60 if (!has_interface<PPB_WebSocket_Dev>())
61 return PP_ERROR_BADRESOURCE;
62
63 return get_interface<PPB_WebSocket_Dev>()->Close(
64 pp_resource(), code, reason.pp_var(),
65 callback.pp_completion_callback());
66 }
67
68 int32_t WebSocket_Dev::ReceiveMessage(Var* message,
69 const CompletionCallback& callback) {
70 if (!has_interface<PPB_WebSocket_Dev>())
71 return PP_ERROR_BADRESOURCE;
72
73 return get_interface<PPB_WebSocket_Dev>()->ReceiveMessage(
74 pp_resource(), const_cast<PP_Var*>(&message->pp_var()),
75 callback.pp_completion_callback());
76 }
77
78 int32_t WebSocket_Dev::SendMessage(const Var& message) {
79 if (!has_interface<PPB_WebSocket_Dev>())
80 return PP_ERROR_BADRESOURCE;
81
82 return get_interface<PPB_WebSocket_Dev>()->SendMessage(
83 pp_resource(), message.pp_var());
84 }
85
86 uint64_t WebSocket_Dev::GetBufferedAmount() {
87 if (!has_interface<PPB_WebSocket_Dev>())
88 return 0;
89
90 return get_interface<PPB_WebSocket_Dev>()->GetBufferedAmount(pp_resource());
91 }
92
93 uint16_t WebSocket_Dev::GetCloseCode() {
94 if (!has_interface<PPB_WebSocket_Dev>())
95 return 0;
96
97 return get_interface<PPB_WebSocket_Dev>()->GetCloseCode(pp_resource());
98 }
99
100 Var WebSocket_Dev::GetCloseReason() {
101 if (!has_interface<PPB_WebSocket_Dev>())
102 return 0;
103
104 return Var(Var::PassRef(),
105 get_interface<PPB_WebSocket_Dev>()->GetCloseReason(pp_resource()));
106 }
107
108 bool WebSocket_Dev::GetCloseWasClean() {
109 if (!has_interface<PPB_WebSocket_Dev>())
110 return false;
111
112 PP_Bool result =
113 get_interface<PPB_WebSocket_Dev>()->GetCloseWasClean(pp_resource());
114 return PP_ToBool(result);
115 }
116
117 Var WebSocket_Dev::GetExtensions() {
118 if (!has_interface<PPB_WebSocket_Dev>())
119 return Var();
120
121 return Var(Var::PassRef(),
122 get_interface<PPB_WebSocket_Dev>()->GetExtensions(pp_resource()));
123 }
124
125 Var WebSocket_Dev::GetProtocol() {
126 if (!has_interface<PPB_WebSocket_Dev>())
127 return Var();
128
129 return Var(Var::PassRef(),
130 get_interface<PPB_WebSocket_Dev>()->GetProtocol(pp_resource()));
131 }
132
133 PP_WebSocketReadyState_Dev WebSocket_Dev::GetReadyState() {
134 if (!has_interface<PPB_WebSocket_Dev>())
135 return PP_WEBSOCKETREADYSTATE_INVALID_DEV;
136
137 return get_interface<PPB_WebSocket_Dev>()->GetReadyState(pp_resource());
138 }
139
140 Var WebSocket_Dev::GetURL() {
141 if (!has_interface<PPB_WebSocket_Dev>())
142 return Var();
143
144 return Var(Var::PassRef(),
145 get_interface<PPB_WebSocket_Dev>()->GetURL(pp_resource()));
146 }
147
148 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/websocket_dev.h ('k') | ppapi/ppapi_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698