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

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

Issue 99083002: WIP: Migrate generated bindings to new ExceptionState constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase. Created 7 years 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/workers/WorkerGlobalScope.cpp ('k') | Source/core/xml/XPathEvaluator.cpp » ('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
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details. 16 * Lesser General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Lesser General Public 18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software 19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 U SA 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 U SA
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24 #include "core/xml/XMLHttpRequest.h" 24 #include "core/xml/XMLHttpRequest.h"
25 25
26 #include "FetchInitiatorTypeNames.h" 26 #include "FetchInitiatorTypeNames.h"
27 #include "RuntimeEnabledFeatures.h" 27 #include "RuntimeEnabledFeatures.h"
28 #include "bindings/v8/ExceptionMessages.h"
29 #include "bindings/v8/ExceptionState.h" 28 #include "bindings/v8/ExceptionState.h"
30 #include "core/dom/ContextFeatures.h" 29 #include "core/dom/ContextFeatures.h"
31 #include "core/dom/DOMImplementation.h" 30 #include "core/dom/DOMImplementation.h"
32 #include "core/dom/ExceptionCode.h" 31 #include "core/dom/ExceptionCode.h"
33 #include "core/editing/markup.h" 32 #include "core/editing/markup.h"
34 #include "core/events/Event.h" 33 #include "core/events/Event.h"
35 #include "core/fetch/CrossOriginAccessControl.h" 34 #include "core/fetch/CrossOriginAccessControl.h"
36 #include "core/fetch/TextResourceDecoder.h" 35 #include "core/fetch/TextResourceDecoder.h"
37 #include "core/fileapi/Blob.h" 36 #include "core/fileapi/Blob.h"
38 #include "core/fileapi/File.h" 37 #include "core/fileapi/File.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 ASSERT(m_responseTypeCode == ResponseTypeJSON); 228 ASSERT(m_responseTypeCode == ResponseTypeJSON);
230 229
231 if (m_error || m_state != DONE) 230 if (m_error || m_state != DONE)
232 return ScriptString(); 231 return ScriptString();
233 return m_responseText; 232 return m_responseText;
234 } 233 }
235 234
236 Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState) 235 Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState)
237 { 236 {
238 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo nseTypeDocument) { 237 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo nseTypeDocument) {
239 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToGet("responseXML", "XMLHttpRequest", "The value is only accessible if the object's 'responseType' is '' or 'document' (was '" + responseType() + "').")); 238 exceptionState.throwDOMException(InvalidStateError, "The value is only a ccessible if the object's 'responseType' is '' or 'document' (was '" + responseT ype() + "').");
240 return 0; 239 return 0;
241 } 240 }
242 241
243 if (m_error || m_state != DONE) 242 if (m_error || m_state != DONE)
244 return 0; 243 return 0;
245 244
246 if (!m_createdDocument) { 245 if (!m_createdDocument) {
247 bool isHTML = equalIgnoringCase(responseMIMEType(), "text/html"); 246 bool isHTML = equalIgnoringCase(responseMIMEType(), "text/html");
248 247
249 // The W3C spec requires the final MIME type to be some valid XML type, or text/html. 248 // The W3C spec requires the final MIME type to be some valid XML type, or text/html.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return 0; 325 return 0;
327 326
328 return m_responseStream.get(); 327 return m_responseStream.get();
329 } 328 }
330 329
331 void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionState& exception State) 330 void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionState& exception State)
332 { 331 {
333 // FIXME: Need to trigger or update the timeout Timer here, if needed. http: //webkit.org/b/98156 332 // FIXME: Need to trigger or update the timeout Timer here, if needed. http: //webkit.org/b/98156
334 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set whi le fetching is in progress. If that occurs it will still be measured relative to the start of fetching." 333 // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set whi le fetching is in progress. If that occurs it will still be measured relative to the start of fetching."
335 if (executionContext()->isDocument() && !m_async) { 334 if (executionContext()->isDocument() && !m_async) {
336 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: failedToSet("timeout", "XMLHttpRequest", "Timeouts cannot be set for synchronous requests made from a document.")); 335 exceptionState.throwDOMException(InvalidAccessError, "Timeouts cannot be set for synchronous requests made from a document.");
337 return; 336 return;
338 } 337 }
339 m_timeoutMilliseconds = timeout; 338 m_timeoutMilliseconds = timeout;
340 } 339 }
341 340
342 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState& exceptionState) 341 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState& exceptionState)
343 { 342 {
344 if (m_state >= LOADING) { 343 if (m_state >= LOADING) {
345 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToSet("responseType", "XMLHttpRequest", "The response type cannot be set if the object's state is LOADING or DONE.")); 344 exceptionState.throwDOMException(InvalidStateError, "The response type c annot be set if the object's state is LOADING or DONE.");
346 return; 345 return;
347 } 346 }
348 347
349 // Newer functionality is not available to synchronous requests in window co ntexts, as a spec-mandated 348 // Newer functionality is not available to synchronous requests in window co ntexts, as a spec-mandated
350 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality. 349 // attempt to discourage synchronous XHR use. responseType is one such piece of functionality.
351 // We'll only disable this functionality for HTTP(S) requests since sync req uests for local protocols 350 // We'll only disable this functionality for HTTP(S) requests since sync req uests for local protocols
352 // such as file: and data: still make sense to allow. 351 // such as file: and data: still make sense to allow.
353 if (!m_async && executionContext()->isDocument() && m_url.protocolIsInHTTPFa mily()) { 352 if (!m_async && executionContext()->isDocument() && m_url.protocolIsInHTTPFa mily()) {
354 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: failedToSet("responseType", "XMLHttpRequest", "The response type can only be cha nged for asynchronous HTTP requests made from a document.")); 353 exceptionState.throwDOMException(InvalidAccessError, "The response type can only be changed for asynchronous HTTP requests made from a document.");
355 return; 354 return;
356 } 355 }
357 356
358 if (responseType == "") { 357 if (responseType == "") {
359 m_responseTypeCode = ResponseTypeDefault; 358 m_responseTypeCode = ResponseTypeDefault;
360 } else if (responseType == "text") { 359 } else if (responseType == "text") {
361 m_responseTypeCode = ResponseTypeText; 360 m_responseTypeCode = ResponseTypeText;
362 } else if (responseType == "json") { 361 } else if (responseType == "json") {
363 m_responseTypeCode = ResponseTypeJSON; 362 m_responseTypeCode = ResponseTypeJSON;
364 } else if (responseType == "document") { 363 } else if (responseType == "document") {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDi spatchXHRLoadEvent(executionContext(), this); 454 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDi spatchXHRLoadEvent(executionContext(), this);
456 dispatchThrottledProgressEventSnapshot(EventTypeNames::load); 455 dispatchThrottledProgressEventSnapshot(EventTypeNames::load);
457 InspectorInstrumentation::didDispatchXHRLoadEvent(cookie); 456 InspectorInstrumentation::didDispatchXHRLoadEvent(cookie);
458 dispatchThrottledProgressEventSnapshot(EventTypeNames::loadend); 457 dispatchThrottledProgressEventSnapshot(EventTypeNames::loadend);
459 } 458 }
460 } 459 }
461 460
462 void XMLHttpRequest::setWithCredentials(bool value, ExceptionState& exceptionSta te) 461 void XMLHttpRequest::setWithCredentials(bool value, ExceptionState& exceptionSta te)
463 { 462 {
464 if (m_state > OPENED || m_loader) { 463 if (m_state > OPENED || m_loader) {
465 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToSet("withCredentials", "XMLHttpRequest", "The value may only be set if th e object's state is UNSENT or OPENED.")); 464 exceptionState.throwDOMException(InvalidStateError, "The value may only be set if the object's state is UNSENT or OPENED.");
466 return; 465 return;
467 } 466 }
468 467
469 m_includeCredentials = value; 468 m_includeCredentials = value;
470 } 469 }
471 470
472 bool XMLHttpRequest::isAllowedHTTPMethod(const String& method) 471 bool XMLHttpRequest::isAllowedHTTPMethod(const String& method)
473 { 472 {
474 return !equalIgnoringCase(method, "TRACE") 473 return !equalIgnoringCase(method, "TRACE")
475 && !equalIgnoringCase(method, "TRACK") 474 && !equalIgnoringCase(method, "TRACK")
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } 1074 }
1076 1075
1077 void XMLHttpRequest::overrideMimeType(const AtomicString& override) 1076 void XMLHttpRequest::overrideMimeType(const AtomicString& override)
1078 { 1077 {
1079 m_mimeTypeOverride = override; 1078 m_mimeTypeOverride = override;
1080 } 1079 }
1081 1080
1082 void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicStri ng& value, ExceptionState& exceptionState) 1081 void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicStri ng& value, ExceptionState& exceptionState)
1083 { 1082 {
1084 if (m_state != OPENED || m_loader) { 1083 if (m_state != OPENED || m_loader) {
1085 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f ailedToExecute("setRequestHeader", "XMLHttpRequest", "The object's state must be OPENED.")); 1084 exceptionState.throwDOMException(InvalidStateError, "The object's state must be OPENED.");
1086 return; 1085 return;
1087 } 1086 }
1088 1087
1089 if (!isValidHTTPToken(name)) { 1088 if (!isValidHTTPToken(name)) {
1090 exceptionState.throwDOMException(SyntaxError, ExceptionMessages::failedT oExecute("setRequestHeader", "XMLHttpRequest", "'" + name + "' is not a valid HT TP header field name.")); 1089 exceptionState.throwDOMException(SyntaxError, "'" + name + "' is not a v alid HTTP header field name.");
1091 return; 1090 return;
1092 } 1091 }
1093 1092
1094 if (!isValidHTTPHeaderValue(value)) { 1093 if (!isValidHTTPHeaderValue(value)) {
1095 exceptionState.throwDOMException(SyntaxError, ExceptionMessages::failedT oExecute("setRequestHeader", "XMLHttpRequest", "'" + value + "' is not a valid H TTP header field value.")); 1094 exceptionState.throwDOMException(SyntaxError, "'" + value + "' is not a valid HTTP header field value.");
1096 return; 1095 return;
1097 } 1096 }
1098 1097
1099 // No script (privileged or not) can set unsafe headers. 1098 // No script (privileged or not) can set unsafe headers.
1100 if (!isAllowedHTTPHeader(name)) { 1099 if (!isAllowedHTTPHeader(name)) {
1101 logConsoleError(executionContext(), "Refused to set unsafe header \"" + name + "\""); 1100 logConsoleError(executionContext(), "Refused to set unsafe header \"" + name + "\"");
1102 return; 1101 return;
1103 } 1102 }
1104 1103
1105 setRequestHeaderInternal(name, value); 1104 setRequestHeaderInternal(name, value);
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 { 1427 {
1429 return EventTargetNames::XMLHttpRequest; 1428 return EventTargetNames::XMLHttpRequest;
1430 } 1429 }
1431 1430
1432 ExecutionContext* XMLHttpRequest::executionContext() const 1431 ExecutionContext* XMLHttpRequest::executionContext() const
1433 { 1432 {
1434 return ActiveDOMObject::executionContext(); 1433 return ActiveDOMObject::executionContext();
1435 } 1434 }
1436 1435
1437 } // namespace WebCore 1436 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/workers/WorkerGlobalScope.cpp ('k') | Source/core/xml/XPathEvaluator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698