dom/plugins/ipc/NPEventUnix.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 #ifndef mozilla_dom_plugins_NPEventUnix_h
     8 #define mozilla_dom_plugins_NPEventUnix_h 1
    10 #include "npapi.h"
    12 #ifdef MOZ_X11
    13 #include "mozilla/X11Util.h"
    14 #endif
    16 namespace mozilla {
    18 namespace plugins {
    20 struct NPRemoteEvent {
    21     NPEvent event;
    22 };
    24 }
    26 }
    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 //
    46 namespace IPC {
    48 template <>
    49 struct ParamTraits<mozilla::plugins::NPRemoteEvent>     // synonym for XEvent
    50 {
    51     typedef mozilla::plugins::NPRemoteEvent paramType;
    53     static void Write(Message* aMsg, const paramType& aParam)
    54     {
    55         aMsg->WriteBytes(&aParam, sizeof(paramType));
    56     }
    58     static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    59     {
    60         const char* bytes = 0;
    62         if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) {
    63             return false;
    64         }
    66         memcpy(aResult, bytes, sizeof(paramType));
    68 #ifdef MOZ_X11
    69         SetXDisplay(aResult->event);
    70 #endif
    71         return true;
    72     }
    74     static void Log(const paramType& aParam, std::wstring* aLog)
    75     {
    76         // TODO
    77         aLog->append(L"(XEvent)");
    78     }
    80 #ifdef MOZ_X11
    81 private:
    82     static void SetXDisplay(XEvent& ev)
    83     {
    84         Display* display = mozilla::DefaultXDisplay();
    85         if (ev.type >= KeyPress) {
    86             ev.xany.display = display;
    87         }
    88         else {
    89             // XXX assuming that this is an error event
    90             // (type == 0? not clear from Xlib.h)
    91             ev.xerror.display = display;
    92         }
    93     }
    94 #endif
    95 };
    97 } // namespace IPC
   100 #endif // ifndef mozilla_dom_plugins_NPEventX11_h

mercurial