Bug 1335989 - Split aData into smaller chunks to avoid going over the IPC message size limit. r=billm draft
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 14 Feb 2017 15:27:06 -0800
changeset 484195 2979580ba0e787a89e52f0667eb2504b6fad8349
parent 483291 195049fabb7ac5709e5f75614ba630ba3d1b5a9b
child 484905 9355c5a630c6ec417ed6b9ea13b743f9b885e282
push id45418
push userbmo:mrbkap@mozilla.com
push dateTue, 14 Feb 2017 23:45:22 +0000
reviewersbillm
bugs1335989
milestone54.0a1
Bug 1335989 - Split aData into smaller chunks to avoid going over the IPC message size limit. r=billm Unfortunately, this copies each chunk twice (once for the PromiseFlatString and again for the message itself). At first blush it's hard to avoid the double copy, but it seems like we could make this better. MozReview-Commit-ID: F7ujVhUj596
netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
--- a/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
@@ -688,18 +688,32 @@ WyciwygChannelChild::WriteToCacheEntry(c
 
     PBrowserOrId browser = static_cast<ContentChild*>(Manager()->Manager())
                            ->GetBrowserOrId(tabChild);
 
     SendAppData(IPC::SerializedLoadContext(this), browser);
     mSentAppData = true;
   }
 
-  SendWriteToCacheEntry(PromiseFlatString(aData));
   mState = WCC_ONWRITE;
+
+  // Give ourselves a megabyte of headroom for the message size. Convert bytes
+  // to wide chars.
+  static const size_t kMaxMessageSize = (IPC::Channel::kMaximumMessageSize - 1024) / 2;
+
+  size_t curIndex = 0;
+  size_t charsRemaining = aData.Length();
+  do {
+    size_t chunkSize = std::min(charsRemaining, kMaxMessageSize);
+    SendWriteToCacheEntry(PromiseFlatString(Substring(aData, curIndex, chunkSize)));
+
+    charsRemaining -= chunkSize;
+    curIndex += chunkSize;
+  } while (charsRemaining != 0);
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 WyciwygChannelChild::CloseCacheEntry(nsresult reason)
 {
   NS_ENSURE_TRUE(mState == WCC_ONWRITE, NS_ERROR_UNEXPECTED);