PermissionMessageUtils.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_permission_message_utils_h__
  6. #define mozilla_dom_permission_message_utils_h__
  7. #include "ipc/IPCMessageUtils.h"
  8. #include "nsCOMPtr.h"
  9. #include "nsIPrincipal.h"
  10. namespace IPC {
  11. class Principal
  12. {
  13. friend struct ParamTraits<Principal>;
  14. public:
  15. Principal()
  16. : mPrincipal(nullptr)
  17. {}
  18. explicit Principal(nsIPrincipal* aPrincipal)
  19. : mPrincipal(aPrincipal)
  20. {}
  21. operator nsIPrincipal*() const { return mPrincipal.get(); }
  22. Principal& operator=(const Principal& aOther)
  23. {
  24. mPrincipal = aOther.mPrincipal;
  25. return *this;
  26. }
  27. private:
  28. nsCOMPtr<nsIPrincipal> mPrincipal;
  29. };
  30. template <>
  31. struct ParamTraits<Principal>
  32. {
  33. typedef Principal paramType;
  34. static void Write(Message* aMsg, const paramType& aParam);
  35. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult);
  36. };
  37. } // namespace IPC
  38. #endif // mozilla_dom_permission_message_utils_h__