1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/ipc/NPEventWindows.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,144 @@ 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_NPEventWindows_h 1.11 +#define mozilla_dom_plugins_NPEventWindows_h 1 1.12 + 1.13 + 1.14 +#include "npapi.h" 1.15 +namespace mozilla { 1.16 + 1.17 +namespace plugins { 1.18 + 1.19 +// We use an NPRemoteEvent struct so that we can store the extra data on 1.20 +// the stack so that we don't need to worry about managing the memory. 1.21 +struct NPRemoteEvent 1.22 +{ 1.23 + NPEvent event; 1.24 + union { 1.25 + RECT rect; 1.26 + WINDOWPOS windowpos; 1.27 + } lParamData; 1.28 +}; 1.29 + 1.30 +} 1.31 + 1.32 +} 1.33 + 1.34 +namespace IPC { 1.35 + 1.36 +template <> 1.37 +struct ParamTraits<mozilla::plugins::NPRemoteEvent> 1.38 +{ 1.39 + typedef mozilla::plugins::NPRemoteEvent paramType; 1.40 + 1.41 + static void Write(Message* aMsg, const paramType& aParam) 1.42 + { 1.43 + // Make a non-const copy of aParam so that we can muck with 1.44 + // its insides for tranport 1.45 + paramType paramCopy; 1.46 + 1.47 + paramCopy.event = aParam.event; 1.48 + 1.49 + // We can't blindly ipc events because they may sometimes contain 1.50 + // pointers to memory in the sending process. For example, the 1.51 + // WM_IME_CONTROL with the IMC_GETCOMPOSITIONFONT message has lParam 1.52 + // set to a pointer to a LOGFONT structure. 1.53 + switch (paramCopy.event.event) { 1.54 + case WM_WINDOWPOSCHANGED: 1.55 + // The lParam parameter of WM_WINDOWPOSCHANGED holds a pointer to 1.56 + // a WINDOWPOS structure that contains information about the 1.57 + // window's new size and position 1.58 + paramCopy.lParamData.windowpos = *(reinterpret_cast<WINDOWPOS*>(paramCopy.event.lParam)); 1.59 + break; 1.60 + case WM_PAINT: 1.61 + // The lParam parameter of WM_PAINT holds a pointer to an RECT 1.62 + // structure specifying the bounding box of the update area. 1.63 + paramCopy.lParamData.rect = *(reinterpret_cast<RECT*>(paramCopy.event.lParam)); 1.64 + break; 1.65 + 1.66 + // the white list of events that we will ipc to the client 1.67 + case WM_CHAR: 1.68 + case WM_SYSCHAR: 1.69 + 1.70 + case WM_KEYUP: 1.71 + case WM_SYSKEYUP: 1.72 + 1.73 + case WM_KEYDOWN: 1.74 + case WM_SYSKEYDOWN: 1.75 + 1.76 + case WM_DEADCHAR: 1.77 + case WM_SYSDEADCHAR: 1.78 + case WM_CONTEXTMENU: 1.79 + 1.80 + case WM_CUT: 1.81 + case WM_COPY: 1.82 + case WM_PASTE: 1.83 + case WM_CLEAR: 1.84 + case WM_UNDO: 1.85 + 1.86 + case WM_MOUSELEAVE: 1.87 + case WM_MOUSEMOVE: 1.88 + case WM_LBUTTONDOWN: 1.89 + case WM_MBUTTONDOWN: 1.90 + case WM_RBUTTONDOWN: 1.91 + case WM_LBUTTONUP: 1.92 + case WM_MBUTTONUP: 1.93 + case WM_RBUTTONUP: 1.94 + case WM_LBUTTONDBLCLK: 1.95 + case WM_MBUTTONDBLCLK: 1.96 + case WM_RBUTTONDBLCLK: 1.97 + 1.98 + case WM_SETFOCUS: 1.99 + case WM_KILLFOCUS: 1.100 + break; 1.101 + 1.102 + default: 1.103 + // RegisterWindowMessage events should be passed. 1.104 + if (paramCopy.event.event >= 0xC000) 1.105 + break; 1.106 + 1.107 + // FIXME/bug 567465: temporarily work around unhandled 1.108 + // events by forwarding a "dummy event". The eventual 1.109 + // fix will be to stop trying to send these events 1.110 + // entirely. 1.111 + paramCopy.event.event = WM_NULL; 1.112 + break; 1.113 + } 1.114 + 1.115 + aMsg->WriteBytes(¶mCopy, sizeof(paramType)); 1.116 + } 1.117 + 1.118 + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) 1.119 + { 1.120 + const char* bytes = 0; 1.121 + 1.122 + if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) { 1.123 + return false; 1.124 + } 1.125 + memcpy(aResult, bytes, sizeof(paramType)); 1.126 + 1.127 + if (aResult->event.event == WM_PAINT) { 1.128 + // restore the lParam to point at the RECT 1.129 + aResult->event.lParam = reinterpret_cast<LPARAM>(&aResult->lParamData.rect); 1.130 + } else if (aResult->event.event == WM_WINDOWPOSCHANGED) { 1.131 + // restore the lParam to point at the WINDOWPOS 1.132 + aResult->event.lParam = reinterpret_cast<LPARAM>(&aResult->lParamData.windowpos); 1.133 + } 1.134 + 1.135 + return true; 1.136 + } 1.137 + 1.138 + static void Log(const paramType& aParam, std::wstring* aLog) 1.139 + { 1.140 + aLog->append(L"(WINEvent)"); 1.141 + } 1.142 + 1.143 +}; 1.144 + 1.145 +} // namespace IPC 1.146 + 1.147 +#endif // ifndef mozilla_dom_plugins_NPEventWindows_h