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

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
« no previous file with comments | « content/public/common/common_param_traits.cc ('k') | net/websockets/websocket_channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 namespace url {
26 class Origin;
27 } // namespace url
28
25 namespace net { 29 namespace net {
26 30
27 class BoundNetLog; 31 class BoundNetLog;
28 class IOBuffer; 32 class IOBuffer;
29 class URLRequestContext; 33 class URLRequestContext;
30 struct WebSocketHandshakeRequestInfo; 34 struct WebSocketHandshakeRequestInfo;
31 struct WebSocketHandshakeResponseInfo; 35 struct WebSocketHandshakeResponseInfo;
32 36
33 // Transport-independent implementation of WebSockets. Implements protocol 37 // Transport-independent implementation of WebSockets. Implements protocol
34 // semantics that do not depend on the underlying transport. Provides the 38 // semantics that do not depend on the underlying transport. Provides the
35 // interface to the content layer. Some WebSocket concepts are used here without 39 // 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 40 // definition; please see the RFC at http://tools.ietf.org/html/rfc6455 for
37 // clarification. 41 // clarification.
38 class NET_EXPORT WebSocketChannel { 42 class NET_EXPORT WebSocketChannel {
39 public: 43 public:
40 // The type of a WebSocketStream creator callback. Must match the signature of 44 // The type of a WebSocketStream creator callback. Must match the signature of
41 // WebSocketStream::CreateAndConnectStream(). 45 // WebSocketStream::CreateAndConnectStream().
42 typedef base::Callback<scoped_ptr<WebSocketStreamRequest>( 46 typedef base::Callback<scoped_ptr<WebSocketStreamRequest>(
43 const GURL&, 47 const GURL&,
44 const std::vector<std::string>&, 48 const std::vector<std::string>&,
45 const GURL&, 49 const url::Origin&,
46 URLRequestContext*, 50 URLRequestContext*,
47 const BoundNetLog&, 51 const BoundNetLog&,
48 scoped_ptr<WebSocketStream::ConnectDelegate>)> WebSocketStreamCreator; 52 scoped_ptr<WebSocketStream::ConnectDelegate>)> WebSocketStreamCreator;
49 53
50 // Creates a new WebSocketChannel in an idle state. 54 // Creates a new WebSocketChannel in an idle state.
51 // SendAddChannelRequest() must be called immediately afterwards to start the 55 // SendAddChannelRequest() must be called immediately afterwards to start the
52 // connection process. 56 // connection process.
53 WebSocketChannel(scoped_ptr<WebSocketEventInterface> event_interface, 57 WebSocketChannel(scoped_ptr<WebSocketEventInterface> event_interface,
54 URLRequestContext* url_request_context); 58 URLRequestContext* url_request_context);
55 virtual ~WebSocketChannel(); 59 virtual ~WebSocketChannel();
56 60
57 // Starts the connection process. 61 // Starts the connection process.
58 void SendAddChannelRequest( 62 void SendAddChannelRequest(
59 const GURL& socket_url, 63 const GURL& socket_url,
60 const std::vector<std::string>& requested_protocols, 64 const std::vector<std::string>& requested_protocols,
61 const GURL& origin); 65 const url::Origin& origin);
62 66
63 // Sends a data frame to the remote side. The frame should usually be no 67 // 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 68 // 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 69 // 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 70 // 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 71 // that they have sufficient send quota to send this data, otherwise the
68 // connection will be closed without sending. |fin| indicates the last frame 72 // 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 73 // 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 74 // 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 75 // 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 93 // This does *not* trigger the event OnClosingHandshake(). The caller should
90 // assume that the closing handshake has started and perform the equivalent 94 // assume that the closing handshake has started and perform the equivalent
91 // processing to OnClosingHandshake() if necessary. 95 // processing to OnClosingHandshake() if necessary.
92 void StartClosingHandshake(uint16 code, const std::string& reason); 96 void StartClosingHandshake(uint16 code, const std::string& reason);
93 97
94 // Starts the connection process, using a specified creator callback rather 98 // Starts the connection process, using a specified creator callback rather
95 // than the default. This is exposed for testing. 99 // than the default. This is exposed for testing.
96 void SendAddChannelRequestForTesting( 100 void SendAddChannelRequestForTesting(
97 const GURL& socket_url, 101 const GURL& socket_url,
98 const std::vector<std::string>& requested_protocols, 102 const std::vector<std::string>& requested_protocols,
99 const GURL& origin, 103 const url::Origin& origin,
100 const WebSocketStreamCreator& creator); 104 const WebSocketStreamCreator& creator);
101 105
102 // The default timout for the closing handshake is a sensible value (see 106 // The default timout for the closing handshake is a sensible value (see
103 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can 107 // kClosingHandshakeTimeoutSeconds in websocket_channel.cc). However, we can
104 // set it to a very small value for testing purposes. 108 // set it to a very small value for testing purposes.
105 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay); 109 void SetClosingHandshakeTimeoutForTesting(base::TimeDelta delay);
106 110
107 // Called when the stream starts the WebSocket Opening Handshake. 111 // Called when the stream starts the WebSocket Opening Handshake.
108 // This method is public for testing. 112 // This method is public for testing.
109 void OnStartOpeningHandshake( 113 void OnStartOpeningHandshake(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // WebSocketStream::ConnectDelegate directly to avoid cluttering the public 148 // WebSocketStream::ConnectDelegate directly to avoid cluttering the public
145 // interface with the implementation of those methods, and because the 149 // interface with the implementation of those methods, and because the
146 // lifetime of a WebSocketChannel is longer than the lifetime of the 150 // lifetime of a WebSocketChannel is longer than the lifetime of the
147 // connection process. 151 // connection process.
148 class ConnectDelegate; 152 class ConnectDelegate;
149 153
150 // Starts the connection process, using the supplied creator callback. 154 // Starts the connection process, using the supplied creator callback.
151 void SendAddChannelRequestWithSuppliedCreator( 155 void SendAddChannelRequestWithSuppliedCreator(
152 const GURL& socket_url, 156 const GURL& socket_url,
153 const std::vector<std::string>& requested_protocols, 157 const std::vector<std::string>& requested_protocols,
154 const GURL& origin, 158 const url::Origin& origin,
155 const WebSocketStreamCreator& creator); 159 const WebSocketStreamCreator& creator);
156 160
157 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports 161 // Success callback from WebSocketStream::CreateAndConnectStream(). Reports
158 // success to the event interface. May delete |this|. 162 // success to the event interface. May delete |this|.
159 void OnConnectSuccess(scoped_ptr<WebSocketStream> stream); 163 void OnConnectSuccess(scoped_ptr<WebSocketStream> stream);
160 164
161 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports 165 // Failure callback from WebSocketStream::CreateAndConnectStream(). Reports
162 // failure to the event interface. May delete |this|. 166 // failure to the event interface. May delete |this|.
163 void OnConnectFailure(const std::string& message); 167 void OnConnectFailure(const std::string& message);
164 168
(...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 343 // 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. 344 // message to the renderer. This can be false if the message is empty so far.
341 bool initial_frame_forwarded_; 345 bool initial_frame_forwarded_;
342 346
343 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel); 347 DISALLOW_COPY_AND_ASSIGN(WebSocketChannel);
344 }; 348 };
345 349
346 } // namespace net 350 } // namespace net
347 351
348 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_ 352 #endif // NET_WEBSOCKETS_WEBSOCKET_CHANNEL_H_
OLDNEW
« no previous file with comments | « content/public/common/common_param_traits.cc ('k') | net/websockets/websocket_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698