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

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

Issue 1808533003: Revert of Reduce ActiveDOMObjects from core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 : ContextLifecycleObserver(context) 64 : ActiveDOMObject(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
94 source->scheduleInitialConnect(); 95 source->scheduleInitialConnect();
96 source->suspendIfNeeded();
95 return source; 97 return source;
96 } 98 }
97 99
98 EventSource::~EventSource() 100 EventSource::~EventSource()
99 { 101 {
100 ASSERT(m_state == CLOSED); 102 ASSERT(m_state == CLOSED);
101 ASSERT(!m_loader); 103 ASSERT(!m_loader);
102 } 104 }
103 105
104 void EventSource::scheduleInitialConnect() 106 void EventSource::scheduleInitialConnect()
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 188
187 void EventSource::close() 189 void EventSource::close()
188 { 190 {
189 if (m_state == CLOSED) { 191 if (m_state == CLOSED) {
190 ASSERT(!m_loader); 192 ASSERT(!m_loader);
191 return; 193 return;
192 } 194 }
193 if (m_parser) 195 if (m_parser)
194 m_parser->stop(); 196 m_parser->stop();
195 197
196 // Stop trying to reconnect if EventSource was explicitly closed 198 // Stop trying to reconnect if EventSource was explicitly closed or if Activ eDOMObject::stop() was called.
197 // or if ContextLifecycleObserver::stop() was called.
198 if (m_connectTimer.isActive()) { 199 if (m_connectTimer.isActive()) {
199 m_connectTimer.stop(); 200 m_connectTimer.stop();
200 } 201 }
201 202
202 if (m_loader) { 203 if (m_loader) {
203 m_loader->cancel(); 204 m_loader->cancel();
204 m_loader = nullptr; 205 m_loader = nullptr;
205 } 206 }
206 207
207 m_state = CLOSED; 208 m_state = CLOSED;
208 } 209 }
209 210
210 const AtomicString& EventSource::interfaceName() const 211 const AtomicString& EventSource::interfaceName() const
211 { 212 {
212 return EventTargetNames::EventSource; 213 return EventTargetNames::EventSource;
213 } 214 }
214 215
215 ExecutionContext* EventSource::executionContext() const 216 ExecutionContext* EventSource::executionContext() const
216 { 217 {
217 return ContextLifecycleObserver::executionContext(); 218 return ActiveDOMObject::executionContext();
218 } 219 }
219 220
220 void EventSource::didReceiveResponse(unsigned long, const ResourceResponse& resp onse, PassOwnPtr<WebDataConsumerHandle> handle) 221 void EventSource::didReceiveResponse(unsigned long, const ResourceResponse& resp onse, PassOwnPtr<WebDataConsumerHandle> handle)
221 { 222 {
222 ASSERT_UNUSED(handle, !handle); 223 ASSERT_UNUSED(handle, !handle);
223 ASSERT(m_state == CONNECTING); 224 ASSERT(m_state == CONNECTING);
224 ASSERT(m_loader); 225 ASSERT(m_loader);
225 226
226 m_eventStreamOrigin = SecurityOrigin::create(response.url())->toString(); 227 m_eventStreamOrigin = SecurityOrigin::create(response.url())->toString();
227 int statusCode = response.httpStatusCode(); 228 int statusCode = response.httpStatusCode();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 { 329 {
329 ASSERT(m_state == CONNECTING); 330 ASSERT(m_state == CONNECTING);
330 331
331 m_loader = nullptr; 332 m_loader = nullptr;
332 m_state = CLOSED; 333 m_state = CLOSED;
333 networkRequestEnded(); 334 networkRequestEnded();
334 335
335 dispatchEvent(Event::create(EventTypeNames::error)); 336 dispatchEvent(Event::create(EventTypeNames::error));
336 } 337 }
337 338
338 void EventSource::contextDestroyed() 339 void EventSource::stop()
339 { 340 {
340 close(); 341 close();
341 } 342 }
342 343
343 bool EventSource::hasPendingActivity() const 344 bool EventSource::hasPendingActivity() const
344 { 345 {
345 return m_state != CLOSED; 346 return m_state != CLOSED;
346 } 347 }
347 348
348 DEFINE_TRACE(EventSource) 349 DEFINE_TRACE(EventSource)
349 { 350 {
350 visitor->trace(m_parser); 351 visitor->trace(m_parser);
351 RefCountedGarbageCollectedEventTargetWithInlineData::trace(visitor); 352 RefCountedGarbageCollectedEventTargetWithInlineData::trace(visitor);
352 ContextLifecycleObserver::trace(visitor); 353 ActiveDOMObject::trace(visitor);
353 EventSourceParser::Client::trace(visitor); 354 EventSourceParser::Client::trace(visitor);
354 } 355 }
355 356
356 } // namespace blink 357 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/page/EventSource.h ('k') | third_party/WebKit/Source/core/streams/ReadableStreamReader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698