Request.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_Request_h
  6. #define mozilla_dom_Request_h
  7. #include "nsIContentPolicy.h"
  8. #include "nsISupportsImpl.h"
  9. #include "nsWrapperCache.h"
  10. #include "mozilla/dom/Fetch.h"
  11. #include "mozilla/dom/AbortSignal.h"
  12. #include "mozilla/dom/InternalRequest.h"
  13. // Required here due to certain WebIDL enums/classes being declared in both
  14. // files.
  15. #include "mozilla/dom/RequestBinding.h"
  16. namespace mozilla {
  17. namespace dom {
  18. class Headers;
  19. class InternalHeaders;
  20. class RequestOrUSVString;
  21. class Request final : public nsISupports
  22. , public FetchBody<Request>
  23. , public nsWrapperCache
  24. {
  25. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  26. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Request)
  27. public:
  28. Request(nsIGlobalObject* aOwner, InternalRequest* aRequest, AbortSignal* aSignal);
  29. static bool
  30. RequestContextEnabled(JSContext* aCx, JSObject* aObj);
  31. JSObject*
  32. WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
  33. {
  34. return RequestBinding::Wrap(aCx, this, aGivenProto);
  35. }
  36. void
  37. GetUrl(nsAString& aUrl) const
  38. {
  39. nsAutoCString url;
  40. mRequest->GetURL(url);
  41. CopyUTF8toUTF16(url, aUrl);
  42. }
  43. void
  44. GetMethod(nsCString& aMethod) const
  45. {
  46. aMethod = mRequest->mMethod;
  47. }
  48. RequestMode
  49. Mode() const
  50. {
  51. return mRequest->mMode;
  52. }
  53. RequestCredentials
  54. Credentials() const
  55. {
  56. return mRequest->mCredentialsMode;
  57. }
  58. RequestCache
  59. Cache() const
  60. {
  61. return mRequest->GetCacheMode();
  62. }
  63. RequestRedirect
  64. Redirect() const
  65. {
  66. return mRequest->GetRedirectMode();
  67. }
  68. void
  69. GetIntegrity(nsAString& aIntegrity) const
  70. {
  71. aIntegrity = mRequest->GetIntegrity();
  72. }
  73. RequestContext
  74. Context() const
  75. {
  76. return mRequest->Context();
  77. }
  78. void
  79. OverrideContentPolicyType(nsContentPolicyType aContentPolicyType)
  80. {
  81. mRequest->OverrideContentPolicyType(aContentPolicyType);
  82. }
  83. bool
  84. IsContentPolicyTypeOverridden() const
  85. {
  86. return mRequest->IsContentPolicyTypeOverridden();
  87. }
  88. void
  89. GetReferrer(nsAString& aReferrer) const
  90. {
  91. mRequest->GetReferrer(aReferrer);
  92. }
  93. ReferrerPolicy
  94. ReferrerPolicy_() const
  95. {
  96. return mRequest->ReferrerPolicy_();
  97. }
  98. InternalHeaders*
  99. GetInternalHeaders() const
  100. {
  101. return mRequest->Headers();
  102. }
  103. Headers* Headers_();
  104. void
  105. GetBody(nsIInputStream** aStream) { return mRequest->GetBody(aStream); }
  106. void
  107. SetBody(nsIInputStream* aStream) { return mRequest->SetBody(aStream); }
  108. static already_AddRefed<Request>
  109. Constructor(const GlobalObject& aGlobal, const RequestOrUSVString& aInput,
  110. const RequestInit& aInit, ErrorResult& rv);
  111. nsIGlobalObject* GetParentObject() const
  112. {
  113. return mOwner;
  114. }
  115. already_AddRefed<Request>
  116. Clone(ErrorResult& aRv);
  117. already_AddRefed<InternalRequest>
  118. GetInternalRequest();
  119. const UniquePtr<mozilla::ipc::PrincipalInfo>&
  120. GetPrincipalInfo() const
  121. {
  122. return mRequest->GetPrincipalInfo();
  123. }
  124. AbortSignal*
  125. GetOrCreateSignal();
  126. // This can return a null AbortSignal.
  127. AbortSignal*
  128. GetSignal() const override;
  129. private:
  130. ~Request();
  131. nsCOMPtr<nsIGlobalObject> mOwner;
  132. RefPtr<InternalRequest> mRequest;
  133. // Lazily created.
  134. RefPtr<Headers> mHeaders;
  135. RefPtr<AbortSignal> mSignal;
  136. };
  137. } // namespace dom
  138. } // namespace mozilla
  139. #endif // mozilla_dom_Request_h