mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
bc8ce42355
- Bug 1226200: Don't assume a TCPSocket has only one managee (and rename LoneManagedOrNull) r=jdm (aa2d0fcc14) - Bug 1227300, Part 1 - Add an alert notification component. r=MattN,wchen (37758ce9ff) - Bug 1230700. Make Notification::ShowInternal explicitly suppress the exception from GetPermissionInternal. r=smaug (9e288cf5ae) - Bug 1225336 - Add telemetry about web notification display/messages. r=wchen,kitcambridge p=vladan# Please enter the commit message for your changes. Lines starting (b2e481691a) - Bug 1219030 - Collect notification management telemetry. r=wchen,MattN; p=ally (c0ba425b4e) - Bug 1212611 - Use system notification for website notifications in Android. r=mfinkle (84985bcf01) - Bug 1227300, Part 2 - Implement showAlert. r=MattN,wchen (33eedc7e91) - Bug 1214305 - Part 0: Ensure site security service is initialized before trying to use DataStorage via IPC. (8bd73f43b0) - Bug 1137681 - Make user agent docshell overrides affect network requests. r=jduell (e8dabb8338) - Bug 1233245 - Propagate the interception information in the non-e10s case for all HTTP redirects, not just the internal ones; r=jdm (6922fddcf8) - Bug 1226444 - Use helper function to identify preloads. r=sicking (d110669f73) - Bug 1214305 - Part 1: Refactor the logic for querying whether a connection should go through a secure upgrade into NS_ShouldSecureUpgrade; r=mcmanus (2d04c78290) - Bug 1137681 - Per-tab user agent emulation. r=bz (4ff70db690) - Bug 1227300, Part 3 - Implement showAlert for the OS X alerts backend. r=mstange (5eb05d0728) - Bug 1227300, Part 4 - Implement showAlert for the libnotify alerts backend. r=karlt (0942fa2764) - Bug 1227300, Part 5 - Implement showAlert for the B2G alerts backend. r=mhenretty (e39581aea5) - Bug 1227300, Part 6 - Use showAlert to display web notifications. r=wchen (ab79eaa0c8) - domBug 1227300, Part 7 - Update test interfaces. a=testonly (387cb62772) - Bug 1214305 - Part 3: Add a nsIInterceptedChannel.secureUpgradedChannelURI helper; r=jdm (811d25bd58) - Bug 1214305 - Part 4: Use the secure upgraded channel URI in ServiceWorkerManager::PrepareFetchEvent; r=jdm (0c44bf527c) - Bug 1214305 - Part 5: Use the secure upgraded channel URI in FetchEventRunnable::Init; r=jdm (a30f239261) - Bug 1214305 - Part 6: Use a non-IPC redirect for synthesized upgraded responses to ensure the response URL is correctly propagated; r=mcmanus (8ba8a5728c) - Bug 1214305 - Part 7: Decide in the child process whether an intercepted channel should go through a secure upgrade; r=mcmanus (93e27decae) - Bug 1198397 - Add a test for interception of requests upgraded through the CSP upgrade-insecure-requests directive; r=jdm (21eb14eb34) - Bug 1214305 - Part 8: Enable secure upgrade service worker tests on e10s; r=jdm (c14f5fb504) - Bug 1214305 - Part 10: Clean up global DataStorage references in the child process; r=keeler (ef0b52d049) - Bug 1224771 - Close all web notifications when the originating tab is closed. r=wchen (da295b4ba7) - Bug 1214305 - Part 2: Refactor the logic for obtaining the secure upgraded URI into HttpBaseChannel; r=mcmanus (3346078285) - Bug 1237151 (part 1) - Remove ignored qualifiers in dom/media/gmp/. r=cpearce. (18134820a6) - Bug 1237151 (part 2) - Remove ignored qualifiers in WebRTC-relate code. r=jesup. (effe5bd694) - Bug 1118820 part 1 (style system part) - [css-grid] Implement the 'auto-fill' and 'auto-fit' keywords in the repeat() function. r=dholbert (5db1a577db) - Bug 1118820 part 2a - [css-grid] Add a LineNameMap class that lets us lookup line names with a dynamic number of 'repeat(auto-fill/auto-fit)' tracks taken into account. r=dholbert (3ecf4b53f0) - Bug 1118820 part 2b - [css-grid] Move the static functions FindLine/RFindLine/FindNamedLine into the LineNameMap class (idempotent patch). r=dholbert (efb12c594b) - Bug 1118820 part 2c+2d - [css-grid] Modify the LineNameMap::FindLine/RFindLine/FindNamedLine methods to take line names associated with 'repeat(auto-fill/auto-fit)' tracks into account. Instantiate and pass around a LineNameMap object instead of an array of line name arrays. r=dholbert (a3db750297) - Bug 1118820 part 3a - [css-grid] Modify TrackSizingFunctions to take a dynamic number of 'repeat(auto-fill/auto-fit)' tracks taking into account. r=dholbert (9aa6033332) - Bug 1118820 part 3b - [css-grid] Implement the CalculateRepeatFillCount method that calculates the number of 'repeat(auto-fill/auto-fit)' tracks to use for the given sizes. r=dholbert (cf75fab8a8) - Bug 1118820 part 4 - [css-grid] Provide the sizes to use for CalculateRepeatFillCount. r=dholbert (8184c00dba) - Bug 1118820 part 5 - [css-grid] Remove any empty 'repeat(auto-fit)' tracks at the end of its range and adjust affected grid area line numbers accordingly. r=dholbert (c02ba6a6e3) - Bug 1229165 - [css-grid] Reftests for min/max-width/height properties on the grid container. (725097f878) - Bug 1229999 - [css-grid] Reftest. (51b5bc9535) - Bug 1237151 (part 3) - Remove ignored qualifiers in all remaining code. r=froydnj. (69917ebbad) - more bits of Bug 1178892 - Split the profiler into Core & Gecko files (41bb127b9c) - Bug 1199841 - Restructure private browsing to remember status after OnStopRequest r=jdm (16c2c1044d) - Bug 1233845 - Report an interception error and cancel the HTTP channel when encountering a known topcrash situation. r=ehsan (5d08075110) - Bug 664163 - Fix Get(Local|Remote)(Address|Port) in HttpChannelChild. r=jduell (cbf70af4e8) - Bug 1229177 - Show the tracking protection shield for fetch and XHR requests. r=jduell (5833b3e872) - Bug 1220678 Don't crash when DivertToParent() is called on an intercepted channel. r=jdm (5d7ff6ecc8) - Bug 1220681 P1 Make HttpChannelChild::DivertToParent() work with synthetic responses. r=jdm (67715703ef) - Bug 1169819 Add browser chrome test to validate SW force refresh. r=ehsan (c0b6b3e874) - Bug 1220681 P2 Test synthetic responses that trigger downloads. r=ehsan (c701f3ddb1) - Bug 1220681 P3 Delay diversion on parent side until response head has been synthesized. r=jdm (7c697aacee) - Bug 1220681 P4 Automatically suspend the parent channel after synthesizing the response for diverison. r=jdm (27f31bcb35) - Bug 1220681 P5 Don't double suspend parent channel during synthesized divert to parent. r=jdm (62081d4b56) - Bug 1220681 P6 Use clients.claim() in browser_download.js to avoid worker unregister race. r=jdm (c8de291727) - Bug 1240161 - Remove "only-if-cached" from RequestCache; r=bkelly (283486f584) - Bug 1184550 - Add a mochitest for the Request constructor that tests that the body is set to used after being fetched and then fails on the second fetch with the same Request. r=bkelly (db4a967203) - Bug 1205495 - Correctly use the requests's body and redirect mode in reroute.js; r=nsm (a36a96624a) - Bug 1189656 - Fix fetch-request-fallback test paths. r=bkelly (366c884179) - Bug 1219085 - Import the fetch-request-redirect.https.html test from Blink; r=jdm (bf6b484d82) - Bug 1209081 - Part 1: Implement the "navigate" value for RequestMode; r=bkelly (a22f19d94b) - Bug 1209081 - Part 2: Upgrade the saved Requests in the DOM Cache to reflect the "navigate" RequestMode if they represent navigation content policy types; r=bkelly (60d1da23bb) - Bug 1219469 - Part 1: Revert the error reporting added in bug 1233845; r=jdm (dcc022b9d3) - Bug 1219469 - Part 2: Make HttpChannelParentListener be the controller; r=jdm,jduell (9c5f0dfbe0) - Bug 1229369 - Intercept redirected network fetches that have their request mode set to manual; r=jdm (fb21d86ed2)
867 lines
21 KiB
C++
867 lines
21 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
* vim: sw=4 ts=4 et :
|
|
* 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/. */
|
|
|
|
#ifndef DOM_PLUGINS_PLUGINMESSAGEUTILS_H
|
|
#define DOM_PLUGINS_PLUGINMESSAGEUTILS_H
|
|
|
|
#include "ipc/IPCMessageUtils.h"
|
|
#include "base/message_loop.h"
|
|
|
|
#include "mozilla/ipc/MessageChannel.h"
|
|
#include "mozilla/ipc/CrossProcessMutex.h"
|
|
#include "mozilla/UniquePtr.h"
|
|
#include "gfxipc/ShadowLayerUtils.h"
|
|
|
|
#include "npapi.h"
|
|
#include "npruntime.h"
|
|
#include "npfunctions.h"
|
|
#include "nsAutoPtr.h"
|
|
#include "nsString.h"
|
|
#include "nsTArray.h"
|
|
#include "mozilla/Logging.h"
|
|
#include "nsHashKeys.h"
|
|
#ifdef XP_MACOSX
|
|
#include "PluginInterposeOSX.h"
|
|
#else
|
|
namespace mac_plugin_interposing { class NSCursorInfo { }; }
|
|
#endif
|
|
using mac_plugin_interposing::NSCursorInfo;
|
|
|
|
namespace mozilla {
|
|
namespace plugins {
|
|
|
|
using layers::SurfaceDescriptorX11;
|
|
|
|
enum ScriptableObjectType
|
|
{
|
|
LocalObject,
|
|
Proxy
|
|
};
|
|
|
|
mozilla::ipc::RacyInterruptPolicy
|
|
MediateRace(const mozilla::ipc::MessageChannel::Message& parent,
|
|
const mozilla::ipc::MessageChannel::Message& child);
|
|
|
|
std::string
|
|
MungePluginDsoPath(const std::string& path);
|
|
std::string
|
|
UnmungePluginDsoPath(const std::string& munged);
|
|
|
|
extern mozilla::LogModule* GetPluginLog();
|
|
|
|
#if defined(_MSC_VER)
|
|
#define FULLFUNCTION __FUNCSIG__
|
|
#elif defined(__GNUC__)
|
|
#define FULLFUNCTION __PRETTY_FUNCTION__
|
|
#else
|
|
#define FULLFUNCTION __FUNCTION__
|
|
#endif
|
|
|
|
#define PLUGIN_LOG_DEBUG(args) MOZ_LOG(GetPluginLog(), mozilla::LogLevel::Debug, args)
|
|
#define PLUGIN_LOG_DEBUG_FUNCTION MOZ_LOG(GetPluginLog(), mozilla::LogLevel::Debug, ("%s", FULLFUNCTION))
|
|
#define PLUGIN_LOG_DEBUG_METHOD MOZ_LOG(GetPluginLog(), mozilla::LogLevel::Debug, ("%s [%p]", FULLFUNCTION, (void*) this))
|
|
|
|
/**
|
|
* This is NPByteRange without the linked list.
|
|
*/
|
|
struct IPCByteRange
|
|
{
|
|
int32_t offset;
|
|
uint32_t length;
|
|
};
|
|
|
|
typedef nsTArray<IPCByteRange> IPCByteRanges;
|
|
|
|
typedef nsCString Buffer;
|
|
|
|
struct NPRemoteWindow
|
|
{
|
|
NPRemoteWindow();
|
|
uint64_t window;
|
|
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 */
|
|
#if defined(XP_MACOSX)
|
|
double contentsScaleFactor;
|
|
#endif
|
|
};
|
|
|
|
#ifdef XP_WIN
|
|
typedef HWND NativeWindowHandle;
|
|
#elif defined(MOZ_X11)
|
|
typedef XID NativeWindowHandle;
|
|
#elif defined(XP_MACOSX) || defined(ANDROID) || defined(MOZ_WIDGET_QT)
|
|
typedef intptr_t NativeWindowHandle; // never actually used, will always be 0
|
|
#else
|
|
#error Need NativeWindowHandle for this platform
|
|
#endif
|
|
|
|
#ifdef XP_WIN
|
|
typedef base::SharedMemoryHandle WindowsSharedMemoryHandle;
|
|
typedef HANDLE DXGISharedSurfaceHandle;
|
|
#else
|
|
typedef mozilla::null_t WindowsSharedMemoryHandle;
|
|
typedef mozilla::null_t DXGISharedSurfaceHandle;
|
|
#endif
|
|
|
|
// XXX maybe not the best place for these. better one?
|
|
|
|
#define VARSTR(v_) case v_: return #v_
|
|
inline const char*
|
|
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);
|
|
VARSTR(NPNVdocumentOrigin);
|
|
|
|
default: return "???";
|
|
}
|
|
}
|
|
#undef VARSTR
|
|
|
|
inline bool IsPluginThread()
|
|
{
|
|
MessageLoop* loop = MessageLoop::current();
|
|
if (!loop)
|
|
return false;
|
|
return (loop->type() == MessageLoop::TYPE_UI);
|
|
}
|
|
|
|
inline void AssertPluginThread()
|
|
{
|
|
NS_ASSERTION(IsPluginThread(), "Should be on the plugin's main thread!");
|
|
}
|
|
|
|
#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
|
|
|
|
void DeferNPObjectLastRelease(const NPNetscapeFuncs* f, NPObject* o);
|
|
void DeferNPVariantLastRelease(const NPNetscapeFuncs* f, NPVariant* v);
|
|
|
|
inline bool IsDrawingModelDirect(int16_t aModel)
|
|
{
|
|
return aModel == NPDrawingModelAsyncBitmapSurface
|
|
#if defined(XP_WIN)
|
|
|| aModel == NPDrawingModelAsyncWindowsDXGISurface
|
|
#endif
|
|
;
|
|
}
|
|
|
|
// in NPAPI, char* == nullptr is sometimes meaningful. the following is
|
|
// helper code for dealing with nullable nsCString's
|
|
inline nsCString
|
|
NullableString(const char* aString)
|
|
{
|
|
if (!aString) {
|
|
nsCString str;
|
|
str.SetIsVoid(true);
|
|
return str;
|
|
}
|
|
return nsCString(aString);
|
|
}
|
|
|
|
inline const char*
|
|
NullableStringGet(const nsCString& str)
|
|
{
|
|
if (str.IsVoid())
|
|
return nullptr;
|
|
|
|
return str.get();
|
|
}
|
|
|
|
struct DeletingObjectEntry : public nsPtrHashKey<NPObject>
|
|
{
|
|
explicit DeletingObjectEntry(const NPObject* key)
|
|
: nsPtrHashKey<NPObject>(key)
|
|
, mDeleted(false)
|
|
{ }
|
|
|
|
bool mDeleted;
|
|
};
|
|
|
|
} /* namespace plugins */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
namespace IPC {
|
|
|
|
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_t(aParam));
|
|
}
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
{
|
|
int16_t 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_t(aParam)));
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct ParamTraits<mozilla::plugins::NPRemoteWindow>
|
|
{
|
|
typedef mozilla::plugins::NPRemoteWindow paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
{
|
|
aMsg->WriteUInt64(aParam.window);
|
|
WriteParam(aMsg, aParam.x);
|
|
WriteParam(aMsg, aParam.y);
|
|
WriteParam(aMsg, aParam.width);
|
|
WriteParam(aMsg, aParam.height);
|
|
WriteParam(aMsg, aParam.clipRect);
|
|
WriteParam(aMsg, aParam.type);
|
|
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
aMsg->WriteULong(aParam.visualID);
|
|
aMsg->WriteULong(aParam.colormap);
|
|
#endif
|
|
#if defined(XP_MACOSX)
|
|
aMsg->WriteDouble(aParam.contentsScaleFactor);
|
|
#endif
|
|
}
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
{
|
|
uint64_t window;
|
|
int32_t x, y;
|
|
uint32_t width, height;
|
|
NPRect clipRect;
|
|
NPWindowType type;
|
|
if (!(aMsg->ReadUInt64(aIter, &window) &&
|
|
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;
|
|
|
|
#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
|
|
|
|
#if defined(XP_MACOSX)
|
|
double contentsScaleFactor;
|
|
if (!aMsg->ReadDouble(aIter, &contentsScaleFactor))
|
|
return false;
|
|
#endif
|
|
|
|
aResult->window = window;
|
|
aResult->x = x;
|
|
aResult->y = y;
|
|
aResult->width = width;
|
|
aResult->height = height;
|
|
aResult->clipRect = clipRect;
|
|
aResult->type = type;
|
|
#if defined(MOZ_X11) && defined(XP_UNIX) && !defined(XP_MACOSX)
|
|
aResult->visualID = visualID;
|
|
aResult->colormap = colormap;
|
|
#endif
|
|
#if defined(XP_MACOSX)
|
|
aResult->contentsScaleFactor = contentsScaleFactor;
|
|
#endif
|
|
return true;
|
|
}
|
|
|
|
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));
|
|
}
|
|
};
|
|
|
|
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;
|
|
}
|
|
|
|
const char* messageBuffer = nullptr;
|
|
mozilla::UniquePtr<char[]> newBuffer(new char[byteCount]);
|
|
if (newBuffer && aMsg->ReadBytes(aIter, &messageBuffer, byteCount )) {
|
|
memcpy((void*)messageBuffer, newBuffer.get(), byteCount);
|
|
aResult->UTF8Characters = newBuffer.release();
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static void Log(const paramType& aParam, std::wstring* aLog)
|
|
{
|
|
aLog->append(StringPrintf(L"%s", aParam.UTF8Characters));
|
|
}
|
|
};
|
|
|
|
#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 nullptr terminating character in buffers.
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
{
|
|
CFStringRef cfString = (CFStringRef)aParam;
|
|
|
|
// Write true if we have a string, false represents nullptr.
|
|
aMsg->WriteBool(!!cfString);
|
|
if (!cfString) {
|
|
return;
|
|
}
|
|
|
|
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)
|
|
{
|
|
bool haveString = false;
|
|
if (!aMsg->ReadBool(aIter, &haveString)) {
|
|
return false;
|
|
}
|
|
if (!haveString) {
|
|
*aResult = nullptr;
|
|
return true;
|
|
}
|
|
|
|
long length;
|
|
if (!ReadParam(aMsg, aIter, &length)) {
|
|
return false;
|
|
}
|
|
|
|
UniChar* buffer = nullptr;
|
|
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
|
|
|
|
#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 = nullptr;
|
|
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
|
|
|
|
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_t 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!");
|
|
}
|
|
};
|
|
|
|
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;
|
|
}
|
|
};
|
|
|
|
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;
|
|
}
|
|
};
|
|
|
|
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;
|
|
}
|
|
};
|
|
|
|
|
|
template<>
|
|
struct ParamTraits<NPCoordinateSpace>
|
|
{
|
|
typedef NPCoordinateSpace paramType;
|
|
|
|
static void Write(Message* aMsg, const paramType& aParam)
|
|
{
|
|
WriteParam(aMsg, int32_t(aParam));
|
|
}
|
|
|
|
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
|
|
{
|
|
int32_t 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;
|
|
}
|
|
};
|
|
|
|
} /* namespace IPC */
|
|
|
|
|
|
// 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(ANDROID)
|
|
# include "mozilla/plugins/NPEventAndroid.h"
|
|
#elif defined(XP_UNIX)
|
|
# include "mozilla/plugins/NPEventUnix.h"
|
|
#else
|
|
# error Unsupported platform
|
|
#endif
|
|
|
|
#endif /* DOM_PLUGINS_PLUGINMESSAGEUTILS_H */
|