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