SerializedLoadContext.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 SerializedLoadContext_h
  6. #define SerializedLoadContext_h
  7. #include "base/basictypes.h"
  8. #include "ipc/IPCMessageUtils.h"
  9. #include "mozilla/BasePrincipal.h"
  10. class nsILoadContext;
  11. /*
  12. * This file contains the IPC::SerializedLoadContext class, which is used to
  13. * copy data across IPDL from Child process contexts so it is available in the
  14. * Parent.
  15. */
  16. class nsIChannel;
  17. class nsIWebSocketChannel;
  18. namespace IPC {
  19. class SerializedLoadContext
  20. {
  21. public:
  22. SerializedLoadContext()
  23. : mIsNotNull(false)
  24. , mIsPrivateBitValid(false)
  25. , mIsContent(false)
  26. , mUseRemoteTabs(false)
  27. {
  28. Init(nullptr);
  29. }
  30. explicit SerializedLoadContext(nsILoadContext* aLoadContext);
  31. explicit SerializedLoadContext(nsIChannel* aChannel);
  32. explicit SerializedLoadContext(nsIWebSocketChannel* aChannel);
  33. void Init(nsILoadContext* aLoadContext);
  34. bool IsNotNull() const { return mIsNotNull; }
  35. bool IsPrivateBitValid() const { return mIsPrivateBitValid; }
  36. // used to indicate if child-side LoadContext * was null.
  37. bool mIsNotNull;
  38. // used to indicate if child-side mUsePrivateBrowsing flag is valid, even if
  39. // mIsNotNull is false, i.e., child LoadContext was null.
  40. bool mIsPrivateBitValid;
  41. bool mIsContent;
  42. bool mUseRemoteTabs;
  43. mozilla::DocShellOriginAttributes mOriginAttributes;
  44. };
  45. // Function to serialize over IPDL
  46. template<>
  47. struct ParamTraits<SerializedLoadContext>
  48. {
  49. typedef SerializedLoadContext paramType;
  50. static void Write(Message* aMsg, const paramType& aParam)
  51. {
  52. nsAutoCString suffix;
  53. aParam.mOriginAttributes.CreateSuffix(suffix);
  54. WriteParam(aMsg, aParam.mIsNotNull);
  55. WriteParam(aMsg, aParam.mIsContent);
  56. WriteParam(aMsg, aParam.mIsPrivateBitValid);
  57. WriteParam(aMsg, aParam.mUseRemoteTabs);
  58. WriteParam(aMsg, suffix);
  59. }
  60. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  61. {
  62. nsAutoCString suffix;
  63. if (!ReadParam(aMsg, aIter, &aResult->mIsNotNull) ||
  64. !ReadParam(aMsg, aIter, &aResult->mIsContent) ||
  65. !ReadParam(aMsg, aIter, &aResult->mIsPrivateBitValid) ||
  66. !ReadParam(aMsg, aIter, &aResult->mUseRemoteTabs) ||
  67. !ReadParam(aMsg, aIter, &suffix)) {
  68. return false;
  69. }
  70. return aResult->mOriginAttributes.PopulateFromSuffix(suffix);
  71. }
  72. };
  73. } // namespace IPC
  74. #endif // SerializedLoadContext_h