OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 ASSERT(m_framer); | 68 ASSERT(m_framer); |
69 } | 69 } |
70 | 70 |
71 String WebSocketExtensionDeflateFrame::handshakeString() | 71 String WebSocketExtensionDeflateFrame::handshakeString() |
72 { | 72 { |
73 return extensionToken(); // No parameter | 73 return extensionToken(); // No parameter |
74 } | 74 } |
75 | 75 |
76 bool WebSocketExtensionDeflateFrame::processResponse(const HashMap<String, Strin
g>& serverParameters) | 76 bool WebSocketExtensionDeflateFrame::processResponse(const HashMap<String, Strin
g>& serverParameters) |
77 { | 77 { |
78 #if USE(ZLIB) | |
79 if (m_responseProcessed) { | 78 if (m_responseProcessed) { |
80 m_failureReason = "Received duplicate deflate-frame response"; | 79 m_failureReason = "Received duplicate deflate-frame response"; |
81 return false; | 80 return false; |
82 } | 81 } |
83 m_responseProcessed = true; | 82 m_responseProcessed = true; |
84 | 83 |
85 int expectedNumParameters = 0; | 84 int expectedNumParameters = 0; |
86 int windowBits = 15; | 85 int windowBits = 15; |
87 HashMap<String, String>::const_iterator parameter = serverParameters.find("m
ax_window_bits"); | 86 HashMap<String, String>::const_iterator parameter = serverParameters.find("m
ax_window_bits"); |
88 if (parameter != serverParameters.end()) { | 87 if (parameter != serverParameters.end()) { |
(...skipping 16 matching lines...) Expand all Loading... |
105 expectedNumParameters++; | 104 expectedNumParameters++; |
106 } | 105 } |
107 | 106 |
108 if (expectedNumParameters != serverParameters.size()) { | 107 if (expectedNumParameters != serverParameters.size()) { |
109 m_failureReason = "Received unexpected deflate-frame parameter"; | 108 m_failureReason = "Received unexpected deflate-frame parameter"; |
110 return false; | 109 return false; |
111 } | 110 } |
112 | 111 |
113 m_framer->enableDeflate(windowBits, mode); | 112 m_framer->enableDeflate(windowBits, mode); |
114 return true; | 113 return true; |
115 #else | |
116 ASSERT_NOT_REACHED(); | |
117 return false; | |
118 #endif | |
119 } | 114 } |
120 | 115 |
121 DeflateResultHolder::DeflateResultHolder(WebSocketDeflateFramer* framer) | 116 DeflateResultHolder::DeflateResultHolder(WebSocketDeflateFramer* framer) |
122 : m_framer(framer) | 117 : m_framer(framer) |
123 , m_succeeded(true) | 118 , m_succeeded(true) |
124 { | 119 { |
125 ASSERT(m_framer); | 120 ASSERT(m_framer); |
126 } | 121 } |
127 | 122 |
128 DeflateResultHolder::~DeflateResultHolder() | 123 DeflateResultHolder::~DeflateResultHolder() |
(...skipping 28 matching lines...) Expand all Loading... |
157 WebSocketDeflateFramer::WebSocketDeflateFramer() | 152 WebSocketDeflateFramer::WebSocketDeflateFramer() |
158 : m_enabled(false) | 153 : m_enabled(false) |
159 { | 154 { |
160 } | 155 } |
161 | 156 |
162 PassOwnPtr<WebSocketExtensionProcessor> WebSocketDeflateFramer::createExtensionP
rocessor() | 157 PassOwnPtr<WebSocketExtensionProcessor> WebSocketDeflateFramer::createExtensionP
rocessor() |
163 { | 158 { |
164 return WebSocketExtensionDeflateFrame::create(this); | 159 return WebSocketExtensionDeflateFrame::create(this); |
165 } | 160 } |
166 | 161 |
167 bool WebSocketDeflateFramer::canDeflate() const | |
168 { | |
169 #if USE(ZLIB) | |
170 return true; | |
171 #else | |
172 return false; | |
173 #endif | |
174 } | |
175 | |
176 #if USE(ZLIB) | |
177 void WebSocketDeflateFramer::enableDeflate(int windowBits, WebSocketDeflater::Co
ntextTakeOverMode mode) | 162 void WebSocketDeflateFramer::enableDeflate(int windowBits, WebSocketDeflater::Co
ntextTakeOverMode mode) |
178 { | 163 { |
179 m_deflater = WebSocketDeflater::create(windowBits, mode); | 164 m_deflater = WebSocketDeflater::create(windowBits, mode); |
180 m_inflater = WebSocketInflater::create(); | 165 m_inflater = WebSocketInflater::create(); |
181 if (!m_deflater->initialize() || !m_inflater->initialize()) { | 166 if (!m_deflater->initialize() || !m_inflater->initialize()) { |
182 m_deflater.clear(); | 167 m_deflater.clear(); |
183 m_inflater.clear(); | 168 m_inflater.clear(); |
184 return; | 169 return; |
185 } | 170 } |
186 m_enabled = true; | 171 m_enabled = true; |
187 } | 172 } |
188 #endif | |
189 | 173 |
190 PassOwnPtr<DeflateResultHolder> WebSocketDeflateFramer::deflate(WebSocketFrame&
frame) | 174 PassOwnPtr<DeflateResultHolder> WebSocketDeflateFramer::deflate(WebSocketFrame&
frame) |
191 { | 175 { |
192 #if USE(ZLIB) | |
193 OwnPtr<DeflateResultHolder> result = DeflateResultHolder::create(this); | 176 OwnPtr<DeflateResultHolder> result = DeflateResultHolder::create(this); |
194 if (!enabled() || !WebSocketFrame::isNonControlOpCode(frame.opCode) || !fram
e.payloadLength) | 177 if (!enabled() || !WebSocketFrame::isNonControlOpCode(frame.opCode) || !fram
e.payloadLength) |
195 return result.release(); | 178 return result.release(); |
196 if (!m_deflater->addBytes(frame.payload, frame.payloadLength) || !m_deflater
->finish()) { | 179 if (!m_deflater->addBytes(frame.payload, frame.payloadLength) || !m_deflater
->finish()) { |
197 result->fail("Failed to compress frame"); | 180 result->fail("Failed to compress frame"); |
198 return result.release(); | 181 return result.release(); |
199 } | 182 } |
200 frame.compress = true; | 183 frame.compress = true; |
201 frame.payload = m_deflater->data(); | 184 frame.payload = m_deflater->data(); |
202 frame.payloadLength = m_deflater->size(); | 185 frame.payloadLength = m_deflater->size(); |
203 return result.release(); | 186 return result.release(); |
204 #else | |
205 return DeflateResultHolder::create(this); | |
206 #endif | |
207 } | 187 } |
208 | 188 |
209 void WebSocketDeflateFramer::resetDeflateContext() | 189 void WebSocketDeflateFramer::resetDeflateContext() |
210 { | 190 { |
211 #if USE(ZLIB) | |
212 if (m_deflater) | 191 if (m_deflater) |
213 m_deflater->reset(); | 192 m_deflater->reset(); |
214 #endif | |
215 } | 193 } |
216 | 194 |
217 PassOwnPtr<InflateResultHolder> WebSocketDeflateFramer::inflate(WebSocketFrame&
frame) | 195 PassOwnPtr<InflateResultHolder> WebSocketDeflateFramer::inflate(WebSocketFrame&
frame) |
218 { | 196 { |
219 OwnPtr<InflateResultHolder> result = InflateResultHolder::create(this); | 197 OwnPtr<InflateResultHolder> result = InflateResultHolder::create(this); |
220 if (!enabled() && frame.compress) { | 198 if (!enabled() && frame.compress) { |
221 result->fail("Compressed bit must be 0 if no negotiated deflate-frame ex
tension"); | 199 result->fail("Compressed bit must be 0 if no negotiated deflate-frame ex
tension"); |
222 return result.release(); | 200 return result.release(); |
223 } | 201 } |
224 #if USE(ZLIB) | |
225 if (!frame.compress) | 202 if (!frame.compress) |
226 return result.release(); | 203 return result.release(); |
227 if (!WebSocketFrame::isNonControlOpCode(frame.opCode)) { | 204 if (!WebSocketFrame::isNonControlOpCode(frame.opCode)) { |
228 result->fail("Received unexpected compressed frame"); | 205 result->fail("Received unexpected compressed frame"); |
229 return result.release(); | 206 return result.release(); |
230 } | 207 } |
231 if (!m_inflater->addBytes(frame.payload, frame.payloadLength) || !m_inflater
->finish()) { | 208 if (!m_inflater->addBytes(frame.payload, frame.payloadLength) || !m_inflater
->finish()) { |
232 result->fail("Failed to decompress frame"); | 209 result->fail("Failed to decompress frame"); |
233 return result.release(); | 210 return result.release(); |
234 } | 211 } |
235 frame.compress = false; | 212 frame.compress = false; |
236 frame.payload = m_inflater->data(); | 213 frame.payload = m_inflater->data(); |
237 frame.payloadLength = m_inflater->size(); | 214 frame.payloadLength = m_inflater->size(); |
238 return result.release(); | 215 return result.release(); |
239 #else | |
240 return result.release(); | |
241 #endif | |
242 } | 216 } |
243 | 217 |
244 void WebSocketDeflateFramer::resetInflateContext() | 218 void WebSocketDeflateFramer::resetInflateContext() |
245 { | 219 { |
246 #if USE(ZLIB) | |
247 if (m_inflater) | 220 if (m_inflater) |
248 m_inflater->reset(); | 221 m_inflater->reset(); |
249 #endif | |
250 } | 222 } |
251 | 223 |
252 void WebSocketDeflateFramer::didFail() | 224 void WebSocketDeflateFramer::didFail() |
253 { | 225 { |
254 resetDeflateContext(); | 226 resetDeflateContext(); |
255 resetInflateContext(); | 227 resetInflateContext(); |
256 } | 228 } |
257 | 229 |
258 } // namespace WebCore | 230 } // namespace WebCore |
OLD | NEW |