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

Side by Side Diff: ppapi/proxy/websocket_resource.h

Issue 10944005: Pepper WebSocket API: Implement new design Chrome IPC (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: retry Created 8 years, 2 months 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef PPAPI_PROXY_WEBSOCKET_RESOURCE_H_
6 #define PPAPI_PROXY_WEBSOCKET_RESOURCE_H_
7
8 #include <queue>
9
10 #include "ppapi/c/ppb_websocket.h"
11 #include "ppapi/proxy/plugin_resource.h"
12 #include "ppapi/shared_impl/tracked_callback.h"
13 #include "ppapi/thunk/ppb_websocket_api.h"
14
15 namespace ppapi {
16
17 class StringVar;
18 class Var;
19
20 namespace proxy {
21
22 // This class contains protocol checks which doesn't affect security when it
23 // run with untrusted code.
24 class PPAPI_PROXY_EXPORT WebSocketResource
25 : public PluginResource,
26 public NON_EXPORTED_BASE(thunk::PPB_WebSocket_API) {
27 public:
28 WebSocketResource(Connection connection, PP_Instance instance);
29 virtual ~WebSocketResource();
30
31 // PluginResource implementation.
32 virtual thunk::PPB_WebSocket_API* AsPPB_WebSocket_API() OVERRIDE;
33
34 // PPB_WebSocket_API implementation.
35 virtual int32_t Connect(PP_Var url,
36 const PP_Var protocols[],
37 uint32_t protocol_count,
38 scoped_refptr<TrackedCallback> callback) OVERRIDE;
39 virtual int32_t Close(uint16_t code,
40 PP_Var reason,
41 scoped_refptr<TrackedCallback> callback) OVERRIDE;
42 virtual int32_t ReceiveMessage(
43 PP_Var* message,
44 scoped_refptr<TrackedCallback> callback) OVERRIDE;
45 virtual int32_t SendMessage(PP_Var message) OVERRIDE;
46 virtual uint64_t GetBufferedAmount() OVERRIDE;
47 virtual uint16_t GetCloseCode() OVERRIDE;
48 virtual PP_Var GetCloseReason() OVERRIDE;
49 virtual PP_Bool GetCloseWasClean() OVERRIDE;
50 virtual PP_Var GetExtensions() OVERRIDE;
51 virtual PP_Var GetProtocol() OVERRIDE;
52 virtual PP_WebSocketReadyState GetReadyState() OVERRIDE;
53 virtual PP_Var GetURL() OVERRIDE;
54
55 private:
56 // PluginResource override.
57 virtual void OnReplyReceived(const ResourceMessageReplyParams& params,
58 const IPC::Message& msg) OVERRIDE;
59
60 // IPC message handlers.
61 void OnPluginMsgConnectReply(const ResourceMessageReplyParams& params,
62 const std::string& url,
63 const std::string& protocol);
64 void OnPluginMsgCloseReply(const ResourceMessageReplyParams& params,
65 unsigned long buffered_amount,
66 bool was_clean,
67 unsigned short code,
68 const std::string& reason);
69 void OnPluginMsgReceiveTextReply(const ResourceMessageReplyParams& params,
70 const std::string& message);
71 void OnPluginMsgReceiveBinaryReply(const ResourceMessageReplyParams& params,
72 const std::vector<uint8_t>& message);
73 void OnPluginMsgErrorReply(const ResourceMessageReplyParams& params);
74 void OnPluginMsgBufferedAmountReply(const ResourceMessageReplyParams& params,
75 unsigned long buffered_amount);
76 void OnPluginMsgStateReply(const ResourceMessageReplyParams& params,
77 int32_t state);
78 void OnPluginMsgClosedReply(const ResourceMessageReplyParams& params,
79 unsigned long buffered_amount,
80 bool was_clean,
81 unsigned short code,
82 const std::string& reason);
83
84 // Picks up a received message and moves it to user receiving buffer. This
85 // function is used in both ReceiveMessage for fast returning path and
86 // didReceiveMessage callback.
brettw 2012/10/03 04:54:02 Is this comment out-of-date?
Takashi Toyoshima 2012/10/03 11:42:20 Done.
87 int32_t DoReceive();
88
89 // IPC request IDs.
90 int32_t connect_request_id_;
91 int32_t close_request_id_;
92
93 // Holds user callbacks to invoke later.
94 scoped_refptr<TrackedCallback> connect_callback_;
95 scoped_refptr<TrackedCallback> close_callback_;
96 scoped_refptr<TrackedCallback> receive_callback_;
97
98 // Represents readyState described in the WebSocket API specification. It can
99 // be read via GetReadyState().
100 PP_WebSocketReadyState state_;
101
102 // Becomes true if any error is detected. Incoming data will be disposed
103 // if this variable is true, then ReceiveMessage() returns PP_ERROR_FAILED
104 // after returning all received data.
105 bool error_was_received_;
106
107 // Keeps a pointer to PP_Var which is provided via ReceiveMessage().
108 // Received data will be copied to this PP_Var on ready.
109 PP_Var* receive_callback_var_;
110
111 // Keeps received data until ReceiveMessage() requests.
112 std::queue<scoped_refptr<Var> > received_messages_;
113
114 // Keeps empty string for functions to return empty string.
115 scoped_refptr<StringVar> empty_string_;
116
117 // Keeps the status code field of closing handshake. It can be read via
118 // GetCloseCode().
119 uint16_t close_code_;
120
121 // Keeps the reason field of closing handshake. It can be read via
122 // GetCloseReason().
123 scoped_refptr<StringVar> close_reason_;
124
125 // Becomes true when closing handshake is performed successfully. It can be
126 // read via GetCloseWasClean().
127 PP_Bool close_was_clean_;
128
129 // Represents extensions described in the WebSocket API specification. It can
130 // be read via GetExtensions().
131 scoped_refptr<StringVar> extensions_;
132
133 // Represents protocol described in the WebSocket API specification. It can be
134 // read via GetProtocol().
135 scoped_refptr<StringVar> protocol_;
136
137 // Represents url described in the WebSocket API specification. It can be
138 // read via GetURL().
139 scoped_refptr<StringVar> url_;
140
141 // Keeps the number of bytes of application data that have been queued using
142 // SendMessage(). WebKit side implementation calculates the actual amount.
143 // This is a cached value which is notified through a WebKit callback.
144 // This value is used to calculate bufferedAmount in the WebSocket API
145 // specification. The calculated value can be read via GetBufferedAmount().
146 uint64_t buffered_amount_;
147
148 // Keeps the number of bytes of application data that have been ignored
149 // because the connection was already closed.
150 // This value is used to calculate bufferedAmount in the WebSocket API
151 // specification. The calculated value can be read via GetBufferedAmount().
152 uint64_t buffered_amount_after_close_;
153
154 DISALLOW_COPY_AND_ASSIGN(WebSocketResource);
155 };
156
157 } // namespace proxy
158 } // namespace ppapi
159
160 #endif // PPAPI_PROXY_WEBSOCKET_RESOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698