Bug 1310017 - Remove nsISupportsArray usage from nsITransferable and nsIFormatConverter. r=smaug

This converts |nsITransferable.flavorsTransferableCanExport| and
|nsITransferable.flavorsTransferableCanImport| to return a |nsIArray|.

|nsIFormatConverter.getInputDataFlavors| and
|nsIFormatConverter.getOutputDataFlavors| are updated as well.
This commit is contained in:
Eric Rahm 2016-10-16 12:43:56 -07:00
parent e1ceba9dc4
commit 52edf921c1
17 changed files with 123 additions and 159 deletions

View File

@ -67,6 +67,7 @@
#include "mozilla/Preferences.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/TextEvents.h"
#include "nsArrayUtils.h"
#include "nsAString.h"
#include "nsAttrName.h"
#include "nsAttrValue.h"
@ -7693,11 +7694,11 @@ nsContentUtils::TransferableToIPCTransferable(nsITransferable* aTransferable,
MOZ_ASSERT((aChild && !aParent) || (!aChild && aParent));
if (aTransferable) {
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
if (flavorList) {
uint32_t flavorCount = 0;
flavorList->Count(&flavorCount);
flavorList->GetLength(&flavorCount);
for (uint32_t j = 0; j < flavorCount; ++j) {
nsCOMPtr<nsISupportsCString> flavor = do_QueryElementAt(flavorList, j);
if (!flavor) {

View File

@ -18,6 +18,7 @@
#include "mozilla/TextEvents.h"
#include "mozilla/TouchEvents.h"
#include "nsArrayUtils.h"
#include "nsObjCExceptions.h"
#include "nsCOMPtr.h"
#include "nsToolkit.h"
@ -131,7 +132,7 @@ extern NSMenu* sApplicationMenu; // Application menu shared by all menubars
static bool gChildViewMethodsSwizzled = false;
extern nsISupportsArray *gDraggedTransferables;
extern nsIArray *gDraggedTransferables;
ChildView* ChildViewMouseTracker::sLastMouseEventView = nil;
NSEvent* ChildViewMouseTracker::sLastMouseMoveEvent = nil;
@ -5838,14 +5839,12 @@ PanGestureTypeForEvent(NSEvent* aEvent)
return nil;
uint32_t transferableCount;
rv = gDraggedTransferables->Count(&transferableCount);
rv = gDraggedTransferables->GetLength(&transferableCount);
if (NS_FAILED(rv))
return nil;
for (uint32_t i = 0; i < transferableCount; i++) {
nsCOMPtr<nsISupports> genericItem;
gDraggedTransferables->GetElementAt(i, getter_AddRefs(genericItem));
nsCOMPtr<nsITransferable> item(do_QueryInterface(genericItem));
nsCOMPtr<nsITransferable> item = do_QueryElementAt(gDraggedTransferables, i);
if (!item) {
NS_ERROR("no transferable");
return nil;

View File

@ -8,6 +8,7 @@
#include "mozilla/Unused.h"
#include "gfxPlatform.h"
#include "nsArrayUtils.h"
#include "nsCOMPtr.h"
#include "nsClipboard.h"
#include "nsString.h"
@ -146,18 +147,16 @@ nsClipboard::TransferableFromPasteboard(nsITransferable *aTransferable, NSPasteb
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
// get flavor list that includes all acceptable flavors (including ones obtained through conversion)
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
uint32_t flavorCount;
flavorList->Count(&flavorCount);
flavorList->GetLength(&flavorCount);
for (uint32_t i = 0; i < flavorCount; i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
if (!currentFlavor)
continue;
@ -317,13 +316,13 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, int32_t aWhi
return NS_ERROR_FAILURE;
// get flavor list that includes all acceptable flavors (including ones obtained through conversion)
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
uint32_t flavorCount;
flavorList->Count(&flavorCount);
flavorList->GetLength(&flavorCount);
// If we were the last ones to put something on the pasteboard, then just use the cached
// transferable. Otherwise clear it because it isn't relevant any more.
@ -331,9 +330,7 @@ nsClipboard::GetNativeClipboardData(nsITransferable* aTransferable, int32_t aWhi
mChangeCount == [cocoaPasteboard changeCount]) {
if (mTransferable) {
for (uint32_t i = 0; i < flavorCount; i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
if (!currentFlavor)
continue;
@ -375,15 +372,14 @@ nsClipboard::HasDataMatchingFlavors(const char** aFlavorList, uint32_t aLength,
// first see if we have data for this in our cached transferable
if (mTransferable) {
nsCOMPtr<nsISupportsArray> transferableFlavorList;
nsCOMPtr<nsIArray> transferableFlavorList;
nsresult rv = mTransferable->FlavorsTransferableCanImport(getter_AddRefs(transferableFlavorList));
if (NS_SUCCEEDED(rv)) {
uint32_t transferableFlavorCount;
transferableFlavorList->Count(&transferableFlavorCount);
transferableFlavorList->GetLength(&transferableFlavorCount);
for (uint32_t j = 0; j < transferableFlavorCount; j++) {
nsCOMPtr<nsISupports> transferableFlavorSupports;
transferableFlavorList->GetElementAt(j, getter_AddRefs(transferableFlavorSupports));
nsCOMPtr<nsISupportsCString> currentTransferableFlavor(do_QueryInterface(transferableFlavorSupports));
nsCOMPtr<nsISupportsCString> currentTransferableFlavor =
do_QueryElementAt(transferableFlavorList, j);
if (!currentTransferableFlavor)
continue;
nsXPIDLCString transferableFlavorStr;
@ -456,17 +452,15 @@ nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable)
NSMutableDictionary* pasteboardOutputDict = [NSMutableDictionary dictionary];
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
if (NS_FAILED(rv))
return nil;
uint32_t flavorCount;
flavorList->Count(&flavorCount);
flavorList->GetLength(&flavorCount);
for (uint32_t i = 0; i < flavorCount; i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
if (!currentFlavor)
continue;
@ -778,4 +772,4 @@ nsClipboard::SupportsSelectionClipboard(bool* _retval)
{
*_retval = false; // we don't support the selection clipboard by default.
return NS_OK;
}
}

View File

@ -6,6 +6,7 @@
#include "mozilla/Logging.h"
#include "nsDragService.h"
#include "nsArrayUtils.h"
#include "nsObjCExceptions.h"
#include "nsITransferable.h"
#include "nsString.h"
@ -387,13 +388,13 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex)
return NS_ERROR_FAILURE;
// get flavor list that includes all acceptable flavors (including ones obtained through conversion)
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
uint32_t acceptableFlavorCount;
flavorList->Count(&acceptableFlavorCount);
flavorList->GetLength(&acceptableFlavorCount);
// if this drag originated within Mozilla we should just use the cached data from
// when the drag started if possible
@ -404,9 +405,7 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex)
nsCOMPtr<nsITransferable> currentTransferable(do_QueryInterface(currentTransferableSupports));
if (currentTransferable) {
for (uint32_t i = 0; i < acceptableFlavorCount; i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
if (!currentFlavor)
continue;
nsXPIDLCString flavorStr;
@ -426,10 +425,7 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex)
// now check the actual clipboard for data
for (uint32_t i = 0; i < acceptableFlavorCount; i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(i, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
if (!currentFlavor)
continue;
@ -598,17 +594,15 @@ nsDragService::IsDataFlavorSupported(const char *aDataFlavor, bool *_retval)
if (!currentTransferable)
continue;
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
nsresult rv = currentTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
if (NS_FAILED(rv))
continue;
uint32_t flavorCount;
flavorList->Count(&flavorCount);
flavorList->GetLength(&flavorCount);
for (uint32_t j = 0; j < flavorCount; j++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt(j, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor(do_QueryInterface(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, j);
if (!currentFlavor)
continue;
nsXPIDLCString flavorStr;

View File

@ -11,6 +11,7 @@
#include "imgTools.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/Preferences.h"
#include "nsArrayUtils.h"
#include "nsClipboardProxy.h"
#include "nsISupportsPrimitives.h"
#include "nsComponentManagerUtils.h"
@ -73,14 +74,14 @@ nsClipboard::SetData(nsITransferable *aTransferable,
}
// Get the types of supported flavors.
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
if (!flavorList || NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
uint32_t flavorCount = 0;
flavorList->Count(&flavorCount);
flavorList->GetLength(&flavorCount);
bool imageAdded = false;
for (uint32_t i = 0; i < flavorCount; ++i) {
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
@ -203,7 +204,7 @@ nsClipboard::GetData(nsITransferable *aTransferable,
// ones obtained through conversion).
// Note: We don't need to call nsITransferable::AddDataFlavor here
// because ContentParent already did.
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
if (!flavorList || NS_FAILED(rv)) {
@ -212,7 +213,7 @@ nsClipboard::GetData(nsITransferable *aTransferable,
// Walk through flavors and see which flavor matches the one being pasted.
uint32_t flavorCount;
flavorList->Count(&flavorCount);
flavorList->GetLength(&flavorCount);
for (uint32_t i = 0; i < flavorCount; ++i) {
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);

View File

@ -7,6 +7,7 @@
#include "mozilla/ArrayUtils.h"
#include "nsArrayUtils.h"
#include "nsClipboard.h"
#include "nsSupportsPrimitives.h"
#include "nsString.h"
@ -158,7 +159,7 @@ nsClipboard::SetData(nsITransferable *aTransferable,
GtkTargetList *list = gtk_target_list_new(nullptr, 0);
// Get the types of supported flavors
nsCOMPtr<nsISupportsArray> flavors;
nsCOMPtr<nsIArray> flavors;
nsresult rv =
aTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavors));
@ -168,11 +169,9 @@ nsClipboard::SetData(nsITransferable *aTransferable,
// Add all the flavors to this widget's supported type.
bool imagesAdded = false;
uint32_t count;
flavors->Count(&count);
flavors->GetLength(&count);
for (uint32_t i=0; i < count; i++) {
nsCOMPtr<nsISupports> tastesLike;
flavors->GetElementAt(i, getter_AddRefs(tastesLike));
nsCOMPtr<nsISupportsCString> flavor = do_QueryInterface(tastesLike);
nsCOMPtr<nsISupportsCString> flavor = do_QueryElementAt(flavors, i);
if (flavor) {
nsXPIDLCString flavorStr;
@ -258,20 +257,17 @@ nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard)
nsAutoCString foundFlavor;
// Get a list of flavors this transferable can import
nsCOMPtr<nsISupportsArray> flavors;
nsCOMPtr<nsIArray> flavors;
nsresult rv;
rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavors));
if (!flavors || NS_FAILED(rv))
return NS_ERROR_FAILURE;
uint32_t count;
flavors->Count(&count);
flavors->GetLength(&count);
for (uint32_t i=0; i < count; i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavors->GetElementAt(i, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor;
currentFlavor = do_QueryInterface(genericFlavor);
currentFlavor = do_QueryElementAt(flavors, i);
if (currentFlavor) {
nsXPIDLCString flavorStr;

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsDragService.h"
#include "nsArrayUtils.h"
#include "nsIObserverService.h"
#include "nsWidgetsCID.h"
#include "nsWindow.h"
@ -703,7 +704,7 @@ nsDragService::GetData(nsITransferable * aTransferable,
// get flavor list that includes all acceptable flavors (including
// ones obtained through conversion). Flavors are nsISupportsStrings
// so that they can be seen from JS.
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
nsresult rv = aTransferable->FlavorsTransferableCanImport(
getter_AddRefs(flavorList));
if (NS_FAILED(rv))
@ -711,7 +712,7 @@ nsDragService::GetData(nsITransferable * aTransferable,
// count the number of flavors
uint32_t cnt;
flavorList->Count(&cnt);
flavorList->GetLength(&cnt);
unsigned int i;
// check to see if this is an internal list
@ -721,10 +722,8 @@ nsDragService::GetData(nsITransferable * aTransferable,
MOZ_LOG(sDragLm, LogLevel::Debug, ("it's a list..."));
// find a matching flavor
for (i = 0; i < cnt; ++i) {
nsCOMPtr<nsISupports> genericWrapper;
flavorList->GetElementAt(i, getter_AddRefs(genericWrapper));
nsCOMPtr<nsISupportsCString> currentFlavor;
currentFlavor = do_QueryInterface(genericWrapper);
currentFlavor = do_QueryElementAt(flavorList, i);
if (!currentFlavor)
continue;
@ -772,10 +771,8 @@ nsDragService::GetData(nsITransferable * aTransferable,
// actually present, copy out the data into the transferable in that
// format. SetTransferData() implicitly handles conversions.
for ( i = 0; i < cnt; ++i ) {
nsCOMPtr<nsISupports> genericWrapper;
flavorList->GetElementAt(i,getter_AddRefs(genericWrapper));
nsCOMPtr<nsISupportsCString> currentFlavor;
currentFlavor = do_QueryInterface(genericWrapper);
currentFlavor = do_QueryElementAt(flavorList, i);
if (currentFlavor) {
// find our gtk flavor
nsXPIDLCString flavorStr;
@ -1033,20 +1030,17 @@ nsDragService::IsDataFlavorSupported(const char *aDataFlavor,
getter_AddRefs(genericItem));
nsCOMPtr<nsITransferable> currItem(do_QueryInterface(genericItem));
if (currItem) {
nsCOMPtr <nsISupportsArray> flavorList;
nsCOMPtr <nsIArray> flavorList;
currItem->FlavorsTransferableCanExport(
getter_AddRefs(flavorList));
if (flavorList) {
uint32_t numFlavors;
flavorList->Count( &numFlavors );
flavorList->GetLength( &numFlavors );
for ( uint32_t flavorIndex = 0;
flavorIndex < numFlavors ;
++flavorIndex ) {
nsCOMPtr<nsISupports> genericWrapper;
flavorList->GetElementAt(flavorIndex,
getter_AddRefs(genericWrapper));
nsCOMPtr<nsISupportsCString> currentFlavor;
currentFlavor = do_QueryInterface(genericWrapper);
currentFlavor = do_QueryElementAt(flavorList, flavorIndex);
if (currentFlavor) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
@ -1274,19 +1268,16 @@ nsDragService::GetSourceList(void)
nsCOMPtr<nsITransferable> currItem(do_QueryInterface(genericItem));
if (currItem) {
nsCOMPtr <nsISupportsArray> flavorList;
nsCOMPtr <nsIArray> flavorList;
currItem->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
if (flavorList) {
uint32_t numFlavors;
flavorList->Count( &numFlavors );
flavorList->GetLength( &numFlavors );
for (uint32_t flavorIndex = 0;
flavorIndex < numFlavors ;
++flavorIndex ) {
nsCOMPtr<nsISupports> genericWrapper;
flavorList->GetElementAt(flavorIndex,
getter_AddRefs(genericWrapper));
nsCOMPtr<nsISupportsCString> currentFlavor;
currentFlavor = do_QueryInterface(genericWrapper);
currentFlavor = do_QueryElementAt(flavorList, flavorIndex);
if (currentFlavor) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
@ -1313,19 +1304,16 @@ nsDragService::GetSourceList(void)
mSourceDataItems->GetElementAt(0, getter_AddRefs(genericItem));
nsCOMPtr<nsITransferable> currItem(do_QueryInterface(genericItem));
if (currItem) {
nsCOMPtr <nsISupportsArray> flavorList;
nsCOMPtr <nsIArray> flavorList;
currItem->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
if (flavorList) {
uint32_t numFlavors;
flavorList->Count( &numFlavors );
flavorList->GetLength( &numFlavors );
for (uint32_t flavorIndex = 0;
flavorIndex < numFlavors ;
++flavorIndex ) {
nsCOMPtr<nsISupports> genericWrapper;
flavorList->GetElementAt(flavorIndex,
getter_AddRefs(genericWrapper));
nsCOMPtr<nsISupportsCString> currentFlavor;
currentFlavor = do_QueryInterface(genericWrapper);
currentFlavor = do_QueryElementAt(flavorList, flavorIndex);
if (currentFlavor) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));

View File

@ -8,7 +8,6 @@
#include "nsIServiceManager.h"
#include "nsITransferable.h"
#include "nsISupportsArray.h"
#include "nsSize.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"

View File

@ -4,6 +4,7 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/Unused.h"
#include "nsArrayUtils.h"
#include "nsClipboardProxy.h"
#include "nsISupportsPrimitives.h"
#include "nsCOMPtr.h"
@ -47,11 +48,11 @@ nsClipboardProxy::GetData(nsITransferable *aTransferable, int32_t aWhichClipboar
{
nsTArray<nsCString> types;
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList));
if (flavorList) {
uint32_t flavorCount = 0;
flavorList->Count(&flavorCount);
flavorList->GetLength(&flavorCount);
for (uint32_t j = 0; j < flavorCount; ++j) {
nsCOMPtr<nsISupportsCString> flavor = do_QueryElementAt(flavorList, j);
if (flavor) {

View File

@ -5,8 +5,8 @@
#include "nsHTMLFormatConverter.h"
#include "nsArray.h"
#include "nsCRT.h"
#include "nsISupportsArray.h"
#include "nsIComponentManager.h"
#include "nsCOMPtr.h"
#include "nsXPCOM.h"
@ -39,15 +39,15 @@ NS_IMPL_ISUPPORTS(nsHTMLFormatConverter, nsIFormatConverter)
// access them easily via XPConnect.
//
NS_IMETHODIMP
nsHTMLFormatConverter::GetInputDataFlavors(nsISupportsArray **_retval)
nsHTMLFormatConverter::GetInputDataFlavors(nsIArray **_retval)
{
if ( !_retval )
return NS_ERROR_INVALID_ARG;
nsresult rv = NS_NewISupportsArray ( _retval ); // addrefs for us
if ( NS_SUCCEEDED(rv) )
rv = AddFlavorToList ( *_retval, kHTMLMime );
nsCOMPtr<nsIMutableArray> array = nsArray::Create();
nsresult rv = AddFlavorToList ( array, kHTMLMime );
array.forget(_retval);
return rv;
} // GetInputDataFlavors
@ -64,28 +64,20 @@ nsHTMLFormatConverter::GetInputDataFlavors(nsISupportsArray **_retval)
// access them easily via XPConnect.
//
NS_IMETHODIMP
nsHTMLFormatConverter::GetOutputDataFlavors(nsISupportsArray **_retval)
nsHTMLFormatConverter::GetOutputDataFlavors(nsIArray **_retval)
{
if ( !_retval )
return NS_ERROR_INVALID_ARG;
nsresult rv = NS_NewISupportsArray ( _retval ); // addrefs for us
if ( NS_SUCCEEDED(rv) ) {
rv = AddFlavorToList ( *_retval, kHTMLMime );
if ( NS_FAILED(rv) )
return rv;
#if NOT_NOW
// pinkerton
// no one uses this flavor right now, so it's just slowing things down. If anyone cares I
// can put it back in.
rv = AddFlavorToList ( *_retval, kAOLMailMime );
if ( NS_FAILED(rv) )
return rv;
#endif
rv = AddFlavorToList ( *_retval, kUnicodeMime );
if ( NS_FAILED(rv) )
return rv;
}
nsCOMPtr<nsIMutableArray> array = nsArray::Create();
nsresult rv = AddFlavorToList ( array, kHTMLMime );
if ( NS_FAILED(rv) )
return rv;
rv = AddFlavorToList ( array, kUnicodeMime );
if ( NS_FAILED(rv) )
return rv;
array.forget(_retval);
return rv;
} // GetOutputDataFlavors
@ -98,7 +90,7 @@ nsHTMLFormatConverter::GetOutputDataFlavors(nsISupportsArray **_retval)
// to a list
//
nsresult
nsHTMLFormatConverter :: AddFlavorToList ( nsISupportsArray* inList, const char* inFlavor )
nsHTMLFormatConverter :: AddFlavorToList ( nsCOMPtr<nsIMutableArray>& inList, const char* inFlavor )
{
nsresult rv;
@ -109,7 +101,7 @@ nsHTMLFormatConverter :: AddFlavorToList ( nsISupportsArray* inList, const char*
// add to list as an nsISupports so the correct interface gets the addref
// in AppendElement()
nsCOMPtr<nsISupports> genericFlavor ( do_QueryInterface(dataFlavor) );
inList->AppendElement ( genericFlavor);
inList->AppendElement ( genericFlavor, /*weak =*/ false);
}
return rv;

View File

@ -6,9 +6,12 @@
#ifndef nsHTMLFormatConverter_h__
#define nsHTMLFormatConverter_h__
#include "nsCOMPtr.h"
#include "nsIFormatConverter.h"
#include "nsString.h"
class nsIMutableArray;
class nsHTMLFormatConverter : public nsIFormatConverter
{
public:
@ -22,7 +25,7 @@ public:
protected:
virtual ~nsHTMLFormatConverter();
nsresult AddFlavorToList ( nsISupportsArray* inList, const char* inFlavor ) ;
nsresult AddFlavorToList ( nsCOMPtr<nsIMutableArray>& inList, const char* inFlavor ) ;
NS_IMETHOD ConvertFromHTMLToUnicode(const nsAutoString & aFromStr, nsAutoString & aToStr);
NS_IMETHOD ConvertFromHTMLToAOLMail(const nsAutoString & aFromStr, nsAutoString & aToStr);

View File

@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
#include "nsISupportsArray.idl"
#include "nsIArray.idl"
[scriptable, uuid(948A0023-E3A7-11d2-96CF-0060B0FB9956)]
@ -15,7 +15,7 @@ interface nsIFormatConverter : nsISupports
* in otherwords, the flavors that this converter can convert "from" (the
* incoming data to the converter).
*/
nsISupportsArray getInputDataFlavors ( ) ;
nsIArray getInputDataFlavors ( ) ;
/**
* Get the list of the "output" data flavors (mime types as nsISupportsCString),
@ -24,7 +24,7 @@ interface nsIFormatConverter : nsISupports
*
* @param aDataFlavorList fills list with supported flavors
*/
nsISupportsArray getOutputDataFlavors ( ) ;
nsIArray getOutputDataFlavors ( ) ;
/**
* Determines whether a conversion from one flavor to another is supported

View File

@ -4,8 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsIArray.idl"
#include "nsISupports.idl"
#include "nsISupportsArray.idl"
#include "nsIFormatConverter.idl"
#include "nsIContentPolicyBase.idl"
@ -123,7 +123,7 @@ interface nsITransferable : nsISupports
* @param aDataFlavorList fills list with supported flavors. This is a copy of
* the internal list, so it may be edited w/out affecting the transferable.
*/
nsISupportsArray flavorsTransferableCanExport ( ) ;
nsIArray flavorsTransferableCanExport ( ) ;
/**
* Given a flavor retrieve the data.
@ -161,7 +161,7 @@ interface nsITransferable : nsISupports
* @param outFlavorList fills list with supported flavors. This is a copy of
* the internal list, so it may be edited w/out affecting the transferable.
*/
nsISupportsArray flavorsTransferableCanImport ( ) ;
nsIArray flavorsTransferableCanImport ( ) ;
/**
* Sets the data in the transferable with the specified flavor. The transferable

View File

@ -8,12 +8,14 @@ Notes to self:
- at some point, strings will be accessible from JS, so we won't have to wrap
flavors in an nsISupportsCString. Until then, we're kinda stuck with
this crappy API of nsISupportsArrays.
this crappy API of nsIArrays.
*/
#include "nsTransferable.h"
#include "nsArray.h"
#include "nsArrayUtils.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsTArray.h"
@ -260,13 +262,12 @@ nsTransferable::Init(nsILoadContext* aContext)
// account any converter that may be registered. This list consists of
// nsISupportsCString objects so that the flavor list can be accessed from JS.
//
nsresult
nsTransferable::GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList)
already_AddRefed<nsIMutableArray>
nsTransferable::GetTransferDataFlavors()
{
MOZ_ASSERT(mInitialized);
nsresult rv = NS_NewISupportsArray ( aDataFlavorList );
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIMutableArray> array = nsArray::Create();
for (size_t i = 0; i < mDataArray.Length(); ++i) {
DataStruct& data = mDataArray.ElementAt(i);
@ -274,11 +275,11 @@ nsTransferable::GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList)
if ( flavorWrapper ) {
flavorWrapper->SetData ( data.GetFlavor() );
nsCOMPtr<nsISupports> genericWrapper ( do_QueryInterface(flavorWrapper) );
(*aDataFlavorList)->AppendElement( genericWrapper );
array->AppendElement( genericWrapper, /*weak =*/ false );
}
}
return NS_OK;
return array.forget();
}
@ -528,7 +529,7 @@ NS_IMETHODIMP nsTransferable::GetConverter(nsIFormatConverter * *aConverter)
// intrinsic knowledge or input data converters.
//
NS_IMETHODIMP
nsTransferable::FlavorsTransferableCanImport(nsISupportsArray **_retval)
nsTransferable::FlavorsTransferableCanImport(nsIArray **_retval)
{
MOZ_ASSERT(mInitialized);
@ -537,32 +538,31 @@ nsTransferable::FlavorsTransferableCanImport(nsISupportsArray **_retval)
// Get the flavor list, and on to the end of it, append the list of flavors we
// can also get to through a converter. This is so that we can just walk the list
// in one go, looking for the desired flavor.
GetTransferDataFlavors(_retval); // addrefs
nsCOMPtr<nsIMutableArray> array = GetTransferDataFlavors();
nsCOMPtr<nsIFormatConverter> converter;
GetConverter(getter_AddRefs(converter));
if ( converter ) {
nsCOMPtr<nsISupportsArray> convertedList;
nsCOMPtr<nsIArray> convertedList;
converter->GetInputDataFlavors(getter_AddRefs(convertedList));
if ( convertedList ) {
uint32_t importListLen;
convertedList->Count(&importListLen);
convertedList->GetLength(&importListLen);
for (uint32_t i = 0; i < importListLen; ++i ) {
nsCOMPtr<nsISupports> genericFlavor;
convertedList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
nsCOMPtr<nsISupportsCString> flavorWrapper ( do_QueryInterface (genericFlavor) );
nsCOMPtr<nsISupportsCString> flavorWrapper =
do_QueryElementAt(convertedList, i);
nsAutoCString flavorStr;
flavorWrapper->GetData( flavorStr );
if (GetDataForFlavor (mDataArray, flavorStr.get())
== mDataArray.NoIndex) // Don't append if already in intrinsic list
(*_retval)->AppendElement (genericFlavor);
array->AppendElement (flavorWrapper, /*weak =*/ false);
} // foreach flavor that can be converted to
}
} // if a converter exists
array.forget(_retval);
return NS_OK;
} // FlavorsTransferableCanImport
@ -574,7 +574,7 @@ nsTransferable::FlavorsTransferableCanImport(nsISupportsArray **_retval)
// intrinsic knowledge or output data converters.
//
NS_IMETHODIMP
nsTransferable::FlavorsTransferableCanExport(nsISupportsArray **_retval)
nsTransferable::FlavorsTransferableCanExport(nsIArray **_retval)
{
MOZ_ASSERT(mInitialized);
@ -583,32 +583,31 @@ nsTransferable::FlavorsTransferableCanExport(nsISupportsArray **_retval)
// Get the flavor list, and on to the end of it, append the list of flavors we
// can also get to through a converter. This is so that we can just walk the list
// in one go, looking for the desired flavor.
GetTransferDataFlavors(_retval); // addrefs
nsCOMPtr<nsIMutableArray> array = GetTransferDataFlavors();
nsCOMPtr<nsIFormatConverter> converter;
GetConverter(getter_AddRefs(converter));
if ( converter ) {
nsCOMPtr<nsISupportsArray> convertedList;
nsCOMPtr<nsIArray> convertedList;
converter->GetOutputDataFlavors(getter_AddRefs(convertedList));
if ( convertedList ) {
uint32_t importListLen;
convertedList->Count(&importListLen);
convertedList->GetLength(&importListLen);
for ( uint32_t i=0; i < importListLen; ++i ) {
nsCOMPtr<nsISupports> genericFlavor;
convertedList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
nsCOMPtr<nsISupportsCString> flavorWrapper ( do_QueryInterface (genericFlavor) );
nsCOMPtr<nsISupportsCString> flavorWrapper =
do_QueryElementAt(convertedList, i);
nsAutoCString flavorStr;
flavorWrapper->GetData( flavorStr );
if (GetDataForFlavor (mDataArray, flavorStr.get())
== mDataArray.NoIndex) // Don't append if already in intrinsic list
(*_retval)->AppendElement (genericFlavor);
array->AppendElement (flavorWrapper, /*weak =*/ false);
} // foreach flavor that can be converted to
}
} // if a converter exists
array.forget(_retval);
return NS_OK;
} // FlavorsTransferableCanExport

View File

@ -14,6 +14,7 @@
#include "nsTArray.h"
#include "nsIPrincipal.h"
class nsIMutableArray;
class nsString;
//
@ -69,7 +70,7 @@ protected:
virtual ~nsTransferable();
// get flavors w/out converter
nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList);
already_AddRefed<nsIMutableArray> GetTransferDataFlavors();
nsTArray<DataStruct> mDataArray;
nsCOMPtr<nsIFormatConverter> mFormatConv;

View File

@ -11,6 +11,7 @@
// shellapi.h is needed to build with WIN32_LEAN_AND_MEAN
#include <shellapi.h>
#include "nsArrayUtils.h"
#include "nsCOMPtr.h"
#include "nsDataObj.h"
#include "nsIClipboardOwner.h"
@ -157,18 +158,16 @@ nsresult nsClipboard::SetupNativeDataObject(nsITransferable * aTransferable, IDa
dObj->SetTransferable(aTransferable);
// Get the transferable list of data flavors
nsCOMPtr<nsISupportsArray> dfList;
nsCOMPtr<nsIArray> dfList;
aTransferable->FlavorsTransferableCanExport(getter_AddRefs(dfList));
// Walk through flavors that contain data and register them
// into the DataObj as supported flavors
uint32_t i;
uint32_t cnt;
dfList->Count(&cnt);
dfList->GetLength(&cnt);
for (i=0;i<cnt;i++) {
nsCOMPtr<nsISupports> genericFlavor;
dfList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
nsCOMPtr<nsISupportsCString> currentFlavor ( do_QueryInterface(genericFlavor) );
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(dfList, i);
if ( currentFlavor ) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));
@ -591,7 +590,7 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject,
// get flavor list that includes all flavors that can be written (including ones
// obtained through conversion)
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
res = aTransferable->FlavorsTransferableCanImport ( getter_AddRefs(flavorList) );
if ( NS_FAILED(res) )
return NS_ERROR_FAILURE;
@ -599,11 +598,9 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject,
// Walk through flavors and see which flavor is on the clipboard them on the native clipboard,
uint32_t i;
uint32_t cnt;
flavorList->Count(&cnt);
flavorList->GetLength(&cnt);
for (i=0;i<cnt;i++) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt ( i, getter_AddRefs(genericFlavor) );
nsCOMPtr<nsISupportsCString> currentFlavor ( do_QueryInterface(genericFlavor) );
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
if ( currentFlavor ) {
nsXPIDLCString flavorStr;
currentFlavor->ToString(getter_Copies(flavorStr));

View File

@ -9,6 +9,7 @@
#include <shlobj.h>
#include "nsDataObj.h"
#include "nsArrayUtils.h"
#include "nsClipboard.h"
#include "nsReadableUtils.h"
#include "nsITransferable.h"
@ -1205,17 +1206,15 @@ bool nsDataObj :: IsFlavourPresent(const char *inFlavour)
NS_ENSURE_TRUE(mTransferable, false);
// get the list of flavors available in the transferable
nsCOMPtr<nsISupportsArray> flavorList;
nsCOMPtr<nsIArray> flavorList;
mTransferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList));
NS_ENSURE_TRUE(flavorList, false);
// try to find requested flavour
uint32_t cnt;
flavorList->Count(&cnt);
flavorList->GetLength(&cnt);
for (uint32_t i = 0; i < cnt; ++i) {
nsCOMPtr<nsISupports> genericFlavor;
flavorList->GetElementAt (i, getter_AddRefs(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor (do_QueryInterface(genericFlavor));
nsCOMPtr<nsISupportsCString> currentFlavor = do_QueryElementAt(flavorList, i);
if (currentFlavor) {
nsAutoCString flavorStr;
currentFlavor->GetData(flavorStr);