Bug 1689827 - Remove length parameter from JS callers of setTransferData. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D103555
This commit is contained in:
Tom Schuster
2021-02-01 12:05:12 +00:00
parent 284007d949
commit f7d112c734
19 changed files with 27 additions and 40 deletions

View File

@@ -1439,11 +1439,7 @@ var PlacesUIUtils = {
function addData(type, data) {
xferable.addDataFlavor(type);
xferable.setTransferData(
type,
PlacesUtils.toISupportsString(data),
data.length * 2
);
xferable.setTransferData(type, PlacesUtils.toISupportsString(data));
}
contents.forEach(function(content) {

View File

@@ -1090,7 +1090,7 @@ PlacesController.prototype = {
// Empty transferables may cause crashes, so just add an unknown type.
const TYPE = "text/x-moz-place-empty";
xferable.addDataFlavor(TYPE);
xferable.setTransferData(TYPE, PlacesUtils.toISupportsString(""), 0);
xferable.setTransferData(TYPE, PlacesUtils.toISupportsString(""));
this.clipboard.setData(xferable, null, Ci.nsIClipboard.kGlobalClipboard);
},
@@ -1122,11 +1122,7 @@ PlacesController.prototype = {
function addData(type, data) {
xferable.addDataFlavor(type);
xferable.setTransferData(
type,
PlacesUtils.toISupportsString(data),
data.length * 2
);
xferable.setTransferData(type, PlacesUtils.toISupportsString(data));
}
let xferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(

View File

@@ -239,8 +239,7 @@ add_task(async function paste_from_different_instance() {
xferable.addDataFlavor(PlacesUtils.TYPE_X_MOZ_PLACE);
xferable.setTransferData(
PlacesUtils.TYPE_X_MOZ_PLACE,
PlacesUtils.toISupportsString(data),
data.length * 2
PlacesUtils.toISupportsString(data)
);
Services.clipboard.setData(xferable, null, Ci.nsIClipboard.kGlobalClipboard);
@@ -289,8 +288,7 @@ add_task(async function paste_separator_from_different_instance() {
xferable.addDataFlavor(PlacesUtils.TYPE_X_MOZ_PLACE);
xferable.setTransferData(
PlacesUtils.TYPE_X_MOZ_PLACE,
PlacesUtils.toISupportsString(data),
data.length * 2
PlacesUtils.toISupportsString(data)
);
Services.clipboard.setData(xferable, null, Ci.nsIClipboard.kGlobalClipboard);

View File

@@ -378,7 +378,7 @@ function copyImageToClipboard(data) {
);
xferable.init(null);
xferable.addDataFlavor("image/png");
xferable.setTransferData("image/png", imgPtr, -1);
xferable.setTransferData("image/png", imgPtr);
Services.clipboard.setData(
xferable,

View File

@@ -204,7 +204,7 @@ function saveToClipboard(base64URI) {
].createInstance(Ci.nsITransferable);
transferable.init(null);
transferable.addDataFlavor("image/png");
transferable.setTransferData("image/png", img, -1);
transferable.setTransferData("image/png", img);
Services.clipboard.setData(
transferable,

View File

@@ -71,7 +71,7 @@ function copyCF_HTML(cfhtml, success, failure) {
var data = Cc["@mozilla.org/supports-cstring;1"].
createInstance(Ci.nsISupportsCString);
data.data = cfhtml;
trans.setTransferData(CF_HTML, data, cfhtml.length);
trans.setTransferData(CF_HTML, data);
cb.setData(trans, null, cb.kGlobalClipboard);
copyCF_HTML_worker(success, failure);
}

View File

@@ -41,7 +41,7 @@ function runTest() {
var cstr = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
cstr.data = test_data;
trans.setTransferData("text/html", cstr, test_data.length*2);
trans.setTransferData("text/html", cstr);
window.docShell
.rootTreeItem

View File

@@ -525,7 +525,7 @@ function runTest(test) {
.createInstance(SpecialPowers.Ci.nsISupportsString);
data.data = test.payload;
trans.addDataFlavor("text/html");
trans.setTransferData("text/html", data, data.data.length * 2);
trans.setTransferData("text/html", data);
if ("indirectPaste" in test) {
var editor, win;

View File

@@ -101,11 +101,11 @@ async function runTest() {
// if (asHTML) {
// trans.addDataFlavor("text/html");
// ssData.data = doc.body.innerHTML;
// trans.setTransferData("text/html", ssData, ssData.length * 2);
// trans.setTransferData("text/html", ssData);
// } else {
// trans.addDataFlavor("text/unicode");
// ssData.data = doc.body.innerHTML;
// trans.setTransferData("text/unicode", ssData, ssData.length * 2);
// trans.setTransferData("text/unicode", ssData);
// }
//
// return trans;

View File

@@ -49,7 +49,7 @@ function paste(str) {
trans.init(getLoadContext());
var s = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
s.data = str;
trans.setTransferData("text/unicode", s, str.length * 2);
trans.setTransferData("text/unicode", s);
let beforeInputEvent = null;
let inputEvent = null;

View File

@@ -34,7 +34,7 @@ function pasteText(str) {
let s = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
s.data = str;
trans.setTransferData("text/unicode", s, str.length * 2);
trans.setTransferData("text/unicode", s);
let inputEvent = null;
window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true});
getEditor().pasteTransferable(trans);

View File

@@ -73,9 +73,7 @@ this.clipboard = class extends ExtensionAPI {
// are read from the clipboard (on all platforms, not just macOS).
// This forces nsClipboard::GetNativeClipboardData to fall back to
// the native clipboard, and return the image as a nsITransferable.
// The length should not be zero. (Bug 1493292)
transferable.setTransferData(kNativeImageMime, img, 1);
transferable.setTransferData(kNativeImageMime, img);
Services.clipboard.setData(
transferable,

View File

@@ -52,7 +52,7 @@ function clearClipboard() {
// Empty transferables may cause crashes, so just add an unknown type.
const TYPE = "text/x-moz-place-empty";
transf.addDataFlavor(TYPE);
transf.setTransferData(TYPE, {}, 0);
transf.setTransferData(TYPE, {});
SpecialPowers.Services.clipboard.setData(transf, null, SpecialPowers.Services.clipboard.kGlobalClipboard);
}

View File

@@ -1451,7 +1451,7 @@ function copyRawDataToClipboard(button) {
].createInstance(Ci.nsITransferable);
transferable.init(getLoadContext());
transferable.addDataFlavor("text/unicode");
transferable.setTransferData("text/unicode", str, str.data.length * 2);
transferable.setTransferData("text/unicode", str);
Services.clipboard.setData(
transferable,
null,
@@ -1501,12 +1501,12 @@ async function copyContentsToClipboard() {
// Add the HTML flavor.
transferable.addDataFlavor("text/html");
ssHtml.data = dataHtml;
transferable.setTransferData("text/html", ssHtml, dataHtml.length * 2);
transferable.setTransferData("text/html", ssHtml);
// Add the plain text flavor.
transferable.addDataFlavor("text/unicode");
ssText.data = dataText;
transferable.setTransferData("text/unicode", ssText, dataText.length * 2);
transferable.setTransferData("text/unicode", ssText);
// Store the data into the clipboard.
Services.clipboard.setData(

View File

@@ -66,8 +66,8 @@ interface nsIPrincipal;
* nsIFlavorDataProvider allows a flavor to 'promise' data later,
* supplying the data lazily.
*
* To use it, call setTransferData, passing the flavor string,
* a nsIFlavorDataProvider QI'd to nsISupports, and a data size of 0.
* To use it, call setTransferData, passing the flavor string and
* a nsIFlavorDataProvider QI'd to nsISupports.
*
* When someone calls getTransferData later, if the data size is
* stored as 0, the nsISupports will be QI'd to nsIFlavorDataProvider,
@@ -158,7 +158,6 @@ interface nsITransferable : nsISupports
* @param aFlavor the flavor of data that is being set
* @param aData the data, either some variant of class in nsISupportsPrimitives.idl,
* an nsIFile, or an nsIFlavorDataProvider (see above)
* @param aDataLen the length of the data, or 0 if passing a nsIFlavorDataProvider
*/
void setTransferData(in string aFlavor, in nsISupports aData);

View File

@@ -109,7 +109,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1123480
Suppstr.data = Ipsum;
Transfer.init(Loadctx);
Transfer.addDataFlavor("text/unicode");
Transfer.setTransferData("text/unicode", Suppstr, IpsumByteLength);
Transfer.setTransferData("text/unicode", Suppstr);
// Enabled private browsing mode should not cache any selection to disk; disabled should
if (private) {
@@ -129,7 +129,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1123480
// Sanitize the environment.
Suppstr = nsSupportsString();
Suppstr.data = SHORT_STRING_NO_CACHE;
Transfer.setTransferData("text/unicode", Suppstr, SHORT_STRING_NO_CACHE.length * 2);
Transfer.setTransferData("text/unicode", Suppstr);
is(getClipboardCacheFDCount(), initialFdCount, "should drop the cache file, if any.");
Services.clipboard.setData(Transfer, null, Services.clipboard.kGlobalClipboard);

View File

@@ -43,7 +43,7 @@ function copyToClipboard(txt)
Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString);
var copytext = txt;
str.data = copytext;
trans.setTransferData("text/html",str,copytext.length*2);
trans.setTransferData("text/html",str);
if (!clip)
return false;
clip.setData(trans,null,clipid.kGlobalClipboard);

View File

@@ -24,11 +24,11 @@ var transferable = Cc['@mozilla.org/widget/transferable;1']
transferable.init(getLoadContext());
transferable.addDataFlavor("text/unicode");
transferable.setTransferData("text/unicode", document, 4);
transferable.setTransferData("text/unicode", document);
Services.clipboard.setData(transferable, null, Ci.nsIClipboard.kGlobalClipboard);
transferable.setTransferData("text/unicode", null, 0);
transferable.setTransferData("text/unicode", null);
SimpleTest.ok(true, "Didn't crash setting non-text data for text/unicode type");
</script>

View File

@@ -24,7 +24,7 @@
function assignTextToTransferable(transferable, string) {
var Suppstr = nsSupportsString();
Suppstr.data = string;
transferable.setTransferData("text/unicode", Suppstr, string.length * 2);
transferable.setTransferData("text/unicode", Suppstr);
}
function checkTransferableText(transferable, expectedString, description) {