OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 CONTENT_RENDERER_WEBSOCKETHANDLE_IMPL_H_ | |
6 #define CONTENT_RENDERER_WEBSOCKETHANDLE_IMPL_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/single_thread_task_runner.h" | |
13 #include "content/common/websocket.mojom.h" | |
14 #include "mojo/public/cpp/bindings/binding.h" | |
15 #include "third_party/WebKit/public/platform/WebVector.h" | |
16 #include "third_party/WebKit/public/platform/modules/websockets/WebSocketHandle.
h" | |
17 | |
18 namespace blink { | |
19 class InterfaceProvider; | |
20 class WebSecurityOrigin; | |
21 class WebString; | |
22 class WebURL; | |
23 } // namespace blink | |
24 | |
25 namespace content { | |
26 | |
27 class WebSocketHandleImpl : public blink::WebSocketHandle, | |
28 public mojom::WebSocketClient { | |
29 public: | |
30 explicit WebSocketHandleImpl( | |
31 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
32 | |
33 // This method may optionally be called before connect() to specify a | |
34 // specific InterfaceProvider to get a WebSocket instance. By default, | |
35 // connect() will use blink::Platform::interfaceProvider(). | |
36 void Initialize(blink::InterfaceProvider* interface_provider); | |
37 | |
38 // blink::WebSocketHandle methods: | |
39 void connect(const blink::WebURL& url, | |
40 const blink::WebVector<blink::WebString>& protocols, | |
41 const blink::WebSecurityOrigin& origin, | |
42 const blink::WebURL& first_party_for_cookies, | |
43 const blink::WebString& user_agent_override, | |
44 blink::WebSocketHandleClient* client) override; | |
45 void send(bool fin, | |
46 WebSocketHandle::MessageType type, | |
47 const char* data, | |
48 size_t size) override; | |
49 void flowControl(int64_t quota) override; | |
50 void close(unsigned short code, const blink::WebString& reason) override; | |
51 | |
52 private: | |
53 ~WebSocketHandleImpl() override; | |
54 void Disconnect(); | |
55 void OnConnectionError(); | |
56 | |
57 // mojom::WebSocketClient methods: | |
58 void OnFailChannel(const std::string& reason) override; | |
59 void OnStartOpeningHandshake( | |
60 mojom::WebSocketHandshakeRequestPtr request) override; | |
61 void OnFinishOpeningHandshake( | |
62 mojom::WebSocketHandshakeResponsePtr response) override; | |
63 void OnAddChannelResponse(const std::string& selected_protocol, | |
64 const std::string& extensions) override; | |
65 void OnDataFrame(bool fin, | |
66 mojom::WebSocketMessageType type, | |
67 const std::vector<uint8_t>& data) override; | |
68 void OnFlowControl(int64_t quota) override; | |
69 void OnDropChannel(bool was_clean, | |
70 uint16_t code, | |
71 const std::string& reason) override; | |
72 void OnClosingHandshake() override; | |
73 | |
74 blink::WebSocketHandleClient* client_; | |
75 | |
76 mojom::WebSocketPtr websocket_; | |
77 mojo::Binding<mojom::WebSocketClient> client_binding_; | |
78 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
79 bool did_initialize_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(WebSocketHandleImpl); | |
82 }; | |
83 | |
84 } // namespace content | |
85 | |
86 #endif // CONTENT_RENDERER_WEBSOCKETHANDLE_IMPL_H_ | |
OLD | NEW |