|
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/. */ |
|
6 |
|
7 #ifndef mozilla_dom_plugins_NPEventWindows_h |
|
8 #define mozilla_dom_plugins_NPEventWindows_h 1 |
|
9 |
|
10 |
|
11 #include "npapi.h" |
|
12 namespace mozilla { |
|
13 |
|
14 namespace plugins { |
|
15 |
|
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 }; |
|
26 |
|
27 } |
|
28 |
|
29 } |
|
30 |
|
31 namespace IPC { |
|
32 |
|
33 template <> |
|
34 struct ParamTraits<mozilla::plugins::NPRemoteEvent> |
|
35 { |
|
36 typedef mozilla::plugins::NPRemoteEvent paramType; |
|
37 |
|
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; |
|
43 |
|
44 paramCopy.event = aParam.event; |
|
45 |
|
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; |
|
62 |
|
63 // the white list of events that we will ipc to the client |
|
64 case WM_CHAR: |
|
65 case WM_SYSCHAR: |
|
66 |
|
67 case WM_KEYUP: |
|
68 case WM_SYSKEYUP: |
|
69 |
|
70 case WM_KEYDOWN: |
|
71 case WM_SYSKEYDOWN: |
|
72 |
|
73 case WM_DEADCHAR: |
|
74 case WM_SYSDEADCHAR: |
|
75 case WM_CONTEXTMENU: |
|
76 |
|
77 case WM_CUT: |
|
78 case WM_COPY: |
|
79 case WM_PASTE: |
|
80 case WM_CLEAR: |
|
81 case WM_UNDO: |
|
82 |
|
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: |
|
94 |
|
95 case WM_SETFOCUS: |
|
96 case WM_KILLFOCUS: |
|
97 break; |
|
98 |
|
99 default: |
|
100 // RegisterWindowMessage events should be passed. |
|
101 if (paramCopy.event.event >= 0xC000) |
|
102 break; |
|
103 |
|
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 } |
|
111 |
|
112 aMsg->WriteBytes(¶mCopy, sizeof(paramType)); |
|
113 } |
|
114 |
|
115 static bool Read(const Message* aMsg, void** aIter, paramType* aResult) |
|
116 { |
|
117 const char* bytes = 0; |
|
118 |
|
119 if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) { |
|
120 return false; |
|
121 } |
|
122 memcpy(aResult, bytes, sizeof(paramType)); |
|
123 |
|
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 } |
|
131 |
|
132 return true; |
|
133 } |
|
134 |
|
135 static void Log(const paramType& aParam, std::wstring* aLog) |
|
136 { |
|
137 aLog->append(L"(WINEvent)"); |
|
138 } |
|
139 |
|
140 }; |
|
141 |
|
142 } // namespace IPC |
|
143 |
|
144 #endif // ifndef mozilla_dom_plugins_NPEventWindows_h |