Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: Source/core/page/EventSource.cpp

Issue 561533002: Add EventSourceInit (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/page/EventSource.h ('k') | Source/core/page/EventSource.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33 #include "config.h" 33 #include "config.h"
34 #include "core/page/EventSource.h" 34 #include "core/page/EventSource.h"
35 35
36 #include "bindings/core/v8/Dictionary.h"
37 #include "bindings/core/v8/ExceptionState.h" 36 #include "bindings/core/v8/ExceptionState.h"
38 #include "bindings/core/v8/ScriptController.h" 37 #include "bindings/core/v8/ScriptController.h"
39 #include "bindings/core/v8/SerializedScriptValue.h" 38 #include "bindings/core/v8/SerializedScriptValue.h"
40 #include "core/dom/Document.h" 39 #include "core/dom/Document.h"
41 #include "core/dom/ExceptionCode.h" 40 #include "core/dom/ExceptionCode.h"
42 #include "core/dom/ExecutionContext.h" 41 #include "core/dom/ExecutionContext.h"
43 #include "core/events/Event.h" 42 #include "core/events/Event.h"
44 #include "core/events/MessageEvent.h" 43 #include "core/events/MessageEvent.h"
45 #include "core/frame/LocalDOMWindow.h" 44 #include "core/frame/LocalDOMWindow.h"
46 #include "core/frame/LocalFrame.h" 45 #include "core/frame/LocalFrame.h"
47 #include "core/frame/csp/ContentSecurityPolicy.h" 46 #include "core/frame/csp/ContentSecurityPolicy.h"
48 #include "core/html/parser/TextResourceDecoder.h" 47 #include "core/html/parser/TextResourceDecoder.h"
49 #include "core/inspector/ConsoleMessage.h" 48 #include "core/inspector/ConsoleMessage.h"
50 #include "core/loader/ThreadableLoader.h" 49 #include "core/loader/ThreadableLoader.h"
50 #include "core/page/EventSourceInit.h"
51 #include "platform/network/ResourceError.h" 51 #include "platform/network/ResourceError.h"
52 #include "platform/network/ResourceRequest.h" 52 #include "platform/network/ResourceRequest.h"
53 #include "platform/network/ResourceResponse.h" 53 #include "platform/network/ResourceResponse.h"
54 #include "platform/weborigin/SecurityOrigin.h" 54 #include "platform/weborigin/SecurityOrigin.h"
55 #include "public/platform/WebURLRequest.h" 55 #include "public/platform/WebURLRequest.h"
56 #include "wtf/text/StringBuilder.h" 56 #include "wtf/text/StringBuilder.h"
57 57
58 namespace blink { 58 namespace blink {
59 59
60 const unsigned long long EventSource::defaultReconnectDelay = 3000; 60 const unsigned long long EventSource::defaultReconnectDelay = 3000;
61 61
62 inline EventSource::EventSource(ExecutionContext* context, const KURL& url, cons t Dictionary& eventSourceInit) 62 inline EventSource::EventSource(ExecutionContext* context, const KURL& url, cons t EventSourceInit* eventSourceInit)
63 : ActiveDOMObject(context) 63 : ActiveDOMObject(context)
64 , m_url(url) 64 , m_url(url)
65 , m_withCredentials(false) 65 , m_withCredentials(eventSourceInit->withCredentials())
66 , m_state(CONNECTING) 66 , m_state(CONNECTING)
67 , m_decoder(TextResourceDecoder::create("text/plain", "UTF-8")) 67 , m_decoder(TextResourceDecoder::create("text/plain", "UTF-8"))
68 , m_connectTimer(this, &EventSource::connectTimerFired) 68 , m_connectTimer(this, &EventSource::connectTimerFired)
69 , m_discardTrailingNewline(false) 69 , m_discardTrailingNewline(false)
70 , m_requestInFlight(false) 70 , m_requestInFlight(false)
71 , m_reconnectDelay(defaultReconnectDelay) 71 , m_reconnectDelay(defaultReconnectDelay)
72 { 72 {
73 DictionaryHelper::get(eventSourceInit, "withCredentials", m_withCredentials) ;
74 } 73 }
75 74
76 PassRefPtrWillBeRawPtr<EventSource> EventSource::create(ExecutionContext* contex t, const String& url, const Dictionary& eventSourceInit, ExceptionState& excepti onState) 75 PassRefPtrWillBeRawPtr<EventSource> EventSource::create(ExecutionContext* contex t, const String& url, const EventSourceInit* eventSourceInit, ExceptionState& ex ceptionState)
77 { 76 {
78 if (url.isEmpty()) { 77 if (url.isEmpty()) {
79 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc e to an empty URL."); 78 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc e to an empty URL.");
80 return nullptr; 79 return nullptr;
81 } 80 }
82 81
83 KURL fullURL = context->completeURL(url); 82 KURL fullURL = context->completeURL(url);
84 if (!fullURL.isValid()) { 83 if (!fullURL.isValid()) {
85 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc e to '" + url + "'. The URL is invalid."); 84 exceptionState.throwDOMException(SyntaxError, "Cannot open an EventSourc e to '" + url + "'. The URL is invalid.");
86 return nullptr; 85 return nullptr;
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 431
433 PassRefPtrWillBeRawPtr<MessageEvent> EventSource::createMessageEvent() 432 PassRefPtrWillBeRawPtr<MessageEvent> EventSource::createMessageEvent()
434 { 433 {
435 RefPtrWillBeRawPtr<MessageEvent> event = MessageEvent::create(); 434 RefPtrWillBeRawPtr<MessageEvent> event = MessageEvent::create();
436 event->initMessageEvent(m_eventName.isEmpty() ? EventTypeNames::message : m_ eventName, false, false, SerializedScriptValue::create(String(m_data)), m_eventS treamOrigin, m_lastEventId, 0, nullptr); 435 event->initMessageEvent(m_eventName.isEmpty() ? EventTypeNames::message : m_ eventName, false, false, SerializedScriptValue::create(String(m_data)), m_eventS treamOrigin, m_lastEventId, 0, nullptr);
437 m_data.clear(); 436 m_data.clear();
438 return event.release(); 437 return event.release();
439 } 438 }
440 439
441 } // namespace blink 440 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/page/EventSource.h ('k') | Source/core/page/EventSource.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698