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
--- 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);