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 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_WEBSOCKET_IMPL_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_WEBSOCKET_IMPL_H_ |
6 #define WEBKIT_PLUGINS_PPAPI_PPB_WEBSOCKET_IMPL_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_PPB_WEBSOCKET_IMPL_H_ |
7 | 7 |
| 8 #include <queue> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
8 #include "ppapi/shared_impl/resource.h" | 11 #include "ppapi/shared_impl/resource.h" |
9 #include "ppapi/thunk/ppb_websocket_api.h" | 12 #include "ppapi/thunk/ppb_websocket_api.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSocketClient.h" |
| 14 |
| 15 struct PPB_Var; |
| 16 |
| 17 namespace ppapi { |
| 18 class StringVar; |
| 19 } |
| 20 |
| 21 namespace WebKit { |
| 22 class WebSocket; |
| 23 } |
10 | 24 |
11 namespace webkit { | 25 namespace webkit { |
12 namespace ppapi { | 26 namespace ppapi { |
13 | 27 |
14 // All implementation is in this class for now. We should move some common | 28 // All implementation is in this class for now. We should move some common |
15 // implementation to shared_impl when we implement proxy interfaces. | 29 // implementation to shared_impl when we implement proxy interfaces. |
16 class PPB_WebSocket_Impl : public ::ppapi::Resource, | 30 class PPB_WebSocket_Impl : public ::ppapi::Resource, |
17 public ::ppapi::thunk::PPB_WebSocket_API { | 31 public ::ppapi::thunk::PPB_WebSocket_API, |
| 32 public ::WebKit::WebSocketClient { |
18 public: | 33 public: |
19 explicit PPB_WebSocket_Impl(PP_Instance instance); | 34 explicit PPB_WebSocket_Impl(PP_Instance instance); |
20 virtual ~PPB_WebSocket_Impl(); | 35 virtual ~PPB_WebSocket_Impl(); |
21 | 36 |
22 static PP_Resource Create(PP_Instance instance); | 37 static PP_Resource Create(PP_Instance instance); |
23 | 38 |
24 // Resource overrides. | 39 // Resource overrides. |
25 virtual ::ppapi::thunk::PPB_WebSocket_API* AsPPB_WebSocket_API() OVERRIDE; | 40 virtual ::ppapi::thunk::PPB_WebSocket_API* AsPPB_WebSocket_API() OVERRIDE; |
26 | 41 |
27 // PPB_WebSocket_API implementation. | 42 // PPB_WebSocket_API implementation. |
28 virtual int32_t Connect(PP_Var url, | 43 virtual int32_t Connect(PP_Var url, |
29 const PP_Var protocols[], | 44 const PP_Var protocols[], |
30 uint32_t protocol_count, | 45 uint32_t protocol_count, |
31 PP_CompletionCallback callback) OVERRIDE; | 46 PP_CompletionCallback callback) OVERRIDE; |
32 virtual int32_t Close(uint16_t code, | 47 virtual int32_t Close(uint16_t code, |
33 PP_Var reason, | 48 PP_Var reason, |
34 PP_CompletionCallback callback) OVERRIDE; | 49 PP_CompletionCallback callback) OVERRIDE; |
35 virtual int32_t ReceiveMessage(PP_Var* message, | 50 virtual int32_t ReceiveMessage(PP_Var* message, |
36 PP_CompletionCallback callbac) OVERRIDE; | 51 PP_CompletionCallback callbac) OVERRIDE; |
37 virtual int32_t SendMessage(PP_Var message) OVERRIDE; | 52 virtual int32_t SendMessage(PP_Var message) OVERRIDE; |
38 virtual uint64_t GetBufferedAmount() OVERRIDE; | 53 virtual uint64_t GetBufferedAmount() OVERRIDE; |
39 virtual uint16_t GetCloseCode() OVERRIDE; | 54 virtual uint16_t GetCloseCode() OVERRIDE; |
40 virtual PP_Var GetCloseReason() OVERRIDE; | 55 virtual PP_Var GetCloseReason() OVERRIDE; |
41 virtual PP_Bool GetCloseWasClean() OVERRIDE; | 56 virtual PP_Bool GetCloseWasClean() OVERRIDE; |
42 virtual PP_Var GetExtensions() OVERRIDE; | 57 virtual PP_Var GetExtensions() OVERRIDE; |
43 virtual PP_Var GetProtocol() OVERRIDE; | 58 virtual PP_Var GetProtocol() OVERRIDE; |
44 virtual PP_WebSocketReadyState_Dev GetReadyState() OVERRIDE; | 59 virtual PP_WebSocketReadyState_Dev GetReadyState() OVERRIDE; |
45 virtual PP_Var GetURL() OVERRIDE; | 60 virtual PP_Var GetURL() OVERRIDE; |
46 | 61 |
| 62 // WebSocketClient implementation. |
| 63 virtual void didConnect() OVERRIDE; |
| 64 virtual void didReceiveMessage(const WebKit::WebString& message) OVERRIDE; |
| 65 virtual void didReceiveBinaryData( |
| 66 const WebKit::WebData& binaryData) OVERRIDE; |
| 67 virtual void didReceiveMessageError() OVERRIDE; |
| 68 virtual void didStartClosingHandshake() OVERRIDE; |
| 69 virtual void didClose(unsigned long bufferedAmount, |
| 70 ClosingHandshakeCompletionStatus status, |
| 71 unsigned short code, |
| 72 const WebKit::WebString& reason) OVERRIDE; |
| 73 private: |
| 74 int32_t DoReceive(); |
| 75 |
| 76 scoped_ptr<WebKit::WebSocket> websocket_; |
| 77 PP_WebSocketReadyState_Dev state_; |
| 78 |
| 79 PP_CompletionCallback connect_callback_; |
| 80 |
| 81 PP_CompletionCallback receive_callback_; |
| 82 PP_Var* receive_callback_var_; |
| 83 bool wait_for_receive_; |
| 84 std::queue<PP_Var> received_messages_; |
| 85 |
| 86 PP_CompletionCallback close_callback_; |
| 87 uint16_t close_code_; |
| 88 scoped_refptr< ::ppapi::StringVar> close_reason_; |
| 89 PP_Bool close_was_clean_; |
| 90 |
| 91 scoped_refptr< ::ppapi::StringVar> empty_string_; |
| 92 scoped_refptr< ::ppapi::StringVar> extensions_; |
| 93 scoped_refptr< ::ppapi::StringVar> protocol_; |
| 94 scoped_refptr< ::ppapi::StringVar> url_; |
| 95 |
47 DISALLOW_COPY_AND_ASSIGN(PPB_WebSocket_Impl); | 96 DISALLOW_COPY_AND_ASSIGN(PPB_WebSocket_Impl); |
48 }; | 97 }; |
49 | 98 |
50 } // namespace ppapi | 99 } // namespace ppapi |
51 } // namespace webkit | 100 } // namespace webkit |
52 | 101 |
53 #endif // WEBKIT_PLUGINS_PPAPI_PPB_WEBSOCKET_IMPL_H_ | 102 #endif // WEBKIT_PLUGINS_PPAPI_PPB_WEBSOCKET_IMPL_H_ |
OLD | NEW |