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

Side by Side Diff: third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp

Issue 1773813007: blink: Rename modules/ method to prefix with get when they collide. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clash-modules: rebase-fixes 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) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org>
4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org>
5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved.
6 * Copyright (C) 2012 Intel Corporation 6 * Copyright (C) 2012 Intel Corporation
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 DEFINE_INLINE_TRACE() 168 DEFINE_INLINE_TRACE()
169 { 169 {
170 visitor->trace(m_xhr); 170 visitor->trace(m_xhr);
171 } 171 }
172 172
173 private: 173 private:
174 BlobLoader(XMLHttpRequest* xhr, PassRefPtr<BlobDataHandle> handle) 174 BlobLoader(XMLHttpRequest* xhr, PassRefPtr<BlobDataHandle> handle)
175 : m_xhr(xhr) 175 : m_xhr(xhr)
176 , m_loader(FileReaderLoader::ReadByClient, this) 176 , m_loader(FileReaderLoader::ReadByClient, this)
177 { 177 {
178 m_loader.start(m_xhr->executionContext(), handle); 178 m_loader.start(m_xhr->getExecutionContext(), handle);
179 } 179 }
180 180
181 Member<XMLHttpRequest> m_xhr; 181 Member<XMLHttpRequest> m_xhr;
182 FileReaderLoader m_loader; 182 FileReaderLoader m_loader;
183 }; 183 };
184 184
185 XMLHttpRequest* XMLHttpRequest::create(ScriptState* scriptState) 185 XMLHttpRequest* XMLHttpRequest::create(ScriptState* scriptState)
186 { 186 {
187 ExecutionContext* context = scriptState->executionContext(); 187 ExecutionContext* context = scriptState->getExecutionContext();
188 DOMWrapperWorld& world = scriptState->world(); 188 DOMWrapperWorld& world = scriptState->world();
189 RefPtr<SecurityOrigin> isolatedWorldSecurityOrigin = world.isIsolatedWorld() ? world.isolatedWorldSecurityOrigin() : nullptr; 189 RefPtr<SecurityOrigin> isolatedWorldSecurityOrigin = world.isIsolatedWorld() ? world.isolatedWorldSecurityOrigin() : nullptr;
190 XMLHttpRequest* xmlHttpRequest = new XMLHttpRequest(context, isolatedWorldSe curityOrigin); 190 XMLHttpRequest* xmlHttpRequest = new XMLHttpRequest(context, isolatedWorldSe curityOrigin);
191 xmlHttpRequest->suspendIfNeeded(); 191 xmlHttpRequest->suspendIfNeeded();
192 192
193 return xmlHttpRequest; 193 return xmlHttpRequest;
194 } 194 }
195 195
196 XMLHttpRequest* XMLHttpRequest::create(ExecutionContext* context) 196 XMLHttpRequest* XMLHttpRequest::create(ExecutionContext* context)
197 { 197 {
(...skipping 30 matching lines...) Expand all
228 ASSERT(IS_EAGERLY_FINALIZED()); 228 ASSERT(IS_EAGERLY_FINALIZED());
229 #endif 229 #endif
230 } 230 }
231 231
232 XMLHttpRequest::~XMLHttpRequest() 232 XMLHttpRequest::~XMLHttpRequest()
233 { 233 {
234 } 234 }
235 235
236 Document* XMLHttpRequest::document() const 236 Document* XMLHttpRequest::document() const
237 { 237 {
238 ASSERT(executionContext()->isDocument()); 238 ASSERT(getExecutionContext()->isDocument());
239 return toDocument(executionContext()); 239 return toDocument(getExecutionContext());
240 } 240 }
241 241
242 SecurityOrigin* XMLHttpRequest::securityOrigin() const 242 SecurityOrigin* XMLHttpRequest::getSecurityOrigin() const
243 { 243 {
244 return m_isolatedWorldSecurityOrigin ? m_isolatedWorldSecurityOrigin.get() : executionContext()->securityOrigin(); 244 return m_isolatedWorldSecurityOrigin ? m_isolatedWorldSecurityOrigin.get() : getExecutionContext()->getSecurityOrigin();
245 } 245 }
246 246
247 XMLHttpRequest::State XMLHttpRequest::readyState() const 247 XMLHttpRequest::State XMLHttpRequest::readyState() const
248 { 248 {
249 return m_state; 249 return m_state;
250 } 250 }
251 251
252 ScriptString XMLHttpRequest::responseText(ExceptionState& exceptionState) 252 ScriptString XMLHttpRequest::responseText(ExceptionState& exceptionState)
253 { 253 {
254 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo nseTypeText) { 254 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo nseTypeText) {
(...skipping 14 matching lines...) Expand all
269 return m_responseText; 269 return m_responseText;
270 } 270 }
271 271
272 void XMLHttpRequest::initResponseDocument() 272 void XMLHttpRequest::initResponseDocument()
273 { 273 {
274 // The W3C spec requires the final MIME type to be some valid XML type, or t ext/html. 274 // The W3C spec requires the final MIME type to be some valid XML type, or t ext/html.
275 // If it is text/html, then the responseType of "document" must have been su pplied explicitly. 275 // If it is text/html, then the responseType of "document" must have been su pplied explicitly.
276 bool isHTML = responseIsHTML(); 276 bool isHTML = responseIsHTML();
277 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) 277 if ((m_response.isHTTP() && !responseIsXML() && !isHTML)
278 || (isHTML && m_responseTypeCode == ResponseTypeDefault) 278 || (isHTML && m_responseTypeCode == ResponseTypeDefault)
279 || executionContext()->isWorkerGlobalScope()) { 279 || getExecutionContext()->isWorkerGlobalScope()) {
280 m_responseDocument = nullptr; 280 m_responseDocument = nullptr;
281 return; 281 return;
282 } 282 }
283 283
284 DocumentInit init = DocumentInit::fromContext(document()->contextDocument(), m_url); 284 DocumentInit init = DocumentInit::fromContext(document()->contextDocument(), m_url);
285 if (isHTML) 285 if (isHTML)
286 m_responseDocument = HTMLDocument::create(init); 286 m_responseDocument = HTMLDocument::create(init);
287 else 287 else
288 m_responseDocument = XMLDocument::create(init); 288 m_responseDocument = XMLDocument::create(init);
289 289
290 // FIXME: Set Last-Modified. 290 // FIXME: Set Last-Modified.
291 m_responseDocument->setSecurityOrigin(securityOrigin()); 291 m_responseDocument->setSecurityOrigin(getSecurityOrigin());
292 m_responseDocument->setContextFeatures(document()->contextFeatures()); 292 m_responseDocument->setContextFeatures(document()->contextFeatures());
293 m_responseDocument->setMimeType(finalResponseMIMETypeWithFallback()); 293 m_responseDocument->setMimeType(finalResponseMIMETypeWithFallback());
294 } 294 }
295 295
296 Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState) 296 Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState)
297 { 297 {
298 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo nseTypeDocument) { 298 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo nseTypeDocument) {
299 exceptionState.throwDOMException(InvalidStateError, "The value is only a ccessible if the object's 'responseType' is '' or 'document' (was '" + responseT ype() + "')."); 299 exceptionState.throwDOMException(InvalidStateError, "The value is only a ccessible if the object's 'responseType' is '' or 'document' (was '" + responseT ype() + "').");
300 return nullptr; 300 return nullptr;
301 } 301 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (m_error || (m_state != LOADING && m_state != DONE)) 384 if (m_error || (m_state != LOADING && m_state != DONE))
385 return nullptr; 385 return nullptr;
386 386
387 return m_responseLegacyStream; 387 return m_responseLegacyStream;
388 } 388 }
389 389
390 void XMLHttpRequest::setTimeout(unsigned timeout, ExceptionState& exceptionState ) 390 void XMLHttpRequest::setTimeout(unsigned timeout, ExceptionState& exceptionState )
391 { 391 {
392 // FIXME: Need to trigger or update the timeout Timer here, if needed. http: //webkit.org/b/98156 392 // FIXME: Need to trigger or update the timeout Timer here, if needed. http: //webkit.org/b/98156
393 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set whi le fetching is in progress. If that occurs it will still be measured relative to the start of fetching." 393 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set whi le fetching is in progress. If that occurs it will still be measured relative to the start of fetching."
394 if (executionContext()->isDocument() && !m_async) { 394 if (getExecutionContext()->isDocument() && !m_async) {
395 exceptionState.throwDOMException(InvalidAccessError, "Timeouts cannot be set for synchronous requests made from a document."); 395 exceptionState.throwDOMException(InvalidAccessError, "Timeouts cannot be set for synchronous requests made from a document.");
396 return; 396 return;
397 } 397 }
398 398
399 m_timeoutMilliseconds = timeout; 399 m_timeoutMilliseconds = timeout;
400 400
401 // From http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute: 401 // From http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute:
402 // Note: This implies that the timeout attribute can be set while fetching i s in progress. If 402 // Note: This implies that the timeout attribute can be set while fetching i s in progress. If
403 // that occurs it will still be measured relative to the start of fetching. 403 // that occurs it will still be measured relative to the start of fetching.
404 // 404 //
405 // The timeout may be overridden after send. 405 // The timeout may be overridden after send.
406 if (m_loader) 406 if (m_loader)
407 m_loader->overrideTimeout(timeout); 407 m_loader->overrideTimeout(timeout);
408 } 408 }
409 409
410 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState& exceptionState) 410 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState& exceptionState)
411 { 411 {
412 if (m_state >= LOADING) { 412 if (m_state >= LOADING) {
413 exceptionState.throwDOMException(InvalidStateError, "The response type c annot be set if the object's state is LOADING or DONE."); 413 exceptionState.throwDOMException(InvalidStateError, "The response type c annot be set if the object's state is LOADING or DONE.");
414 return; 414 return;
415 } 415 }
416 416
417 // Newer functionality is not available to synchronous requests in window co ntexts, as a spec-mandated 417 // Newer functionality is not available to synchronous requests in window co ntexts, as a spec-mandated
418 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality. 418 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality.
419 if (!m_async && executionContext()->isDocument()) { 419 if (!m_async && getExecutionContext()->isDocument()) {
420 exceptionState.throwDOMException(InvalidAccessError, "The response type cannot be changed for synchronous requests made from a document."); 420 exceptionState.throwDOMException(InvalidAccessError, "The response type cannot be changed for synchronous requests made from a document.");
421 return; 421 return;
422 } 422 }
423 423
424 if (responseType == "") { 424 if (responseType == "") {
425 m_responseTypeCode = ResponseTypeDefault; 425 m_responseTypeCode = ResponseTypeDefault;
426 } else if (responseType == "text") { 426 } else if (responseType == "text") {
427 m_responseTypeCode = ResponseTypeText; 427 m_responseTypeCode = ResponseTypeText;
428 } else if (responseType == "json") { 428 } else if (responseType == "json") {
429 m_responseTypeCode = ResponseTypeJSON; 429 m_responseTypeCode = ResponseTypeJSON;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 void XMLHttpRequest::changeState(State newState) 493 void XMLHttpRequest::changeState(State newState)
494 { 494 {
495 if (m_state != newState) { 495 if (m_state != newState) {
496 m_state = newState; 496 m_state = newState;
497 dispatchReadyStateChangeEvent(); 497 dispatchReadyStateChangeEvent();
498 } 498 }
499 } 499 }
500 500
501 void XMLHttpRequest::dispatchReadyStateChangeEvent() 501 void XMLHttpRequest::dispatchReadyStateChangeEvent()
502 { 502 {
503 if (!executionContext()) 503 if (!getExecutionContext())
504 return; 504 return;
505 505
506 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); 506 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel);
507 if (m_async || (m_state <= OPENED || m_state == DONE)) { 507 if (m_async || (m_state <= OPENED || m_state == DONE)) {
508 TRACE_EVENT1("devtools.timeline", "XHRReadyStateChange", "data", Inspect orXhrReadyStateChangeEvent::data(executionContext(), this)); 508 TRACE_EVENT1("devtools.timeline", "XHRReadyStateChange", "data", Inspect orXhrReadyStateChangeEvent::data(getExecutionContext(), this));
509 XMLHttpRequestProgressEventThrottle::DeferredEventAction action = XMLHtt pRequestProgressEventThrottle::Ignore; 509 XMLHttpRequestProgressEventThrottle::DeferredEventAction action = XMLHtt pRequestProgressEventThrottle::Ignore;
510 if (m_state == DONE) { 510 if (m_state == DONE) {
511 if (m_error) 511 if (m_error)
512 action = XMLHttpRequestProgressEventThrottle::Clear; 512 action = XMLHttpRequestProgressEventThrottle::Clear;
513 else 513 else
514 action = XMLHttpRequestProgressEventThrottle::Flush; 514 action = XMLHttpRequestProgressEventThrottle::Flush;
515 } 515 }
516 m_progressEventThrottle->dispatchReadyStateChangeEvent(Event::create(Eve ntTypeNames::readystatechange), action); 516 m_progressEventThrottle->dispatchReadyStateChangeEvent(Event::create(Eve ntTypeNames::readystatechange), action);
517 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d ata()); 517 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d ata());
518 } 518 }
519 519
520 if (m_state == DONE && !m_error) { 520 if (m_state == DONE && !m_error) {
521 TRACE_EVENT1("devtools.timeline", "XHRLoad", "data", InspectorXhrLoadEve nt::data(executionContext(), this)); 521 TRACE_EVENT1("devtools.timeline", "XHRLoad", "data", InspectorXhrLoadEve nt::data(getExecutionContext(), this));
522 dispatchProgressEventFromSnapshot(EventTypeNames::load); 522 dispatchProgressEventFromSnapshot(EventTypeNames::load);
523 dispatchProgressEventFromSnapshot(EventTypeNames::loadend); 523 dispatchProgressEventFromSnapshot(EventTypeNames::loadend);
524 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d ata()); 524 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Up dateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::d ata());
525 } 525 }
526 } 526 }
527 527
528 void XMLHttpRequest::setWithCredentials(bool value, ExceptionState& exceptionSta te) 528 void XMLHttpRequest::setWithCredentials(bool value, ExceptionState& exceptionSta te)
529 { 529 {
530 if (m_state > OPENED || m_loader) { 530 if (m_state > OPENED || m_loader) {
531 exceptionState.throwDOMException(InvalidStateError, "The value may only be set if the object's state is UNSENT or OPENED."); 531 exceptionState.throwDOMException(InvalidStateError, "The value may only be set if the object's state is UNSENT or OPENED.");
532 return; 532 return;
533 } 533 }
534 534
535 // FIXME: According to XMLHttpRequest Level 2 we should throw InvalidAccessE rror exception here. 535 // FIXME: According to XMLHttpRequest Level 2 we should throw InvalidAccessE rror exception here.
536 // However for time being only print warning message to warn web developers. 536 // However for time being only print warning message to warn web developers.
537 if (!m_async) 537 if (!m_async)
538 Deprecation::countDeprecation(executionContext(), UseCounter::SyncXHRWit hCredentials); 538 Deprecation::countDeprecation(getExecutionContext(), UseCounter::SyncXHR WithCredentials);
539 539
540 m_includeCredentials = value; 540 m_includeCredentials = value;
541 } 541 }
542 542
543 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, E xceptionState& exceptionState) 543 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, E xceptionState& exceptionState)
544 { 544 {
545 open(method, executionContext()->completeURL(urlString), true, exceptionStat e); 545 open(method, getExecutionContext()->completeURL(urlString), true, exceptionS tate);
546 } 546 }
547 547
548 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, b ool async, const String& username, const String& password, ExceptionState& excep tionState) 548 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, b ool async, const String& username, const String& password, ExceptionState& excep tionState)
549 { 549 {
550 KURL url(executionContext()->completeURL(urlString)); 550 KURL url(getExecutionContext()->completeURL(urlString));
551 if (!username.isNull()) 551 if (!username.isNull())
552 url.setUser(username); 552 url.setUser(username);
553 if (!password.isNull()) 553 if (!password.isNull())
554 url.setPass(password); 554 url.setPass(password);
555 555
556 open(method, url, async, exceptionState); 556 open(method, url, async, exceptionState);
557 } 557 }
558 558
559 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn c, ExceptionState& exceptionState) 559 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn c, ExceptionState& exceptionState)
560 { 560 {
(...skipping 10 matching lines...) Expand all
571 if (!isValidHTTPToken(method)) { 571 if (!isValidHTTPToken(method)) {
572 exceptionState.throwDOMException(SyntaxError, "'" + method + "' is not a valid HTTP method."); 572 exceptionState.throwDOMException(SyntaxError, "'" + method + "' is not a valid HTTP method.");
573 return; 573 return;
574 } 574 }
575 575
576 if (FetchUtils::isForbiddenMethod(method)) { 576 if (FetchUtils::isForbiddenMethod(method)) {
577 exceptionState.throwSecurityError("'" + method + "' HTTP method is unsup ported."); 577 exceptionState.throwSecurityError("'" + method + "' HTTP method is unsup ported.");
578 return; 578 return;
579 } 579 }
580 580
581 if (!ContentSecurityPolicy::shouldBypassMainWorld(executionContext()) && !ex ecutionContext()->contentSecurityPolicy()->allowConnectToSource(url)) { 581 if (!ContentSecurityPolicy::shouldBypassMainWorld(getExecutionContext()) && !getExecutionContext()->contentSecurityPolicy()->allowConnectToSource(url)) {
582 // We can safely expose the URL to JavaScript, as these checks happen sy nchronously before redirection. JavaScript receives no new information. 582 // We can safely expose the URL to JavaScript, as these checks happen sy nchronously before redirection. JavaScript receives no new information.
583 exceptionState.throwSecurityError("Refused to connect to '" + url.elided String() + "' because it violates the document's Content Security Policy."); 583 exceptionState.throwSecurityError("Refused to connect to '" + url.elided String() + "' because it violates the document's Content Security Policy.");
584 return; 584 return;
585 } 585 }
586 586
587 if (!async && executionContext()->isDocument()) { 587 if (!async && getExecutionContext()->isDocument()) {
588 if (document()->settings() && !document()->settings()->syncXHRInDocument sEnabled()) { 588 if (document()->settings() && !document()->settings()->syncXHRInDocument sEnabled()) {
589 exceptionState.throwDOMException(InvalidAccessError, "Synchronous re quests are disabled for this page."); 589 exceptionState.throwDOMException(InvalidAccessError, "Synchronous re quests are disabled for this page.");
590 return; 590 return;
591 } 591 }
592 592
593 // Newer functionality is not available to synchronous requests in windo w contexts, as a spec-mandated 593 // Newer functionality is not available to synchronous requests in windo w contexts, as a spec-mandated
594 // attempt to discourage synchronous XHR use. responseType is one such p iece of functionality. 594 // attempt to discourage synchronous XHR use. responseType is one such p iece of functionality.
595 if (m_responseTypeCode != ResponseTypeDefault) { 595 if (m_responseTypeCode != ResponseTypeDefault) {
596 exceptionState.throwDOMException(InvalidAccessError, "Synchronous re quests from a document must not set a response type."); 596 exceptionState.throwDOMException(InvalidAccessError, "Synchronous re quests from a document must not set a response type.");
597 return; 597 return;
598 } 598 }
599 599
600 // Similarly, timeouts are disabled for synchronous requests as well. 600 // Similarly, timeouts are disabled for synchronous requests as well.
601 if (m_timeoutMilliseconds > 0) { 601 if (m_timeoutMilliseconds > 0) {
602 exceptionState.throwDOMException(InvalidAccessError, "Synchronous re quests must not set a timeout."); 602 exceptionState.throwDOMException(InvalidAccessError, "Synchronous re quests must not set a timeout.");
603 return; 603 return;
604 } 604 }
605 605
606 // Here we just warn that firing sync XHR's may affect responsiveness. 606 // Here we just warn that firing sync XHR's may affect responsiveness.
607 // Eventually sync xhr will be deprecated and an "InvalidAccessError" ex ception thrown. 607 // Eventually sync xhr will be deprecated and an "InvalidAccessError" ex ception thrown.
608 // Refer : https://xhr.spec.whatwg.org/#sync-warning 608 // Refer : https://xhr.spec.whatwg.org/#sync-warning
609 // Use count for XHR synchronous requests on main thread only. 609 // Use count for XHR synchronous requests on main thread only.
610 if (!document()->processingBeforeUnload()) 610 if (!document()->processingBeforeUnload())
611 Deprecation::countDeprecation(executionContext(), UseCounter::XMLHtt pRequestSynchronousInNonWorkerOutsideBeforeUnload); 611 Deprecation::countDeprecation(getExecutionContext(), UseCounter::XML HttpRequestSynchronousInNonWorkerOutsideBeforeUnload);
612 } 612 }
613 613
614 m_method = FetchUtils::normalizeMethod(method); 614 m_method = FetchUtils::normalizeMethod(method);
615 615
616 m_url = url; 616 m_url = url;
617 617
618 m_async = async; 618 m_async = async;
619 619
620 ASSERT(!m_loader); 620 ASSERT(!m_loader);
621 621
622 // Check previous state to avoid dispatching readyState event 622 // Check previous state to avoid dispatching readyState event
623 // when calling open several times in a row. 623 // when calling open several times in a row.
624 if (previousState != OPENED) 624 if (previousState != OPENED)
625 changeState(OPENED); 625 changeState(OPENED);
626 else 626 else
627 m_state = OPENED; 627 m_state = OPENED;
628 } 628 }
629 629
630 bool XMLHttpRequest::initSend(ExceptionState& exceptionState) 630 bool XMLHttpRequest::initSend(ExceptionState& exceptionState)
631 { 631 {
632 if (!executionContext()) 632 if (!getExecutionContext())
633 return false; 633 return false;
634 634
635 if (m_state != OPENED || m_loader) { 635 if (m_state != OPENED || m_loader) {
636 exceptionState.throwDOMException(InvalidStateError, "The object's state must be OPENED."); 636 exceptionState.throwDOMException(InvalidStateError, "The object's state must be OPENED.");
637 return false; 637 return false;
638 } 638 }
639 639
640 m_error = false; 640 m_error = false;
641 return true; 641 return true;
642 } 642 }
643 643
644 void XMLHttpRequest::send(const ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrSt ringOrFormData& body, ExceptionState& exceptionState) 644 void XMLHttpRequest::send(const ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrSt ringOrFormData& body, ExceptionState& exceptionState)
645 { 645 {
646 InspectorInstrumentation::willSendXMLHttpRequest(executionContext(), url()); 646 InspectorInstrumentation::willSendXMLHttpRequest(getExecutionContext(), url( ));
647 647
648 if (body.isNull()) { 648 if (body.isNull()) {
649 send(String(), exceptionState); 649 send(String(), exceptionState);
650 return; 650 return;
651 } 651 }
652 652
653 if (body.isArrayBuffer()) { 653 if (body.isArrayBuffer()) {
654 send(body.getAsArrayBuffer().get(), exceptionState); 654 send(body.getAsArrayBuffer().get(), exceptionState);
655 return; 655 return;
656 } 656 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 // Also, only async requests support upload progress events. 860 // Also, only async requests support upload progress events.
861 bool uploadEvents = false; 861 bool uploadEvents = false;
862 if (m_async) { 862 if (m_async) {
863 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); 863 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0);
864 if (httpBody && m_upload) { 864 if (httpBody && m_upload) {
865 uploadEvents = m_upload->hasEventListeners(); 865 uploadEvents = m_upload->hasEventListeners();
866 m_upload->dispatchEvent(ProgressEvent::create(EventTypeNames::loadst art, false, 0, 0)); 866 m_upload->dispatchEvent(ProgressEvent::create(EventTypeNames::loadst art, false, 0, 0));
867 } 867 }
868 } 868 }
869 869
870 m_sameOriginRequest = securityOrigin()->canRequestNoSuborigin(m_url); 870 m_sameOriginRequest = getSecurityOrigin()->canRequestNoSuborigin(m_url);
871 871
872 // We also remember whether upload events should be allowed for this request in case the upload listeners are 872 // We also remember whether upload events should be allowed for this request in case the upload listeners are
873 // added after the request is started. 873 // added after the request is started.
874 m_uploadEventsAllowed = m_sameOriginRequest || uploadEvents || !FetchUtils:: isSimpleRequest(m_method, m_requestHeaders); 874 m_uploadEventsAllowed = m_sameOriginRequest || uploadEvents || !FetchUtils:: isSimpleRequest(m_method, m_requestHeaders);
875 875
876 ASSERT(executionContext()); 876 ASSERT(getExecutionContext());
877 ExecutionContext& executionContext = *this->executionContext(); 877 ExecutionContext& executionContext = *this->getExecutionContext();
878 878
879 ResourceRequest request(m_url); 879 ResourceRequest request(m_url);
880 request.setHTTPMethod(m_method); 880 request.setHTTPMethod(m_method);
881 request.setRequestContext(WebURLRequest::RequestContextXMLHttpRequest); 881 request.setRequestContext(WebURLRequest::RequestContextXMLHttpRequest);
882 request.setFetchCredentialsMode(m_includeCredentials ? WebURLRequest::FetchC redentialsModeInclude : WebURLRequest::FetchCredentialsModeSameOrigin); 882 request.setFetchCredentialsMode(m_includeCredentials ? WebURLRequest::FetchC redentialsModeInclude : WebURLRequest::FetchCredentialsModeSameOrigin);
883 request.setSkipServiceWorker(m_isolatedWorldSecurityOrigin); 883 request.setSkipServiceWorker(m_isolatedWorldSecurityOrigin);
884 request.setExternalRequestStateFromRequestorAddressSpace(executionContext.se curityContext().addressSpace()); 884 request.setExternalRequestStateFromRequestorAddressSpace(executionContext.se curityContext().addressSpace());
885 885
886 InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_metho d, m_url, m_async, httpBody ? httpBody->deepCopy() : nullptr, m_requestHeaders, m_includeCredentials); 886 InspectorInstrumentation::willLoadXHR(&executionContext, this, this, m_metho d, m_url, m_async, httpBody ? httpBody->deepCopy() : nullptr, m_requestHeaders, m_includeCredentials);
887 887
888 if (httpBody) { 888 if (httpBody) {
889 ASSERT(m_method != HTTPNames::GET); 889 ASSERT(m_method != HTTPNames::GET);
890 ASSERT(m_method != HTTPNames::HEAD); 890 ASSERT(m_method != HTTPNames::HEAD);
891 request.setHTTPBody(httpBody); 891 request.setHTTPBody(httpBody);
892 } 892 }
893 893
894 if (m_requestHeaders.size() > 0) 894 if (m_requestHeaders.size() > 0)
895 request.addHTTPHeaderFields(m_requestHeaders); 895 request.addHTTPHeaderFields(m_requestHeaders);
896 896
897 ThreadableLoaderOptions options; 897 ThreadableLoaderOptions options;
898 options.preflightPolicy = uploadEvents ? ForcePreflight : ConsiderPreflight; 898 options.preflightPolicy = uploadEvents ? ForcePreflight : ConsiderPreflight;
899 options.crossOriginRequestPolicy = UseAccessControl; 899 options.crossOriginRequestPolicy = UseAccessControl;
900 options.initiator = FetchInitiatorTypeNames::xmlhttprequest; 900 options.initiator = FetchInitiatorTypeNames::xmlhttprequest;
901 options.contentSecurityPolicyEnforcement = ContentSecurityPolicy::shouldBypa ssMainWorld(&executionContext) ? DoNotEnforceContentSecurityPolicy : EnforceCont entSecurityPolicy; 901 options.contentSecurityPolicyEnforcement = ContentSecurityPolicy::shouldBypa ssMainWorld(&executionContext) ? DoNotEnforceContentSecurityPolicy : EnforceCont entSecurityPolicy;
902 options.timeoutMilliseconds = m_timeoutMilliseconds; 902 options.timeoutMilliseconds = m_timeoutMilliseconds;
903 903
904 ResourceLoaderOptions resourceLoaderOptions; 904 ResourceLoaderOptions resourceLoaderOptions;
905 resourceLoaderOptions.allowCredentials = (m_sameOriginRequest || m_includeCr edentials) ? AllowStoredCredentials : DoNotAllowStoredCredentials; 905 resourceLoaderOptions.allowCredentials = (m_sameOriginRequest || m_includeCr edentials) ? AllowStoredCredentials : DoNotAllowStoredCredentials;
906 resourceLoaderOptions.credentialsRequested = m_includeCredentials ? ClientRe questedCredentials : ClientDidNotRequestCredentials; 906 resourceLoaderOptions.credentialsRequested = m_includeCredentials ? ClientRe questedCredentials : ClientDidNotRequestCredentials;
907 resourceLoaderOptions.securityOrigin = securityOrigin(); 907 resourceLoaderOptions.securityOrigin = getSecurityOrigin();
908 908
909 // When responseType is set to "blob", we redirect the downloaded data to a 909 // When responseType is set to "blob", we redirect the downloaded data to a
910 // file-handle directly. 910 // file-handle directly.
911 m_downloadingToFile = getResponseTypeCode() == ResponseTypeBlob; 911 m_downloadingToFile = getResponseTypeCode() == ResponseTypeBlob;
912 if (m_downloadingToFile) { 912 if (m_downloadingToFile) {
913 request.setDownloadToFile(true); 913 request.setDownloadToFile(true);
914 resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData; 914 resourceLoaderOptions.dataBufferingPolicy = DoNotBufferData;
915 } 915 }
916 916
917 m_exceptionCode = 0; 917 m_exceptionCode = 0;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 1065
1066 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type, long long r eceivedLength, long long expectedLength) 1066 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type, long long r eceivedLength, long long expectedLength)
1067 { 1067 {
1068 bool lengthComputable = expectedLength > 0 && receivedLength <= expectedLeng th; 1068 bool lengthComputable = expectedLength > 0 && receivedLength <= expectedLeng th;
1069 unsigned long long loaded = receivedLength >= 0 ? static_cast<unsigned long long>(receivedLength) : 0; 1069 unsigned long long loaded = receivedLength >= 0 ? static_cast<unsigned long long>(receivedLength) : 0;
1070 unsigned long long total = lengthComputable ? static_cast<unsigned long long >(expectedLength) : 0; 1070 unsigned long long total = lengthComputable ? static_cast<unsigned long long >(expectedLength) : 0;
1071 1071
1072 m_progressEventThrottle->dispatchProgressEvent(type, lengthComputable, loade d, total); 1072 m_progressEventThrottle->dispatchProgressEvent(type, lengthComputable, loade d, total);
1073 1073
1074 if (type == EventTypeNames::loadend) 1074 if (type == EventTypeNames::loadend)
1075 InspectorInstrumentation::didDispatchXHRLoadendEvent(executionContext(), this); 1075 InspectorInstrumentation::didDispatchXHRLoadendEvent(getExecutionContext (), this);
1076 } 1076 }
1077 1077
1078 void XMLHttpRequest::dispatchProgressEventFromSnapshot(const AtomicString& type) 1078 void XMLHttpRequest::dispatchProgressEventFromSnapshot(const AtomicString& type)
1079 { 1079 {
1080 dispatchProgressEvent(type, m_receivedLength, m_response.expectedContentLeng th()); 1080 dispatchProgressEvent(type, m_receivedLength, m_response.expectedContentLeng th());
1081 } 1081 }
1082 1082
1083 void XMLHttpRequest::handleNetworkError() 1083 void XMLHttpRequest::handleNetworkError()
1084 { 1084 {
1085 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this); 1085 WTF_LOG(Network, "XMLHttpRequest %p handleNetworkError()", this);
(...skipping 19 matching lines...) Expand all
1105 if (!internalAbort()) 1105 if (!internalAbort())
1106 return; 1106 return;
1107 1107
1108 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength); 1108 handleRequestError(AbortError, EventTypeNames::abort, receivedLength, expect edLength);
1109 } 1109 }
1110 1110
1111 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength) 1111 void XMLHttpRequest::handleRequestError(ExceptionCode exceptionCode, const Atomi cString& type, long long receivedLength, long long expectedLength)
1112 { 1112 {
1113 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this); 1113 WTF_LOG(Network, "XMLHttpRequest %p handleRequestError()", this);
1114 1114
1115 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this, m_method, m_url); 1115 InspectorInstrumentation::didFailXHRLoading(getExecutionContext(), this, thi s, m_method, m_url);
1116 1116
1117 if (!m_async) { 1117 if (!m_async) {
1118 ASSERT(exceptionCode); 1118 ASSERT(exceptionCode);
1119 m_state = DONE; 1119 m_state = DONE;
1120 m_exceptionCode = exceptionCode; 1120 m_exceptionCode = exceptionCode;
1121 return; 1121 return;
1122 } 1122 }
1123 1123
1124 // With m_error set, the state change steps are minimal: any pending 1124 // With m_error set, the state change steps are minimal: any pending
1125 // progress event is flushed + a readystatechange is dispatched. 1125 // progress event is flushed + a readystatechange is dispatched.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 return; 1164 return;
1165 } 1165 }
1166 1166
1167 if (!isValidHTTPHeaderValue(value)) { 1167 if (!isValidHTTPHeaderValue(value)) {
1168 exceptionState.throwDOMException(SyntaxError, "'" + value + "' is not a valid HTTP header field value."); 1168 exceptionState.throwDOMException(SyntaxError, "'" + value + "' is not a valid HTTP header field value.");
1169 return; 1169 return;
1170 } 1170 }
1171 1171
1172 // No script (privileged or not) can set unsafe headers. 1172 // No script (privileged or not) can set unsafe headers.
1173 if (FetchUtils::isForbiddenHeaderName(name)) { 1173 if (FetchUtils::isForbiddenHeaderName(name)) {
1174 logConsoleError(executionContext(), "Refused to set unsafe header \"" + name + "\""); 1174 logConsoleError(getExecutionContext(), "Refused to set unsafe header \"" + name + "\"");
1175 return; 1175 return;
1176 } 1176 }
1177 1177
1178 setRequestHeaderInternal(name, value); 1178 setRequestHeaderInternal(name, value);
1179 } 1179 }
1180 1180
1181 void XMLHttpRequest::setRequestHeaderInternal(const AtomicString& name, const At omicString& value) 1181 void XMLHttpRequest::setRequestHeaderInternal(const AtomicString& name, const At omicString& value)
1182 { 1182 {
1183 HeaderValueCategoryByRFC7230 headerValueCategory = HeaderValueValid; 1183 HeaderValueCategoryByRFC7230 headerValueCategory = HeaderValueValid;
1184 1184
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 1222
1223 HTTPHeaderSet accessControlExposeHeaderSet; 1223 HTTPHeaderSet accessControlExposeHeaderSet;
1224 parseAccessControlExposeHeadersAllowList(m_response.httpHeaderField(HTTPName s::Access_Control_Expose_Headers), accessControlExposeHeaderSet); 1224 parseAccessControlExposeHeadersAllowList(m_response.httpHeaderField(HTTPName s::Access_Control_Expose_Headers), accessControlExposeHeaderSet);
1225 HTTPHeaderMap::const_iterator end = m_response.httpHeaderFields().end(); 1225 HTTPHeaderMap::const_iterator end = m_response.httpHeaderFields().end();
1226 for (HTTPHeaderMap::const_iterator it = m_response.httpHeaderFields().begin( ); it!= end; ++it) { 1226 for (HTTPHeaderMap::const_iterator it = m_response.httpHeaderFields().begin( ); it!= end; ++it) {
1227 // Hide any headers whose name is a forbidden response-header name. 1227 // Hide any headers whose name is a forbidden response-header name.
1228 // This is required for all kinds of filtered responses. 1228 // This is required for all kinds of filtered responses.
1229 // 1229 //
1230 // TODO: Consider removing canLoadLocalResources() call. 1230 // TODO: Consider removing canLoadLocalResources() call.
1231 // crbug.com/567527 1231 // crbug.com/567527
1232 if (FetchUtils::isForbiddenResponseHeaderName(it->key) && !securityOrigi n()->canLoadLocalResources()) 1232 if (FetchUtils::isForbiddenResponseHeaderName(it->key) && !getSecurityOr igin()->canLoadLocalResources())
1233 continue; 1233 continue;
1234 1234
1235 if (!m_sameOriginRequest && !isOnAccessControlResponseHeaderWhitelist(it ->key) && !accessControlExposeHeaderSet.contains(it->key)) 1235 if (!m_sameOriginRequest && !isOnAccessControlResponseHeaderWhitelist(it ->key) && !accessControlExposeHeaderSet.contains(it->key))
1236 continue; 1236 continue;
1237 1237
1238 stringBuilder.append(it->key); 1238 stringBuilder.append(it->key);
1239 stringBuilder.append(':'); 1239 stringBuilder.append(':');
1240 stringBuilder.append(' '); 1240 stringBuilder.append(' ');
1241 stringBuilder.append(it->value); 1241 stringBuilder.append(it->value);
1242 stringBuilder.append('\r'); 1242 stringBuilder.append('\r');
1243 stringBuilder.append('\n'); 1243 stringBuilder.append('\n');
1244 } 1244 }
1245 1245
1246 return stringBuilder.toString(); 1246 return stringBuilder.toString();
1247 } 1247 }
1248 1248
1249 const AtomicString& XMLHttpRequest::getResponseHeader(const AtomicString& name) const 1249 const AtomicString& XMLHttpRequest::getResponseHeader(const AtomicString& name) const
1250 { 1250 {
1251 if (m_state < HEADERS_RECEIVED || m_error) 1251 if (m_state < HEADERS_RECEIVED || m_error)
1252 return nullAtom; 1252 return nullAtom;
1253 1253
1254 // See comment in getAllResponseHeaders above. 1254 // See comment in getAllResponseHeaders above.
1255 if (FetchUtils::isForbiddenResponseHeaderName(name) && !securityOrigin()->ca nLoadLocalResources()) { 1255 if (FetchUtils::isForbiddenResponseHeaderName(name) && !getSecurityOrigin()- >canLoadLocalResources()) {
1256 logConsoleError(executionContext(), "Refused to get unsafe header \"" + name + "\""); 1256 logConsoleError(getExecutionContext(), "Refused to get unsafe header \"" + name + "\"");
1257 return nullAtom; 1257 return nullAtom;
1258 } 1258 }
1259 1259
1260 HTTPHeaderSet accessControlExposeHeaderSet; 1260 HTTPHeaderSet accessControlExposeHeaderSet;
1261 parseAccessControlExposeHeadersAllowList(m_response.httpHeaderField(HTTPName s::Access_Control_Expose_Headers), accessControlExposeHeaderSet); 1261 parseAccessControlExposeHeadersAllowList(m_response.httpHeaderField(HTTPName s::Access_Control_Expose_Headers), accessControlExposeHeaderSet);
1262 1262
1263 if (!m_sameOriginRequest && !isOnAccessControlResponseHeaderWhitelist(name) && !accessControlExposeHeaderSet.contains(name)) { 1263 if (!m_sameOriginRequest && !isOnAccessControlResponseHeaderWhitelist(name) && !accessControlExposeHeaderSet.contains(name)) {
1264 logConsoleError(executionContext(), "Refused to get unsafe header \"" + name + "\""); 1264 logConsoleError(getExecutionContext(), "Refused to get unsafe header \"" + name + "\"");
1265 return nullAtom; 1265 return nullAtom;
1266 } 1266 }
1267 return m_response.httpHeaderField(name); 1267 return m_response.httpHeaderField(name);
1268 } 1268 }
1269 1269
1270 AtomicString XMLHttpRequest::finalResponseMIMEType() const 1270 AtomicString XMLHttpRequest::finalResponseMIMEType() const
1271 { 1271 {
1272 AtomicString overriddenType = extractMIMETypeFromMediaType(m_mimeTypeOverrid e); 1272 AtomicString overriddenType = extractMIMETypeFromMediaType(m_mimeTypeOverrid e);
1273 if (!overriddenType.isEmpty()) 1273 if (!overriddenType.isEmpty())
1274 return overriddenType; 1274 return overriddenType;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 } 1338 }
1339 1339
1340 if (error.isTimeout()) { 1340 if (error.isTimeout()) {
1341 handleDidTimeout(); 1341 handleDidTimeout();
1342 // Now the XMLHttpRequest instance may be dead. 1342 // Now the XMLHttpRequest instance may be dead.
1343 return; 1343 return;
1344 } 1344 }
1345 1345
1346 // Network failures are already reported to Web Inspector by ResourceLoader. 1346 // Network failures are already reported to Web Inspector by ResourceLoader.
1347 if (error.domain() == errorDomainBlinkInternal) 1347 if (error.domain() == errorDomainBlinkInternal)
1348 logConsoleError(executionContext(), "XMLHttpRequest cannot load " + erro r.failingURL() + ". " + error.localizedDescription()); 1348 logConsoleError(getExecutionContext(), "XMLHttpRequest cannot load " + e rror.failingURL() + ". " + error.localizedDescription());
1349 1349
1350 handleNetworkError(); 1350 handleNetworkError();
1351 // Now the XMLHttpRequest instance may be dead. 1351 // Now the XMLHttpRequest instance may be dead.
1352 } 1352 }
1353 1353
1354 void XMLHttpRequest::didFailRedirectCheck() 1354 void XMLHttpRequest::didFailRedirectCheck()
1355 { 1355 {
1356 WTF_LOG(Network, "XMLHttpRequest %p didFailRedirectCheck()", this); 1356 WTF_LOG(Network, "XMLHttpRequest %p didFailRedirectCheck()", this);
1357 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); 1357 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel);
1358 1358
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 if (!m_responseDocument->wellFormed()) 1463 if (!m_responseDocument->wellFormed())
1464 m_responseDocument = nullptr; 1464 m_responseDocument = nullptr;
1465 1465
1466 m_parsedResponse = true; 1466 m_parsedResponse = true;
1467 1467
1468 endLoading(); 1468 endLoading();
1469 } 1469 }
1470 1470
1471 void XMLHttpRequest::endLoading() 1471 void XMLHttpRequest::endLoading()
1472 { 1472 {
1473 InspectorInstrumentation::didFinishXHRLoading(executionContext(), this, this , m_method, m_url); 1473 InspectorInstrumentation::didFinishXHRLoading(getExecutionContext(), this, t his, m_method, m_url);
1474 1474
1475 if (m_loader) 1475 if (m_loader)
1476 m_loader = nullptr; 1476 m_loader = nullptr;
1477 1477
1478 changeState(DONE); 1478 changeState(DONE);
1479 1479
1480 if (!executionContext()->isDocument() || !document() || !document()->frame() || !document()->frame()->page()) 1480 if (!getExecutionContext()->isDocument() || !document() || !document()->fram e() || !document()->frame()->page())
1481 return; 1481 return;
1482 1482
1483 if (status() >= 200 && status() < 300) { 1483 if (status() >= 200 && status() < 300) {
1484 document()->frame()->page()->chromeClient().ajaxSucceeded(document()->fr ame()); 1484 document()->frame()->page()->chromeClient().ajaxSucceeded(document()->fr ame());
1485 } 1485 }
1486 } 1486 }
1487 1487
1488 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) 1488 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent)
1489 { 1489 {
1490 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent); 1490 WTF_LOG(Network, "XMLHttpRequest %p didSendData(%llu, %llu)", this, bytesSen t, totalBytesToBeSent);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 m_responseText = m_responseText.concatenateWith(text); 1591 m_responseText = m_responseText.concatenateWith(text);
1592 m_responseTextOverflow = m_responseText.isEmpty(); 1592 m_responseTextOverflow = m_responseText.isEmpty();
1593 } 1593 }
1594 } else if (m_responseTypeCode == ResponseTypeArrayBuffer || m_responseTypeCo de == ResponseTypeBlob) { 1594 } else if (m_responseTypeCode == ResponseTypeArrayBuffer || m_responseTypeCo de == ResponseTypeBlob) {
1595 // Buffer binary data. 1595 // Buffer binary data.
1596 if (!m_binaryResponseBuilder) 1596 if (!m_binaryResponseBuilder)
1597 m_binaryResponseBuilder = SharedBuffer::create(); 1597 m_binaryResponseBuilder = SharedBuffer::create();
1598 m_binaryResponseBuilder->append(data, len); 1598 m_binaryResponseBuilder->append(data, len);
1599 } else if (m_responseTypeCode == ResponseTypeLegacyStream) { 1599 } else if (m_responseTypeCode == ResponseTypeLegacyStream) {
1600 if (!m_responseLegacyStream) 1600 if (!m_responseLegacyStream)
1601 m_responseLegacyStream = Stream::create(executionContext(), response Type()); 1601 m_responseLegacyStream = Stream::create(getExecutionContext(), respo nseType());
1602 m_responseLegacyStream->addData(data, len); 1602 m_responseLegacyStream->addData(data, len);
1603 } 1603 }
1604 1604
1605 if (m_blobLoader) { 1605 if (m_blobLoader) {
1606 // In this case, the data is provided by m_blobLoader. As progress 1606 // In this case, the data is provided by m_blobLoader. As progress
1607 // events are already fired, we should return here. 1607 // events are already fired, we should return here.
1608 return; 1608 return;
1609 } 1609 }
1610 trackProgress(len); 1610 trackProgress(len);
1611 } 1611 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 m_progressEventThrottle->suspend(); 1653 m_progressEventThrottle->suspend();
1654 } 1654 }
1655 1655
1656 void XMLHttpRequest::resume() 1656 void XMLHttpRequest::resume()
1657 { 1657 {
1658 m_progressEventThrottle->resume(); 1658 m_progressEventThrottle->resume();
1659 } 1659 }
1660 1660
1661 void XMLHttpRequest::stop() 1661 void XMLHttpRequest::stop()
1662 { 1662 {
1663 InspectorInstrumentation::didFailXHRLoading(executionContext(), this, this, m_method, m_url); 1663 InspectorInstrumentation::didFailXHRLoading(getExecutionContext(), this, thi s, m_method, m_url);
1664 m_progressEventThrottle->stop(); 1664 m_progressEventThrottle->stop();
1665 internalAbort(); 1665 internalAbort();
1666 } 1666 }
1667 1667
1668 bool XMLHttpRequest::hasPendingActivity() const 1668 bool XMLHttpRequest::hasPendingActivity() const
1669 { 1669 {
1670 // Neither this object nor the JavaScript wrapper should be deleted while 1670 // Neither this object nor the JavaScript wrapper should be deleted while
1671 // a request is in progress because we need to keep the listeners alive, 1671 // a request is in progress because we need to keep the listeners alive,
1672 // and they are referenced by the JavaScript wrapper. 1672 // and they are referenced by the JavaScript wrapper.
1673 // |m_loader| is non-null while request is active and ThreadableLoaderClient 1673 // |m_loader| is non-null while request is active and ThreadableLoaderClient
1674 // callbacks may be called, and |m_responseDocumentParser| is non-null while 1674 // callbacks may be called, and |m_responseDocumentParser| is non-null while
1675 // DocumentParserClient callbacks may be called. 1675 // DocumentParserClient callbacks may be called.
1676 if (m_loader || m_responseDocumentParser) 1676 if (m_loader || m_responseDocumentParser)
1677 return true; 1677 return true;
1678 return m_eventDispatchRecursionLevel > 0; 1678 return m_eventDispatchRecursionLevel > 0;
1679 } 1679 }
1680 1680
1681 void XMLHttpRequest::contextDestroyed() 1681 void XMLHttpRequest::contextDestroyed()
1682 { 1682 {
1683 ASSERT(!m_loader); 1683 ASSERT(!m_loader);
1684 ActiveDOMObject::contextDestroyed(); 1684 ActiveDOMObject::contextDestroyed();
1685 } 1685 }
1686 1686
1687 const AtomicString& XMLHttpRequest::interfaceName() const 1687 const AtomicString& XMLHttpRequest::interfaceName() const
1688 { 1688 {
1689 return EventTargetNames::XMLHttpRequest; 1689 return EventTargetNames::XMLHttpRequest;
1690 } 1690 }
1691 1691
1692 ExecutionContext* XMLHttpRequest::executionContext() const 1692 ExecutionContext* XMLHttpRequest::getExecutionContext() const
1693 { 1693 {
1694 return ActiveDOMObject::executionContext(); 1694 return ActiveDOMObject::getExecutionContext();
1695 } 1695 }
1696 1696
1697 DEFINE_TRACE(XMLHttpRequest) 1697 DEFINE_TRACE(XMLHttpRequest)
1698 { 1698 {
1699 visitor->trace(m_responseBlob); 1699 visitor->trace(m_responseBlob);
1700 visitor->trace(m_responseLegacyStream); 1700 visitor->trace(m_responseLegacyStream);
1701 visitor->trace(m_responseDocument); 1701 visitor->trace(m_responseDocument);
1702 visitor->trace(m_responseDocumentParser); 1702 visitor->trace(m_responseDocumentParser);
1703 visitor->trace(m_progressEventThrottle); 1703 visitor->trace(m_progressEventThrottle);
1704 visitor->trace(m_upload); 1704 visitor->trace(m_upload);
1705 visitor->trace(m_blobLoader); 1705 visitor->trace(m_blobLoader);
1706 XMLHttpRequestEventTarget::trace(visitor); 1706 XMLHttpRequestEventTarget::trace(visitor);
1707 DocumentParserClient::trace(visitor); 1707 DocumentParserClient::trace(visitor);
1708 ActiveDOMObject::trace(visitor); 1708 ActiveDOMObject::trace(visitor);
1709 } 1709 }
1710 1710
1711 } // namespace blink 1711 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698