зеркало из https://github.com/mozilla/gecko-dev.git
Bug 571074 - Mark nsITransferable.getTransferData as [must_use]. r=mats
Differential Revision: https://phabricator.services.mozilla.com/D13454 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
13fc0d95f9
Коммит
891f0040e6
|
@ -241,7 +241,9 @@ nsContentAreaDragDropDataProvider::GetFlavorData(nsITransferable *aTransferable,
|
|||
// get the URI from the kFilePromiseURLMime flavor
|
||||
NS_ENSURE_ARG(aTransferable);
|
||||
nsCOMPtr<nsISupports> tmp;
|
||||
aTransferable->GetTransferData(kFilePromiseURLMime, getter_AddRefs(tmp));
|
||||
rv = aTransferable->GetTransferData(kFilePromiseURLMime,
|
||||
getter_AddRefs(tmp));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsISupportsString> supportsString =
|
||||
do_QueryInterface(tmp);
|
||||
if (!supportsString)
|
||||
|
@ -256,8 +258,9 @@ nsContentAreaDragDropDataProvider::GetFlavorData(nsITransferable *aTransferable,
|
|||
rv = NS_NewURI(getter_AddRefs(sourceURI), sourceURLString);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aTransferable->GetTransferData(kFilePromiseDestFilename,
|
||||
getter_AddRefs(tmp));
|
||||
rv = aTransferable->GetTransferData(kFilePromiseDestFilename,
|
||||
getter_AddRefs(tmp));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
supportsString = do_QueryInterface(tmp);
|
||||
if (!supportsString)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -275,8 +278,9 @@ nsContentAreaDragDropDataProvider::GetFlavorData(nsITransferable *aTransferable,
|
|||
// because sandboxing blocks access to MIME-handler info from
|
||||
// content processes.
|
||||
if (XRE_IsParentProcess()) {
|
||||
aTransferable->GetTransferData(kImageRequestMime,
|
||||
getter_AddRefs(tmp));
|
||||
rv = aTransferable->GetTransferData(kImageRequestMime,
|
||||
getter_AddRefs(tmp));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
supportsString = do_QueryInterface(tmp);
|
||||
if (!supportsString)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -324,8 +328,9 @@ nsContentAreaDragDropDataProvider::GetFlavorData(nsITransferable *aTransferable,
|
|||
// get the target directory from the kFilePromiseDirectoryMime
|
||||
// flavor
|
||||
nsCOMPtr<nsISupports> dirPrimitive;
|
||||
aTransferable->GetTransferData(kFilePromiseDirectoryMime,
|
||||
getter_AddRefs(dirPrimitive));
|
||||
rv = aTransferable->GetTransferData(kFilePromiseDirectoryMime,
|
||||
getter_AddRefs(dirPrimitive));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIFile> destDirectory = do_QueryInterface(dirPrimitive);
|
||||
if (!destDirectory)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
|
@ -8110,7 +8110,10 @@ nsContentUtils::TransferableToIPCTransferable(nsITransferable* aTransferable,
|
|||
}
|
||||
|
||||
nsCOMPtr<nsISupports> data;
|
||||
aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(data));
|
||||
if (NS_FAILED(aTransferable->GetTransferData(flavorStr.get(),
|
||||
getter_AddRefs(data)))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupportsString> text = do_QueryInterface(data);
|
||||
nsCOMPtr<nsISupportsCString> ctext = do_QueryInterface(data);
|
||||
|
|
|
@ -1595,8 +1595,11 @@ HTMLEditor::PasteInternal(int32_t aClipboardType,
|
|||
contextTransferable->Init(nullptr);
|
||||
contextTransferable->AddDataFlavor(kHTMLContext);
|
||||
clipboard->GetData(contextTransferable, aClipboardType);
|
||||
contextTransferable->GetTransferData(kHTMLContext,
|
||||
getter_AddRefs(contextDataObj));
|
||||
rv = contextTransferable->GetTransferData(kHTMLContext,
|
||||
getter_AddRefs(contextDataObj));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsITransferable> infoTransferable =
|
||||
do_CreateInstance("@mozilla.org/widget/transferable;1");
|
||||
|
@ -1606,8 +1609,11 @@ HTMLEditor::PasteInternal(int32_t aClipboardType,
|
|||
infoTransferable->Init(nullptr);
|
||||
infoTransferable->AddDataFlavor(kHTMLInfo);
|
||||
clipboard->GetData(infoTransferable, aClipboardType);
|
||||
infoTransferable->GetTransferData(kHTMLInfo,
|
||||
getter_AddRefs(infoDataObj));
|
||||
rv = infoTransferable->GetTransferData(kHTMLInfo,
|
||||
getter_AddRefs(infoDataObj));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (contextDataObj) {
|
||||
textDataObj = do_QueryInterface(contextDataObj);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "mozilla/ArrayUtils.h"
|
||||
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
@ -6256,8 +6257,8 @@ provideDataForType:(NSString*)aType
|
|||
// Now request the kFilePromiseMime data, which will invoke the data
|
||||
// provider. If successful, the file will have been created.
|
||||
nsCOMPtr<nsISupports> fileDataPrimitive;
|
||||
item->GetTransferData(kFilePromiseMime,
|
||||
getter_AddRefs(fileDataPrimitive));
|
||||
Unused << item->GetTransferData(kFilePromiseMime,
|
||||
getter_AddRefs(fileDataPrimitive));
|
||||
}
|
||||
CFRelease(urlRef);
|
||||
CFRelease(pboardRef);
|
||||
|
|
|
@ -562,7 +562,10 @@ nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable)
|
|||
flavorStr.EqualsLiteral(kJPGImageMime) || flavorStr.EqualsLiteral(kGIFImageMime) ||
|
||||
flavorStr.EqualsLiteral(kNativeImageMime)) {
|
||||
nsCOMPtr<nsISupports> transferSupports;
|
||||
aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(transferSupports));
|
||||
rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(transferSupports));
|
||||
if (NS_FAILED(rv)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nsCOMPtr<imgIContainer> image(do_QueryInterface(transferSupports));
|
||||
if (!image) {
|
||||
|
|
|
@ -482,8 +482,9 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard,
|
|||
// the transferable for this clipboard and try to get the
|
||||
// text/unicode type for it.
|
||||
rv = trans->GetTransferData("text/unicode", getter_AddRefs(item));
|
||||
if (!item || NS_FAILED(rv))
|
||||
if (NS_FAILED(rv) || !item) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupportsString> wideString;
|
||||
wideString = do_QueryInterface(item);
|
||||
|
@ -533,7 +534,7 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard,
|
|||
|
||||
if (selectionTarget == gdk_atom_intern(kHTMLMime, FALSE)) {
|
||||
rv = trans->GetTransferData(kHTMLMime, getter_AddRefs(item));
|
||||
if (!item || NS_FAILED(rv)) {
|
||||
if (NS_FAILED(rv) || !item) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -564,7 +565,7 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard,
|
|||
|
||||
rv = trans->GetTransferData(target_name, getter_AddRefs(item));
|
||||
// nothing found?
|
||||
if (!item || NS_FAILED(rv)) {
|
||||
if (NS_FAILED(rv) || !item) {
|
||||
g_free(target_name);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1739,11 +1739,16 @@ nsDragService::SourceBeginDrag(GdkDragContext *aContext)
|
|||
for (uint32_t i = 0; i < flavors.Length(); ++i) {
|
||||
if (flavors[i].EqualsLiteral(kFilePromiseDestFilename)) {
|
||||
nsCOMPtr<nsISupports> data;
|
||||
transferable->GetTransferData(kFilePromiseDestFilename,
|
||||
getter_AddRefs(data));
|
||||
nsCOMPtr<nsISupportsString> fileName = do_QueryInterface(data);
|
||||
if (!fileName)
|
||||
rv = transferable->GetTransferData(kFilePromiseDestFilename,
|
||||
getter_AddRefs(data));
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupportsString> fileName = do_QueryInterface(data);
|
||||
if (!fileName) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoString fileNameStr;
|
||||
fileName->GetData(fileNameStr);
|
||||
|
|
|
@ -131,7 +131,7 @@ interface nsITransferable : nsISupports
|
|||
* @param aData the data. Some variant of class in nsISupportsPrimitives.idl
|
||||
* @param aDataLen the length of the data
|
||||
*/
|
||||
void getTransferData(in string aFlavor, out nsISupports aData);
|
||||
[must_use] void getTransferData(in string aFlavor, out nsISupports aData);
|
||||
|
||||
/**
|
||||
* Returns the best flavor in the transferable, given those that have
|
||||
|
|
|
@ -897,65 +897,67 @@ nsDataObj::GetDib(const nsACString& inFlavor,
|
|||
FORMATETC &aFormat,
|
||||
STGMEDIUM & aSTG)
|
||||
{
|
||||
ULONG result = E_FAIL;
|
||||
nsCOMPtr<nsISupports> genericDataWrapper;
|
||||
mTransferable->GetTransferData(PromiseFlatCString(inFlavor).get(), getter_AddRefs(genericDataWrapper));
|
||||
nsCOMPtr<imgIContainer> image ( do_QueryInterface(genericDataWrapper) );
|
||||
if ( image ) {
|
||||
nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
|
||||
|
||||
nsAutoString options;
|
||||
if (aFormat.cfFormat == CF_DIBV5) {
|
||||
options.AppendLiteral("version=5");
|
||||
} else {
|
||||
options.AppendLiteral("version=3");
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
nsresult rv = imgTools->EncodeImage(image, NS_LITERAL_CSTRING(IMAGE_BMP),
|
||||
options, getter_AddRefs(inputStream));
|
||||
if (NS_FAILED(rv) || !inputStream) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
nsCOMPtr<imgIEncoder> encoder = do_QueryInterface(inputStream);
|
||||
if (!encoder) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
uint32_t size = 0;
|
||||
rv = encoder->GetImageBufferUsed(&size);
|
||||
if (NS_FAILED(rv) || size <= BFH_LENGTH) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
char *src = nullptr;
|
||||
rv = encoder->GetImageBuffer(&src);
|
||||
if (NS_FAILED(rv) || !src) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
// We don't want the file header.
|
||||
src += BFH_LENGTH;
|
||||
size -= BFH_LENGTH;
|
||||
|
||||
HGLOBAL glob = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, size);
|
||||
if (!glob) {
|
||||
DWORD err = ::GetLastError();
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
char *dst = (char*) ::GlobalLock(glob);
|
||||
::CopyMemory(dst, src, size);
|
||||
::GlobalUnlock(glob);
|
||||
|
||||
aSTG.hGlobal = glob;
|
||||
aSTG.tymed = TYMED_HGLOBAL;
|
||||
result = S_OK;
|
||||
} else {
|
||||
NS_WARNING ( "Definitely not an image on clipboard" );
|
||||
if (NS_FAILED(mTransferable->GetTransferData(PromiseFlatCString(inFlavor).get(),
|
||||
getter_AddRefs(genericDataWrapper)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
return result;
|
||||
|
||||
nsCOMPtr<imgIContainer> image = do_QueryInterface(genericDataWrapper);
|
||||
if (!image) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
nsCOMPtr<imgITools> imgTools = do_CreateInstance("@mozilla.org/image/tools;1");
|
||||
|
||||
nsAutoString options;
|
||||
if (aFormat.cfFormat == CF_DIBV5) {
|
||||
options.AppendLiteral("version=5");
|
||||
} else {
|
||||
options.AppendLiteral("version=3");
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
nsresult rv = imgTools->EncodeImage(image, NS_LITERAL_CSTRING(IMAGE_BMP),
|
||||
options, getter_AddRefs(inputStream));
|
||||
if (NS_FAILED(rv) || !inputStream) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
nsCOMPtr<imgIEncoder> encoder = do_QueryInterface(inputStream);
|
||||
if (!encoder) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
uint32_t size = 0;
|
||||
rv = encoder->GetImageBufferUsed(&size);
|
||||
if (NS_FAILED(rv) || size <= BFH_LENGTH) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
char *src = nullptr;
|
||||
rv = encoder->GetImageBuffer(&src);
|
||||
if (NS_FAILED(rv) || !src) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
// We don't want the file header.
|
||||
src += BFH_LENGTH;
|
||||
size -= BFH_LENGTH;
|
||||
|
||||
HGLOBAL glob = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, size);
|
||||
if (!glob) {
|
||||
DWORD err = ::GetLastError();
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
char *dst = (char*) ::GlobalLock(glob);
|
||||
::CopyMemory(dst, src, size);
|
||||
::GlobalUnlock(glob);
|
||||
|
||||
aSTG.hGlobal = glob;
|
||||
aSTG.tymed = TYMED_HGLOBAL;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1374,9 +1376,11 @@ HRESULT nsDataObj::GetText(const nsACString & aDataFlavor, FORMATETC& aFE, STGME
|
|||
|
||||
// NOTE: CreateDataFromPrimitive creates new memory, that needs to be deleted
|
||||
nsCOMPtr<nsISupports> genericDataWrapper;
|
||||
mTransferable->GetTransferData(flavorStr, getter_AddRefs(genericDataWrapper));
|
||||
if ( !genericDataWrapper )
|
||||
nsresult rv = mTransferable->GetTransferData(flavorStr,
|
||||
getter_AddRefs(genericDataWrapper));
|
||||
if (NS_FAILED(rv) || !genericDataWrapper) {
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
uint32_t len;
|
||||
nsPrimitiveHelpers::CreateDataFromPrimitive(
|
||||
|
@ -1484,7 +1488,9 @@ HRESULT nsDataObj::DropFile(FORMATETC& aFE, STGMEDIUM& aSTG)
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsISupports> genericDataWrapper;
|
||||
|
||||
mTransferable->GetTransferData(kFileMime, getter_AddRefs(genericDataWrapper));
|
||||
if (NS_FAILED(mTransferable->GetTransferData(kFileMime, getter_AddRefs(genericDataWrapper)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
nsCOMPtr<nsIFile> file ( do_QueryInterface(genericDataWrapper) );
|
||||
if (!file)
|
||||
return E_FAIL;
|
||||
|
@ -1537,7 +1543,10 @@ HRESULT nsDataObj::DropImage(FORMATETC& aFE, STGMEDIUM& aSTG)
|
|||
if (!mCachedTempFile) {
|
||||
nsCOMPtr<nsISupports> genericDataWrapper;
|
||||
|
||||
mTransferable->GetTransferData(kNativeImageMime, getter_AddRefs(genericDataWrapper));
|
||||
if (NS_FAILED(mTransferable->GetTransferData(kNativeImageMime,
|
||||
getter_AddRefs(genericDataWrapper)))) {
|
||||
return E_FAIL;
|
||||
}
|
||||
nsCOMPtr<imgIContainer> image(do_QueryInterface(genericDataWrapper));
|
||||
if (!image)
|
||||
return E_FAIL;
|
||||
|
@ -2096,7 +2105,8 @@ HRESULT nsDataObj::GetDownloadDetails(nsIURI **aSourceURI,
|
|||
|
||||
// get the URI from the kFilePromiseURLMime flavor
|
||||
nsCOMPtr<nsISupports> urlPrimitive;
|
||||
mTransferable->GetTransferData(kFilePromiseURLMime, getter_AddRefs(urlPrimitive));
|
||||
nsresult rv = mTransferable->GetTransferData(kFilePromiseURLMime, getter_AddRefs(urlPrimitive));
|
||||
NS_ENSURE_SUCCESS(rv, E_FAIL);
|
||||
nsCOMPtr<nsISupportsString> srcUrlPrimitive = do_QueryInterface(urlPrimitive);
|
||||
NS_ENSURE_TRUE(srcUrlPrimitive, E_FAIL);
|
||||
|
||||
|
@ -2109,7 +2119,8 @@ HRESULT nsDataObj::GetDownloadDetails(nsIURI **aSourceURI,
|
|||
|
||||
nsAutoString srcFileName;
|
||||
nsCOMPtr<nsISupports> fileNamePrimitive;
|
||||
mTransferable->GetTransferData(kFilePromiseDestFilename, getter_AddRefs(fileNamePrimitive));
|
||||
rv = mTransferable->GetTransferData(kFilePromiseDestFilename, getter_AddRefs(fileNamePrimitive));
|
||||
NS_ENSURE_SUCCESS(rv, E_FAIL);
|
||||
nsCOMPtr<nsISupportsString> srcFileNamePrimitive = do_QueryInterface(fileNamePrimitive);
|
||||
if (srcFileNamePrimitive) {
|
||||
srcFileNamePrimitive->GetData(srcFileName);
|
||||
|
|
Загрузка…
Ссылка в новой задаче