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 ""; return "";
} }
trans.addDataFlavor("text/unicode"); trans.addDataFlavor("text/plain");
Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard); Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard);
var str = {}; var str = {};
trans.getTransferData("text/unicode", str); trans.getTransferData("text/plain", str);
if (str) { if (str) {
str = str.value.QueryInterface(Ci.nsISupportsString); str = str.value.QueryInterface(Ci.nsISupportsString);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -168,7 +168,7 @@ PlacesController.prototype = {
case "cmd_paste": case "cmd_paste":
case "placesCmd_paste": case "placesCmd_paste":
// If the clipboard contains a Places flavor it is definitely pasteable, // 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 // We don't check if the data is valid here, because the clipboard may
// contain very large blobs that would largely slowdown commands updating. // contain very large blobs that would largely slowdown commands updating.
// Of course later paste() should ignore any invalid data. // Of course later paste() should ignore any invalid data.
@@ -178,7 +178,7 @@ PlacesController.prototype = {
[ [
...PlacesUIUtils.PLACES_FLAVORS, ...PlacesUIUtils.PLACES_FLAVORS,
PlacesUtils.TYPE_X_MOZ_URL, PlacesUtils.TYPE_X_MOZ_URL,
PlacesUtils.TYPE_UNICODE, PlacesUtils.TYPE_PLAINTEXT,
], ],
Ci.nsIClipboard.kGlobalClipboard Ci.nsIClipboard.kGlobalClipboard
) )
@@ -1049,7 +1049,7 @@ PlacesController.prototype = {
function addURIData(index) { function addURIData(index) {
addData(PlacesUtils.TYPE_X_MOZ_URL, index); addData(PlacesUtils.TYPE_X_MOZ_URL, index);
addData(PlacesUtils.TYPE_UNICODE, index); addData(PlacesUtils.TYPE_PLAINTEXT, index);
addData(PlacesUtils.TYPE_HTML, index); addData(PlacesUtils.TYPE_HTML, index);
} }
@@ -1131,7 +1131,7 @@ PlacesController.prototype = {
{ type: PlacesUtils.TYPE_X_MOZ_PLACE, entries: [] }, { type: PlacesUtils.TYPE_X_MOZ_PLACE, entries: [] },
{ type: PlacesUtils.TYPE_X_MOZ_URL, entries: [] }, { type: PlacesUtils.TYPE_X_MOZ_URL, entries: [] },
{ type: PlacesUtils.TYPE_HTML, 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 // 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_PLACE,
PlacesUtils.TYPE_X_MOZ_URL, PlacesUtils.TYPE_X_MOZ_URL,
PlacesUtils.TYPE_UNICODE, PlacesUtils.TYPE_PLAINTEXT,
].forEach(type => xferable.addDataFlavor(type)); ].forEach(type => xferable.addDataFlavor(type));
Services.clipboard.getData(xferable, Ci.nsIClipboard.kGlobalClipboard); 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; return null;
}, },
@@ -1623,7 +1616,7 @@ var PlacesControllerDragHelper = {
// Following flavors may contain duplicated data. // Following flavors may contain duplicated data.
let duplicable = new Map(); 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()); duplicable.set(PlacesUtils.TYPE_X_MOZ_URL, new Set());
// Collect all data from the DataTransfer before processing it, as the // 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. // 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"]; let effects = ["move", "copy", "link"];
for (let effect of effects) { for (let effect of effects) {
for (let mimeType of mimeTypes) { for (let mimeType of mimeTypes) {

View File

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

View File

@@ -3604,7 +3604,7 @@ export class UrlbarInput {
let title = this.window.gBrowser.contentTitle || href; let title = this.window.gBrowser.contentTitle || href;
event.dataTransfer.setData("text/x-moz-url", `${href}\n${title}`); 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.setData("text/html", `<a href="${href}">${title}</a>`);
event.dataTransfer.effectAllowed = "copyLink"; event.dataTransfer.effectAllowed = "copyLink";
event.stopPropagation(); event.stopPropagation();
@@ -3709,7 +3709,7 @@ function getDroppableData(event) {
} }
} }
// Handle as text. // 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( let primaryAsText = SpecialPowers.getClipboardData(
"text/unicode", "text/plain",
SpecialPowers.Ci.nsIClipboard.kSelectionClipboard SpecialPowers.Ci.nsIClipboard.kSelectionClipboard
); );
Assert.equal(primaryAsText, TEXT_FOR_PRIMARY); Assert.equal(primaryAsText, TEXT_FOR_PRIMARY);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -182,7 +182,7 @@ async function checkCopyEditorValue(view) {
} }
function checkClipboardData(expectedPattern) { function checkClipboardData(expectedPattern) {
const actual = SpecialPowers.getClipboardData("text/unicode"); const actual = SpecialPowers.getClipboardData("text/plain");
const expectedRegExp = new RegExp(expectedPattern, "g"); const expectedRegExp = new RegExp(expectedPattern, "g");
return expectedRegExp.test(actual); return expectedRegExp.test(actual);
} }
@@ -194,7 +194,7 @@ function failedClipboard(expectedPattern) {
expectedPattern = expectedPattern.replace(/\\\(/g, "("); expectedPattern = expectedPattern.replace(/\\\(/g, "(");
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 // Trim the right hand side of our strings. This is because expectedPattern
// accounts for windows sometimes adding a newline to our copied data. // 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"); ok(true, "The eyedropper is now hidden");
info("Check that the clipboard still contains the copied color"); 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"); info("Replace the clipboard content with another text");
SpecialPowers.clipboardCopyString("not-a-color"); 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"); info("Click on the page again, check the clipboard was not updated");
await BrowserTestUtils.synthesizeMouseAtCenter( await BrowserTestUtils.synthesizeMouseAtCenter(
@@ -57,7 +57,7 @@ add_task(async function() {
); );
// Wait 500ms because nothing is observable when the test is successful. // Wait 500ms because nothing is observable when the test is successful.
await wait(500); await wait(500);
is(SpecialPowers.getClipboardData("text/unicode"), "not-a-color"); is(SpecialPowers.getClipboardData("text/plain"), "not-a-color");
finalize(); finalize();
}); });

View File

@@ -155,7 +155,7 @@ async function testClearedRequests({ tab, monitor, toolbox }) {
connector connector
); );
const jsonString = SpecialPowers.getClipboardData("text/unicode"); const jsonString = SpecialPowers.getClipboardData("text/plain");
const har = JSON.parse(jsonString); const har = JSON.parse(jsonString);
is(har.log.entries.length, 2, "There must be two requests"); is(har.log.entries.length, 2, "There must be two requests");
is( is(
@@ -233,6 +233,6 @@ async function reloadAndCopyAllAsHar({
connector connector
); );
const jsonString = SpecialPowers.getClipboardData("text/unicode"); const jsonString = SpecialPowers.getClipboardData("text/plain");
return JSON.parse(jsonString); 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. * @return {String} Clipboard text content, null if no text clipboard data is available.
*/ */
function getText() { function getText() {
const flavor = "text/unicode"; const flavor = "text/plain";
const xferable = Cc["@mozilla.org/widget/transferable;1"].createInstance( const xferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(
Ci.nsITransferable Ci.nsITransferable

View File

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

View File

@@ -7785,9 +7785,7 @@ void nsContentUtils::CallOnAllRemoteChildren(
bool nsContentUtils::IPCDataTransferItemHasKnownFlavor( bool nsContentUtils::IPCDataTransferItemHasKnownFlavor(
const IPCDataTransferItem& aItem) { const IPCDataTransferItem& aItem) {
// Unknown types are converted to kCustomTypesMime. // Unknown types are converted to kCustomTypesMime.
// FIXME(bug 1776879) text/plain is converted to text/unicode still. if (aItem.flavor().EqualsASCII(kCustomTypesMime)) {
if (aItem.flavor().EqualsASCII(kCustomTypesMime) ||
aItem.flavor().EqualsASCII(kUnicodeMime)) {
return true; 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 // html content with pre-wrap style : text/plain. Otherwise text/html. see
// nsHTMLCopyEncoder::SetSelection // nsHTMLCopyEncoder::SetSelection
nsAutoString mimeType; nsAutoString mimeType;
mimeType.AssignLiteral(kUnicodeMime); mimeType.AssignLiteral("text/unicode");
// Do the first and potentially trial encoding as preformatted and raw. // Do the first and potentially trial encoding as preformatted and raw.
uint32_t flags = aAdditionalEncoderFlags | uint32_t flags = aAdditionalEncoderFlags |
@@ -171,7 +171,7 @@ static nsresult EncodeAsTextHTMLWithContext(
} }
struct EncodedDocumentWithContext { 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 // 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 // encode the document as `text/html` or `text/plain`. It is `true` iff
// `text/html` was used. // `text/html` was used.
@@ -274,14 +274,13 @@ static nsresult CreateTransferable(
if (!aEncodedDocumentWithContext.mSerializationForTextUnicode.IsEmpty()) { if (!aEncodedDocumentWithContext.mSerializationForTextUnicode.IsEmpty()) {
// unicode text // 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 // 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) // (eg. when pasting into Notepad)
rv = rv = AppendString(
AppendString(aTransferable, aTransferable,
aEncodedDocumentWithContext.mSerializationForTextUnicode, aEncodedDocumentWithContext.mSerializationForTextUnicode, kTextMime);
kUnicodeMime);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
@@ -308,10 +307,9 @@ static nsresult CreateTransferable(
} else { } else {
if (!aEncodedDocumentWithContext.mSerializationForTextUnicode.IsEmpty()) { if (!aEncodedDocumentWithContext.mSerializationForTextUnicode.IsEmpty()) {
// Add the unicode DataFlavor to the transferable // Add the unicode DataFlavor to the transferable
rv = rv = AppendString(
AppendString(aTransferable, aTransferable,
aEncodedDocumentWithContext.mSerializationForTextUnicode, aEncodedDocumentWithContext.mSerializationForTextUnicode, kTextMime);
kUnicodeMime);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
} }
@@ -475,7 +473,7 @@ nsresult nsCopySupport::ImageCopy(nsIImageLoadingContent* aImageElement,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// append the string to the transferable // 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); NS_ENSURE_SUCCESS(rv, rv);
} }

View File

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

View File

@@ -59,8 +59,8 @@ function hasExpectedFlavors() {
var cb = Cc["@mozilla.org/widget/clipboard;1"]. var cb = Cc["@mozilla.org/widget/clipboard;1"].
getService(Ci.nsIClipboard); getService(Ci.nsIClipboard);
ok(cb.hasDataMatchingFlavors(["text/unicode"], cb.kGlobalClipboard), ok(cb.hasDataMatchingFlavors(["text/plain"], cb.kGlobalClipboard),
"The clipboard has text/unicode"); "The clipboard has text/plain");
ok(cb.hasDataMatchingFlavors(["text/html"], cb.kGlobalClipboard), ok(cb.hasDataMatchingFlavors(["text/html"], cb.kGlobalClipboard),
"The clipboard has text/html"); "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)); window.getSelection().selectAllChildren(document.getElementById(id));
documentViewer.copySelection(); documentViewer.copySelection();
is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1), true); is(clipboard.hasDataMatchingFlavors(["text/plain"], 1), true);
is(clipboard.hasDataMatchingFlavors(["text/html"], 1), true); is(clipboard.hasDataMatchingFlavors(["text/html"], 1), true);
} }
function getClipboardData(mime) { function getClipboardData(mime) {
@@ -110,7 +110,7 @@ var clipboardHTML = [
'<p id=\"test5\">This<span style=\"user-select: all\"> text should</span> be copied.</p>', '<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 = [ var clipboardUnicode = [
'This text should be copied.', 'This text should be copied.',
'This text should be copied.', 'This text should be copied.',
@@ -145,7 +145,7 @@ for (var i = 0; i < originalStrings.length; i++) {
copyChildrenToClipboard(id); copyChildrenToClipboard(id);
is(window.getSelection().toString(), originalStrings[i], id + ' Selection.toString()'); is(window.getSelection().toString(), originalStrings[i], id + ' Selection.toString()');
testHtmlClipboardValue("text/html", clipboardHTML[i], id); testHtmlClipboardValue("text/html", clipboardHTML[i], id);
testClipboardValue("text/unicode", clipboardUnicode[i], id); testClipboardValue("text/plain", clipboardUnicode[i], id);
testInnerHTML(id, innerHTMLStrings[i]); testInnerHTML(id, innerHTMLStrings[i]);
testPasteText(textareaStrings[i], id + '.innerHTML'); testPasteText(textareaStrings[i], id + '.innerHTML');
} }

View File

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

View File

@@ -57,15 +57,15 @@ function testCopyImage () {
//--------- Let's check the content of the clipboard now. //--------- Let's check the content of the clipboard now.
// Does the clipboard contain text/unicode data ? // Does the clipboard contain text/plain data ?
ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard), "clipboard contains unicode text"); ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard), "clipboard contains unicode text");
// Does the clipboard contain text/html data ? // Does the clipboard contain text/html data ?
ok(clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard), "clipboard contains html text"); ok(clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard), "clipboard contains html text");
// Does the clipboard contain image data ? // Does the clipboard contain image data ?
ok(clipboard.hasDataMatchingFlavors(["image/png"], clipboard.kGlobalClipboard), "clipboard contains image"); ok(clipboard.hasDataMatchingFlavors(["image/png"], clipboard.kGlobalClipboard), "clipboard contains image");
// Is the text/uncodie data correct ? // Is the text/plain data correct ?
testClipboardValue('text/unicode', 'about:logo'); testClipboardValue('text/plain', 'about:logo');
// Is the text/html data correct ? // Is the text/html data correct ?
var expected = '<img id="logo" src="about:logo">'; var expected = '<img id="logo" src="about:logo">';
if (navigator.platform.includes("Win")) { 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 1. The text/html clipboard flavor isn't tested, since nsCopySupport doesn't
produce it for XHTML. 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, since nsCopySupport doesn't produce text/plain for hidden
elements, and unlike HTML, neither does it produce text/_moz_htmlcontext 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"> <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head> <head>

View File

@@ -82,7 +82,7 @@ waitUntilApzStable().then(async function() {
let element = doc.getElementById(id); let element = doc.getElementById(id);
dragSelect(element, 0, 60); dragSelect(element, 0, 60);
await copySelectionToClipboard(); 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, aSetup,
aNext, aNext,
aNext, aNext,
"text/unicode", "text/plain",
WATCH_TIMEOUT, WATCH_TIMEOUT,
true true
); );

View File

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

View File

@@ -22,15 +22,7 @@ NS_IMPL_CYCLE_COLLECTION(ClipboardItem::ItemEntry, mData,
ClipboardItem::ItemEntry::ItemEntry(const nsAString& aType, ClipboardItem::ItemEntry::ItemEntry(const nsAString& aType,
const nsACString& aFormat) const nsACString& aFormat)
: mType(aType), mFormat(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));
}
void ClipboardItem::ItemEntry::SetData(already_AddRefed<Blob>&& aBlob) { void ClipboardItem::ItemEntry::SetData(already_AddRefed<Blob>&& aBlob) {
// XXX maybe we could consider adding a method to check whether the union // 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; nsTArray<RefPtr<ItemEntry>> items;
for (const auto& entry : aItems.Entries()) { for (const auto& entry : aItems.Entries()) {
nsAutoCString format = entry.mKey.EqualsLiteral(kTextMime) nsAutoCString format = NS_ConvertUTF16toUTF8(entry.mKey);
? nsAutoCString(kUnicodeMime)
: NS_ConvertUTF16toUTF8(entry.mKey);
items.AppendElement( items.AppendElement(
MakeRefPtr<ItemEntry>(entry.mKey, format, entry.mValue)); MakeRefPtr<ItemEntry>(entry.mKey, format, entry.mValue));
} }

View File

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

View File

@@ -365,7 +365,7 @@ class DataTransfer final : public nsISupports, public nsWrapperCache {
DataTransfer** aResult); DataTransfer** aResult);
// converts some formats used for compatibility in aInFormat into aOutFormat. // 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; void GetRealFormat(const nsAString& aInFormat, nsAString& aOutFormat) const;
static bool PrincipalMaySetData(const nsAString& aFormat, nsIVariant* aData, static bool PrincipalMaySetData(const nsAString& aFormat, nsIVariant* aData,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1551,7 +1551,7 @@ nsHTMLCopyEncoder::Init(Document* aDocument, const nsAString& aMimeType,
mIsCopying = true; mIsCopying = true;
mDocument = aDocument; 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 // 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" // different meaning in other contexts. Sigh.) From now on, "text/plain"
// means forcing text/plain instead of guessing. // means forcing text/plain instead of guessing.

View File

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

View File

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

View File

@@ -190,7 +190,7 @@
info("cut"); info("cut");
await synthesizeKey(VK.X, { accelKey: true }, "x"); await synthesizeKey(VK.X, { accelKey: true }, "x");
await checkElement(editor, 0, "", ""); 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"); is(text, "Test text", "Should have cut to the clipboard");
SpecialPowers.clipboardCopyString("New text"); SpecialPowers.clipboardCopyString("New text");

View File

@@ -146,7 +146,7 @@ async function startTest() {
info("cut"); info("cut");
await synthesizeKey(VK.X, { accelKey: true }, "x", "input"); await synthesizeKey(VK.X, { accelKey: true }, "x", "input");
await checkElement(input, 0, 0, ""); 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"); is(text, "Test text", "Should have cut to the clipboard");
SpecialPowers.clipboardCopyString("New text"); SpecialPowers.clipboardCopyString("New text");

View File

@@ -146,7 +146,7 @@ async function startTest() {
info("cut"); info("cut");
await synthesizeKey(VK.X, { accelKey: true }, "x", "input"); await synthesizeKey(VK.X, { accelKey: true }, "x", "input");
await checkElement(input, 0, 0, ""); 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"); is(text, "Test text", "Should have cut to the clipboard");
SpecialPowers.clipboardCopyString("New text"); SpecialPowers.clipboardCopyString("New text");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -76,7 +76,7 @@ SimpleTest.waitForFocus(function() {
SimpleTest.finish(); SimpleTest.finish();
}, },
// TODO: bug 1686012 // 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); input.setSelectionRange(0, 6);
ok(true, "Trying to copy masked password..."); ok(true, "Trying to copy masked password...");
await copyToClipboard(null); 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"); "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"); "Copying masked password shouldn't copy masked value into the clipboard");
ok(true, "Trying to cut masked password..."); ok(true, "Trying to cut masked password...");
await cutToClipboard(null); 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"); "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"); "Cutting masked password shouldn't copy masked value into the clipboard");
is(input.value, "abcdef", is(input.value, "abcdef",
"Cutting masked password shouldn't modify the value"); "Cutting masked password shouldn't modify the value");
@@ -54,19 +54,19 @@ SimpleTest.waitForFocus(async () => {
input.setSelectionRange(0, 6); input.setSelectionRange(0, 6);
ok(true, "Trying to copy partially masked password..."); ok(true, "Trying to copy partially masked password...");
await copyToClipboard(null); 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"); "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"); "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"); "Copying partially masked password shouldn't copy masked value into the clipboard");
ok(true, "Trying to cut partially masked password..."); ok(true, "Trying to cut partially masked password...");
await cutToClipboard(null); 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"); "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"); "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"); "Cutting partially masked password shouldn't copy masked value into the clipboard");
is(input.value, "abcdef", is(input.value, "abcdef",
"Cutting partially masked password shouldn't modify the value"); "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"]. let s = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString); createInstance(Ci.nsISupportsString);
s.data = str; s.data = str;
trans.setTransferData("text/unicode", s); trans.setTransferData("text/plain", s);
let inputEvent = null; let inputEvent = null;
window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true}); window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true});
getEditor().pasteTransferable(trans); getEditor().pasteTransferable(trans);

View File

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

View File

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

View File

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

View File

@@ -15,7 +15,7 @@ import org.mozilla.gecko.annotation.WrapForJNI;
public final class Clipboard { public final class Clipboard {
private static final String HTML_MIME = "text/html"; 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 static final String LOGTAG = "GeckoClipboard";
private Clipboard() {} private Clipboard() {}
@@ -27,14 +27,14 @@ public final class Clipboard {
* @return a plain text string of clipboard data. * @return a plain text string of clipboard data.
*/ */
public static String getText(final Context context) { 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 * Get the data on the primary clip on clipboard
* *
* @param context application context * @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. * type, we do nothing.
* @return a string into clipboard. * @return a string into clipboard.
*/ */
@@ -57,7 +57,7 @@ public final class Clipboard {
} }
return data.toString(); return data.toString();
} }
if (UNICODE_MIME.equals(mimeType)) { if (PLAINTEXT_MIME.equals(mimeType)) {
try { try {
return clip.getItemAt(0).coerceToText(context).toString(); return clip.getItemAt(0).coerceToText(context).toString();
} catch (final SecurityException e) { } catch (final SecurityException e) {
@@ -130,7 +130,7 @@ public final class Clipboard {
@WrapForJNI(calledFrom = "gecko") @WrapForJNI(calledFrom = "gecko")
public static boolean hasData(final Context context, final String mimeType) { public static boolean hasData(final Context context, final String mimeType) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) { 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 !TextUtils.isEmpty(getData(context, mimeType));
} }
return false; return false;
@@ -155,7 +155,7 @@ public final class Clipboard {
return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML); 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. // We cannot check content in data at this time to avoid toast message.
return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML) return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)
|| description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); || 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 * 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 * 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 * 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. * values.
* *
* @param {String|Function} aExpectedStringOrValidatorFn * @param {String|Function} aExpectedStringOrValidatorFn
@@ -1087,7 +1087,7 @@ const kTextHtmlSuffixClipboardDataWindows =
* @param {Function} aFailureFn * @param {Function} aFailureFn
* A function called if the expected value isn't found on the clipboard * 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. * 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. * The flavor to look for.
* @param {Number} [aTimeout=5000] * @param {Number} [aTimeout=5000]
* The timeout (in milliseconds) to wait for a clipboard change. * The timeout (in milliseconds) to wait for a clipboard change.
@@ -1131,7 +1131,7 @@ SimpleTest.promiseClipboardChange = async function(
aExpectFailure, aExpectFailure,
aDontInitializeClipboardIfExpectFailure aDontInitializeClipboardIfExpectFailure
) { ) {
let requestedFlavor = aFlavor || "text/unicode"; let requestedFlavor = aFlavor || "text/plain";
// The known value we put on the clipboard before running aSetupFn // The known value we put on the clipboard before running aSetupFn
let initialVal = "waitForClipboard-known-value-" + Math.random(); let initialVal = "waitForClipboard-known-value-" + Math.random();
@@ -1223,7 +1223,7 @@ SimpleTest.promiseClipboardChange = async function(
function(aData) { function(aData) {
return aData == preExpectedVal; return aData == preExpectedVal;
}, },
"text/unicode", "text/plain",
false false
); );

View File

@@ -99,7 +99,7 @@
// differences. // differences.
synthesizeKey("A", {accelKey: true}); synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {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)"); actual = actual.replace(/\(pid \d+\)/g, "(pid NNN)");
if (actual.trim() === aExpected.trim()) { if (actual.trim() === aExpected.trim()) {

View File

@@ -50,7 +50,7 @@
// differences. // differences.
synthesizeKey("A", {accelKey: true}); synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {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)"); actual = actual.replace(/\(pid \d+\)/, "(pid NNN)");
if (actual.trim() === aExpected.trim()) { if (actual.trim() === aExpected.trim()) {

View File

@@ -105,7 +105,7 @@
// differences. // differences.
synthesizeKey("A", {accelKey: true}); synthesizeKey("A", {accelKey: true});
synthesizeKey("C", {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 // If we have more than 1000 chars, we've probably successfully
// copy+pasted. // copy+pasted.

View File

@@ -179,7 +179,7 @@ add_task(async function test_contentscript_clipboard_permission_writetext() {
await extension.startup(); await extension.startup();
let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html"); let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html");
await extension.awaitMessage("ready"); await extension.awaitMessage("ready");
const actual = SpecialPowers.getClipboardData("text/unicode"); const actual = SpecialPowers.getClipboardData("text/plain");
is(actual, "HI", "right string copied by write"); is(actual, "HI", "right string copied by write");
win.close(); win.close();
await extension.unload(); await extension.unload();
@@ -219,7 +219,7 @@ add_task(async function test_contentscript_clipboard_permission_readtext() {
}; };
await SimpleTest.promiseClipboardChange("HI", () => { await SimpleTest.promiseClipboardChange("HI", () => {
SpecialPowers.clipboardCopyString("HI"); SpecialPowers.clipboardCopyString("HI");
}, "text/unicode"); }, "text/plain");
let extension = ExtensionTestUtils.loadExtension(extensionData); let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup(); await extension.startup();
let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html"); 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(); await extension.startup();
let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html"); let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html");
await extension.awaitMessage("ready"); await extension.awaitMessage("ready");
const actual = SpecialPowers.getClipboardData("text/unicode"); const actual = SpecialPowers.getClipboardData("text/plain");
is(actual, "HI", "right string copied by write"); is(actual, "HI", "right string copied by write");
win.close(); win.close();
await extension.unload(); await extension.unload();
@@ -303,7 +303,7 @@ add_task(async function test_contentscript_clipboard_permission_read() {
}; };
await SimpleTest.promiseClipboardChange("HELLO", () => { await SimpleTest.promiseClipboardChange("HELLO", () => {
SpecialPowers.clipboardCopyString("HELLO"); SpecialPowers.clipboardCopyString("HELLO");
}, "text/unicode"); }, "text/plain");
let extension = ExtensionTestUtils.loadExtension(extensionData); let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup(); await extension.startup();
let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html"); 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(""); SpecialPowers.clipboardCopyString("");
DownloadsCommon.copyDownloadLink(dl); 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(copiedUrl, pdfUrl, "The copied url must be the original one");
is( is(

View File

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

View File

@@ -20,9 +20,9 @@ add_task(function() {
PlacesUtils.TYPE_X_MOZ_URL, PlacesUtils.TYPE_X_MOZ_URL,
], ],
// Single url. // Single url.
["place:type=0&sort=1:", PlacesUtils.TYPE_UNICODE], ["place:type=0&sort=1:", PlacesUtils.TYPE_PLAINTEXT],
// Multiple urls. // 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) { for (let [blob, type] of tests) {
Assert.deepEqual( Assert.deepEqual(

View File

@@ -45,7 +45,7 @@ add_task(async function test_readerModeURLDrag() {
urlBarContainer.click(); urlBarContainer.click();
urlbar.dispatchEvent(urlEvent); 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"); ok(!newUrl.includes("about:reader"), "URL does not contain about:reader");
Assert.equal(newUrl, oldUrl, "URL is the same"); Assert.equal(newUrl, oldUrl, "URL is the same");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -10,13 +10,13 @@ function getString(clipboard) {
Ci.nsITransferable Ci.nsITransferable
); );
trans.init(null); trans.init(null);
trans.addDataFlavor("text/unicode"); trans.addDataFlavor("text/plain");
clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard); clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
try { try {
var data = {}; var data = {};
trans.getTransferData("text/unicode", data); trans.getTransferData("text/plain", data);
if (data) { if (data) {
data = data.value.QueryInterface(Ci.nsISupportsString); 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 // Add the text data flavor to the transferable
rv = trans->AddDataFlavor(kUnicodeMime); rv = trans->AddDataFlavor(kTextMime);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// get wStrings to hold clip data // get wStrings to hold clip data
@@ -93,7 +93,7 @@ nsClipboardHelper::CopyStringToClipboard(const nsAString& aString,
NS_ENSURE_TRUE(genericData, NS_ERROR_FAILURE); NS_ENSURE_TRUE(genericData, NS_ERROR_FAILURE);
// set the transfer data // set the transfer data
rv = trans->SetTransferData(kUnicodeMime, genericData); rv = trans->SetTransferData(kTextMime, genericData);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// put the transferable on the clipboard // put the transferable on the clipboard

View File

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

View File

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

View File

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

View File

@@ -45,7 +45,7 @@ class nsLinebreakHelpers {
// taken care of internally, see the note below). // taken care of internally, see the note below).
// //
// NOTE: this assumes that it can use 'free' to dispose of the old buffer. // 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, void** ioData,
int32_t* ioLengthInBytes); int32_t* ioLengthInBytes);

View File

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

View File

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

View File

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

View File

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

View File

@@ -99,8 +99,6 @@ UINT nsClipboard::GetFormat(const char* aMimeStr, bool aMapHTMLMime) {
UINT format; UINT format;
if (strcmp(aMimeStr, kTextMime) == 0) { if (strcmp(aMimeStr, kTextMime) == 0) {
format = CF_TEXT;
} else if (strcmp(aMimeStr, kUnicodeMime) == 0) {
format = CF_UNICODETEXT; format = CF_UNICODETEXT;
} else if (strcmp(aMimeStr, kRTFMime) == 0) { } else if (strcmp(aMimeStr, kRTFMime) == 0) {
format = ::RegisterClipboardFormat(L"Rich Text Format"); format = ::RegisterClipboardFormat(L"Rich Text Format");
@@ -210,9 +208,9 @@ nsresult nsClipboard::SetupNativeDataObject(
// Do various things internal to the implementation, like map one // Do various things internal to the implementation, like map one
// flavor to another or add additional flavors based on what's required // flavor to another or add additional flavors based on what's required
// for the win32 impl. // for the win32 impl.
if (flavorStr.EqualsLiteral(kUnicodeMime)) { if (flavorStr.EqualsLiteral(kTextMime)) {
// if we find text/unicode, also advertise text/plain (which we will // if we find text/plain, also add CF_TEXT, but we can add it for
// convert on our own in nsDataObj::GetText(). // text/plain as well.
FORMATETC textFE; FORMATETC textFE;
SET_FORMATETC(textFE, CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL); SET_FORMATETC(textFE, CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
dObj->AddDataFlavor(kTextMime, &textFE); 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 // when directly asking for the flavor. Let's try digging around in other
// flavors to help satisfy our craving for data. // flavors to help satisfy our craving for data.
if (!dataFound) { if (!dataFound) {
if (flavorStr.EqualsLiteral(kUnicodeMime)) { if (flavorStr.EqualsLiteral(kTextMime)) {
dataFound = dataFound =
FindUnicodeFromPlainText(aDataObject, anIndex, &data, &dataLen); FindUnicodeFromPlainText(aDataObject, anIndex, &data, &dataLen);
} else if (flavorStr.EqualsLiteral(kURLMime)) { } else if (flavorStr.EqualsLiteral(kURLMime)) {
@@ -954,14 +952,15 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject* aDataObject,
} else { } else {
// Treat custom types as a string of bytes. // Treat custom types as a string of bytes.
if (!flavorStr.EqualsLiteral(kCustomTypesMime)) { if (!flavorStr.EqualsLiteral(kCustomTypesMime)) {
bool isRTF = flavorStr.EqualsLiteral(kRTFMime);
// we probably have some form of text. The DOM only wants LF, so // we probably have some form of text. The DOM only wants LF, so
// convert from Win32 line endings to DOM line endings. // convert from Win32 line endings to DOM line endings.
int32_t signedLen = static_cast<int32_t>(dataLen); int32_t signedLen = static_cast<int32_t>(dataLen);
nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(flavorStr, &data, nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(isRTF, &data,
&signedLen); &signedLen);
dataLen = signedLen; dataLen = signedLen;
if (flavorStr.EqualsLiteral(kRTFMime)) { if (isRTF) {
// RTF on Windows is known to sometimes deliver an extra null byte. // RTF on Windows is known to sometimes deliver an extra null byte.
if (dataLen > 0 && static_cast<char*>(data)[dataLen - 1] == '\0') { if (dataLen > 0 && static_cast<char*>(data)[dataLen - 1] == '\0') {
dataLen--; dataLen--;
@@ -1049,20 +1048,21 @@ bool nsClipboard ::FindPlatformHTML(IDataObject* inDataObject, UINT inIndex,
// //
// FindUnicodeFromPlainText // FindUnicodeFromPlainText
// //
// we are looking for text/unicode and we failed to find it on the clipboard // Looks for CF_TEXT on the clipboard and converts it into an UTF-16 string
// first, try again with text/plain. If that is present, convert it to unicode. // 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, bool nsClipboard ::FindUnicodeFromPlainText(IDataObject* inDataObject,
UINT inIndex, void** outData, UINT inIndex, void** outData,
uint32_t* outDataLen) { uint32_t* outDataLen) {
MOZ_LOG(gWin32ClipboardLog, LogLevel::Debug, ("%s", __FUNCTION__)); MOZ_LOG(gWin32ClipboardLog, LogLevel::Debug, ("%s", __FUNCTION__));
// we are looking for text/unicode and we failed to find it on the clipboard // We are looking for text/plain and we failed to find it on the clipboard
// first, try again with text/plain. If that is present, convert it to // first, so try again with CF_TEXT. If that is present, convert it to
// unicode. // unicode.
nsresult rv = nsresult rv = GetNativeDataOffClipboard(inDataObject, inIndex, CF_TEXT,
GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kTextMime), nullptr, outData, outDataLen);
nullptr, outData, outDataLen);
if (NS_FAILED(rv) || !*outData) { if (NS_FAILED(rv) || !*outData) {
return false; return false;
} }
@@ -1303,30 +1303,10 @@ NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors(
} }
for (auto& flavor : aFlavorList) { 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()); UINT format = GetFormat(flavor.get());
if (IsClipboardFormatAvailable(format)) { if (IsClipboardFormatAvailable(format)) {
*_retval = true; *_retval = true;
break; 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) { STGMEDIUM& aSTG) {
void* data = nullptr; void* data = nullptr;
// if someone asks for text/plain, look up text/unicode instead in the const nsPromiseFlatCString& flavorStr = PromiseFlatCString(aDataFlavor);
// transferable.
const char* flavorStr;
const nsPromiseFlatCString& flat = PromiseFlatCString(aDataFlavor);
if (aDataFlavor.EqualsLiteral("text/plain"))
flavorStr = kUnicodeMime;
else
flavorStr = flat.get();
// NOTE: CreateDataFromPrimitive creates new memory, that needs to be deleted // NOTE: CreateDataFromPrimitive creates new memory, that needs to be deleted
nsCOMPtr<nsISupports> genericDataWrapper; nsCOMPtr<nsISupports> genericDataWrapper;
nsresult rv = mTransferable->GetTransferData( nsresult rv = mTransferable->GetTransferData(
flavorStr, getter_AddRefs(genericDataWrapper)); flavorStr.get(), getter_AddRefs(genericDataWrapper));
if (NS_FAILED(rv) || !genericDataWrapper) { if (NS_FAILED(rv) || !genericDataWrapper) {
return E_FAIL; return E_FAIL;
} }
uint32_t len; uint32_t len;
nsPrimitiveHelpers::CreateDataFromPrimitive(nsDependentCString(flavorStr), nsPrimitiveHelpers::CreateDataFromPrimitive(
genericDataWrapper, &data, &len); nsDependentCString(flavorStr.get()), genericDataWrapper, &data, &len);
if (!data) return E_FAIL; if (!data) return E_FAIL;
HGLOBAL hGlobalMemory = nullptr; HGLOBAL hGlobalMemory = nullptr;

View File

@@ -451,13 +451,6 @@ NS_IMETHODIMP
nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) { nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) {
if (!aDataFlavor || !mDataObject || !_retval) return NS_ERROR_FAILURE; 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; *_retval = false;
FORMATETC fe; 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 // 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 // maybe we can still find it from something else that's on the
// clipboard // clipboard
if (strcmp(aDataFlavor, kUnicodeMime) == 0) { if (strcmp(aDataFlavor, kTextMime) == 0) {
// client asked for unicode and it wasn't present, check if we // 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 // have CF_TEXT. We'll handle the actual data substitution in
// the data object. // the data object.
format = nsClipboard::GetFormat(kTextMime); SET_FORMATETC(fe, CF_TEXT, 0, DVASPECT_CONTENT, -1,
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1,
TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI); TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI);
if (mDataObject->QueryGetData(&fe) == S_OK) if (mDataObject->QueryGetData(&fe) == S_OK)
*_retval = true; // found it! *_retval = true; // found it!

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