Line data Source code
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 :
13 : #include "mozilla/ipc/CrossProcessMutex.h"
14 : #include "mozilla/ipc/MessageChannel.h"
15 : #include "mozilla/ipc/ProtocolUtils.h"
16 : #include "mozilla/UniquePtr.h"
17 : #include "gfxipc/ShadowLayerUtils.h"
18 :
19 : #include "npapi.h"
20 : #include "npruntime.h"
21 : #include "npfunctions.h"
22 : #include "nsString.h"
23 : #include "nsTArray.h"
24 : #include "mozilla/Logging.h"
25 : #include "nsHashKeys.h"
26 : #ifdef MOZ_CRASHREPORTER
27 : # include "nsExceptionHandler.h"
28 : #endif
29 : #ifdef XP_MACOSX
30 : #include "PluginInterposeOSX.h"
31 : #else
32 : namespace mac_plugin_interposing { class NSCursorInfo { }; }
33 : #endif
34 : using mac_plugin_interposing::NSCursorInfo;
35 : #ifdef XP_WIN
36 : #include "commdlg.h"
37 : #endif
38 :
39 : namespace mozilla {
40 : namespace plugins {
41 :
42 : using layers::SurfaceDescriptorX11;
43 :
44 : enum ScriptableObjectType
45 : {
46 : LocalObject,
47 : Proxy
48 : };
49 :
50 : mozilla::ipc::RacyInterruptPolicy
51 : MediateRace(const mozilla::ipc::MessageChannel::MessageInfo& parent,
52 : const mozilla::ipc::MessageChannel::MessageInfo& child);
53 :
54 : std::string
55 : MungePluginDsoPath(const std::string& path);
56 : std::string
57 : UnmungePluginDsoPath(const std::string& munged);
58 :
59 : extern mozilla::LogModule* GetPluginLog();
60 :
61 : #if defined(_MSC_VER)
62 : #define FULLFUNCTION __FUNCSIG__
63 : #elif defined(__GNUC__)
64 : #define FULLFUNCTION __PRETTY_FUNCTION__
65 : #else
66 : #define FULLFUNCTION __FUNCTION__
67 : #endif
68 :
69 : #define PLUGIN_LOG_DEBUG(args) MOZ_LOG(GetPluginLog(), mozilla::LogLevel::Debug, args)
70 : #define PLUGIN_LOG_DEBUG_FUNCTION MOZ_LOG(GetPluginLog(), mozilla::LogLevel::Debug, ("%s", FULLFUNCTION))
71 : #define PLUGIN_LOG_DEBUG_METHOD MOZ_LOG(GetPluginLog(), mozilla::LogLevel::Debug, ("%s [%p]", FULLFUNCTION, (void*) this))
72 :
73 : /**
74 : * This is NPByteRange without the linked list.
75 : */
76 : struct IPCByteRange
77 : {
78 : int32_t offset;
79 : uint32_t length;
80 : };
81 :
82 : typedef nsTArray<IPCByteRange> IPCByteRanges;
83 :
84 : typedef nsCString Buffer;
85 :
86 : struct NPRemoteWindow
87 : {
88 : NPRemoteWindow();
89 : uint64_t window;
90 : int32_t x;
91 : int32_t y;
92 : uint32_t width;
93 : uint32_t height;
94 : NPRect clipRect;
95 : NPWindowType type;
96 : #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
97 : VisualID visualID;
98 : Colormap colormap;
99 : #endif /* XP_UNIX */
100 : #if defined(XP_MACOSX) || defined(XP_WIN)
101 : double contentsScaleFactor;
102 : #endif
103 : };
104 :
105 : // This struct is like NPAudioDeviceChangeDetails, only it uses a
106 : // std::wstring instead of a const wchar_t* for the defaultDevice.
107 : // This gives us the necessary memory-ownership semantics without
108 : // requiring C++ objects in npapi.h.
109 0 : struct NPAudioDeviceChangeDetailsIPC
110 : {
111 : int32_t flow;
112 : int32_t role;
113 : std::wstring defaultDevice;
114 : };
115 :
116 : #ifdef XP_WIN
117 : typedef HWND NativeWindowHandle;
118 : #elif defined(MOZ_X11)
119 : typedef XID NativeWindowHandle;
120 : #elif defined(XP_DARWIN) || defined(ANDROID)
121 : typedef intptr_t NativeWindowHandle; // never actually used, will always be 0
122 : #else
123 : #error Need NativeWindowHandle for this platform
124 : #endif
125 :
126 : #ifdef XP_WIN
127 : typedef base::SharedMemoryHandle WindowsSharedMemoryHandle;
128 : typedef HANDLE DXGISharedSurfaceHandle;
129 :
130 : // Values indicate GetOpenFileNameW and GetSaveFileNameW.
131 : enum GetFileNameFunc { OPEN_FUNC, SAVE_FUNC };
132 :
133 : // IPC-capable version of the Windows OPENFILENAMEW struct.
134 : typedef struct _OpenFileNameIPC
135 : {
136 : // Allocates memory for the strings in this object. This should usually
137 : // be used with a zeroed out OPENFILENAMEW structure.
138 : void AllocateOfnStrings(LPOPENFILENAMEW aLpofn) const;
139 : void FreeOfnStrings(LPOPENFILENAMEW aLpofn) const;
140 : void AddToOfn(LPOPENFILENAMEW aLpofn) const;
141 : void CopyFromOfn(LPOPENFILENAMEW aLpofn);
142 :
143 : NativeWindowHandle mHwndOwner;
144 : std::wstring mFilter; // Double-NULL terminated (i.e. L"\0\0") if mHasFilter is true
145 : bool mHasFilter;
146 : std::wstring mCustomFilterIn;
147 : bool mHasCustomFilter;
148 : uint32_t mNMaxCustFilterOut;
149 : uint32_t mFilterIndex;
150 : std::wstring mFile;
151 : uint32_t mNMaxFile;
152 : uint32_t mNMaxFileTitle;
153 : std::wstring mInitialDir;
154 : bool mHasInitialDir;
155 : std::wstring mTitle;
156 : bool mHasTitle;
157 : uint32_t mFlags;
158 : std::wstring mDefExt;
159 : bool mHasDefExt;
160 : uint32_t mFlagsEx;
161 : } OpenFileNameIPC;
162 :
163 : // GetOpenFileNameW and GetSaveFileNameW overwrite fields of their OPENFILENAMEW
164 : // parameter. This represents those values so that they can be returned via IPC.
165 : typedef struct _OpenFileNameRetIPC
166 : {
167 : void CopyFromOfn(LPOPENFILENAMEW aLpofn);
168 : void AddToOfn(LPOPENFILENAMEW aLpofn) const;
169 :
170 : std::wstring mCustomFilterOut;
171 : std::wstring mFile; // Double-NULL terminated (i.e. L"\0\0")
172 : std::wstring mFileTitle;
173 : uint16_t mFileOffset;
174 : uint16_t mFileExtension;
175 : } OpenFileNameRetIPC;
176 : #else // XP_WIN
177 : typedef mozilla::null_t WindowsSharedMemoryHandle;
178 : typedef mozilla::null_t DXGISharedSurfaceHandle;
179 : typedef mozilla::null_t GetFileNameFunc;
180 : typedef mozilla::null_t OpenFileNameIPC;
181 : typedef mozilla::null_t OpenFileNameRetIPC;
182 : #endif
183 :
184 : // XXX maybe not the best place for these. better one?
185 :
186 : #define VARSTR(v_) case v_: return #v_
187 : inline const char*
188 0 : NPPVariableToString(NPPVariable aVar)
189 : {
190 0 : switch (aVar) {
191 0 : VARSTR(NPPVpluginNameString);
192 0 : VARSTR(NPPVpluginDescriptionString);
193 0 : VARSTR(NPPVpluginWindowBool);
194 0 : VARSTR(NPPVpluginTransparentBool);
195 0 : VARSTR(NPPVjavaClass);
196 0 : VARSTR(NPPVpluginWindowSize);
197 0 : VARSTR(NPPVpluginTimerInterval);
198 :
199 0 : VARSTR(NPPVpluginScriptableInstance);
200 0 : VARSTR(NPPVpluginScriptableIID);
201 :
202 0 : VARSTR(NPPVjavascriptPushCallerBool);
203 :
204 0 : VARSTR(NPPVpluginKeepLibraryInMemory);
205 0 : VARSTR(NPPVpluginNeedsXEmbed);
206 :
207 0 : VARSTR(NPPVpluginScriptableNPObject);
208 :
209 0 : VARSTR(NPPVformValue);
210 :
211 0 : VARSTR(NPPVpluginUrlRequestsDisplayedBool);
212 :
213 0 : VARSTR(NPPVpluginWantsAllNetworkStreams);
214 :
215 : #ifdef XP_MACOSX
216 : VARSTR(NPPVpluginDrawingModel);
217 : VARSTR(NPPVpluginEventModel);
218 : #endif
219 :
220 : #ifdef XP_WIN
221 : VARSTR(NPPVpluginRequiresAudioDeviceChanges);
222 : #endif
223 :
224 0 : default: return "???";
225 : }
226 : }
227 :
228 : inline const char*
229 0 : NPNVariableToString(NPNVariable aVar)
230 : {
231 0 : switch(aVar) {
232 0 : VARSTR(NPNVxDisplay);
233 0 : VARSTR(NPNVxtAppContext);
234 0 : VARSTR(NPNVnetscapeWindow);
235 0 : VARSTR(NPNVjavascriptEnabledBool);
236 0 : VARSTR(NPNVasdEnabledBool);
237 0 : VARSTR(NPNVisOfflineBool);
238 :
239 0 : VARSTR(NPNVserviceManager);
240 0 : VARSTR(NPNVDOMElement);
241 0 : VARSTR(NPNVDOMWindow);
242 0 : VARSTR(NPNVToolkit);
243 0 : VARSTR(NPNVSupportsXEmbedBool);
244 :
245 0 : VARSTR(NPNVWindowNPObject);
246 :
247 0 : VARSTR(NPNVPluginElementNPObject);
248 :
249 0 : VARSTR(NPNVSupportsWindowless);
250 :
251 0 : VARSTR(NPNVprivateModeBool);
252 0 : VARSTR(NPNVdocumentOrigin);
253 :
254 : #ifdef XP_WIN
255 : VARSTR(NPNVaudioDeviceChangeDetails);
256 : #endif
257 :
258 0 : default: return "???";
259 : }
260 : }
261 : #undef VARSTR
262 :
263 0 : inline bool IsPluginThread()
264 : {
265 0 : MessageLoop* loop = MessageLoop::current();
266 0 : if (!loop)
267 0 : return false;
268 0 : return (loop->type() == MessageLoop::TYPE_UI);
269 : }
270 :
271 0 : inline void AssertPluginThread()
272 : {
273 0 : MOZ_RELEASE_ASSERT(IsPluginThread(), "Should be on the plugin's main thread!");
274 0 : }
275 :
276 : #define ENSURE_PLUGIN_THREAD(retval) \
277 : PR_BEGIN_MACRO \
278 : if (!IsPluginThread()) { \
279 : NS_WARNING("Not running on the plugin's main thread!"); \
280 : return (retval); \
281 : } \
282 : PR_END_MACRO
283 :
284 : #define ENSURE_PLUGIN_THREAD_VOID() \
285 : PR_BEGIN_MACRO \
286 : if (!IsPluginThread()) { \
287 : NS_WARNING("Not running on the plugin's main thread!"); \
288 : return; \
289 : } \
290 : PR_END_MACRO
291 :
292 : void DeferNPObjectLastRelease(const NPNetscapeFuncs* f, NPObject* o);
293 : void DeferNPVariantLastRelease(const NPNetscapeFuncs* f, NPVariant* v);
294 :
295 0 : inline bool IsDrawingModelDirect(int16_t aModel)
296 : {
297 0 : return aModel == NPDrawingModelAsyncBitmapSurface
298 : #if defined(XP_WIN)
299 : || aModel == NPDrawingModelAsyncWindowsDXGISurface
300 : #endif
301 : ;
302 : }
303 :
304 : // in NPAPI, char* == nullptr is sometimes meaningful. the following is
305 : // helper code for dealing with nullable nsCString's
306 : inline nsCString
307 0 : NullableString(const char* aString)
308 : {
309 0 : if (!aString) {
310 0 : return NullCString();
311 : }
312 0 : return nsCString(aString);
313 : }
314 :
315 : inline const char*
316 0 : NullableStringGet(const nsCString& str)
317 : {
318 0 : if (str.IsVoid())
319 0 : return nullptr;
320 :
321 0 : return str.get();
322 : }
323 :
324 0 : struct DeletingObjectEntry : public nsPtrHashKey<NPObject>
325 : {
326 0 : explicit DeletingObjectEntry(const NPObject* key)
327 0 : : nsPtrHashKey<NPObject>(key)
328 0 : , mDeleted(false)
329 0 : { }
330 :
331 : bool mDeleted;
332 : };
333 :
334 : } /* namespace plugins */
335 :
336 : } /* namespace mozilla */
337 :
338 : namespace IPC {
339 :
340 : template <>
341 : struct ParamTraits<NPRect>
342 : {
343 : typedef NPRect paramType;
344 :
345 0 : static void Write(Message* aMsg, const paramType& aParam)
346 : {
347 0 : WriteParam(aMsg, aParam.top);
348 0 : WriteParam(aMsg, aParam.left);
349 0 : WriteParam(aMsg, aParam.bottom);
350 0 : WriteParam(aMsg, aParam.right);
351 0 : }
352 :
353 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
354 : {
355 : uint16_t top, left, bottom, right;
356 0 : if (ReadParam(aMsg, aIter, &top) &&
357 0 : ReadParam(aMsg, aIter, &left) &&
358 0 : ReadParam(aMsg, aIter, &bottom) &&
359 0 : ReadParam(aMsg, aIter, &right)) {
360 0 : aResult->top = top;
361 0 : aResult->left = left;
362 0 : aResult->bottom = bottom;
363 0 : aResult->right = right;
364 0 : return true;
365 : }
366 0 : return false;
367 : }
368 :
369 : static void Log(const paramType& aParam, std::wstring* aLog)
370 : {
371 : aLog->append(StringPrintf(L"[%u, %u, %u, %u]", aParam.top, aParam.left,
372 : aParam.bottom, aParam.right));
373 : }
374 : };
375 :
376 : template <>
377 : struct ParamTraits<NPWindowType>
378 : {
379 : typedef NPWindowType paramType;
380 :
381 0 : static void Write(Message* aMsg, const paramType& aParam)
382 : {
383 0 : aMsg->WriteInt16(int16_t(aParam));
384 0 : }
385 :
386 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
387 : {
388 : int16_t result;
389 0 : if (aMsg->ReadInt16(aIter, &result)) {
390 0 : *aResult = paramType(result);
391 0 : return true;
392 : }
393 0 : return false;
394 : }
395 :
396 : static void Log(const paramType& aParam, std::wstring* aLog)
397 : {
398 : aLog->append(StringPrintf(L"%d", int16_t(aParam)));
399 : }
400 : };
401 :
402 : template <>
403 : struct ParamTraits<mozilla::plugins::NPRemoteWindow>
404 : {
405 : typedef mozilla::plugins::NPRemoteWindow paramType;
406 :
407 0 : static void Write(Message* aMsg, const paramType& aParam)
408 : {
409 0 : aMsg->WriteUInt64(aParam.window);
410 0 : WriteParam(aMsg, aParam.x);
411 0 : WriteParam(aMsg, aParam.y);
412 0 : WriteParam(aMsg, aParam.width);
413 0 : WriteParam(aMsg, aParam.height);
414 0 : WriteParam(aMsg, aParam.clipRect);
415 0 : WriteParam(aMsg, aParam.type);
416 : #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
417 0 : aMsg->WriteULong(aParam.visualID);
418 0 : aMsg->WriteULong(aParam.colormap);
419 : #endif
420 : #if defined(XP_MACOSX) || defined(XP_WIN)
421 : aMsg->WriteDouble(aParam.contentsScaleFactor);
422 : #endif
423 0 : }
424 :
425 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
426 : {
427 : uint64_t window;
428 : int32_t x, y;
429 : uint32_t width, height;
430 : NPRect clipRect;
431 : NPWindowType type;
432 0 : if (!(aMsg->ReadUInt64(aIter, &window) &&
433 0 : ReadParam(aMsg, aIter, &x) &&
434 0 : ReadParam(aMsg, aIter, &y) &&
435 0 : ReadParam(aMsg, aIter, &width) &&
436 0 : ReadParam(aMsg, aIter, &height) &&
437 0 : ReadParam(aMsg, aIter, &clipRect) &&
438 0 : ReadParam(aMsg, aIter, &type)))
439 0 : return false;
440 :
441 : #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
442 : unsigned long visualID;
443 : unsigned long colormap;
444 0 : if (!(aMsg->ReadULong(aIter, &visualID) &&
445 0 : aMsg->ReadULong(aIter, &colormap)))
446 0 : return false;
447 : #endif
448 :
449 : #if defined(XP_MACOSX) || defined(XP_WIN)
450 : double contentsScaleFactor;
451 : if (!aMsg->ReadDouble(aIter, &contentsScaleFactor))
452 : return false;
453 : #endif
454 :
455 0 : aResult->window = window;
456 0 : aResult->x = x;
457 0 : aResult->y = y;
458 0 : aResult->width = width;
459 0 : aResult->height = height;
460 0 : aResult->clipRect = clipRect;
461 0 : aResult->type = type;
462 : #if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
463 0 : aResult->visualID = visualID;
464 0 : aResult->colormap = colormap;
465 : #endif
466 : #if defined(XP_MACOSX) || defined(XP_WIN)
467 : aResult->contentsScaleFactor = contentsScaleFactor;
468 : #endif
469 0 : return true;
470 : }
471 :
472 : static void Log(const paramType& aParam, std::wstring* aLog)
473 : {
474 : aLog->append(StringPrintf(L"[%u, %d, %d, %u, %u, %d",
475 : (unsigned long)aParam.window,
476 : aParam.x, aParam.y, aParam.width,
477 : aParam.height, (long)aParam.type));
478 : }
479 : };
480 :
481 : #ifdef XP_MACOSX
482 : template <>
483 : struct ParamTraits<NPNSString*>
484 : {
485 : typedef NPNSString* paramType;
486 :
487 : // Empty string writes a length of 0 and no buffer.
488 : // We don't write a nullptr terminating character in buffers.
489 : static void Write(Message* aMsg, const paramType& aParam)
490 : {
491 : CFStringRef cfString = (CFStringRef)aParam;
492 :
493 : // Write true if we have a string, false represents nullptr.
494 : aMsg->WriteBool(!!cfString);
495 : if (!cfString) {
496 : return;
497 : }
498 :
499 : long length = ::CFStringGetLength(cfString);
500 : WriteParam(aMsg, length);
501 : if (length == 0) {
502 : return;
503 : }
504 :
505 : // Attempt to get characters without any allocation/conversion.
506 : if (::CFStringGetCharactersPtr(cfString)) {
507 : aMsg->WriteBytes(::CFStringGetCharactersPtr(cfString), length * sizeof(UniChar));
508 : } else {
509 : UniChar *buffer = (UniChar*)moz_xmalloc(length * sizeof(UniChar));
510 : ::CFStringGetCharacters(cfString, ::CFRangeMake(0, length), buffer);
511 : aMsg->WriteBytes(buffer, length * sizeof(UniChar));
512 : free(buffer);
513 : }
514 : }
515 :
516 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
517 : {
518 : bool haveString = false;
519 : if (!aMsg->ReadBool(aIter, &haveString)) {
520 : return false;
521 : }
522 : if (!haveString) {
523 : *aResult = nullptr;
524 : return true;
525 : }
526 :
527 : long length;
528 : if (!ReadParam(aMsg, aIter, &length)) {
529 : return false;
530 : }
531 :
532 : // Avoid integer multiplication overflow.
533 : if (length > INT_MAX / static_cast<long>(sizeof(UniChar))) {
534 : return false;
535 : }
536 :
537 : auto chars = mozilla::MakeUnique<UniChar[]>(length);
538 : if (length != 0) {
539 : if (!aMsg->ReadBytesInto(aIter, chars.get(), length * sizeof(UniChar))) {
540 : return false;
541 : }
542 : }
543 :
544 : *aResult = (NPNSString*)::CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*)chars.get(),
545 : length * sizeof(UniChar),
546 : kCFStringEncodingUTF16, false);
547 : if (!*aResult) {
548 : return false;
549 : }
550 :
551 : return true;
552 : }
553 : };
554 : #endif
555 :
556 : #ifdef XP_MACOSX
557 : template <>
558 : struct ParamTraits<NSCursorInfo>
559 : {
560 : typedef NSCursorInfo paramType;
561 :
562 : static void Write(Message* aMsg, const paramType& aParam)
563 : {
564 : NSCursorInfo::Type type = aParam.GetType();
565 :
566 : aMsg->WriteInt(type);
567 :
568 : nsPoint hotSpot = aParam.GetHotSpot();
569 : WriteParam(aMsg, hotSpot.x);
570 : WriteParam(aMsg, hotSpot.y);
571 :
572 : uint32_t dataLength = aParam.GetCustomImageDataLength();
573 : WriteParam(aMsg, dataLength);
574 : if (dataLength == 0) {
575 : return;
576 : }
577 :
578 : uint8_t* buffer = (uint8_t*)moz_xmalloc(dataLength);
579 : memcpy(buffer, aParam.GetCustomImageData(), dataLength);
580 : aMsg->WriteBytes(buffer, dataLength);
581 : free(buffer);
582 : }
583 :
584 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
585 : {
586 : NSCursorInfo::Type type;
587 : if (!aMsg->ReadInt(aIter, (int*)&type)) {
588 : return false;
589 : }
590 :
591 : nscoord hotSpotX, hotSpotY;
592 : if (!ReadParam(aMsg, aIter, &hotSpotX) ||
593 : !ReadParam(aMsg, aIter, &hotSpotY)) {
594 : return false;
595 : }
596 :
597 : uint32_t dataLength;
598 : if (!ReadParam(aMsg, aIter, &dataLength)) {
599 : return false;
600 : }
601 :
602 : auto data = mozilla::MakeUnique<uint8_t[]>(dataLength);
603 : if (dataLength != 0) {
604 : if (!aMsg->ReadBytesInto(aIter, data.get(), dataLength)) {
605 : return false;
606 : }
607 : }
608 :
609 : aResult->SetType(type);
610 : aResult->SetHotSpot(nsPoint(hotSpotX, hotSpotY));
611 : aResult->SetCustomImageData(data.get(), dataLength);
612 :
613 : return true;
614 : }
615 :
616 : static void Log(const paramType& aParam, std::wstring* aLog)
617 : {
618 : const char* typeName = aParam.GetTypeName();
619 : nsPoint hotSpot = aParam.GetHotSpot();
620 : int hotSpotX, hotSpotY;
621 : #ifdef NS_COORD_IS_FLOAT
622 : hotSpotX = rint(hotSpot.x);
623 : hotSpotY = rint(hotSpot.y);
624 : #else
625 : hotSpotX = hotSpot.x;
626 : hotSpotY = hotSpot.y;
627 : #endif
628 : uint32_t dataLength = aParam.GetCustomImageDataLength();
629 : uint8_t* data = aParam.GetCustomImageData();
630 :
631 : aLog->append(StringPrintf(L"[%s, (%i %i), %u, %p]",
632 : typeName, hotSpotX, hotSpotY, dataLength, data));
633 : }
634 : };
635 : #else
636 : template<>
637 : struct ParamTraits<NSCursorInfo>
638 : {
639 : typedef NSCursorInfo paramType;
640 0 : static void Write(Message* aMsg, const paramType& aParam) {
641 0 : MOZ_CRASH("NSCursorInfo isn't meaningful on this platform");
642 : }
643 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
644 0 : MOZ_CRASH("NSCursorInfo isn't meaningful on this platform");
645 : return false;
646 : }
647 : };
648 : #endif // #ifdef XP_MACOSX
649 :
650 : template <>
651 : struct ParamTraits<mozilla::plugins::IPCByteRange>
652 : {
653 : typedef mozilla::plugins::IPCByteRange paramType;
654 :
655 0 : static void Write(Message* aMsg, const paramType& aParam)
656 : {
657 0 : WriteParam(aMsg, aParam.offset);
658 0 : WriteParam(aMsg, aParam.length);
659 0 : }
660 :
661 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
662 : {
663 : paramType p;
664 0 : if (ReadParam(aMsg, aIter, &p.offset) &&
665 0 : ReadParam(aMsg, aIter, &p.length)) {
666 0 : *aResult = p;
667 0 : return true;
668 : }
669 0 : return false;
670 : }
671 : };
672 :
673 : template <>
674 : struct ParamTraits<NPNVariable>
675 : {
676 : typedef NPNVariable paramType;
677 :
678 0 : static void Write(Message* aMsg, const paramType& aParam)
679 : {
680 0 : WriteParam(aMsg, int(aParam));
681 0 : }
682 :
683 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
684 : {
685 : int intval;
686 0 : if (ReadParam(aMsg, aIter, &intval)) {
687 0 : *aResult = paramType(intval);
688 0 : return true;
689 : }
690 0 : return false;
691 : }
692 : };
693 :
694 : template<>
695 : struct ParamTraits<NPNURLVariable>
696 : {
697 : typedef NPNURLVariable paramType;
698 :
699 0 : static void Write(Message* aMsg, const paramType& aParam)
700 : {
701 0 : WriteParam(aMsg, int(aParam));
702 0 : }
703 :
704 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
705 : {
706 : int intval;
707 0 : if (ReadParam(aMsg, aIter, &intval) &&
708 0 : intval == NPNURLVProxy) {
709 0 : *aResult = paramType(intval);
710 0 : return true;
711 : }
712 0 : return false;
713 : }
714 : };
715 :
716 :
717 : template<>
718 : struct ParamTraits<NPCoordinateSpace>
719 : {
720 : typedef NPCoordinateSpace paramType;
721 :
722 0 : static void Write(Message* aMsg, const paramType& aParam)
723 : {
724 0 : WriteParam(aMsg, int32_t(aParam));
725 0 : }
726 :
727 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
728 : {
729 : int32_t intval;
730 0 : if (ReadParam(aMsg, aIter, &intval)) {
731 0 : switch (intval) {
732 : case NPCoordinateSpacePlugin:
733 : case NPCoordinateSpaceWindow:
734 : case NPCoordinateSpaceFlippedWindow:
735 : case NPCoordinateSpaceScreen:
736 : case NPCoordinateSpaceFlippedScreen:
737 0 : *aResult = paramType(intval);
738 0 : return true;
739 : }
740 : }
741 0 : return false;
742 : }
743 : };
744 :
745 : template <>
746 : struct ParamTraits<mozilla::plugins::NPAudioDeviceChangeDetailsIPC>
747 : {
748 : typedef mozilla::plugins::NPAudioDeviceChangeDetailsIPC paramType;
749 :
750 0 : static void Write(Message* aMsg, const paramType& aParam)
751 : {
752 0 : WriteParam(aMsg, aParam.flow);
753 0 : WriteParam(aMsg, aParam.role);
754 0 : WriteParam(aMsg, aParam.defaultDevice);
755 0 : }
756 :
757 0 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
758 : {
759 : int32_t flow, role;
760 0 : std::wstring defaultDevice;
761 0 : if (ReadParam(aMsg, aIter, &flow) &&
762 0 : ReadParam(aMsg, aIter, &role) &&
763 0 : ReadParam(aMsg, aIter, &defaultDevice)) {
764 0 : aResult->flow = flow;
765 0 : aResult->role = role;
766 0 : aResult->defaultDevice = defaultDevice;
767 0 : return true;
768 : }
769 0 : return false;
770 : }
771 :
772 : static void Log(const paramType& aParam, std::wstring* aLog)
773 : {
774 : aLog->append(StringPrintf(L"[%d, %d, %S]", aParam.flow, aParam.role,
775 : aParam.defaultDevice.c_str()));
776 : }
777 : };
778 :
779 : #ifdef XP_WIN
780 : template <>
781 : struct ParamTraits<mozilla::plugins::_OpenFileNameIPC>
782 : {
783 : typedef mozilla::plugins::_OpenFileNameIPC paramType;
784 :
785 : static void Write(Message* aMsg, const paramType& aParam)
786 : {
787 : WriteParam(aMsg, aParam.mHwndOwner);
788 : WriteParam(aMsg, aParam.mFilter);
789 : WriteParam(aMsg, aParam.mHasFilter);
790 : WriteParam(aMsg, aParam.mCustomFilterIn);
791 : WriteParam(aMsg, aParam.mHasCustomFilter);
792 : WriteParam(aMsg, aParam.mNMaxCustFilterOut);
793 : WriteParam(aMsg, aParam.mFilterIndex);
794 : WriteParam(aMsg, aParam.mFile);
795 : WriteParam(aMsg, aParam.mNMaxFile);
796 : WriteParam(aMsg, aParam.mNMaxFileTitle);
797 : WriteParam(aMsg, aParam.mInitialDir);
798 : WriteParam(aMsg, aParam.mHasInitialDir);
799 : WriteParam(aMsg, aParam.mTitle);
800 : WriteParam(aMsg, aParam.mHasTitle);
801 : WriteParam(aMsg, aParam.mFlags);
802 : WriteParam(aMsg, aParam.mDefExt);
803 : WriteParam(aMsg, aParam.mHasDefExt);
804 : WriteParam(aMsg, aParam.mFlagsEx);
805 : }
806 :
807 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
808 : {
809 : if (ReadParam(aMsg, aIter, &aResult->mHwndOwner) &&
810 : ReadParam(aMsg, aIter, &aResult->mFilter) &&
811 : ReadParam(aMsg, aIter, &aResult->mHasFilter) &&
812 : ReadParam(aMsg, aIter, &aResult->mCustomFilterIn) &&
813 : ReadParam(aMsg, aIter, &aResult->mHasCustomFilter) &&
814 : ReadParam(aMsg, aIter, &aResult->mNMaxCustFilterOut) &&
815 : ReadParam(aMsg, aIter, &aResult->mFilterIndex) &&
816 : ReadParam(aMsg, aIter, &aResult->mFile) &&
817 : ReadParam(aMsg, aIter, &aResult->mNMaxFile) &&
818 : ReadParam(aMsg, aIter, &aResult->mNMaxFileTitle) &&
819 : ReadParam(aMsg, aIter, &aResult->mInitialDir) &&
820 : ReadParam(aMsg, aIter, &aResult->mHasInitialDir) &&
821 : ReadParam(aMsg, aIter, &aResult->mTitle) &&
822 : ReadParam(aMsg, aIter, &aResult->mHasTitle) &&
823 : ReadParam(aMsg, aIter, &aResult->mFlags) &&
824 : ReadParam(aMsg, aIter, &aResult->mDefExt) &&
825 : ReadParam(aMsg, aIter, &aResult->mHasDefExt) &&
826 : ReadParam(aMsg, aIter, &aResult->mFlagsEx)) {
827 : return true;
828 : }
829 : return false;
830 : }
831 :
832 : static void Log(const paramType& aParam, std::wstring* aLog)
833 : {
834 : aLog->append(StringPrintf(L"[%S, %S, %S, %S]", aParam.mFilter.c_str(),
835 : aParam.mCustomFilterIn.c_str(), aParam.mFile.c_str(),
836 : aParam.mTitle.c_str()));
837 : }
838 : };
839 :
840 : template <>
841 : struct ParamTraits<mozilla::plugins::_OpenFileNameRetIPC>
842 : {
843 : typedef mozilla::plugins::_OpenFileNameRetIPC paramType;
844 :
845 : static void Write(Message* aMsg, const paramType& aParam)
846 : {
847 : WriteParam(aMsg, aParam.mCustomFilterOut);
848 : WriteParam(aMsg, aParam.mFile);
849 : WriteParam(aMsg, aParam.mFileTitle);
850 : WriteParam(aMsg, aParam.mFileOffset);
851 : WriteParam(aMsg, aParam.mFileExtension);
852 : }
853 :
854 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
855 : {
856 : if (ReadParam(aMsg, aIter, &aResult->mCustomFilterOut) &&
857 : ReadParam(aMsg, aIter, &aResult->mFile) &&
858 : ReadParam(aMsg, aIter, &aResult->mFileTitle) &&
859 : ReadParam(aMsg, aIter, &aResult->mFileOffset) &&
860 : ReadParam(aMsg, aIter, &aResult->mFileExtension)) {
861 : return true;
862 : }
863 : return false;
864 : }
865 :
866 : static void Log(const paramType& aParam, std::wstring* aLog)
867 : {
868 : aLog->append(StringPrintf(L"[%S, %S, %S, %d, %d]", aParam.mCustomFilterOut.c_str(),
869 : aParam.mFile.c_str(), aParam.mFileTitle.c_str(),
870 : aParam.mFileOffset, aParam.mFileExtension));
871 : }
872 : };
873 :
874 : template <>
875 : struct ParamTraits<mozilla::plugins::GetFileNameFunc>
876 : {
877 : typedef mozilla::plugins::GetFileNameFunc paramType;
878 :
879 : static void Write(Message* aMsg, const paramType& aParam)
880 : {
881 : WriteParam(aMsg, static_cast<uint32_t>(aParam));
882 : }
883 :
884 : static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
885 : {
886 : uint32_t result;
887 : if (ReadParam(aMsg, aIter, &result)) {
888 : *aResult = static_cast<paramType>(result);
889 : return true;
890 : }
891 : return false;
892 : }
893 :
894 : static void Log(const paramType& aParam, std::wstring* aLog)
895 : {
896 : aLog->append(StringPrintf(L"[%S]",
897 : aParam == mozilla::plugins::OPEN_FUNC ? "GetOpenFileName" : "GetSaveFileName"));
898 : }
899 : };
900 : #endif // XP_WIN
901 :
902 : } /* namespace IPC */
903 :
904 :
905 : // Serializing NPEvents is completely platform-specific and can be rather
906 : // intricate depending on the platform. So for readability we split it
907 : // into separate files and have the only macro crud live here.
908 : //
909 : // NB: these guards are based on those where struct NPEvent is defined
910 : // in npapi.h. They should be kept in sync.
911 : #if defined(XP_MACOSX)
912 : # include "mozilla/plugins/NPEventOSX.h"
913 : #elif defined(XP_WIN)
914 : # include "mozilla/plugins/NPEventWindows.h"
915 : #elif defined(ANDROID)
916 : # include "mozilla/plugins/NPEventAndroid.h"
917 : #elif defined(XP_UNIX)
918 : # include "mozilla/plugins/NPEventUnix.h"
919 : #else
920 : # error Unsupported platform
921 : #endif
922 :
923 : #endif /* DOM_PLUGINS_PLUGINMESSAGEUTILS_H */
|