OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 167 } |
168 | 168 |
169 String WebSocketHandshake::clientOrigin() const | 169 String WebSocketHandshake::clientOrigin() const |
170 { | 170 { |
171 return m_document->securityOrigin()->toString(); | 171 return m_document->securityOrigin()->toString(); |
172 } | 172 } |
173 | 173 |
174 String WebSocketHandshake::clientLocation() const | 174 String WebSocketHandshake::clientLocation() const |
175 { | 175 { |
176 StringBuilder builder; | 176 StringBuilder builder; |
177 builder.append(m_secure ? "wss" : "ws"); | 177 if (m_secure) |
178 builder.append("://"); | 178 builder.appendLiteral("wss"); |
| 179 else |
| 180 builder.appendLiteral("ws"); |
| 181 builder.appendLiteral("://"); |
179 builder.append(hostName(m_url, m_secure)); | 182 builder.append(hostName(m_url, m_secure)); |
180 builder.append(resourceName(m_url)); | 183 builder.append(resourceName(m_url)); |
181 return builder.toString(); | 184 return builder.toString(); |
182 } | 185 } |
183 | 186 |
184 CString WebSocketHandshake::clientHandshakeMessage() const | 187 CString WebSocketHandshake::clientHandshakeMessage() const |
185 { | 188 { |
186 ASSERT(m_document); | 189 ASSERT(m_document); |
187 | 190 |
188 // Keep the following consistent with clientHandshakeRequest(). | 191 // Keep the following consistent with clientHandshakeRequest(). |
189 StringBuilder builder; | 192 StringBuilder builder; |
190 | 193 |
191 builder.append("GET "); | 194 builder.appendLiteral("GET "); |
192 builder.append(resourceName(m_url)); | 195 builder.append(resourceName(m_url)); |
193 builder.append(" HTTP/1.1\r\n"); | 196 builder.appendLiteral(" HTTP/1.1\r\n"); |
194 | 197 |
195 Vector<String> fields; | 198 Vector<String> fields; |
196 fields.append("Upgrade: websocket"); | 199 fields.append("Upgrade: websocket"); |
197 fields.append("Connection: Upgrade"); | 200 fields.append("Connection: Upgrade"); |
198 fields.append("Host: " + hostName(m_url, m_secure)); | 201 fields.append("Host: " + hostName(m_url, m_secure)); |
199 fields.append("Origin: " + clientOrigin()); | 202 fields.append("Origin: " + clientOrigin()); |
200 if (!m_clientProtocol.isEmpty()) | 203 if (!m_clientProtocol.isEmpty()) |
201 fields.append("Sec-WebSocket-Protocol: " + m_clientProtocol); | 204 fields.append("Sec-WebSocket-Protocol: " + m_clientProtocol); |
202 | 205 |
203 // Add no-cache headers to avoid compatibility issue. | 206 // Add no-cache headers to avoid compatibility issue. |
(...skipping 10 matching lines...) Expand all Loading... |
214 fields.append("Sec-WebSocket-Extensions: " + extensionValue); | 217 fields.append("Sec-WebSocket-Extensions: " + extensionValue); |
215 | 218 |
216 fields.append("User-Agent: " + m_document->userAgent(m_document->url())); | 219 fields.append("User-Agent: " + m_document->userAgent(m_document->url())); |
217 | 220 |
218 // Fields in the handshake are sent by the client in a random order; the | 221 // Fields in the handshake are sent by the client in a random order; the |
219 // order is not meaningful. Thus, it's ok to send the order we constructed | 222 // order is not meaningful. Thus, it's ok to send the order we constructed |
220 // the fields. | 223 // the fields. |
221 | 224 |
222 for (size_t i = 0; i < fields.size(); i++) { | 225 for (size_t i = 0; i < fields.size(); i++) { |
223 builder.append(fields[i]); | 226 builder.append(fields[i]); |
224 builder.append("\r\n"); | 227 builder.appendLiteral("\r\n"); |
225 } | 228 } |
226 | 229 |
227 builder.append("\r\n"); | 230 builder.appendLiteral("\r\n"); |
228 | 231 |
229 return builder.toString().utf8(); | 232 return builder.toString().utf8(); |
230 } | 233 } |
231 | 234 |
232 PassRefPtr<WebSocketHandshakeRequest> WebSocketHandshake::clientHandshakeRequest
() const | 235 PassRefPtr<WebSocketHandshakeRequest> WebSocketHandshake::clientHandshakeRequest
() const |
233 { | 236 { |
234 ASSERT(m_document); | 237 ASSERT(m_document); |
235 | 238 |
236 // Keep the following consistent with clientHandshakeMessage(). | 239 // Keep the following consistent with clientHandshakeMessage(). |
237 // FIXME: do we need to store m_secWebSocketKey1, m_secWebSocketKey2 and | 240 // FIXME: do we need to store m_secWebSocketKey1, m_secWebSocketKey2 and |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } | 547 } |
545 return true; | 548 return true; |
546 } | 549 } |
547 | 550 |
548 void WebSocketHandshake::trace(Visitor* visitor) | 551 void WebSocketHandshake::trace(Visitor* visitor) |
549 { | 552 { |
550 visitor->trace(m_document); | 553 visitor->trace(m_document); |
551 } | 554 } |
552 | 555 |
553 } // namespace blink | 556 } // namespace blink |
OLD | NEW |