| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "wtf/text/StringBuilder.h" | 58 #include "wtf/text/StringBuilder.h" |
| 59 #include <memory> | 59 #include <memory> |
| 60 | 60 |
| 61 namespace blink { | 61 namespace blink { |
| 62 | 62 |
| 63 const unsigned long long EventSource::defaultReconnectDelay = 3000; | 63 const unsigned long long EventSource::defaultReconnectDelay = 3000; |
| 64 | 64 |
| 65 inline EventSource::EventSource(ExecutionContext* context, | 65 inline EventSource::EventSource(ExecutionContext* context, |
| 66 const KURL& url, | 66 const KURL& url, |
| 67 const EventSourceInit& eventSourceInit) | 67 const EventSourceInit& eventSourceInit) |
| 68 : SuspendableObject(context), | 68 : ContextLifecycleObserver(context), |
| 69 m_url(url), | 69 m_url(url), |
| 70 m_currentURL(url), | 70 m_currentURL(url), |
| 71 m_withCredentials(eventSourceInit.withCredentials()), | 71 m_withCredentials(eventSourceInit.withCredentials()), |
| 72 m_state(kConnecting), | 72 m_state(kConnecting), |
| 73 m_connectTimer(this, &EventSource::connectTimerFired), | 73 m_connectTimer(this, &EventSource::connectTimerFired), |
| 74 m_reconnectDelay(defaultReconnectDelay) {} | 74 m_reconnectDelay(defaultReconnectDelay) {} |
| 75 | 75 |
| 76 EventSource* EventSource::create(ExecutionContext* context, | 76 EventSource* EventSource::create(ExecutionContext* context, |
| 77 const String& url, | 77 const String& url, |
| 78 const EventSourceInit& eventSourceInit, | 78 const EventSourceInit& eventSourceInit, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 104 // synchronously before any redirects take place. | 104 // synchronously before any redirects take place. |
| 105 exceptionState.throwSecurityError( | 105 exceptionState.throwSecurityError( |
| 106 "Refused to connect to '" + fullURL.elidedString() + | 106 "Refused to connect to '" + fullURL.elidedString() + |
| 107 "' because it violates the document's Content Security Policy."); | 107 "' because it violates the document's Content Security Policy."); |
| 108 return nullptr; | 108 return nullptr; |
| 109 } | 109 } |
| 110 | 110 |
| 111 EventSource* source = new EventSource(context, fullURL, eventSourceInit); | 111 EventSource* source = new EventSource(context, fullURL, eventSourceInit); |
| 112 | 112 |
| 113 source->scheduleInitialConnect(); | 113 source->scheduleInitialConnect(); |
| 114 source->suspendIfNeeded(); | |
| 115 return source; | 114 return source; |
| 116 } | 115 } |
| 117 | 116 |
| 118 EventSource::~EventSource() { | 117 EventSource::~EventSource() { |
| 119 DCHECK_EQ(kClosed, m_state); | 118 DCHECK_EQ(kClosed, m_state); |
| 120 DCHECK(!m_loader); | 119 DCHECK(!m_loader); |
| 121 } | 120 } |
| 122 | 121 |
| 123 void EventSource::scheduleInitialConnect() { | 122 void EventSource::scheduleInitialConnect() { |
| 124 DCHECK_EQ(kConnecting, m_state); | 123 DCHECK_EQ(kConnecting, m_state); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 214 |
| 216 void EventSource::close() { | 215 void EventSource::close() { |
| 217 if (m_state == kClosed) { | 216 if (m_state == kClosed) { |
| 218 DCHECK(!m_loader); | 217 DCHECK(!m_loader); |
| 219 return; | 218 return; |
| 220 } | 219 } |
| 221 if (m_parser) | 220 if (m_parser) |
| 222 m_parser->stop(); | 221 m_parser->stop(); |
| 223 | 222 |
| 224 // Stop trying to reconnect if EventSource was explicitly closed or if | 223 // Stop trying to reconnect if EventSource was explicitly closed or if |
| 225 // SuspendableObject::stop() was called. | 224 // contextDestroyed() was called. |
| 226 if (m_connectTimer.isActive()) { | 225 if (m_connectTimer.isActive()) { |
| 227 m_connectTimer.stop(); | 226 m_connectTimer.stop(); |
| 228 } | 227 } |
| 229 | 228 |
| 230 if (m_loader) { | 229 if (m_loader) { |
| 231 m_loader->cancel(); | 230 m_loader->cancel(); |
| 232 m_loader = nullptr; | 231 m_loader = nullptr; |
| 233 } | 232 } |
| 234 | 233 |
| 235 m_state = kClosed; | 234 m_state = kClosed; |
| 236 } | 235 } |
| 237 | 236 |
| 238 const AtomicString& EventSource::interfaceName() const { | 237 const AtomicString& EventSource::interfaceName() const { |
| 239 return EventTargetNames::EventSource; | 238 return EventTargetNames::EventSource; |
| 240 } | 239 } |
| 241 | 240 |
| 242 ExecutionContext* EventSource::getExecutionContext() const { | 241 ExecutionContext* EventSource::getExecutionContext() const { |
| 243 return SuspendableObject::getExecutionContext(); | 242 return ContextLifecycleObserver::getExecutionContext(); |
| 244 } | 243 } |
| 245 | 244 |
| 246 void EventSource::didReceiveResponse( | 245 void EventSource::didReceiveResponse( |
| 247 unsigned long, | 246 unsigned long, |
| 248 const ResourceResponse& response, | 247 const ResourceResponse& response, |
| 249 std::unique_ptr<WebDataConsumerHandle> handle) { | 248 std::unique_ptr<WebDataConsumerHandle> handle) { |
| 250 DCHECK(!handle); | 249 DCHECK(!handle); |
| 251 DCHECK_EQ(kConnecting, m_state); | 250 DCHECK_EQ(kConnecting, m_state); |
| 252 DCHECK(m_loader); | 251 DCHECK(m_loader); |
| 253 | 252 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 371 } |
| 373 | 372 |
| 374 bool EventSource::hasPendingActivity() const { | 373 bool EventSource::hasPendingActivity() const { |
| 375 return m_state != kClosed; | 374 return m_state != kClosed; |
| 376 } | 375 } |
| 377 | 376 |
| 378 DEFINE_TRACE(EventSource) { | 377 DEFINE_TRACE(EventSource) { |
| 379 visitor->trace(m_parser); | 378 visitor->trace(m_parser); |
| 380 visitor->trace(m_loader); | 379 visitor->trace(m_loader); |
| 381 EventTargetWithInlineData::trace(visitor); | 380 EventTargetWithInlineData::trace(visitor); |
| 382 SuspendableObject::trace(visitor); | 381 ContextLifecycleObserver::trace(visitor); |
| 383 EventSourceParser::Client::trace(visitor); | 382 EventSourceParser::Client::trace(visitor); |
| 384 } | 383 } |
| 385 | 384 |
| 386 } // namespace blink | 385 } // namespace blink |
| OLD | NEW |