mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-10-30 15:58:03 +02:00
Revert "Bug 1966443: Use proper length for Windows clipboard elements r=win-reviewers,emilio,gstoll" for causing Bug 1968744
This reverts commit cff2580bc6b540ff1bb9b890d9cf79c1bcc563a5.
This commit is contained in:
parent
4777da5f47
commit
b7be7bd4a6
1 changed files with 22 additions and 28 deletions
|
|
@ -578,7 +578,6 @@ NS_IMETHODIMP nsClipboard::SetNativeClipboardData(
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
/* static */
|
||||
nsresult nsClipboard::GetGlobalData(HGLOBAL aHGBL, void** aData,
|
||||
uint32_t* aLen) {
|
||||
MOZ_CLIPBOARD_LOG("%s", __FUNCTION__);
|
||||
|
|
@ -701,29 +700,6 @@ HRESULT nsClipboard::FillSTGMedium(IDataObject* aDataObject, UINT aFormat,
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Get the data out of the global data handle. The size we
|
||||
// return should be the size returned from GetGlobalData(), since the
|
||||
// string returned from Windows may have nulls inserted -- it may not
|
||||
// even be null-terminated. GetGlobalData adds bytes for null
|
||||
// termination to the buffer but they are not considered in the returned
|
||||
// byte count. We check and skip the last counted byte if it is a null
|
||||
// since Windows also appears to add null termination. See GetGlobalData.
|
||||
template <typename CharType>
|
||||
static nsresult GetCharDataFromGlobalData(STGMEDIUM& aStm, CharType** aData,
|
||||
uint32_t* aLen) {
|
||||
uint32_t nBytes = 0;
|
||||
MOZ_TRY(nsClipboard::GetGlobalData(aStm.hGlobal,
|
||||
reinterpret_cast<void**>(aData), &nBytes));
|
||||
auto nChars = nBytes / sizeof(CharType);
|
||||
if (nChars < 1) {
|
||||
*aLen = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
bool hasNullTerminator = (*aData)[nChars - 1] == CharType(0);
|
||||
*aLen = hasNullTerminator ? nBytes - sizeof(CharType) : nBytes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If aFormat is CF_DIBV5, aMIMEImageFormat must be a type for which we have
|
||||
// an image encoder (e.g. image/png).
|
||||
// For other values of aFormat, it is OK to pass null for aMIMEImageFormat.
|
||||
|
|
@ -788,13 +764,31 @@ nsresult nsClipboard::GetNativeDataOffClipboard(IDataObject* aDataObject,
|
|||
// compile-time-constant format indicators:
|
||||
switch (fe.cfFormat) {
|
||||
case CF_TEXT: {
|
||||
return GetCharDataFromGlobalData(stm, reinterpret_cast<char**>(aData),
|
||||
aLen);
|
||||
// Get the data out of the global data handle. The size we
|
||||
// return should not include the null because the other
|
||||
// platforms don't use nulls, so just return the length we get
|
||||
// back from strlen(), since we know CF_TEXT is null
|
||||
// terminated. Recall that GetGlobalData() returns the size of
|
||||
// the allocated buffer, not the size of the data (on 98, these
|
||||
// are not the same) so we can't use that.
|
||||
uint32_t allocLen = 0;
|
||||
MOZ_TRY(GetGlobalData(stm.hGlobal, aData, &allocLen));
|
||||
*aLen = strlen(reinterpret_cast<char*>(*aData));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
case CF_UNICODETEXT: {
|
||||
return GetCharDataFromGlobalData(stm, reinterpret_cast<char16_t**>(aData),
|
||||
aLen);
|
||||
// Get the data out of the global data handle. The size we
|
||||
// return should not include the null because the other
|
||||
// platforms don't use nulls, so just return the length we get
|
||||
// back from strlen(), since we know CF_UNICODETEXT is null
|
||||
// terminated. Recall that GetGlobalData() returns the size of
|
||||
// the allocated buffer, not the size of the data (on 98, these
|
||||
// are not the same) so we can't use that.
|
||||
uint32_t allocLen = 0;
|
||||
MOZ_TRY(GetGlobalData(stm.hGlobal, aData, &allocLen));
|
||||
*aLen = NS_strlen(reinterpret_cast<char16_t*>(*aData)) * 2;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
case CF_DIBV5: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue