diff --git a/widget/BasicEvents.h b/widget/BasicEvents.h index 902299bb8722..97ea284e1578 100644 --- a/widget/BasicEvents.h +++ b/widget/BasicEvents.h @@ -495,6 +495,61 @@ public: bool IsAllowedToDispatchDOMEvent() const; }; +/****************************************************************************** + * mozilla::NativeEventData + * + * WidgetGUIEvent's mPluginEvent member used to be a void* pointer, + * used to reference external, OS-specific data structures. + * + * That void* pointer wasn't serializable by itself, causing + * certain plugin events not to function in e10s. See bug 586656. + * + * To make this serializable, we changed this void* pointer into + * a proper buffer, and copy these external data structures into this + * buffer. + * + * That buffer is NativeEventData::mBuffer below. + * + * We wrap this in that NativeEventData class providing operators to + * be compatible with existing code that was written around + * the old void* field. + ******************************************************************************/ + +class NativeEventData final +{ + nsTArray mBuffer; + + friend struct IPC::ParamTraits; + +public: + + MOZ_EXPLICIT_CONVERSION operator bool() const + { + return !mBuffer.IsEmpty(); + } + + template + MOZ_EXPLICIT_CONVERSION operator const T*() const + { + return mBuffer.IsEmpty() + ? nullptr + : reinterpret_cast(mBuffer.Elements()); + } + + template + void Copy(const T& other) + { + static_assert(!mozilla::IsPointer::value, "Don't want a pointer!"); + mBuffer.SetLength(sizeof(T)); + memcpy(mBuffer.Elements(), &other, mBuffer.Length()); + } + + void Clear() + { + mBuffer.Clear(); + } +}; + /****************************************************************************** * mozilla::WidgetGUIEvent ******************************************************************************/ @@ -537,24 +592,6 @@ public: nsCOMPtr mWidget; /* - * Explanation for this PluginEvent class: - * - * WidgetGUIEvent's mPluginEvent member used to be a void* pointer, - * used to reference external, OS-specific data structures. - * - * That void* pointer wasn't serializable by itself, causing - * certain plugin events not to function in e10s. See bug 586656. - * - * To make this serializable, we changed this void* pointer into - * a proper buffer, and copy these external data structures into this - * buffer. - * - * That buffer is PluginEvent::mBuffer below. - * - * We wrap this in that PluginEvent class providing operators to - * be compatible with existing code that was written around - * the old void* field. - * * Ideally though, we wouldn't allow arbitrary reinterpret_cast'ing here; * instead, we would at least store type information here so that * this class can't be used to reinterpret one structure type into another. @@ -562,40 +599,7 @@ public: * WidgetGUIEvent and other Event classes to remove the need for this * mPluginEvent field. */ - class PluginEvent final - { - nsTArray mBuffer; - - friend struct IPC::ParamTraits; - - public: - - MOZ_EXPLICIT_CONVERSION operator bool() const - { - return !mBuffer.IsEmpty(); - } - - template - MOZ_EXPLICIT_CONVERSION operator const T*() const - { - return mBuffer.IsEmpty() - ? nullptr - : reinterpret_cast(mBuffer.Elements()); - } - - template - void Copy(const T& other) - { - static_assert(!mozilla::IsPointer::value, "Don't want a pointer!"); - mBuffer.SetLength(sizeof(T)); - memcpy(mBuffer.Elements(), &other, mBuffer.Length()); - } - - void Clear() - { - mBuffer.Clear(); - } - }; + typedef NativeEventData PluginEvent; // Event for NPAPI plugin PluginEvent mPluginEvent; diff --git a/widget/EventForwards.h b/widget/EventForwards.h index 64fc4a29a8b5..3d5ae180de47 100644 --- a/widget/EventForwards.h +++ b/widget/EventForwards.h @@ -139,6 +139,8 @@ struct EventFlags; class WidgetEventTime; +class NativeEventData; + // TextEvents.h struct AlternativeCharCode; struct ShortcutKeyCandidate; diff --git a/widget/nsGUIEventIPC.h b/widget/nsGUIEventIPC.h index f7cfef085406..e4ae78fa4624 100644 --- a/widget/nsGUIEventIPC.h +++ b/widget/nsGUIEventIPC.h @@ -88,6 +88,22 @@ struct ParamTraits } }; +template<> +struct ParamTraits +{ + typedef mozilla::NativeEventData paramType; + + static void Write(Message* aMsg, const paramType& aParam) + { + WriteParam(aMsg, aParam.mBuffer); + } + + static bool Read(const Message* aMsg, void** aIter, paramType* aResult) + { + return ReadParam(aMsg, aIter, &aResult->mBuffer); + } +}; + template<> struct ParamTraits { @@ -96,13 +112,13 @@ struct ParamTraits static void Write(Message* aMsg, const paramType& aParam) { WriteParam(aMsg, static_cast(aParam)); - WriteParam(aMsg, aParam.mPluginEvent.mBuffer); + WriteParam(aMsg, aParam.mPluginEvent); } static bool Read(const Message* aMsg, void** aIter, paramType* aResult) { return ReadParam(aMsg, aIter, static_cast(aResult)) && - ReadParam(aMsg, aIter, &aResult->mPluginEvent.mBuffer); + ReadParam(aMsg, aIter, &aResult->mPluginEvent); } };