Bug 1503588 - Remove aDataLen parameter from nsITransferable.getAnyTransferData. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D10441

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Schuster 2018-11-02 11:02:25 +00:00
Родитель b5693d09ca
Коммит 8c1f89b6e5
9 изменённых файлов: 60 добавлений и 60 удалений

Просмотреть файл

@ -528,7 +528,7 @@ DownloadsPlacesView.prototype = {
// Getting the data or creating the nsIURI might fail.
try {
let data = {};
trans.getAnyTransferData({}, data, {});
trans.getAnyTransferData({}, data);
let [url, name] = data.value.QueryInterface(Ci.nsISupportsString)
.data.split("\n");
if (url) {

Просмотреть файл

@ -450,7 +450,7 @@ var DownloadsPanel = {
// Getting the data or creating the nsIURI might fail
try {
let data = {};
trans.getAnyTransferData({}, data, {});
trans.getAnyTransferData({}, data);
let [url, name] = data.value
.QueryInterface(Ci.nsISupportsString)
.data

Просмотреть файл

@ -347,7 +347,7 @@ PlacesController.prototype = {
try {
// getAnyTransferData will throw if no data is available.
var data = { }, type = { };
xferable.getAnyTransferData(type, data, { });
xferable.getAnyTransferData(type, data);
data = data.value.QueryInterface(Ci.nsISupportsString).data;
if (type.value != PlacesUtils.TYPE_X_MOZ_URL &&
type.value != PlacesUtils.TYPE_UNICODE)
@ -1135,7 +1135,7 @@ PlacesController.prototype = {
// Now get the clipboard contents, in the best available flavor.
let data = {}, type = {}, items = [];
try {
xferable.getAnyTransferData(type, data, {});
xferable.getAnyTransferData(type, data);
data = data.value.QueryInterface(Ci.nsISupportsString).data;
type = type.value;
items = PlacesUtils.unwrapNodes(data, type);

Просмотреть файл

@ -1227,6 +1227,28 @@ HTMLEditor::InsertObject(const nsACString& aType,
return NS_OK;
}
static bool
GetString(nsISupports* aData, nsAString& aText)
{
if (nsCOMPtr<nsISupportsString> str = do_QueryInterface(aData)) {
str->GetData(aText);
return !aText.IsEmpty();
}
return false;
}
static bool
GetCString(nsISupports* aData, nsACString& aText)
{
if (nsCOMPtr<nsISupportsCString> str = do_QueryInterface(aData)) {
str->GetData(aText);
return !aText.IsEmpty();
}
return false;
}
nsresult
HTMLEditor::InsertFromTransferable(nsITransferable* transferable,
nsIDocument* aSourceDoc,
@ -1238,15 +1260,12 @@ HTMLEditor::InsertFromTransferable(nsITransferable* transferable,
nsresult rv = NS_OK;
nsAutoCString bestFlavor;
nsCOMPtr<nsISupports> genericDataObj;
uint32_t len = 0;
if (NS_SUCCEEDED(
transferable->GetAnyTransferData(bestFlavor,
getter_AddRefs(genericDataObj),
&len))) {
getter_AddRefs(genericDataObj)))) {
AutoTransactionsConserveSelection dontChangeMySelection(*this);
nsAutoString flavor;
CopyASCIItoUTF16(bestFlavor, flavor);
nsAutoString stuffToPaste;
bool isSafe = IsSafeToInsertData(aSourceDoc);
if (bestFlavor.EqualsLiteral(kFileMime) ||
@ -1257,12 +1276,9 @@ HTMLEditor::InsertFromTransferable(nsITransferable* transferable,
rv = InsertObject(bestFlavor, genericDataObj, isSafe,
aSourceDoc, nullptr, 0, aDoDeleteSelection);
} else if (bestFlavor.EqualsLiteral(kNativeHTMLMime)) {
// note cf_html uses utf8, hence use length = len, not len/2 as in flavors below
nsCOMPtr<nsISupportsCString> textDataObj = do_QueryInterface(genericDataObj);
if (textDataObj && len > 0) {
nsAutoCString cfhtml;
textDataObj->GetData(cfhtml);
NS_ASSERTION(cfhtml.Length() <= (len), "Invalid length!");
// note cf_html uses utf8
nsAutoCString cfhtml;
if (GetCString(genericDataObj, cfhtml)) {
nsString cfcontext, cffragment, cfselection; // cfselection left emtpy for now
rv = ParseCFHTML(cfhtml, getter_Copies(cffragment), getter_Copies(cfcontext));
@ -1300,19 +1316,11 @@ HTMLEditor::InsertFromTransferable(nsITransferable* transferable,
if (bestFlavor.EqualsLiteral(kHTMLMime) ||
bestFlavor.EqualsLiteral(kUnicodeMime) ||
bestFlavor.EqualsLiteral(kMozTextInternal)) {
nsCOMPtr<nsISupportsString> textDataObj = do_QueryInterface(genericDataObj);
if (textDataObj && len > 0) {
nsAutoString text;
textDataObj->GetData(text);
NS_ASSERTION(text.Length() <= (len/2), "Invalid length!");
stuffToPaste.Assign(text.get(), len / 2);
} else {
nsCOMPtr<nsISupportsCString> textDataObj(do_QueryInterface(genericDataObj));
if (textDataObj && len > 0) {
nsAutoCString text;
textDataObj->GetData(text);
NS_ASSERTION(text.Length() <= len, "Invalid length!");
stuffToPaste.Assign(NS_ConvertUTF8toUTF16(Substring(text, 0, len)));
nsAutoString stuffToPaste;
if (!GetString(genericDataObj, stuffToPaste)) {
nsAutoCString text;
if (GetCString(genericDataObj, text)) {
CopyUTF8toUTF16(text, stuffToPaste);
}
}
@ -1817,17 +1825,13 @@ HTMLEditor::PasteAsPlaintextQuotation(int32_t aSelectionType)
// it still owns the data, we just have a pointer to it.
// If it can't support a "text" output of the data the call will fail
nsCOMPtr<nsISupports> genericDataObj;
uint32_t len = 0;
nsAutoCString flav;
rv = trans->GetAnyTransferData(flav, getter_AddRefs(genericDataObj), &len);
rv = trans->GetAnyTransferData(flav, getter_AddRefs(genericDataObj));
NS_ENSURE_SUCCESS(rv, rv);
if (flav.EqualsLiteral(kUnicodeMime)) {
nsCOMPtr<nsISupportsString> textDataObj = do_QueryInterface(genericDataObj);
if (textDataObj && len > 0) {
nsAutoString stuffToPaste;
textDataObj->GetData(stuffToPaste);
NS_ASSERTION(stuffToPaste.Length() <= (len/2), "Invalid length!");
nsAutoString stuffToPaste;
if (GetString(genericDataObj, stuffToPaste)) {
AutoPlaceholderBatch treatAsOneTransaction(*this);
rv = InsertAsPlaintextQuotation(stuffToPaste, true, 0);
}

Просмотреть файл

@ -2106,10 +2106,8 @@ TextEditor::PasteAsQuotationAsAction(int32_t aClipboardType,
// it still owns the data, we just have a pointer to it.
// If it can't support a "text" output of the data the call will fail
nsCOMPtr<nsISupports> genericDataObj;
uint32_t len;
nsAutoCString flav;
rv = trans->GetAnyTransferData(flav, getter_AddRefs(genericDataObj),
&len);
rv = trans->GetAnyTransferData(flav, getter_AddRefs(genericDataObj));
if (NS_FAILED(rv)) {
return rv;
}
@ -2119,14 +2117,15 @@ TextEditor::PasteAsQuotationAsAction(int32_t aClipboardType,
return NS_OK;
}
nsCOMPtr<nsISupportsString> textDataObj = do_QueryInterface(genericDataObj);
if (textDataObj && len > 0) {
if (nsCOMPtr<nsISupportsString> text = do_QueryInterface(genericDataObj)) {
nsAutoString stuffToPaste;
textDataObj->GetData ( stuffToPaste );
AutoPlaceholderBatch treatAsOneTransaction(*this);
rv = InsertWithQuotationsAsSubAction(stuffToPaste);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
text->GetData(stuffToPaste);
if (!stuffToPaste.IsEmpty()) {
AutoPlaceholderBatch treatAsOneTransaction(*this);
rv = InsertWithQuotationsAsSubAction(stuffToPaste);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
}
return NS_OK;

Просмотреть файл

@ -107,20 +107,19 @@ TextEditor::InsertTextFromTransferable(nsITransferable* aTransferable)
nsresult rv = NS_OK;
nsAutoCString bestFlavor;
nsCOMPtr<nsISupports> genericDataObj;
uint32_t len = 0;
if (NS_SUCCEEDED(
aTransferable->GetAnyTransferData(bestFlavor,
getter_AddRefs(genericDataObj),
&len)) &&
getter_AddRefs(genericDataObj))) &&
(bestFlavor.EqualsLiteral(kUnicodeMime) ||
bestFlavor.EqualsLiteral(kMozTextInternal))) {
AutoTransactionsConserveSelection dontChangeMySelection(*this);
nsCOMPtr<nsISupportsString> textDataObj ( do_QueryInterface(genericDataObj) );
if (textDataObj && len > 0) {
nsAutoString stuffToPaste;
textDataObj->GetData(stuffToPaste);
NS_ASSERTION(stuffToPaste.Length() <= (len/2), "Invalid length!");
nsAutoString stuffToPaste;
if (nsCOMPtr<nsISupportsString> text = do_QueryInterface(genericDataObj)) {
text->GetData(stuffToPaste);
}
if (!stuffToPaste.IsEmpty()) {
// Sanitize possible carriage returns in the string to be inserted
nsContentUtils::PlatformToDOMLineBreaks(stuffToPaste);

Просмотреть файл

@ -140,10 +140,8 @@ interface nsITransferable : nsISupports
*
* @param aFlavor (out parameter) the flavor of data that was retrieved
* @param aData the data. Some variant of class in nsISupportsPrimitives.idl
* @param aDataLen the length of the data
*/
void getAnyTransferData ( out ACString aFlavor, out nsISupports aData,
out unsigned long aDataLen ) ;
void getAnyTransferData(out ACString aFlavor, out nsISupports aData);
///////////////////////////////
// Setter part of interface

Просмотреть файл

@ -323,8 +323,7 @@ nsTransferable::GetTransferData(const char* aFlavor,
//
NS_IMETHODIMP
nsTransferable::GetAnyTransferData(nsACString& aFlavor,
nsISupports** aData,
uint32_t* aDataLen)
nsISupports** aData)
{
MOZ_ASSERT(mInitialized);
@ -332,7 +331,8 @@ nsTransferable::GetAnyTransferData(nsACString& aFlavor,
DataStruct& data = mDataArray.ElementAt(i);
if (data.IsDataAvailable()) {
aFlavor.Assign(data.GetFlavor());
data.GetData(aData, aDataLen);
uint32_t dataLen;
data.GetData(aData, &dataLen);
return NS_OK;
}
}

Просмотреть файл

@ -58,8 +58,8 @@ function runImageClipboardTests(aCBSvc, aImageType)
xfer.addDataFlavor(aImageType);
aCBSvc.getData(xfer, knsIClipboard.kGlobalClipboard);
var typeObj = {}, dataObj = {}, lenObj = {};
xfer.getAnyTransferData(typeObj, dataObj, lenObj);
var typeObj = {}, dataObj = {};
xfer.getAnyTransferData(typeObj, dataObj);
var gotValue = (null != dataObj.value);
ok(gotValue, aImageType + " - getData() returned a value");
if (gotValue)