OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "wtf/ArrayBuffer.h" | 54 #include "wtf/ArrayBuffer.h" |
55 #include "wtf/ArrayBufferView.h" | 55 #include "wtf/ArrayBufferView.h" |
56 #include "wtf/Assertions.h" | 56 #include "wtf/Assertions.h" |
57 #include "wtf/HashSet.h" | 57 #include "wtf/HashSet.h" |
58 #include "wtf/PassOwnPtr.h" | 58 #include "wtf/PassOwnPtr.h" |
59 #include "wtf/StdLibExtras.h" | 59 #include "wtf/StdLibExtras.h" |
60 #include "wtf/text/CString.h" | 60 #include "wtf/text/CString.h" |
61 #include "wtf/text/StringBuilder.h" | 61 #include "wtf/text/StringBuilder.h" |
62 #include "wtf/text/WTFString.h" | 62 #include "wtf/text/WTFString.h" |
63 | 63 |
64 using namespace std; | |
65 | |
66 namespace WebCore { | 64 namespace WebCore { |
67 | 65 |
68 WebSocket::EventQueue::EventQueue(EventTarget* target) | 66 WebSocket::EventQueue::EventQueue(EventTarget* target) |
69 : m_state(Active) | 67 : m_state(Active) |
70 , m_target(target) | 68 , m_target(target) |
71 , m_resumeTimer(this, &EventQueue::resumeTimerFired) { } | 69 , m_resumeTimer(this, &EventQueue::resumeTimerFired) { } |
72 | 70 |
73 WebSocket::EventQueue::~EventQueue() { stop(); } | 71 WebSocket::EventQueue::~EventQueue() { stop(); } |
74 | 72 |
75 void WebSocket::EventQueue::dispatch(PassRefPtrWillBeRawPtr<Event> event) | 73 void WebSocket::EventQueue::dispatch(PassRefPtrWillBeRawPtr<Event> event) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 const UChar maximumProtocolCharacter = '~'; // U+007E. | 163 const UChar maximumProtocolCharacter = '~'; // U+007E. |
166 // Set to true if character does not matches "separators" ABNF defined in | 164 // Set to true if character does not matches "separators" ABNF defined in |
167 // RFC2616. SP and HT are excluded since the range check excludes them. | 165 // RFC2616. SP and HT are excluded since the range check excludes them. |
168 bool isNotSeparator = character != '"' && character != '(' && character != '
)' && character != ',' && character != '/' | 166 bool isNotSeparator = character != '"' && character != '(' && character != '
)' && character != ',' && character != '/' |
169 && !(character >= ':' && character <= '@') // U+003A - U+0040 (':', ';',
'<', '=', '>', '?', '@'). | 167 && !(character >= ':' && character <= '@') // U+003A - U+0040 (':', ';',
'<', '=', '>', '?', '@'). |
170 && !(character >= '[' && character <= ']') // U+005B - U+005D ('[', '\\'
, ']'). | 168 && !(character >= '[' && character <= ']') // U+005B - U+005D ('[', '\\'
, ']'). |
171 && character != '{' && character != '}'; | 169 && character != '{' && character != '}'; |
172 return character >= minimumProtocolCharacter && character <= maximumProtocol
Character && isNotSeparator; | 170 return character >= minimumProtocolCharacter && character <= maximumProtocol
Character && isNotSeparator; |
173 } | 171 } |
174 | 172 |
175 static bool isValidSubprotocolString(const String& protocol) | 173 bool WebSocket::isValidSubprotocolString(const String& protocol) |
176 { | 174 { |
177 if (protocol.isEmpty()) | 175 if (protocol.isEmpty()) |
178 return false; | 176 return false; |
179 for (size_t i = 0; i < protocol.length(); ++i) { | 177 for (size_t i = 0; i < protocol.length(); ++i) { |
180 if (!isValidSubprotocolCharacter(protocol[i])) | 178 if (!isValidSubprotocolCharacter(protocol[i])) |
181 return false; | 179 return false; |
182 } | 180 } |
183 return true; | 181 return true; |
184 } | 182 } |
185 | 183 |
(...skipping 17 matching lines...) Expand all Loading... |
203 for (size_t i = 0; i < strings.size(); ++i) { | 201 for (size_t i = 0; i < strings.size(); ++i) { |
204 if (i) | 202 if (i) |
205 builder.append(separator); | 203 builder.append(separator); |
206 builder.append(strings[i]); | 204 builder.append(strings[i]); |
207 } | 205 } |
208 return builder.toString(); | 206 return builder.toString(); |
209 } | 207 } |
210 | 208 |
211 static unsigned long saturateAdd(unsigned long a, unsigned long b) | 209 static unsigned long saturateAdd(unsigned long a, unsigned long b) |
212 { | 210 { |
213 if (numeric_limits<unsigned long>::max() - a < b) | 211 if (std::numeric_limits<unsigned long>::max() - a < b) |
214 return numeric_limits<unsigned long>::max(); | 212 return std::numeric_limits<unsigned long>::max(); |
215 return a + b; | 213 return a + b; |
216 } | 214 } |
217 | 215 |
218 static void setInvalidStateErrorForSendMethod(ExceptionState& exceptionState) | 216 static void setInvalidStateErrorForSendMethod(ExceptionState& exceptionState) |
219 { | 217 { |
220 exceptionState.throwDOMException(InvalidStateError, "Still in CONNECTING sta
te."); | 218 exceptionState.throwDOMException(InvalidStateError, "Still in CONNECTING sta
te."); |
221 } | 219 } |
222 | 220 |
223 const char* WebSocket::subProtocolSeperator() | 221 const char* WebSocket::subprotocolSeperator() |
224 { | 222 { |
225 return ", "; | 223 return ", "; |
226 } | 224 } |
227 | 225 |
228 WebSocket::WebSocket(ExecutionContext* context) | 226 WebSocket::WebSocket(ExecutionContext* context) |
229 : ActiveDOMObject(context) | 227 : ActiveDOMObject(context) |
230 , m_state(CONNECTING) | 228 , m_state(CONNECTING) |
231 , m_bufferedAmount(0) | 229 , m_bufferedAmount(0) |
232 , m_bufferedAmountAfterClose(0) | 230 , m_bufferedAmountAfterClose(0) |
233 , m_binaryType(BinaryTypeBlob) | 231 , m_binaryType(BinaryTypeBlob) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 Document* document = toDocument(executionContext()); | 309 Document* document = toDocument(executionContext()); |
312 shouldBypassMainWorldContentSecurityPolicy = document->frame()->script()
.shouldBypassMainWorldContentSecurityPolicy(); | 310 shouldBypassMainWorldContentSecurityPolicy = document->frame()->script()
.shouldBypassMainWorldContentSecurityPolicy(); |
313 } | 311 } |
314 if (!shouldBypassMainWorldContentSecurityPolicy && !executionContext()->cont
entSecurityPolicy()->allowConnectToSource(m_url)) { | 312 if (!shouldBypassMainWorldContentSecurityPolicy && !executionContext()->cont
entSecurityPolicy()->allowConnectToSource(m_url)) { |
315 m_state = CLOSED; | 313 m_state = CLOSED; |
316 // The URL is safe to expose to JavaScript, as this check happens synchr
onously before redirection. | 314 // The URL is safe to expose to JavaScript, as this check happens synchr
onously before redirection. |
317 exceptionState.throwSecurityError("Refused to connect to '" + m_url.elid
edString() + "' because it violates the document's Content Security Policy."); | 315 exceptionState.throwSecurityError("Refused to connect to '" + m_url.elid
edString() + "' because it violates the document's Content Security Policy."); |
318 return; | 316 return; |
319 } | 317 } |
320 | 318 |
321 m_channel = WebSocketChannel::create(executionContext(), this); | 319 m_channel = createChannel(executionContext(), this); |
322 | 320 |
323 for (size_t i = 0; i < protocols.size(); ++i) { | 321 for (size_t i = 0; i < protocols.size(); ++i) { |
324 if (!isValidSubprotocolString(protocols[i])) { | 322 if (!isValidSubprotocolString(protocols[i])) { |
325 m_state = CLOSED; | 323 m_state = CLOSED; |
326 exceptionState.throwDOMException(SyntaxError, "The subprotocol '" +
encodeSubprotocolString(protocols[i]) + "' is invalid."); | 324 exceptionState.throwDOMException(SyntaxError, "The subprotocol '" +
encodeSubprotocolString(protocols[i]) + "' is invalid."); |
327 releaseChannel(); | 325 releaseChannel(); |
328 return; | 326 return; |
329 } | 327 } |
330 } | 328 } |
331 HashSet<String> visited; | 329 HashSet<String> visited; |
332 for (size_t i = 0; i < protocols.size(); ++i) { | 330 for (size_t i = 0; i < protocols.size(); ++i) { |
333 if (!visited.add(protocols[i]).isNewEntry) { | 331 if (!visited.add(protocols[i]).isNewEntry) { |
334 m_state = CLOSED; | 332 m_state = CLOSED; |
335 exceptionState.throwDOMException(SyntaxError, "The subprotocol '" +
encodeSubprotocolString(protocols[i]) + "' is duplicated."); | 333 exceptionState.throwDOMException(SyntaxError, "The subprotocol '" +
encodeSubprotocolString(protocols[i]) + "' is duplicated."); |
336 releaseChannel(); | 334 releaseChannel(); |
337 return; | 335 return; |
338 } | 336 } |
339 } | 337 } |
340 | 338 |
341 String protocolString; | 339 String protocolString; |
342 if (!protocols.isEmpty()) | 340 if (!protocols.isEmpty()) |
343 protocolString = joinStrings(protocols, subProtocolSeperator()); | 341 protocolString = joinStrings(protocols, subprotocolSeperator()); |
344 | 342 |
345 if (!m_channel->connect(m_url, protocolString)) { | 343 if (!m_channel->connect(m_url, protocolString)) { |
346 m_state = CLOSED; | 344 m_state = CLOSED; |
347 exceptionState.throwSecurityError("An insecure WebSocket connection may
not be initiated from a page loaded over HTTPS."); | 345 exceptionState.throwSecurityError("An insecure WebSocket connection may
not be initiated from a page loaded over HTTPS."); |
348 releaseChannel(); | 346 releaseChannel(); |
349 return; | 347 return; |
350 } | 348 } |
351 } | 349 } |
352 | 350 |
353 void WebSocket::handleSendResult(WebSocketChannel::SendResult result, ExceptionS
tate& exceptionState, WebSocketSendType dataType) | 351 void WebSocket::handleSendResult(WebSocketChannel::SendResult result, ExceptionS
tate& exceptionState, WebSocketSendType dataType) |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 } | 681 } |
684 | 682 |
685 void WebSocket::trace(Visitor* visitor) | 683 void WebSocket::trace(Visitor* visitor) |
686 { | 684 { |
687 visitor->trace(m_channel); | 685 visitor->trace(m_channel); |
688 visitor->trace(m_eventQueue); | 686 visitor->trace(m_eventQueue); |
689 EventTargetWithInlineData::trace(visitor); | 687 EventTargetWithInlineData::trace(visitor); |
690 } | 688 } |
691 | 689 |
692 } // namespace WebCore | 690 } // namespace WebCore |
OLD | NEW |