Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsGeoPositionIPCSerialiser.h
Line
Count
Source (jump to first uncovered line)
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 dom_src_geolocation_IPC_serialiser
8
#define dom_src_geolocation_IPC_serialiser
9
10
#include "ipc/IPCMessageUtils.h"
11
#include "nsGeoPosition.h"
12
#include "nsIDOMGeoPosition.h"
13
14
namespace IPC {
15
16
template <>
17
struct ParamTraits<nsIDOMGeoPositionCoords>
18
{
19
  // Function to serialize a geoposition
20
  static void Write(Message *aMsg, nsIDOMGeoPositionCoords* aParam)
21
0
  {
22
0
    bool isNull = !aParam;
23
0
    WriteParam(aMsg, isNull);
24
0
    // If it is a null object, then we are done
25
0
    if (isNull) return;
26
0
27
0
    double coordData;
28
0
29
0
    aParam->GetLatitude(&coordData);
30
0
    WriteParam(aMsg, coordData);
31
0
32
0
    aParam->GetLongitude(&coordData);
33
0
    WriteParam(aMsg, coordData);
34
0
35
0
    aParam->GetAltitude(&coordData);
36
0
    WriteParam(aMsg, coordData);
37
0
38
0
    aParam->GetAccuracy(&coordData);
39
0
    WriteParam(aMsg, coordData);
40
0
41
0
    aParam->GetAltitudeAccuracy(&coordData);
42
0
    WriteParam(aMsg, coordData);
43
0
44
0
    aParam->GetHeading(&coordData);
45
0
    WriteParam(aMsg, coordData);
46
0
47
0
    aParam->GetSpeed(&coordData);
48
0
    WriteParam(aMsg, coordData);
49
0
  }
50
51
  // Function to de-serialize a geoposition
52
  static bool Read(const Message* aMsg, PickleIterator* aIter,
53
                   RefPtr<nsIDOMGeoPositionCoords>* aResult)
54
0
  {
55
0
    // Check if it is the null pointer we have transfered
56
0
    bool isNull;
57
0
    if (!ReadParam(aMsg, aIter, &isNull)) return false;
58
0
59
0
    if (isNull) {
60
0
      *aResult = nullptr;
61
0
      return true;
62
0
    }
63
0
64
0
    double latitude;
65
0
    double longitude;
66
0
    double altitude;
67
0
    double accuracy;
68
0
    double altitudeAccuracy;
69
0
    double heading;
70
0
    double speed;
71
0
72
0
    // It's not important to us where it fails, but rather if it fails
73
0
    if (!(   ReadParam(aMsg, aIter, &latitude         )
74
0
          && ReadParam(aMsg, aIter, &longitude        )
75
0
          && ReadParam(aMsg, aIter, &altitude         )
76
0
          && ReadParam(aMsg, aIter, &accuracy         )
77
0
          && ReadParam(aMsg, aIter, &altitudeAccuracy )
78
0
          && ReadParam(aMsg, aIter, &heading          )
79
0
          && ReadParam(aMsg, aIter, &speed            ))) return false;
80
0
81
0
    // We now have all the data
82
0
    *aResult = new nsGeoPositionCoords(latitude,         /* aLat     */
83
0
                                       longitude,        /* aLong    */
84
0
                                       altitude,         /* aAlt     */
85
0
                                       accuracy,         /* aHError  */
86
0
                                       altitudeAccuracy, /* aVError  */
87
0
                                       heading,          /* aHeading */
88
0
                                       speed             /* aSpeed   */
89
0
                                      );
90
0
    return true;
91
0
  }
92
93
};
94
95
template <>
96
struct ParamTraits<nsIDOMGeoPosition>
97
{
98
  // Function to serialize a geoposition
99
  static void Write(Message *aMsg, nsIDOMGeoPosition* aParam)
100
0
  {
101
0
    bool isNull = !aParam;
102
0
    WriteParam(aMsg, isNull);
103
0
    // If it is a null object, then we are done
104
0
    if (isNull) return;
105
0
106
0
    DOMTimeStamp timeStamp;
107
0
    aParam->GetTimestamp(&timeStamp);
108
0
    WriteParam(aMsg, timeStamp);
109
0
110
0
    nsCOMPtr<nsIDOMGeoPositionCoords> coords;
111
0
    aParam->GetCoords(getter_AddRefs(coords));
112
0
    WriteParam(aMsg, coords);
113
0
  }
114
115
  // Function to de-serialize a geoposition
116
  static bool Read(const Message* aMsg, PickleIterator* aIter,
117
                   RefPtr<nsIDOMGeoPosition>* aResult)
118
0
  {
119
0
    // Check if it is the null pointer we have transfered
120
0
    bool isNull;
121
0
    if (!ReadParam(aMsg, aIter, &isNull)) return false;
122
0
123
0
    if (isNull) {
124
0
      *aResult = nullptr;
125
0
      return true;
126
0
    }
127
0
128
0
    DOMTimeStamp timeStamp;
129
0
    RefPtr<nsIDOMGeoPositionCoords> coords;
130
0
131
0
    // It's not important to us where it fails, but rather if it fails
132
0
    if (!ReadParam(aMsg, aIter, &timeStamp) ||
133
0
        !ReadParam(aMsg, aIter, &coords)) {
134
0
      return false;
135
0
    }
136
0
137
0
    *aResult = new nsGeoPosition(coords, timeStamp);
138
0
139
0
    return true;
140
0
  };
141
142
};
143
144
} // namespace IPC
145
146
#endif