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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #include "wtf/ArrayBuffer.h" | 55 #include "wtf/ArrayBuffer.h" |
56 #include "wtf/ArrayBufferView.h" | 56 #include "wtf/ArrayBufferView.h" |
57 #include "wtf/Assertions.h" | 57 #include "wtf/Assertions.h" |
58 #include "wtf/HashSet.h" | 58 #include "wtf/HashSet.h" |
59 #include "wtf/PassOwnPtr.h" | 59 #include "wtf/PassOwnPtr.h" |
60 #include "wtf/StdLibExtras.h" | 60 #include "wtf/StdLibExtras.h" |
61 #include "wtf/text/CString.h" | 61 #include "wtf/text/CString.h" |
62 #include "wtf/text/StringBuilder.h" | 62 #include "wtf/text/StringBuilder.h" |
63 #include "wtf/text/WTFString.h" | 63 #include "wtf/text/WTFString.h" |
64 | 64 |
65 using namespace std; | |
66 | |
67 namespace WebCore { | 65 namespace WebCore { |
68 | 66 |
69 WebSocket::EventQueue::EventQueue(EventTarget* target) | 67 WebSocket::EventQueue::EventQueue(EventTarget* target) |
70 : m_state(Active) | 68 : m_state(Active) |
71 , m_target(target) | 69 , m_target(target) |
72 , m_resumeTimer(this, &EventQueue::resumeTimerFired) { } | 70 , m_resumeTimer(this, &EventQueue::resumeTimerFired) { } |
73 | 71 |
74 WebSocket::EventQueue::~EventQueue() { stop(); } | 72 WebSocket::EventQueue::~EventQueue() { stop(); } |
75 | 73 |
76 void WebSocket::EventQueue::dispatch(PassRefPtrWillBeRawPtr<Event> event) | 74 void WebSocket::EventQueue::dispatch(PassRefPtrWillBeRawPtr<Event> event) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 const UChar maximumProtocolCharacter = '~'; // U+007E. | 164 const UChar maximumProtocolCharacter = '~'; // U+007E. |
167 // Set to true if character does not matches "separators" ABNF defined in | 165 // Set to true if character does not matches "separators" ABNF defined in |
168 // RFC2616. SP and HT are excluded since the range check excludes them. | 166 // RFC2616. SP and HT are excluded since the range check excludes them. |
169 bool isNotSeparator = character != '"' && character != '(' && character != '
)' && character != ',' && character != '/' | 167 bool isNotSeparator = character != '"' && character != '(' && character != '
)' && character != ',' && character != '/' |
170 && !(character >= ':' && character <= '@') // U+003A - U+0040 (':', ';',
'<', '=', '>', '?', '@'). | 168 && !(character >= ':' && character <= '@') // U+003A - U+0040 (':', ';',
'<', '=', '>', '?', '@'). |
171 && !(character >= '[' && character <= ']') // U+005B - U+005D ('[', '\\'
, ']'). | 169 && !(character >= '[' && character <= ']') // U+005B - U+005D ('[', '\\'
, ']'). |
172 && character != '{' && character != '}'; | 170 && character != '{' && character != '}'; |
173 return character >= minimumProtocolCharacter && character <= maximumProtocol
Character && isNotSeparator; | 171 return character >= minimumProtocolCharacter && character <= maximumProtocol
Character && isNotSeparator; |
174 } | 172 } |
175 | 173 |
176 static bool isValidSubprotocolString(const String& protocol) | 174 bool WebSocket::isValidSubprotocolString(const String& protocol) |
177 { | 175 { |
178 if (protocol.isEmpty()) | 176 if (protocol.isEmpty()) |
179 return false; | 177 return false; |
180 for (size_t i = 0; i < protocol.length(); ++i) { | 178 for (size_t i = 0; i < protocol.length(); ++i) { |
181 if (!isValidSubprotocolCharacter(protocol[i])) | 179 if (!isValidSubprotocolCharacter(protocol[i])) |
182 return false; | 180 return false; |
183 } | 181 } |
184 return true; | 182 return true; |
185 } | 183 } |
186 | 184 |
(...skipping 17 matching lines...) Expand all Loading... |
204 for (size_t i = 0; i < strings.size(); ++i) { | 202 for (size_t i = 0; i < strings.size(); ++i) { |
205 if (i) | 203 if (i) |
206 builder.append(separator); | 204 builder.append(separator); |
207 builder.append(strings[i]); | 205 builder.append(strings[i]); |
208 } | 206 } |
209 return builder.toString(); | 207 return builder.toString(); |
210 } | 208 } |
211 | 209 |
212 static unsigned long saturateAdd(unsigned long a, unsigned long b) | 210 static unsigned long saturateAdd(unsigned long a, unsigned long b) |
213 { | 211 { |
214 if (numeric_limits<unsigned long>::max() - a < b) | 212 if (std::numeric_limits<unsigned long>::max() - a < b) |
215 return numeric_limits<unsigned long>::max(); | 213 return std::numeric_limits<unsigned long>::max(); |
216 return a + b; | 214 return a + b; |
217 } | 215 } |
218 | 216 |
219 static void setInvalidStateErrorForSendMethod(ExceptionState& exceptionState) | 217 static void setInvalidStateErrorForSendMethod(ExceptionState& exceptionState) |
220 { | 218 { |
221 exceptionState.throwDOMException(InvalidStateError, "Still in CONNECTING sta
te."); | 219 exceptionState.throwDOMException(InvalidStateError, "Still in CONNECTING sta
te."); |
222 } | 220 } |
223 | 221 |
224 const char* WebSocket::subProtocolSeperator() | 222 const char* WebSocket::subProtocolSeperator() |
225 { | 223 { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 Document* document = toDocument(executionContext()); | 310 Document* document = toDocument(executionContext()); |
313 shouldBypassMainWorldContentSecurityPolicy = document->frame()->script()
.shouldBypassMainWorldContentSecurityPolicy(); | 311 shouldBypassMainWorldContentSecurityPolicy = document->frame()->script()
.shouldBypassMainWorldContentSecurityPolicy(); |
314 } | 312 } |
315 if (!shouldBypassMainWorldContentSecurityPolicy && !executionContext()->cont
entSecurityPolicy()->allowConnectToSource(m_url)) { | 313 if (!shouldBypassMainWorldContentSecurityPolicy && !executionContext()->cont
entSecurityPolicy()->allowConnectToSource(m_url)) { |
316 m_state = CLOSED; | 314 m_state = CLOSED; |
317 // The URL is safe to expose to JavaScript, as this check happens synchr
onously before redirection. | 315 // The URL is safe to expose to JavaScript, as this check happens synchr
onously before redirection. |
318 exceptionState.throwSecurityError("Refused to connect to '" + m_url.elid
edString() + "' because it violates the document's Content Security Policy."); | 316 exceptionState.throwSecurityError("Refused to connect to '" + m_url.elid
edString() + "' because it violates the document's Content Security Policy."); |
319 return; | 317 return; |
320 } | 318 } |
321 | 319 |
322 m_channel = WebSocketChannel::create(executionContext(), this); | 320 m_channel = createChannel(executionContext(), this); |
323 | 321 |
324 for (size_t i = 0; i < protocols.size(); ++i) { | 322 for (size_t i = 0; i < protocols.size(); ++i) { |
325 if (!isValidSubprotocolString(protocols[i])) { | 323 if (!isValidSubprotocolString(protocols[i])) { |
326 m_state = CLOSED; | 324 m_state = CLOSED; |
327 exceptionState.throwDOMException(SyntaxError, "The subprotocol '" +
encodeSubprotocolString(protocols[i]) + "' is invalid."); | 325 exceptionState.throwDOMException(SyntaxError, "The subprotocol '" +
encodeSubprotocolString(protocols[i]) + "' is invalid."); |
328 releaseChannel(); | 326 releaseChannel(); |
329 return; | 327 return; |
330 } | 328 } |
331 } | 329 } |
332 HashSet<String> visited; | 330 HashSet<String> visited; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 return overhead; | 681 return overhead; |
684 } | 682 } |
685 | 683 |
686 void WebSocket::trace(Visitor* visitor) | 684 void WebSocket::trace(Visitor* visitor) |
687 { | 685 { |
688 visitor->trace(m_channel); | 686 visitor->trace(m_channel); |
689 visitor->trace(m_eventQueue); | 687 visitor->trace(m_eventQueue); |
690 } | 688 } |
691 | 689 |
692 } // namespace WebCore | 690 } // namespace WebCore |
OLD | NEW |