LoadContext.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 LoadContext_h
  6. #define LoadContext_h
  7. #include "SerializedLoadContext.h"
  8. #include "mozilla/Attributes.h"
  9. #include "mozilla/BasePrincipal.h"
  10. #include "nsIWeakReferenceUtils.h"
  11. #include "mozilla/dom/Element.h"
  12. #include "nsIInterfaceRequestor.h"
  13. #include "nsILoadContext.h"
  14. namespace mozilla {
  15. /**
  16. * Class that provides nsILoadContext info in Parent process. Typically copied
  17. * from Child via SerializedLoadContext.
  18. *
  19. * Note: this is not the "normal" or "original" nsILoadContext. That is
  20. * typically provided by nsDocShell. This is only used when the original
  21. * docshell is in a different process and we need to copy certain values from
  22. * it.
  23. *
  24. * Note: we also generate a new nsILoadContext using LoadContext(uint32_t aAppId)
  25. * to separate the safebrowsing cookie.
  26. */
  27. class LoadContext final
  28. : public nsILoadContext
  29. , public nsIInterfaceRequestor
  30. {
  31. public:
  32. NS_DECL_ISUPPORTS
  33. NS_DECL_NSILOADCONTEXT
  34. NS_DECL_NSIINTERFACEREQUESTOR
  35. // appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
  36. // provided by child process.
  37. LoadContext(const IPC::SerializedLoadContext& aToCopy,
  38. dom::Element* aTopFrameElement,
  39. DocShellOriginAttributes& aAttrs)
  40. : mTopFrameElement(do_GetWeakReference(aTopFrameElement))
  41. , mNestedFrameId(0)
  42. , mIsContent(aToCopy.mIsContent)
  43. , mUseRemoteTabs(aToCopy.mUseRemoteTabs)
  44. , mOriginAttributes(aAttrs)
  45. #ifdef DEBUG
  46. , mIsNotNull(aToCopy.mIsNotNull)
  47. #endif
  48. {
  49. }
  50. // appId/inIsolatedMozBrowser arguments override those in SerializedLoadContext
  51. // provided by child process.
  52. LoadContext(const IPC::SerializedLoadContext& aToCopy,
  53. uint64_t aNestedFrameId,
  54. DocShellOriginAttributes& aAttrs)
  55. : mTopFrameElement(nullptr)
  56. , mNestedFrameId(aNestedFrameId)
  57. , mIsContent(aToCopy.mIsContent)
  58. , mUseRemoteTabs(aToCopy.mUseRemoteTabs)
  59. , mOriginAttributes(aAttrs)
  60. #ifdef DEBUG
  61. , mIsNotNull(aToCopy.mIsNotNull)
  62. #endif
  63. {
  64. }
  65. LoadContext(dom::Element* aTopFrameElement,
  66. bool aIsContent,
  67. bool aUsePrivateBrowsing,
  68. bool aUseRemoteTabs,
  69. const DocShellOriginAttributes& aAttrs)
  70. : mTopFrameElement(do_GetWeakReference(aTopFrameElement))
  71. , mNestedFrameId(0)
  72. , mIsContent(aIsContent)
  73. , mUseRemoteTabs(aUseRemoteTabs)
  74. , mOriginAttributes(aAttrs)
  75. #ifdef DEBUG
  76. , mIsNotNull(true)
  77. #endif
  78. {
  79. }
  80. // Constructor taking reserved origin attributes.
  81. explicit LoadContext(DocShellOriginAttributes& aAttrs)
  82. : mTopFrameElement(nullptr)
  83. , mNestedFrameId(0)
  84. , mIsContent(false)
  85. , mUseRemoteTabs(false)
  86. , mOriginAttributes(aAttrs)
  87. #ifdef DEBUG
  88. , mIsNotNull(true)
  89. #endif
  90. {
  91. }
  92. // Constructor for creating a LoadContext with a given principal's appId and
  93. // browser flag.
  94. explicit LoadContext(nsIPrincipal* aPrincipal,
  95. nsILoadContext* aOptionalBase = nullptr);
  96. private:
  97. ~LoadContext() {}
  98. nsWeakPtr mTopFrameElement;
  99. uint64_t mNestedFrameId;
  100. bool mIsContent;
  101. bool mUseRemoteTabs;
  102. DocShellOriginAttributes mOriginAttributes;
  103. #ifdef DEBUG
  104. bool mIsNotNull;
  105. #endif
  106. };
  107. } // namespace mozilla
  108. #endif // LoadContext_h