2009-08-18 13:20:03 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2009-07-02 09:54:22 -07:00
|
|
|
* vim: sw=4 ts=4 et :
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-07-02 09:54:22 -07:00
|
|
|
|
|
|
|
#ifndef DOM_PLUGINS_PLUGINMESSAGEUTILS_H
|
|
|
|
#define DOM_PLUGINS_PLUGINMESSAGEUTILS_H
|
|
|
|
|
2012-08-28 05:41:04 -07:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2010-02-03 14:17:09 -08:00
|
|
|
#include "base/message_loop.h"
|
2009-07-02 09:54:22 -07:00
|
|
|
|
2010-03-10 23:35:31 -08:00
|
|
|
#include "mozilla/ipc/RPCChannel.h"
|
2012-02-15 19:30:22 -08:00
|
|
|
#include "mozilla/ipc/CrossProcessMutex.h"
|
2012-01-10 02:54:35 -08:00
|
|
|
#include "gfxipc/ShadowLayerUtils.h"
|
2010-03-10 23:35:31 -08:00
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
#include "npapi.h"
|
2009-08-10 16:28:22 -07:00
|
|
|
#include "npruntime.h"
|
2009-10-30 14:02:47 -07:00
|
|
|
#include "npfunctions.h"
|
2009-08-10 16:28:22 -07:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsStringGlue.h"
|
2010-01-15 12:35:57 -08:00
|
|
|
#include "nsTArray.h"
|
2009-10-08 12:11:13 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2009-12-18 14:22:51 -08:00
|
|
|
#include "prlog.h"
|
2010-02-24 13:14:13 -08:00
|
|
|
#include "nsHashKeys.h"
|
2010-03-30 17:24:47 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
# include "nsExceptionHandler.h"
|
|
|
|
#endif
|
2011-05-23 23:58:28 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "PluginInterposeOSX.h"
|
|
|
|
#else
|
|
|
|
namespace mac_plugin_interposing { class NSCursorInfo { }; }
|
|
|
|
#endif
|
|
|
|
using mac_plugin_interposing::NSCursorInfo;
|
2009-07-02 09:54:22 -07:00
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
namespace mozilla {
|
2009-08-18 13:20:03 -07:00
|
|
|
namespace plugins {
|
|
|
|
|
2012-01-10 02:54:35 -08:00
|
|
|
using layers::SurfaceDescriptorX11;
|
|
|
|
|
2010-01-15 12:35:57 -08:00
|
|
|
enum ScriptableObjectType
|
|
|
|
{
|
|
|
|
LocalObject,
|
|
|
|
Proxy
|
|
|
|
};
|
|
|
|
|
2010-03-10 23:35:31 -08:00
|
|
|
mozilla::ipc::RPCChannel::RacyRPCPolicy
|
|
|
|
MediateRace(const mozilla::ipc::RPCChannel::Message& parent,
|
|
|
|
const mozilla::ipc::RPCChannel::Message& child);
|
|
|
|
|
2010-04-14 00:04:52 -07:00
|
|
|
std::string
|
|
|
|
MungePluginDsoPath(const std::string& path);
|
|
|
|
std::string
|
|
|
|
UnmungePluginDsoPath(const std::string& munged);
|
|
|
|
|
2009-12-18 14:22:51 -08:00
|
|
|
extern PRLogModuleInfo* gPluginLog;
|
|
|
|
|
2012-02-15 19:24:38 -08:00
|
|
|
const uint32_t kAllowAsyncDrawing = 0x1;
|
|
|
|
|
2012-02-15 19:30:22 -08:00
|
|
|
inline bool IsDrawingModelAsync(int16_t aModel) {
|
|
|
|
return aModel == NPDrawingModelAsyncBitmapSurface
|
|
|
|
#ifdef XP_WIN
|
|
|
|
|| aModel == NPDrawingModelAsyncWindowsDXGISurface
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2009-12-18 14:22:51 -08:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#define FULLFUNCTION __FUNCSIG__
|
|
|
|
#elif (__GNUC__ >= 4)
|
|
|
|
#define FULLFUNCTION __PRETTY_FUNCTION__
|
|
|
|
#else
|
|
|
|
#define FULLFUNCTION __FUNCTION__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PLUGIN_LOG_DEBUG(args) PR_LOG(gPluginLog, PR_LOG_DEBUG, args)
|
|
|
|
#define PLUGIN_LOG_DEBUG_FUNCTION PR_LOG(gPluginLog, PR_LOG_DEBUG, ("%s", FULLFUNCTION))
|
|
|
|
#define PLUGIN_LOG_DEBUG_METHOD PR_LOG(gPluginLog, PR_LOG_DEBUG, ("%s [%p]", FULLFUNCTION, (void*) this))
|
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
/**
|
|
|
|
* This is NPByteRange without the linked list.
|
|
|
|
*/
|
|
|
|
struct IPCByteRange
|
|
|
|
{
|
|
|
|
int32_t offset;
|
|
|
|
uint32_t length;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<IPCByteRange> IPCByteRanges;
|
|
|
|
|
|
|
|
typedef nsCString Buffer;
|
|
|
|
|
2009-09-30 14:36:14 -07:00
|
|
|
struct NPRemoteWindow
|
|
|
|
{
|
2011-11-28 08:12:27 -08:00
|
|
|
NPRemoteWindow();
|
2011-09-06 21:54:21 -07:00
|
|
|
uint64_t window;
|
2009-09-30 14:36:14 -07:00
|
|
|
int32_t x;
|
|
|
|
int32_t y;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
NPRect clipRect;
|
|
|
|
NPWindowType type;
|
|
|
|
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
VisualID visualID;
|
|
|
|
Colormap colormap;
|
|
|
|
#endif /* XP_UNIX */
|
2009-12-01 13:05:26 -08:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
base::SharedMemoryHandle surfaceHandle;
|
|
|
|
#endif
|
2009-09-30 14:36:14 -07:00
|
|
|
};
|
|
|
|
|
2010-01-14 07:18:34 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
typedef HWND NativeWindowHandle;
|
|
|
|
#elif defined(MOZ_X11)
|
|
|
|
typedef XID NativeWindowHandle;
|
2011-08-24 09:15:58 -07:00
|
|
|
#elif defined(XP_MACOSX) || defined(ANDROID) || defined(MOZ_WIDGET_QT)
|
2010-03-17 11:38:28 -07:00
|
|
|
typedef intptr_t NativeWindowHandle; // never actually used, will always be 0
|
2010-01-14 07:18:34 -08:00
|
|
|
#else
|
|
|
|
#error Need NativeWindowHandle for this platform
|
|
|
|
#endif
|
|
|
|
|
2010-10-25 12:12:25 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
typedef base::SharedMemoryHandle WindowsSharedMemoryHandle;
|
2012-02-15 19:09:06 -08:00
|
|
|
typedef HANDLE DXGISharedSurfaceHandle;
|
2010-10-25 12:12:25 -07:00
|
|
|
#else
|
|
|
|
typedef mozilla::null_t WindowsSharedMemoryHandle;
|
2012-02-15 19:09:06 -08:00
|
|
|
typedef mozilla::null_t DXGISharedSurfaceHandle;
|
2010-10-25 12:12:25 -07:00
|
|
|
#endif
|
|
|
|
|
2009-09-24 19:03:59 -07:00
|
|
|
// XXX maybe not the best place for these. better one?
|
|
|
|
|
|
|
|
#define VARSTR(v_) case v_: return #v_
|
|
|
|
inline const char* const
|
|
|
|
NPPVariableToString(NPPVariable aVar)
|
|
|
|
{
|
|
|
|
switch (aVar) {
|
|
|
|
VARSTR(NPPVpluginNameString);
|
|
|
|
VARSTR(NPPVpluginDescriptionString);
|
|
|
|
VARSTR(NPPVpluginWindowBool);
|
|
|
|
VARSTR(NPPVpluginTransparentBool);
|
|
|
|
VARSTR(NPPVjavaClass);
|
|
|
|
VARSTR(NPPVpluginWindowSize);
|
|
|
|
VARSTR(NPPVpluginTimerInterval);
|
|
|
|
|
|
|
|
VARSTR(NPPVpluginScriptableInstance);
|
|
|
|
VARSTR(NPPVpluginScriptableIID);
|
|
|
|
|
|
|
|
VARSTR(NPPVjavascriptPushCallerBool);
|
|
|
|
|
|
|
|
VARSTR(NPPVpluginKeepLibraryInMemory);
|
|
|
|
VARSTR(NPPVpluginNeedsXEmbed);
|
|
|
|
|
|
|
|
VARSTR(NPPVpluginScriptableNPObject);
|
|
|
|
|
|
|
|
VARSTR(NPPVformValue);
|
|
|
|
|
|
|
|
VARSTR(NPPVpluginUrlRequestsDisplayedBool);
|
|
|
|
|
|
|
|
VARSTR(NPPVpluginWantsAllNetworkStreams);
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
VARSTR(NPPVpluginDrawingModel);
|
|
|
|
VARSTR(NPPVpluginEventModel);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default: return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const char*
|
|
|
|
NPNVariableToString(NPNVariable aVar)
|
|
|
|
{
|
|
|
|
switch(aVar) {
|
|
|
|
VARSTR(NPNVxDisplay);
|
|
|
|
VARSTR(NPNVxtAppContext);
|
|
|
|
VARSTR(NPNVnetscapeWindow);
|
|
|
|
VARSTR(NPNVjavascriptEnabledBool);
|
|
|
|
VARSTR(NPNVasdEnabledBool);
|
|
|
|
VARSTR(NPNVisOfflineBool);
|
|
|
|
|
|
|
|
VARSTR(NPNVserviceManager);
|
|
|
|
VARSTR(NPNVDOMElement);
|
|
|
|
VARSTR(NPNVDOMWindow);
|
|
|
|
VARSTR(NPNVToolkit);
|
|
|
|
VARSTR(NPNVSupportsXEmbedBool);
|
|
|
|
|
|
|
|
VARSTR(NPNVWindowNPObject);
|
|
|
|
|
|
|
|
VARSTR(NPNVPluginElementNPObject);
|
|
|
|
|
|
|
|
VARSTR(NPNVSupportsWindowless);
|
|
|
|
|
|
|
|
VARSTR(NPNVprivateModeBool);
|
2011-09-14 09:22:27 -07:00
|
|
|
VARSTR(NPNVdocumentOrigin);
|
2009-09-24 19:03:59 -07:00
|
|
|
|
|
|
|
default: return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef VARSTR
|
|
|
|
|
2010-03-24 12:30:45 -07:00
|
|
|
inline bool IsPluginThread()
|
|
|
|
{
|
2010-04-12 13:25:57 -07:00
|
|
|
MessageLoop* loop = MessageLoop::current();
|
|
|
|
if (!loop)
|
|
|
|
return false;
|
|
|
|
return (loop->type() == MessageLoop::TYPE_UI);
|
2010-03-24 12:30:45 -07:00
|
|
|
}
|
2009-09-24 19:03:59 -07:00
|
|
|
|
2009-10-08 12:11:13 -07:00
|
|
|
inline void AssertPluginThread()
|
|
|
|
{
|
2010-03-24 12:30:45 -07:00
|
|
|
NS_ASSERTION(IsPluginThread(), "Should be on the plugin's main thread!");
|
2009-10-08 12:11:13 -07:00
|
|
|
}
|
|
|
|
|
2010-03-24 12:30:45 -07:00
|
|
|
#define ENSURE_PLUGIN_THREAD(retval) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (!IsPluginThread()) { \
|
|
|
|
NS_WARNING("Not running on the plugin's main thread!"); \
|
|
|
|
return (retval); \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
#define ENSURE_PLUGIN_THREAD_VOID() \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (!IsPluginThread()) { \
|
|
|
|
NS_WARNING("Not running on the plugin's main thread!"); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
2009-10-30 14:02:47 -07:00
|
|
|
void DeferNPObjectLastRelease(const NPNetscapeFuncs* f, NPObject* o);
|
|
|
|
void DeferNPVariantLastRelease(const NPNetscapeFuncs* f, NPVariant* v);
|
2009-10-08 12:11:13 -07:00
|
|
|
|
2009-09-21 19:02:15 -07:00
|
|
|
// in NPAPI, char* == NULL is sometimes meaningful. the following is
|
|
|
|
// helper code for dealing with nullable nsCString's
|
2009-11-25 12:07:45 -08:00
|
|
|
inline nsCString
|
2009-09-21 19:02:15 -07:00
|
|
|
NullableString(const char* aString)
|
|
|
|
{
|
|
|
|
if (!aString) {
|
|
|
|
nsCString str;
|
2011-10-17 07:59:28 -07:00
|
|
|
str.SetIsVoid(true);
|
2009-09-21 19:02:15 -07:00
|
|
|
return str;
|
|
|
|
}
|
|
|
|
return nsCString(aString);
|
|
|
|
}
|
|
|
|
|
2009-11-25 12:07:45 -08:00
|
|
|
inline const char*
|
|
|
|
NullableStringGet(const nsCString& str)
|
|
|
|
{
|
|
|
|
if (str.IsVoid())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return str.get();
|
|
|
|
}
|
2009-09-21 19:02:15 -07:00
|
|
|
|
2010-02-24 13:14:13 -08:00
|
|
|
struct DeletingObjectEntry : public nsPtrHashKey<NPObject>
|
|
|
|
{
|
|
|
|
DeletingObjectEntry(const NPObject* key)
|
|
|
|
: nsPtrHashKey<NPObject>(key)
|
|
|
|
, mDeleted(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
bool mDeleted;
|
|
|
|
};
|
|
|
|
|
2010-08-16 07:10:25 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// The private event used for double-pass widgetless plugin rendering.
|
|
|
|
UINT DoublePassRenderingEvent();
|
|
|
|
#endif
|
|
|
|
|
2009-11-25 12:07:45 -08:00
|
|
|
} /* namespace plugins */
|
2009-09-21 19:02:15 -07:00
|
|
|
|
2009-11-25 12:07:45 -08:00
|
|
|
} /* namespace mozilla */
|
2009-09-21 19:02:15 -07:00
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
namespace IPC {
|
2009-07-02 09:54:22 -07:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<NPRect>
|
|
|
|
{
|
|
|
|
typedef NPRect paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.top);
|
|
|
|
WriteParam(aMsg, aParam.left);
|
|
|
|
WriteParam(aMsg, aParam.bottom);
|
|
|
|
WriteParam(aMsg, aParam.right);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
uint16_t top, left, bottom, right;
|
|
|
|
if (ReadParam(aMsg, aIter, &top) &&
|
|
|
|
ReadParam(aMsg, aIter, &left) &&
|
|
|
|
ReadParam(aMsg, aIter, &bottom) &&
|
|
|
|
ReadParam(aMsg, aIter, &right)) {
|
|
|
|
aResult->top = top;
|
|
|
|
aResult->left = left;
|
|
|
|
aResult->bottom = bottom;
|
|
|
|
aResult->right = right;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
aLog->append(StringPrintf(L"[%u, %u, %u, %u]", aParam.top, aParam.left,
|
|
|
|
aParam.bottom, aParam.right));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<NPWindowType>
|
|
|
|
{
|
|
|
|
typedef NPWindowType paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteInt16(int16(aParam));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
int16 result;
|
|
|
|
if (aMsg->ReadInt16(aIter, &result)) {
|
|
|
|
*aResult = paramType(result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
aLog->append(StringPrintf(L"%d", int16(aParam)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-15 19:09:06 -08:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<NPImageFormat>
|
|
|
|
{
|
|
|
|
typedef NPImageFormat paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
aMsg->WriteInt16(int16(aParam));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
int16 result;
|
|
|
|
if (aMsg->ReadInt16(aIter, &result)) {
|
|
|
|
*aResult = paramType(result);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
aLog->append(StringPrintf(L"%d", int16(aParam)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
template <>
|
2009-09-30 14:36:14 -07:00
|
|
|
struct ParamTraits<mozilla::plugins::NPRemoteWindow>
|
2009-07-02 09:54:22 -07:00
|
|
|
{
|
2009-09-30 14:36:14 -07:00
|
|
|
typedef mozilla::plugins::NPRemoteWindow paramType;
|
2009-07-02 09:54:22 -07:00
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
2011-09-06 21:54:21 -07:00
|
|
|
aMsg->WriteUInt64(aParam.window);
|
2009-07-02 09:54:22 -07:00
|
|
|
WriteParam(aMsg, aParam.x);
|
|
|
|
WriteParam(aMsg, aParam.y);
|
|
|
|
WriteParam(aMsg, aParam.width);
|
|
|
|
WriteParam(aMsg, aParam.height);
|
|
|
|
WriteParam(aMsg, aParam.clipRect);
|
|
|
|
WriteParam(aMsg, aParam.type);
|
2009-09-30 14:36:14 -07:00
|
|
|
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
aMsg->WriteULong(aParam.visualID);
|
|
|
|
aMsg->WriteULong(aParam.colormap);
|
2009-12-01 13:05:26 -08:00
|
|
|
#endif
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
WriteParam(aMsg, aParam.surfaceHandle);
|
2009-09-30 14:36:14 -07:00
|
|
|
#endif
|
2009-07-02 09:54:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
2011-09-20 09:20:51 -07:00
|
|
|
uint64 window;
|
2009-07-02 09:54:22 -07:00
|
|
|
int32_t x, y;
|
|
|
|
uint32_t width, height;
|
2009-09-25 13:35:03 -07:00
|
|
|
NPRect clipRect;
|
2009-07-02 09:54:22 -07:00
|
|
|
NPWindowType type;
|
2011-09-06 21:54:21 -07:00
|
|
|
if (!(aMsg->ReadUInt64(aIter, &window) &&
|
2009-09-25 13:35:03 -07:00
|
|
|
ReadParam(aMsg, aIter, &x) &&
|
|
|
|
ReadParam(aMsg, aIter, &y) &&
|
|
|
|
ReadParam(aMsg, aIter, &width) &&
|
|
|
|
ReadParam(aMsg, aIter, &height) &&
|
|
|
|
ReadParam(aMsg, aIter, &clipRect) &&
|
|
|
|
ReadParam(aMsg, aIter, &type)))
|
|
|
|
return false;
|
|
|
|
|
2009-09-30 14:36:14 -07:00
|
|
|
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
unsigned long visualID;
|
|
|
|
unsigned long colormap;
|
|
|
|
if (!(aMsg->ReadULong(aIter, &visualID) &&
|
|
|
|
aMsg->ReadULong(aIter, &colormap)))
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
2009-12-01 13:05:26 -08:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
base::SharedMemoryHandle surfaceHandle;
|
|
|
|
if (!ReadParam(aMsg, aIter, &surfaceHandle))
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
2009-09-30 14:36:14 -07:00
|
|
|
aResult->window = window;
|
2009-09-25 13:35:03 -07:00
|
|
|
aResult->x = x;
|
|
|
|
aResult->y = y;
|
|
|
|
aResult->width = width;
|
|
|
|
aResult->height = height;
|
|
|
|
aResult->clipRect = clipRect;
|
|
|
|
aResult->type = type;
|
2009-09-30 14:36:14 -07:00
|
|
|
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
|
|
aResult->visualID = visualID;
|
|
|
|
aResult->colormap = colormap;
|
2009-12-01 13:05:26 -08:00
|
|
|
#endif
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
aResult->surfaceHandle = surfaceHandle;
|
2009-09-30 14:36:14 -07:00
|
|
|
#endif
|
2009-09-25 13:35:03 -07:00
|
|
|
return true;
|
2009-07-02 09:54:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
aLog->append(StringPrintf(L"[%u, %d, %d, %u, %u, %d",
|
|
|
|
(unsigned long)aParam.window,
|
|
|
|
aParam.x, aParam.y, aParam.width,
|
|
|
|
aParam.height, (long)aParam.type));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<NPString>
|
|
|
|
{
|
|
|
|
typedef NPString paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.UTF8Length);
|
|
|
|
aMsg->WriteBytes(aParam.UTF8Characters,
|
|
|
|
aParam.UTF8Length * sizeof(NPUTF8));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
if (ReadParam(aMsg, aIter, &aResult->UTF8Length)) {
|
|
|
|
int byteCount = aResult->UTF8Length * sizeof(NPUTF8);
|
|
|
|
if (!byteCount) {
|
|
|
|
aResult->UTF8Characters = "\0";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
const char* messageBuffer = nullptr;
|
2009-08-10 16:28:22 -07:00
|
|
|
nsAutoArrayPtr<char> newBuffer(new char[byteCount]);
|
|
|
|
if (newBuffer && aMsg->ReadBytes(aIter, &messageBuffer, byteCount )) {
|
|
|
|
memcpy((void*)messageBuffer, newBuffer.get(), byteCount);
|
|
|
|
aResult->UTF8Characters = newBuffer.forget();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
aLog->append(StringPrintf(L"%s", aParam.UTF8Characters));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-03-29 12:27:49 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<NPNSString*>
|
|
|
|
{
|
|
|
|
typedef NPNSString* paramType;
|
|
|
|
|
|
|
|
// Empty string writes a length of 0 and no buffer.
|
|
|
|
// We don't write a NULL terminating character in buffers.
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
CFStringRef cfString = (CFStringRef)aParam;
|
2010-08-26 01:21:41 -07:00
|
|
|
|
|
|
|
// Write true if we have a string, false represents NULL.
|
|
|
|
aMsg->WriteBool(!!cfString);
|
|
|
|
if (!cfString) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-29 12:27:49 -07:00
|
|
|
long length = ::CFStringGetLength(cfString);
|
|
|
|
WriteParam(aMsg, length);
|
|
|
|
if (length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to get characters without any allocation/conversion.
|
|
|
|
if (::CFStringGetCharactersPtr(cfString)) {
|
|
|
|
aMsg->WriteBytes(::CFStringGetCharactersPtr(cfString), length * sizeof(UniChar));
|
|
|
|
} else {
|
|
|
|
UniChar *buffer = (UniChar*)moz_xmalloc(length * sizeof(UniChar));
|
|
|
|
::CFStringGetCharacters(cfString, ::CFRangeMake(0, length), buffer);
|
|
|
|
aMsg->WriteBytes(buffer, length * sizeof(UniChar));
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
2010-08-26 01:21:41 -07:00
|
|
|
bool haveString = false;
|
|
|
|
if (!aMsg->ReadBool(aIter, &haveString)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!haveString) {
|
|
|
|
*aResult = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-29 12:27:49 -07:00
|
|
|
long length;
|
|
|
|
if (!ReadParam(aMsg, aIter, &length)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
UniChar* buffer = nullptr;
|
2010-03-29 12:27:49 -07:00
|
|
|
if (length != 0) {
|
|
|
|
if (!aMsg->ReadBytes(aIter, (const char**)&buffer, length * sizeof(UniChar)) ||
|
|
|
|
!buffer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = (NPNSString*)::CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8*)buffer,
|
|
|
|
length * sizeof(UniChar),
|
|
|
|
kCFStringEncodingUTF16, false);
|
|
|
|
if (!*aResult) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2011-05-23 23:58:28 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<NSCursorInfo>
|
|
|
|
{
|
|
|
|
typedef NSCursorInfo paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
NSCursorInfo::Type type = aParam.GetType();
|
|
|
|
|
|
|
|
aMsg->WriteInt(type);
|
|
|
|
|
|
|
|
nsPoint hotSpot = aParam.GetHotSpot();
|
|
|
|
WriteParam(aMsg, hotSpot.x);
|
|
|
|
WriteParam(aMsg, hotSpot.y);
|
|
|
|
|
|
|
|
uint32_t dataLength = aParam.GetCustomImageDataLength();
|
|
|
|
WriteParam(aMsg, dataLength);
|
|
|
|
if (dataLength == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* buffer = (uint8_t*)moz_xmalloc(dataLength);
|
|
|
|
memcpy(buffer, aParam.GetCustomImageData(), dataLength);
|
|
|
|
aMsg->WriteBytes(buffer, dataLength);
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
NSCursorInfo::Type type;
|
|
|
|
if (!aMsg->ReadInt(aIter, (int*)&type)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord hotSpotX, hotSpotY;
|
|
|
|
if (!ReadParam(aMsg, aIter, &hotSpotX) ||
|
|
|
|
!ReadParam(aMsg, aIter, &hotSpotY)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t dataLength;
|
|
|
|
if (!ReadParam(aMsg, aIter, &dataLength)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* data = NULL;
|
|
|
|
if (dataLength != 0) {
|
|
|
|
if (!aMsg->ReadBytes(aIter, (const char**)&data, dataLength) || !data) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult->SetType(type);
|
|
|
|
aResult->SetHotSpot(nsPoint(hotSpotX, hotSpotY));
|
|
|
|
aResult->SetCustomImageData(data, dataLength);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
const char* typeName = aParam.GetTypeName();
|
|
|
|
nsPoint hotSpot = aParam.GetHotSpot();
|
|
|
|
int hotSpotX, hotSpotY;
|
|
|
|
#ifdef NS_COORD_IS_FLOAT
|
|
|
|
hotSpotX = rint(hotSpot.x);
|
|
|
|
hotSpotY = rint(hotSpot.y);
|
|
|
|
#else
|
|
|
|
hotSpotX = hotSpot.x;
|
|
|
|
hotSpotY = hotSpot.y;
|
|
|
|
#endif
|
|
|
|
uint32_t dataLength = aParam.GetCustomImageDataLength();
|
|
|
|
uint8_t* data = aParam.GetCustomImageData();
|
|
|
|
|
|
|
|
aLog->append(StringPrintf(L"[%s, (%i %i), %u, %p]",
|
|
|
|
typeName, hotSpotX, hotSpotY, dataLength, data));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
template<>
|
|
|
|
struct ParamTraits<NSCursorInfo>
|
|
|
|
{
|
|
|
|
typedef NSCursorInfo paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam) {
|
|
|
|
NS_RUNTIMEABORT("NSCursorInfo isn't meaningful on this platform");
|
|
|
|
}
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult) {
|
|
|
|
NS_RUNTIMEABORT("NSCursorInfo isn't meaningful on this platform");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // #ifdef XP_MACOSX
|
|
|
|
|
2009-08-10 16:28:22 -07:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<NPVariant>
|
|
|
|
{
|
|
|
|
typedef NPVariant paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
if (NPVARIANT_IS_VOID(aParam)) {
|
|
|
|
aMsg->WriteInt(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_NULL(aParam)) {
|
|
|
|
aMsg->WriteInt(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_BOOLEAN(aParam)) {
|
|
|
|
aMsg->WriteInt(2);
|
|
|
|
WriteParam(aMsg, NPVARIANT_TO_BOOLEAN(aParam));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_INT32(aParam)) {
|
|
|
|
aMsg->WriteInt(3);
|
|
|
|
WriteParam(aMsg, NPVARIANT_TO_INT32(aParam));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_DOUBLE(aParam)) {
|
|
|
|
aMsg->WriteInt(4);
|
|
|
|
WriteParam(aMsg, NPVARIANT_TO_DOUBLE(aParam));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_STRING(aParam)) {
|
|
|
|
aMsg->WriteInt(5);
|
|
|
|
WriteParam(aMsg, NPVARIANT_TO_STRING(aParam));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ERROR("Unsupported type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
if (!aMsg->ReadInt(aIter, &type)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
VOID_TO_NPVARIANT(*aResult);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
NULL_TO_NPVARIANT(*aResult);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
bool value;
|
|
|
|
if (ReadParam(aMsg, aIter, &value)) {
|
|
|
|
BOOLEAN_TO_NPVARIANT(value, *aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 3: {
|
|
|
|
int32 value;
|
|
|
|
if (ReadParam(aMsg, aIter, &value)) {
|
|
|
|
INT32_TO_NPVARIANT(value, *aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 4: {
|
|
|
|
double value;
|
|
|
|
if (ReadParam(aMsg, aIter, &value)) {
|
|
|
|
DOUBLE_TO_NPVARIANT(value, *aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 5: {
|
|
|
|
NPString value;
|
|
|
|
if (ReadParam(aMsg, aIter, &value)) {
|
|
|
|
STRINGN_TO_NPVARIANT(value.UTF8Characters, value.UTF8Length,
|
|
|
|
*aResult);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unsupported type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
|
|
{
|
|
|
|
if (NPVARIANT_IS_VOID(aParam)) {
|
|
|
|
aLog->append(L"[void]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_NULL(aParam)) {
|
|
|
|
aLog->append(L"[null]");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_BOOLEAN(aParam)) {
|
|
|
|
LogParam(NPVARIANT_TO_BOOLEAN(aParam), aLog);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_INT32(aParam)) {
|
|
|
|
LogParam(NPVARIANT_TO_INT32(aParam), aLog);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_DOUBLE(aParam)) {
|
|
|
|
LogParam(NPVARIANT_TO_DOUBLE(aParam), aLog);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NPVARIANT_IS_STRING(aParam)) {
|
|
|
|
LogParam(NPVARIANT_TO_STRING(aParam), aLog);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ERROR("Unsupported type!");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-18 13:20:03 -07:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<mozilla::plugins::IPCByteRange>
|
|
|
|
{
|
|
|
|
typedef mozilla::plugins::IPCByteRange paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, aParam.offset);
|
|
|
|
WriteParam(aMsg, aParam.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
paramType p;
|
|
|
|
if (ReadParam(aMsg, aIter, &p.offset) &&
|
|
|
|
ReadParam(aMsg, aIter, &p.length)) {
|
|
|
|
*aResult = p;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-12-01 13:27:13 -08:00
|
|
|
template <>
|
|
|
|
struct ParamTraits<NPNVariable>
|
|
|
|
{
|
|
|
|
typedef NPNVariable paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, int(aParam));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
int intval;
|
|
|
|
if (ReadParam(aMsg, aIter, &intval)) {
|
|
|
|
*aResult = paramType(intval);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2009-09-18 18:19:11 -07:00
|
|
|
|
2010-01-15 08:26:46 -08:00
|
|
|
template<>
|
|
|
|
struct ParamTraits<NPNURLVariable>
|
|
|
|
{
|
|
|
|
typedef NPNURLVariable paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, int(aParam));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
int intval;
|
|
|
|
if (ReadParam(aMsg, aIter, &intval)) {
|
|
|
|
switch (intval) {
|
|
|
|
case NPNURLVCookie:
|
|
|
|
case NPNURLVProxy:
|
|
|
|
*aResult = paramType(intval);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-03-26 13:55:56 -07:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParamTraits<NPCoordinateSpace>
|
|
|
|
{
|
|
|
|
typedef NPCoordinateSpace paramType;
|
|
|
|
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
|
|
{
|
|
|
|
WriteParam(aMsg, int32(aParam));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
|
|
{
|
|
|
|
int32 intval;
|
|
|
|
if (ReadParam(aMsg, aIter, &intval)) {
|
|
|
|
switch (intval) {
|
|
|
|
case NPCoordinateSpacePlugin:
|
|
|
|
case NPCoordinateSpaceWindow:
|
|
|
|
case NPCoordinateSpaceFlippedWindow:
|
|
|
|
case NPCoordinateSpaceScreen:
|
|
|
|
case NPCoordinateSpaceFlippedScreen:
|
|
|
|
*aResult = paramType(intval);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
} /* namespace IPC */
|
|
|
|
|
2009-09-18 18:19:11 -07:00
|
|
|
|
|
|
|
// Serializing NPEvents is completely platform-specific and can be rather
|
|
|
|
// intricate depending on the platform. So for readability we split it
|
|
|
|
// into separate files and have the only macro crud live here.
|
|
|
|
//
|
|
|
|
// NB: these guards are based on those where struct NPEvent is defined
|
|
|
|
// in npapi.h. They should be kept in sync.
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
# include "mozilla/plugins/NPEventOSX.h"
|
|
|
|
#elif defined(XP_WIN)
|
|
|
|
# include "mozilla/plugins/NPEventWindows.h"
|
|
|
|
#elif defined(XP_OS2)
|
|
|
|
# error Sorry, OS/2 is not supported
|
2010-06-25 13:24:50 -07:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
# include "mozilla/plugins/NPEventAndroid.h"
|
2011-08-24 09:15:58 -07:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
# include "mozilla/plugins/NPEventUnix.h"
|
2009-09-18 18:19:11 -07:00
|
|
|
#else
|
|
|
|
# error Unsupported platform
|
|
|
|
#endif
|
|
|
|
|
2009-07-02 09:54:22 -07:00
|
|
|
#endif /* DOM_PLUGINS_PLUGINMESSAGEUTILS_H */
|