| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "platform/network/ResourceResponse.h" | 54 #include "platform/network/ResourceResponse.h" |
| 55 #include "platform/weborigin/SecurityOrigin.h" | 55 #include "platform/weborigin/SecurityOrigin.h" |
| 56 #include "public/platform/WebURLRequest.h" | 56 #include "public/platform/WebURLRequest.h" |
| 57 #include "wtf/text/StringBuilder.h" | 57 #include "wtf/text/StringBuilder.h" |
| 58 | 58 |
| 59 namespace blink { | 59 namespace blink { |
| 60 | 60 |
| 61 const unsigned long long EventSource::defaultReconnectDelay = 3000; | 61 const unsigned long long EventSource::defaultReconnectDelay = 3000; |
| 62 | 62 |
| 63 inline EventSource::EventSource(ExecutionContext* context, const KURL& url, cons
t EventSourceInit& eventSourceInit) | 63 inline EventSource::EventSource(ExecutionContext* context, const KURL& url, cons
t EventSourceInit& eventSourceInit) |
| 64 : ActiveDOMObject(context) | 64 : ContextLifecycleObserver(context) |
| 65 , m_url(url) | 65 , m_url(url) |
| 66 , m_withCredentials(eventSourceInit.withCredentials()) | 66 , m_withCredentials(eventSourceInit.withCredentials()) |
| 67 , m_state(CONNECTING) | 67 , m_state(CONNECTING) |
| 68 , m_connectTimer(this, &EventSource::connectTimerFired) | 68 , m_connectTimer(this, &EventSource::connectTimerFired) |
| 69 , m_reconnectDelay(defaultReconnectDelay) | 69 , m_reconnectDelay(defaultReconnectDelay) |
| 70 { | 70 { |
| 71 } | 71 } |
| 72 | 72 |
| 73 EventSource* EventSource::create(ExecutionContext* context, const String& url, c
onst EventSourceInit& eventSourceInit, ExceptionState& exceptionState) | 73 EventSource* EventSource::create(ExecutionContext* context, const String& url, c
onst EventSourceInit& eventSourceInit, ExceptionState& exceptionState) |
| 74 { | 74 { |
| 75 if (url.isEmpty()) { | 75 if (url.isEmpty()) { |
| 76 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc
e to an empty URL."); | 76 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc
e to an empty URL."); |
| 77 return nullptr; | 77 return nullptr; |
| 78 } | 78 } |
| 79 | 79 |
| 80 KURL fullURL = context->completeURL(url); | 80 KURL fullURL = context->completeURL(url); |
| 81 if (!fullURL.isValid()) { | 81 if (!fullURL.isValid()) { |
| 82 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc
e to '" + url + "'. The URL is invalid."); | 82 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc
e to '" + url + "'. The URL is invalid."); |
| 83 return nullptr; | 83 return nullptr; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. | 86 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. |
| 87 if (!ContentSecurityPolicy::shouldBypassMainWorld(context) && !context->cont
entSecurityPolicy()->allowConnectToSource(fullURL)) { | 87 if (!ContentSecurityPolicy::shouldBypassMainWorld(context) && !context->cont
entSecurityPolicy()->allowConnectToSource(fullURL)) { |
| 88 // We can safely expose the URL to JavaScript, as this exception is gene
rate synchronously before any redirects take place. | 88 // We can safely expose the URL to JavaScript, as this exception is gene
rate synchronously before any redirects take place. |
| 89 exceptionState.throwSecurityError("Refused to connect to '" + fullURL.el
idedString() + "' because it violates the document's Content Security Policy."); | 89 exceptionState.throwSecurityError("Refused to connect to '" + fullURL.el
idedString() + "' because it violates the document's Content Security Policy."); |
| 90 return nullptr; | 90 return nullptr; |
| 91 } | 91 } |
| 92 | 92 |
| 93 EventSource* source = new EventSource(context, fullURL, eventSourceInit); | 93 EventSource* source = new EventSource(context, fullURL, eventSourceInit); |
| 94 | |
| 95 source->scheduleInitialConnect(); | 94 source->scheduleInitialConnect(); |
| 96 source->suspendIfNeeded(); | |
| 97 return source; | 95 return source; |
| 98 } | 96 } |
| 99 | 97 |
| 100 EventSource::~EventSource() | 98 EventSource::~EventSource() |
| 101 { | 99 { |
| 102 ASSERT(m_state == CLOSED); | 100 ASSERT(m_state == CLOSED); |
| 103 ASSERT(!m_loader); | 101 ASSERT(!m_loader); |
| 104 } | 102 } |
| 105 | 103 |
| 106 void EventSource::scheduleInitialConnect() | 104 void EventSource::scheduleInitialConnect() |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 186 |
| 189 void EventSource::close() | 187 void EventSource::close() |
| 190 { | 188 { |
| 191 if (m_state == CLOSED) { | 189 if (m_state == CLOSED) { |
| 192 ASSERT(!m_loader); | 190 ASSERT(!m_loader); |
| 193 return; | 191 return; |
| 194 } | 192 } |
| 195 if (m_parser) | 193 if (m_parser) |
| 196 m_parser->stop(); | 194 m_parser->stop(); |
| 197 | 195 |
| 198 // Stop trying to reconnect if EventSource was explicitly closed or if Activ
eDOMObject::stop() was called. | 196 // Stop trying to reconnect if EventSource was explicitly closed |
| 197 // or if ContextLifecycleObserver::stop() was called. |
| 199 if (m_connectTimer.isActive()) { | 198 if (m_connectTimer.isActive()) { |
| 200 m_connectTimer.stop(); | 199 m_connectTimer.stop(); |
| 201 } | 200 } |
| 202 | 201 |
| 203 if (m_loader) { | 202 if (m_loader) { |
| 204 m_loader->cancel(); | 203 m_loader->cancel(); |
| 205 m_loader = nullptr; | 204 m_loader = nullptr; |
| 206 } | 205 } |
| 207 | 206 |
| 208 m_state = CLOSED; | 207 m_state = CLOSED; |
| 209 } | 208 } |
| 210 | 209 |
| 211 const AtomicString& EventSource::interfaceName() const | 210 const AtomicString& EventSource::interfaceName() const |
| 212 { | 211 { |
| 213 return EventTargetNames::EventSource; | 212 return EventTargetNames::EventSource; |
| 214 } | 213 } |
| 215 | 214 |
| 216 ExecutionContext* EventSource::executionContext() const | 215 ExecutionContext* EventSource::executionContext() const |
| 217 { | 216 { |
| 218 return ActiveDOMObject::executionContext(); | 217 return ContextLifecycleObserver::executionContext(); |
| 219 } | 218 } |
| 220 | 219 |
| 221 void EventSource::didReceiveResponse(unsigned long, const ResourceResponse& resp
onse, PassOwnPtr<WebDataConsumerHandle> handle) | 220 void EventSource::didReceiveResponse(unsigned long, const ResourceResponse& resp
onse, PassOwnPtr<WebDataConsumerHandle> handle) |
| 222 { | 221 { |
| 223 ASSERT_UNUSED(handle, !handle); | 222 ASSERT_UNUSED(handle, !handle); |
| 224 ASSERT(m_state == CONNECTING); | 223 ASSERT(m_state == CONNECTING); |
| 225 ASSERT(m_loader); | 224 ASSERT(m_loader); |
| 226 | 225 |
| 227 m_eventStreamOrigin = SecurityOrigin::create(response.url())->toString(); | 226 m_eventStreamOrigin = SecurityOrigin::create(response.url())->toString(); |
| 228 int statusCode = response.httpStatusCode(); | 227 int statusCode = response.httpStatusCode(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 { | 328 { |
| 330 ASSERT(m_state == CONNECTING); | 329 ASSERT(m_state == CONNECTING); |
| 331 | 330 |
| 332 m_loader = nullptr; | 331 m_loader = nullptr; |
| 333 m_state = CLOSED; | 332 m_state = CLOSED; |
| 334 networkRequestEnded(); | 333 networkRequestEnded(); |
| 335 | 334 |
| 336 dispatchEvent(Event::create(EventTypeNames::error)); | 335 dispatchEvent(Event::create(EventTypeNames::error)); |
| 337 } | 336 } |
| 338 | 337 |
| 339 void EventSource::stop() | 338 void EventSource::contextDestroyed() |
| 340 { | 339 { |
| 341 close(); | 340 close(); |
| 342 } | 341 } |
| 343 | 342 |
| 344 bool EventSource::hasPendingActivity() const | 343 bool EventSource::hasPendingActivity() const |
| 345 { | 344 { |
| 346 return m_state != CLOSED; | 345 return m_state != CLOSED; |
| 347 } | 346 } |
| 348 | 347 |
| 349 DEFINE_TRACE(EventSource) | 348 DEFINE_TRACE(EventSource) |
| 350 { | 349 { |
| 351 visitor->trace(m_parser); | 350 visitor->trace(m_parser); |
| 352 RefCountedGarbageCollectedEventTargetWithInlineData::trace(visitor); | 351 RefCountedGarbageCollectedEventTargetWithInlineData::trace(visitor); |
| 353 ActiveDOMObject::trace(visitor); | 352 ContextLifecycleObserver::trace(visitor); |
| 354 EventSourceParser::Client::trace(visitor); | 353 EventSourceParser::Client::trace(visitor); |
| 355 } | 354 } |
| 356 | 355 |
| 357 } // namespace blink | 356 } // namespace blink |
| OLD | NEW |