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

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

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

Powered by Google App Engine
This is Rietveld 408576698