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

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

Issue 1167563002: Sync the XHR-related interfaces with the spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: data->body Created 5 years, 6 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 | Annotate | Revision Log
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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 } 693 }
694 694
695 // FIXME: According to XMLHttpRequest Level 2 we should throw InvalidAccessE rror exception here. 695 // FIXME: According to XMLHttpRequest Level 2 we should throw InvalidAccessE rror exception here.
696 // However for time being only print warning message to warn web developers. 696 // However for time being only print warning message to warn web developers.
697 if (!m_async) 697 if (!m_async)
698 UseCounter::countDeprecation(executionContext(), UseCounter::SyncXHRWith Credentials); 698 UseCounter::countDeprecation(executionContext(), UseCounter::SyncXHRWith Credentials);
699 699
700 m_includeCredentials = value; 700 m_includeCredentials = value;
701 } 701 }
702 702
703 void XMLHttpRequest::open(const AtomicString& method, const String& url, Excepti onState& exceptionState) 703 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, E xceptionState& exceptionState)
704 { 704 {
705 open(method, url, true, exceptionState); 705 open(method, executionContext()->completeURL(urlString), true, exceptionStat e);
706 } 706 }
707 707
708 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, b ool async, ExceptionState& exceptionState) 708 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, b ool async, const String& username, const String& password, ExceptionState& excep tionState)
709 { 709 {
710 open(method, executionContext()->completeURL(urlString), async, exceptionSta te); 710 KURL url(executionContext()->completeURL(urlString));
711 if (!username.isNull())
712 url.setUser(username);
713 if (!password.isNull())
714 url.setPass(password);
715
716 open(method, url, async, exceptionState);
711 } 717 }
712 718
713 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn c, ExceptionState& exceptionState) 719 void XMLHttpRequest::open(const AtomicString& method, const KURL& url, bool asyn c, ExceptionState& exceptionState)
714 { 720 {
715 WTF_LOG(Network, "XMLHttpRequest %p open('%s', '%s', %d)", this, method.utf8 ().data(), url.elidedString().utf8().data(), async); 721 WTF_LOG(Network, "XMLHttpRequest %p open('%s', '%s', %d)", this, method.utf8 ().data(), url.elidedString().utf8().data(), async);
716 722
717 if (!internalAbort()) 723 if (!internalAbort())
718 return; 724 return;
719 725
720 State previousState = m_state; 726 State previousState = m_state;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 ASSERT(!m_loader); 780 ASSERT(!m_loader);
775 781
776 // Check previous state to avoid dispatching readyState event 782 // Check previous state to avoid dispatching readyState event
777 // when calling open several times in a row. 783 // when calling open several times in a row.
778 if (previousState != OPENED) 784 if (previousState != OPENED)
779 changeState(OPENED); 785 changeState(OPENED);
780 else 786 else
781 m_state = OPENED; 787 m_state = OPENED;
782 } 788 }
783 789
784 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, b ool async, const String& user, ExceptionState& exceptionState)
785 {
786 KURL urlWithCredentials(executionContext()->completeURL(urlString));
787 if (!user.isNull())
788 urlWithCredentials.setUser(user);
789
790 open(method, urlWithCredentials, async, exceptionState);
791 }
792
793 void XMLHttpRequest::open(const AtomicString& method, const String& urlString, b ool async, const String& user, const String& password, ExceptionState& exception State)
794 {
795 KURL urlWithCredentials(executionContext()->completeURL(urlString));
796 if (!user.isNull())
797 urlWithCredentials.setUser(user);
798 if (!password.isNull())
799 urlWithCredentials.setPass(password);
800
801 open(method, urlWithCredentials, async, exceptionState);
802 }
803
804 bool XMLHttpRequest::initSend(ExceptionState& exceptionState) 790 bool XMLHttpRequest::initSend(ExceptionState& exceptionState)
805 { 791 {
806 if (!executionContext()) 792 if (!executionContext())
807 return false; 793 return false;
808 794
809 if (m_state != OPENED || m_loader) { 795 if (m_state != OPENED || m_loader) {
810 exceptionState.throwDOMException(InvalidStateError, "The object's state must be OPENED."); 796 exceptionState.throwDOMException(InvalidStateError, "The object's state must be OPENED.");
811 return false; 797 return false;
812 } 798 }
813 799
814 m_error = false; 800 m_error = false;
815 return true; 801 return true;
816 } 802 }
817 803
818 void XMLHttpRequest::send(const ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrSt ringOrFormData& data, ExceptionState& exceptionState) 804 void XMLHttpRequest::send(const ArrayBufferOrArrayBufferViewOrBlobOrDocumentOrSt ringOrFormData& body, ExceptionState& exceptionState)
819 { 805 {
820 if (data.isNull()) { 806 InspectorInstrumentation::willSendXMLHttpRequest(executionContext(), url());
821 send(exceptionState); 807
808 if (body.isNull()) {
809 send(String(), exceptionState);
822 return; 810 return;
823 } 811 }
824 812
825 InspectorInstrumentation::willSendXMLHttpRequest(executionContext(), url()); 813 if (body.isArrayBuffer()) {
826 if (data.isArrayBuffer()) { 814 send(body.getAsArrayBuffer().get(), exceptionState);
827 send(data.getAsArrayBuffer().get(), exceptionState);
828 return; 815 return;
829 } 816 }
830 817
831 if (data.isArrayBufferView()) { 818 if (body.isArrayBufferView()) {
832 send(data.getAsArrayBufferView().get(), exceptionState); 819 send(body.getAsArrayBufferView().get(), exceptionState);
833 return; 820 return;
834 } 821 }
835 822
836 if (data.isBlob()) { 823 if (body.isBlob()) {
837 send(data.getAsBlob(), exceptionState); 824 send(body.getAsBlob(), exceptionState);
838 return; 825 return;
839 } 826 }
840 827
841 if (data.isDocument()) { 828 if (body.isDocument()) {
842 send(data.getAsDocument().get(), exceptionState); 829 send(body.getAsDocument().get(), exceptionState);
843 return; 830 return;
844 } 831 }
845 832
846 if (data.isFormData()) { 833 if (body.isFormData()) {
847 send(data.getAsFormData(), exceptionState); 834 send(body.getAsFormData(), exceptionState);
848 return; 835 return;
849 } 836 }
850 837
851 ASSERT(data.isString()); 838 ASSERT(body.isString());
852 send(data.getAsString(), exceptionState); 839 send(body.getAsString(), exceptionState);
853 }
854
855 void XMLHttpRequest::send(ExceptionState& exceptionState)
856 {
857 InspectorInstrumentation::willSendXMLHttpRequest(executionContext(), url());
858 send(String(), exceptionState);
859 } 840 }
860 841
861 bool XMLHttpRequest::areMethodAndURLValidForSend() 842 bool XMLHttpRequest::areMethodAndURLValidForSend()
862 { 843 {
863 return m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFami ly(); 844 return m_method != "GET" && m_method != "HEAD" && m_url.protocolIsInHTTPFami ly();
864 } 845 }
865 846
866 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState) 847 void XMLHttpRequest::send(Document* document, ExceptionState& exceptionState)
867 { 848 {
868 WTF_LOG(Network, "XMLHttpRequest %p send() Document %p", this, document); 849 WTF_LOG(Network, "XMLHttpRequest %p send() Document %p", this, document);
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 visitor->trace(m_responseDocumentParser); 1864 visitor->trace(m_responseDocumentParser);
1884 visitor->trace(m_progressEventThrottle); 1865 visitor->trace(m_progressEventThrottle);
1885 visitor->trace(m_upload); 1866 visitor->trace(m_upload);
1886 visitor->trace(m_blobLoader); 1867 visitor->trace(m_blobLoader);
1887 XMLHttpRequestEventTarget::trace(visitor); 1868 XMLHttpRequestEventTarget::trace(visitor);
1888 DocumentParserClient::trace(visitor); 1869 DocumentParserClient::trace(visitor);
1889 ActiveDOMObject::trace(visitor); 1870 ActiveDOMObject::trace(visitor);
1890 } 1871 }
1891 1872
1892 } // namespace blink 1873 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/xmlhttprequest/XMLHttpRequest.h ('k') | Source/core/xmlhttprequest/XMLHttpRequest.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698