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

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

Issue 2365463004: Revert of Clear LifecycleObserver::m_context when LifecycleObserver::contextDestroyed gets called (Closed)
Patch Set: Created 4 years, 2 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return m_responseText; 288 return m_responseText;
289 } 289 }
290 290
291 void XMLHttpRequest::initResponseDocument() 291 void XMLHttpRequest::initResponseDocument()
292 { 292 {
293 // The W3C spec requires the final MIME type to be some valid XML type, or t ext/html. 293 // The W3C spec requires the final MIME type to be some valid XML type, or t ext/html.
294 // If it is text/html, then the responseType of "document" must have been su pplied explicitly. 294 // If it is text/html, then the responseType of "document" must have been su pplied explicitly.
295 bool isHTML = responseIsHTML(); 295 bool isHTML = responseIsHTML();
296 if ((m_response.isHTTP() && !responseIsXML() && !isHTML) 296 if ((m_response.isHTTP() && !responseIsXML() && !isHTML)
297 || (isHTML && m_responseTypeCode == ResponseTypeDefault) 297 || (isHTML && m_responseTypeCode == ResponseTypeDefault)
298 || !getExecutionContext()
299 || getExecutionContext()->isWorkerGlobalScope()) { 298 || getExecutionContext()->isWorkerGlobalScope()) {
300 m_responseDocument = nullptr; 299 m_responseDocument = nullptr;
301 return; 300 return;
302 } 301 }
303 302
304 DocumentInit init = DocumentInit::fromContext(document()->contextDocument(), m_url); 303 DocumentInit init = DocumentInit::fromContext(document()->contextDocument(), m_url);
305 if (isHTML) 304 if (isHTML)
306 m_responseDocument = HTMLDocument::create(init); 305 m_responseDocument = HTMLDocument::create(init);
307 else 306 else
308 m_responseDocument = XMLDocument::create(init); 307 m_responseDocument = XMLDocument::create(init);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 if (m_error || (m_state != kLoading && m_state != kDone)) 403 if (m_error || (m_state != kLoading && m_state != kDone))
405 return nullptr; 404 return nullptr;
406 405
407 return m_responseLegacyStream; 406 return m_responseLegacyStream;
408 } 407 }
409 408
410 void XMLHttpRequest::setTimeout(unsigned timeout, ExceptionState& exceptionState ) 409 void XMLHttpRequest::setTimeout(unsigned timeout, ExceptionState& exceptionState )
411 { 410 {
412 // FIXME: Need to trigger or update the timeout Timer here, if needed. http: //webkit.org/b/98156 411 // FIXME: Need to trigger or update the timeout Timer here, if needed. http: //webkit.org/b/98156
413 // 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." 412 // 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."
414 if (getExecutionContext() && getExecutionContext()->isDocument() && !m_async ) { 413 if (getExecutionContext()->isDocument() && !m_async) {
415 exceptionState.throwDOMException(InvalidAccessError, "Timeouts cannot be set for synchronous requests made from a document."); 414 exceptionState.throwDOMException(InvalidAccessError, "Timeouts cannot be set for synchronous requests made from a document.");
416 return; 415 return;
417 } 416 }
418 417
419 m_timeoutMilliseconds = timeout; 418 m_timeoutMilliseconds = timeout;
420 419
421 // From http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute: 420 // From http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute:
422 // Note: This implies that the timeout attribute can be set while fetching i s in progress. If 421 // Note: This implies that the timeout attribute can be set while fetching i s in progress. If
423 // that occurs it will still be measured relative to the start of fetching. 422 // that occurs it will still be measured relative to the start of fetching.
424 // 423 //
425 // The timeout may be overridden after send. 424 // The timeout may be overridden after send.
426 if (m_loader) 425 if (m_loader)
427 m_loader->overrideTimeout(timeout); 426 m_loader->overrideTimeout(timeout);
428 } 427 }
429 428
430 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState& exceptionState) 429 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState& exceptionState)
431 { 430 {
432 if (m_state >= kLoading) { 431 if (m_state >= kLoading) {
433 exceptionState.throwDOMException(InvalidStateError, "The response type c annot be set if the object's state is LOADING or DONE."); 432 exceptionState.throwDOMException(InvalidStateError, "The response type c annot be set if the object's state is LOADING or DONE.");
434 return; 433 return;
435 } 434 }
436 435
437 // Newer functionality is not available to synchronous requests in window co ntexts, as a spec-mandated 436 // Newer functionality is not available to synchronous requests in window co ntexts, as a spec-mandated
438 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality. 437 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality.
439 if (getExecutionContext() && getExecutionContext()->isDocument() && !m_async ) { 438 if (!m_async && getExecutionContext()->isDocument()) {
440 exceptionState.throwDOMException(InvalidAccessError, "The response type cannot be changed for synchronous requests made from a document."); 439 exceptionState.throwDOMException(InvalidAccessError, "The response type cannot be changed for synchronous requests made from a document.");
441 return; 440 return;
442 } 441 }
443 442
444 if (responseType == "") { 443 if (responseType == "") {
445 m_responseTypeCode = ResponseTypeDefault; 444 m_responseTypeCode = ResponseTypeDefault;
446 } else if (responseType == "text") { 445 } else if (responseType == "text") {
447 m_responseTypeCode = ResponseTypeText; 446 m_responseTypeCode = ResponseTypeText;
448 } else if (responseType == "json") { 447 } else if (responseType == "json") {
449 m_responseTypeCode = ResponseTypeJSON; 448 m_responseTypeCode = ResponseTypeJSON;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 if (m_state > kOpened || m_loader) { 549 if (m_state > kOpened || m_loader) {
551 exceptionState.throwDOMException(InvalidStateError, "The value may only be set if the object's state is UNSENT or OPENED."); 550 exceptionState.throwDOMException(InvalidStateError, "The value may only be set if the object's state is UNSENT or OPENED.");
552 return; 551 return;
553 } 552 }
554 553
555 m_includeCredentials = value; 554 m_includeCredentials = value;
556 } 555 }
557 556
558 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, E xceptionState& exceptionState) 557 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, E xceptionState& exceptionState)
559 { 558 {
560 if (!getExecutionContext())
561 return;
562
563 KURL url(getExecutionContext()->completeURL(urlString)); 559 KURL url(getExecutionContext()->completeURL(urlString));
564 if (!validateOpenArguments(method, url, exceptionState)) 560 if (!validateOpenArguments(method, url, exceptionState))
565 return; 561 return;
566 562
567 open(method, url, true, exceptionState); 563 open(method, url, true, exceptionState);
568 } 564 }
569 565
570 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, b ool async, const String& username, const String& password, ExceptionState& excep tionState) 566 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, b ool async, const String& username, const String& password, ExceptionState& excep tionState)
571 { 567 {
572 if (!getExecutionContext())
573 return;
574
575 KURL url(getExecutionContext()->completeURL(urlString)); 568 KURL url(getExecutionContext()->completeURL(urlString));
576 if (!validateOpenArguments(method, url, exceptionState)) 569 if (!validateOpenArguments(method, url, exceptionState))
577 return; 570 return;
578 571
579 if (!username.isNull()) 572 if (!username.isNull())
580 url.setUser(username); 573 url.setUser(username);
581 if (!password.isNull()) 574 if (!password.isNull())
582 url.setPass(password); 575 url.setPass(password);
583 576
584 open(method, url, async, exceptionState); 577 open(method, url, async, exceptionState);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 // Check previous state to avoid dispatching readyState event 635 // Check previous state to avoid dispatching readyState event
643 // when calling open several times in a row. 636 // when calling open several times in a row.
644 if (previousState != kOpened) 637 if (previousState != kOpened)
645 changeState(kOpened); 638 changeState(kOpened);
646 else 639 else
647 m_state = kOpened; 640 m_state = kOpened;
648 } 641 }
649 642
650 bool XMLHttpRequest::initSend(ExceptionState& exceptionState) 643 bool XMLHttpRequest::initSend(ExceptionState& exceptionState)
651 { 644 {
652 if (!getExecutionContext()) { 645 if (!getExecutionContext())
653 handleNetworkError();
654 throwForLoadFailureIfNeeded(exceptionState, "Document is already detache d.");
655 return false; 646 return false;
656 }
657 647
658 if (m_state != kOpened || m_loader) { 648 if (m_state != kOpened || m_loader) {
659 exceptionState.throwDOMException(InvalidStateError, "The object's state must be OPENED."); 649 exceptionState.throwDOMException(InvalidStateError, "The object's state must be OPENED.");
660 return false; 650 return false;
661 } 651 }
662 652
663 if (!m_async) { 653 if (!m_async) {
664 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 654 v8::Isolate* isolate = v8::Isolate::GetCurrent();
665 if (isolate && v8::MicrotasksScope::IsRunningMicrotasks(isolate)) { 655 if (isolate && v8::MicrotasksScope::IsRunningMicrotasks(isolate)) {
666 UseCounter::count(getExecutionContext(), UseCounter::During_Microtas k_SyncXHR); 656 UseCounter::count(getExecutionContext(), UseCounter::During_Microtas k_SyncXHR);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 if (m_url.protocolIs("blob") && m_method != HTTPNames::GET) { 869 if (m_url.protocolIs("blob") && m_method != HTTPNames::GET) {
880 handleNetworkError(); 870 handleNetworkError();
881 871
882 if (!m_async) { 872 if (!m_async) {
883 throwForLoadFailureIfNeeded(exceptionState, "'GET' is the only metho d allowed for 'blob:' URLs."); 873 throwForLoadFailureIfNeeded(exceptionState, "'GET' is the only metho d allowed for 'blob:' URLs.");
884 } 874 }
885 return; 875 return;
886 } 876 }
887 877
888 DCHECK(getExecutionContext()); 878 DCHECK(getExecutionContext());
889 ExecutionContext& executionContext = *getExecutionContext(); 879 ExecutionContext& executionContext = *this->getExecutionContext();
890 880
891 // The presence of upload event listeners forces us to use preflighting beca use POSTing to an URL that does not 881 // The presence of upload event listeners forces us to use preflighting beca use POSTing to an URL that does not
892 // permit cross origin requests should look exactly like POSTing to an URL t hat does not respond at all. 882 // permit cross origin requests should look exactly like POSTing to an URL t hat does not respond at all.
893 // Also, only async requests support upload progress events. 883 // Also, only async requests support upload progress events.
894 bool uploadEvents = false; 884 bool uploadEvents = false;
895 if (m_async) { 885 if (m_async) {
896 InspectorInstrumentation::asyncTaskScheduled(&executionContext, "XMLHttp Request.send", this, true); 886 InspectorInstrumentation::asyncTaskScheduled(&executionContext, "XMLHttp Request.send", this, true);
897 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); 887 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0);
898 if (httpBody && m_upload) { 888 if (httpBody && m_upload) {
899 uploadEvents = m_upload->hasEventListeners(); 889 uploadEvents = m_upload->hasEventListeners();
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 // Set |m_error| in order to suppress the cancel notification (see 1497 // Set |m_error| in order to suppress the cancel notification (see
1508 // XMLHttpRequest::didFail). 1498 // XMLHttpRequest::didFail).
1509 m_error = true; 1499 m_error = true;
1510 m_loader->cancel(); 1500 m_loader->cancel();
1511 m_error = hasError; 1501 m_error = hasError;
1512 m_loader = nullptr; 1502 m_loader = nullptr;
1513 } 1503 }
1514 1504
1515 changeState(kDone); 1505 changeState(kDone);
1516 1506
1517 if (!getExecutionContext() || !getExecutionContext()->isDocument() || !docum ent() || !document()->frame() || !document()->frame()->page()) 1507 if (!getExecutionContext()->isDocument() || !document() || !document()->fram e() || !document()->frame()->page())
1518 return; 1508 return;
1519 1509
1520 if (status() >= 200 && status() < 300) { 1510 if (status() >= 200 && status() < 300) {
1521 document()->frame()->page()->chromeClient().ajaxSucceeded(document()->fr ame()); 1511 document()->frame()->page()->chromeClient().ajaxSucceeded(document()->fr ame());
1522 } 1512 }
1523 } 1513 }
1524 1514
1525 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent) 1515 void XMLHttpRequest::didSendData(unsigned long long bytesSent, unsigned long lon g totalBytesToBeSent)
1526 { 1516 {
1527 NETWORK_DVLOG(1) << this << " didSendData(" << bytesSent << ", " << totalByt esToBeSent << ")"; 1517 NETWORK_DVLOG(1) << this << " didSendData(" << bytesSent << ", " << totalByt esToBeSent << ")";
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 visitor->traceWrappers(m_responseDocument); 1745 visitor->traceWrappers(m_responseDocument);
1756 visitor->traceWrappers(m_responseArrayBuffer); 1746 visitor->traceWrappers(m_responseArrayBuffer);
1757 } 1747 }
1758 1748
1759 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) 1749 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr)
1760 { 1750 {
1761 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); 1751 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr);
1762 } 1752 }
1763 1753
1764 } // namespace blink 1754 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698