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