WebrtcIPCTraits.h (2821B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef _WEBRTC_IPC_TRAITS_H_ 6 #define _WEBRTC_IPC_TRAITS_H_ 7 8 #include <vector> 9 10 #include "ipc/EnumSerializer.h" 11 #include "ipc/IPCMessageUtils.h" 12 #include "ipc/IPCMessageUtilsSpecializations.h" 13 #include "mozilla/dom/BindingDeclarations.h" 14 #include "mozilla/dom/BindingIPCUtils.h" 15 #include "mozilla/dom/CandidateInfo.h" 16 #include "mozilla/dom/RTCConfigurationBinding.h" 17 #include "mozilla/media/webrtc/WebrtcGlobal.h" 18 #include "transport/dtlsidentity.h" 19 20 namespace mozilla { 21 typedef std::vector<std::string> StringVector; 22 } 23 24 namespace IPC { 25 26 template <> 27 struct ParamTraits<mozilla::dom::OwningStringOrStringSequence> { 28 typedef mozilla::dom::OwningStringOrStringSequence paramType; 29 30 // Ugh. OwningStringOrStringSequence already has this enum, but it is 31 // private generated code. So we have to re-create it. 32 enum Type { kUninitialized, kString, kStringSequence }; 33 34 static void Write(MessageWriter* aWriter, const paramType& aParam) { 35 if (aParam.IsString()) { 36 aWriter->WriteInt16(kString); 37 WriteParam(aWriter, aParam.GetAsString()); 38 } else if (aParam.IsStringSequence()) { 39 aWriter->WriteInt16(kStringSequence); 40 WriteParam(aWriter, aParam.GetAsStringSequence()); 41 } else { 42 aWriter->WriteInt16(kUninitialized); 43 } 44 } 45 46 static bool Read(MessageReader* aReader, paramType* aResult) { 47 int16_t type; 48 if (!aReader->ReadInt16(&type)) { 49 return false; 50 } 51 52 switch (type) { 53 case kUninitialized: 54 aResult->Uninit(); 55 return true; 56 case kString: 57 return ReadParam(aReader, &aResult->SetAsString()); 58 case kStringSequence: 59 return ReadParam(aReader, &aResult->SetAsStringSequence()); 60 } 61 62 return false; 63 } 64 }; 65 66 template <> 67 struct ParamTraits<mozilla::dom::RTCIceCredentialType> 68 : public mozilla::dom::WebIDLEnumSerializer< 69 mozilla::dom::RTCIceCredentialType> {}; 70 71 template <> 72 struct ParamTraits<mozilla::dom::RTCIceTransportPolicy> 73 : public mozilla::dom::WebIDLEnumSerializer< 74 mozilla::dom::RTCIceTransportPolicy> {}; 75 76 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCIceServer, mCredential, 77 mCredentialType, mUrl, mUrls, mUsername) 78 79 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::CandidateInfo, mCandidate, mUfrag, 80 mDefaultHostRtp, mDefaultPortRtp, 81 mDefaultHostRtcp, mDefaultPortRtcp, 82 mMDNSAddress, mActualAddress) 83 84 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::DtlsDigest, algorithm_, value_) 85 86 } // namespace IPC 87 88 #endif // _WEBRTC_IPC_TRAITS_H_