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

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

Issue 23465030: Prevent entering XHR methods while loader is being cancelled. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 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
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | Source/core/xml/XMLHttpRequest.idl » ('j') | 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 return xmlHttpRequest.release(); 165 return xmlHttpRequest.release();
166 } 166 }
167 167
168 XMLHttpRequest::XMLHttpRequest(ScriptExecutionContext* context, PassRefPtr<Secur ityOrigin> securityOrigin) 168 XMLHttpRequest::XMLHttpRequest(ScriptExecutionContext* context, PassRefPtr<Secur ityOrigin> securityOrigin)
169 : ActiveDOMObject(context) 169 : ActiveDOMObject(context)
170 , m_async(true) 170 , m_async(true)
171 , m_includeCredentials(false) 171 , m_includeCredentials(false)
172 , m_timeoutMilliseconds(0) 172 , m_timeoutMilliseconds(0)
173 , m_state(UNSENT) 173 , m_state(UNSENT)
174 , m_createdDocument(false) 174 , m_createdDocument(false)
175 , m_preventReentrant(false)
175 , m_error(false) 176 , m_error(false)
176 , m_uploadEventsAllowed(true) 177 , m_uploadEventsAllowed(true)
177 , m_uploadComplete(false) 178 , m_uploadComplete(false)
178 , m_sameOriginRequest(true) 179 , m_sameOriginRequest(true)
179 , m_receivedLength(0) 180 , m_receivedLength(0)
180 , m_lastSendLineNumber(0) 181 , m_lastSendLineNumber(0)
181 , m_exceptionCode(0) 182 , m_exceptionCode(0)
182 , m_progressEventThrottle(this) 183 , m_progressEventThrottle(this)
183 , m_responseTypeCode(ResponseTypeDefault) 184 , m_responseTypeCode(ResponseTypeDefault)
184 , m_protectionTimer(this, &XMLHttpRequest::dropProtection) 185 , m_protectionTimer(this, &XMLHttpRequest::dropProtection)
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 && !name.startsWith(staticData->m_secHeaderPrefix, false); 475 && !name.startsWith(staticData->m_secHeaderPrefix, false);
475 } 476 }
476 477
477 void XMLHttpRequest::open(const String& method, const KURL& url, ExceptionState& es) 478 void XMLHttpRequest::open(const String& method, const KURL& url, ExceptionState& es)
478 { 479 {
479 open(method, url, true, es); 480 open(method, url, true, es);
480 } 481 }
481 482
482 void XMLHttpRequest::open(const String& method, const KURL& url, bool async, Exc eptionState& es) 483 void XMLHttpRequest::open(const String& method, const KURL& url, bool async, Exc eptionState& es)
483 { 484 {
485 if (m_preventReentrant) {
486 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("open", "XMLHttpRequest", "reentrant is not allowed."));
487 return;
488 }
489
484 internalAbort(); 490 internalAbort();
485 State previousState = m_state; 491 State previousState = m_state;
486 m_state = UNSENT; 492 m_state = UNSENT;
487 m_error = false; 493 m_error = false;
488 m_uploadComplete = false; 494 m_uploadComplete = false;
489 495
490 // clear stuff from possible previous load 496 // clear stuff from possible previous load
491 clearResponse(); 497 clearResponse();
492 clearRequest(); 498 clearRequest();
493 499
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 { 565 {
560 KURL urlWithCredentials(url); 566 KURL urlWithCredentials(url);
561 urlWithCredentials.setUser(user); 567 urlWithCredentials.setUser(user);
562 urlWithCredentials.setPass(password); 568 urlWithCredentials.setPass(password);
563 569
564 open(method, urlWithCredentials, async, es); 570 open(method, urlWithCredentials, async, es);
565 } 571 }
566 572
567 bool XMLHttpRequest::initSend(ExceptionState& es) 573 bool XMLHttpRequest::initSend(ExceptionState& es)
568 { 574 {
575 if (m_preventReentrant) {
576 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("send", "XMLHttpRequest", "reentrant is not allowed."));
577 return false;
578 }
579
569 if (!scriptExecutionContext()) 580 if (!scriptExecutionContext())
570 return false; 581 return false;
571 582
572 if (m_state != OPENED || m_loader) { 583 if (m_state != OPENED || m_loader) {
573 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("send", "XMLHttpRequest", "the object's state must be OPENED.")); 584 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("send", "XMLHttpRequest", "the object's state must be OPENED."));
574 return false; 585 return false;
575 } 586 }
576 587
577 m_error = false; 588 m_error = false;
578 return true; 589 return true;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 m_requestEntityBody = FormData::create(data, length); 720 m_requestEntityBody = FormData::create(data, length);
710 if (m_upload) 721 if (m_upload)
711 m_requestEntityBody->setAlwaysStream(true); 722 m_requestEntityBody->setAlwaysStream(true);
712 } 723 }
713 724
714 createRequest(es); 725 createRequest(es);
715 } 726 }
716 727
717 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex ceptionState& es) 728 void XMLHttpRequest::sendForInspectorXHRReplay(PassRefPtr<FormData> formData, Ex ceptionState& es)
718 { 729 {
730 if (m_preventReentrant) {
731 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("sendForInspectorXHRReplay", "XMLHttpRequest", "reentrant is not allowed."));
732 return;
733 }
734
719 m_requestEntityBody = formData ? formData->deepCopy() : 0; 735 m_requestEntityBody = formData ? formData->deepCopy() : 0;
720 createRequest(es); 736 createRequest(es);
721 m_exceptionCode = es.code(); 737 m_exceptionCode = es.code();
722 } 738 }
723 739
724 void XMLHttpRequest::createRequest(ExceptionState& es) 740 void XMLHttpRequest::createRequest(ExceptionState& es)
725 { 741 {
726 // Only GET request is supported for blob URL. 742 // Only GET request is supported for blob URL.
727 if (m_url.protocolIs("blob") && m_method != "GET") { 743 if (m_url.protocolIs("blob") && m_method != "GET") {
728 es.throwDOMException(NetworkError, ExceptionMessages::failedToExecute("s end", "XMLHttpRequest", "'GET' is the only method allowed for 'blob:' URLs.")); 744 es.throwDOMException(NetworkError, ExceptionMessages::failedToExecute("s end", "XMLHttpRequest", "'GET' is the only method allowed for 'blob:' URLs."));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), re quest, *this, options); 819 ThreadableLoader::loadResourceSynchronously(scriptExecutionContext(), re quest, *this, options);
804 InspectorInstrumentation::didLoadXHRSynchronously(scriptExecutionContext ()); 820 InspectorInstrumentation::didLoadXHRSynchronously(scriptExecutionContext ());
805 } 821 }
806 822
807 if (!m_exceptionCode && m_error) 823 if (!m_exceptionCode && m_error)
808 m_exceptionCode = NetworkError; 824 m_exceptionCode = NetworkError;
809 if (m_exceptionCode) 825 if (m_exceptionCode)
810 es.throwDOMException(m_exceptionCode); 826 es.throwDOMException(m_exceptionCode);
811 } 827 }
812 828
813 void XMLHttpRequest::abort() 829 void XMLHttpRequest::abort(ExceptionState& es)
814 { 830 {
831 if (m_preventReentrant) {
832 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("abort", "XMLHttpRequest", "reentrant is not allowed."));
833 return;
834 }
835
815 // internalAbort() calls dropProtection(), which may release the last refere nce. 836 // internalAbort() calls dropProtection(), which may release the last refere nce.
816 RefPtr<XMLHttpRequest> protect(this); 837 RefPtr<XMLHttpRequest> protect(this);
817 838
818 bool sendFlag = m_loader; 839 bool sendFlag = m_loader;
819 840
820 internalAbort(); 841 internalAbort();
821 842
822 clearResponseBuffers(); 843 clearResponseBuffers();
823 844
824 // Clear headers as required by the spec 845 // Clear headers as required by the spec
(...skipping 24 matching lines...) Expand all
849 m_decoder = 0; 870 m_decoder = 0;
850 871
851 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this); 872 InspectorInstrumentation::didFailXHRLoading(scriptExecutionContext(), this);
852 873
853 if (m_responseStream && m_state != DONE) 874 if (m_responseStream && m_state != DONE)
854 m_responseStream->abort(); 875 m_responseStream->abort();
855 876
856 if (!m_loader) 877 if (!m_loader)
857 return; 878 return;
858 879
880 m_preventReentrant = true;
859 m_loader->cancel(); 881 m_loader->cancel();
Nate Chapin 2013/09/19 16:31:30 Is it possible to solve this similarly to http://s
882 m_preventReentrant = false;
860 m_loader = 0; 883 m_loader = 0;
861 884
862 if (async == DropProtectionAsync) 885 if (async == DropProtectionAsync)
863 dropProtectionSoon(); 886 dropProtectionSoon();
864 else 887 else
865 dropProtection(); 888 dropProtection();
866 } 889 }
867 890
868 void XMLHttpRequest::clearResponse() 891 void XMLHttpRequest::clearResponse()
869 { 892 {
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 { 1317 {
1295 return eventNames().interfaceForXMLHttpRequest; 1318 return eventNames().interfaceForXMLHttpRequest;
1296 } 1319 }
1297 1320
1298 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const 1321 ScriptExecutionContext* XMLHttpRequest::scriptExecutionContext() const
1299 { 1322 {
1300 return ActiveDOMObject::scriptExecutionContext(); 1323 return ActiveDOMObject::scriptExecutionContext();
1301 } 1324 }
1302 1325
1303 } // namespace WebCore 1326 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/xml/XMLHttpRequest.h ('k') | Source/core/xml/XMLHttpRequest.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698