Bug 1842773 - Part 18: Update TypedArray length, byteLength, and byteOffset accesses...
[gecko.git] / dom / geolocation / nsGeoPositionIPCSerialiser.h
blobc1a255ad2bb49aeb13f5c6cd6a9e59b50fc04a6b
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/. */
7 #ifndef dom_src_geolocation_IPC_serialiser
8 #define dom_src_geolocation_IPC_serialiser
10 #include "ipc/IPCMessageUtils.h"
11 #include "mozilla/dom/GeolocationPosition.h"
12 #include "nsIDOMGeoPosition.h"
14 namespace IPC {
16 template <>
17 struct ParamTraits<nsIDOMGeoPositionCoords*> {
18 // Function to serialize a geoposition
19 static void Write(MessageWriter* aWriter, nsIDOMGeoPositionCoords* aParam) {
20 bool isNull = !aParam;
21 WriteParam(aWriter, isNull);
22 // If it is a null object, then we are done
23 if (isNull) return;
25 double coordData;
27 aParam->GetLatitude(&coordData);
28 WriteParam(aWriter, coordData);
30 aParam->GetLongitude(&coordData);
31 WriteParam(aWriter, coordData);
33 aParam->GetAltitude(&coordData);
34 WriteParam(aWriter, coordData);
36 aParam->GetAccuracy(&coordData);
37 WriteParam(aWriter, coordData);
39 aParam->GetAltitudeAccuracy(&coordData);
40 WriteParam(aWriter, coordData);
42 aParam->GetHeading(&coordData);
43 WriteParam(aWriter, coordData);
45 aParam->GetSpeed(&coordData);
46 WriteParam(aWriter, coordData);
49 // Function to de-serialize a geoposition
50 static bool Read(MessageReader* aReader,
51 RefPtr<nsIDOMGeoPositionCoords>* aResult) {
52 // Check if it is the null pointer we have transfered
53 bool isNull;
54 if (!ReadParam(aReader, &isNull)) return false;
56 if (isNull) {
57 *aResult = nullptr;
58 return true;
61 double latitude;
62 double longitude;
63 double altitude;
64 double accuracy;
65 double altitudeAccuracy;
66 double heading;
67 double speed;
69 // It's not important to us where it fails, but rather if it fails
70 if (!(ReadParam(aReader, &latitude) && ReadParam(aReader, &longitude) &&
71 ReadParam(aReader, &altitude) && ReadParam(aReader, &accuracy) &&
72 ReadParam(aReader, &altitudeAccuracy) &&
73 ReadParam(aReader, &heading) && ReadParam(aReader, &speed)))
74 return false;
76 // We now have all the data
77 *aResult = new nsGeoPositionCoords(latitude, /* aLat */
78 longitude, /* aLong */
79 altitude, /* aAlt */
80 accuracy, /* aHError */
81 altitudeAccuracy, /* aVError */
82 heading, /* aHeading */
83 speed /* aSpeed */
85 return true;
89 template <>
90 struct ParamTraits<nsIDOMGeoPosition*> {
91 // Function to serialize a geoposition
92 static void Write(MessageWriter* aWriter, nsIDOMGeoPosition* aParam) {
93 bool isNull = !aParam;
94 WriteParam(aWriter, isNull);
95 // If it is a null object, then we are done
96 if (isNull) return;
98 EpochTimeStamp timeStamp;
99 aParam->GetTimestamp(&timeStamp);
100 WriteParam(aWriter, timeStamp);
102 nsCOMPtr<nsIDOMGeoPositionCoords> coords;
103 aParam->GetCoords(getter_AddRefs(coords));
104 WriteParam(aWriter, coords);
107 // Function to de-serialize a geoposition
108 static bool Read(MessageReader* aReader, RefPtr<nsIDOMGeoPosition>* aResult) {
109 // Check if it is the null pointer we have transfered
110 bool isNull;
111 if (!ReadParam(aReader, &isNull)) return false;
113 if (isNull) {
114 *aResult = nullptr;
115 return true;
118 EpochTimeStamp timeStamp;
119 RefPtr<nsIDOMGeoPositionCoords> coords;
121 // It's not important to us where it fails, but rather if it fails
122 if (!ReadParam(aReader, &timeStamp) || !ReadParam(aReader, &coords)) {
123 return false;
126 *aResult = new nsGeoPosition(coords, timeStamp);
128 return true;
132 } // namespace IPC
134 #endif