Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 dom_src_geolocation_IPC_serialiser
6 #define dom_src_geolocation_IPC_serialiser
8 #include "ipc/IPCMessageUtils.h"
9 #include "nsGeoPosition.h"
10 #include "nsIDOMGeoPosition.h"
12 typedef nsIDOMGeoPosition* GeoPosition;
14 namespace IPC {
16 template <>
17 struct ParamTraits<nsIDOMGeoPositionCoords*>
18 {
19 typedef nsIDOMGeoPositionCoords* paramType;
21 // Function to serialize a geoposition
22 static void Write(Message *aMsg, const paramType& aParam)
23 {
24 bool isNull = !aParam;
25 WriteParam(aMsg, isNull);
26 // If it is a null object, then we are done
27 if (isNull) return;
29 double coordData;
31 aParam->GetLatitude(&coordData);
32 WriteParam(aMsg, coordData);
34 aParam->GetLongitude(&coordData);
35 WriteParam(aMsg, coordData);
37 aParam->GetAltitude(&coordData);
38 WriteParam(aMsg, coordData);
40 aParam->GetAccuracy(&coordData);
41 WriteParam(aMsg, coordData);
43 aParam->GetAltitudeAccuracy(&coordData);
44 WriteParam(aMsg, coordData);
46 aParam->GetHeading(&coordData);
47 WriteParam(aMsg, coordData);
49 aParam->GetSpeed(&coordData);
50 WriteParam(aMsg, coordData);
51 }
53 // Function to de-serialize a geoposition
54 static bool Read(const Message* aMsg, void **aIter, paramType* aResult)
55 {
56 // Check if it is the null pointer we have transfered
57 bool isNull;
58 if (!ReadParam(aMsg, aIter, &isNull)) return false;
60 if (isNull) {
61 *aResult = 0;
62 return true;
63 }
65 double latitude;
66 double longitude;
67 double altitude;
68 double accuracy;
69 double altitudeAccuracy;
70 double heading;
71 double speed;
73 // It's not important to us where it fails, but rather if it fails
74 if (!( ReadParam(aMsg, aIter, &latitude )
75 && ReadParam(aMsg, aIter, &longitude )
76 && ReadParam(aMsg, aIter, &altitude )
77 && ReadParam(aMsg, aIter, &accuracy )
78 && ReadParam(aMsg, aIter, &altitudeAccuracy )
79 && ReadParam(aMsg, aIter, &heading )
80 && ReadParam(aMsg, aIter, &speed ))) return false;
82 // We now have all the data
83 *aResult = new nsGeoPositionCoords(latitude, /* aLat */
84 longitude, /* aLong */
85 altitude, /* aAlt */
86 accuracy, /* aHError */
87 altitudeAccuracy, /* aVError */
88 heading, /* aHeading */
89 speed /* aSpeed */
90 );
91 return true;
93 }
95 };
97 template <>
98 struct ParamTraits<nsIDOMGeoPosition*>
99 {
100 typedef nsIDOMGeoPosition* paramType;
102 // Function to serialize a geoposition
103 static void Write(Message *aMsg, const paramType& aParam)
104 {
105 bool isNull = !aParam;
106 WriteParam(aMsg, isNull);
107 // If it is a null object, then we are done
108 if (isNull) return;
110 DOMTimeStamp timeStamp;
111 aParam->GetTimestamp(&timeStamp);
112 WriteParam(aMsg, timeStamp);
114 nsCOMPtr<nsIDOMGeoPositionCoords> coords;
115 aParam->GetCoords(getter_AddRefs(coords));
116 WriteParam(aMsg, coords.get());
117 }
119 // Function to de-serialize a geoposition
120 static bool Read(const Message* aMsg, void **aIter, paramType* aResult)
121 {
122 // Check if it is the null pointer we have transfered
123 bool isNull;
124 if (!ReadParam(aMsg, aIter, &isNull)) return false;
126 if (isNull) {
127 *aResult = 0;
128 return true;
129 }
131 DOMTimeStamp timeStamp;
132 nsIDOMGeoPositionCoords* coords = nullptr;
134 // It's not important to us where it fails, but rather if it fails
135 if (!ReadParam(aMsg, aIter, &timeStamp) ||
136 !ReadParam(aMsg, aIter, &coords)) {
137 nsCOMPtr<nsIDOMGeoPositionCoords> tmpcoords = coords;
138 return false;
139 }
141 *aResult = new nsGeoPosition(coords, timeStamp);
143 return true;
144 };
146 };
148 }
150 #endif