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