URIUtils.h (1446B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_ipc_URIUtils_h 8 #define mozilla_ipc_URIUtils_h 9 10 #include "ipc/IPCMessageUtilsSpecializations.h" 11 #include "mozilla/ipc/URIParams.h" 12 #include "nsCOMPtr.h" 13 #include "nsIURI.h" 14 15 namespace mozilla { 16 namespace ipc { 17 18 void SerializeURI(nsIURI* aURI, URIParams& aParams); 19 20 void SerializeURI(nsIURI* aURI, Maybe<URIParams>& aParams); 21 22 already_AddRefed<nsIURI> DeserializeURI(const URIParams& aParams); 23 24 already_AddRefed<nsIURI> DeserializeURI(const Maybe<URIParams>& aParams); 25 26 } // namespace ipc 27 } // namespace mozilla 28 29 namespace IPC { 30 31 template <> 32 struct ParamTraits<nsIURI*> { 33 static void Write(IPC::MessageWriter* aWriter, nsIURI* aParam) { 34 mozilla::Maybe<mozilla::ipc::URIParams> params; 35 mozilla::ipc::SerializeURI(aParam, params); 36 WriteParam(aWriter, params); 37 } 38 39 static bool Read(IPC::MessageReader* aReader, RefPtr<nsIURI>* aResult) { 40 mozilla::Maybe<mozilla::ipc::URIParams> params; 41 if (!ReadParam(aReader, ¶ms)) { 42 return false; 43 } 44 *aResult = mozilla::ipc::DeserializeURI(params); 45 return true; 46 } 47 }; 48 49 } // namespace IPC 50 51 #endif // mozilla_ipc_URIUtils_h