OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // An implementation of WebSocketStreamHandle. | 5 // An implementation of WebSocketStreamHandle. |
6 | 6 |
7 #include "content/child/web_socket_stream_handle_impl.h" | 7 #include "webkit/child/websocketstreamhandle_impl.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "content/child/blink_platform_impl.h" | |
17 #include "content/child/web_socket_stream_handle_bridge.h" | |
18 #include "content/child/web_socket_stream_handle_delegate.h" | |
19 #include "third_party/WebKit/public/platform/WebData.h" | 16 #include "third_party/WebKit/public/platform/WebData.h" |
20 #include "third_party/WebKit/public/platform/WebSocketStreamError.h" | 17 #include "third_party/WebKit/public/platform/WebSocketStreamError.h" |
21 #include "third_party/WebKit/public/platform/WebSocketStreamHandleClient.h" | 18 #include "third_party/WebKit/public/platform/WebSocketStreamHandleClient.h" |
22 #include "third_party/WebKit/public/platform/WebURL.h" | 19 #include "third_party/WebKit/public/platform/WebURL.h" |
| 20 #include "webkit/child/webkitplatformsupport_impl.h" |
| 21 #include "webkit/child/websocketstreamhandle_bridge.h" |
| 22 #include "webkit/child/websocketstreamhandle_delegate.h" |
23 | 23 |
24 using blink::WebData; | 24 using blink::WebData; |
25 using blink::WebSocketStreamError; | 25 using blink::WebSocketStreamError; |
26 using blink::WebSocketStreamHandle; | 26 using blink::WebSocketStreamHandle; |
27 using blink::WebSocketStreamHandleClient; | 27 using blink::WebSocketStreamHandleClient; |
28 using blink::WebURL; | 28 using blink::WebURL; |
29 | 29 |
30 namespace content { | 30 namespace webkit_glue { |
31 | 31 |
32 // WebSocketStreamHandleImpl::Context ----------------------------------------- | 32 // WebSocketStreamHandleImpl::Context ----------------------------------------- |
33 | 33 |
34 class WebSocketStreamHandleImpl::Context | 34 class WebSocketStreamHandleImpl::Context |
35 : public base::RefCounted<Context>, | 35 : public base::RefCounted<Context>, |
36 public WebSocketStreamHandleDelegate { | 36 public WebSocketStreamHandleDelegate { |
37 public: | 37 public: |
38 explicit Context(WebSocketStreamHandleImpl* handle); | 38 explicit Context(WebSocketStreamHandleImpl* handle); |
39 | 39 |
40 WebSocketStreamHandleClient* client() const { return client_; } | 40 WebSocketStreamHandleClient* client() const { return client_; } |
41 void set_client(WebSocketStreamHandleClient* client) { | 41 void set_client(WebSocketStreamHandleClient* client) { |
42 client_ = client; | 42 client_ = client; |
43 } | 43 } |
44 | 44 |
45 void Connect(const WebURL& url, BlinkPlatformImpl* platform); | 45 void Connect(const WebURL& url, WebKitPlatformSupportImpl* platform); |
46 bool Send(const WebData& data); | 46 bool Send(const WebData& data); |
47 void Close(); | 47 void Close(); |
48 | 48 |
49 // Must be called before |handle_| or |client_| is deleted. | 49 // Must be called before |handle_| or |client_| is deleted. |
50 // Once detached, it never calls |client_| back. | 50 // Once detached, it never calls |client_| back. |
51 void Detach(); | 51 void Detach(); |
52 | 52 |
53 // WebSocketStreamHandleDelegate methods: | 53 // WebSocketStreamHandleDelegate methods: |
54 virtual void DidOpenStream(WebSocketStreamHandle*, int) OVERRIDE; | 54 virtual void DidOpenStream(WebSocketStreamHandle*, int) OVERRIDE; |
55 virtual void DidSendData(WebSocketStreamHandle*, int) OVERRIDE; | 55 virtual void DidSendData(WebSocketStreamHandle*, int) OVERRIDE; |
(...skipping 20 matching lines...) Expand all Loading... |
76 scoped_refptr<WebSocketStreamHandleBridge> bridge_; | 76 scoped_refptr<WebSocketStreamHandleBridge> bridge_; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(Context); | 78 DISALLOW_COPY_AND_ASSIGN(Context); |
79 }; | 79 }; |
80 | 80 |
81 WebSocketStreamHandleImpl::Context::Context(WebSocketStreamHandleImpl* handle) | 81 WebSocketStreamHandleImpl::Context::Context(WebSocketStreamHandleImpl* handle) |
82 : handle_(handle), | 82 : handle_(handle), |
83 client_(NULL) { | 83 client_(NULL) { |
84 } | 84 } |
85 | 85 |
86 void WebSocketStreamHandleImpl::Context::Connect(const WebURL& url, | 86 void WebSocketStreamHandleImpl::Context::Connect( |
87 BlinkPlatformImpl* platform) { | 87 const WebURL& url, |
| 88 WebKitPlatformSupportImpl* platform) { |
88 VLOG(1) << "Connect url=" << url; | 89 VLOG(1) << "Connect url=" << url; |
89 DCHECK(!bridge_.get()); | 90 DCHECK(!bridge_.get()); |
90 bridge_ = platform->CreateWebSocketStreamBridge(handle_, this); | 91 bridge_ = platform->CreateWebSocketStreamBridge(handle_, this); |
91 AddRef(); // Will be released by DidClose(). | 92 AddRef(); // Will be released by DidClose(). |
92 bridge_->Connect(url); | 93 bridge_->Connect(url); |
93 } | 94 } |
94 | 95 |
95 bool WebSocketStreamHandleImpl::Context::Send(const WebData& data) { | 96 bool WebSocketStreamHandleImpl::Context::Send(const WebData& data) { |
96 VLOG(1) << "Send data.size=" << data.size(); | 97 VLOG(1) << "Send data.size=" << data.size(); |
97 DCHECK(bridge_.get()); | 98 DCHECK(bridge_.get()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 if (client_) { | 158 if (client_) { |
158 client_->didFail( | 159 client_->didFail( |
159 handle_, | 160 handle_, |
160 WebSocketStreamError(error_code, error_msg)); | 161 WebSocketStreamError(error_code, error_msg)); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 // WebSocketStreamHandleImpl ------------------------------------------------ | 165 // WebSocketStreamHandleImpl ------------------------------------------------ |
165 | 166 |
166 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl( | 167 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl( |
167 BlinkPlatformImpl* platform) | 168 WebKitPlatformSupportImpl* platform) |
168 : context_(new Context(this)), | 169 : context_(new Context(this)), |
169 platform_(platform) { | 170 platform_(platform) { |
170 } | 171 } |
171 | 172 |
172 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() { | 173 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() { |
173 // We won't receive any events from |context_|. | 174 // We won't receive any events from |context_|. |
174 // |context_| is ref counted, and will be released when it received | 175 // |context_| is ref counted, and will be released when it received |
175 // DidClose. | 176 // DidClose. |
176 context_->Detach(); | 177 context_->Detach(); |
177 } | 178 } |
178 | 179 |
179 void WebSocketStreamHandleImpl::connect( | 180 void WebSocketStreamHandleImpl::connect( |
180 const WebURL& url, WebSocketStreamHandleClient* client) { | 181 const WebURL& url, WebSocketStreamHandleClient* client) { |
181 VLOG(1) << "connect url=" << url; | 182 VLOG(1) << "connect url=" << url; |
182 DCHECK(!context_->client()); | 183 DCHECK(!context_->client()); |
183 context_->set_client(client); | 184 context_->set_client(client); |
184 | 185 |
185 context_->Connect(url, platform_); | 186 context_->Connect(url, platform_); |
186 } | 187 } |
187 | 188 |
188 bool WebSocketStreamHandleImpl::send(const WebData& data) { | 189 bool WebSocketStreamHandleImpl::send(const WebData& data) { |
189 return context_->Send(data); | 190 return context_->Send(data); |
190 } | 191 } |
191 | 192 |
192 void WebSocketStreamHandleImpl::close() { | 193 void WebSocketStreamHandleImpl::close() { |
193 context_->Close(); | 194 context_->Close(); |
194 } | 195 } |
195 | 196 |
196 } // namespace content | 197 } // namespace webkit_glue |
OLD | NEW |