ChannelInfo.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_ChannelInfo_h
  6. #define mozilla_dom_ChannelInfo_h
  7. #include "nsString.h"
  8. #include "nsCOMPtr.h"
  9. class nsIChannel;
  10. class nsIDocument;
  11. class nsIGlobalObject;
  12. class nsIURI;
  13. namespace mozilla {
  14. namespace ipc {
  15. class IPCChannelInfo;
  16. } // namespace ipc
  17. namespace dom {
  18. // This class represents the information related to a Response that we
  19. // retrieve from the corresponding channel that is used to perform the fetch.
  20. //
  21. // When adding new members to this object, the following code needs to be
  22. // updated:
  23. // * IPCChannelInfo
  24. // * InitFromChannel and InitFromIPCChannelInfo members
  25. // * ResurrectInfoOnChannel member
  26. // * AsIPCChannelInfo member
  27. // * constructors and assignment operators for this class.
  28. // * DOM Cache schema code (in dom/cache/DBSchema.cpp) to ensure that the newly
  29. // added member is saved into the DB and loaded from it properly.
  30. //
  31. // Care must be taken when initializing this object, or when calling
  32. // ResurrectInfoOnChannel(). This object cannot be initialized twice, and
  33. // ResurrectInfoOnChannel() cannot be called on it before it has been
  34. // initialized. There are assertions ensuring these invariants.
  35. class ChannelInfo final
  36. {
  37. public:
  38. typedef mozilla::ipc::IPCChannelInfo IPCChannelInfo;
  39. ChannelInfo()
  40. : mInited(false)
  41. {
  42. }
  43. ChannelInfo(const ChannelInfo& aRHS)
  44. : mSecurityInfo(aRHS.mSecurityInfo)
  45. , mInited(aRHS.mInited)
  46. {
  47. }
  48. ChannelInfo&
  49. operator=(const ChannelInfo& aRHS)
  50. {
  51. mSecurityInfo = aRHS.mSecurityInfo;
  52. mInited = aRHS.mInited;
  53. return *this;
  54. }
  55. void InitFromDocument(nsIDocument* aDoc);
  56. void InitFromChannel(nsIChannel* aChannel);
  57. void InitFromChromeGlobal(nsIGlobalObject* aGlobal);
  58. void InitFromIPCChannelInfo(const IPCChannelInfo& aChannelInfo);
  59. // This restores every possible information stored from a previous channel
  60. // object on a new one.
  61. nsresult ResurrectInfoOnChannel(nsIChannel* aChannel);
  62. bool IsInitialized() const
  63. {
  64. return mInited;
  65. }
  66. IPCChannelInfo AsIPCChannelInfo() const;
  67. private:
  68. void SetSecurityInfo(nsISupports* aSecurityInfo);
  69. private:
  70. nsCString mSecurityInfo;
  71. bool mInited;
  72. };
  73. } // namespace dom
  74. } // namespace mozilla
  75. #endif // mozilla_dom_ChannelInfo_h