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) { function addData(type, data) {
xferable.addDataFlavor(type); xferable.addDataFlavor(type);
xferable.setTransferData( xferable.setTransferData(type, PlacesUtils.toISupportsString(data));
type,
PlacesUtils.toISupportsString(data),
data.length * 2
);
} }
contents.forEach(function(content) { contents.forEach(function(content) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -34,7 +34,7 @@ function pasteText(str) {
let s = Cc["@mozilla.org/supports-string;1"]. let s = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString); createInstance(Ci.nsISupportsString);
s.data = str; s.data = str;
trans.setTransferData("text/unicode", s, str.length * 2); trans.setTransferData("text/unicode", s);
let inputEvent = null; let inputEvent = null;
window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true}); window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true});
getEditor().pasteTransferable(trans); 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). // are read from the clipboard (on all platforms, not just macOS).
// This forces nsClipboard::GetNativeClipboardData to fall back to // This forces nsClipboard::GetNativeClipboardData to fall back to
// the native clipboard, and return the image as a nsITransferable. // the native clipboard, and return the image as a nsITransferable.
transferable.setTransferData(kNativeImageMime, img);
// The length should not be zero. (Bug 1493292)
transferable.setTransferData(kNativeImageMime, img, 1);
Services.clipboard.setData( Services.clipboard.setData(
transferable, transferable,

View File

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

View File

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

View File

@@ -66,8 +66,8 @@ interface nsIPrincipal;
* nsIFlavorDataProvider allows a flavor to 'promise' data later, * nsIFlavorDataProvider allows a flavor to 'promise' data later,
* supplying the data lazily. * supplying the data lazily.
* *
* To use it, call setTransferData, passing the flavor string, * To use it, call setTransferData, passing the flavor string and
* a nsIFlavorDataProvider QI'd to nsISupports, and a data size of 0. * a nsIFlavorDataProvider QI'd to nsISupports.
* *
* When someone calls getTransferData later, if the data size is * When someone calls getTransferData later, if the data size is
* stored as 0, the nsISupports will be QI'd to nsIFlavorDataProvider, * 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 aFlavor the flavor of data that is being set
* @param aData the data, either some variant of class in nsISupportsPrimitives.idl, * @param aData the data, either some variant of class in nsISupportsPrimitives.idl,
* an nsIFile, or an nsIFlavorDataProvider (see above) * 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); 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; Suppstr.data = Ipsum;
Transfer.init(Loadctx); Transfer.init(Loadctx);
Transfer.addDataFlavor("text/unicode"); 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 // Enabled private browsing mode should not cache any selection to disk; disabled should
if (private) { if (private) {
@@ -129,7 +129,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1123480
// Sanitize the environment. // Sanitize the environment.
Suppstr = nsSupportsString(); Suppstr = nsSupportsString();
Suppstr.data = SHORT_STRING_NO_CACHE; 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."); is(getClipboardCacheFDCount(), initialFdCount, "should drop the cache file, if any.");
Services.clipboard.setData(Transfer, null, Services.clipboard.kGlobalClipboard); 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); Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString);
var copytext = txt; var copytext = txt;
str.data = copytext; str.data = copytext;
trans.setTransferData("text/html",str,copytext.length*2); trans.setTransferData("text/html",str);
if (!clip) if (!clip)
return false; return false;
clip.setData(trans,null,clipid.kGlobalClipboard); clip.setData(trans,null,clipid.kGlobalClipboard);

View File

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

View File

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