Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/plugins/NPEventUnix.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
2
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
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 mozilla_dom_plugins_NPEventUnix_h
8
#define mozilla_dom_plugins_NPEventUnix_h 1
9
10
#include "npapi.h"
11
12
#ifdef MOZ_X11
13
#include "mozilla/X11Util.h"
14
#endif
15
16
namespace mozilla {
17
18
namespace plugins {
19
20
struct NPRemoteEvent {
21
    NPEvent event;
22
};
23
24
}
25
26
}
27
28
29
//
30
// XEvent is defined as a union of all more specific X*Events.
31
// Luckily, as of xorg 1.6.0 / X protocol 11 rev 0, the only pointer
32
// field contained in any of these specific X*Event structs is a
33
// |Display*|.  So to simplify serializing these XEvents, we make the
34
//
35
// ********** XXX ASSUMPTION XXX **********
36
//
37
// that the process to which the event is forwarded shares the same
38
// display as the process on which the event originated.
39
//
40
// With this simplification, serialization becomes a simple memcpy to
41
// the output stream.  Deserialization starts as just a memcpy from
42
// the input stream, BUT we then have to write the correct |Display*|
43
// into the right field of each X*Event that contains one.
44
//
45
46
namespace IPC {
47
48
template <>
49
struct ParamTraits<mozilla::plugins::NPRemoteEvent>     // synonym for XEvent
50
{
51
    typedef mozilla::plugins::NPRemoteEvent paramType;
52
53
    static void Write(Message* aMsg, const paramType& aParam)
54
0
    {
55
0
        aMsg->WriteBytes(&aParam, sizeof(paramType));
56
0
    }
57
58
    static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
59
0
    {
60
0
        if (!aMsg->ReadBytesInto(aIter, aResult, sizeof(paramType))) {
61
0
            return false;
62
0
        }
63
0
64
0
#ifdef MOZ_X11
65
0
        SetXDisplay(aResult->event);
66
0
#endif
67
0
        return true;
68
0
    }
69
70
    static void Log(const paramType& aParam, std::wstring* aLog)
71
0
    {
72
0
        // TODO
73
0
        aLog->append(L"(XEvent)");
74
0
    }
75
76
#ifdef MOZ_X11
77
private:
78
    static void SetXDisplay(XEvent& ev)
79
0
    {
80
0
        Display* display = mozilla::DefaultXDisplay();
81
0
        if (ev.type >= KeyPress) {
82
0
            ev.xany.display = display;
83
0
        }
84
0
        else {
85
0
            // XXX assuming that this is an error event
86
0
            // (type == 0? not clear from Xlib.h)
87
0
            ev.xerror.display = display;
88
0
        }
89
0
    }
90
#endif
91
};
92
93
} // namespace IPC
94
95
96
#endif // ifndef mozilla_dom_plugins_NPEventX11_h