| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 NET_API WebSocketJob | 33 class NET_API WebSocketJob |
| 33 : public SocketStreamJob, | 34 : public SocketStreamJob, |
| 34 public SocketStream::Delegate { | 35 public SocketStream::Delegate, |
| 36 public SpdyWebSocketStream::Delegate { |
| 35 public: | 37 public: |
| 36 // This is state of WebSocket, not SocketStream. | 38 // This is state of WebSocket, not SocketStream. |
| 37 enum State { | 39 enum State { |
| 38 INITIALIZED = -1, | 40 INITIALIZED = -1, |
| 39 CONNECTING = 0, | 41 CONNECTING = 0, |
| 40 OPEN = 1, | 42 OPEN = 1, |
| 41 CLOSING = 2, | 43 CLOSING = 2, |
| 42 CLOSED = 3, | 44 CLOSED = 3, |
| 43 }; | 45 }; |
| 44 | 46 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 63 virtual int OnStartOpenConnection( | 65 virtual int OnStartOpenConnection( |
| 64 SocketStream* socket, CompletionCallback* callback); | 66 SocketStream* socket, CompletionCallback* callback); |
| 65 virtual void OnConnected(SocketStream* socket, int max_pending_send_allowed); | 67 virtual void OnConnected(SocketStream* socket, int max_pending_send_allowed); |
| 66 virtual void OnSentData(SocketStream* socket, int amount_sent); | 68 virtual void OnSentData(SocketStream* socket, int amount_sent); |
| 67 virtual void OnReceivedData(SocketStream* socket, const char* data, int len); | 69 virtual void OnReceivedData(SocketStream* socket, const char* data, int len); |
| 68 virtual void OnClose(SocketStream* socket); | 70 virtual void OnClose(SocketStream* socket); |
| 69 virtual void OnAuthRequired( | 71 virtual void OnAuthRequired( |
| 70 SocketStream* socket, AuthChallengeInfo* auth_info); | 72 SocketStream* socket, AuthChallengeInfo* auth_info); |
| 71 virtual void OnError(const SocketStream* socket, int error); | 73 virtual void OnError(const SocketStream* socket, int error); |
| 72 | 74 |
| 75 // SpdyWebSocketStream::Delegate methods. |
| 76 virtual void OnCreatedSpdyStream(int status); |
| 77 virtual void OnSentSpdyHeaders(int status); |
| 78 virtual int OnReceivedSpdyResponseHeader( |
| 79 const spdy::SpdyHeaderBlock& headers, int status); |
| 80 virtual void OnSentSpdyData(int amount_sent); |
| 81 virtual void OnReceivedSpdyData(const char* data, int length); |
| 82 virtual void OnCloseSpdyStream(); |
| 83 |
| 73 private: | 84 private: |
| 74 friend class WebSocketThrottle; | 85 friend class WebSocketThrottle; |
| 75 friend class WebSocketJobTest; | 86 friend class WebSocketJobTest; |
| 76 virtual ~WebSocketJob(); | 87 virtual ~WebSocketJob(); |
| 77 | 88 |
| 78 bool SendHandshakeRequest(const char* data, int len); | 89 bool SendHandshakeRequest(const char* data, int len); |
| 79 void AddCookieHeaderAndSend(); | 90 void AddCookieHeaderAndSend(); |
| 80 | 91 |
| 81 void OnSentHandshakeRequest(SocketStream* socket, int amount_sent); | 92 void OnSentHandshakeRequest(SocketStream* socket, int amount_sent); |
| 82 void OnReceivedHandshakeResponse( | 93 void OnReceivedHandshakeResponse( |
| 83 SocketStream* socket, const char* data, int len); | 94 SocketStream* socket, const char* data, int len); |
| 84 void SaveCookiesAndNotifyHeaderComplete(); | 95 void SaveCookiesAndNotifyHeaderComplete(); |
| 85 void SaveNextCookie(); | 96 void SaveNextCookie(); |
| 86 | 97 |
| 87 GURL GetURLForCookies() const; | 98 GURL GetURLForCookies() const; |
| 88 | 99 |
| 89 const AddressList& address_list() const; | 100 const AddressList& address_list() const; |
| 90 int TrySpdyStream(); | 101 int TrySpdyStream(); |
| 91 void SetWaiting(); | 102 void SetWaiting(); |
| 92 bool IsWaiting() const; | 103 bool IsWaiting() const; |
| 93 void Wakeup(); | 104 void Wakeup(); |
| 94 void RetryPendingIO(); | 105 void RetryPendingIO(); |
| 106 void CompleteIO(int result); |
| 95 | 107 |
| 96 bool SendDataInternal(const char* data, int length); | 108 bool SendDataInternal(const char* data, int length); |
| 97 void CloseInternal(); | 109 void CloseInternal(); |
| 98 void SendPending(); | 110 void SendPending(); |
| 99 | 111 |
| 100 static bool websocket_over_spdy_enabled_; | 112 static bool websocket_over_spdy_enabled_; |
| 101 | 113 |
| 102 SocketStream::Delegate* delegate_; | 114 SocketStream::Delegate* delegate_; |
| 103 State state_; | 115 State state_; |
| 104 bool waiting_; | 116 bool waiting_; |
| 105 AddressList addresses_; | 117 AddressList addresses_; |
| 106 CompletionCallback* callback_; // for throttling. | 118 CompletionCallback* callback_; // for throttling. |
| 107 | 119 |
| 108 scoped_ptr<WebSocketHandshakeRequestHandler> handshake_request_; | 120 scoped_ptr<WebSocketHandshakeRequestHandler> handshake_request_; |
| 109 scoped_ptr<WebSocketHandshakeResponseHandler> handshake_response_; | 121 scoped_ptr<WebSocketHandshakeResponseHandler> handshake_response_; |
| 110 | 122 |
| 111 bool started_to_send_handshake_request_; | 123 bool started_to_send_handshake_request_; |
| 112 size_t handshake_request_sent_; | 124 size_t handshake_request_sent_; |
| 113 | 125 |
| 114 std::vector<std::string> response_cookies_; | 126 std::vector<std::string> response_cookies_; |
| 115 size_t response_cookies_save_index_; | 127 size_t response_cookies_save_index_; |
| 116 | 128 |
| 117 scoped_ptr<WebSocketFrameHandler> send_frame_handler_; | 129 scoped_ptr<WebSocketFrameHandler> send_frame_handler_; |
| 118 scoped_refptr<DrainableIOBuffer> current_buffer_; | 130 scoped_refptr<DrainableIOBuffer> current_buffer_; |
| 119 scoped_ptr<WebSocketFrameHandler> receive_frame_handler_; | 131 scoped_ptr<WebSocketFrameHandler> receive_frame_handler_; |
| 120 | 132 |
| 133 scoped_ptr<SpdyWebSocketStream> spdy_websocket_stream_; |
| 134 std::string challenge_; |
| 135 |
| 121 DISALLOW_COPY_AND_ASSIGN(WebSocketJob); | 136 DISALLOW_COPY_AND_ASSIGN(WebSocketJob); |
| 122 }; | 137 }; |
| 123 | 138 |
| 124 } // namespace | 139 } // namespace |
| 125 | 140 |
| 126 #endif // NET_WEBSOCKETS_WEBSOCKET_JOB_H_ | 141 #endif // NET_WEBSOCKETS_WEBSOCKET_JOB_H_ |
| OLD | NEW |