OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2012 Ericsson AB. All rights reserved. | 2 * Copyright (C) 2009, 2012 Ericsson AB. All rights reserved. |
3 * Copyright (C) 2010 Apple Inc. All rights reserved. | 3 * Copyright (C) 2010 Apple Inc. All rights reserved. |
4 * Copyright (C) 2011, Code Aurora Forum. All rights reserved. | 4 * Copyright (C) 2011, Code Aurora Forum. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * | 9 * |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 { | 274 { |
275 ASSERT(m_state == OPEN); | 275 ASSERT(m_state == OPEN); |
276 ASSERT(m_requestInFlight); | 276 ASSERT(m_requestInFlight); |
277 | 277 |
278 if (m_receiveBuf.size() > 0 || m_data.size() > 0) { | 278 if (m_receiveBuf.size() > 0 || m_data.size() > 0) { |
279 parseEventStream(); | 279 parseEventStream(); |
280 | 280 |
281 // Discard everything that has not been dispatched by now. | 281 // Discard everything that has not been dispatched by now. |
282 m_receiveBuf.clear(); | 282 m_receiveBuf.clear(); |
283 m_data.clear(); | 283 m_data.clear(); |
284 m_eventName = ""; | 284 m_eventName = emptyAtom; |
285 m_currentlyParsedEventId = String(); | 285 m_currentlyParsedEventId = nullAtom; |
286 } | 286 } |
287 networkRequestEnded(); | 287 networkRequestEnded(); |
288 } | 288 } |
289 | 289 |
290 void EventSource::didFail(const ResourceError& error) | 290 void EventSource::didFail(const ResourceError& error) |
291 { | 291 { |
292 ASSERT(m_state != CLOSED); | 292 ASSERT(m_state != CLOSED); |
293 ASSERT(m_requestInFlight); | 293 ASSERT(m_requestInFlight); |
294 | 294 |
295 if (error.isCancellation()) | 295 if (error.isCancellation()) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 else if (bufPos) | 369 else if (bufPos) |
370 m_receiveBuf.remove(0, bufPos); | 370 m_receiveBuf.remove(0, bufPos); |
371 } | 371 } |
372 | 372 |
373 void EventSource::parseEventStreamLine(unsigned bufPos, int fieldLength, int lin
eLength) | 373 void EventSource::parseEventStreamLine(unsigned bufPos, int fieldLength, int lin
eLength) |
374 { | 374 { |
375 if (!lineLength) { | 375 if (!lineLength) { |
376 if (!m_data.isEmpty()) { | 376 if (!m_data.isEmpty()) { |
377 m_data.removeLast(); | 377 m_data.removeLast(); |
378 if (!m_currentlyParsedEventId.isNull()) { | 378 if (!m_currentlyParsedEventId.isNull()) { |
379 m_lastEventId.swap(m_currentlyParsedEventId); | 379 m_lastEventId = m_currentlyParsedEventId; |
380 m_currentlyParsedEventId = String(); | 380 m_currentlyParsedEventId = nullAtom; |
381 } | 381 } |
382 dispatchEvent(createMessageEvent()); | 382 dispatchEvent(createMessageEvent()); |
383 } | 383 } |
384 if (!m_eventName.isEmpty()) | 384 if (!m_eventName.isEmpty()) |
385 m_eventName = ""; | 385 m_eventName = emptyAtom; |
386 } else if (fieldLength) { | 386 } else if (fieldLength) { |
387 bool noValue = fieldLength < 0; | 387 bool noValue = fieldLength < 0; |
388 | 388 |
389 String field(&m_receiveBuf[bufPos], noValue ? lineLength : fieldLength); | 389 String field(&m_receiveBuf[bufPos], noValue ? lineLength : fieldLength); |
390 int step; | 390 int step; |
391 if (noValue) | 391 if (noValue) |
392 step = lineLength; | 392 step = lineLength; |
393 else if (m_receiveBuf[bufPos + fieldLength + 1] != ' ') | 393 else if (m_receiveBuf[bufPos + fieldLength + 1] != ' ') |
394 step = fieldLength + 1; | 394 step = fieldLength + 1; |
395 else | 395 else |
396 step = fieldLength + 2; | 396 step = fieldLength + 2; |
397 bufPos += step; | 397 bufPos += step; |
398 int valueLength = lineLength - step; | 398 int valueLength = lineLength - step; |
399 | 399 |
400 if (field == "data") { | 400 if (field == "data") { |
401 if (valueLength) | 401 if (valueLength) |
402 m_data.append(&m_receiveBuf[bufPos], valueLength); | 402 m_data.append(&m_receiveBuf[bufPos], valueLength); |
403 m_data.append('\n'); | 403 m_data.append('\n'); |
404 } else if (field == "event") | 404 } else if (field == "event") { |
405 m_eventName = valueLength ? String(&m_receiveBuf[bufPos], valueLengt
h) : ""; | 405 m_eventName = valueLength ? AtomicString(&m_receiveBuf[bufPos], valu
eLength) : ""; |
406 else if (field == "id") | 406 } else if (field == "id") { |
407 m_currentlyParsedEventId = valueLength ? String(&m_receiveBuf[bufPos
], valueLength) : ""; | 407 m_currentlyParsedEventId = valueLength ? AtomicString(&m_receiveBuf[
bufPos], valueLength) : ""; |
408 else if (field == "retry") { | 408 } else if (field == "retry") { |
409 if (!valueLength) | 409 if (!valueLength) |
410 m_reconnectDelay = defaultReconnectDelay; | 410 m_reconnectDelay = defaultReconnectDelay; |
411 else { | 411 else { |
412 String value(&m_receiveBuf[bufPos], valueLength); | 412 String value(&m_receiveBuf[bufPos], valueLength); |
413 bool ok; | 413 bool ok; |
414 unsigned long long retry = value.toUInt64(&ok); | 414 unsigned long long retry = value.toUInt64(&ok); |
415 if (ok) | 415 if (ok) |
416 m_reconnectDelay = retry; | 416 m_reconnectDelay = retry; |
417 } | 417 } |
418 } | 418 } |
419 } | 419 } |
420 } | 420 } |
421 | 421 |
422 void EventSource::stop() | 422 void EventSource::stop() |
423 { | 423 { |
424 close(); | 424 close(); |
425 } | 425 } |
426 | 426 |
427 PassRefPtr<MessageEvent> EventSource::createMessageEvent() | 427 PassRefPtr<MessageEvent> EventSource::createMessageEvent() |
428 { | 428 { |
429 RefPtr<MessageEvent> event = MessageEvent::create(); | 429 RefPtr<MessageEvent> event = MessageEvent::create(); |
430 event->initMessageEvent(m_eventName.isEmpty() ? EventTypeNames::message : At
omicString(m_eventName), false, false, SerializedScriptValue::create(String(m_da
ta)), m_eventStreamOrigin, m_lastEventId, 0, nullptr); | 430 event->initMessageEvent(m_eventName.isEmpty() ? EventTypeNames::message : m_
eventName, false, false, SerializedScriptValue::create(String(m_data)), m_eventS
treamOrigin, m_lastEventId, 0, nullptr); |
431 m_data.clear(); | 431 m_data.clear(); |
432 return event.release(); | 432 return event.release(); |
433 } | 433 } |
434 | 434 |
435 } // namespace WebCore | 435 } // namespace WebCore |
OLD | NEW |