Bug 1383816 - Adds IPC Read and Write methods for FocusTarget and NoFocusState structs and creates EmptyStructSerializer helper class; r?botond draft
authorJeff Hajewski <jeff.hajewski@gmail.com>
Sat, 02 Sep 2017 14:10:40 -0500
changeset 661709 f4ff720f709a5e51a9f15fce2a2efbd641b741f8
parent 661708 973750414eba2a6eb86d4eb5b47d1543d49dfdc6
child 661710 34970578a546b4adca1497ad92cb084bf562ef02
push id78858
push userjeff.hajewski@gmail.com
push dateFri, 08 Sep 2017 22:55:28 +0000
reviewersbotond
bugs1383816
milestone57.0a1
Bug 1383816 - Adds IPC Read and Write methods for FocusTarget and NoFocusState structs and creates EmptyStructSerializer helper class; r?botond Since NoFocusState is am empty struct used in the |mData| variant in FocusTarget, we need to add a Reader and a Writer for IPC for NoFocusState so we can properly read and write the |mData| variant. The NoFocusState Read and Write methods do not read or write anything, since NoFocusState does not contain any data. This is done by creating a helper class EmptyStructSerliazer and inheritting from EmptyStructSerializer for the NoFocusState specialization. The |Read| and |Write| methods for FocusTarget are updated by removing the read and write code for the individual types of |mData| and instead makes use of the IPC read and write methods for Variant. MozReview-Commit-ID: 3159sp6FLek
gfx/layers/ipc/LayersMessageUtils.h
ipc/glue/IPCMessageUtils.h
--- a/gfx/layers/ipc/LayersMessageUtils.h
+++ b/gfx/layers/ipc/LayersMessageUtils.h
@@ -443,46 +443,39 @@ template <>
 struct ParamTraits<mozilla::layers::FocusTarget::FocusTargetType>
   : public ContiguousEnumSerializerInclusive<
              mozilla::layers::FocusTarget::FocusTargetType,
              mozilla::layers::FocusTarget::eNone,
              mozilla::layers::FocusTarget::sHighestFocusTargetType>
 {};
 
 template <>
+struct ParamTraits<mozilla::layers::FocusTarget::NoFocusTarget>
+  : public EmptyStructSerializer<mozilla::layers::FocusTarget::NoFocusTarget>
+{};
+
+template <>
 struct ParamTraits<mozilla::layers::FocusTarget>
 {
   typedef mozilla::layers::FocusTarget paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     WriteParam(aMsg, aParam.mSequenceNumber);
     WriteParam(aMsg, aParam.mFocusHasKeyEventListeners);
-    WriteParam(aMsg, aParam.mType);
-    if (aParam.mType == mozilla::layers::FocusTarget::eRefLayer) {
-      WriteParam(aMsg, aParam.mData.mRefLayerId);
-    } else if (aParam.mType == mozilla::layers::FocusTarget::eScrollLayer) {
-      WriteParam(aMsg, aParam.mData.mScrollTargets);
-    }
+    WriteParam(aMsg, aParam.mData);
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
   {
     if (!ReadParam(aMsg, aIter, &aResult->mSequenceNumber) ||
         !ReadParam(aMsg, aIter, &aResult->mFocusHasKeyEventListeners) ||
-        !ReadParam(aMsg, aIter, &aResult->mType)) {
+        !ReadParam(aMsg, aIter, &aResult->mData)) {
       return false;
     }
-
-    if (aResult->mType == mozilla::layers::FocusTarget::eRefLayer) {
-      return ReadParam(aMsg, aIter, &aResult->mData.mRefLayerId);
-    } else if (aResult->mType == mozilla::layers::FocusTarget::eScrollLayer) {
-      return ReadParam(aMsg, aIter, &aResult->mData.mScrollTargets);
-    }
-
     return true;
   }
 };
 
 template <>
 struct ParamTraits<mozilla::layers::KeyboardScrollAction::KeyboardScrollActionType>
   : public ContiguousEnumSerializerInclusive<
              mozilla::layers::KeyboardScrollAction::KeyboardScrollActionType,
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -281,16 +281,33 @@ struct PlainOldDataSerializer
     aMsg->WriteBytes(&aParam, sizeof(aParam));
   }
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
     return aMsg->ReadBytesInto(aIter, aResult, sizeof(paramType));
   }
 };
 
+/**
+ * A helper class for serializing empty structs. Since the struct is empty there
+ * is nothing to write, and a priori we know the result of the read.
+ */
+template <typename T>
+struct EmptyStructSerializer
+{
+  typedef T paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam) {}
+
+  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult) {
+    *aResult = {};
+    return true;
+  }
+};
+
 template<>
 struct ParamTraits<int8_t>
 {
   typedef int8_t paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     aMsg->WriteBytes(&aParam, sizeof(aParam));