OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/glue/websocketstreamhandle_impl.h" | 7 #include "webkit/glue/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/string16.h" | |
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" |
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebSocketStreamErro
r.h" | |
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebSocketStreamHand
leClient.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebSocketStreamHand
leClient.h" |
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" |
20 #include "webkit/glue/webkitplatformsupport_impl.h" | 18 #include "webkit/glue/webkitplatformsupport_impl.h" |
21 #include "webkit/glue/websocketstreamhandle_bridge.h" | 19 #include "webkit/glue/websocketstreamhandle_bridge.h" |
22 #include "webkit/glue/websocketstreamhandle_delegate.h" | 20 #include "webkit/glue/websocketstreamhandle_delegate.h" |
23 | 21 |
24 using WebKit::WebData; | 22 using WebKit::WebData; |
25 using WebKit::WebSocketStreamError; | |
26 using WebKit::WebSocketStreamHandle; | 23 using WebKit::WebSocketStreamHandle; |
27 using WebKit::WebSocketStreamHandleClient; | 24 using WebKit::WebSocketStreamHandleClient; |
28 using WebKit::WebURL; | 25 using WebKit::WebURL; |
29 | 26 |
30 namespace webkit_glue { | 27 namespace webkit_glue { |
31 | 28 |
32 // WebSocketStreamHandleImpl::Context ----------------------------------------- | 29 // WebSocketStreamHandleImpl::Context ----------------------------------------- |
33 | 30 |
34 class WebSocketStreamHandleImpl::Context | 31 class WebSocketStreamHandleImpl::Context |
35 : public base::RefCounted<Context>, | 32 : public base::RefCounted<Context>, |
(...skipping 14 matching lines...) Expand all Loading... |
50 // Once detached, it never calls |client_| back. | 47 // Once detached, it never calls |client_| back. |
51 void Detach(); | 48 void Detach(); |
52 | 49 |
53 // WebSocketStreamHandleDelegate methods: | 50 // WebSocketStreamHandleDelegate methods: |
54 virtual void DidOpenStream(WebSocketStreamHandle*, int) OVERRIDE; | 51 virtual void DidOpenStream(WebSocketStreamHandle*, int) OVERRIDE; |
55 virtual void DidSendData(WebSocketStreamHandle*, int) OVERRIDE; | 52 virtual void DidSendData(WebSocketStreamHandle*, int) OVERRIDE; |
56 virtual void DidReceiveData(WebSocketStreamHandle*, | 53 virtual void DidReceiveData(WebSocketStreamHandle*, |
57 const char*, | 54 const char*, |
58 int) OVERRIDE; | 55 int) OVERRIDE; |
59 virtual void DidClose(WebSocketStreamHandle*) OVERRIDE; | 56 virtual void DidClose(WebSocketStreamHandle*) OVERRIDE; |
60 virtual void DidFail(WebSocketStreamHandle*, int, const string16&); | |
61 | 57 |
62 private: | 58 private: |
63 friend class base::RefCounted<Context>; | 59 friend class base::RefCounted<Context>; |
64 virtual ~Context() { | 60 virtual ~Context() { |
65 DCHECK(!handle_); | 61 DCHECK(!handle_); |
66 DCHECK(!client_); | 62 DCHECK(!client_); |
67 DCHECK(!bridge_); | 63 DCHECK(!bridge_); |
68 } | 64 } |
69 | 65 |
70 WebSocketStreamHandleImpl* handle_; | 66 WebSocketStreamHandleImpl* handle_; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 WebSocketStreamHandleImpl* handle = handle_; | 138 WebSocketStreamHandleImpl* handle = handle_; |
143 handle_ = NULL; | 139 handle_ = NULL; |
144 if (client_) { | 140 if (client_) { |
145 WebSocketStreamHandleClient* client = client_; | 141 WebSocketStreamHandleClient* client = client_; |
146 client_ = NULL; | 142 client_ = NULL; |
147 client->didClose(handle); | 143 client->didClose(handle); |
148 } | 144 } |
149 Release(); | 145 Release(); |
150 } | 146 } |
151 | 147 |
152 void WebSocketStreamHandleImpl::Context::DidFail( | |
153 WebSocketStreamHandle* web_handle, | |
154 int error_code, | |
155 const string16& error_msg) { | |
156 VLOG(1) << "DidFail"; | |
157 if (client_) { | |
158 client_->didFail( | |
159 handle_, | |
160 WebSocketStreamError(error_code, error_msg)); | |
161 } | |
162 } | |
163 | |
164 // WebSocketStreamHandleImpl ------------------------------------------------ | 148 // WebSocketStreamHandleImpl ------------------------------------------------ |
165 | 149 |
166 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl( | 150 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl( |
167 WebKitPlatformSupportImpl* platform) | 151 WebKitPlatformSupportImpl* platform) |
168 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))), | 152 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))), |
169 platform_(platform) { | 153 platform_(platform) { |
170 } | 154 } |
171 | 155 |
172 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() { | 156 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() { |
173 // We won't receive any events from |context_|. | 157 // We won't receive any events from |context_|. |
(...skipping 13 matching lines...) Expand all Loading... |
187 | 171 |
188 bool WebSocketStreamHandleImpl::send(const WebData& data) { | 172 bool WebSocketStreamHandleImpl::send(const WebData& data) { |
189 return context_->Send(data); | 173 return context_->Send(data); |
190 } | 174 } |
191 | 175 |
192 void WebSocketStreamHandleImpl::close() { | 176 void WebSocketStreamHandleImpl::close() { |
193 context_->Close(); | 177 context_->Close(); |
194 } | 178 } |
195 | 179 |
196 } // namespace webkit_glue | 180 } // namespace webkit_glue |
OLD | NEW |