Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Side by Side Diff: webkit/glue/websocketstreamhandle_impl.cc

Issue 6474012: Create a path to deliver SocketStream errors to the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add unit test and test_shell code Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "net/base/net_errors.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSocketStreamError. h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSocketStreamHandle Client.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSocketStreamHandle Client.h"
18 #include "webkit/glue/websocketstreamhandle_bridge.h" 20 #include "webkit/glue/websocketstreamhandle_bridge.h"
19 #include "webkit/glue/websocketstreamhandle_delegate.h" 21 #include "webkit/glue/websocketstreamhandle_delegate.h"
20 22
21 namespace webkit_glue { 23 namespace webkit_glue {
22 24
23 // WebSocketStreamHandleImpl::Context ----------------------------------------- 25 // WebSocketStreamHandleImpl::Context -----------------------------------------
24 26
25 class WebSocketStreamHandleImpl::Context 27 class WebSocketStreamHandleImpl::Context
26 : public base::RefCounted<Context>, 28 : public base::RefCounted<Context>,
27 public WebSocketStreamHandleDelegate { 29 public WebSocketStreamHandleDelegate {
(...skipping 12 matching lines...) Expand all
40 // Must be called before |handle_| or |client_| is deleted. 42 // Must be called before |handle_| or |client_| is deleted.
41 // Once detached, it never calls |client_| back. 43 // Once detached, it never calls |client_| back.
42 void Detach(); 44 void Detach();
43 45
44 // WebSocketStreamHandleDelegate methods: 46 // WebSocketStreamHandleDelegate methods:
45 virtual void DidOpenStream(WebKit::WebSocketStreamHandle*, int); 47 virtual void DidOpenStream(WebKit::WebSocketStreamHandle*, int);
46 virtual void DidSendData(WebKit::WebSocketStreamHandle*, int); 48 virtual void DidSendData(WebKit::WebSocketStreamHandle*, int);
47 virtual void DidReceiveData( 49 virtual void DidReceiveData(
48 WebKit::WebSocketStreamHandle*, const char*, int); 50 WebKit::WebSocketStreamHandle*, const char*, int);
49 virtual void DidClose(WebKit::WebSocketStreamHandle*); 51 virtual void DidClose(WebKit::WebSocketStreamHandle*);
52 virtual void DidFail(WebKit::WebSocketStreamHandle*, int);
50 53
51 private: 54 private:
52 friend class base::RefCounted<Context>; 55 friend class base::RefCounted<Context>;
53 ~Context() { 56 ~Context() {
54 DCHECK(!handle_); 57 DCHECK(!handle_);
55 DCHECK(!client_); 58 DCHECK(!client_);
56 DCHECK(!bridge_); 59 DCHECK(!bridge_);
57 } 60 }
58 61
59 WebSocketStreamHandleImpl* handle_; 62 WebSocketStreamHandleImpl* handle_;
60 WebKit::WebSocketStreamHandleClient* client_; 63 WebKit::WebSocketStreamHandleClient* client_;
64 WebKit::WebURL url_;
61 // |bridge_| is alive from Connect to DidClose, so Context must be alive 65 // |bridge_| is alive from Connect to DidClose, so Context must be alive
62 // in the time period. 66 // in the time period.
63 scoped_refptr<WebSocketStreamHandleBridge> bridge_; 67 scoped_refptr<WebSocketStreamHandleBridge> bridge_;
64 68
65 DISALLOW_COPY_AND_ASSIGN(Context); 69 DISALLOW_COPY_AND_ASSIGN(Context);
66 }; 70 };
67 71
68 WebSocketStreamHandleImpl::Context::Context(WebSocketStreamHandleImpl* handle) 72 WebSocketStreamHandleImpl::Context::Context(WebSocketStreamHandleImpl* handle)
69 : handle_(handle), 73 : handle_(handle),
70 client_(NULL), 74 client_(NULL),
71 bridge_(NULL) { 75 bridge_(NULL) {
72 } 76 }
73 77
74 void WebSocketStreamHandleImpl::Context::Connect(const WebKit::WebURL& url) { 78 void WebSocketStreamHandleImpl::Context::Connect(const WebKit::WebURL& url) {
75 VLOG(1) << "Connect url=" << url; 79 VLOG(1) << "Connect url=" << url;
76 DCHECK(!bridge_); 80 DCHECK(!bridge_);
77 bridge_ = WebSocketStreamHandleBridge::Create(handle_, this); 81 bridge_ = WebSocketStreamHandleBridge::Create(handle_, this);
78 AddRef(); // Will be released by DidClose(). 82 AddRef(); // Will be released by DidClose().
83 url_ = url;
79 bridge_->Connect(url); 84 bridge_->Connect(url);
80 } 85 }
81 86
82 bool WebSocketStreamHandleImpl::Context::Send(const WebKit::WebData& data) { 87 bool WebSocketStreamHandleImpl::Context::Send(const WebKit::WebData& data) {
83 VLOG(1) << "Send data.size=" << data.size(); 88 VLOG(1) << "Send data.size=" << data.size();
84 DCHECK(bridge_); 89 DCHECK(bridge_);
85 return bridge_->Send( 90 return bridge_->Send(
86 std::vector<char>(data.data(), data.data() + data.size())); 91 std::vector<char>(data.data(), data.data() + data.size()));
87 } 92 }
88 93
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 WebSocketStreamHandleImpl* handle = handle_; 134 WebSocketStreamHandleImpl* handle = handle_;
130 handle_ = NULL; 135 handle_ = NULL;
131 if (client_) { 136 if (client_) {
132 WebKit::WebSocketStreamHandleClient* client = client_; 137 WebKit::WebSocketStreamHandleClient* client = client_;
133 client_ = NULL; 138 client_ = NULL;
134 client->didClose(handle); 139 client->didClose(handle);
135 } 140 }
136 Release(); 141 Release();
137 } 142 }
138 143
144 void WebSocketStreamHandleImpl::Context::DidFail(
145 WebKit::WebSocketStreamHandle* web_handle,
146 int error_code) {
147 if (client_) {
148 const char* error_description = net::ErrorToString(error_code);
149 WebKit::WebSocketStreamError error(
150 error_code,
ukai 2011/05/10 08:10:39 when error_code is translated in WebKit's code? we
Yuta Kitamura 2011/05/10 09:01:22 In WebKit, SocketStreamError's errorCode is consid
ukai 2011/05/10 10:00:29 Hmm. then I think we should refrain from using err
151 WebKit::WebString::fromUTF8(error_description),
152 url_);
153 client_->didFail(handle_, error);
154 }
155 }
156
139 // WebSocketStreamHandleImpl ------------------------------------------------ 157 // WebSocketStreamHandleImpl ------------------------------------------------
140 158
141 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl() 159 WebSocketStreamHandleImpl::WebSocketStreamHandleImpl()
142 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))) { 160 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))) {
143 } 161 }
144 162
145 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() { 163 WebSocketStreamHandleImpl::~WebSocketStreamHandleImpl() {
146 // We won't receive any events from |context_|. 164 // We won't receive any events from |context_|.
147 // |context_| is ref counted, and will be released when it received 165 // |context_| is ref counted, and will be released when it received
148 // DidClose. 166 // DidClose.
(...skipping 11 matching lines...) Expand all
160 178
161 bool WebSocketStreamHandleImpl::send(const WebKit::WebData& data) { 179 bool WebSocketStreamHandleImpl::send(const WebKit::WebData& data) {
162 return context_->Send(data); 180 return context_->Send(data);
163 } 181 }
164 182
165 void WebSocketStreamHandleImpl::close() { 183 void WebSocketStreamHandleImpl::close() {
166 context_->Close(); 184 context_->Close();
167 } 185 }
168 186
169 } // namespace webkit_glue 187 } // namespace webkit_glue
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698