1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/ipc/NPEventUnix.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */ 1.5 +/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_plugins_NPEventUnix_h 1.11 +#define mozilla_dom_plugins_NPEventUnix_h 1 1.12 + 1.13 +#include "npapi.h" 1.14 + 1.15 +#ifdef MOZ_X11 1.16 +#include "mozilla/X11Util.h" 1.17 +#endif 1.18 + 1.19 +namespace mozilla { 1.20 + 1.21 +namespace plugins { 1.22 + 1.23 +struct NPRemoteEvent { 1.24 + NPEvent event; 1.25 +}; 1.26 + 1.27 +} 1.28 + 1.29 +} 1.30 + 1.31 + 1.32 +// 1.33 +// XEvent is defined as a union of all more specific X*Events. 1.34 +// Luckily, as of xorg 1.6.0 / X protocol 11 rev 0, the only pointer 1.35 +// field contained in any of these specific X*Event structs is a 1.36 +// |Display*|. So to simplify serializing these XEvents, we make the 1.37 +// 1.38 +// ********** XXX ASSUMPTION XXX ********** 1.39 +// 1.40 +// that the process to which the event is forwarded shares the same 1.41 +// display as the process on which the event originated. 1.42 +// 1.43 +// With this simplification, serialization becomes a simple memcpy to 1.44 +// the output stream. Deserialization starts as just a memcpy from 1.45 +// the input stream, BUT we then have to write the correct |Display*| 1.46 +// into the right field of each X*Event that contains one. 1.47 +// 1.48 + 1.49 +namespace IPC { 1.50 + 1.51 +template <> 1.52 +struct ParamTraits<mozilla::plugins::NPRemoteEvent> // synonym for XEvent 1.53 +{ 1.54 + typedef mozilla::plugins::NPRemoteEvent paramType; 1.55 + 1.56 + static void Write(Message* aMsg, const paramType& aParam) 1.57 + { 1.58 + aMsg->WriteBytes(&aParam, sizeof(paramType)); 1.59 + } 1.60 + 1.61 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.62 + { 1.63 + const char* bytes = 0; 1.64 + 1.65 + if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) { 1.66 + return false; 1.67 + } 1.68 + 1.69 + memcpy(aResult, bytes, sizeof(paramType)); 1.70 + 1.71 +#ifdef MOZ_X11 1.72 + SetXDisplay(aResult->event); 1.73 +#endif 1.74 + return true; 1.75 + } 1.76 + 1.77 + static void Log(const paramType& aParam, std::wstring* aLog) 1.78 + { 1.79 + // TODO 1.80 + aLog->append(L"(XEvent)"); 1.81 + } 1.82 + 1.83 +#ifdef MOZ_X11 1.84 +private: 1.85 + static void SetXDisplay(XEvent& ev) 1.86 + { 1.87 + Display* display = mozilla::DefaultXDisplay(); 1.88 + if (ev.type >= KeyPress) { 1.89 + ev.xany.display = display; 1.90 + } 1.91 + else { 1.92 + // XXX assuming that this is an error event 1.93 + // (type == 0? not clear from Xlib.h) 1.94 + ev.xerror.display = display; 1.95 + } 1.96 + } 1.97 +#endif 1.98 +}; 1.99 + 1.100 +} // namespace IPC 1.101 + 1.102 + 1.103 +#endif // ifndef mozilla_dom_plugins_NPEventX11_h