Bug 1776879, replace text/unicode for clipboard and drag and drop and use text/plain directly, r=edgar,mak,stransky,geckoview-reviewers,extension-reviewers,zombie,m_kato

Most usage is a straight replacement but gtk needs extra changes as it transfers plain text in UTF8 natively and needs to be converted into UTF16, and Windows uses single-byte characters for RTF and CF_HTML formats so we preserve this.

Differential Revision: https://phabricator.services.mozilla.com/D158587
This commit is contained in:
Neil Deakin
2023-02-01 23:30:55 +00:00
parent 7070212c9e
commit 21426e24f4
101 changed files with 349 additions and 448 deletions

View File

@@ -847,11 +847,11 @@ function getTextFromClipboard() {
return "";
}
trans.addDataFlavor("text/unicode");
trans.addDataFlavor("text/plain");
Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard);
var str = {};
trans.getTransferData("text/unicode", str);
trans.getTransferData("text/plain", str);
if (str) {
str = str.value.QueryInterface(Ci.nsISupportsString);

View File

@@ -1379,7 +1379,7 @@ var PlacesToolbarHelper = {
}
addData(PlacesUtils.TYPE_X_MOZ_URL, 0);
addData(PlacesUtils.TYPE_UNICODE, 0);
addData(PlacesUtils.TYPE_PLAINTEXT, 0);
addData(PlacesUtils.TYPE_HTML, 0);
},
};

View File

@@ -3176,7 +3176,7 @@ function readFromClipboard() {
);
trans.init(getLoadContext());
trans.addDataFlavor("text/unicode");
trans.addDataFlavor("text/plain");
// If available, use selection clipboard, otherwise global one
let clipboard = Services.clipboard;
@@ -3187,7 +3187,7 @@ function readFromClipboard() {
}
var data = {};
trans.getTransferData("text/unicode", data);
trans.getTransferData("text/plain", data);
if (data) {
data = data.value.QueryInterface(Ci.nsISupportsString);

View File

@@ -93,9 +93,9 @@ add_task(async function test_contenteditable() {
"text/html",
PlacesUtils.toISupportsString("<strong>Bold text</strong>")
);
xferable.addDataFlavor("text/unicode");
xferable.addDataFlavor("text/plain");
xferable.setTransferData(
"text/unicode",
"text/plain",
PlacesUtils.toISupportsString("Bold text")
);
Services.clipboard.setData(

View File

@@ -29,7 +29,7 @@ function getTransferableFromClipboard(asHTML) {
if (asHTML) {
trans.addDataFlavor("text/html");
} else {
trans.addDataFlavor("text/unicode");
trans.addDataFlavor("text/plain");
}
Services.clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
return trans;

View File

@@ -16,12 +16,12 @@ function setClipboard(path) {
trans.addDataFlavor("application/x-moz-file");
trans.setTransferData("application/x-moz-file", file);
trans.addDataFlavor("text/unicode");
trans.addDataFlavor("text/plain");
const str = Cc["@mozilla.org/supports-string;1"].createInstance(
Ci.nsISupportsString
);
str.data = "Alternate";
trans.setTransferData("text/unicode", str);
trans.setTransferData("text/plain", str);
// Write to clipboard.
Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard);

View File

@@ -639,7 +639,7 @@ DownloadsPlacesView.prototype = {
);
trans.init(null);
let flavors = ["text/x-moz-url", "text/unicode"];
let flavors = ["text/x-moz-url", "text/plain"];
flavors.forEach(trans.addDataFlavor);
Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard);

View File

@@ -471,7 +471,7 @@ var DownloadsPanel = {
Ci.nsITransferable
);
trans.init(null);
let flavors = ["text/x-moz-url", "text/unicode"];
let flavors = ["text/x-moz-url", "text/plain"];
flavors.forEach(trans.addDataFlavor);
Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard);
// Getting the data or creating the nsIURI might fail

View File

@@ -1793,7 +1793,7 @@ export var PlacesUIUtils = {
let contents = [
{ type: lazy.PlacesUtils.TYPE_X_MOZ_URL, entries: [] },
{ type: lazy.PlacesUtils.TYPE_HTML, entries: [] },
{ type: lazy.PlacesUtils.TYPE_UNICODE, entries: [] },
{ type: lazy.PlacesUtils.TYPE_PLAINTEXT, entries: [] },
];
contents.forEach(function(content) {
@@ -2034,7 +2034,7 @@ XPCOMUtils.defineLazyGetter(PlacesUIUtils, "URI_FLAVORS", () => {
return [
lazy.PlacesUtils.TYPE_X_MOZ_URL,
TAB_DROP_TYPE,
lazy.PlacesUtils.TYPE_UNICODE,
lazy.PlacesUtils.TYPE_PLAINTEXT,
];
});
XPCOMUtils.defineLazyGetter(PlacesUIUtils, "SUPPORTED_FLAVORS", () => {
@@ -2271,7 +2271,7 @@ function getTransactionsForCopy(items, insertionIndex, insertionParentGuid) {
});
} else {
let title =
item.type != lazy.PlacesUtils.TYPE_UNICODE ? item.title : item.uri;
item.type != lazy.PlacesUtils.TYPE_PLAINTEXT ? item.title : item.uri;
transaction = lazy.PlacesTransactions.NewBookmark({
index,
parentGuid: insertionParentGuid,

View File

@@ -168,7 +168,7 @@ PlacesController.prototype = {
case "cmd_paste":
case "placesCmd_paste":
// If the clipboard contains a Places flavor it is definitely pasteable,
// otherwise we also allow pasting "text/unicode" and "text/x-moz-url" data.
// otherwise we also allow pasting "text/plain" and "text/x-moz-url" data.
// We don't check if the data is valid here, because the clipboard may
// contain very large blobs that would largely slowdown commands updating.
// Of course later paste() should ignore any invalid data.
@@ -178,7 +178,7 @@ PlacesController.prototype = {
[
...PlacesUIUtils.PLACES_FLAVORS,
PlacesUtils.TYPE_X_MOZ_URL,
PlacesUtils.TYPE_UNICODE,
PlacesUtils.TYPE_PLAINTEXT,
],
Ci.nsIClipboard.kGlobalClipboard
)
@@ -1049,7 +1049,7 @@ PlacesController.prototype = {
function addURIData(index) {
addData(PlacesUtils.TYPE_X_MOZ_URL, index);
addData(PlacesUtils.TYPE_UNICODE, index);
addData(PlacesUtils.TYPE_PLAINTEXT, index);
addData(PlacesUtils.TYPE_HTML, index);
}
@@ -1131,7 +1131,7 @@ PlacesController.prototype = {
{ type: PlacesUtils.TYPE_X_MOZ_PLACE, entries: [] },
{ type: PlacesUtils.TYPE_X_MOZ_URL, entries: [] },
{ type: PlacesUtils.TYPE_HTML, entries: [] },
{ type: PlacesUtils.TYPE_UNICODE, entries: [] },
{ type: PlacesUtils.TYPE_PLAINTEXT, entries: [] },
];
// Avoid handling descendants of a copied node, the transactions take care
@@ -1264,7 +1264,7 @@ PlacesController.prototype = {
[
PlacesUtils.TYPE_X_MOZ_PLACE,
PlacesUtils.TYPE_X_MOZ_URL,
PlacesUtils.TYPE_UNICODE,
PlacesUtils.TYPE_PLAINTEXT,
].forEach(type => xferable.addDataFlavor(type));
Services.clipboard.getData(xferable, Ci.nsIClipboard.kGlobalClipboard);
@@ -1494,13 +1494,6 @@ var PlacesControllerDragHelper = {
}
}
// If no supported flavor is found, check if data includes text/plain
// contents. If so, request them as text/unicode, a conversion will happen
// automatically.
if (aFlavors.contains("text/plain")) {
return PlacesUtils.TYPE_UNICODE;
}
return null;
},
@@ -1623,7 +1616,7 @@ var PlacesControllerDragHelper = {
// Following flavors may contain duplicated data.
let duplicable = new Map();
duplicable.set(PlacesUtils.TYPE_UNICODE, new Set());
duplicable.set(PlacesUtils.TYPE_PLAINTEXT, new Set());
duplicable.set(PlacesUtils.TYPE_X_MOZ_URL, new Set());
// Collect all data from the DataTransfer before processing it, as the

View File

@@ -133,7 +133,7 @@ add_task(async function test() {
};
// Simulate a bookmark drop for all of the mime types and effects.
let mimeTypes = ["text/plain", "text/unicode", "text/x-moz-url"];
let mimeTypes = ["text/plain", "text/x-moz-url"];
let effects = ["move", "copy", "link"];
for (let effect of effects) {
for (let mimeType of mimeTypes) {

View File

@@ -19,11 +19,11 @@ function getTextFromClipboard() {
Ci.nsITransferable
);
transferable.init(window.docShell.QueryInterface(Ci.nsILoadContext));
transferable.addDataFlavor("text/unicode");
transferable.addDataFlavor("text/plain");
Services.clipboard.getData(transferable, Services.clipboard.kGlobalClipboard);
const results = {};
transferable.getTransferData("text/unicode", results);
transferable.getTransferData("text/plain", results);
return results.value.QueryInterface(Ci.nsISupportsString)?.data ?? "";
}

View File

@@ -3604,7 +3604,7 @@ export class UrlbarInput {
let title = this.window.gBrowser.contentTitle || href;
event.dataTransfer.setData("text/x-moz-url", `${href}\n${title}`);
event.dataTransfer.setData("text/unicode", href);
event.dataTransfer.setData("text/plain", href);
event.dataTransfer.setData("text/html", `<a href="${href}">${title}</a>`);
event.dataTransfer.effectAllowed = "copyLink";
event.stopPropagation();
@@ -3709,7 +3709,7 @@ function getDroppableData(event) {
}
}
// Handle as text.
return event.dataTransfer.getData("text/unicode");
return event.dataTransfer.getData("text/plain");
}
/**

View File

@@ -60,7 +60,7 @@ add_task(async function() {
}
let primaryAsText = SpecialPowers.getClipboardData(
"text/unicode",
"text/plain",
SpecialPowers.Ci.nsIClipboard.kSelectionClipboard
);
Assert.equal(primaryAsText, TEXT_FOR_PRIMARY);

View File

@@ -60,7 +60,7 @@ add_task(async function test_selectByKey() {
function assertClipboard() {
Assert.equal(
SpecialPowers.getClipboardData("text/unicode"),
SpecialPowers.getClipboardData("text/plain"),
"100 cm",
"The result of conversion is copied to clipboard"
);

View File

@@ -83,7 +83,7 @@ function checkPrimarySelection(expectedVal = "") {
)
) {
let primaryAsText = SpecialPowers.getClipboardData(
"text/unicode",
"text/plain",
SpecialPowers.Ci.nsIClipboard.kSelectionClipboard
);
Assert.equal(primaryAsText, expectedVal);

View File

@@ -110,7 +110,7 @@ add_task(async function testSimpleSourcesWithManualClickExpand() {
info("Test the copy to clipboard context menu");
const mathMinTreeNode = findSourceNodeWithText(dbg, "math.min.js");
await triggerCopySourceContextMenu(dbg, mathMinTreeNode);
const clipboardData = SpecialPowers.getClipboardData("text/unicode");
const clipboardData = SpecialPowers.getClipboardData("text/plain");
is(
clipboardData,
EXAMPLE_URL + "math.min.js",

View File

@@ -48,6 +48,6 @@ add_task(async function() {
});
function checkClipboardData(expected) {
const actual = SpecialPowers.getClipboardData("text/unicode");
const actual = SpecialPowers.getClipboardData("text/plain");
return decodeURIComponent(actual).trim() === expected.trim();
}

View File

@@ -62,6 +62,6 @@ add_task(async function() {
});
function checkClipboardData(expected) {
const actual = SpecialPowers.getClipboardData("text/unicode");
const actual = SpecialPowers.getClipboardData("text/plain");
return actual.trim() === expected.trim();
}

View File

@@ -59,6 +59,6 @@ add_task(async function() {
});
function checkClipboardData(expected) {
const actual = SpecialPowers.getClipboardData("text/unicode");
const actual = SpecialPowers.getClipboardData("text/plain");
return actual.trim() === expected.trim();
}

View File

@@ -237,7 +237,7 @@ async function copySomeTextAndCheckClipboard(view, positions, expectedPattern) {
}
function checkClipboard(expectedPattern) {
const actual = SpecialPowers.getClipboardData("text/unicode");
const actual = SpecialPowers.getClipboardData("text/plain");
const expectedRegExp = new RegExp(expectedPattern, "g");
return expectedRegExp.test(actual);
}
@@ -249,7 +249,7 @@ function failClipboardCheck(expectedPattern) {
expectedPattern = expectedPattern.replace(/\\\(/g, "(");
expectedPattern = expectedPattern.replace(/\\\)/g, ")");
let actual = SpecialPowers.getClipboardData("text/unicode");
let actual = SpecialPowers.getClipboardData("text/plain");
// Trim the right hand side of our strings. This is because expectedPattern
// accounts for windows sometimes adding a newline to our copied data.

View File

@@ -330,7 +330,7 @@ async function disableProperty(view, index) {
}
function checkClipboardData(expectedPattern) {
const actual = SpecialPowers.getClipboardData("text/unicode");
const actual = SpecialPowers.getClipboardData("text/plain");
const expectedRegExp = new RegExp(expectedPattern, "g");
return expectedRegExp.test(actual);
}
@@ -342,7 +342,7 @@ function failedClipboard(expectedPattern) {
expectedPattern = expectedPattern.replace(/\\\(/g, "(");
expectedPattern = expectedPattern.replace(/\\\)/g, ")");
let actual = SpecialPowers.getClipboardData("text/unicode");
let actual = SpecialPowers.getClipboardData("text/plain");
// Trim the right hand side of our strings. This is because expectedPattern
// accounts for windows sometimes adding a newline to our copied data.

View File

@@ -182,7 +182,7 @@ async function checkCopyEditorValue(view) {
}
function checkClipboardData(expectedPattern) {
const actual = SpecialPowers.getClipboardData("text/unicode");
const actual = SpecialPowers.getClipboardData("text/plain");
const expectedRegExp = new RegExp(expectedPattern, "g");
return expectedRegExp.test(actual);
}
@@ -194,7 +194,7 @@ function failedClipboard(expectedPattern) {
expectedPattern = expectedPattern.replace(/\\\(/g, "(");
expectedPattern = expectedPattern.replace(/\\\)/g, ")");
let actual = SpecialPowers.getClipboardData("text/unicode");
let actual = SpecialPowers.getClipboardData("text/plain");
// Trim the right hand side of our strings. This is because expectedPattern
// accounts for windows sometimes adding a newline to our copied data.

View File

@@ -43,11 +43,11 @@ add_task(async function() {
ok(true, "The eyedropper is now hidden");
info("Check that the clipboard still contains the copied color");
is(SpecialPowers.getClipboardData("text/unicode"), "#ff0000");
is(SpecialPowers.getClipboardData("text/plain"), "#ff0000");
info("Replace the clipboard content with another text");
SpecialPowers.clipboardCopyString("not-a-color");
is(SpecialPowers.getClipboardData("text/unicode"), "not-a-color");
is(SpecialPowers.getClipboardData("text/plain"), "not-a-color");
info("Click on the page again, check the clipboard was not updated");
await BrowserTestUtils.synthesizeMouseAtCenter(
@@ -57,7 +57,7 @@ add_task(async function() {
);
// Wait 500ms because nothing is observable when the test is successful.
await wait(500);
is(SpecialPowers.getClipboardData("text/unicode"), "not-a-color");
is(SpecialPowers.getClipboardData("text/plain"), "not-a-color");
finalize();
});

View File

@@ -155,7 +155,7 @@ async function testClearedRequests({ tab, monitor, toolbox }) {
connector
);
const jsonString = SpecialPowers.getClipboardData("text/unicode");
const jsonString = SpecialPowers.getClipboardData("text/plain");
const har = JSON.parse(jsonString);
is(har.log.entries.length, 2, "There must be two requests");
is(
@@ -233,6 +233,6 @@ async function reloadAndCopyAllAsHar({
connector
);
const jsonString = SpecialPowers.getClipboardData("text/unicode");
const jsonString = SpecialPowers.getClipboardData("text/plain");
return JSON.parse(jsonString);
}

View File

@@ -15,12 +15,12 @@ function copyString(string) {
}
/**
* Retrieve the current clipboard data matching the flavor "text/unicode".
* Retrieve the current clipboard data matching the flavor "text/plain".
*
* @return {String} Clipboard text content, null if no text clipboard data is available.
*/
function getText() {
const flavor = "text/unicode";
const flavor = "text/plain";
const xferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(
Ci.nsITransferable

View File

@@ -692,7 +692,7 @@ nsresult DragDataProducer::Produce(DataTransfer* aDataTransfer, bool* aCanDrag,
if (NS_SUCCEEDED(rv)) {
data->GetData(mInfoString);
}
rv = transferable->GetTransferData(kUnicodeMime, getter_AddRefs(supports));
rv = transferable->GetTransferData(kTextMime, getter_AddRefs(supports));
data = do_QueryInterface(supports);
NS_ENSURE_SUCCESS(rv, rv); // require plain text at a minimum
data->GetData(mTitleString);

View File

@@ -7785,9 +7785,7 @@ void nsContentUtils::CallOnAllRemoteChildren(
bool nsContentUtils::IPCDataTransferItemHasKnownFlavor(
const IPCDataTransferItem& aItem) {
// Unknown types are converted to kCustomTypesMime.
// FIXME(bug 1776879) text/plain is converted to text/unicode still.
if (aItem.flavor().EqualsASCII(kCustomTypesMime) ||
aItem.flavor().EqualsASCII(kUnicodeMime)) {
if (aItem.flavor().EqualsASCII(kCustomTypesMime)) {
return true;
}

View File

@@ -93,7 +93,7 @@ static nsresult EncodeForTextUnicode(nsIDocumentEncoder& aEncoder,
// html content with pre-wrap style : text/plain. Otherwise text/html. see
// nsHTMLCopyEncoder::SetSelection
nsAutoString mimeType;
mimeType.AssignLiteral(kUnicodeMime);
mimeType.AssignLiteral("text/unicode");
// Do the first and potentially trial encoding as preformatted and raw.
uint32_t flags = aAdditionalEncoderFlags |
@@ -171,7 +171,7 @@ static nsresult EncodeAsTextHTMLWithContext(
}
struct EncodedDocumentWithContext {
// When determening `mSerializationForTextUnicode`, `text/unicode` is passed
// When determining `mSerializationForTextUnicode`, `text/unicode` is passed
// as mime type to the encoder. It uses this as a switch to decide whether to
// encode the document as `text/html` or `text/plain`. It is `true` iff
// `text/html` was used.
@@ -274,14 +274,13 @@ static nsresult CreateTransferable(
if (!aEncodedDocumentWithContext.mSerializationForTextUnicode.IsEmpty()) {
// unicode text
// Add the unicode DataFlavor to the transferable
// Add the plain text DataFlavor to the transferable
// If we didn't have this, then nsDataObj::GetData matches
// text/unicode against the kURLMime flavour which is not desirable
// text/plain against the kURLMime flavour which is not desirable
// (eg. when pasting into Notepad)
rv =
AppendString(aTransferable,
aEncodedDocumentWithContext.mSerializationForTextUnicode,
kUnicodeMime);
rv = AppendString(
aTransferable,
aEncodedDocumentWithContext.mSerializationForTextUnicode, kTextMime);
NS_ENSURE_SUCCESS(rv, rv);
}
@@ -308,10 +307,9 @@ static nsresult CreateTransferable(
} else {
if (!aEncodedDocumentWithContext.mSerializationForTextUnicode.IsEmpty()) {
// Add the unicode DataFlavor to the transferable
rv =
AppendString(aTransferable,
aEncodedDocumentWithContext.mSerializationForTextUnicode,
kUnicodeMime);
rv = AppendString(
aTransferable,
aEncodedDocumentWithContext.mSerializationForTextUnicode, kTextMime);
NS_ENSURE_SUCCESS(rv, rv);
}
}
@@ -475,7 +473,7 @@ nsresult nsCopySupport::ImageCopy(nsIImageLoadingContent* aImageElement,
NS_ENSURE_SUCCESS(rv, rv);
// append the string to the transferable
rv = AppendString(trans, NS_ConvertUTF8toUTF16(location), kUnicodeMime);
rv = AppendString(trans, NS_ConvertUTF8toUTF16(location), kTextMime);
NS_ENSURE_SUCCESS(rv, rv);
}

View File

@@ -50,8 +50,8 @@ async function testCopyPaste(isXHTML) {
);
if (!suppressUnicodeCheck) {
ok(
clipboard.hasDataMatchingFlavors(["text/unicode"], 1),
"check text/unicode"
clipboard.hasDataMatchingFlavors(["text/plain"], 1),
"check text/plain"
);
}
if (!suppressHTMLCheck) {
@@ -159,7 +159,7 @@ async function testCopyPaste(isXHTML) {
await copyChildrenToClipboard("draggable");
testSelectionToString("This is a draggable bit of text.");
testClipboardValue("text/unicode", "This is a draggable bit of text.");
testClipboardValue("text/plain", "This is a draggable bit of text.");
testHtmlClipboardValue(
"text/html",
'<div id="draggable" title="title to have a long HTML line">This is a <em>draggable</em> bit of text.</div>'
@@ -168,7 +168,7 @@ async function testCopyPaste(isXHTML) {
await copyChildrenToClipboard("alist");
testSelectionToString(" bla\n\n foo\n bar\n\n");
testClipboardValue("text/unicode", " bla\n\n foo\n bar\n\n");
testClipboardValue("text/plain", " bla\n\n foo\n bar\n\n");
testHtmlClipboardValue(
"text/html",
'<div id="alist">\n bla\n <ul>\n <li>foo</li>\n \n <li>bar</li>\n </ul>\n </div>'
@@ -177,7 +177,7 @@ async function testCopyPaste(isXHTML) {
await copyChildrenToClipboard("blist");
testSelectionToString(" mozilla\n\n foo\n bar\n\n");
testClipboardValue("text/unicode", " mozilla\n\n foo\n bar\n\n");
testClipboardValue("text/plain", " mozilla\n\n foo\n bar\n\n");
testHtmlClipboardValue(
"text/html",
'<div id="blist">\n mozilla\n <ol>\n <li>foo</li>\n \n <li>bar</li>\n </ol>\n </div>'
@@ -187,7 +187,7 @@ async function testCopyPaste(isXHTML) {
await copyChildrenToClipboard("clist");
testSelectionToString(" mzla\n\n foo\n bazzinga!\n bar\n\n");
testClipboardValue(
"text/unicode",
"text/plain",
" mzla\n\n foo\n bazzinga!\n bar\n\n"
);
testHtmlClipboardValue(
@@ -198,7 +198,7 @@ async function testCopyPaste(isXHTML) {
await copyChildrenToClipboard("div4");
testSelectionToString(" Tt t t ");
testClipboardValue("text/unicode", " Tt t t ");
testClipboardValue("text/plain", " Tt t t ");
if (isXHTML) {
testHtmlClipboardValue(
"text/html",
@@ -219,7 +219,7 @@ async function testCopyPaste(isXHTML) {
await copyChildrenToClipboard("div5");
testSelectionToString(" T ");
testClipboardValue("text/unicode", " T ");
testClipboardValue("text/plain", " T ");
if (isXHTML) {
testHtmlClipboardValue(
"text/html",
@@ -248,7 +248,7 @@ async function testCopyPaste(isXHTML) {
testSelectionToString("");
// START Disabled due to bug 564688
if (false) {
testClipboardValue("text/unicode", "");
testClipboardValue("text/plain", "");
testClipboardValue("text/html", "");
}
// END Disabled due to bug 564688
@@ -264,7 +264,7 @@ async function testCopyPaste(isXHTML) {
testSelectionToString("");
// START Disabled due to bug 564688
if (false) {
testClipboardValue("text/unicode", "");
testClipboardValue("text/plain", "");
testClipboardValue("text/html", "");
}
// END Disabled due to bug 564688
@@ -280,7 +280,7 @@ async function testCopyPaste(isXHTML) {
testSelectionToString("");
// START Disabled due to bug 564688
if (false) {
testClipboardValue("text/unicode", "");
testClipboardValue("text/plain", "");
testClipboardValue("text/html", "");
}
// END Disabled due to bug 564688
@@ -294,7 +294,7 @@ async function testCopyPaste(isXHTML) {
suppressUnicodeCheckIfHidden
);
testSelectionToString("div9");
testClipboardValue("text/unicode", "div9");
testClipboardValue("text/plain", "div9");
testHtmlClipboardValue("text/html", "div9");
testInnerHTML("div9", "div9");
@@ -462,20 +462,20 @@ async function testCopyPaste(isXHTML) {
await copyChildrenToClipboard("div13");
testSelectionToString("__");
testClipboardValue("text/unicode", "__");
testClipboardValue("text/plain", "__");
testHtmlClipboardValue("text/html", '<div id="div13">__</div>');
testPasteText("__");
// ============ converting cell boundaries to tabs in tables
await copyToClipboard($("tr1"));
testClipboardValue("text/unicode", "foo\tbar");
testClipboardValue("text/plain", "foo\tbar");
if (!isXHTML) {
// ============ spanning multiple rows
await copyRangeToClipboard($("tr2"), 0, $("tr3"), 0);
testClipboardValue("text/unicode", "1\t2\n3\t4\n");
testClipboardValue("text/plain", "1\t2\n3\t4\n");
testHtmlClipboardValue(
"text/html",
'<table><tbody><tr id="tr2"><tr id="tr2"><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr><tr id="tr3"></tr></tr></tbody></table>'
@@ -487,7 +487,7 @@ async function testCopyPaste(isXHTML) {
addRange($("tr2"), 0, $("tr2"), 2);
addRange($("tr3"), 0, $("tr3"), 2);
await copySelectionToClipboard();
testClipboardValue("text/unicode", "1\t2\n5\t6");
testClipboardValue("text/plain", "1\t2\n5\t6");
testHtmlClipboardValue(
"text/html",
'<table><tbody><tr id="tr2"><td>1</td><td>2</td></tr><tr id="tr3"><td>5</td><td>6</td></tr></tbody></table>'
@@ -502,7 +502,7 @@ async function testCopyPaste(isXHTML) {
$("div11").childNodes[1],
2
);
testClipboardValue("text/unicode", "Xdiv11");
testClipboardValue("text/plain", "Xdiv11");
testHtmlClipboardValue("text/html", "<div><p>X<span>div</span>11</p></div>");
await new Promise(resolve => {
@@ -520,7 +520,7 @@ async function testCopyPaste(isXHTML) {
2
);
testClipboardValue("text/unicode", "Xdiv12");
testClipboardValue("text/plain", "Xdiv12");
testHtmlClipboardValue("text/html", "<div><p>X<span>div</span>12</p></div>");
await new Promise(resolve => {
setTimeout(resolve, 0);
@@ -539,18 +539,18 @@ async function testCopyPaste(isXHTML) {
// Ruby annotation is included when selecting inside ruby.
await copyRangeToClipboard(ruby1, 0, ruby1, 6);
testClipboardValue("text/unicode", "aabb(AABB)");
testClipboardValue("text/plain", "aabb(AABB)");
// Ruby annotation is ignored when selecting across ruby.
await copyRangeToClipboard(ruby1Container, 0, ruby1Container, 3);
testClipboardValue("text/unicode", "XaabbY");
testClipboardValue("text/plain", "XaabbY");
// ... unless converter.html2txt.always_include_ruby is set
await SpecialPowers.pushPrefEnv({
set: [["converter.html2txt.always_include_ruby", true]],
});
await copyRangeToClipboard(ruby1Container, 0, ruby1Container, 3);
testClipboardValue("text/unicode", "Xaabb(AABB)Y");
testClipboardValue("text/plain", "Xaabb(AABB)Y");
await SpecialPowers.popPrefEnv();
}
}

View File

@@ -59,8 +59,8 @@ function hasExpectedFlavors() {
var cb = Cc["@mozilla.org/widget/clipboard;1"].
getService(Ci.nsIClipboard);
ok(cb.hasDataMatchingFlavors(["text/unicode"], cb.kGlobalClipboard),
"The clipboard has text/unicode");
ok(cb.hasDataMatchingFlavors(["text/plain"], cb.kGlobalClipboard),
"The clipboard has text/plain");
ok(cb.hasDataMatchingFlavors(["text/html"], cb.kGlobalClipboard),
"The clipboard has text/html");

View File

@@ -50,7 +50,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=816298
window.getSelection().selectAllChildren(document.getElementById(id));
documentViewer.copySelection();
is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1), true);
is(clipboard.hasDataMatchingFlavors(["text/plain"], 1), true);
is(clipboard.hasDataMatchingFlavors(["text/html"], 1), true);
}
function getClipboardData(mime) {
@@ -110,7 +110,7 @@ var clipboardHTML = [
'<p id=\"test5\">This<span style=\"user-select: all\"> text should</span> be copied.</p>',
];
// expected results for clipboard text/unicode
// expected results for clipboard text/plain
var clipboardUnicode = [
'This text should be copied.',
'This text should be copied.',
@@ -145,7 +145,7 @@ for (var i = 0; i < originalStrings.length; i++) {
copyChildrenToClipboard(id);
is(window.getSelection().toString(), originalStrings[i], id + ' Selection.toString()');
testHtmlClipboardValue("text/html", clipboardHTML[i], id);
testClipboardValue("text/unicode", clipboardUnicode[i], id);
testClipboardValue("text/plain", clipboardUnicode[i], id);
testInnerHTML(id, innerHTMLStrings[i]);
testPasteText(textareaStrings[i], id + '.innerHTML');
}

View File

@@ -80,7 +80,7 @@ async function clipboardTextForElementId(aDomId, aExpectedString) {
function setup() {
synthesizeKey("C", {accelKey: true});
},
"text/unicode");
"text/plain");
return copiedText;
}

View File

@@ -57,15 +57,15 @@ function testCopyImage () {
//--------- Let's check the content of the clipboard now.
// Does the clipboard contain text/unicode data ?
ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard), "clipboard contains unicode text");
// Does the clipboard contain text/plain data ?
ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard), "clipboard contains unicode text");
// Does the clipboard contain text/html data ?
ok(clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard), "clipboard contains html text");
// Does the clipboard contain image data ?
ok(clipboard.hasDataMatchingFlavors(["image/png"], clipboard.kGlobalClipboard), "clipboard contains image");
// Is the text/uncodie data correct ?
testClipboardValue('text/unicode', 'about:logo');
// Is the text/plain data correct ?
testClipboardValue('text/plain', 'about:logo');
// Is the text/html data correct ?
var expected = '<img id="logo" src="about:logo">';
if (navigator.platform.includes("Win")) {

View File

@@ -6,10 +6,10 @@ This test is different from test_copypaste.html in two ways:
1. The text/html clipboard flavor isn't tested, since nsCopySupport doesn't
produce it for XHTML.
2. The text/unicode flavor isn't tested when the selection is in hidden
2. The text/plain flavor isn't tested when the selection is in hidden
elements, since nsCopySupport doesn't produce text/plain for hidden
elements, and unlike HTML, neither does it produce text/_moz_htmlcontext
and text/_moz_htmlinfo, which the clipboard converts to text/unicode.
and text/_moz_htmlinfo, which the clipboard converts to text/plain.
-->
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

View File

@@ -82,7 +82,7 @@ waitUntilApzStable().then(async function() {
let element = doc.getElementById(id);
dragSelect(element, 0, 60);
await copySelectionToClipboard();
testClipboardValue("text/unicode", element.value.substr(0, 3));
testClipboardValue("text/plain", element.value.substr(0, 3));
}
}

View File

@@ -91,7 +91,7 @@ function cutCopyAll(
aSetup,
aNext,
aNext,
"text/unicode",
"text/plain",
WATCH_TIMEOUT,
true
);

View File

@@ -97,7 +97,7 @@ void Clipboard::ReadRequest::Answer() {
// Mandatory data types defined in
// https://w3c.github.io/clipboard-apis/#mandatory-data-types-x
AutoTArray<nsCString, 3>{nsDependentCString(kHTMLMime),
nsDependentCString(kUnicodeMime),
nsDependentCString(kTextMime),
nsDependentCString(kPNGImageMime)},
nsIClipboard::kGlobalClipboard)
->Then(
@@ -123,10 +123,7 @@ void Clipboard::ReadRequest::Answer() {
RefPtr<ClipboardItem::ItemEntry> entry =
MakeRefPtr<ClipboardItem::ItemEntry>(
format.EqualsLiteral(kUnicodeMime)
? NS_ConvertUTF8toUTF16(kTextMime)
: NS_ConvertUTF8toUTF16(format),
format);
NS_ConvertUTF8toUTF16(format), format);
entry->LoadData(*global, *trans);
entries.AppendElement(std::move(entry));
}
@@ -152,7 +149,7 @@ void Clipboard::ReadRequest::Answer() {
}
trans->Init(nullptr);
trans->AddDataFlavor(kUnicodeMime);
trans->AddDataFlavor(kTextMime);
clipboardService->AsyncGetData(trans, nsIClipboard::kGlobalClipboard)
->Then(
GetMainThreadSerialEventTarget(), __func__,
@@ -160,7 +157,7 @@ void Clipboard::ReadRequest::Answer() {
[trans, p]() {
nsCOMPtr<nsISupports> data;
nsresult rv =
trans->GetTransferData(kUnicodeMime, getter_AddRefs(data));
trans->GetTransferData(kTextMime, getter_AddRefs(data));
nsAutoString str;
if (!NS_WARN_IF(NS_FAILED(rv))) {
@@ -681,7 +678,7 @@ already_AddRefed<Promise> Clipboard::WriteText(const nsAString& aData,
nsTArray<RefPtr<ClipboardItem::ItemEntry>> items;
items.AppendElement(MakeRefPtr<ClipboardItem::ItemEntry>(
NS_LITERAL_STRING_FROM_CSTRING(kTextMime), nsLiteralCString(kUnicodeMime),
NS_LITERAL_STRING_FROM_CSTRING(kTextMime), nsLiteralCString(kTextMime),
std::move(data)));
nsTArray<OwningNonNull<ClipboardItem>> sequence;

View File

@@ -22,15 +22,7 @@ NS_IMPL_CYCLE_COLLECTION(ClipboardItem::ItemEntry, mData,
ClipboardItem::ItemEntry::ItemEntry(const nsAString& aType,
const nsACString& aFormat)
: mType(aType), mFormat(aFormat) {
// XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1776879.
// In most of cases, the mType and mFormat are the same, execpt for plain
// text. We expose it as "text/plain" to the web, but we use "text/unicode"
// internally to retrieve from system clipboard.
MOZ_ASSERT_IF(
!mType.Equals(NS_ConvertUTF8toUTF16(mFormat)),
mType.EqualsLiteral(kTextMime) && mFormat.EqualsLiteral(kUnicodeMime));
}
: mType(aType), mFormat(aFormat) {}
void ClipboardItem::ItemEntry::SetData(already_AddRefed<Blob>&& aBlob) {
// XXX maybe we could consider adding a method to check whether the union
@@ -190,9 +182,7 @@ already_AddRefed<ClipboardItem> ClipboardItem::Constructor(
nsTArray<RefPtr<ItemEntry>> items;
for (const auto& entry : aItems.Entries()) {
nsAutoCString format = entry.mKey.EqualsLiteral(kTextMime)
? nsAutoCString(kUnicodeMime)
: NS_ConvertUTF16toUTF8(entry.mKey);
nsAutoCString format = NS_ConvertUTF16toUTF8(entry.mKey);
items.AppendElement(
MakeRefPtr<ItemEntry>(entry.mKey, format, entry.mValue));
}

View File

@@ -623,7 +623,7 @@ already_AddRefed<DataTransfer> DataTransfer::MozCloneForEvent(
// types.
static const char* kNonPlainTextExternalFormats[] = {
kCustomTypesMime, kFileMime, kHTMLMime, kRTFMime, kURLMime,
kURLDataMime, kUnicodeMime, kPNGImageMime, kPDFJSMime};
kURLDataMime, kTextMime, kPNGImageMime, kPDFJSMime};
/* static */
void DataTransfer::GetExternalClipboardFormats(const int32_t& aWhichClipboard,
@@ -643,12 +643,12 @@ void DataTransfer::GetExternalClipboardFormats(const int32_t& aWhichClipboard,
if (aPlainTextOnly) {
bool hasType;
AutoTArray<nsCString, 1> unicodeMime = {nsDependentCString(kUnicodeMime)};
nsresult rv = clipboard->HasDataMatchingFlavors(unicodeMime,
aWhichClipboard, &hasType);
AutoTArray<nsCString, 1> textMime = {nsDependentCString(kTextMime)};
nsresult rv =
clipboard->HasDataMatchingFlavors(textMime, aWhichClipboard, &hasType);
NS_SUCCEEDED(rv);
if (hasType) {
aResult->AppendElement(kUnicodeMime);
aResult->AppendElement(kTextMime);
}
return;
}
@@ -685,9 +685,9 @@ void DataTransfer::GetExternalTransferableFormats(
aTransferable->FlavorsTransferableCanExport(flavors);
if (aPlainTextOnly) {
auto index = flavors.IndexOf(nsLiteralCString(kUnicodeMime));
auto index = flavors.IndexOf(nsLiteralCString(kTextMime));
if (index != flavors.NoIndex) {
aResult->AppendElement(nsLiteralCString(kUnicodeMime));
aResult->AppendElement(nsLiteralCString(kTextMime));
}
return;
}
@@ -1084,27 +1084,20 @@ already_AddRefed<nsITransferable> DataTransfer::GetTransferable(
continue;
}
// The underlying drag code uses text/unicode, so use that instead of
// text/plain
const char* format;
NS_ConvertUTF16toUTF8 utf8format(type);
if (utf8format.EqualsLiteral(kTextMime)) {
format = kUnicodeMime;
} else {
format = utf8format.get();
}
NS_ConvertUTF16toUTF8 format(type);
// If a converter is set for a format, set the converter for the
// transferable and don't add the item
nsCOMPtr<nsIFormatConverter> converter =
do_QueryInterface(convertedData);
if (converter) {
transferable->AddDataFlavor(format);
transferable->AddDataFlavor(format.get());
transferable->SetConverter(converter);
continue;
}
nsresult rv = transferable->SetTransferData(format, convertedData);
nsresult rv =
transferable->SetTransferData(format.get(), convertedData);
if (NS_FAILED(rv)) {
return nullptr;
}
@@ -1225,7 +1218,7 @@ void DataTransfer::SetDataWithPrincipalFromOtherProcess(
void DataTransfer::GetRealFormat(const nsAString& aInFormat,
nsAString& aOutFormat) const {
// treat text/unicode as equivalent to text/plain
// For compatibility, treat text/unicode as equivalent to text/plain
nsAutoString lowercaseFormat;
nsContentUtils::ASCIIToLower(aInFormat, lowercaseFormat);
if (lowercaseFormat.EqualsLiteral("text") ||
@@ -1248,7 +1241,7 @@ nsresult DataTransfer::CacheExternalData(const char* aFormat, uint32_t aIndex,
ErrorResult rv;
RefPtr<DataTransferItem> item;
if (strcmp(aFormat, kUnicodeMime) == 0) {
if (strcmp(aFormat, kTextMime) == 0) {
item = mItems->SetDataWithPrincipal(u"text/plain"_ns, nullptr, aIndex,
aPrincipal, false, aHidden, rv);
if (NS_WARN_IF(rv.Failed())) {
@@ -1299,7 +1292,7 @@ void DataTransfer::CacheExternalDragFormats() {
// NOTE: kFileMime must have index 0
// TODO: should this be `kNonPlainTextExternalFormats` instead?
static const char* formats[] = {kFileMime, kHTMLMime, kURLMime,
kURLDataMime, kUnicodeMime, kPNGImageMime};
kURLDataMime, kTextMime, kPNGImageMime};
uint32_t count;
dragSession->GetNumDropItems(&count);
@@ -1350,10 +1343,10 @@ void DataTransfer::CacheExternalClipboardFormats(bool aPlainTextOnly) {
}
if (aPlainTextOnly) {
// The only thing that will be in types is kUnicodeMime
// The only thing that will be in types is kTextMime
MOZ_ASSERT(typesArray.IsEmpty() || typesArray.Length() == 1);
if (typesArray.Length() == 1) {
CacheExternalData(kUnicodeMime, 0, sysPrincipal, false);
CacheExternalData(kTextMime, 0, sysPrincipal, false);
}
return;
}

View File

@@ -365,7 +365,7 @@ class DataTransfer final : public nsISupports, public nsWrapperCache {
DataTransfer** aResult);
// converts some formats used for compatibility in aInFormat into aOutFormat.
// Text and text/unicode become text/plain, and URL becomes text/uri-list
// Text becomes text/plain, and URL becomes text/uri-list
void GetRealFormat(const nsAString& aInFormat, nsAString& aOutFormat) const;
static bool PrincipalMaySetData(const nsAString& aFormat, nsIVariant* aData,

View File

@@ -150,9 +150,7 @@ void DataTransferItem::FillInExternalData() {
NS_ConvertUTF16toUTF8 utf8format(mType);
const char* format = utf8format.get();
if (strcmp(format, "text/plain") == 0) {
format = kUnicodeMime;
} else if (strcmp(format, "text/uri-list") == 0) {
if (strcmp(format, "text/uri-list") == 0) {
format = kURLDataMime;
}

View File

@@ -24,10 +24,6 @@
"resource://gre/modules/PlacesUtils.jsm"
);
// Some of the clipboard code requires reading or writing "text/unicode" when
// actually "text/plain" is desired.
const kTextUnicodeMimeType = "text/unicode";
const kTextPlainMimeType = "text/plain";
function clearClipboard() {
@@ -38,7 +34,7 @@
let expected = "x";
await SimpleTest.promiseClipboardChange(expected, () => {
SpecialPowers.clipboardCopyString(expected);
}, kTextUnicodeMimeType);
}, kTextPlainMimeType);
let items = await navigator.clipboard.read();
is(items.length, 1, "read() read exactly one item");
const actual = await items[0].getType(kTextPlainMimeType).then(blob => blob.text());
@@ -54,7 +50,7 @@
// eslint-disable-next-line no-undef
let item = new ClipboardItem({[kTextPlainMimeType]: expected});
await navigator.clipboard.write([item]);
let actual = SpecialPowers.getClipboardData(kTextUnicodeMimeType);
let actual = SpecialPowers.getClipboardData(kTextPlainMimeType);
is(actual, expected, "write() wrote the right thing");
}
@@ -62,7 +58,7 @@
let expected = "x";
await SimpleTest.promiseClipboardChange(expected, () => {
SpecialPowers.clipboardCopyString(expected);
}, kTextUnicodeMimeType);
}, kTextPlainMimeType);
let actual = await navigator.clipboard.readText();
is(actual, expected, "readText() read the right thing");
}
@@ -74,7 +70,7 @@
let expected = "x";
await navigator.clipboard.writeText(expected);
let actual = SpecialPowers.getClipboardData(kTextUnicodeMimeType);
let actual = SpecialPowers.getClipboardData(kTextPlainMimeType);
is(actual, expected, "writeText() wrote the right thing");
}

View File

@@ -26,8 +26,8 @@ SimpleTest.waitForFocus(() => {
//--------- now check the content of the clipboard
var clipboard = SpecialPowers.Cc["@mozilla.org/widget/clipboard;1"]
.getService(SpecialPowers.Ci.nsIClipboard);
// does the clipboard contain text/unicode data ?
ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard),
// does the clipboard contain text/plain data ?
ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard),
"clipboard contains unicode text");
// does the clipboard contain text/html data ?
ok(clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard),

View File

@@ -142,12 +142,13 @@ function doDragStartSelection(event)
is(dt.getData("text/html"), "<div id=\"draggable\" ondragstart=\"doDragStartSelection(event)\">This is a <em>draggable</em> bit of text.</div>",
"initial selection text/html");
// text/unicode and Text are available for compatibility. They retrieve the
// text/plain data
is(dt.getData("text/unicode"), "This is a draggable bit of text.", "initial selection text/unicode");
// text/plain and Text are available for compatibility. They retrieve the
// text/plain data. text/unicode is also for compatibility and retreives the plain text.
is(dt.getData("text/plain"), "This is a draggable bit of text.", "initial selection text/plain");
is(dt.getData("Text"), "This is a draggable bit of text.", "initial selection Text");
is(dt.getData("TEXT"), "This is a draggable bit of text.", "initial selection TEXT");
is(dt.getData("text/UNICODE"), "This is a draggable bit of text.", "initial selection text/UNICODE");
is(dt.getData("text/PLAIN"), "This is a draggable bit of text.", "initial selection text/PLAIN");
is(dt.getData("text/unicode"), "This is a draggable bit of text.", "initial selection text/unicode");
is(SpecialPowers.wrap(dt).mozItemCount, 1, "initial selection item count");

View File

@@ -88,8 +88,8 @@
//--------- now check the content of the clipboard
var clipboard = SpecialPowers.Cc["@mozilla.org/widget/clipboard;1"]
.getService(SpecialPowers.Ci.nsIClipboard);
// does the clipboard contain text/unicode data ?
ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard),
// does the clipboard contain text/plain data ?
ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard),
"clipboard contains unicode text");
// does the clipboard contain text/html data ?
ok(clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard),

View File

@@ -23,8 +23,8 @@ add_task(async function() {
trans.addDataFlavor("text/unknown");
trans.setTransferData("text/unknown", string);
trans.addDataFlavor("text/unicode");
trans.setTransferData("text/unicode", string);
trans.addDataFlavor("text/plain");
trans.setTransferData("text/plain", string);
// Write to clipboard.
Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard);
@@ -34,7 +34,7 @@ add_task(async function() {
for (var i = 0; i < 20; i++) {
if (
Services.clipboard.hasDataMatchingFlavors(
["text/unicode"],
["text/plain"],
Services.clipboard.kGlobalClipboard
)
) {
@@ -57,16 +57,16 @@ add_task(async function() {
ok(
Services.clipboard.hasDataMatchingFlavors(
["text/unicode"],
["text/plain"],
Services.clipboard.kGlobalClipboard
),
"clipboard should have text/unicode"
"clipboard should have text/plain"
);
is(
readClipboard("text/unicode"),
readClipboard("text/plain"),
"blablabla",
"matching string for text/unicode"
"matching string for text/plain"
);
ok(

View File

@@ -1551,7 +1551,7 @@ nsHTMLCopyEncoder::Init(Document* aDocument, const nsAString& aMimeType,
mIsCopying = true;
mDocument = aDocument;
// Hack, hack! Traditionally, the caller passes text/unicode, which is
// Hack, hack! Traditionally, the caller passes text/plain, which is
// treated as "guess text/html or text/plain" in this context. (It has a
// different meaning in other contexts. Sigh.) From now on, "text/plain"
// means forcing text/plain instead of guessing.

View File

@@ -20,8 +20,8 @@ var supportsSelectionClipboard = SpecialPowers.supportsSelectionClipboard();
function checkSelectionClipboardText(count)
{
if ((!supportsSelectionClipboard ||
SpecialPowers.getClipboardData("text/unicode", SpecialPowers.Ci.nsIClipboard.kSelectionClipboard) == "COPY TEXT") &&
SpecialPowers.getClipboardData("text/unicode", SpecialPowers.Ci.nsIClipboard.kGlobalClipboard) == "CLIPBOARD") {
SpecialPowers.getClipboardData("text/plain", SpecialPowers.Ci.nsIClipboard.kSelectionClipboard) == "COPY TEXT") &&
SpecialPowers.getClipboardData("text/plain", SpecialPowers.Ci.nsIClipboard.kGlobalClipboard) == "CLIPBOARD") {
pasteArea();
return;
}

View File

@@ -102,7 +102,7 @@ async function reset() {
}
function getClipboardText() {
return SpecialPowers.getClipboardData("text/unicode");
return SpecialPowers.getClipboardData("text/plain");
}
function getHTMLEditor() {

View File

@@ -190,7 +190,7 @@
info("cut");
await synthesizeKey(VK.X, { accelKey: true }, "x");
await checkElement(editor, 0, "", "");
let text = SpecialPowers.getClipboardData("text/unicode");
let text = SpecialPowers.getClipboardData("text/plain");
is(text, "Test text", "Should have cut to the clipboard");
SpecialPowers.clipboardCopyString("New text");

View File

@@ -146,7 +146,7 @@ async function startTest() {
info("cut");
await synthesizeKey(VK.X, { accelKey: true }, "x", "input");
await checkElement(input, 0, 0, "");
let text = SpecialPowers.getClipboardData("text/unicode");
let text = SpecialPowers.getClipboardData("text/plain");
is(text, "Test text", "Should have cut to the clipboard");
SpecialPowers.clipboardCopyString("New text");

View File

@@ -146,7 +146,7 @@ async function startTest() {
info("cut");
await synthesizeKey(VK.X, { accelKey: true }, "x", "input");
await checkElement(input, 0, 0, "");
let text = SpecialPowers.getClipboardData("text/unicode");
let text = SpecialPowers.getClipboardData("text/plain");
is(text, "Test text", "Should have cut to the clipboard");
SpecialPowers.clipboardCopyString("New text");

View File

@@ -221,10 +221,10 @@ EditorUtils::CreateTransferableForPlainText(const Document& aDocument) {
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"nsITransferable::Init() failed, but ignored");
rvIgnored = transferable->AddDataFlavor(kUnicodeMime);
rvIgnored = transferable->AddDataFlavor(kTextMime);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored),
"nsITransferable::AddDataFlavor(kUnicodeMime) failed, but ignored");
"nsITransferable::AddDataFlavor(kTextMime) failed, but ignored");
rvIgnored = transferable->AddDataFlavor(kMozTextInternal);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored),

View File

@@ -432,7 +432,7 @@ class EditorUtils final {
const nsINode& aParentNode, uint32_t aOffset);
/**
* Create an nsITransferable instance which has kUnicodeMime and
* Create an nsITransferable instance which has kTextMime and
* kMozTextInternal flavors.
*/
static Result<nsCOMPtr<nsITransferable>, nsresult>

View File

@@ -1463,10 +1463,10 @@ void HTMLEditor::HTMLTransferablePreparer::AddDataFlavorsInBestOrder(
break;
}
}
DebugOnly<nsresult> rvIgnored = aTransferable.AddDataFlavor(kUnicodeMime);
DebugOnly<nsresult> rvIgnored = aTransferable.AddDataFlavor(kTextMime);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored),
"nsITransferable::AddDataFlavor(kUnicodeMime) failed, but ignored");
"nsITransferable::AddDataFlavor(kTextMime) failed, but ignored");
rvIgnored = aTransferable.AddDataFlavor(kMozTextInternal);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored),
@@ -2035,7 +2035,7 @@ nsresult HTMLEditor::InsertFromTransferableAtSelection(
}
}
if (bestFlavor.EqualsLiteral(kHTMLMime) ||
bestFlavor.EqualsLiteral(kUnicodeMime) ||
bestFlavor.EqualsLiteral(kTextMime) ||
bestFlavor.EqualsLiteral(kMozTextInternal)) {
nsAutoString stuffToPaste;
if (!GetString(genericDataObj, stuffToPaste)) {
@@ -2542,8 +2542,8 @@ nsresult HTMLEditor::PasteNoFormattingAsAction(int32_t aSelectionType,
// The following arrays contain the MIME types that we can paste. The arrays
// are used by CanPaste() and CanPasteTransferable() below.
static const char* textEditorFlavors[] = {kUnicodeMime};
static const char* textHtmlEditorFlavors[] = {kUnicodeMime, kHTMLMime,
static const char* textEditorFlavors[] = {kTextMime};
static const char* textHtmlEditorFlavors[] = {kTextMime, kHTMLMime,
kJPEGImageMime, kJPGImageMime,
kPNGImageMime, kGIFImageMime};
@@ -2792,10 +2792,10 @@ nsresult HTMLEditor::PasteAsPlaintextQuotation(int32_t aSelectionType) {
"nsITransferable::Init() failed, but ignored");
// We only handle plaintext pastes here
rvIgnored = transferable->AddDataFlavor(kUnicodeMime);
rvIgnored = transferable->AddDataFlavor(kTextMime);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored),
"nsITransferable::AddDataFlavor(kUnicodeMime) failed, but ignored");
"nsITransferable::AddDataFlavor(kTextMime) failed, but ignored");
// Get the Data from the clipboard
rvIgnored = clipboard->GetData(transferable, aSelectionType);
@@ -2813,7 +2813,7 @@ nsresult HTMLEditor::PasteAsPlaintextQuotation(int32_t aSelectionType) {
return rv;
}
if (!flavor.EqualsLiteral(kUnicodeMime)) {
if (!flavor.EqualsLiteral(kTextMime)) {
return NS_OK;
}

View File

@@ -593,8 +593,7 @@ nsresult TextEditor::PasteAsQuotationAsAction(int32_t aClipboardType,
return EditorBase::ToGenericNSResult(rv);
}
if (!flav.EqualsLiteral(kUnicodeMime) &&
!flav.EqualsLiteral(kMozTextInternal)) {
if (!flav.EqualsLiteral(kTextMime) && !flav.EqualsLiteral(kMozTextInternal)) {
return NS_OK;
}

View File

@@ -53,7 +53,7 @@ nsresult TextEditor::InsertTextFromTransferable(
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
"nsITransferable::GetAnyDataTransferData() failed, but ignored");
if (NS_SUCCEEDED(rv) && (bestFlavor.EqualsLiteral(kUnicodeMime) ||
if (NS_SUCCEEDED(rv) && (bestFlavor.EqualsLiteral(kTextMime) ||
bestFlavor.EqualsLiteral(kMozTextInternal))) {
AutoTransactionsConserveSelection dontChangeMySelection(*this);
@@ -271,8 +271,7 @@ bool TextEditor::CanPaste(int32_t aClipboardType) const {
}
// the flavors that we can deal with
AutoTArray<nsCString, 1> textEditorFlavors = {
nsDependentCString(kUnicodeMime)};
AutoTArray<nsCString, 1> textEditorFlavors = {nsDependentCString(kTextMime)};
bool haveFlavors;
rv = clipboard->HasDataMatchingFlavors(textEditorFlavors, aClipboardType,
@@ -294,10 +293,9 @@ bool TextEditor::CanPasteTransferable(nsITransferable* aTransferable) {
}
nsCOMPtr<nsISupports> data;
nsresult rv =
aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(data));
nsresult rv = aTransferable->GetTransferData(kTextMime, getter_AddRefs(data));
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"nsITransferable::GetTransferData(kUnicodeMime) failed");
"nsITransferable::GetTransferData(kTextMime) failed");
return NS_SUCCEEDED(rv) && data;
}

View File

@@ -60,7 +60,7 @@ async function runTest() {
if (asHTML) {
trans.addDataFlavor("text/html");
} else {
trans.addDataFlavor("text/unicode");
trans.addDataFlavor("text/plain");
}
var clip = SpecialPowers.Services.clipboard;
clip.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
@@ -103,9 +103,9 @@ async function runTest() {
// ssData.data = doc.body.innerHTML;
// trans.setTransferData("text/html", ssData);
// } else {
// trans.addDataFlavor("text/unicode");
// trans.addDataFlavor("text/plain");
// ssData.data = doc.body.innerHTML;
// trans.setTransferData("text/unicode", ssData);
// trans.setTransferData("text/plain", ssData);
// }
//
// return trans;

View File

@@ -76,7 +76,7 @@ SimpleTest.waitForFocus(function() {
SimpleTest.finish();
},
// TODO: bug 1686012
SpecialPowers.isHeadless ? "text/unicode" : "text/html"
SpecialPowers.isHeadless ? "text/plain" : "text/html"
);
});

View File

@@ -37,15 +37,15 @@ SimpleTest.waitForFocus(async () => {
input.setSelectionRange(0, 6);
ok(true, "Trying to copy masked password...");
await copyToClipboard(null);
isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef",
isnot(SpecialPowers.getClipboardData("text/plain"), "abcdef",
"Copying masked password shouldn't copy raw value into the clipboard");
isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
"Copying masked password shouldn't copy masked value into the clipboard");
ok(true, "Trying to cut masked password...");
await cutToClipboard(null);
isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef",
isnot(SpecialPowers.getClipboardData("text/plain"), "abcdef",
"Cutting masked password shouldn't copy raw value into the clipboard");
isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
"Cutting masked password shouldn't copy masked value into the clipboard");
is(input.value, "abcdef",
"Cutting masked password shouldn't modify the value");
@@ -54,19 +54,19 @@ SimpleTest.waitForFocus(async () => {
input.setSelectionRange(0, 6);
ok(true, "Trying to copy partially masked password...");
await copyToClipboard(null);
isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef",
isnot(SpecialPowers.getClipboardData("text/plain"), "abcdef",
"Copying partially masked password shouldn't copy raw value into the clipboard");
isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}cd${kMask}${kMask}`,
isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}cd${kMask}${kMask}`,
"Copying partially masked password shouldn't copy partially masked value into the clipboard");
isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
"Copying partially masked password shouldn't copy masked value into the clipboard");
ok(true, "Trying to cut partially masked password...");
await cutToClipboard(null);
isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef",
isnot(SpecialPowers.getClipboardData("text/plain"), "abcdef",
"Cutting partially masked password shouldn't copy raw value into the clipboard");
isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}cd${kMask}${kMask}`,
isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}cd${kMask}${kMask}`,
"Cutting partially masked password shouldn't copy partially masked value into the clipboard");
isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`,
"Cutting partially masked password shouldn't copy masked value into the clipboard");
is(input.value, "abcdef",
"Cutting partially masked password shouldn't modify the value");

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);
trans.setTransferData("text/plain", s);
let inputEvent = null;
window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true});
getEditor().pasteTransferable(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);
trans.setTransferData("text/plain", s);
let beforeInputEvent = null;
let inputEvent = null;

View File

@@ -68,7 +68,7 @@ add_task(async () => {
dump("********************\n");
resolve("");
},
"text/unicode",
"text/plain",
REPORT_TIMEOUT_MS
);
});

View File

@@ -72,7 +72,7 @@ class SelectionActionDelegateChild extends GeckoViewActorChild {
predicate: e =>
e.selectionEditable &&
Services.clipboard.hasDataMatchingFlavors(
["text/unicode"],
["text/plain"],
Ci.nsIClipboard.kGlobalClipboard
),
perform: _ => this._performPaste(),

View File

@@ -15,7 +15,7 @@ import org.mozilla.gecko.annotation.WrapForJNI;
public final class Clipboard {
private static final String HTML_MIME = "text/html";
private static final String UNICODE_MIME = "text/unicode";
private static final String PLAINTEXT_MIME = "text/plain";
private static final String LOGTAG = "GeckoClipboard";
private Clipboard() {}
@@ -27,14 +27,14 @@ public final class Clipboard {
* @return a plain text string of clipboard data.
*/
public static String getText(final Context context) {
return getData(context, UNICODE_MIME);
return getData(context, PLAINTEXT_MIME);
}
/**
* Get the data on the primary clip on clipboard
*
* @param context application context
* @param mimeType the mime type we want. This supports text/html and text/unicode only. If other
* @param mimeType the mime type we want. This supports text/html and text/plain only. If other
* type, we do nothing.
* @return a string into clipboard.
*/
@@ -57,7 +57,7 @@ public final class Clipboard {
}
return data.toString();
}
if (UNICODE_MIME.equals(mimeType)) {
if (PLAINTEXT_MIME.equals(mimeType)) {
try {
return clip.getItemAt(0).coerceToText(context).toString();
} catch (final SecurityException e) {
@@ -130,7 +130,7 @@ public final class Clipboard {
@WrapForJNI(calledFrom = "gecko")
public static boolean hasData(final Context context, final String mimeType) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
if (HTML_MIME.equals(mimeType) || UNICODE_MIME.equals(mimeType)) {
if (HTML_MIME.equals(mimeType) || PLAINTEXT_MIME.equals(mimeType)) {
return !TextUtils.isEmpty(getData(context, mimeType));
}
return false;
@@ -155,7 +155,7 @@ public final class Clipboard {
return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML);
}
if (UNICODE_MIME.equals(mimeType)) {
if (PLAINTEXT_MIME.equals(mimeType)) {
// We cannot check content in data at this time to avoid toast message.
return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)
|| description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN);

View File

@@ -1063,7 +1063,7 @@ const kTextHtmlSuffixClipboardDataWindows =
* Polls the clipboard waiting for the expected value. A known value different than
* the expected value is put on the clipboard first (and also polled for) so we
* can be sure the value we get isn't just the expected value because it was already
* on the clipboard. This only uses the global clipboard and only for text/unicode
* on the clipboard. This only uses the global clipboard and only for text/plain
* values.
*
* @param {String|Function} aExpectedStringOrValidatorFn
@@ -1087,7 +1087,7 @@ const kTextHtmlSuffixClipboardDataWindows =
* @param {Function} aFailureFn
* A function called if the expected value isn't found on the clipboard
* within 5s. It can also be called if the known value can't be found.
* @param {String} [aFlavor="text/unicode"]
* @param {String} [aFlavor="text/plain"]
* The flavor to look for.
* @param {Number} [aTimeout=5000]
* The timeout (in milliseconds) to wait for a clipboard change.
@@ -1131,7 +1131,7 @@ SimpleTest.promiseClipboardChange = async function(
aExpectFailure,
aDontInitializeClipboardIfExpectFailure
) {
let requestedFlavor = aFlavor || "text/unicode";
let requestedFlavor = aFlavor || "text/plain";
// The known value we put on the clipboard before running aSetupFn
let initialVal = "waitForClipboard-known-value-" + Math.random();
@@ -1223,7 +1223,7 @@ SimpleTest.promiseClipboardChange = async function(
function(aData) {
return aData == preExpectedVal;
},
"text/unicode",
"text/plain",
false
);

View File

@@ -99,7 +99,7 @@
// differences.
synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {accelKey: true});
let actual = SpecialPowers.getClipboardData("text/unicode");
let actual = SpecialPowers.getClipboardData("text/plain");
actual = actual.replace(/\(pid \d+\)/g, "(pid NNN)");
if (actual.trim() === aExpected.trim()) {

View File

@@ -50,7 +50,7 @@
// differences.
synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {accelKey: true});
let actual = SpecialPowers.getClipboardData("text/unicode");
let actual = SpecialPowers.getClipboardData("text/plain");
actual = actual.replace(/\(pid \d+\)/, "(pid NNN)");
if (actual.trim() === aExpected.trim()) {

View File

@@ -105,7 +105,7 @@
// differences.
synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {accelKey: true});
let actual = SpecialPowers.getClipboardData("text/unicode");
let actual = SpecialPowers.getClipboardData("text/plain");
// If we have more than 1000 chars, we've probably successfully
// copy+pasted.

View File

@@ -179,7 +179,7 @@ add_task(async function test_contentscript_clipboard_permission_writetext() {
await extension.startup();
let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html");
await extension.awaitMessage("ready");
const actual = SpecialPowers.getClipboardData("text/unicode");
const actual = SpecialPowers.getClipboardData("text/plain");
is(actual, "HI", "right string copied by write");
win.close();
await extension.unload();
@@ -219,7 +219,7 @@ add_task(async function test_contentscript_clipboard_permission_readtext() {
};
await SimpleTest.promiseClipboardChange("HI", () => {
SpecialPowers.clipboardCopyString("HI");
}, "text/unicode");
}, "text/plain");
let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup();
let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html");
@@ -262,7 +262,7 @@ add_task(async function test_contentscript_clipboard_permission_write() {
await extension.startup();
let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html");
await extension.awaitMessage("ready");
const actual = SpecialPowers.getClipboardData("text/unicode");
const actual = SpecialPowers.getClipboardData("text/plain");
is(actual, "HI", "right string copied by write");
win.close();
await extension.unload();
@@ -303,7 +303,7 @@ add_task(async function test_contentscript_clipboard_permission_read() {
};
await SimpleTest.promiseClipboardChange("HELLO", () => {
SpecialPowers.clipboardCopyString("HELLO");
}, "text/unicode");
}, "text/plain");
let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup();
let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html");

View File

@@ -101,7 +101,7 @@ add_task(async function test_downloading_pdf_nonprivate_window() {
SpecialPowers.clipboardCopyString("");
DownloadsCommon.copyDownloadLink(dl);
const copiedUrl = SpecialPowers.getClipboardData("text/unicode");
const copiedUrl = SpecialPowers.getClipboardData("text/plain");
is(copiedUrl, pdfUrl, "The copied url must be the original one");
is(

View File

@@ -430,7 +430,7 @@ export var PlacesUtils = {
// Place entries formatted as HTML anchors
TYPE_HTML: "text/html",
// Place entries as raw URL text
TYPE_UNICODE: "text/unicode",
TYPE_PLAINTEXT: "text/plain",
// Used to track the action that populated the clipboard.
TYPE_X_MOZ_PLACE_ACTION: "text/x-moz-place-action",
@@ -1102,7 +1102,7 @@ export var PlacesUtils = {
}
}
// Otherwise, we wrap as TYPE_UNICODE.
// Otherwise, we wrap as TYPE_PLAINTEXT.
return gatherDataFromNode(aNode, gatherDataText);
},
@@ -1158,11 +1158,11 @@ export var PlacesUtils = {
}
break;
}
case this.TYPE_UNICODE: {
case this.TYPE_PLAINTEXT: {
let parts = blob.split("\n");
for (let i = 0; i < parts.length; i++) {
let uriString = parts[i];
// text/uri-list is converted to TYPE_UNICODE but it could contain
// text/uri-list is converted to TYPE_PLAINTEXT but it could contain
// comments line prepended by #, we should skip them, as well as
// empty uris.
if (uriString.substr(0, 1) == "\x23" || uriString == "") {

View File

@@ -20,9 +20,9 @@ add_task(function() {
PlacesUtils.TYPE_X_MOZ_URL,
],
// Single url.
["place:type=0&sort=1:", PlacesUtils.TYPE_UNICODE],
["place:type=0&sort=1:", PlacesUtils.TYPE_PLAINTEXT],
// Multiple urls.
["place:type=0&sort=1:\nplace:type=0&sort=1", PlacesUtils.TYPE_UNICODE],
["place:type=0&sort=1:\nplace:type=0&sort=1", PlacesUtils.TYPE_PLAINTEXT],
];
for (let [blob, type] of tests) {
Assert.deepEqual(

View File

@@ -45,7 +45,7 @@ add_task(async function test_readerModeURLDrag() {
urlBarContainer.click();
urlbar.dispatchEvent(urlEvent);
let newUrl = urlEvent.dataTransfer.getData("text/unicode");
let newUrl = urlEvent.dataTransfer.getData("text/plain");
ok(!newUrl.includes("about:reader"), "URL does not contain about:reader");
Assert.equal(newUrl, oldUrl, "URL is the same");

View File

@@ -1377,8 +1377,8 @@ function copyRawDataToClipboard(button) {
"@mozilla.org/widget/transferable;1"
].createInstance(Ci.nsITransferable);
transferable.init(getLoadContext());
transferable.addDataFlavor("text/unicode");
transferable.setTransferData("text/unicode", str);
transferable.addDataFlavor("text/plain");
transferable.setTransferData("text/plain", str);
Services.clipboard.setData(
transferable,
null,
@@ -1422,9 +1422,9 @@ async function copyContentsToClipboard() {
transferable.setTransferData("text/html", ssHtml);
// Add the plain text flavor.
transferable.addDataFlavor("text/unicode");
transferable.addDataFlavor("text/plain");
ssText.data = dataText;
transferable.setTransferData("text/unicode", ssText);
transferable.setTransferData("text/plain", ssText);
// Store the data into the clipboard.
Services.clipboard.setData(

View File

@@ -821,12 +821,12 @@ export function GetClipboardSearchString(aLoadContext) {
Ci.nsITransferable
);
trans.init(aLoadContext);
trans.addDataFlavor("text/unicode");
trans.addDataFlavor("text/plain");
Services.clipboard.getData(trans, Ci.nsIClipboard.kFindClipboard);
let data = {};
trans.getTransferData("text/unicode", data);
trans.getTransferData("text/plain", data);
if (data.value) {
data = data.value.QueryInterface(Ci.nsISupportsString);
searchString = data.toString();

View File

@@ -105,7 +105,7 @@ function convertHTMLToPlainText(html) {
input.data = html.replace(/\n/g, "<br>");
var output = {};
converter.convert("text/html", input, "text/unicode", output);
converter.convert("text/html", input, "text/plain", output);
if (output.value instanceof Ci.nsISupportsString) {
return output.value.data.replace(/\r\n/g, "\n");

View File

@@ -15,7 +15,7 @@ using namespace mozilla;
NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard)
/* The Android clipboard only supports text and doesn't support mime types
* so we assume all clipboard data is text/unicode for now. Documentation
* so we assume all clipboard data is text/plain for now. Documentation
* indicates that support for other data types is planned for future
* releases.
*/
@@ -38,10 +38,10 @@ nsClipboard::SetData(nsITransferable* aTransferable, nsIClipboardOwner* anOwner,
nsAutoString text;
for (auto& flavorStr : flavors) {
if (flavorStr.EqualsLiteral(kUnicodeMime)) {
if (flavorStr.EqualsLiteral(kTextMime)) {
nsCOMPtr<nsISupports> item;
nsresult rv =
aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(item));
aTransferable->GetTransferData(kTextMime, getter_AddRefs(item));
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
@@ -89,7 +89,7 @@ nsClipboard::GetData(nsITransferable* aTransferable, int32_t aWhichClipboard) {
aTransferable->FlavorsTransferableCanImport(flavors);
for (auto& flavorStr : flavors) {
if (flavorStr.EqualsLiteral(kUnicodeMime) ||
if (flavorStr.EqualsLiteral(kTextMime) ||
flavorStr.EqualsLiteral(kHTMLMime)) {
auto text = java::Clipboard::GetData(
java::GeckoAppShell::GetApplicationContext(), flavorStr);

View File

@@ -4513,7 +4513,7 @@ static CFTypeRefPtr<CFURLRef> GetPasteLocation(NSPasteboard* aPasteboard) {
if (NS_FAILED(rv)) return NO;
trans->Init(nullptr);
trans->AddDataFlavor(kUnicodeMime);
trans->AddDataFlavor(kTextMime);
trans->AddDataFlavor(kHTMLMime);
rv = nsClipboard::TransferableFromPasteboard(trans, pboard);

View File

@@ -146,7 +146,9 @@ nsresult nsClipboard::TransferableFromPasteboard(nsITransferable* aTransferable,
}
NSData* stringData;
if ([pboardType isEqualToString:[UTIHelper stringFromPboardType:NSPasteboardTypeRTF]]) {
bool isRTF =
[pboardType isEqualToString:[UTIHelper stringFromPboardType:NSPasteboardTypeRTF]];
if (isRTF) {
stringData = [pString dataUsingEncoding:NSASCIIStringEncoding];
} else {
stringData = [pString dataUsingEncoding:NSUnicodeStringEncoding];
@@ -160,7 +162,7 @@ nsresult nsClipboard::TransferableFromPasteboard(nsITransferable* aTransferable,
// The DOM only wants LF, so convert from MacOS line endings to DOM line endings.
int32_t signedDataLength = dataLength;
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(flavorStr, &clipboardDataPtr,
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(isRTF, &clipboardDataPtr,
&signedDataLength);
dataLength = signedDataLength;
@@ -700,7 +702,7 @@ NSDictionary* nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTran
}
bool nsClipboard::IsStringType(const nsCString& aMIMEType, NSString** aPboardType) {
if (aMIMEType.EqualsLiteral(kUnicodeMime)) {
if (aMIMEType.EqualsLiteral(kTextMime)) {
*aPboardType = [UTIHelper stringFromPboardType:NSPasteboardTypeString];
return true;
} else if (aMIMEType.EqualsLiteral(kRTFMime)) {

View File

@@ -1693,7 +1693,7 @@ void nsCocoaUtils::SetTransferDataForTypeFromPasteboardItem(nsITransferable* aTr
}
NSString* pString = nil;
if (aFlavor.EqualsLiteral(kUnicodeMime)) {
if (aFlavor.EqualsLiteral(kTextMime)) {
pString = nsCocoaUtils::GetStringForTypeFromPasteboardItem(
aItem, [UTIHelper stringFromPboardType:NSPasteboardTypeString]);
} else if (aFlavor.EqualsLiteral(kHTMLMime)) {
@@ -1720,7 +1720,8 @@ void nsCocoaUtils::SetTransferDataForTypeFromPasteboardItem(nsITransferable* aTr
}
if (pString) {
NSData* stringData;
if (aFlavor.EqualsLiteral(kRTFMime)) {
bool isRTF = aFlavor.EqualsLiteral(kRTFMime);
if (isRTF) {
stringData = [pString dataUsingEncoding:NSASCIIStringEncoding];
} else {
stringData = [pString dataUsingEncoding:NSUnicodeStringEncoding];
@@ -1734,8 +1735,7 @@ void nsCocoaUtils::SetTransferDataForTypeFromPasteboardItem(nsITransferable* aTr
// The DOM only wants LF, so convert from MacOS line endings to DOM line endings.
int32_t signedDataLength = dataLength;
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(aFlavor, &clipboardDataPtr,
&signedDataLength);
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(isRTF, &clipboardDataPtr, &signedDataLength);
dataLength = signedDataLength;
// skip BOM (Byte Order Mark to distinguish little or big endian)

View File

@@ -348,7 +348,7 @@ nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) {
if (dataFlavor.EqualsLiteral(kFileMime)) {
type = [UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL];
allowFileURL = true;
} else if (dataFlavor.EqualsLiteral(kUnicodeMime)) {
} else if (dataFlavor.EqualsLiteral(kTextMime)) {
type = [UTIHelper stringFromPboardType:NSPasteboardTypeString];
} else if (dataFlavor.EqualsLiteral(kHTMLMime)) {
type = [UTIHelper stringFromPboardType:NSPasteboardTypeHTML];

View File

@@ -282,8 +282,8 @@ nsClipboard::SetData(nsITransferable* aTransferable, nsIClipboardOwner* aOwner,
nsCString& flavorStr = flavors[i];
LOGCLIP(" processing target %s\n", flavorStr.get());
// Special case text/unicode since we can handle all of the string types.
if (flavorStr.EqualsLiteral(kUnicodeMime)) {
// Special case text/plain since we can handle all of the string types.
if (flavorStr.EqualsLiteral(kTextMime)) {
LOGCLIP(" adding TEXT targets\n");
gtk_target_list_add_text_targets(list, 0);
continue;
@@ -473,7 +473,7 @@ static bool TransferableSetHTML(nsITransferable* aTransferable,
Span<const char> aData) {
nsLiteralCString mimeType(kHTMLMime);
// Convert text/html into our unicode format
// Convert text/html into our text format
nsAutoCString charset;
if (!GetHTMLCharset(aData, charset)) {
// Fall back to utf-8 in case html/data is missing kHTMLMarkupPrefix.
@@ -577,27 +577,27 @@ nsClipboard::GetData(nsITransferable* aTransferable, int32_t aWhichClipboard) {
return NS_OK;
}
// Special case text/unicode since we can convert any
// string into text/unicode
if (flavorStr.EqualsLiteral(kUnicodeMime)) {
LOGCLIP(" Getting unicode %s MIME clipboard data\n", flavorStr.get());
// Special case text/plain since we can convert any
// string into text/plain
if (flavorStr.EqualsLiteral(kTextMime)) {
LOGCLIP(" Getting text %s MIME clipboard data\n", flavorStr.get());
auto clipboardData = mContext->GetClipboardText(aWhichClipboard);
if (!clipboardData) {
LOGCLIP(" failed to get unicode data\n");
// If the type was text/unicode and we couldn't get
LOGCLIP(" failed to get text data\n");
// If the type was text/plain and we couldn't get
// text off the clipboard, run the next loop
// iteration.
continue;
}
// Convert utf-8 into our unicode format.
// Convert utf-8 into our text format.
NS_ConvertUTF8toUTF16 ucs2string(clipboardData.get());
SetTransferableData(aTransferable, flavorStr,
(const char*)ucs2string.BeginReading(),
ucs2string.Length() * 2);
LOGCLIP(" got unicode data, length %zd\n", ucs2string.Length());
LOGCLIP(" got text data, length %zd\n", ucs2string.Length());
return NS_OK;
}
@@ -706,14 +706,14 @@ static RefPtr<GenericPromise> AsyncGetTextImpl(nsITransferable* aTransferable,
// Convert utf-8 into our unicode format.
NS_ConvertUTF8toUTF16 utf16string(aText, dataLength);
nsLiteralCString flavor(kUnicodeMime);
nsLiteralCString flavor(kTextMime);
SetTransferableData(ref->mTransferable, flavor,
(const char*)utf16string.BeginReading(),
utf16string.Length() * 2);
LOGCLIP(" text is set, length = %d", (int)dataLength);
ref->mDataPromise->Resolve(true, __func__);
},
new DataPromiseHandler(aTransferable, dataPromise, kUnicodeMime));
new DataPromiseHandler(aTransferable, dataPromise, kTextMime));
return dataPromise;
}
@@ -812,9 +812,9 @@ static RefPtr<GenericPromise> AsyncGetDataFlavor(nsITransferable* aTransferable,
return AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(),
DATATYPE_IMAGE);
}
// Special case text/unicode since we can convert any
// string into text/unicode
if (aFlavorStr.EqualsLiteral(kUnicodeMime)) {
// Special case text/plain since we can convert any
// string into text/plain
if (aFlavorStr.EqualsLiteral(kTextMime)) {
LOGCLIP(" Getting unicode clipboard data");
return AsyncGetTextImpl(aTransferable, aWhichClipboard);
}
@@ -984,12 +984,12 @@ nsClipboard::HasDataMatchingFlavors(const nsTArray<nsCString>& aFlavorList,
// Walk through the provided types and try to match it to a
// provided type.
for (auto& flavor : aFlavorList) {
// We special case text/unicode here.
if (flavor.EqualsLiteral(kUnicodeMime) &&
// We special case text/plain here.
if (flavor.EqualsLiteral(kTextMime) &&
gtk_targets_include_text(targets.AsSpan().data(),
targets.AsSpan().Length())) {
*_retval = true;
LOGCLIP(" has kUnicodeMime\n");
LOGCLIP(" has kTextMime\n");
return NS_OK;
}
for (const auto& target : targets.AsSpan()) {
@@ -1041,11 +1041,10 @@ RefPtr<DataFlavorsPromise> nsClipboard::AsyncHasDataMatchingFlavors(
if (targetsNum) {
for (auto& flavor : handler->mAcceptedFlavorList) {
LOGCLIP(" looking for %s", flavor.get());
// We can convert any text to unicode.
if (flavor.EqualsLiteral(kUnicodeMime) &&
if (flavor.EqualsLiteral(kTextMime) &&
gtk_targets_include_text(targets, targetsNum)) {
results.AppendElement(flavor);
LOGCLIP(" has kUnicodeMime\n");
LOGCLIP(" has kTextMime\n");
continue;
}
for (int i = 0; i < targetsNum; i++) {
@@ -1085,7 +1084,7 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
GtkSelectionData* aSelectionData) {
// Someone has asked us to hand them something. The first thing
// that we want to do is see if that something includes text. If
// it does, try to give it text/unicode after converting it to
// it does, try to give it text/plain after converting it to
// utf-8.
int32_t whichClipboard;
@@ -1119,13 +1118,13 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard,
// Check to see if the selection data is some text type.
if (gtk_targets_include_text(&selectionTarget, 1)) {
LOGCLIP(" providing text/unicode data\n");
LOGCLIP(" providing text/plain data\n");
// Try to convert our internal type into a text string. Get
// the transferable for this clipboard and try to get the
// text/unicode type for it.
rv = trans->GetTransferData("text/unicode", getter_AddRefs(item));
// text/plain type for it.
rv = trans->GetTransferData("text/plain", getter_AddRefs(item));
if (NS_FAILED(rv) || !item) {
LOGCLIP(" GetTransferData() failed to get text/unicode!\n");
LOGCLIP(" GetTransferData() failed to get text/plain!\n");
return;
}

View File

@@ -797,7 +797,13 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) {
// format. SetTransferData() implicitly handles conversions.
for (uint32_t i = 0; i < flavors.Length(); ++i) {
nsCString& flavorStr = flavors[i];
GdkAtom gdkFlavor = gdk_atom_intern(flavorStr.get(), FALSE);
GdkAtom gdkFlavor;
if (flavorStr.EqualsLiteral(kTextMime)) {
gdkFlavor = gdk_atom_intern(gTextPlainUTF8Type, FALSE);
} else {
gdkFlavor = gdk_atom_intern(flavorStr.get(), FALSE);
}
LOGDRAGSERVICE(" we're getting data %s (gdk flavor %p)\n", flavorStr.get(),
gdkFlavor);
bool dataFound = false;
@@ -854,46 +860,15 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) {
}
}
// if we are looking for text/unicode and we fail to find it
// on the clipboard first, try again with text/plain. If that
// is present, convert it to unicode.
if (flavorStr.EqualsLiteral(kUnicodeMime)) {
LOGDRAGSERVICE(" conversion %s => %s", kUnicodeMime,
gTextPlainUTF8Type);
gdkFlavor = gdk_atom_intern(gTextPlainUTF8Type, FALSE);
GetTargetDragData(gdkFlavor, dragFlavors);
if (mTargetDragData) {
const char* castedText = reinterpret_cast<char*>(mTargetDragData);
char16_t* convertedText = nullptr;
NS_ConvertUTF8toUTF16 ucs2string(castedText, mTargetDragDataLen);
convertedText = ToNewUnicode(ucs2string, mozilla::fallible);
if (convertedText) {
// out with the old, in with the new
g_free(mTargetDragData);
mTargetDragData = convertedText;
mTargetDragDataLen = ucs2string.Length() * 2;
dataFound = true;
} // if plain text data on clipboard
} else {
LOGDRAGSERVICE(" conversion %s => %s", kUnicodeMime, kTextMime);
// If we are looking for text/plain, try again with non utf-8 text.
if (flavorStr.EqualsLiteral(kTextMime)) {
LOGDRAGSERVICE(" conversion %s => %s", kTextMime, kTextMime);
gdkFlavor = gdk_atom_intern(kTextMime, FALSE);
GetTargetDragData(gdkFlavor, dragFlavors);
if (mTargetDragData) {
const char* castedText = reinterpret_cast<char*>(mTargetDragData);
char16_t* convertedText = nullptr;
uint32_t convertedTextLen = 0;
UTF8ToNewUTF16(castedText, mTargetDragDataLen, &convertedText,
&convertedTextLen);
if (convertedText) {
// out with the old, in with the new
g_free(mTargetDragData);
mTargetDragData = convertedText;
mTargetDragDataLen = convertedTextLen * 2;
dataFound = true;
} // if plain text data on clipboard
} // if plain text flavor present
} // if plain text charset=utf-8 flavor present
} // if looking for text/unicode
} // if looking for text/plain
// if we are looking for text/x-moz-url and we failed to find
// it on the clipboard, try again with text/uri-list, and then
@@ -945,6 +920,18 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) {
LOGDRAGSERVICE(" actual data found %s\n",
GUniquePtr<gchar>(gdk_atom_name(gdkFlavor)).get());
if (flavorStr.EqualsLiteral(kTextMime)) {
// The text is in UTF-8, so convert the text into UTF-16
const char* text = static_cast<char*>(mTargetDragData);
NS_ConvertUTF8toUTF16 ucs2string(text, mTargetDragDataLen);
char16_t* convertedText = ToNewUnicode(ucs2string, mozilla::fallible);
if (convertedText) {
g_free(mTargetDragData);
mTargetDragData = convertedText;
mTargetDragDataLen = ucs2string.Length() * 2;
}
}
if (flavorStr.EqualsLiteral(kJPEGImageMime) ||
flavorStr.EqualsLiteral(kJPGImageMime) ||
flavorStr.EqualsLiteral(kPNGImageMime) ||
@@ -963,7 +950,7 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) {
// the DOM only wants LF, so convert from MacOS line endings
// to DOM line endings.
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(
flavorStr, &mTargetDragData,
flavorStr.EqualsLiteral(kRTFMime), &mTargetDragData,
reinterpret_cast<int*>(&mTargetDragDataLen));
}
@@ -1062,11 +1049,6 @@ nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) {
(strcmp(aDataFlavor, kURLMime) == 0)) {
*_retval = true;
}
// check for auto text/plain -> text/unicode mapping
else if (strcmp(name.get(), kTextMime) == 0 &&
(strcmp(aDataFlavor, kUnicodeMime) == 0)) {
*_retval = true;
}
if (*_retval) {
LOGDRAGSERVICE(" supported, with converting %s => %s", name.get(),
@@ -1374,13 +1356,9 @@ GtkTargetList* nsDragService::GetSourceList(void) {
if (flavorStr.EqualsLiteral(kFileMime)) {
TargetArrayAddTarget(targetArray, gTextUriListType);
}
// Check to see if this is text/unicode.
// If it is, add text/plain
// since we automatically support text/plain
// if we support text/unicode.
else if (flavorStr.EqualsLiteral(kUnicodeMime)) {
// Check to see if this is text/plain.
else if (flavorStr.EqualsLiteral(kTextMime)) {
TargetArrayAddTarget(targetArray, gTextPlainUTF8Type);
TargetArrayAddTarget(targetArray, kTextMime);
}
// Check to see if this is the x-moz-url type.
// If it is, add _NETSCAPE_URL
@@ -2051,7 +2029,7 @@ void nsDragService::SourceDataGet(GtkWidget* aWidget, GdkDragContext* aContext,
if (mimeFlavor.EqualsLiteral(kTextMime) ||
mimeFlavor.EqualsLiteral(gTextPlainUTF8Type)) {
SourceDataGetText(item, nsDependentCString(kUnicodeMime),
SourceDataGetText(item, nsDependentCString(kTextMime),
/* aNeedToDoConversionToPlainText */ true,
aSelectionData);
// no fallback for text mime types

View File

@@ -29,8 +29,7 @@ HeadlessClipboard::SetData(nsITransferable* aTransferable,
// Only support plain text for now.
nsCOMPtr<nsISupports> clip;
nsresult rv =
aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(clip));
nsresult rv = aTransferable->GetTransferData(kTextMime, getter_AddRefs(clip));
if (NS_FAILED(rv)) {
return rv;
}
@@ -60,7 +59,7 @@ HeadlessClipboard::GetData(nsITransferable* aTransferable,
return rv;
}
nsCOMPtr<nsISupports> genericDataWrapper = do_QueryInterface(dataWrapper);
rv = aTransferable->SetTransferData(kUnicodeMime, genericDataWrapper);
rv = aTransferable->SetTransferData(kTextMime, genericDataWrapper);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@@ -86,7 +85,7 @@ HeadlessClipboard::HasDataMatchingFlavors(
}
// Retrieve the union of all aHasType in aFlavorList
for (auto& flavor : aFlavorList) {
if (flavor.EqualsLiteral(kUnicodeMime) && mClipboard->HasText()) {
if (flavor.EqualsLiteral(kTextMime) && mClipboard->HasText()) {
*aHasType = true;
break;
}

View File

@@ -10,13 +10,13 @@ function getString(clipboard) {
Ci.nsITransferable
);
trans.init(null);
trans.addDataFlavor("text/unicode");
trans.addDataFlavor("text/plain");
clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
try {
var data = {};
trans.getTransferData("text/unicode", data);
trans.getTransferData("text/plain", data);
if (data) {
data = data.value.QueryInterface(Ci.nsISupportsString);

View File

@@ -73,7 +73,7 @@ nsClipboardHelper::CopyStringToClipboard(const nsAString& aString,
}
// Add the text data flavor to the transferable
rv = trans->AddDataFlavor(kUnicodeMime);
rv = trans->AddDataFlavor(kTextMime);
NS_ENSURE_SUCCESS(rv, rv);
// get wStrings to hold clip data
@@ -93,7 +93,7 @@ nsClipboardHelper::CopyStringToClipboard(const nsAString& aString,
NS_ENSURE_TRUE(genericData, NS_ERROR_FAILURE);
// set the transfer data
rv = trans->SetTransferData(kUnicodeMime, genericData);
rv = trans->SetTransferData(kTextMime, genericData);
NS_ENSURE_SUCCESS(rv, rv);
// put the transferable on the clipboard

View File

@@ -46,7 +46,7 @@ nsHTMLFormatConverter::GetInputDataFlavors(nsTArray<nsCString>& aFlavors) {
NS_IMETHODIMP
nsHTMLFormatConverter::GetOutputDataFlavors(nsTArray<nsCString>& aFlavors) {
aFlavors.AppendElement(nsLiteralCString(kHTMLMime));
aFlavors.AppendElement(nsLiteralCString(kUnicodeMime));
aFlavors.AppendElement(nsLiteralCString(kTextMime));
return NS_OK;
}
@@ -63,10 +63,11 @@ nsHTMLFormatConverter::CanConvert(const char* aFromDataFlavor,
*_retval = false;
if (!nsCRT::strcmp(aFromDataFlavor, kHTMLMime)) {
if (!nsCRT::strcmp(aToDataFlavor, kHTMLMime))
if (!nsCRT::strcmp(aToDataFlavor, kHTMLMime)) {
*_retval = true;
else if (!nsCRT::strcmp(aToDataFlavor, kUnicodeMime))
} else if (!nsCRT::strcmp(aToDataFlavor, kTextMime)) {
*_retval = true;
}
#if NOT_NOW
// pinkerton
// no one uses this flavor right now, so it's just slowing things down. If
@@ -120,7 +121,7 @@ nsHTMLFormatConverter::Convert(const char* aFromDataFlavor,
dataWrapper0->GetData(dataStr); // COPY #1
// note: conversion to text/plain is done inside the clipboard. we do not
// need to worry about it here.
if (toFlavor.Equals(kHTMLMime) || toFlavor.Equals(kUnicodeMime)) {
if (toFlavor.Equals(kHTMLMime) || toFlavor.Equals(kTextMime)) {
nsresult res;
if (toFlavor.Equals(kHTMLMime)) {
int32_t dataLen = dataStr.Length() * 2;

View File

@@ -23,7 +23,6 @@ interface nsIPrincipal;
// by the entire app.
#define kTextMime "text/plain"
#define kRTFMime "text/rtf"
#define kUnicodeMime "text/unicode"
#define kMozTextInternal "text/x-moz-text-internal" // text data which isn't suppoed to be parsed by other apps.
#define kHTMLMime "text/html"
#define kAOLMailMime "AOLMAIL"

View File

@@ -43,8 +43,7 @@ void nsPrimitiveHelpers ::CreatePrimitiveForData(const nsACString& aFlavor,
nsISupports** aPrimitive) {
if (!aPrimitive) return;
if (aFlavor.EqualsLiteral(kTextMime) ||
aFlavor.EqualsLiteral(kNativeHTMLMime) ||
if (aFlavor.EqualsLiteral(kNativeHTMLMime) ||
aFlavor.EqualsLiteral(kRTFMime) ||
aFlavor.EqualsLiteral(kCustomTypesMime)) {
nsCOMPtr<nsISupportsCString> primitive =
@@ -97,8 +96,7 @@ void nsPrimitiveHelpers ::CreatePrimitiveForCFHTML(const void* aDataBuff,
void* utf8 = moz_xmalloc(*aDataLen);
memcpy(utf8, aDataBuff, *aDataLen);
int32_t signedLen = static_cast<int32_t>(*aDataLen);
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(
nsDependentCString(kTextMime), &utf8, &signedLen);
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(true, &utf8, &signedLen);
*aDataLen = signedLen;
nsAutoString str(
@@ -125,8 +123,7 @@ void nsPrimitiveHelpers::CreateDataFromPrimitive(const nsACString& aFlavor,
*aDataBuff = nullptr;
*aDataLen = 0;
if (aFlavor.EqualsLiteral(kTextMime) ||
aFlavor.EqualsLiteral(kCustomTypesMime)) {
if (aFlavor.EqualsLiteral(kCustomTypesMime)) {
nsCOMPtr<nsISupportsCString> plainText(do_QueryInterface(aPrimitive));
if (plainText) {
nsAutoCString data;
@@ -156,13 +153,14 @@ void nsPrimitiveHelpers::CreateDataFromPrimitive(const nsACString& aFlavor,
// NOTE: this assumes that it can use 'free' to dispose of the old buffer.
//
nsresult nsLinebreakHelpers ::ConvertPlatformToDOMLinebreaks(
const nsACString& inFlavor, void** ioData, int32_t* ioLengthInBytes) {
bool aIsSingleByteChars, void** ioData, int32_t* ioLengthInBytes) {
NS_ASSERTION(ioData && *ioData && ioLengthInBytes, "Bad Params");
if (!(ioData && *ioData && ioLengthInBytes)) return NS_ERROR_INVALID_ARG;
nsresult retVal = NS_OK;
if (inFlavor.EqualsLiteral(kTextMime) || inFlavor.EqualsLiteral(kRTFMime)) {
// RTF and CF_HTML on Windows are transfered as single-byte characters.
if (aIsSingleByteChars) {
char* buffAsChars = reinterpret_cast<char*>(*ioData);
char* oldBuffer = buffAsChars;
retVal = nsLinebreakConverter::ConvertLineBreaksInSitu(
@@ -174,8 +172,6 @@ nsresult nsLinebreakHelpers ::ConvertPlatformToDOMLinebreaks(
free(oldBuffer);
*ioData = buffAsChars;
}
} else if (inFlavor.EqualsLiteral("image/jpeg")) {
// I'd assume we don't want to do anything for binary data....
} else {
char16_t* buffAsUnichar = reinterpret_cast<char16_t*>(*ioData);
char16_t* oldBuffer = buffAsUnichar;

View File

@@ -45,7 +45,7 @@ class nsLinebreakHelpers {
// taken care of internally, see the note below).
//
// NOTE: this assumes that it can use 'free' to dispose of the old buffer.
static nsresult ConvertPlatformToDOMLinebreaks(const nsACString& inFlavor,
static nsresult ConvertPlatformToDOMLinebreaks(bool aIsSingleByteChars,
void** ioData,
int32_t* ioLengthInBytes);

View File

@@ -111,8 +111,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1123480
var Suppstr = nsSupportsString();
Suppstr.data = Ipsum;
Transfer.init(Loadctx);
Transfer.addDataFlavor("text/unicode");
Transfer.setTransferData("text/unicode", Suppstr);
Transfer.addDataFlavor("text/plain");
Transfer.setTransferData("text/plain", Suppstr);
// Enabled private browsing mode should not cache any selection to disk; disabled should
if (private) {
@@ -132,7 +132,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);
Transfer.setTransferData("text/plain", Suppstr);
await new Promise(resolve => setTimeout(resolve, 0));
is(getClipboardCacheFDCount(), initialFdCount, "should drop the cache file, if any.");

View File

@@ -21,13 +21,13 @@ var transferable = Cc['@mozilla.org/widget/transferable;1']
.createInstance(Ci.nsITransferable);
transferable.init(getLoadContext());
transferable.addDataFlavor("text/unicode");
transferable.setTransferData("text/unicode", document);
transferable.addDataFlavor("text/plain");
transferable.setTransferData("text/plain", document);
Services.clipboard.setData(transferable, null, Ci.nsIClipboard.kGlobalClipboard);
transferable.setTransferData("text/unicode", null);
transferable.setTransferData("text/plain", 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/plain type");
</script>
</window>

View File

@@ -31,11 +31,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=948065
let trans = Cc['@mozilla.org/widget/transferable;1']
.createInstance(Ci.nsITransferable);
trans.init(getLoadContext());
trans.addDataFlavor("text/unicode");
trans.addDataFlavor("text/plain");
clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
let str = {};
try {
trans.getTransferData('text/unicode', str);
trans.getTransferData('text/plain', str);
} catch (e) {
str = '';
}

View File

@@ -58,17 +58,17 @@ clipboardTypes.forEach(function(type) {
add_task(function test_clipboard_hasDataMatchingFlavors() {
info(`Test write data to clipboard type ${type}`);
// Write text/unicode data to main clipboard.
writeStringToClipboard(GenerateRandomString(), "text/unicode", clipboard.kGlobalClipboard);
ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard),
"Should have text/unicode flavor");
// Write text/plain data to main clipboard.
writeStringToClipboard(GenerateRandomString(), "text/plain", clipboard.kGlobalClipboard);
ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard),
"Should have text/plain flavor");
ok(!clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard),
"Should not have text/html flavor");
// Write text/html data to other clipboard.
writeStringToClipboard(GenerateRandomString(), "text/html", type);
ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard),
"Should have text/unicode flavor");
ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard),
"Should have text/plain flavor");
ok(!clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard),
"Should not have text/html flavor");

View File

@@ -24,12 +24,12 @@
function assignTextToTransferable(transferable, string) {
var Suppstr = nsSupportsString();
Suppstr.data = string;
transferable.setTransferData("text/unicode", Suppstr);
transferable.setTransferData("text/plain", Suppstr);
}
function checkTransferableText(transferable, expectedString, description) {
var data = {};
transferable.getTransferData("text/unicode", data);
transferable.getTransferData("text/plain", data);
var actualValue = data.value.QueryInterface(Ci.nsISupportsString).data;
// Use ok + shortenString instead of is(...) to avoid dumping millions of characters in the output.
ok(actualValue === expectedString, description + ": text should match. " +
@@ -89,7 +89,7 @@
var Loadctx = PrivateBrowsingUtils.privacyContextFromWindow(win);
var Transfer = nsTransferable();
Transfer.init(Loadctx);
Transfer.addDataFlavor("text/unicode");
Transfer.addDataFlavor("text/plain");
var initialFdCount = isFDCountingSupported() ? getClipboardCacheFDCount() : -1;
assignTextToTransferable(Transfer, BIG_STRING);
@@ -117,7 +117,7 @@
var Transfer2 = nsTransferable();
Transfer2.init(Loadctx);
Transfer2.addDataFlavor("text/unicode");
Transfer2.addDataFlavor("text/plain");
// Iniitalize with a small string, so we can see that mData -> mCacheFD works.
assignTextToTransferable(Transfer2, SMALL_STRING);

View File

@@ -99,8 +99,6 @@ UINT nsClipboard::GetFormat(const char* aMimeStr, bool aMapHTMLMime) {
UINT format;
if (strcmp(aMimeStr, kTextMime) == 0) {
format = CF_TEXT;
} else if (strcmp(aMimeStr, kUnicodeMime) == 0) {
format = CF_UNICODETEXT;
} else if (strcmp(aMimeStr, kRTFMime) == 0) {
format = ::RegisterClipboardFormat(L"Rich Text Format");
@@ -210,9 +208,9 @@ nsresult nsClipboard::SetupNativeDataObject(
// Do various things internal to the implementation, like map one
// flavor to another or add additional flavors based on what's required
// for the win32 impl.
if (flavorStr.EqualsLiteral(kUnicodeMime)) {
// if we find text/unicode, also advertise text/plain (which we will
// convert on our own in nsDataObj::GetText().
if (flavorStr.EqualsLiteral(kTextMime)) {
// if we find text/plain, also add CF_TEXT, but we can add it for
// text/plain as well.
FORMATETC textFE;
SET_FORMATETC(textFE, CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
dObj->AddDataFlavor(kTextMime, &textFE);
@@ -888,7 +886,7 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject* aDataObject,
// when directly asking for the flavor. Let's try digging around in other
// flavors to help satisfy our craving for data.
if (!dataFound) {
if (flavorStr.EqualsLiteral(kUnicodeMime)) {
if (flavorStr.EqualsLiteral(kTextMime)) {
dataFound =
FindUnicodeFromPlainText(aDataObject, anIndex, &data, &dataLen);
} else if (flavorStr.EqualsLiteral(kURLMime)) {
@@ -954,14 +952,15 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject* aDataObject,
} else {
// Treat custom types as a string of bytes.
if (!flavorStr.EqualsLiteral(kCustomTypesMime)) {
bool isRTF = flavorStr.EqualsLiteral(kRTFMime);
// we probably have some form of text. The DOM only wants LF, so
// convert from Win32 line endings to DOM line endings.
int32_t signedLen = static_cast<int32_t>(dataLen);
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(flavorStr, &data,
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(isRTF, &data,
&signedLen);
dataLen = signedLen;
if (flavorStr.EqualsLiteral(kRTFMime)) {
if (isRTF) {
// RTF on Windows is known to sometimes deliver an extra null byte.
if (dataLen > 0 && static_cast<char*>(data)[dataLen - 1] == '\0') {
dataLen--;
@@ -1049,19 +1048,20 @@ bool nsClipboard ::FindPlatformHTML(IDataObject* inDataObject, UINT inIndex,
//
// FindUnicodeFromPlainText
//
// we are looking for text/unicode and we failed to find it on the clipboard
// first, try again with text/plain. If that is present, convert it to unicode.
// Looks for CF_TEXT on the clipboard and converts it into an UTF-16 string
// if present. Returns this string in outData, and its length in outDataLen.
// XXXndeakin Windows converts between CF_UNICODE and CF_TEXT automatically
// so it doesn't seem like this is actually needed.
//
bool nsClipboard ::FindUnicodeFromPlainText(IDataObject* inDataObject,
UINT inIndex, void** outData,
uint32_t* outDataLen) {
MOZ_LOG(gWin32ClipboardLog, LogLevel::Debug, ("%s", __FUNCTION__));
// we are looking for text/unicode and we failed to find it on the clipboard
// first, try again with text/plain. If that is present, convert it to
// We are looking for text/plain and we failed to find it on the clipboard
// first, so try again with CF_TEXT. If that is present, convert it to
// unicode.
nsresult rv =
GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kTextMime),
nsresult rv = GetNativeDataOffClipboard(inDataObject, inIndex, CF_TEXT,
nullptr, outData, outDataLen);
if (NS_FAILED(rv) || !*outData) {
return false;
@@ -1303,30 +1303,10 @@ NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(
}
for (auto& flavor : aFlavorList) {
#ifdef DEBUG
if (flavor.EqualsLiteral(kTextMime)) {
NS_WARNING(
"DO NOT USE THE text/plain DATA FLAVOR ANY MORE. USE text/unicode "
"INSTEAD");
}
#endif
UINT format = GetFormat(flavor.get());
if (IsClipboardFormatAvailable(format)) {
*_retval = true;
break;
} else {
// We haven't found the exact flavor the client asked for, but maybe we
// can still find it from something else that's on the clipboard...
if (flavor.EqualsLiteral(kUnicodeMime)) {
// client asked for unicode and it wasn't present, check if we have
// CF_TEXT. We'll handle the actual data substitution in the data
// object.
if (IsClipboardFormatAvailable(GetFormat(kTextMime))) {
*_retval = true;
break;
}
}
}
}

View File

@@ -1428,26 +1428,19 @@ HRESULT nsDataObj::GetText(const nsACString& aDataFlavor, FORMATETC& aFE,
STGMEDIUM& aSTG) {
void* data = nullptr;
// if someone asks for text/plain, look up text/unicode instead in the
// transferable.
const char* flavorStr;
const nsPromiseFlatCString& flat = PromiseFlatCString(aDataFlavor);
if (aDataFlavor.EqualsLiteral("text/plain"))
flavorStr = kUnicodeMime;
else
flavorStr = flat.get();
const nsPromiseFlatCString& flavorStr = PromiseFlatCString(aDataFlavor);
// NOTE: CreateDataFromPrimitive creates new memory, that needs to be deleted
nsCOMPtr<nsISupports> genericDataWrapper;
nsresult rv = mTransferable->GetTransferData(
flavorStr, getter_AddRefs(genericDataWrapper));
flavorStr.get(), getter_AddRefs(genericDataWrapper));
if (NS_FAILED(rv) || !genericDataWrapper) {
return E_FAIL;
}
uint32_t len;
nsPrimitiveHelpers::CreateDataFromPrimitive(nsDependentCString(flavorStr),
genericDataWrapper, &data, &len);
nsPrimitiveHelpers::CreateDataFromPrimitive(
nsDependentCString(flavorStr.get()), genericDataWrapper, &data, &len);
if (!data) return E_FAIL;
HGLOBAL hGlobalMemory = nullptr;

View File

@@ -451,13 +451,6 @@ NS_IMETHODIMP
nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) {
if (!aDataFlavor || !mDataObject || !_retval) return NS_ERROR_FAILURE;
#ifdef DEBUG
if (strcmp(aDataFlavor, kTextMime) == 0)
NS_WARNING(
"DO NOT USE THE text/plain DATA FLAVOR ANY MORE. USE text/unicode "
"INSTEAD");
#endif
*_retval = false;
FORMATETC fe;
@@ -494,12 +487,12 @@ nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) {
// We haven't found the exact flavor the client asked for, but
// maybe we can still find it from something else that's on the
// clipboard
if (strcmp(aDataFlavor, kUnicodeMime) == 0) {
// client asked for unicode and it wasn't present, check if we
if (strcmp(aDataFlavor, kTextMime) == 0) {
// If unicode wasn't there, it might exist as CF_TEXT, client asked
// for unicode and it wasn't present, check if we
// have CF_TEXT. We'll handle the actual data substitution in
// the data object.
format = nsClipboard::GetFormat(kTextMime);
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
SET_FORMATETC(fe, CF_TEXT, 0, DVASPECT_CONTENT, -1,
TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI);
if (mDataObject->QueryGetData(&fe) == S_OK)
*_retval = true; // found it!

Some files were not shown because too many files have changed in this diff Show More