OLD | NEW |
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 #ifndef NET_WEBSOCKETS_WEBSOCKET_JOB_H_ | 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_JOB_H_ |
6 #define NET_WEBSOCKETS_WEBSOCKET_JOB_H_ | 6 #define NET_WEBSOCKETS_WEBSOCKET_JOB_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
14 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
15 #include "net/socket_stream/socket_stream_job.h" | 15 #include "net/socket_stream/socket_stream_job.h" |
| 16 #include "net/spdy/spdy_websocket_stream.h" |
16 | 17 |
17 class GURL; | 18 class GURL; |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 | 21 |
21 class DrainableIOBuffer; | 22 class DrainableIOBuffer; |
22 class WebSocketFrameHandler; | 23 class WebSocketFrameHandler; |
23 class WebSocketHandshakeRequestHandler; | 24 class WebSocketHandshakeRequestHandler; |
24 class WebSocketHandshakeResponseHandler; | 25 class WebSocketHandshakeResponseHandler; |
25 | 26 |
26 // WebSocket protocol specific job on SocketStream. | 27 // WebSocket protocol specific job on SocketStream. |
27 // It captures WebSocket handshake message and handles cookie operations. | 28 // It captures WebSocket handshake message and handles cookie operations. |
28 // Chrome security policy doesn't allow renderer process (except dev tools) | 29 // Chrome security policy doesn't allow renderer process (except dev tools) |
29 // see HttpOnly cookies, so it injects cookie header in handshake request and | 30 // see HttpOnly cookies, so it injects cookie header in handshake request and |
30 // strips set-cookie headers in handshake response. | 31 // strips set-cookie headers in handshake response. |
31 // TODO(ukai): refactor websocket.cc to use this. | 32 // TODO(ukai): refactor websocket.cc to use this. |
32 class WebSocketJob : public SocketStreamJob, public SocketStream::Delegate { | 33 class WebSocketJob : public SocketStreamJob, |
| 34 public SocketStream::Delegate, |
| 35 public SpdyWebSocketStreamDelegate { |
33 public: | 36 public: |
34 // This is state of WebSocket, not SocketStream. | 37 // This is state of WebSocket, not SocketStream. |
35 enum State { | 38 enum State { |
36 INITIALIZED = -1, | 39 INITIALIZED = -1, |
37 CONNECTING = 0, | 40 CONNECTING = 0, |
38 OPEN = 1, | 41 OPEN = 1, |
39 CLOSING = 2, | 42 CLOSING = 2, |
40 CLOSED = 3, | 43 CLOSED = 3, |
41 }; | 44 }; |
42 static void EnsureInit(); | 45 static void EnsureInit(); |
(...skipping 17 matching lines...) Expand all Loading... |
60 virtual void OnSentData( | 63 virtual void OnSentData( |
61 SocketStream* socket, int amount_sent); | 64 SocketStream* socket, int amount_sent); |
62 virtual void OnReceivedData( | 65 virtual void OnReceivedData( |
63 SocketStream* socket, const char* data, int len); | 66 SocketStream* socket, const char* data, int len); |
64 virtual void OnClose(SocketStream* socket); | 67 virtual void OnClose(SocketStream* socket); |
65 virtual void OnAuthRequired( | 68 virtual void OnAuthRequired( |
66 SocketStream* socket, AuthChallengeInfo* auth_info); | 69 SocketStream* socket, AuthChallengeInfo* auth_info); |
67 virtual void OnError( | 70 virtual void OnError( |
68 const SocketStream* socket, int error); | 71 const SocketStream* socket, int error); |
69 | 72 |
| 73 // SpdyWebSocketStreamDelegate methods. |
| 74 virtual void OnCreatedSpdyStream( |
| 75 SpdyWebSocketStream* spdy_websocket_stream, int status); |
| 76 virtual void OnSentSpdyHeaders( |
| 77 SpdyWebSocketStream* spdy_websocket_stream); |
| 78 virtual int OnReceivedSpdyResponseHeader( |
| 79 SpdyWebSocketStream* spdy_websocket_stream, |
| 80 const spdy::SpdyHeaderBlock& headers, |
| 81 int status); |
| 82 virtual void OnSentSpdyData( |
| 83 SpdyWebSocketStream* spdy_websocket_stream, int amount_sent); |
| 84 virtual void OnReceivedSpdyData( |
| 85 SpdyWebSocketStream* spdy_websocket_stream, const char* data, int length); |
| 86 virtual void OnCloseSpdyStream( |
| 87 SpdyWebSocketStream* spdy_websocket_stream); |
| 88 |
70 private: | 89 private: |
71 friend class WebSocketThrottle; | 90 friend class WebSocketThrottle; |
72 friend class WebSocketJobTest; | 91 friend class WebSocketJobTest; |
73 virtual ~WebSocketJob(); | 92 virtual ~WebSocketJob(); |
74 | 93 |
75 bool SendHandshakeRequest(const char* data, int len); | 94 bool SendHandshakeRequest(const char* data, int len); |
76 void AddCookieHeaderAndSend(); | 95 void AddCookieHeaderAndSend(); |
77 void OnCanGetCookiesCompleted(int policy); | 96 void OnCanGetCookiesCompleted(int policy); |
78 | 97 |
79 void OnSentHandshakeRequest(SocketStream* socket, int amount_sent); | 98 void OnSentHandshakeRequest(SocketStream* socket, int amount_sent); |
80 void OnReceivedHandshakeResponse( | 99 void OnReceivedHandshakeResponse( |
81 SocketStream* socket, const char* data, int len); | 100 SocketStream* socket, const char* data, int len); |
82 void SaveCookiesAndNotifyHeaderComplete(); | 101 void SaveCookiesAndNotifyHeaderComplete(); |
83 void SaveNextCookie(); | 102 void SaveNextCookie(); |
84 void OnCanSetCookieCompleted(int policy); | 103 void OnCanSetCookieCompleted(int policy); |
85 | 104 |
86 GURL GetURLForCookies() const; | 105 GURL GetURLForCookies() const; |
87 | 106 |
88 const AddressList& address_list() const; | 107 const AddressList& address_list() const; |
| 108 int TrySpdyStream(); |
89 void SetWaiting(); | 109 void SetWaiting(); |
90 bool IsWaiting() const; | 110 bool IsWaiting() const; |
91 void Wakeup(); | 111 void Wakeup(); |
92 void DoCallback(); | 112 void DoCallback(int result); |
93 | 113 |
| 114 void SendDataInternal(const char* data, int length); |
| 115 void CloseInternal(); |
94 void SendPending(); | 116 void SendPending(); |
95 | 117 |
96 SocketStream::Delegate* delegate_; | 118 SocketStream::Delegate* delegate_; |
97 State state_; | 119 State state_; |
98 bool waiting_; | 120 bool waiting_; |
99 AddressList addresses_; | 121 AddressList addresses_; |
100 CompletionCallback* callback_; // for throttling. | 122 CompletionCallback* callback_; // for throttling. |
101 | 123 |
102 scoped_ptr<WebSocketHandshakeRequestHandler> handshake_request_; | 124 scoped_ptr<WebSocketHandshakeRequestHandler> handshake_request_; |
103 scoped_ptr<WebSocketHandshakeResponseHandler> handshake_response_; | 125 scoped_ptr<WebSocketHandshakeResponseHandler> handshake_response_; |
104 | 126 |
105 size_t handshake_request_sent_; | 127 size_t handshake_request_sent_; |
106 | 128 |
107 std::vector<std::string> response_cookies_; | 129 std::vector<std::string> response_cookies_; |
108 size_t response_cookies_save_index_; | 130 size_t response_cookies_save_index_; |
109 | 131 |
110 CompletionCallbackImpl<WebSocketJob> can_get_cookies_callback_; | 132 CompletionCallbackImpl<WebSocketJob> can_get_cookies_callback_; |
111 CompletionCallbackImpl<WebSocketJob> can_set_cookie_callback_; | 133 CompletionCallbackImpl<WebSocketJob> can_set_cookie_callback_; |
112 | 134 |
113 scoped_ptr<WebSocketFrameHandler> send_frame_handler_; | 135 scoped_ptr<WebSocketFrameHandler> send_frame_handler_; |
114 scoped_refptr<DrainableIOBuffer> current_buffer_; | 136 scoped_refptr<DrainableIOBuffer> current_buffer_; |
115 scoped_ptr<WebSocketFrameHandler> receive_frame_handler_; | 137 scoped_ptr<WebSocketFrameHandler> receive_frame_handler_; |
116 | 138 |
| 139 scoped_ptr<SpdyWebSocketStream> spdy_websocket_stream_; |
| 140 std::string challenge_; |
| 141 |
117 DISALLOW_COPY_AND_ASSIGN(WebSocketJob); | 142 DISALLOW_COPY_AND_ASSIGN(WebSocketJob); |
118 }; | 143 }; |
119 | 144 |
120 } // namespace | 145 } // namespace |
121 | 146 |
122 #endif // NET_WEBSOCKETS_WEBSOCKET_JOB_H_ | 147 #endif // NET_WEBSOCKETS_WEBSOCKET_JOB_H_ |
OLD | NEW |