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

@ -385,6 +385,18 @@ struct ParamTraits<nsLiteralCString> : ParamTraits<nsACString>
typedef nsLiteralCString paramType;
};
template <>
struct ParamTraits<nsDependentSubstring> : ParamTraits<nsAString>
{
typedef nsDependentSubstring paramType;
};
template <>
struct ParamTraits<nsDependentCSubstring> : ParamTraits<nsACString>
{
typedef nsDependentCSubstring paramType;
};
#ifdef MOZILLA_INTERNAL_API
template<>

View file

@ -36,6 +36,8 @@ Types = (
'nsresult',
'nsString',
'nsCString',
'nsDependentSubstring',
'nsDependentCSubstring',
'mozilla::ipc::Shmem',
'mozilla::ipc::FileDescriptor'
)

View file

@ -35,7 +35,7 @@ parent:
async AppData(SerializedLoadContext loadContext, PBrowserOrId browser);
// methods corresponding to those of nsIWyciwygChannel
async WriteToCacheEntry(nsString data);
async WriteToCacheEntry(nsDependentSubstring data);
async CloseCacheEntry(nsresult reason);
async SetCharsetAndSource(int32_t source, nsCString charset);
async SetSecurityInfo(nsCString securityInfo);

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

View file

@ -213,7 +213,7 @@ WyciwygChannelParent::RecvAsyncOpen(const URIParams& aOriginal,
}
bool
WyciwygChannelParent::RecvWriteToCacheEntry(const nsString& data)
WyciwygChannelParent::RecvWriteToCacheEntry(const nsDependentSubstring& data)
{
if (!mReceivedAppData) {
printf_stderr("WyciwygChannelParent::RecvWriteToCacheEntry: FATAL ERROR: didn't receive app data\n");

View file

@ -45,7 +45,7 @@ protected:
const uint32_t& loadFlags,
const IPC::SerializedLoadContext& loadContext,
const PBrowserOrId &parent) override;
virtual bool RecvWriteToCacheEntry(const nsString& data) override;
virtual bool RecvWriteToCacheEntry(const nsDependentSubstring& data) override;
virtual bool RecvCloseCacheEntry(const nsresult& reason) override;
virtual bool RecvSetCharsetAndSource(const int32_t& source,
const nsCString& charset) override;