OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ | |
6 #define NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/logging.h" | |
11 #include "net/base/net_export.h" | |
12 #include "net/websockets/websocket_deflater.h" | |
13 #include "net/websockets/websocket_extension.h" | |
14 | |
15 namespace net { | |
16 | |
17 // A WebSocketDeflateParameters represents permessage-deflate extension | |
18 // parameters. This class is used either for request and response. | |
19 class NET_EXPORT_PRIVATE WebSocketDeflateParameters { | |
20 using ContextTakeOverMode = WebSocketDeflater::ContextTakeOverMode; | |
21 static const ContextTakeOverMode TAKE_OVER_CONTEXT = | |
22 WebSocketDeflater::TAKE_OVER_CONTEXT; | |
23 static const ContextTakeOverMode DO_NOT_TAKE_OVER_CONTEXT = | |
24 WebSocketDeflater::DO_NOT_TAKE_OVER_CONTEXT; | |
25 struct WindowBits { | |
26 WindowBits() : WindowBits(0, false, false) {} | |
27 WindowBits(int16 bits, bool is_specified, bool has_value) | |
28 : bits(bits), is_specified(is_specified), has_value(has_value) {} | |
29 | |
30 int16 bits; | |
31 // True when "window bits" parameter appears in the parameters. | |
32 bool is_specified; | |
33 // True when "window bits" parameter has the value. | |
34 bool has_value; | |
35 }; | |
36 | |
37 public: | |
38 // Returns an WebSocketExtension instance containing this parameters. | |
tyoshino (SeeGerritForStatus)
2015/09/10 09:06:19
an -> a
tyoshino (SeeGerritForStatus)
2015/09/10 09:06:19
this -> these
or
containing the parameters store
yhirano
2015/09/10 11:20:13
Done.
yhirano
2015/09/10 11:20:13
Done.
| |
39 WebSocketExtension AsExtension() const; | |
40 | |
41 // Returns true when succeeded. | |
42 // Returns false and store the failure message to |failure_message| otherwise. | |
tyoshino (SeeGerritForStatus)
2015/09/10 09:06:19
store -> stores
yhirano
2015/09/10 11:20:13
Done.
| |
43 // Note that even if this function succeeds it is not guaranteed that the | |
44 // object is valid. To check it, call IsValidAsRequest or IsValidAsResponse. | |
45 bool Initialize(const WebSocketExtension& input, | |
46 std::string* failure_message); | |
47 | |
48 // Returns true when |*this| and |response| are compatible. | |
49 // |*this| must be valid as a request and |response| must be valid as a | |
50 // response. | |
51 bool IsCompatibleWith(const WebSocketDeflateParameters& response) const; | |
52 | |
53 bool IsValidAsRequest(std::string* failure_message) const; | |
54 bool IsValidAsResponse(std::string* failure_message) const; | |
55 bool IsValidAsRequest() const { | |
56 std::string message; | |
57 return IsValidAsRequest(&message); | |
58 } | |
59 bool IsValidAsResponse() const { | |
60 std::string message; | |
61 return IsValidAsResponse(&message); | |
62 } | |
63 | |
64 ContextTakeOverMode server_context_take_over_mode() const { | |
65 return server_context_take_over_mode_; | |
66 } | |
67 ContextTakeOverMode client_context_take_over_mode() const { | |
68 return client_context_take_over_mode_; | |
69 } | |
70 bool is_server_max_window_bits_specified() const { | |
71 return server_max_window_bits_.is_specified; | |
72 } | |
73 int server_max_window_bits() const { | |
74 DCHECK(is_server_max_window_bits_specified()); | |
75 return server_max_window_bits_.bits; | |
76 } | |
77 bool is_client_max_window_bits_specified() const { | |
78 return client_max_window_bits_.is_specified; | |
79 } | |
80 bool has_client_max_window_bits_value() const { | |
81 DCHECK(is_client_max_window_bits_specified()); | |
82 return client_max_window_bits_.has_value; | |
83 } | |
84 int client_max_window_bits() const { | |
85 DCHECK(has_client_max_window_bits_value()); | |
86 return client_max_window_bits_.bits; | |
87 } | |
88 void SetServerNoContextTakeOver() { | |
89 server_context_take_over_mode_ = DO_NOT_TAKE_OVER_CONTEXT; | |
90 } | |
91 void SetClientNoContextTakeOver() { | |
92 client_context_take_over_mode_ = DO_NOT_TAKE_OVER_CONTEXT; | |
93 } | |
94 // |bits| must be valid as a max_window_bits value. | |
95 void SetServerMaxWindowBits(int bits) { | |
96 DCHECK(IsValidWindowBits(bits)); | |
97 server_max_window_bits_ = WindowBits(bits, true, true); | |
98 } | |
99 void SetClientMaxWindowBits() { | |
100 client_max_window_bits_ = WindowBits(0, true, false); | |
101 } | |
102 // |bits| must be valid as a max_window_bits value. | |
103 void SetClientMaxWindowBits(int bits) { | |
104 DCHECK(IsValidWindowBits(bits)); | |
105 client_max_window_bits_ = WindowBits(bits, true, true); | |
106 } | |
107 | |
108 // Return true if |bits| is valid as a max_window_bits value. | |
109 static bool IsValidWindowBits(int bits) { return 8 <= bits && bits <= 15; } | |
110 | |
111 private: | |
112 // |server_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and | |
113 // only if |server_no_context_takeover| is set in the parameters. | |
114 ContextTakeOverMode server_context_take_over_mode_ = TAKE_OVER_CONTEXT; | |
115 // |client_context_take_over_mode| is set to DO_NOT_TAKE_OVER_CONTEXT if and | |
116 // only if |client_no_context_takeover| is set in the parameters. | |
117 ContextTakeOverMode client_context_take_over_mode_ = TAKE_OVER_CONTEXT; | |
118 WindowBits server_max_window_bits_; | |
119 WindowBits client_max_window_bits_; | |
120 }; | |
121 | |
122 } // namespace net | |
123 | |
124 #endif // NET_WEBSOCKETS_WEBSOCKET_DEFLATE_PARAMETERS_H_ | |
OLD | NEW |