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

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

Issue 1060113004: [XMLHttpRequest] Stop throwing for network error in async mode (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebease Created 5 years, 5 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/xmlhttprequest/XMLHttpRequest.h ('k') | no next file » | 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) 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 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 830
831 createRequest(httpBody.release(), exceptionState); 831 createRequest(httpBody.release(), exceptionState);
832 } 832 }
833 833
834 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex ceptionState& exceptionState) 834 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex ceptionState& exceptionState)
835 { 835 {
836 createRequest(formData ? formData->deepCopy() : nullptr, exceptionState); 836 createRequest(formData ? formData->deepCopy() : nullptr, exceptionState);
837 m_exceptionCode = exceptionState.code(); 837 m_exceptionCode = exceptionState.code();
838 } 838 }
839 839
840 void XMLHttpRequest::throwForLoadFailureIfNeeded(ExceptionState& exceptionState, const String& reason)
841 {
842 if (m_error && !m_exceptionCode)
843 m_exceptionCode = NetworkError;
844
845 if (!m_exceptionCode)
846 return;
847
848 String message = "Failed to load '" + m_url.elidedString() + "'";
849 if (reason.isNull()) {
850 message.append(".");
851 } else {
852 message.append(": ");
853 message.append(reason);
854 }
855
856 exceptionState.throwDOMException(m_exceptionCode, message);
857 }
858
840 void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState & exceptionState) 859 void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState & exceptionState)
841 { 860 {
842 // Only GET request is supported for blob URL. 861 // Only GET request is supported for blob URL.
843 if (m_url.protocolIs("blob") && m_method != "GET") { 862 if (m_url.protocolIs("blob") && m_method != "GET") {
844 exceptionState.throwDOMException(NetworkError, "'GET' is the only method allowed for 'blob:' URLs."); 863 handleNetworkError();
864
865 if (!m_async) {
866 throwForLoadFailureIfNeeded(exceptionState, "'GET' is the only metho d allowed for 'blob:' URLs.");
867 }
845 return; 868 return;
846 } 869 }
847 870
848 // The presence of upload event listeners forces us to use preflighting beca use POSTing to an URL that does not 871 // The presence of upload event listeners forces us to use preflighting beca use POSTing to an URL that does not
849 // permit cross origin requests should look exactly like POSTing to an URL t hat does not respond at all. 872 // permit cross origin requests should look exactly like POSTing to an URL t hat does not respond at all.
850 // Also, only async requests support upload progress events. 873 // Also, only async requests support upload progress events.
851 bool uploadEvents = false; 874 bool uploadEvents = false;
852 if (m_async) { 875 if (m_async) {
853 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); 876 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0);
854 if (httpBody && m_upload) { 877 if (httpBody && m_upload) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestAsynchron ous); 932 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestAsynchron ous);
910 if (m_upload) 933 if (m_upload)
911 request.setReportUploadProgress(true); 934 request.setReportUploadProgress(true);
912 935
913 // ThreadableLoader::create can return null here, for example if we're n o longer attached to a page. 936 // ThreadableLoader::create can return null here, for example if we're n o longer attached to a page.
914 // This is true while running onunload handlers. 937 // This is true while running onunload handlers.
915 // FIXME: Maybe we need to be able to send XMLHttpRequests from onunload , <http://bugs.webkit.org/show_bug.cgi?id=10904>. 938 // FIXME: Maybe we need to be able to send XMLHttpRequests from onunload , <http://bugs.webkit.org/show_bug.cgi?id=10904>.
916 // FIXME: Maybe create() can return null for other reasons too? 939 // FIXME: Maybe create() can return null for other reasons too?
917 ASSERT(!m_loader); 940 ASSERT(!m_loader);
918 m_loader = ThreadableLoader::create(executionContext, this, request, opt ions, resourceLoaderOptions); 941 m_loader = ThreadableLoader::create(executionContext, this, request, opt ions, resourceLoaderOptions);
919 } else { 942
920 // Use count for XHR synchronous requests. 943 return;
921 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestSynchrono us);
922 ThreadableLoader::loadResourceSynchronously(executionContext, request, * this, options, resourceLoaderOptions);
923 } 944 }
924 945
925 if (!m_exceptionCode && m_error) 946 // Use count for XHR synchronous requests.
926 m_exceptionCode = NetworkError; 947 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestSynchronous);
927 if (m_exceptionCode) 948 ThreadableLoader::loadResourceSynchronously(executionContext, request, *this , options, resourceLoaderOptions);
928 exceptionState.throwDOMException(m_exceptionCode, "Failed to load '" + m _url.elidedString() + "'."); 949
950 throwForLoadFailureIfNeeded(exceptionState, String());
929 } 951 }
930 952
931 void XMLHttpRequest::abort() 953 void XMLHttpRequest::abort()
932 { 954 {
933 WTF_LOG(Network, "XMLHttpRequest %p abort()", this); 955 WTF_LOG(Network, "XMLHttpRequest %p abort()", this);
934 956
935 // internalAbort() clears |m_loader|. Compute |sendFlag| now. 957 // internalAbort() clears |m_loader|. Compute |sendFlag| now.
936 // 958 //
937 // |sendFlag| corresponds to "the send() flag" defined in the XHR spec. 959 // |sendFlag| corresponds to "the send() flag" defined in the XHR spec.
938 // 960 //
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 visitor->trace(m_responseDocumentParser); 1693 visitor->trace(m_responseDocumentParser);
1672 visitor->trace(m_progressEventThrottle); 1694 visitor->trace(m_progressEventThrottle);
1673 visitor->trace(m_upload); 1695 visitor->trace(m_upload);
1674 visitor->trace(m_blobLoader); 1696 visitor->trace(m_blobLoader);
1675 XMLHttpRequestEventTarget::trace(visitor); 1697 XMLHttpRequestEventTarget::trace(visitor);
1676 DocumentParserClient::trace(visitor); 1698 DocumentParserClient::trace(visitor);
1677 ActiveDOMObject::trace(visitor); 1699 ActiveDOMObject::trace(visitor);
1678 } 1700 }
1679 1701
1680 } // namespace blink 1702 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/xmlhttprequest/XMLHttpRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698