/work/obj-fuzz/dist/include/mozilla/plugins/PluginMessageUtils.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
2 | | * vim: sw=4 ts=4 et : |
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 DOM_PLUGINS_PLUGINMESSAGEUTILS_H |
8 | | #define DOM_PLUGINS_PLUGINMESSAGEUTILS_H |
9 | | |
10 | | #include "ipc/IPCMessageUtils.h" |
11 | | #include "base/message_loop.h" |
12 | | #include "base/shared_memory.h" |
13 | | |
14 | | #include "mozilla/ipc/CrossProcessMutex.h" |
15 | | #include "mozilla/ipc/MessageChannel.h" |
16 | | #include "mozilla/ipc/ProtocolUtils.h" |
17 | | #include "mozilla/UniquePtr.h" |
18 | | #include "gfxipc/ShadowLayerUtils.h" |
19 | | |
20 | | #include "npapi.h" |
21 | | #include "npruntime.h" |
22 | | #include "npfunctions.h" |
23 | | #include "nsString.h" |
24 | | #include "nsTArray.h" |
25 | | #include "mozilla/Logging.h" |
26 | | #include "nsHashKeys.h" |
27 | | |
28 | | #ifdef XP_MACOSX |
29 | | #include "PluginInterposeOSX.h" |
30 | | #else |
31 | | namespace mac_plugin_interposing { class NSCursorInfo { }; } |
32 | | #endif |
33 | | using mac_plugin_interposing::NSCursorInfo; |
34 | | |
35 | | namespace mozilla { |
36 | | namespace plugins { |
37 | | |
38 | | using layers::SurfaceDescriptorX11; |
39 | | |
40 | | enum ScriptableObjectType |
41 | | { |
42 | | LocalObject, |
43 | | Proxy |
44 | | }; |
45 | | |
46 | | mozilla::ipc::RacyInterruptPolicy |
47 | | MediateRace(const mozilla::ipc::MessageChannel::MessageInfo& parent, |
48 | | const mozilla::ipc::MessageChannel::MessageInfo& child); |
49 | | |
50 | | std::string |
51 | | MungePluginDsoPath(const std::string& path); |
52 | | std::string |
53 | | UnmungePluginDsoPath(const std::string& munged); |
54 | | |
55 | | extern mozilla::LogModule* GetPluginLog(); |
56 | | |
57 | | #if defined(_MSC_VER) |
58 | | #define FULLFUNCTION __FUNCSIG__ |
59 | | #elif defined(__GNUC__) |
60 | | #define FULLFUNCTION __PRETTY_FUNCTION__ |
61 | | #else |
62 | | #define FULLFUNCTION __FUNCTION__ |
63 | | #endif |
64 | | |
65 | | #define PLUGIN_LOG_DEBUG(args) MOZ_LOG(GetPluginLog(), mozilla::LogLevel::Debug, args) |
66 | | #define PLUGIN_LOG_DEBUG_FUNCTION MOZ_LOG(GetPluginLog(), mozilla::LogLevel::Debug, ("%s", FULLFUNCTION)) |
67 | | #define PLUGIN_LOG_DEBUG_METHOD MOZ_LOG(GetPluginLog(), mozilla::LogLevel::Debug, ("%s [%p]", FULLFUNCTION, (void*) this)) |
68 | | |
69 | | /** |
70 | | * This is NPByteRange without the linked list. |
71 | | */ |
72 | | struct IPCByteRange |
73 | | { |
74 | | int32_t offset; |
75 | | uint32_t length; |
76 | | }; |
77 | | |
78 | | typedef nsTArray<IPCByteRange> IPCByteRanges; |
79 | | |
80 | | typedef nsCString Buffer; |
81 | | |
82 | | struct NPRemoteWindow |
83 | | { |
84 | | NPRemoteWindow(); |
85 | | uint64_t window; |
86 | | int32_t x; |
87 | | int32_t y; |
88 | | uint32_t width; |
89 | | uint32_t height; |
90 | | NPRect clipRect; |
91 | | NPWindowType type; |
92 | | #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX) |
93 | | VisualID visualID; |
94 | | Colormap colormap; |
95 | | #endif /* XP_UNIX */ |
96 | | #if defined(XP_MACOSX) || defined(XP_WIN) |
97 | | double contentsScaleFactor; |
98 | | #endif |
99 | | }; |
100 | | |
101 | | // This struct is like NPAudioDeviceChangeDetails, only it uses a |
102 | | // std::wstring instead of a const wchar_t* for the defaultDevice. |
103 | | // This gives us the necessary memory-ownership semantics without |
104 | | // requiring C++ objects in npapi.h. |
105 | | struct NPAudioDeviceChangeDetailsIPC |
106 | | { |
107 | | int32_t flow; |
108 | | int32_t role; |
109 | | std::wstring defaultDevice; |
110 | | }; |
111 | | |
112 | | struct NPAudioDeviceStateChangedIPC |
113 | | { |
114 | | std::wstring device; |
115 | | uint32_t state; |
116 | | }; |
117 | | |
118 | | #ifdef XP_WIN |
119 | | typedef HWND NativeWindowHandle; |
120 | | #elif defined(MOZ_X11) |
121 | | typedef XID NativeWindowHandle; |
122 | | #elif defined(XP_DARWIN) || defined(ANDROID) |
123 | | typedef intptr_t NativeWindowHandle; // never actually used, will always be 0 |
124 | | #else |
125 | | #error Need NativeWindowHandle for this platform |
126 | | #endif |
127 | | |
128 | | #ifdef XP_WIN |
129 | | typedef base::SharedMemoryHandle WindowsSharedMemoryHandle; |
130 | | typedef HANDLE DXGISharedSurfaceHandle; |
131 | | #else // XP_WIN |
132 | | typedef mozilla::null_t WindowsSharedMemoryHandle; |
133 | | typedef mozilla::null_t DXGISharedSurfaceHandle; |
134 | | #endif |
135 | | |
136 | | // XXX maybe not the best place for these. better one? |
137 | | |
138 | | #define VARSTR(v_) case v_: return #v_ |
139 | | inline const char* |
140 | | NPPVariableToString(NPPVariable aVar) |
141 | | { |
142 | | switch (aVar) { |
143 | | VARSTR(NPPVpluginNameString); |
144 | | VARSTR(NPPVpluginDescriptionString); |
145 | | VARSTR(NPPVpluginWindowBool); |
146 | | VARSTR(NPPVpluginTransparentBool); |
147 | | VARSTR(NPPVjavaClass); |
148 | | VARSTR(NPPVpluginWindowSize); |
149 | | VARSTR(NPPVpluginTimerInterval); |
150 | | |
151 | | VARSTR(NPPVpluginScriptableInstance); |
152 | | VARSTR(NPPVpluginScriptableIID); |
153 | | |
154 | | VARSTR(NPPVjavascriptPushCallerBool); |
155 | | |
156 | | VARSTR(NPPVpluginKeepLibraryInMemory); |
157 | | VARSTR(NPPVpluginNeedsXEmbed); |
158 | | |
159 | | VARSTR(NPPVpluginScriptableNPObject); |
160 | | |
161 | | VARSTR(NPPVformValue); |
162 | | |
163 | | VARSTR(NPPVpluginUrlRequestsDisplayedBool); |
164 | | |
165 | | VARSTR(NPPVpluginWantsAllNetworkStreams); |
166 | | |
167 | | #ifdef XP_MACOSX |
168 | | VARSTR(NPPVpluginDrawingModel); |
169 | | VARSTR(NPPVpluginEventModel); |
170 | | #endif |
171 | | |
172 | | #ifdef XP_WIN |
173 | | VARSTR(NPPVpluginRequiresAudioDeviceChanges); |
174 | | #endif |
175 | | |
176 | | default: return "???"; |
177 | | } |
178 | | } |
179 | | |
180 | | inline const char* |
181 | | NPNVariableToString(NPNVariable aVar) |
182 | | { |
183 | | switch(aVar) { |
184 | | VARSTR(NPNVxDisplay); |
185 | | VARSTR(NPNVxtAppContext); |
186 | | VARSTR(NPNVnetscapeWindow); |
187 | | VARSTR(NPNVjavascriptEnabledBool); |
188 | | VARSTR(NPNVasdEnabledBool); |
189 | | VARSTR(NPNVisOfflineBool); |
190 | | |
191 | | VARSTR(NPNVserviceManager); |
192 | | VARSTR(NPNVDOMElement); |
193 | | VARSTR(NPNVDOMWindow); |
194 | | VARSTR(NPNVToolkit); |
195 | | VARSTR(NPNVSupportsXEmbedBool); |
196 | | |
197 | | VARSTR(NPNVWindowNPObject); |
198 | | |
199 | | VARSTR(NPNVPluginElementNPObject); |
200 | | |
201 | | VARSTR(NPNVSupportsWindowless); |
202 | | |
203 | | VARSTR(NPNVprivateModeBool); |
204 | | VARSTR(NPNVdocumentOrigin); |
205 | | |
206 | | #ifdef XP_WIN |
207 | | VARSTR(NPNVaudioDeviceChangeDetails); |
208 | | #endif |
209 | | |
210 | | default: return "???"; |
211 | | } |
212 | | } |
213 | | #undef VARSTR |
214 | | |
215 | | inline bool IsPluginThread() |
216 | | { |
217 | | MessageLoop* loop = MessageLoop::current(); |
218 | | if (!loop) |
219 | | return false; |
220 | | return (loop->type() == MessageLoop::TYPE_UI); |
221 | | } |
222 | | |
223 | | inline void AssertPluginThread() |
224 | | { |
225 | | MOZ_RELEASE_ASSERT(IsPluginThread(), "Should be on the plugin's main thread!"); |
226 | | } |
227 | | |
228 | | #define ENSURE_PLUGIN_THREAD(retval) \ |
229 | | PR_BEGIN_MACRO \ |
230 | | if (!IsPluginThread()) { \ |
231 | | NS_WARNING("Not running on the plugin's main thread!"); \ |
232 | | return (retval); \ |
233 | | } \ |
234 | | PR_END_MACRO |
235 | | |
236 | | #define ENSURE_PLUGIN_THREAD_VOID() \ |
237 | | PR_BEGIN_MACRO \ |
238 | | if (!IsPluginThread()) { \ |
239 | | NS_WARNING("Not running on the plugin's main thread!"); \ |
240 | | return; \ |
241 | | } \ |
242 | | PR_END_MACRO |
243 | | |
244 | | void DeferNPObjectLastRelease(const NPNetscapeFuncs* f, NPObject* o); |
245 | | void DeferNPVariantLastRelease(const NPNetscapeFuncs* f, NPVariant* v); |
246 | | |
247 | | inline bool IsDrawingModelDirect(int16_t aModel) |
248 | | { |
249 | | return aModel == NPDrawingModelAsyncBitmapSurface |
250 | | #if defined(XP_WIN) |
251 | | || aModel == NPDrawingModelAsyncWindowsDXGISurface |
252 | | #endif |
253 | | ; |
254 | | } |
255 | | |
256 | | // in NPAPI, char* == nullptr is sometimes meaningful. the following is |
257 | | // helper code for dealing with nullable nsCString's |
258 | | inline nsCString |
259 | | NullableString(const char* aString) |
260 | | { |
261 | | if (!aString) { |
262 | | return VoidCString(); |
263 | | } |
264 | | return nsCString(aString); |
265 | | } |
266 | | |
267 | | inline const char* |
268 | | NullableStringGet(const nsCString& str) |
269 | | { |
270 | | if (str.IsVoid()) |
271 | | return nullptr; |
272 | | |
273 | | return str.get(); |
274 | | } |
275 | | |
276 | | struct DeletingObjectEntry : public nsPtrHashKey<NPObject> |
277 | | { |
278 | | explicit DeletingObjectEntry(const NPObject* key) |
279 | | : nsPtrHashKey<NPObject>(key) |
280 | | , mDeleted(false) |
281 | | { } |
282 | | |
283 | | bool mDeleted; |
284 | | }; |
285 | | |
286 | | } /* namespace plugins */ |
287 | | |
288 | | } /* namespace mozilla */ |
289 | | |
290 | | namespace IPC { |
291 | | |
292 | | template <> |
293 | | struct ParamTraits<NPRect> |
294 | | { |
295 | | typedef NPRect paramType; |
296 | | |
297 | | static void Write(Message* aMsg, const paramType& aParam) |
298 | 0 | { |
299 | 0 | WriteParam(aMsg, aParam.top); |
300 | 0 | WriteParam(aMsg, aParam.left); |
301 | 0 | WriteParam(aMsg, aParam.bottom); |
302 | 0 | WriteParam(aMsg, aParam.right); |
303 | 0 | } |
304 | | |
305 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
306 | 0 | { |
307 | 0 | uint16_t top, left, bottom, right; |
308 | 0 | if (ReadParam(aMsg, aIter, &top) && |
309 | 0 | ReadParam(aMsg, aIter, &left) && |
310 | 0 | ReadParam(aMsg, aIter, &bottom) && |
311 | 0 | ReadParam(aMsg, aIter, &right)) { |
312 | 0 | aResult->top = top; |
313 | 0 | aResult->left = left; |
314 | 0 | aResult->bottom = bottom; |
315 | 0 | aResult->right = right; |
316 | 0 | return true; |
317 | 0 | } |
318 | 0 | return false; |
319 | 0 | } |
320 | | |
321 | | static void Log(const paramType& aParam, std::wstring* aLog) |
322 | 0 | { |
323 | 0 | aLog->append(StringPrintf(L"[%u, %u, %u, %u]", aParam.top, aParam.left, |
324 | 0 | aParam.bottom, aParam.right)); |
325 | 0 | } |
326 | | }; |
327 | | |
328 | | template <> |
329 | | struct ParamTraits<NPWindowType> : |
330 | | public ContiguousEnumSerializerInclusive<NPWindowType, |
331 | | NPWindowType::NPWindowTypeWindow, |
332 | | NPWindowType::NPWindowTypeDrawable> |
333 | | {}; |
334 | | |
335 | | template <> |
336 | | struct ParamTraits<mozilla::plugins::NPRemoteWindow> |
337 | | { |
338 | | typedef mozilla::plugins::NPRemoteWindow paramType; |
339 | | |
340 | | static void Write(Message* aMsg, const paramType& aParam) |
341 | 0 | { |
342 | 0 | aMsg->WriteUInt64(aParam.window); |
343 | 0 | WriteParam(aMsg, aParam.x); |
344 | 0 | WriteParam(aMsg, aParam.y); |
345 | 0 | WriteParam(aMsg, aParam.width); |
346 | 0 | WriteParam(aMsg, aParam.height); |
347 | 0 | WriteParam(aMsg, aParam.clipRect); |
348 | 0 | WriteParam(aMsg, aParam.type); |
349 | 0 | #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX) |
350 | 0 | aMsg->WriteULong(aParam.visualID); |
351 | 0 | aMsg->WriteULong(aParam.colormap); |
352 | 0 | #endif |
353 | | #if defined(XP_MACOSX) || defined(XP_WIN) |
354 | | aMsg->WriteDouble(aParam.contentsScaleFactor); |
355 | | #endif |
356 | | } |
357 | | |
358 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
359 | 0 | { |
360 | 0 | uint64_t window; |
361 | 0 | int32_t x, y; |
362 | 0 | uint32_t width, height; |
363 | 0 | NPRect clipRect; |
364 | 0 | NPWindowType type; |
365 | 0 | if (!(aMsg->ReadUInt64(aIter, &window) && |
366 | 0 | ReadParam(aMsg, aIter, &x) && |
367 | 0 | ReadParam(aMsg, aIter, &y) && |
368 | 0 | ReadParam(aMsg, aIter, &width) && |
369 | 0 | ReadParam(aMsg, aIter, &height) && |
370 | 0 | ReadParam(aMsg, aIter, &clipRect) && |
371 | 0 | ReadParam(aMsg, aIter, &type))) |
372 | 0 | return false; |
373 | 0 | |
374 | 0 | #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX) |
375 | 0 | unsigned long visualID; |
376 | 0 | unsigned long colormap; |
377 | 0 | if (!(aMsg->ReadULong(aIter, &visualID) && |
378 | 0 | aMsg->ReadULong(aIter, &colormap))) |
379 | 0 | return false; |
380 | 0 | #endif |
381 | 0 | |
382 | | #if defined(XP_MACOSX) || defined(XP_WIN) |
383 | | double contentsScaleFactor; |
384 | | if (!aMsg->ReadDouble(aIter, &contentsScaleFactor)) |
385 | | return false; |
386 | | #endif |
387 | | |
388 | 0 | aResult->window = window; |
389 | 0 | aResult->x = x; |
390 | 0 | aResult->y = y; |
391 | 0 | aResult->width = width; |
392 | 0 | aResult->height = height; |
393 | 0 | aResult->clipRect = clipRect; |
394 | 0 | aResult->type = type; |
395 | 0 | #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX) |
396 | 0 | aResult->visualID = visualID; |
397 | 0 | aResult->colormap = colormap; |
398 | 0 | #endif |
399 | | #if defined(XP_MACOSX) || defined(XP_WIN) |
400 | | aResult->contentsScaleFactor = contentsScaleFactor; |
401 | | #endif |
402 | | return true; |
403 | 0 | } |
404 | | |
405 | | static void Log(const paramType& aParam, std::wstring* aLog) |
406 | 0 | { |
407 | 0 | aLog->append(StringPrintf(L"[%u, %d, %d, %u, %u, %d", |
408 | 0 | (unsigned long)aParam.window, |
409 | 0 | aParam.x, aParam.y, aParam.width, |
410 | 0 | aParam.height, (long)aParam.type)); |
411 | 0 | } |
412 | | }; |
413 | | |
414 | | #ifdef XP_MACOSX |
415 | | template <> |
416 | | struct ParamTraits<NPNSString> |
417 | | { |
418 | | // Empty string writes a length of 0 and no buffer. |
419 | | // We don't write a nullptr terminating character in buffers. |
420 | | static void Write(Message* aMsg, NPNSString* aParam) |
421 | | { |
422 | | CFStringRef cfString = (CFStringRef)aParam; |
423 | | |
424 | | // Write true if we have a string, false represents nullptr. |
425 | | aMsg->WriteBool(!!cfString); |
426 | | if (!cfString) { |
427 | | return; |
428 | | } |
429 | | |
430 | | long length = ::CFStringGetLength(cfString); |
431 | | WriteParam(aMsg, length); |
432 | | if (length == 0) { |
433 | | return; |
434 | | } |
435 | | |
436 | | // Attempt to get characters without any allocation/conversion. |
437 | | if (::CFStringGetCharactersPtr(cfString)) { |
438 | | aMsg->WriteBytes(::CFStringGetCharactersPtr(cfString), length * sizeof(UniChar)); |
439 | | } else { |
440 | | UniChar *buffer = (UniChar*)moz_xmalloc(length * sizeof(UniChar)); |
441 | | ::CFStringGetCharacters(cfString, ::CFRangeMake(0, length), buffer); |
442 | | aMsg->WriteBytes(buffer, length * sizeof(UniChar)); |
443 | | free(buffer); |
444 | | } |
445 | | } |
446 | | |
447 | | static bool Read(const Message* aMsg, PickleIterator* aIter, NPNSString** aResult) |
448 | | { |
449 | | bool haveString = false; |
450 | | if (!aMsg->ReadBool(aIter, &haveString)) { |
451 | | return false; |
452 | | } |
453 | | if (!haveString) { |
454 | | *aResult = nullptr; |
455 | | return true; |
456 | | } |
457 | | |
458 | | long length; |
459 | | if (!ReadParam(aMsg, aIter, &length)) { |
460 | | return false; |
461 | | } |
462 | | |
463 | | // Avoid integer multiplication overflow. |
464 | | if (length > INT_MAX / static_cast<long>(sizeof(UniChar))) { |
465 | | return false; |
466 | | } |
467 | | |
468 | | auto chars = mozilla::MakeUnique<UniChar[]>(length); |
469 | | if (length != 0) { |
470 | | if (!aMsg->ReadBytesInto(aIter, chars.get(), length * sizeof(UniChar))) { |
471 | | return false; |
472 | | } |
473 | | } |
474 | | |
475 | | *aResult = (NPNSString*)::CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*)chars.get(), |
476 | | length * sizeof(UniChar), |
477 | | kCFStringEncodingUTF16, false); |
478 | | if (!*aResult) { |
479 | | return false; |
480 | | } |
481 | | |
482 | | return true; |
483 | | } |
484 | | }; |
485 | | #endif |
486 | | |
487 | | #ifdef XP_MACOSX |
488 | | template <> |
489 | | struct ParamTraits<NSCursorInfo> |
490 | | { |
491 | | typedef NSCursorInfo paramType; |
492 | | |
493 | | static void Write(Message* aMsg, const paramType& aParam) |
494 | | { |
495 | | NSCursorInfo::Type type = aParam.GetType(); |
496 | | |
497 | | aMsg->WriteInt(type); |
498 | | |
499 | | nsPoint hotSpot = aParam.GetHotSpot(); |
500 | | WriteParam(aMsg, hotSpot.x); |
501 | | WriteParam(aMsg, hotSpot.y); |
502 | | |
503 | | uint32_t dataLength = aParam.GetCustomImageDataLength(); |
504 | | WriteParam(aMsg, dataLength); |
505 | | if (dataLength == 0) { |
506 | | return; |
507 | | } |
508 | | |
509 | | uint8_t* buffer = (uint8_t*)moz_xmalloc(dataLength); |
510 | | memcpy(buffer, aParam.GetCustomImageData(), dataLength); |
511 | | aMsg->WriteBytes(buffer, dataLength); |
512 | | free(buffer); |
513 | | } |
514 | | |
515 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
516 | | { |
517 | | NSCursorInfo::Type type; |
518 | | if (!aMsg->ReadInt(aIter, (int*)&type)) { |
519 | | return false; |
520 | | } |
521 | | |
522 | | nscoord hotSpotX, hotSpotY; |
523 | | if (!ReadParam(aMsg, aIter, &hotSpotX) || |
524 | | !ReadParam(aMsg, aIter, &hotSpotY)) { |
525 | | return false; |
526 | | } |
527 | | |
528 | | uint32_t dataLength; |
529 | | if (!ReadParam(aMsg, aIter, &dataLength)) { |
530 | | return false; |
531 | | } |
532 | | |
533 | | auto data = mozilla::MakeUnique<uint8_t[]>(dataLength); |
534 | | if (dataLength != 0) { |
535 | | if (!aMsg->ReadBytesInto(aIter, data.get(), dataLength)) { |
536 | | return false; |
537 | | } |
538 | | } |
539 | | |
540 | | aResult->SetType(type); |
541 | | aResult->SetHotSpot(nsPoint(hotSpotX, hotSpotY)); |
542 | | aResult->SetCustomImageData(data.get(), dataLength); |
543 | | |
544 | | return true; |
545 | | } |
546 | | |
547 | | static void Log(const paramType& aParam, std::wstring* aLog) |
548 | | { |
549 | | const char* typeName = aParam.GetTypeName(); |
550 | | nsPoint hotSpot = aParam.GetHotSpot(); |
551 | | int hotSpotX, hotSpotY; |
552 | | #ifdef NS_COORD_IS_FLOAT |
553 | | hotSpotX = rint(hotSpot.x); |
554 | | hotSpotY = rint(hotSpot.y); |
555 | | #else |
556 | | hotSpotX = hotSpot.x; |
557 | | hotSpotY = hotSpot.y; |
558 | | #endif |
559 | | uint32_t dataLength = aParam.GetCustomImageDataLength(); |
560 | | uint8_t* data = aParam.GetCustomImageData(); |
561 | | |
562 | | aLog->append(StringPrintf(L"[%s, (%i %i), %u, %p]", |
563 | | typeName, hotSpotX, hotSpotY, dataLength, data)); |
564 | | } |
565 | | }; |
566 | | #else |
567 | | template<> |
568 | | struct ParamTraits<NSCursorInfo> |
569 | | { |
570 | | typedef NSCursorInfo paramType; |
571 | 0 | static void Write(Message* aMsg, const paramType& aParam) { |
572 | 0 | MOZ_CRASH("NSCursorInfo isn't meaningful on this platform"); |
573 | 0 | } |
574 | 0 | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) { |
575 | 0 | MOZ_CRASH("NSCursorInfo isn't meaningful on this platform"); |
576 | 0 | return false; |
577 | 0 | } |
578 | | }; |
579 | | #endif // #ifdef XP_MACOSX |
580 | | |
581 | | template <> |
582 | | struct ParamTraits<mozilla::plugins::IPCByteRange> |
583 | | { |
584 | | typedef mozilla::plugins::IPCByteRange paramType; |
585 | | |
586 | | static void Write(Message* aMsg, const paramType& aParam) |
587 | 0 | { |
588 | 0 | WriteParam(aMsg, aParam.offset); |
589 | 0 | WriteParam(aMsg, aParam.length); |
590 | 0 | } |
591 | | |
592 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
593 | 0 | { |
594 | 0 | paramType p; |
595 | 0 | if (ReadParam(aMsg, aIter, &p.offset) && |
596 | 0 | ReadParam(aMsg, aIter, &p.length)) { |
597 | 0 | *aResult = p; |
598 | 0 | return true; |
599 | 0 | } |
600 | 0 | return false; |
601 | 0 | } |
602 | | }; |
603 | | |
604 | | template <> |
605 | | struct ParamTraits<NPNVariable> : |
606 | | public ContiguousEnumSerializer<NPNVariable, |
607 | | NPNVariable::NPNVxDisplay, |
608 | | NPNVariable::NPNVLast> |
609 | | {}; |
610 | | |
611 | | // The only accepted value is NPNURLVariable::NPNURLVProxy |
612 | | template<> |
613 | | struct ParamTraits<NPNURLVariable> : |
614 | | public ContiguousEnumSerializerInclusive<NPNURLVariable, |
615 | | NPNURLVariable::NPNURLVProxy, |
616 | | NPNURLVariable::NPNURLVProxy> |
617 | | {}; |
618 | | |
619 | | template<> |
620 | | struct ParamTraits<NPCoordinateSpace> : |
621 | | public ContiguousEnumSerializerInclusive<NPCoordinateSpace, |
622 | | NPCoordinateSpace::NPCoordinateSpacePlugin, |
623 | | NPCoordinateSpace::NPCoordinateSpaceFlippedScreen> |
624 | | {}; |
625 | | |
626 | | template <> |
627 | | struct ParamTraits<mozilla::plugins::NPAudioDeviceChangeDetailsIPC> |
628 | | { |
629 | | typedef mozilla::plugins::NPAudioDeviceChangeDetailsIPC paramType; |
630 | | |
631 | | static void Write(Message* aMsg, const paramType& aParam) |
632 | 0 | { |
633 | 0 | WriteParam(aMsg, aParam.flow); |
634 | 0 | WriteParam(aMsg, aParam.role); |
635 | 0 | WriteParam(aMsg, aParam.defaultDevice); |
636 | 0 | } |
637 | | |
638 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
639 | 0 | { |
640 | 0 | int32_t flow, role; |
641 | 0 | std::wstring defaultDevice; |
642 | 0 | if (ReadParam(aMsg, aIter, &flow) && |
643 | 0 | ReadParam(aMsg, aIter, &role) && |
644 | 0 | ReadParam(aMsg, aIter, &defaultDevice)) { |
645 | 0 | aResult->flow = flow; |
646 | 0 | aResult->role = role; |
647 | 0 | aResult->defaultDevice = defaultDevice; |
648 | 0 | return true; |
649 | 0 | } |
650 | 0 | return false; |
651 | 0 | } |
652 | | |
653 | | static void Log(const paramType& aParam, std::wstring* aLog) |
654 | 0 | { |
655 | 0 | aLog->append(StringPrintf(L"[%d, %d, %S]", aParam.flow, aParam.role, |
656 | 0 | aParam.defaultDevice.c_str())); |
657 | 0 | } |
658 | | }; |
659 | | |
660 | | |
661 | | template <> |
662 | | struct ParamTraits<mozilla::plugins::NPAudioDeviceStateChangedIPC> |
663 | | { |
664 | | typedef mozilla::plugins::NPAudioDeviceStateChangedIPC paramType; |
665 | | |
666 | | static void Write(Message* aMsg, const paramType& aParam) |
667 | 0 | { |
668 | 0 | WriteParam(aMsg, aParam.device); |
669 | 0 | WriteParam(aMsg, aParam.state); |
670 | 0 | } |
671 | | |
672 | | static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) |
673 | 0 | { |
674 | 0 | int32_t state; |
675 | 0 | std::wstring device; |
676 | 0 | if (ReadParam(aMsg, aIter, &device) && ReadParam(aMsg, aIter, &state)) { |
677 | 0 | aResult->device = device; |
678 | 0 | aResult->state = state; |
679 | 0 | return true; |
680 | 0 | } |
681 | 0 | return false; |
682 | 0 | } |
683 | | |
684 | | static void Log(const paramType& aParam, std::wstring* aLog) |
685 | 0 | { |
686 | 0 | aLog->append(StringPrintf(L"[%S,%d]", aParam.device.c_str(), aParam.state)); |
687 | 0 | } |
688 | | }; |
689 | | } /* namespace IPC */ |
690 | | |
691 | | |
692 | | // Serializing NPEvents is completely platform-specific and can be rather |
693 | | // intricate depending on the platform. So for readability we split it |
694 | | // into separate files and have the only macro crud live here. |
695 | | // |
696 | | // NB: these guards are based on those where struct NPEvent is defined |
697 | | // in npapi.h. They should be kept in sync. |
698 | | #if defined(XP_MACOSX) |
699 | | # include "mozilla/plugins/NPEventOSX.h" |
700 | | #elif defined(XP_WIN) |
701 | | # include "mozilla/plugins/NPEventWindows.h" |
702 | | #elif defined(ANDROID) |
703 | | # include "mozilla/plugins/NPEventAndroid.h" |
704 | | #elif defined(XP_UNIX) |
705 | | # include "mozilla/plugins/NPEventUnix.h" |
706 | | #else |
707 | | # error Unsupported platform |
708 | | #endif |
709 | | |
710 | | #endif /* DOM_PLUGINS_PLUGINMESSAGEUTILS_H */ |