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 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Plugin App.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * The Mozilla Foundation.
20 : * Portions created by the Initial Developer are Copyright (C) 2009
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Chris Jones <jones.chris.g@gmail.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef mozilla_dom_plugins_NPEventUnix_h
41 : #define mozilla_dom_plugins_NPEventUnix_h 1
42 :
43 : #include "npapi.h"
44 :
45 : #ifdef MOZ_X11
46 : #include "mozilla/X11Util.h"
47 : #endif
48 :
49 : namespace mozilla {
50 :
51 : namespace plugins {
52 :
53 : struct NPRemoteEvent {
54 : NPEvent event;
55 : };
56 :
57 : }
58 :
59 : }
60 :
61 :
62 : //
63 : // XEvent is defined as a union of all more specific X*Events.
64 : // Luckily, as of xorg 1.6.0 / X protocol 11 rev 0, the only pointer
65 : // field contained in any of these specific X*Event structs is a
66 : // |Display*|. So to simplify serializing these XEvents, we make the
67 : //
68 : // ********** XXX ASSUMPTION XXX **********
69 : //
70 : // that the process to which the event is forwarded shares the same
71 : // display as the process on which the event originated.
72 : //
73 : // With this simplification, serialization becomes a simple memcpy to
74 : // the output stream. Deserialization starts as just a memcpy from
75 : // the input stream, BUT we then have to write the correct |Display*|
76 : // into the right field of each X*Event that contains one.
77 : //
78 :
79 : namespace IPC {
80 :
81 : template <>
82 : struct ParamTraits<mozilla::plugins::NPRemoteEvent> // synonym for XEvent
83 : {
84 : typedef mozilla::plugins::NPRemoteEvent paramType;
85 :
86 0 : static void Write(Message* aMsg, const paramType& aParam)
87 : {
88 0 : aMsg->WriteBytes(&aParam, sizeof(paramType));
89 0 : }
90 :
91 0 : static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
92 : {
93 0 : const char* bytes = 0;
94 :
95 0 : if (!aMsg->ReadBytes(aIter, &bytes, sizeof(paramType))) {
96 0 : return false;
97 : }
98 :
99 0 : memcpy(aResult, bytes, sizeof(paramType));
100 :
101 : #ifdef MOZ_X11
102 0 : SetXDisplay(aResult->event);
103 : #endif
104 0 : return true;
105 : }
106 :
107 : static void Log(const paramType& aParam, std::wstring* aLog)
108 : {
109 : // TODO
110 : aLog->append(L"(XEvent)");
111 : }
112 :
113 : #ifdef MOZ_X11
114 : private:
115 0 : static void SetXDisplay(XEvent& ev)
116 : {
117 0 : Display* display = mozilla::DefaultXDisplay();
118 0 : if (ev.type >= KeyPress) {
119 0 : ev.xany.display = display;
120 : }
121 : else {
122 : // XXX assuming that this is an error event
123 : // (type == 0? not clear from Xlib.h)
124 0 : ev.xerror.display = display;
125 : }
126 0 : }
127 : #endif
128 : };
129 :
130 : } // namespace IPC
131 :
132 :
133 : #endif // ifndef mozilla_dom_plugins_NPEventX11_h
|