XMLHttpRequest.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_XMLHttpRequest_h
  6. #define mozilla_dom_XMLHttpRequest_h
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/dom/XMLHttpRequestEventTarget.h"
  9. #include "mozilla/dom/XMLHttpRequestBinding.h"
  10. #include "nsIXMLHttpRequest.h"
  11. class nsIJSID;
  12. namespace mozilla {
  13. namespace dom {
  14. class Blob;
  15. class DOMString;
  16. class FormData;
  17. class URLSearchParams;
  18. class XMLHttpRequestUpload;
  19. class XMLHttpRequest : public XMLHttpRequestEventTarget
  20. {
  21. public:
  22. static already_AddRefed<XMLHttpRequest>
  23. Constructor(const GlobalObject& aGlobal,
  24. const MozXMLHttpRequestParameters& aParams,
  25. ErrorResult& aRv);
  26. static already_AddRefed<XMLHttpRequest>
  27. Constructor(const GlobalObject& aGlobal, const nsAString& ignored,
  28. ErrorResult& aRv)
  29. {
  30. // Pretend like someone passed null, so we can pick up the default values
  31. MozXMLHttpRequestParameters params;
  32. if (!params.Init(aGlobal.Context(), JS::NullHandleValue)) {
  33. aRv.Throw(NS_ERROR_UNEXPECTED);
  34. return nullptr;
  35. }
  36. return Constructor(aGlobal, params, aRv);
  37. }
  38. IMPL_EVENT_HANDLER(readystatechange)
  39. virtual uint16_t
  40. ReadyState() const = 0;
  41. virtual void
  42. Open(const nsACString& aMethod, const nsAString& aUrl, ErrorResult& aRv) = 0;
  43. virtual void
  44. Open(const nsACString& aMethod, const nsAString& aUrl, bool aAsync,
  45. const nsAString& aUser, const nsAString& aPassword, ErrorResult& aRv) = 0;
  46. virtual void
  47. SetRequestHeader(const nsACString& aHeader, const nsACString& aValue,
  48. ErrorResult& aRv) = 0;
  49. virtual uint32_t
  50. Timeout() const = 0;
  51. virtual void
  52. SetTimeout(uint32_t aTimeout, ErrorResult& aRv) = 0;
  53. virtual bool
  54. WithCredentials() const = 0;
  55. virtual void
  56. SetWithCredentials(bool aWithCredentials, ErrorResult& aRv) = 0;
  57. virtual XMLHttpRequestUpload*
  58. GetUpload(ErrorResult& aRv) = 0;
  59. virtual void
  60. Send(JSContext* aCx, ErrorResult& aRv) = 0;
  61. virtual void
  62. Send(JSContext* aCx, const ArrayBuffer& aArrayBuffer, ErrorResult& aRv) = 0;
  63. virtual void
  64. Send(JSContext* aCx, const ArrayBufferView& aArrayBufferView,
  65. ErrorResult& aRv) = 0;
  66. virtual void
  67. Send(JSContext* aCx, Blob& aBlob, ErrorResult& aRv) = 0;
  68. virtual void
  69. Send(JSContext* aCx, URLSearchParams& aURLSearchParams, ErrorResult& aRv) = 0;
  70. virtual void
  71. Send(JSContext* aCx, nsIDocument& aDoc, ErrorResult& aRv) = 0;
  72. virtual void
  73. Send(JSContext* aCx, const nsAString& aString, ErrorResult& aRv) = 0;
  74. virtual void
  75. Send(JSContext* aCx, FormData& aFormData, ErrorResult& aRv) = 0;
  76. virtual void
  77. Send(JSContext* aCx, nsIInputStream* aStream, ErrorResult& aRv) = 0;
  78. virtual void
  79. Abort(ErrorResult& aRv) = 0;
  80. virtual void
  81. GetResponseURL(nsAString& aUrl) = 0;
  82. virtual uint32_t
  83. GetStatus(ErrorResult& aRv) = 0;
  84. virtual void
  85. GetStatusText(nsACString& aStatusText, ErrorResult& aRv) = 0;
  86. virtual void
  87. GetResponseHeader(const nsACString& aHeader, nsACString& aResult,
  88. ErrorResult& aRv) = 0;
  89. virtual void
  90. GetAllResponseHeaders(nsACString& aResponseHeaders,
  91. ErrorResult& aRv) = 0;
  92. virtual void
  93. OverrideMimeType(const nsAString& aMimeType, ErrorResult& aRv) = 0;
  94. virtual XMLHttpRequestResponseType
  95. ResponseType() const = 0;
  96. virtual void
  97. SetResponseType(XMLHttpRequestResponseType aType,
  98. ErrorResult& aRv) = 0;
  99. virtual void
  100. GetResponse(JSContext* aCx, JS::MutableHandle<JS::Value> aResponse,
  101. ErrorResult& aRv) = 0;
  102. virtual void
  103. GetResponseText(DOMString& aResponseText, ErrorResult& aRv) = 0;
  104. virtual nsIDocument*
  105. GetResponseXML(ErrorResult& aRv) = 0;
  106. virtual bool
  107. MozBackgroundRequest() const = 0;
  108. virtual void
  109. SetMozBackgroundRequest(bool aMozBackgroundRequest, ErrorResult& aRv) = 0;
  110. virtual nsIChannel*
  111. GetChannel() const = 0;
  112. virtual void
  113. GetNetworkInterfaceId(nsACString& aId) const = 0;
  114. virtual void
  115. SetNetworkInterfaceId(const nsACString& aId) = 0;
  116. // We need a GetInterface callable from JS for chrome JS
  117. virtual void
  118. GetInterface(JSContext* aCx, nsIJSID* aIID,
  119. JS::MutableHandle<JS::Value> aRetval,
  120. ErrorResult& aRv) = 0;
  121. virtual void
  122. SetOriginAttributes(const mozilla::dom::OriginAttributesDictionary& aAttrs) = 0;
  123. virtual bool
  124. MozAnon() const = 0;
  125. virtual bool
  126. MozSystem() const = 0;
  127. virtual JSObject*
  128. WrapObject(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override
  129. {
  130. return mozilla::dom::XMLHttpRequestBinding::Wrap(aCx, this, aGivenProto);
  131. }
  132. };
  133. } // dom namespace
  134. } // mozilla namespace
  135. #endif // mozilla_dom_XMLHttpRequest_h