Split aData into smaller chunks to avoid going over the IPC message size limit (1335989).

This commit is contained in:
Fedor 2021-07-30 17:05:04 +03:00 committed by roytam1
commit e84c7ab0c3
6 changed files with 32 additions and 4 deletions

View file

@ -689,8 +689,22 @@ WyciwygChannelChild::WriteToCacheEntry(const nsAString & aData)
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(Substring(aData, curIndex, chunkSize));
charsRemaining -= chunkSize;
curIndex += chunkSize;
} while (charsRemaining != 0);
return NS_OK;
}