LoadInfo.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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_LoadInfo_h
  6. #define mozilla_LoadInfo_h
  7. #include "nsIContentPolicy.h"
  8. #include "nsILoadInfo.h"
  9. #include "nsIPrincipal.h"
  10. #include "nsIWeakReferenceUtils.h" // for nsWeakPtr
  11. #include "nsIURI.h"
  12. #include "nsTArray.h"
  13. #include "mozilla/BasePrincipal.h"
  14. class nsINode;
  15. class nsPIDOMWindowOuter;
  16. namespace mozilla {
  17. namespace dom {
  18. class XMLHttpRequestMainThread;
  19. }
  20. namespace net {
  21. class OptionalLoadInfoArgs;
  22. } // namespace net
  23. namespace ipc {
  24. // we have to forward declare that function so we can use it as a friend.
  25. nsresult
  26. LoadInfoArgsToLoadInfo(const mozilla::net::OptionalLoadInfoArgs& aLoadInfoArgs,
  27. nsILoadInfo** outLoadInfo);
  28. } // namespace ipc
  29. namespace net {
  30. /**
  31. * Class that provides an nsILoadInfo implementation.
  32. *
  33. * Note that there is no reason why this class should be MOZ_EXPORT, but
  34. * Thunderbird relies on some insane hacks which require this, so we'll leave it
  35. * as is for now, but hopefully we'll be able to remove the MOZ_EXPORT keyword
  36. * from this class at some point. See bug 1149127 for the discussion.
  37. */
  38. class MOZ_EXPORT LoadInfo final : public nsILoadInfo
  39. {
  40. public:
  41. NS_DECL_ISUPPORTS
  42. NS_DECL_NSILOADINFO
  43. // aLoadingPrincipal MUST NOT BE NULL.
  44. LoadInfo(nsIPrincipal* aLoadingPrincipal,
  45. nsIPrincipal* aTriggeringPrincipal,
  46. nsINode* aLoadingContext,
  47. nsSecurityFlags aSecurityFlags,
  48. nsContentPolicyType aContentPolicyType);
  49. // Constructor used for TYPE_DOCUMENT loads which have a different
  50. // loadingContext than other loads. This ContextForTopLevelLoad is
  51. // only used for content policy checks.
  52. LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
  53. nsIPrincipal* aTriggeringPrincipal,
  54. nsISupports* aContextForTopLevelLoad,
  55. nsSecurityFlags aSecurityFlags);
  56. // create an exact copy of the loadinfo
  57. already_AddRefed<nsILoadInfo> Clone() const;
  58. // hands off!!! don't use CloneWithNewSecFlags unless you know
  59. // exactly what you are doing - it should only be used within
  60. // nsBaseChannel::Redirect()
  61. already_AddRefed<nsILoadInfo>
  62. CloneWithNewSecFlags(nsSecurityFlags aSecurityFlags) const;
  63. // creates a copy of the loadinfo which is appropriate to use for a
  64. // separate request. I.e. not for a redirect or an inner channel, but
  65. // when a separate request is made with the same security properties.
  66. already_AddRefed<nsILoadInfo> CloneForNewRequest() const;
  67. void SetIsPreflight();
  68. void SetUpgradeInsecureRequests();
  69. void SetIsFromProcessingFrameAttributes();
  70. private:
  71. // private constructor that is only allowed to be called from within
  72. // HttpChannelParent and FTPChannelParent declared as friends undeneath.
  73. // In e10s we can not serialize nsINode, hence we store the innerWindowID.
  74. // Please note that aRedirectChain uses swapElements.
  75. LoadInfo(nsIPrincipal* aLoadingPrincipal,
  76. nsIPrincipal* aTriggeringPrincipal,
  77. nsIPrincipal* aPrincipalToInherit,
  78. nsSecurityFlags aSecurityFlags,
  79. nsContentPolicyType aContentPolicyType,
  80. LoadTainting aTainting,
  81. bool aUpgradeInsecureRequests,
  82. bool aVerifySignedContent,
  83. bool aEnforceSRI,
  84. bool aForceAllowDataURI,
  85. bool aForceInheritPrincipalDropped,
  86. uint64_t aInnerWindowID,
  87. uint64_t aOuterWindowID,
  88. uint64_t aParentOuterWindowID,
  89. uint64_t aFrameOuterWindowID,
  90. bool aEnforceSecurity,
  91. bool aInitialSecurityCheckDone,
  92. bool aIsThirdPartyRequest,
  93. const NeckoOriginAttributes& aOriginAttributes,
  94. nsTArray<nsCOMPtr<nsIPrincipal>>& aRedirectChainIncludingInternalRedirects,
  95. nsTArray<nsCOMPtr<nsIPrincipal>>& aRedirectChain,
  96. const nsTArray<nsCString>& aUnsafeHeaders,
  97. bool aForcePreflight,
  98. bool aIsPreflight,
  99. bool aLoadTriggeredFromExternal);
  100. LoadInfo(const LoadInfo& rhs);
  101. friend nsresult
  102. mozilla::ipc::LoadInfoArgsToLoadInfo(
  103. const mozilla::net::OptionalLoadInfoArgs& aLoadInfoArgs,
  104. nsILoadInfo** outLoadInfo);
  105. ~LoadInfo();
  106. void ComputeIsThirdPartyContext(nsPIDOMWindowOuter* aOuterWindow);
  107. // This function is the *only* function which can change the securityflags
  108. // of a loadinfo. It only exists because of the XHR code. Don't call it
  109. // from anywhere else!
  110. void SetIncludeCookiesSecFlag();
  111. friend class mozilla::dom::XMLHttpRequestMainThread;
  112. // if you add a member, please also update the copy constructor
  113. nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
  114. nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
  115. nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
  116. nsWeakPtr mLoadingContext;
  117. nsWeakPtr mContextForTopLevelLoad;
  118. nsSecurityFlags mSecurityFlags;
  119. nsContentPolicyType mInternalContentPolicyType;
  120. LoadTainting mTainting;
  121. bool mUpgradeInsecureRequests;
  122. bool mVerifySignedContent;
  123. bool mEnforceSRI;
  124. bool mForceAllowDataURI;
  125. bool mForceInheritPrincipalDropped;
  126. uint64_t mInnerWindowID;
  127. uint64_t mOuterWindowID;
  128. uint64_t mParentOuterWindowID;
  129. uint64_t mFrameOuterWindowID;
  130. bool mEnforceSecurity;
  131. bool mInitialSecurityCheckDone;
  132. bool mIsThirdPartyContext;
  133. NeckoOriginAttributes mOriginAttributes;
  134. nsTArray<nsCOMPtr<nsIPrincipal>> mRedirectChainIncludingInternalRedirects;
  135. nsTArray<nsCOMPtr<nsIPrincipal>> mRedirectChain;
  136. nsTArray<nsCString> mCorsUnsafeHeaders;
  137. bool mForcePreflight;
  138. bool mIsPreflight;
  139. bool mLoadTriggeredFromExternal;
  140. // Is true if this load was triggered by processing the attributes of the
  141. // browsing context container.
  142. // See nsILoadInfo.isFromProcessingFrameAttributes
  143. bool mIsFromProcessingFrameAttributes;
  144. };
  145. } // namespace net
  146. } // namespace mozilla
  147. #endif // mozilla_LoadInfo_h