Bug 1257759 part.4 Rename WidgetGUIEvent::PluginEvent to NativeEventData for using this class to send native event from plugin process to content and/or chrome process r=smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 05 Apr 2016 14:23:13 +0900
changeset 355638 b0b5a863360bf0893b161d70124d3a83aa2c3386
parent 355637 66e9351a36dfa88f080ea78972ac0cb347bb174d
child 355639 8140456de278956d2d594e85c7b397ae366b4962
push id16345
push usermasayuki@d-toybox.com
push dateSat, 23 Apr 2016 09:42:11 +0000
reviewerssmaug
bugs1257759
milestone48.0a1
Bug 1257759 part.4 Rename WidgetGUIEvent::PluginEvent to NativeEventData for using this class to send native event from plugin process to content and/or chrome process r=smaug PluginInstanceChild needs to send native key event to the chrome process via a content process. So, IPC needs a platform independent class/struct which can store native event. This purpose is exactly same as the purpose of WidgetGUIEvent::PluginEvent. Therefore, we can use it for this case too. This patch renames WidgetGUIEvent::PluginEvent to NativeEventData but this patch does NOT remove WidgetGUIEvent::PluginEvent. Instead of that, it's defined as an alias of NativeEventData since PluginEvent is clearer name for the original purpose and it's used by plugin module. MozReview-Commit-ID: 3nrHfb8gk8m
widget/BasicEvents.h
widget/EventForwards.h
widget/nsGUIEventIPC.h
--- a/widget/BasicEvents.h
+++ b/widget/BasicEvents.h
@@ -491,16 +491,71 @@ public:
   bool IsTargetedAtFocusedContent() const;
   /**
    * Whether the event should cause a DOM event.
    */
   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<uint8_t> mBuffer;
+
+  friend struct IPC::ParamTraits<mozilla::NativeEventData>;
+
+public:
+
+  MOZ_EXPLICIT_CONVERSION operator bool() const
+  {
+    return !mBuffer.IsEmpty();
+  }
+
+  template<typename T>
+  MOZ_EXPLICIT_CONVERSION operator const T*() const
+  {
+    return mBuffer.IsEmpty()
+           ? nullptr
+           : reinterpret_cast<const T*>(mBuffer.Elements());
+  }
+
+  template <typename T>
+  void Copy(const T& other)
+  {
+    static_assert(!mozilla::IsPointer<T>::value, "Don't want a pointer!");
+    mBuffer.SetLength(sizeof(T));
+    memcpy(mBuffer.Elements(), &other, mBuffer.Length());
+  }
+
+  void Clear()
+  {
+    mBuffer.Clear();
+  }
+};
+
+/******************************************************************************
  * mozilla::WidgetGUIEvent
  ******************************************************************************/
 
 class WidgetGUIEvent : public WidgetEvent
 {
 protected:
   WidgetGUIEvent(bool aIsTrusted, EventMessage aMessage, nsIWidget* aWidget,
                  EventClassID aEventClassID)
@@ -532,75 +587,24 @@ public:
     result->mFlags = mFlags;
     return result;
   }
 
   // Originator of the event
   nsCOMPtr<nsIWidget> 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.
    * We can also wonder if it would be possible to properly extend
    * WidgetGUIEvent and other Event classes to remove the need for this
    * mPluginEvent field.
    */
-  class PluginEvent final
-  {
-    nsTArray<uint8_t> mBuffer;
-
-    friend struct IPC::ParamTraits<mozilla::WidgetGUIEvent>;
-
-  public:
-
-    MOZ_EXPLICIT_CONVERSION operator bool() const
-    {
-      return !mBuffer.IsEmpty();
-    }
-
-    template<typename T>
-    MOZ_EXPLICIT_CONVERSION operator const T*() const
-    {
-      return mBuffer.IsEmpty()
-             ? nullptr
-             : reinterpret_cast<const T*>(mBuffer.Elements());
-    }
-
-    template <typename T>
-    void Copy(const T& other)
-    {
-      static_assert(!mozilla::IsPointer<T>::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;
 
   void AssignGUIEventData(const WidgetGUIEvent& aEvent, bool aCopyTargets)
   {
     AssignEventData(aEvent, aCopyTargets);
 
--- a/widget/EventForwards.h
+++ b/widget/EventForwards.h
@@ -134,16 +134,18 @@ namespace mozilla {
 #undef NS_ROOT_EVENT_CLASS
 
 // BasicEvents.h
 struct BaseEventFlags;
 struct EventFlags;
 
 class WidgetEventTime;
 
+class NativeEventData;
+
 // TextEvents.h
 struct AlternativeCharCode;
 struct ShortcutKeyCandidate;
 
 typedef nsTArray<ShortcutKeyCandidate> ShortcutKeyCandidateArray;
 typedef AutoTArray<ShortcutKeyCandidate, 10> AutoShortcutKeyCandidateArray;
 
 // TextRange.h
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -84,30 +84,46 @@ struct ParamTraits<mozilla::WidgetEvent>
                ReadParam(aMsg, aIter, &aResult->mTimeStamp) &&
                ReadParam(aMsg, aIter, &aResult->mFlags);
     aResult->mClass = static_cast<mozilla::EventClassID>(eventClassID);
     return ret;
   }
 };
 
 template<>
+struct ParamTraits<mozilla::NativeEventData>
+{
+  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<mozilla::WidgetGUIEvent>
 {
   typedef mozilla::WidgetGUIEvent paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, static_cast<mozilla::WidgetEvent>(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<mozilla::WidgetEvent*>(aResult)) &&
-           ReadParam(aMsg, aIter, &aResult->mPluginEvent.mBuffer);
+           ReadParam(aMsg, aIter, &aResult->mPluginEvent);
   }
 };
 
 template<>
 struct ParamTraits<mozilla::WidgetInputEvent>
 {
   typedef mozilla::WidgetInputEvent paramType;