Bug 1176954 part.2 ContentCache in parent process should manage how many events are sent but not yet received r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 11 Jul 2015 10:53:55 +0900
changeset 285771 b226ef6b9ca3e00b97a3b2f97d99dc1dea5d2616
parent 285770 300b08b3eca6f644c33c243ff49da60f79f501fb
child 285772 9d0af72de7c0f193eb56ecd5cd5e61a24d5f7346
push id934
push userraliiev@mozilla.com
push dateMon, 26 Oct 2015 12:58:05 +0000
treeherdermozilla-release@05704e35c1d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1176954
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1176954 part.2 ContentCache in parent process should manage how many events are sent but not yet received r=smaug
dom/ipc/TabParent.cpp
widget/ContentCache.cpp
widget/ContentCache.h
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -2087,16 +2087,17 @@ TabParent::RecvNotifyIMEPositionChange(c
   return true;
 }
 
 bool
 TabParent::RecvOnEventNeedingAckReceived()
 {
   // This is called when the child process receives WidgetCompositionEvent or
   // WidgetSelectionEvent.
+  mContentCache.OnEventNeedingAckReceived();
   return true;
 }
 
 bool
 TabParent::RecvRequestFocus(const bool& aCanRaise)
 {
   nsCOMPtr<nsIFocusManager> fm = nsFocusManager::GetFocusManager();
   if (!fm) {
@@ -2281,16 +2282,17 @@ TabParent::SendSelectionEvent(WidgetSele
 {
   if (mIsDestroyed) {
     return false;
   }
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (!widget) {
     return true;
   }
+  mContentCache.OnSelectionEvent(event);
   return PBrowserParent::SendSelectionEvent(event);
 }
 
 /*static*/ TabParent*
 TabParent::GetFrom(nsFrameLoader* aFrameLoader)
 {
   if (!aFrameLoader) {
     return nullptr;
--- a/widget/ContentCache.cpp
+++ b/widget/ContentCache.cpp
@@ -34,16 +34,18 @@ GetEventMessageName(uint32_t aMessage)
     case NS_COMPOSITION_UPDATE:
       return "NS_COMPOSITION_UPDATE";
     case NS_COMPOSITION_CHANGE:
       return "NS_COMPOSITION_CHANGE";
     case NS_COMPOSITION_COMMIT_AS_IS:
       return "NS_COMPOSITION_COMMIT_AS_IS";
     case NS_COMPOSITION_COMMIT:
       return "NS_COMPOSITION_COMMIT";
+    case NS_SELECTION_SET:
+      return "NS_SELECTION_SET";
     default:
       return "unacceptable event message";
   }
 }
 
 static const char*
 GetNotificationName(const IMENotification* aNotification)
 {
@@ -466,16 +468,17 @@ ContentCacheInChild::SetSelection(nsIWid
 /*****************************************************************************
  * mozilla::ContentCacheInParent
  *****************************************************************************/
 
 ContentCacheInParent::ContentCacheInParent()
   : ContentCache()
   , mCompositionStart(UINT32_MAX)
   , mCompositionEventsDuringRequest(0)
+  , mPendingEventsNeedingAck(0)
   , mIsComposing(false)
   , mRequestedToCommitOrCancelComposition(false)
 {
 }
 
 void
 ContentCacheInParent::AssignContent(const ContentCache& aOther,
                                     const IMENotification* aNotification)
@@ -839,32 +842,35 @@ ContentCacheInParent::GetCaretRect(uint3
 }
 
 bool
 ContentCacheInParent::OnCompositionEvent(const WidgetCompositionEvent& aEvent)
 {
   MOZ_LOG(sContentCacheLog, LogLevel::Info,
     ("ContentCacheInParent: 0x%p OnCompositionEvent(aEvent={ "
      "message=%s, mData=\"%s\" (Length()=%u), mRanges->Length()=%u }), "
-     "mIsComposing=%s, mRequestedToCommitOrCancelComposition=%s",
+     "mPendingEventsNeedingAck=%u, mIsComposing=%s, "
+     "mRequestedToCommitOrCancelComposition=%s",
      this, GetEventMessageName(aEvent.message),
      NS_ConvertUTF16toUTF8(aEvent.mData).get(), aEvent.mData.Length(),
-     aEvent.mRanges ? aEvent.mRanges->Length() : 0, GetBoolName(mIsComposing),
+     aEvent.mRanges ? aEvent.mRanges->Length() : 0, mPendingEventsNeedingAck,
+     GetBoolName(mIsComposing),
      GetBoolName(mRequestedToCommitOrCancelComposition)));
 
   if (!aEvent.CausesDOMTextEvent()) {
     MOZ_ASSERT(aEvent.message == NS_COMPOSITION_START);
     mIsComposing = !aEvent.CausesDOMCompositionEndEvent();
     mCompositionStart = mSelection.StartOffset();
     // XXX What's this case??
     if (mRequestedToCommitOrCancelComposition) {
       mCommitStringByRequest = aEvent.mData;
       mCompositionEventsDuringRequest++;
       return false;
     }
+    mPendingEventsNeedingAck++;
     return true;
   }
 
   // XXX Why do we ignore following composition events here?
   //     TextComposition must handle following events correctly!
 
   // During REQUEST_TO_COMMIT_COMPOSITION or REQUEST_TO_CANCEL_COMPOSITION,
   // widget usually sends a NS_COMPOSITION_CHANGE event to finalize or
@@ -879,19 +885,51 @@ ContentCacheInParent::OnCompositionEvent
   }
 
   // We must be able to simulate the selection because
   // we might not receive selection updates in time
   if (!mIsComposing) {
     mCompositionStart = mSelection.StartOffset();
   }
   mIsComposing = !aEvent.CausesDOMCompositionEndEvent();
+  mPendingEventsNeedingAck++;
   return true;
 }
 
+void
+ContentCacheInParent::OnSelectionEvent(
+                        const WidgetSelectionEvent& aSelectionEvent)
+{
+  MOZ_LOG(sContentCacheLog, LogLevel::Info,
+    ("ContentCacheInParent: 0x%p OnSelectionEvent(aEvent={ "
+     "message=%s, mOffset=%u, mLength=%u, mReversed=%s, "
+     "mExpandToClusterBoundary=%s, mUseNativeLineBreak=%s }), "
+     "mPendingEventsNeedingAck=%u, mIsComposing=%s",
+     this, GetEventMessageName(aSelectionEvent.message),
+     aSelectionEvent.mOffset, aSelectionEvent.mLength,
+     GetBoolName(aSelectionEvent.mReversed),
+     GetBoolName(aSelectionEvent.mExpandToClusterBoundary),
+     GetBoolName(aSelectionEvent.mUseNativeLineBreak), mPendingEventsNeedingAck,
+     GetBoolName(mIsComposing)));
+
+  mPendingEventsNeedingAck++;
+}
+
+void
+ContentCacheInParent::OnEventNeedingAckReceived()
+{
+  MOZ_LOG(sContentCacheLog, LogLevel::Info,
+    ("ContentCacheInParent: 0x%p OnEventNeedingAckReceived(), "
+     "mPendingEventsNeedingAck=%u",
+     this, mPendingEventsNeedingAck));
+
+  MOZ_RELEASE_ASSERT(mPendingEventsNeedingAck > 0);
+  mPendingEventsNeedingAck--;
+}
+
 uint32_t
 ContentCacheInParent::RequestToCommitComposition(nsIWidget* aWidget,
                                                  bool aCancel,
                                                  nsAString& aLastString)
 {
   MOZ_LOG(sContentCacheLog, LogLevel::Info,
     ("ContentCacheInParent: 0x%p RequestToCommitComposition(aWidget=%p, "
      "aCancel=%s), mIsComposing=%s, mRequestedToCommitOrCancelComposition=%s, "
--- a/widget/ContentCache.h
+++ b/widget/ContentCache.h
@@ -310,16 +310,27 @@ public:
 
   /**
    * OnCompositionEvent() should be called before sending composition string.
    * This returns true if the event should be sent.  Otherwise, false.
    */
   bool OnCompositionEvent(const WidgetCompositionEvent& aCompositionEvent);
 
   /**
+   * OnSelectionEvent() should be called before sending selection event.
+   */
+  void OnSelectionEvent(const WidgetSelectionEvent& aSelectionEvent);
+
+  /**
+   * OnEventNeedingAckReceived() should be called when the child process
+   * receives a sent event which needs acknowledging.
+   */
+  void OnEventNeedingAckReceived();
+
+  /**
    * RequestToCommitComposition() requests to commit or cancel composition to
    * the widget.  If it's handled synchronously, this returns the number of
    * composition events after that.
    *
    * @param aWidget     The widget to be requested to commit or cancel
    *                    the composition.
    * @param aCancel     When the caller tries to cancel the composition, true.
    *                    Otherwise, i.e., tries to commit the composition, false.
@@ -342,16 +353,20 @@ public:
 private:
   // This is commit string which is caused by our request.
   nsString mCommitStringByRequest;
   // Start offset of the composition string.
   uint32_t mCompositionStart;
   // Count of composition events during requesting commit or cancel the
   // composition.
   uint32_t mCompositionEventsDuringRequest;
+  // mPendingEventsNeedingAck is increased before sending a composition event or
+  // a selection event and decreased after they are received in the child
+  // process.
+  uint32_t mPendingEventsNeedingAck;
 
   bool mIsComposing;
   bool mRequestedToCommitOrCancelComposition;
 
   bool GetCaretRect(uint32_t aOffset, LayoutDeviceIntRect& aCaretRect) const;
   bool GetTextRect(uint32_t aOffset,
                    LayoutDeviceIntRect& aTextRect) const;
   bool GetUnionTextRects(uint32_t aOffset,