| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 , m_withCredentials(eventSourceInit.withCredentials()) | 67 , m_withCredentials(eventSourceInit.withCredentials()) |
| 68 , m_state(CONNECTING) | 68 , m_state(CONNECTING) |
| 69 , m_decoder(TextResourceDecoder::create("text/plain", "UTF-8")) | 69 , m_decoder(TextResourceDecoder::create("text/plain", "UTF-8")) |
| 70 , m_connectTimer(this, &EventSource::connectTimerFired) | 70 , m_connectTimer(this, &EventSource::connectTimerFired) |
| 71 , m_discardTrailingNewline(false) | 71 , m_discardTrailingNewline(false) |
| 72 , m_requestInFlight(false) | 72 , m_requestInFlight(false) |
| 73 , m_reconnectDelay(defaultReconnectDelay) | 73 , m_reconnectDelay(defaultReconnectDelay) |
| 74 { | 74 { |
| 75 } | 75 } |
| 76 | 76 |
| 77 PassRefPtrWillBeRawPtr<EventSource> EventSource::create(ExecutionContext* contex
t, const String& url, const EventSourceInit& eventSourceInit, ExceptionState& ex
ceptionState) | 77 EventSource* EventSource::create(ExecutionContext* context, const String& url, c
onst EventSourceInit& eventSourceInit, ExceptionState& exceptionState) |
| 78 { | 78 { |
| 79 if (url.isEmpty()) { | 79 if (url.isEmpty()) { |
| 80 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc
e to an empty URL."); | 80 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc
e to an empty URL."); |
| 81 return nullptr; | 81 return nullptr; |
| 82 } | 82 } |
| 83 | 83 |
| 84 KURL fullURL = context->completeURL(url); | 84 KURL fullURL = context->completeURL(url); |
| 85 if (!fullURL.isValid()) { | 85 if (!fullURL.isValid()) { |
| 86 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc
e to '" + url + "'. The URL is invalid."); | 86 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc
e to '" + url + "'. The URL is invalid."); |
| 87 return nullptr; | 87 return nullptr; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. | 90 // FIXME: Convert this to check the isolated world's Content Security Policy
once webkit.org/b/104520 is solved. |
| 91 if (!ContentSecurityPolicy::shouldBypassMainWorld(context) && !context->cont
entSecurityPolicy()->allowConnectToSource(fullURL)) { | 91 if (!ContentSecurityPolicy::shouldBypassMainWorld(context) && !context->cont
entSecurityPolicy()->allowConnectToSource(fullURL)) { |
| 92 // We can safely expose the URL to JavaScript, as this exception is gene
rate synchronously before any redirects take place. | 92 // We can safely expose the URL to JavaScript, as this exception is gene
rate synchronously before any redirects take place. |
| 93 exceptionState.throwSecurityError("Refused to connect to '" + fullURL.el
idedString() + "' because it violates the document's Content Security Policy."); | 93 exceptionState.throwSecurityError("Refused to connect to '" + fullURL.el
idedString() + "' because it violates the document's Content Security Policy."); |
| 94 return nullptr; | 94 return nullptr; |
| 95 } | 95 } |
| 96 | 96 |
| 97 RefPtrWillBeRawPtr<EventSource> source = adoptRefWillBeNoop(new EventSource(
context, fullURL, eventSourceInit)); | 97 EventSource* source = new EventSource(context, fullURL, eventSourceInit); |
| 98 | 98 |
| 99 source->scheduleInitialConnect(); | 99 source->scheduleInitialConnect(); |
| 100 source->suspendIfNeeded(); | 100 source->suspendIfNeeded(); |
| 101 | 101 return source; |
| 102 return source.release(); | |
| 103 } | 102 } |
| 104 | 103 |
| 105 EventSource::~EventSource() | 104 EventSource::~EventSource() |
| 106 { | 105 { |
| 107 ASSERT(m_state == CLOSED); | 106 ASSERT(m_state == CLOSED); |
| 108 ASSERT(!m_requestInFlight); | 107 ASSERT(!m_requestInFlight); |
| 109 } | 108 } |
| 110 | 109 |
| 111 void EventSource::scheduleInitialConnect() | 110 void EventSource::scheduleInitialConnect() |
| 112 { | 111 { |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 if (ok) | 416 if (ok) |
| 418 m_reconnectDelay = retry; | 417 m_reconnectDelay = retry; |
| 419 } | 418 } |
| 420 } | 419 } |
| 421 } | 420 } |
| 422 } | 421 } |
| 423 | 422 |
| 424 void EventSource::stop() | 423 void EventSource::stop() |
| 425 { | 424 { |
| 426 close(); | 425 close(); |
| 426 |
| 427 // (Non)Oilpan: In order to make Worker shutdowns clean, |
| 428 // deref the loader. This will in turn deref its |
| 429 // RefPtr<WorkerGlobalScope>. |
| 430 // |
| 431 // Worth doing regardless, it is no longer of use. |
| 432 m_loader = nullptr; |
| 427 } | 433 } |
| 428 | 434 |
| 429 bool EventSource::hasPendingActivity() const | 435 bool EventSource::hasPendingActivity() const |
| 430 { | 436 { |
| 431 return m_state != CLOSED; | 437 return m_state != CLOSED; |
| 432 } | 438 } |
| 433 | 439 |
| 434 PassRefPtrWillBeRawPtr<MessageEvent> EventSource::createMessageEvent() | 440 PassRefPtrWillBeRawPtr<MessageEvent> EventSource::createMessageEvent() |
| 435 { | 441 { |
| 436 RefPtrWillBeRawPtr<MessageEvent> event = MessageEvent::create(); | 442 RefPtrWillBeRawPtr<MessageEvent> event = MessageEvent::create(); |
| 437 event->initMessageEvent(m_eventName.isEmpty() ? EventTypeNames::message : m_
eventName, false, false, SerializedScriptValueFactory::instance().create(String(
m_data)), m_eventStreamOrigin, m_lastEventId, 0, nullptr); | 443 event->initMessageEvent(m_eventName.isEmpty() ? EventTypeNames::message : m_
eventName, false, false, SerializedScriptValueFactory::instance().create(String(
m_data)), m_eventStreamOrigin, m_lastEventId, 0, nullptr); |
| 438 m_data.clear(); | 444 m_data.clear(); |
| 439 return event.release(); | 445 return event.release(); |
| 440 } | 446 } |
| 441 | 447 |
| 442 DEFINE_TRACE(EventSource) | 448 DEFINE_TRACE(EventSource) |
| 443 { | 449 { |
| 444 EventTargetWithInlineData::trace(visitor); | 450 RefCountedGarbageCollectedEventTargetWithInlineData::trace(visitor); |
| 445 ActiveDOMObject::trace(visitor); | 451 ActiveDOMObject::trace(visitor); |
| 446 } | 452 } |
| 447 | 453 |
| 448 } // namespace blink | 454 } // namespace blink |
| OLD | NEW |