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 |
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 ASSERT(m_responseTypeCode == ResponseTypeJSON); | 227 ASSERT(m_responseTypeCode == ResponseTypeJSON); |
229 | 228 |
230 if (m_error || m_state != DONE) | 229 if (m_error || m_state != DONE) |
231 return ScriptString(); | 230 return ScriptString(); |
232 return m_responseText; | 231 return m_responseText; |
233 } | 232 } |
234 | 233 |
235 Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState) | 234 Document* XMLHttpRequest::responseXML(ExceptionState& exceptionState) |
236 { | 235 { |
237 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeDocument) { | 236 if (m_responseTypeCode != ResponseTypeDefault && m_responseTypeCode != Respo
nseTypeDocument) { |
238 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f
ailedToGet("responseXML", "XMLHttpRequest", "The value is only accessible if the
object's 'responseType' is '' or 'document' (was '" + responseType() + "').")); | 237 exceptionState.throwDOMException(InvalidStateError, "The value is only a
ccessible if the object's 'responseType' is '' or 'document' (was '" + responseT
ype() + "')."); |
239 return 0; | 238 return 0; |
240 } | 239 } |
241 | 240 |
242 if (m_error || m_state != DONE) | 241 if (m_error || m_state != DONE) |
243 return 0; | 242 return 0; |
244 | 243 |
245 if (!m_createdDocument) { | 244 if (!m_createdDocument) { |
246 bool isHTML = equalIgnoringCase(responseMIMEType(), "text/html"); | 245 bool isHTML = equalIgnoringCase(responseMIMEType(), "text/html"); |
247 | 246 |
248 // The W3C spec requires the final MIME type to be some valid XML type,
or text/html. | 247 // The W3C spec requires the final MIME type to be some valid XML type,
or text/html. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 return 0; | 329 return 0; |
331 | 330 |
332 return m_responseStream.get(); | 331 return m_responseStream.get(); |
333 } | 332 } |
334 | 333 |
335 void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionState& exception
State) | 334 void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionState& exception
State) |
336 { | 335 { |
337 // FIXME: Need to trigger or update the timeout Timer here, if needed. http:
//webkit.org/b/98156 | 336 // FIXME: Need to trigger or update the timeout Timer here, if needed. http:
//webkit.org/b/98156 |
338 // 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." | 337 // 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." |
339 if (executionContext()->isDocument() && !m_async) { | 338 if (executionContext()->isDocument() && !m_async) { |
340 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::
failedToSet("timeout", "XMLHttpRequest", "Timeouts cannot be set for synchronous
requests made from a document.")); | 339 exceptionState.throwDOMException(InvalidAccessError, "Timeouts cannot be
set for synchronous requests made from a document."); |
341 return; | 340 return; |
342 } | 341 } |
343 m_timeoutMilliseconds = timeout; | 342 m_timeoutMilliseconds = timeout; |
344 } | 343 } |
345 | 344 |
346 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState&
exceptionState) | 345 void XMLHttpRequest::setResponseType(const String& responseType, ExceptionState&
exceptionState) |
347 { | 346 { |
348 if (m_state >= LOADING) { | 347 if (m_state >= LOADING) { |
349 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f
ailedToSet("responseType", "XMLHttpRequest", "The response type cannot be set if
the object's state is LOADING or DONE.")); | 348 exceptionState.throwDOMException(InvalidStateError, "The response type c
annot be set if the object's state is LOADING or DONE."); |
350 return; | 349 return; |
351 } | 350 } |
352 | 351 |
353 // Newer functionality is not available to synchronous requests in window co
ntexts, as a spec-mandated | 352 // Newer functionality is not available to synchronous requests in window co
ntexts, as a spec-mandated |
354 // attempt to discourage synchronous XHR use. responseType is one such piece
of functionality. | 353 // attempt to discourage synchronous XHR use. responseType is one such piece
of functionality. |
355 // We'll only disable this functionality for HTTP(S) requests since sync req
uests for local protocols | 354 // We'll only disable this functionality for HTTP(S) requests since sync req
uests for local protocols |
356 // such as file: and data: still make sense to allow. | 355 // such as file: and data: still make sense to allow. |
357 if (!m_async && executionContext()->isDocument() && m_url.protocolIsInHTTPFa
mily()) { | 356 if (!m_async && executionContext()->isDocument() && m_url.protocolIsInHTTPFa
mily()) { |
358 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages::
failedToSet("responseType", "XMLHttpRequest", "The response type can only be cha
nged for asynchronous HTTP requests made from a document.")); | 357 exceptionState.throwDOMException(InvalidAccessError, "The response type
can only be changed for asynchronous HTTP requests made from a document."); |
359 return; | 358 return; |
360 } | 359 } |
361 | 360 |
362 if (responseType == "") { | 361 if (responseType == "") { |
363 m_responseTypeCode = ResponseTypeDefault; | 362 m_responseTypeCode = ResponseTypeDefault; |
364 } else if (responseType == "text") { | 363 } else if (responseType == "text") { |
365 m_responseTypeCode = ResponseTypeText; | 364 m_responseTypeCode = ResponseTypeText; |
366 } else if (responseType == "json") { | 365 } else if (responseType == "json") { |
367 m_responseTypeCode = ResponseTypeJSON; | 366 m_responseTypeCode = ResponseTypeJSON; |
368 } else if (responseType == "document") { | 367 } else if (responseType == "document") { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDi
spatchXHRLoadEvent(executionContext(), this); | 439 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willDi
spatchXHRLoadEvent(executionContext(), this); |
441 dispatchThrottledProgressEventSnapshot(EventTypeNames::load); | 440 dispatchThrottledProgressEventSnapshot(EventTypeNames::load); |
442 InspectorInstrumentation::didDispatchXHRLoadEvent(cookie); | 441 InspectorInstrumentation::didDispatchXHRLoadEvent(cookie); |
443 dispatchThrottledProgressEventSnapshot(EventTypeNames::loadend); | 442 dispatchThrottledProgressEventSnapshot(EventTypeNames::loadend); |
444 } | 443 } |
445 } | 444 } |
446 | 445 |
447 void XMLHttpRequest::setWithCredentials(bool value, ExceptionState& exceptionSta
te) | 446 void XMLHttpRequest::setWithCredentials(bool value, ExceptionState& exceptionSta
te) |
448 { | 447 { |
449 if (m_state > OPENED || m_loader) { | 448 if (m_state > OPENED || m_loader) { |
450 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f
ailedToSet("withCredentials", "XMLHttpRequest", "The value may only be set if th
e object's state is UNSENT or OPENED.")); | 449 exceptionState.throwDOMException(InvalidStateError, "The value may only
be set if the object's state is UNSENT or OPENED."); |
451 return; | 450 return; |
452 } | 451 } |
453 | 452 |
454 m_includeCredentials = value; | 453 m_includeCredentials = value; |
455 } | 454 } |
456 | 455 |
457 bool XMLHttpRequest::isAllowedHTTPMethod(const String& method) | 456 bool XMLHttpRequest::isAllowedHTTPMethod(const String& method) |
458 { | 457 { |
459 return !equalIgnoringCase(method, "TRACE") | 458 return !equalIgnoringCase(method, "TRACE") |
460 && !equalIgnoringCase(method, "TRACK") | 459 && !equalIgnoringCase(method, "TRACK") |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 } | 1047 } |
1049 | 1048 |
1050 void XMLHttpRequest::overrideMimeType(const AtomicString& override) | 1049 void XMLHttpRequest::overrideMimeType(const AtomicString& override) |
1051 { | 1050 { |
1052 m_mimeTypeOverride = override; | 1051 m_mimeTypeOverride = override; |
1053 } | 1052 } |
1054 | 1053 |
1055 void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicStri
ng& value, ExceptionState& exceptionState) | 1054 void XMLHttpRequest::setRequestHeader(const AtomicString& name, const AtomicStri
ng& value, ExceptionState& exceptionState) |
1056 { | 1055 { |
1057 if (m_state != OPENED || m_loader) { | 1056 if (m_state != OPENED || m_loader) { |
1058 exceptionState.throwDOMException(InvalidStateError, ExceptionMessages::f
ailedToExecute("setRequestHeader", "XMLHttpRequest", "The object's state must be
OPENED.")); | 1057 exceptionState.throwDOMException(InvalidStateError, "The object's state
must be OPENED."); |
1059 return; | 1058 return; |
1060 } | 1059 } |
1061 | 1060 |
1062 if (!isValidHTTPToken(name)) { | 1061 if (!isValidHTTPToken(name)) { |
1063 exceptionState.throwDOMException(SyntaxError, ExceptionMessages::failedT
oExecute("setRequestHeader", "XMLHttpRequest", "'" + name + "' is not a valid HT
TP header field name.")); | 1062 exceptionState.throwDOMException(SyntaxError, "'" + name + "' is not a v
alid HTTP header field name."); |
1064 return; | 1063 return; |
1065 } | 1064 } |
1066 | 1065 |
1067 if (!isValidHTTPHeaderValue(value)) { | 1066 if (!isValidHTTPHeaderValue(value)) { |
1068 exceptionState.throwDOMException(SyntaxError, ExceptionMessages::failedT
oExecute("setRequestHeader", "XMLHttpRequest", "'" + value + "' is not a valid H
TTP header field value.")); | 1067 exceptionState.throwDOMException(SyntaxError, "'" + value + "' is not a
valid HTTP header field value."); |
1069 return; | 1068 return; |
1070 } | 1069 } |
1071 | 1070 |
1072 // No script (privileged or not) can set unsafe headers. | 1071 // No script (privileged or not) can set unsafe headers. |
1073 if (!isAllowedHTTPHeader(name)) { | 1072 if (!isAllowedHTTPHeader(name)) { |
1074 logConsoleError(executionContext(), "Refused to set unsafe header \"" +
name + "\""); | 1073 logConsoleError(executionContext(), "Refused to set unsafe header \"" +
name + "\""); |
1075 return; | 1074 return; |
1076 } | 1075 } |
1077 | 1076 |
1078 setRequestHeaderInternal(name, value); | 1077 setRequestHeaderInternal(name, value); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 { | 1392 { |
1394 return EventTargetNames::XMLHttpRequest; | 1393 return EventTargetNames::XMLHttpRequest; |
1395 } | 1394 } |
1396 | 1395 |
1397 ExecutionContext* XMLHttpRequest::executionContext() const | 1396 ExecutionContext* XMLHttpRequest::executionContext() const |
1398 { | 1397 { |
1399 return ActiveDOMObject::executionContext(); | 1398 return ActiveDOMObject::executionContext(); |
1400 } | 1399 } |
1401 | 1400 |
1402 } // namespace WebCore | 1401 } // namespace WebCore |
OLD | NEW |