Chromium Code Reviews| 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 WebKit { | |
| 18 class WebSocket; | |
| 19 } | |
| 10 | 20 |
| 11 namespace webkit { | 21 namespace webkit { |
| 12 namespace ppapi { | 22 namespace ppapi { |
| 13 | 23 |
| 14 // All implementation is in this class for now. We should move some common | 24 // All implementation is in this class for now. We should move some common |
| 15 // implementation to shared_impl when we implement proxy interfaces. | 25 // implementation to shared_impl when we implement proxy interfaces. |
| 16 class PPB_WebSocket_Impl : public ::ppapi::Resource, | 26 class PPB_WebSocket_Impl : public ::ppapi::Resource, |
| 17 public ::ppapi::thunk::PPB_WebSocket_API { | 27 public ::ppapi::thunk::PPB_WebSocket_API, |
| 28 public ::WebKit::WebSocketClient { | |
| 18 public: | 29 public: |
| 19 explicit PPB_WebSocket_Impl(PP_Instance instance); | 30 explicit PPB_WebSocket_Impl(PP_Instance instance); |
| 20 virtual ~PPB_WebSocket_Impl(); | 31 virtual ~PPB_WebSocket_Impl(); |
| 21 | 32 |
| 22 static PP_Resource Create(PP_Instance instance); | 33 static PP_Resource Create(PP_Instance instance); |
| 23 | 34 |
| 24 // Resource overrides. | 35 // Resource overrides. |
| 25 virtual ::ppapi::thunk::PPB_WebSocket_API* AsPPB_WebSocket_API() OVERRIDE; | 36 virtual ::ppapi::thunk::PPB_WebSocket_API* AsPPB_WebSocket_API() OVERRIDE; |
| 26 | 37 |
| 27 // PPB_WebSocket_API implementation. | 38 // PPB_WebSocket_API implementation. |
| 28 virtual int32_t Connect(PP_Var url, | 39 virtual int32_t Connect(PP_Var url, |
| 29 const PP_Var protocols[], | 40 const PP_Var protocols[], |
| 30 uint32_t protocol_count, | 41 uint32_t protocol_count, |
| 31 PP_CompletionCallback callback) OVERRIDE; | 42 PP_CompletionCallback callback) OVERRIDE; |
| 32 virtual int32_t Close(uint16_t code, | 43 virtual int32_t Close(uint16_t code, |
| 33 PP_Var reason, | 44 PP_Var reason, |
| 34 PP_CompletionCallback callback) OVERRIDE; | 45 PP_CompletionCallback callback) OVERRIDE; |
| 35 virtual int32_t ReceiveMessage(PP_Var* message, | 46 virtual int32_t ReceiveMessage(PP_Var* message, |
| 36 PP_CompletionCallback callbac) OVERRIDE; | 47 PP_CompletionCallback callbac) OVERRIDE; |
| 37 virtual int32_t SendMessage(PP_Var message) OVERRIDE; | 48 virtual int32_t SendMessage(PP_Var message) OVERRIDE; |
| 38 virtual uint64_t GetBufferedAmount() OVERRIDE; | 49 virtual uint64_t GetBufferedAmount() OVERRIDE; |
| 39 virtual uint16_t GetCloseCode() OVERRIDE; | 50 virtual uint16_t GetCloseCode() OVERRIDE; |
| 40 virtual PP_Var GetCloseReason() OVERRIDE; | 51 virtual PP_Var GetCloseReason() OVERRIDE; |
| 41 virtual PP_Bool GetCloseWasClean() OVERRIDE; | 52 virtual PP_Bool GetCloseWasClean() OVERRIDE; |
| 42 virtual PP_Var GetExtensions() OVERRIDE; | 53 virtual PP_Var GetExtensions() OVERRIDE; |
| 43 virtual PP_Var GetProtocol() OVERRIDE; | 54 virtual PP_Var GetProtocol() OVERRIDE; |
| 44 virtual PP_WebSocketReadyState_Dev GetReadyState() OVERRIDE; | 55 virtual PP_WebSocketReadyState_Dev GetReadyState() OVERRIDE; |
| 45 virtual PP_Var GetURL() OVERRIDE; | 56 virtual PP_Var GetURL() OVERRIDE; |
| 46 | 57 |
| 58 // WebSocketClient | |
|
dmichael (off chromium)
2011/11/23 17:41:24
nit: "WebSocketClient implementation." ?
Takashi Toyoshima
2011/11/24 03:55:49
Done.
| |
| 59 // TODO(toyoshim): Check if OVERRIDE is needed for following methods. | |
|
Takashi Toyoshima
2011/11/24 03:55:49
Oh, I forget to remove this TODO.
I think followin
dmichael (off chromium)
2011/11/24 04:32:36
Since they're overriding WebKit functions it's opt
| |
| 60 virtual void didConnect(); | |
| 61 virtual void didReceiveMessage(const WebKit::WebString& message); | |
| 62 virtual void didReceiveBinaryData(const WebKit::WebData& binaryData); | |
| 63 virtual void didReceiveMessageError(); | |
| 64 virtual void didStartClosingHandshake(); | |
| 65 virtual void didClose(unsigned long bufferedAmount, | |
| 66 ClosingHandshakeCompletionStatus status, | |
| 67 unsigned short code, | |
| 68 const WebKit::WebString& reason); | |
| 69 private: | |
| 70 int32_t DoReceive(); | |
| 71 PP_Var ReturnVarString(PP_Var var); | |
| 72 | |
| 73 scoped_ptr<WebKit::WebSocket> websocket_; | |
| 74 PP_WebSocketReadyState_Dev state_; | |
| 75 | |
| 76 PP_CompletionCallback connect_callback_; | |
| 77 | |
| 78 PP_CompletionCallback receive_callback_; | |
| 79 PP_Var* receive_callback_var_; | |
| 80 bool wait_for_receive_; | |
| 81 std::queue<PP_Var> received_messages_; | |
| 82 | |
| 83 PP_CompletionCallback close_callback_; | |
| 84 uint16_t close_code_; | |
| 85 PP_Var close_reason_; | |
| 86 PP_Bool close_was_clean_; | |
| 87 | |
| 88 PP_Var extensions_; | |
| 89 PP_Var protocol_; | |
| 90 | |
| 91 const PPB_Var* var_interface_; | |
| 92 PP_Var empty_var_; | |
| 93 PP_Var url_; | |
| 94 | |
| 47 DISALLOW_COPY_AND_ASSIGN(PPB_WebSocket_Impl); | 95 DISALLOW_COPY_AND_ASSIGN(PPB_WebSocket_Impl); |
| 48 }; | 96 }; |
| 49 | 97 |
| 50 } // namespace ppapi | 98 } // namespace ppapi |
| 51 } // namespace webkit | 99 } // namespace webkit |
| 52 | 100 |
| 53 #endif // WEBKIT_PLUGINS_PPAPI_PPB_WEBSOCKET_IMPL_H_ | 101 #endif // WEBKIT_PLUGINS_PPAPI_PPB_WEBSOCKET_IMPL_H_ |
| OLD | NEW |