dom/plugins/ipc/NPEventWindows.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_NPEventWindows_h
     8 #define mozilla_dom_plugins_NPEventWindows_h 1
    11 #include "npapi.h"
    12 namespace mozilla {
    14 namespace plugins {
    16 // We use an NPRemoteEvent struct so that we can store the extra data on
    17 // the stack so that we don't need to worry about managing the memory.
    18 struct NPRemoteEvent
    19 {
    20     NPEvent event;
    21     union {
    22         RECT rect;
    23         WINDOWPOS windowpos;
    24     } lParamData;
    25 };
    27 }
    29 }
    31 namespace IPC {
    33 template <>
    34 struct ParamTraits<mozilla::plugins::NPRemoteEvent>
    35 {
    36     typedef mozilla::plugins::NPRemoteEvent paramType;
    38     static void Write(Message* aMsg, const paramType& aParam)
    39     {
    40         // Make a non-const copy of aParam so that we can muck with
    41         // its insides for tranport
    42         paramType paramCopy;
    44         paramCopy.event = aParam.event;
    46         // We can't blindly ipc events because they may sometimes contain
    47         // pointers to memory in the sending process. For example, the
    48         // WM_IME_CONTROL with the IMC_GETCOMPOSITIONFONT message has lParam
    49         // set to a pointer to a LOGFONT structure.
    50         switch (paramCopy.event.event) {
    51             case WM_WINDOWPOSCHANGED:
    52                 // The lParam parameter of WM_WINDOWPOSCHANGED holds a pointer to
    53                 // a WINDOWPOS structure that contains information about the
    54                 // window's new size and position
    55                 paramCopy.lParamData.windowpos = *(reinterpret_cast<WINDOWPOS*>(paramCopy.event.lParam));
    56                 break;
    57             case WM_PAINT:
    58                 // The lParam parameter of WM_PAINT holds a pointer to an RECT
    59                 // structure specifying the bounding box of the update area.
    60                 paramCopy.lParamData.rect = *(reinterpret_cast<RECT*>(paramCopy.event.lParam));
    61                 break;
    63             // the white list of events that we will ipc to the client
    64             case WM_CHAR:
    65             case WM_SYSCHAR:
    67             case WM_KEYUP:
    68             case WM_SYSKEYUP:
    70             case WM_KEYDOWN:
    71             case WM_SYSKEYDOWN:
    73             case WM_DEADCHAR:
    74             case WM_SYSDEADCHAR:
    75             case WM_CONTEXTMENU:
    77             case WM_CUT:
    78             case WM_COPY:
    79             case WM_PASTE:
    80             case WM_CLEAR:
    81             case WM_UNDO:
    83             case WM_MOUSELEAVE:
    84             case WM_MOUSEMOVE:
    85             case WM_LBUTTONDOWN:
    86             case WM_MBUTTONDOWN:
    87             case WM_RBUTTONDOWN:
    88             case WM_LBUTTONUP:
    89             case WM_MBUTTONUP:
    90             case WM_RBUTTONUP:
    91             case WM_LBUTTONDBLCLK:
    92             case WM_MBUTTONDBLCLK:
    93             case WM_RBUTTONDBLCLK:
    95             case WM_SETFOCUS:
    96             case WM_KILLFOCUS:
    97                 break;
    99             default:
   100                 // RegisterWindowMessage events should be passed.
   101                 if (paramCopy.event.event >= 0xC000)
   102                     break;
   104                 // FIXME/bug 567465: temporarily work around unhandled
   105                 // events by forwarding a "dummy event".  The eventual
   106                 // fix will be to stop trying to send these events
   107                 // entirely.
   108                 paramCopy.event.event = WM_NULL;
   109                 break;
   110         }
   112         aMsg->WriteBytes(&paramCopy, sizeof(paramType));
   113     }
   115     static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   116     {
   117         const char* bytes = 0;
   119         if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) {
   120             return false;
   121         }
   122         memcpy(aResult, bytes, sizeof(paramType));
   124         if (aResult->event.event == WM_PAINT) {
   125             // restore the lParam to point at the RECT
   126             aResult->event.lParam = reinterpret_cast<LPARAM>(&aResult->lParamData.rect);
   127         } else if (aResult->event.event == WM_WINDOWPOSCHANGED) {
   128             // restore the lParam to point at the WINDOWPOS
   129             aResult->event.lParam = reinterpret_cast<LPARAM>(&aResult->lParamData.windowpos);
   130         }
   132         return true;
   133     }
   135     static void Log(const paramType& aParam, std::wstring* aLog)
   136     {
   137         aLog->append(L"(WINEvent)");
   138     }
   140 };
   142 } // namespace IPC
   144 #endif // ifndef mozilla_dom_plugins_NPEventWindows_h

mercurial