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

Side by Side Diff: net/websockets/websocket_channel.h

Issue 170843007: Introduce url::Origin to represent Web Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_CHANNEL_H_ 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/compiler_specific.h" // for WARN_UNUSED_RESULT 13 #include "base/compiler_specific.h" // for WARN_UNUSED_RESULT
14 #include "base/i18n/streaming_utf8_validator.h" 14 #include "base/i18n/streaming_utf8_validator.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
19 #include "net/base/net_export.h" 19 #include "net/base/net_export.h"
20 #include "net/websockets/websocket_event_interface.h" 20 #include "net/websockets/websocket_event_interface.h"
21 #include "net/websockets/websocket_frame.h" 21 #include "net/websockets/websocket_frame.h"
22 #include "net/websockets/websocket_stream.h" 22 #include "net/websockets/websocket_stream.h"
23 #include "url/gurl.h" 23 #include "url/gurl.h"
24 24
25 class SerializedOrigin;
26
25 namespace net { 27 namespace net {
26 28
27 class BoundNetLog; 29 class BoundNetLog;
28 class IOBuffer; 30 class IOBuffer;
29 class URLRequestContext; 31 class URLRequestContext;
30 struct WebSocketHandshakeRequestInfo; 32 struct WebSocketHandshakeRequestInfo;
31 struct WebSocketHandshakeResponseInfo; 33 struct WebSocketHandshakeResponseInfo;
32 34
33 // Transport-independent implementation of WebSockets. Implements protocol 35 // Transport-independent implementation of WebSockets. Implements protocol
34 // semantics that do not depend on the underlying transport. Provides the 36 // semantics that do not depend on the underlying transport. Provides the
35 // interface to the content layer. Some WebSocket concepts are used here without 37 // interface to the content layer. Some WebSocket concepts are used here without
36 // definition; please see the RFC at http://tools.ietf.org/html/rfc6455 for 38 // definition; please see the RFC at http://tools.ietf.org/html/rfc6455 for
37 // clarification. 39 // clarification.
38 class NET_EXPORT WebSocketChannel { 40 class NET_EXPORT WebSocketChannel {
39 public: 41 public:
40 // The type of a WebSocketStream creator callback. Must match the signature of 42 // The type of a WebSocketStream creator callback. Must match the signature of
41 // WebSocketStream::CreateAndConnectStream(). 43 // WebSocketStream::CreateAndConnectStream().
42 typedef base::Callback<scoped_ptr<WebSocketStreamRequest>( 44 typedef base::Callback<scoped_ptr<WebSocketStreamRequest>(
43 const GURL&, 45 const GURL&,
44 const std::vector<std::string>&, 46 const std::vector<std::string>&,
45 const GURL&, 47 const SerializedOrigin&,
46 URLRequestContext*, 48 URLRequestContext*,
47 const BoundNetLog&, 49 const BoundNetLog&,
48 scoped_ptr<WebSocketStream::ConnectDelegate>)> WebSocketStreamCreator; 50 scoped_ptr<WebSocketStream::ConnectDelegate>)> WebSocketStreamCreator;
49 51
50 // Creates a new WebSocketChannel in an idle state. 52 // Creates a new WebSocketChannel in an idle state.
51 // SendAddChannelRequest() must be called immediately afterwards to start the 53 // SendAddChannelRequest() must be called immediately afterwards to start the
52 // connection process. 54 // connection process.
53 WebSocketChannel(scoped_ptr<WebSocketEventInterface> event_interface, 55 WebSocketChannel(scoped_ptr<WebSocketEventInterface> event_interface,
54 URLRequestContext* url_request_context); 56 URLRequestContext* url_request_context);
55 virtual ~WebSocketChannel(); 57 virtual ~WebSocketChannel();
56 58
57 // Starts the connection process. 59 // Starts the connection process.
58 void SendAddChannelRequest( 60 void SendAddChannelRequest(
59 const GURL& socket_url, 61 const GURL& socket_url,
60 const std::vector<std::string>& requested_protocols, 62 const std::vector<std::string>& requested_protocols,
61 const GURL& origin); 63 const SerializedOrigin& origin);
62 64
63 // Sends a data frame to the remote side. The frame should usually be no 65 // Sends a data frame to the remote side. The frame should usually be no
64 // larger than 32KB to prevent the time required to copy the buffers from from 66 // larger than 32KB to prevent the time required to copy the buffers from from
65 // unduly delaying other tasks that need to run on the IO thread. This method 67 // unduly delaying other tasks that need to run on the IO thread. This method
66 // has a hard limit of 2GB. It is the responsibility of the caller to ensure 68 // has a hard limit of 2GB. It is the responsibility of the caller to ensure
67 // that they have sufficient send quota to send this data, otherwise the 69 // that they have sufficient send quota to send this data, otherwise the
68 // connection will be closed without sending. |fin| indicates the last frame 70 // connection will be closed without sending. |fin| indicates the last frame
69 // in a message, equivalent to "FIN" as specified in section 5.2 of 71 // in a message, equivalent to "FIN" as specified in section 5.2 of
70 // RFC6455. |data| is the "Payload Data". If |op_code| is kOpCodeText, or it 72 // RFC6455. |data| is the "Payload Data". If |op_code| is kOpCodeText, or it
71 // is kOpCodeContinuation and the type the message is Text, then |data| must 73 // is kOpCodeContinuation and the type the message is Text, then |data| must
(...skipping 17 matching lines...) Expand all
89 // This does *not* trigger the event OnClosingHandshake(). The caller should 91 // This does *not* trigger the event OnClosingHandshake(). The caller should
90 // assume that the closing handshake has started and perform the equivalent 92 // assume that the closing handshake has started and perform the equivalent
91 // processing to OnClosingHandshake() if necessary. 93 // processing to OnClosingHandshake() if necessary.
92 void StartClosingHandshake(uint16 code, const std::string& reason); 94 void StartClosingHandshake(uint16 code, const std::string& reason);
93 95
94 // Starts the connection process, using a specified creator callback rather 96 // Starts the connection process, using a specified creator callback rather
95 // than the default. This is exposed for testing. 97 // than the default. This is exposed for testing.
96 void SendAddChannelRequestForTesting( 98 void SendAddChannelRequestForTesting(
97 const GURL& socket_url, 99 const GURL& socket_url,
98 const std::vector<std::string>& requested_protocols, 100 const std::vector<std::string>& requested_protocols,
99 const GURL& origin, 101 const SerializedOrigin& origin,
100 const WebSocketStreamCreator& creator); 102 const WebSocketStreamCreator& creator);
101 103
102 // The default timout for the closing handshake is a sensible value (see 104 // The default timout for the closing handshake is a sensible value (see
103 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can 105 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can
104 // set it to a very small value for testing purposes. 106 // set it to a very small value for testing purposes.
105 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay); 107 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay);
106 108
107 // Called when the stream starts the WebSocket Opening Handshake. 109 // Called when the stream starts the WebSocket Opening Handshake.
108 // This method is public for testing. 110 // This method is public for testing.
109 void OnStartOpeningHandshake( 111 void OnStartOpeningHandshake(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // WebSocketStream::ConnectDelegate directly to avoid cluttering the public 146 // WebSocketStream::ConnectDelegate directly to avoid cluttering the public
145 // interface with the implementation of those methods, and because the 147 // interface with the implementation of those methods, and because the
146 // lifetime of a WebSocketChannel is longer than the lifetime of the 148 // lifetime of a WebSocketChannel is longer than the lifetime of the
147 // connection process. 149 // connection process.
148 class ConnectDelegate; 150 class ConnectDelegate;
149 151
150 // Starts the connection process, using the supplied creator callback. 152 // Starts the connection process, using the supplied creator callback.
151 void SendAddChannelRequestWithSuppliedCreator( 153 void SendAddChannelRequestWithSuppliedCreator(
152 const GURL& socket_url, 154 const GURL& socket_url,
153 const std::vector<std::string>& requested_protocols, 155 const std::vector<std::string>& requested_protocols,
154 const GURL& origin, 156 const SerializedOrigin& origin,
155 const WebSocketStreamCreator& creator); 157 const WebSocketStreamCreator& creator);
156 158
157 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports 159 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports
158 // success to the event interface. May delete |this|. 160 // success to the event interface. May delete |this|.
159 void OnConnectSuccess(scoped_ptr<WebSocketStream> stream); 161 void OnConnectSuccess(scoped_ptr<WebSocketStream> stream);
160 162
161 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports 163 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports
162 // failure to the event interface. May delete |this|. 164 // failure to the event interface. May delete |this|.
163 void OnConnectFailure(const std::string& message); 165 void OnConnectFailure(const std::string& message);
164 166
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // True if we have already sent the type (Text or Binary) of the current 341 // True if we have already sent the type (Text or Binary) of the current
340 // message to the renderer. This can be false if the message is empty so far. 342 // message to the renderer. This can be false if the message is empty so far.
341 bool initial_frame_forwarded_; 343 bool initial_frame_forwarded_;
342 344
343 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); 345 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel);
344 }; 346 };
345 347
346 } // namespace net 348 } // namespace net
347 349
348 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ 350 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698