Bug 1166436 part.16 Make each member of mozilla::ContentCache used by chrome process or content process r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 05 Jun 2015 18:28:21 +0900
changeset 279724 d5462260041476cf3079d4855074ce51aed12ebb
parent 279723 cc9201883c30f2b20463f9ec6b77a2e8deea2412
child 279725 8feaf4e01d6a6b2f5d51046ded6704a8ce3d510e
push id897
push userjlund@mozilla.com
push dateMon, 14 Sep 2015 18:56:12 +0000
treeherdermozilla-release@9411e2d2b214 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1166436
milestone41.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 1166436 part.16 Make each member of mozilla::ContentCache used by chrome process or content process r=m_kato
widget/ContentCache.cpp
widget/ContentCache.h
--- a/widget/ContentCache.cpp
+++ b/widget/ContentCache.cpp
@@ -127,16 +127,20 @@ ContentCache::ContentCache()
     sContentCacheLog = PR_NewLogModule("ContentCacheWidgets");
   }
 }
 
 void
 ContentCache::AssignContent(const ContentCache& aOther,
                             const IMENotification* aNotification)
 {
+  if (NS_WARN_IF(!mIsChrome)) {
+    return;
+  }
+
   mText = aOther.mText;
   mSelection = aOther.mSelection;
   mCaret = aOther.mCaret;
   mTextRectArray = aOther.mTextRectArray;
   mEditorRect = aOther.mEditorRect;
 
   MOZ_LOG(sContentCacheLog, LogLevel::Info,
     ("ContentCache: 0x%p (mIsChrome=%s) AssignContent(aNotification=%s), "
@@ -155,29 +159,37 @@ ContentCache::AssignContent(const Conten
 
 void
 ContentCache::Clear()
 {
   MOZ_LOG(sContentCacheLog, LogLevel::Info,
     ("ContentCache: 0x%p (mIsChrome=%s) Clear()",
      this, GetBoolName(mIsChrome)));
 
+  if (NS_WARN_IF(mIsChrome)) {
+    return;
+  }
+
   mText.Truncate();
   mSelection.Clear();
   mCaret.Clear();
   mTextRectArray.Clear();
   mEditorRect.SetEmpty();
 }
 
 bool
 ContentCache::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent,
                                       nsIWidget* aWidget) const
 {
   MOZ_ASSERT(aWidget);
 
+  if (NS_WARN_IF(!mIsChrome)) {
+    return false;
+  }
+
   aEvent.mSucceeded = false;
   aEvent.mWasAsync = false;
   aEvent.mReply.mFocusedWidget = aWidget;
 
   switch (aEvent.message) {
     case NS_QUERY_SELECTED_TEXT:
       MOZ_LOG(sContentCacheLog, LogLevel::Info,
         ("ContentCache: 0x%p (mIsChrome=%s) HandleQueryContentEvent("
@@ -493,16 +505,20 @@ ContentCache::CacheText(nsIWidget* aWidg
 
 bool
 ContentCache::QueryCharRect(nsIWidget* aWidget,
                             uint32_t aOffset,
                             LayoutDeviceIntRect& aCharRect) const
 {
   aCharRect.SetEmpty();
 
+  if (NS_WARN_IF(mIsChrome)) {
+    return false;
+  }
+
   nsEventStatus status = nsEventStatus_eIgnore;
   WidgetQueryContentEvent textRect(true, NS_QUERY_TEXT_RECT, aWidget);
   textRect.InitForQueryTextRect(aOffset, 1);
   aWidget->DispatchEvent(&textRect, status);
   if (NS_WARN_IF(!textRect.mSucceeded)) {
     return false;
   }
   aCharRect = textRect.mReply.mRect;
@@ -745,16 +761,20 @@ ContentCache::OnCompositionEvent(const W
     ("ContentCache: 0x%p (mIsChrome=%s) OnCompositionEvent(aEvent={ "
      "message=%s, mData=\"%s\" (Length()=%u), mRanges->Length()=%u }), "
      "mIsComposing=%s, mRequestedToCommitOrCancelComposition=%s",
      this, GetBoolName(mIsChrome), GetEventMessageName(aEvent.message),
      NS_ConvertUTF16toUTF8(aEvent.mData).get(), aEvent.mData.Length(),
      aEvent.mRanges ? aEvent.mRanges->Length() : 0, GetBoolName(mIsComposing),
      GetBoolName(mRequestedToCommitOrCancelComposition)));
 
+  if (NS_WARN_IF(!mIsChrome)) {
+    return false;
+  }
+
   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++;
@@ -796,16 +816,20 @@ ContentCache::RequestToCommitComposition
     ("ContentCache: 0x%p (mIsChrome=%s) RequestToCommitComposition(aWidget=%p, "
      "aCancel=%s), mIsComposing=%s, mRequestedToCommitOrCancelComposition=%s, "
      "mCompositionEventsDuringRequest=%u",
      this, GetBoolName(mIsChrome), aWidget, GetBoolName(aCancel),
      GetBoolName(mIsComposing),
      GetBoolName(mRequestedToCommitOrCancelComposition),
      mCompositionEventsDuringRequest));
 
+  if (NS_WARN_IF(!mIsChrome)) {
+    return 0;
+  }
+
   mRequestedToCommitOrCancelComposition = true;
   mCompositionEventsDuringRequest = 0;
 
   aWidget->NotifyIME(IMENotification(aCancel ? REQUEST_TO_CANCEL_COMPOSITION :
                                                REQUEST_TO_COMMIT_COMPOSITION));
 
   mRequestedToCommitOrCancelComposition = false;
   aLastString = mCommitStringByRequest;
--- a/widget/ContentCache.h
+++ b/widget/ContentCache.h
@@ -21,41 +21,52 @@ class nsIWidget;
 
 namespace mozilla {
 
 namespace widget {
 struct IMENotification;
 }
 
 /**
- * ContentCache stores various information of the child content.  This hides
- * raw information but you can access more useful information with a lot of
- * methods.
+ * ContentCache stores various information of the child content both on
+ * PuppetWidget (child process) and TabParent (chrome process).
+ * When PuppetWidget receives some notifications of content state change,
+ * Cache*() are called.  Then, stored data is modified for the latest content
+ * in PuppetWidget.  After that, PuppetWidget sends the ContentCache to
+ * TabParent.  In this time, TabParent stores the latest content data with
+ * AssignContent().
  */
 
 class ContentCache final
 {
 public:
   typedef InfallibleTArray<LayoutDeviceIntRect> RectArray;
   typedef widget::IMENotification IMENotification;
 
   ContentCache();
 
+  /**
+   * When IME loses focus, this should be called and making this forget the
+   * content for reducing footprint.
+   * This must be called in content process.
+   */
   void Clear();
 
   /**
    * AssignContent() is called when TabParent receives ContentCache from
    * the content process.  This doesn't copy composition information because
    * it's managed by TabParent itself.
+   * This must be called in chrome process.
    */
   void AssignContent(const ContentCache& aOther,
                      const IMENotification* aNotification = nullptr);
 
   /**
    * HandleQueryContentEvent() sets content data to aEvent.mReply.
+   * This must be called in chrome process.
    *
    * For NS_QUERY_SELECTED_TEXT, fail if the cache doesn't contain the whole
    *  selected range. (This shouldn't happen because PuppetWidget should have
    *  already sent the whole selection.)
    *
    * For NS_QUERY_TEXT_CONTENT, fail only if the cache doesn't overlap with
    *  the queried range. Note the difference from above. We use
    *  this behavior because a normal NS_QUERY_TEXT_CONTENT event is allowed to
@@ -70,36 +81,41 @@ public:
    *
    * For NS_QUERY_EDITOR_RECT, always success
    */
   bool HandleQueryContentEvent(WidgetQueryContentEvent& aEvent,
                                nsIWidget* aWidget) const;
 
   /**
    * Cache*() retrieves the latest content information and store them.
+   * Be aware, CacheSelection() calls CacheTextRects(), and also CacheText()
+   * calls CacheSelection().  So, related data is also retrieved automatically.
+   * These methods must be called in content process.
    */
   bool CacheEditorRect(nsIWidget* aWidget,
                        const IMENotification* aNotification = nullptr);
   bool CacheSelection(nsIWidget* aWidget,
                       const IMENotification* aNotification = nullptr);
   bool CacheText(nsIWidget* aWidget,
                  const IMENotification* aNotification = nullptr);
 
   bool CacheAll(nsIWidget* aWidget,
                 const IMENotification* aNotification = nullptr);
 
   /**
    * OnCompositionEvent() should be called before sending composition string.
    * This returns true if the event should be sent.  Otherwise, false.
+   * This must be called in chrome process.
    */
   bool OnCompositionEvent(const WidgetCompositionEvent& aCompositionEvent);
   /**
    * RequestToCommitComposition() requests to commit or cancel composition to
    * the widget.  If it's handled synchronously, this returns the number of
    * composition events after that.
+   * This must be called in chrome process.
    *
    * @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.
    * @param aLastString The last composition string before requesting to
    *                    commit or cancel composition.
    * @return            The count of composition events ignored after a call of
@@ -111,31 +127,39 @@ public:
 
   /**
    * InitNotification() initializes aNotification with stored data.
    *
    * @param aNotification       Must be NOTIFY_IME_OF_SELECTION_CHANGE.
    */
   void InitNotification(IMENotification& aNotification) const;
 
+  /**
+   * SetSelection() modifies selection with specified raw data. And also this
+   * tries to retrieve text rects too.
+   * This must be called in content process.
+   */
   void SetSelection(nsIWidget* aWidget,
                     uint32_t aStartOffset,
                     uint32_t aLength,
                     bool aReversed,
                     const WritingMode& aWritingMode);
 
 private:
   // Whole text in the target
   nsString mText;
   // This is commit string which is caused by our request.
+  // This value is valid only in chrome process.
   nsString mCommitStringByRequest;
   // Start offset of the composition string.
+  // This value is valid only in chrome process.
   uint32_t mCompositionStart;
   // Count of composition events during requesting commit or cancel the
   // composition.
+  // This value is valid only in chrome process.
   uint32_t mCompositionEventsDuringRequest;
 
   struct Selection final
   {
     // Following values are offset in "flat text".
     uint32_t mAnchor;
     uint32_t mFocus;
 
@@ -237,17 +261,19 @@ private:
       return InRange(aOffset) && aOffset + aLength <= EndOffset();
     }
     LayoutDeviceIntRect GetRect(uint32_t aOffset) const;
     LayoutDeviceIntRect GetUnionRect(uint32_t aOffset, uint32_t aLength) const;
   } mTextRectArray;
 
   LayoutDeviceIntRect mEditorRect;
 
+  // mIsComposing is valid only in chrome process.
   bool mIsComposing;
+  // mRequestedToCommitOrCancelComposition is valid only in chrome process.
   bool mRequestedToCommitOrCancelComposition;
   bool mIsChrome;
 
   bool QueryCharRect(nsIWidget* aWidget,
                      uint32_t aOffset,
                      LayoutDeviceIntRect& aCharRect) const;
   bool CacheCaret(nsIWidget* aWidget,
                   const IMENotification* aNotification = nullptr);