Bug 1825333 - Make toolkit/components/sessionstore buildable outside of a unified...
[gecko.git] / toolkit / components / sessionstore / SessionStoreMessageUtils.h
blob8475955f870d5dbc067cb3d99df002d730a8e61a
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
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_SessionStoreMessageUtils_h
6 #define mozilla_dom_SessionStoreMessageUtils_h
8 #include "ipc/IPCMessageUtils.h"
9 #include "mozilla/ipc/IPDLParamTraits.h"
10 #include "mozilla/ipc/URIUtils.h"
11 #include "SessionStoreData.h"
12 #include "SessionStoreUtils.h"
13 #include "SessionStoreRestoreData.h"
15 namespace IPC {
17 template <>
18 struct ParamTraits<mozilla::dom::CollectedNonMultipleSelectValue> {
19 typedef mozilla::dom::CollectedNonMultipleSelectValue paramType;
21 static void Write(MessageWriter* aWriter, const paramType& aParam) {
22 WriteParam(aWriter, aParam.mSelectedIndex);
23 WriteParam(aWriter, aParam.mValue);
26 static bool Read(MessageReader* aReader, paramType* aResult) {
27 return ReadParam(aReader, &aResult->mSelectedIndex) &&
28 ReadParam(aReader, &aResult->mValue);
32 template <>
33 struct ParamTraits<CollectedInputDataValue> {
34 typedef CollectedInputDataValue paramType;
36 static void Write(MessageWriter* aWriter, const paramType& aParam) {
37 WriteParam(aWriter, aParam.id);
38 WriteParam(aWriter, aParam.type);
39 WriteParam(aWriter, aParam.value);
42 static bool Read(MessageReader* aReader, paramType* aResult) {
43 return ReadParam(aReader, &aResult->id) &&
44 ReadParam(aReader, &aResult->type) &&
45 ReadParam(aReader, &aResult->value);
49 template <>
50 struct ParamTraits<InputFormData> {
51 typedef InputFormData paramType;
53 static void Write(MessageWriter* aWriter, const paramType& aParam) {
54 WriteParam(aWriter, aParam.descendants);
55 WriteParam(aWriter, aParam.innerHTML);
56 WriteParam(aWriter, aParam.url);
57 WriteParam(aWriter, aParam.numId);
58 WriteParam(aWriter, aParam.numXPath);
61 static bool Read(MessageReader* aReader, paramType* aResult) {
62 return ReadParam(aReader, &aResult->descendants) &&
63 ReadParam(aReader, &aResult->innerHTML) &&
64 ReadParam(aReader, &aResult->url) &&
65 ReadParam(aReader, &aResult->numId) &&
66 ReadParam(aReader, &aResult->numXPath);
70 } // namespace IPC
72 namespace mozilla {
73 namespace ipc {
75 template <>
76 struct IPDLParamTraits<mozilla::dom::SessionStoreRestoreData*> {
77 // Note that we intentionally don't de/serialize mChildren here. The receiver
78 // won't be doing anything with the children lists, and it avoids sending form
79 // data for subframes to the content processes of their embedders.
81 static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
82 mozilla::dom::SessionStoreRestoreData* aParam) {
83 bool isNull = !aParam;
84 WriteIPDLParam(aWriter, aActor, isNull);
85 if (isNull) {
86 return;
88 WriteIPDLParam(aWriter, aActor, aParam->mURI);
89 WriteIPDLParam(aWriter, aActor, aParam->mInnerHTML);
90 WriteIPDLParam(aWriter, aActor, aParam->mScroll);
91 WriteIPDLParam(aWriter, aActor, aParam->mEntries);
94 static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
95 RefPtr<mozilla::dom::SessionStoreRestoreData>* aResult) {
96 *aResult = nullptr;
97 bool isNull;
98 if (!ReadIPDLParam(aReader, aActor, &isNull)) {
99 return false;
101 if (isNull) {
102 return true;
104 auto data = MakeRefPtr<mozilla::dom::SessionStoreRestoreData>();
105 if (!ReadIPDLParam(aReader, aActor, &data->mURI) ||
106 !ReadIPDLParam(aReader, aActor, &data->mInnerHTML) ||
107 !ReadIPDLParam(aReader, aActor, &data->mScroll) ||
108 !ReadIPDLParam(aReader, aActor, &data->mEntries)) {
109 return false;
111 *aResult = std::move(data);
112 return true;
116 template <>
117 struct IPDLParamTraits<mozilla::dom::SessionStoreRestoreData::Entry> {
118 static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
119 mozilla::dom::SessionStoreRestoreData::Entry aParam) {
120 WriteIPDLParam(aWriter, aActor, aParam.mData);
121 WriteIPDLParam(aWriter, aActor, aParam.mIsXPath);
124 static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
125 mozilla::dom::SessionStoreRestoreData::Entry* aResult) {
126 return ReadIPDLParam(aReader, aActor, &aResult->mData) &&
127 ReadIPDLParam(aReader, aActor, &aResult->mIsXPath);
131 } // namespace ipc
132 } // namespace mozilla
134 #endif // mozilla_dom_SessionStoreMessageUtils_h