OLD | NEW |
---|---|
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 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 | 825 |
826 createRequest(httpBody.release(), exceptionState); | 826 createRequest(httpBody.release(), exceptionState); |
827 } | 827 } |
828 | 828 |
829 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex ceptionState& exceptionState) | 829 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex ceptionState& exceptionState) |
830 { | 830 { |
831 createRequest(formData ? formData->deepCopy() : nullptr, exceptionState); | 831 createRequest(formData ? formData->deepCopy() : nullptr, exceptionState); |
832 m_exceptionCode = exceptionState.code(); | 832 m_exceptionCode = exceptionState.code(); |
833 } | 833 } |
834 | 834 |
835 void XMLHttpRequest::throwForLoadFailureIfNeeded(ExceptionState& exceptionState, const String& reason) | |
836 { | |
837 if (m_error && !m_exceptionCode) | |
838 m_exceptionCode = NetworkError; | |
sof
2015/07/14 07:07:01
Add an early return if !m_exceptionCode ?
tyoshino (SeeGerritForStatus)
2015/07/14 08:48:55
Done.
| |
839 | |
840 String message = "Failed to load '" + m_url.elidedString() + "'"; | |
841 if (!message.isNull()) { | |
842 message.append(": "); | |
843 message.append(reason); | |
844 } | |
845 | |
846 if (m_exceptionCode) | |
847 exceptionState.throwDOMException(m_exceptionCode, message); | |
848 } | |
849 | |
835 void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState & exceptionState) | 850 void XMLHttpRequest::createRequest(PassRefPtr<FormData> httpBody, ExceptionState & exceptionState) |
836 { | 851 { |
837 // Only GET request is supported for blob URL. | 852 // Only GET request is supported for blob URL. |
838 if (m_url.protocolIs("blob") && m_method != "GET") { | 853 if (m_url.protocolIs("blob") && m_method != "GET") { |
839 exceptionState.throwDOMException(NetworkError, "'GET' is the only method allowed for 'blob:' URLs."); | 854 handleNetworkError(); |
855 | |
856 if (!m_async) { | |
857 throwForLoadFailureIfNeeded(exceptionState, "'GET' is the only metho d allowed for 'blob:' URLs."); | |
858 } | |
840 return; | 859 return; |
841 } | 860 } |
842 | 861 |
843 // The presence of upload event listeners forces us to use preflighting beca use POSTing to an URL that does not | 862 // The presence of upload event listeners forces us to use preflighting beca use POSTing to an URL that does not |
844 // permit cross origin requests should look exactly like POSTing to an URL t hat does not respond at all. | 863 // permit cross origin requests should look exactly like POSTing to an URL t hat does not respond at all. |
845 // Also, only async requests support upload progress events. | 864 // Also, only async requests support upload progress events. |
846 bool uploadEvents = false; | 865 bool uploadEvents = false; |
847 if (m_async) { | 866 if (m_async) { |
848 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); | 867 dispatchProgressEvent(EventTypeNames::loadstart, 0, 0); |
849 if (httpBody && m_upload) { | 868 if (httpBody && m_upload) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestAsynchron ous); | 923 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestAsynchron ous); |
905 if (m_upload) | 924 if (m_upload) |
906 request.setReportUploadProgress(true); | 925 request.setReportUploadProgress(true); |
907 | 926 |
908 // ThreadableLoader::create can return null here, for example if we're n o longer attached to a page. | 927 // ThreadableLoader::create can return null here, for example if we're n o longer attached to a page. |
909 // This is true while running onunload handlers. | 928 // This is true while running onunload handlers. |
910 // FIXME: Maybe we need to be able to send XMLHttpRequests from onunload , <http://bugs.webkit.org/show_bug.cgi?id=10904>. | 929 // FIXME: Maybe we need to be able to send XMLHttpRequests from onunload , <http://bugs.webkit.org/show_bug.cgi?id=10904>. |
911 // FIXME: Maybe create() can return null for other reasons too? | 930 // FIXME: Maybe create() can return null for other reasons too? |
912 ASSERT(!m_loader); | 931 ASSERT(!m_loader); |
913 m_loader = ThreadableLoader::create(executionContext, this, request, opt ions, resourceLoaderOptions); | 932 m_loader = ThreadableLoader::create(executionContext, this, request, opt ions, resourceLoaderOptions); |
914 } else { | 933 |
915 // Use count for XHR synchronous requests. | 934 return; |
916 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestSynchrono us); | |
917 ThreadableLoader::loadResourceSynchronously(executionContext, request, * this, options, resourceLoaderOptions); | |
918 } | 935 } |
919 | 936 |
920 if (!m_exceptionCode && m_error) | 937 // Use count for XHR synchronous requests. |
921 m_exceptionCode = NetworkError; | 938 UseCounter::count(&executionContext, UseCounter::XMLHttpRequestSynchronous); |
922 if (m_exceptionCode) | 939 ThreadableLoader::loadResourceSynchronously(executionContext, request, *this , options, resourceLoaderOptions); |
923 exceptionState.throwDOMException(m_exceptionCode, "Failed to load '" + m _url.elidedString() + "'."); | 940 |
941 throwForLoadFailureIfNeeded(exceptionState, String()); | |
924 } | 942 } |
925 | 943 |
926 void XMLHttpRequest::abort() | 944 void XMLHttpRequest::abort() |
927 { | 945 { |
928 WTF_LOG(Network, "XMLHttpRequest %p abort()", this); | 946 WTF_LOG(Network, "XMLHttpRequest %p abort()", this); |
929 | 947 |
930 // internalAbort() clears |m_loader|. Compute |sendFlag| now. | 948 // internalAbort() clears |m_loader|. Compute |sendFlag| now. |
931 // | 949 // |
932 // |sendFlag| corresponds to "the send() flag" defined in the XHR spec. | 950 // |sendFlag| corresponds to "the send() flag" defined in the XHR spec. |
933 // | 951 // |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1667 visitor->trace(m_responseDocumentParser); | 1685 visitor->trace(m_responseDocumentParser); |
1668 visitor->trace(m_progressEventThrottle); | 1686 visitor->trace(m_progressEventThrottle); |
1669 visitor->trace(m_upload); | 1687 visitor->trace(m_upload); |
1670 visitor->trace(m_blobLoader); | 1688 visitor->trace(m_blobLoader); |
1671 XMLHttpRequestEventTarget::trace(visitor); | 1689 XMLHttpRequestEventTarget::trace(visitor); |
1672 DocumentParserClient::trace(visitor); | 1690 DocumentParserClient::trace(visitor); |
1673 ActiveDOMObject::trace(visitor); | 1691 ActiveDOMObject::trace(visitor); |
1674 } | 1692 } |
1675 | 1693 |
1676 } // namespace blink | 1694 } // namespace blink |
OLD | NEW |