diff --git a/accessible/tests/mochitest/common.js b/accessible/tests/mochitest/common.js index 4f4a821d28d5..ae12b4b7bce3 100644 --- a/accessible/tests/mochitest/common.js +++ b/accessible/tests/mochitest/common.js @@ -847,11 +847,11 @@ function getTextFromClipboard() { return ""; } - trans.addDataFlavor("text/unicode"); + trans.addDataFlavor("text/plain"); Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard); var str = {}; - trans.getTransferData("text/unicode", str); + trans.getTransferData("text/plain", str); if (str) { str = str.value.QueryInterface(Ci.nsISupportsString); diff --git a/browser/base/content/browser-places.js b/browser/base/content/browser-places.js index 15eb64deb707..82565ccb658a 100644 --- a/browser/base/content/browser-places.js +++ b/browser/base/content/browser-places.js @@ -1379,7 +1379,7 @@ var PlacesToolbarHelper = { } addData(PlacesUtils.TYPE_X_MOZ_URL, 0); - addData(PlacesUtils.TYPE_UNICODE, 0); + addData(PlacesUtils.TYPE_PLAINTEXT, 0); addData(PlacesUtils.TYPE_HTML, 0); }, }; diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 22de85fca810..38ca7a186235 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -3176,7 +3176,7 @@ function readFromClipboard() { ); trans.init(getLoadContext()); - trans.addDataFlavor("text/unicode"); + trans.addDataFlavor("text/plain"); // If available, use selection clipboard, otherwise global one let clipboard = Services.clipboard; @@ -3187,7 +3187,7 @@ function readFromClipboard() { } var data = {}; - trans.getTransferData("text/unicode", data); + trans.getTransferData("text/plain", data); if (data) { data = data.value.QueryInterface(Ci.nsISupportsString); diff --git a/browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js b/browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js index f818ddba8da1..cb208db601c9 100644 --- a/browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js +++ b/browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js @@ -93,9 +93,9 @@ add_task(async function test_contenteditable() { "text/html", PlacesUtils.toISupportsString("Bold text") ); - xferable.addDataFlavor("text/unicode"); + xferable.addDataFlavor("text/plain"); xferable.setTransferData( - "text/unicode", + "text/plain", PlacesUtils.toISupportsString("Bold text") ); Services.clipboard.setData( diff --git a/browser/base/content/test/general/browser_bug1297539.js b/browser/base/content/test/general/browser_bug1297539.js index b81bd60602bd..3ec33475a392 100644 --- a/browser/base/content/test/general/browser_bug1297539.js +++ b/browser/base/content/test/general/browser_bug1297539.js @@ -29,7 +29,7 @@ function getTransferableFromClipboard(asHTML) { if (asHTML) { trans.addDataFlavor("text/html"); } else { - trans.addDataFlavor("text/unicode"); + trans.addDataFlavor("text/plain"); } Services.clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard); return trans; diff --git a/browser/base/content/test/general/browser_clipboard_pastefile.js b/browser/base/content/test/general/browser_clipboard_pastefile.js index de23107afbb0..562b16b2a82e 100644 --- a/browser/base/content/test/general/browser_clipboard_pastefile.js +++ b/browser/base/content/test/general/browser_clipboard_pastefile.js @@ -16,12 +16,12 @@ function setClipboard(path) { trans.addDataFlavor("application/x-moz-file"); trans.setTransferData("application/x-moz-file", file); - trans.addDataFlavor("text/unicode"); + trans.addDataFlavor("text/plain"); const str = Cc["@mozilla.org/supports-string;1"].createInstance( Ci.nsISupportsString ); str.data = "Alternate"; - trans.setTransferData("text/unicode", str); + trans.setTransferData("text/plain", str); // Write to clipboard. Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard); diff --git a/browser/components/downloads/content/allDownloadsView.js b/browser/components/downloads/content/allDownloadsView.js index 9c1f9f19f314..f0f7058179ab 100644 --- a/browser/components/downloads/content/allDownloadsView.js +++ b/browser/components/downloads/content/allDownloadsView.js @@ -639,7 +639,7 @@ DownloadsPlacesView.prototype = { ); trans.init(null); - let flavors = ["text/x-moz-url", "text/unicode"]; + let flavors = ["text/x-moz-url", "text/plain"]; flavors.forEach(trans.addDataFlavor); Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard); diff --git a/browser/components/downloads/content/downloads.js b/browser/components/downloads/content/downloads.js index 520e0a2dd2d9..cc605dd152fa 100644 --- a/browser/components/downloads/content/downloads.js +++ b/browser/components/downloads/content/downloads.js @@ -471,7 +471,7 @@ var DownloadsPanel = { Ci.nsITransferable ); trans.init(null); - let flavors = ["text/x-moz-url", "text/unicode"]; + let flavors = ["text/x-moz-url", "text/plain"]; flavors.forEach(trans.addDataFlavor); Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard); // Getting the data or creating the nsIURI might fail diff --git a/browser/components/places/PlacesUIUtils.sys.mjs b/browser/components/places/PlacesUIUtils.sys.mjs index 71952806a366..d86723cf8239 100644 --- a/browser/components/places/PlacesUIUtils.sys.mjs +++ b/browser/components/places/PlacesUIUtils.sys.mjs @@ -1793,7 +1793,7 @@ export var PlacesUIUtils = { let contents = [ { type: lazy.PlacesUtils.TYPE_X_MOZ_URL, entries: [] }, { type: lazy.PlacesUtils.TYPE_HTML, entries: [] }, - { type: lazy.PlacesUtils.TYPE_UNICODE, entries: [] }, + { type: lazy.PlacesUtils.TYPE_PLAINTEXT, entries: [] }, ]; contents.forEach(function(content) { @@ -2034,7 +2034,7 @@ XPCOMUtils.defineLazyGetter(PlacesUIUtils, "URI_FLAVORS", () => { return [ lazy.PlacesUtils.TYPE_X_MOZ_URL, TAB_DROP_TYPE, - lazy.PlacesUtils.TYPE_UNICODE, + lazy.PlacesUtils.TYPE_PLAINTEXT, ]; }); XPCOMUtils.defineLazyGetter(PlacesUIUtils, "SUPPORTED_FLAVORS", () => { @@ -2271,7 +2271,7 @@ function getTransactionsForCopy(items, insertionIndex, insertionParentGuid) { }); } else { let title = - item.type != lazy.PlacesUtils.TYPE_UNICODE ? item.title : item.uri; + item.type != lazy.PlacesUtils.TYPE_PLAINTEXT ? item.title : item.uri; transaction = lazy.PlacesTransactions.NewBookmark({ index, parentGuid: insertionParentGuid, diff --git a/browser/components/places/content/controller.js b/browser/components/places/content/controller.js index cea7240332ec..66fbfa2f8e3e 100644 --- a/browser/components/places/content/controller.js +++ b/browser/components/places/content/controller.js @@ -168,7 +168,7 @@ PlacesController.prototype = { case "cmd_paste": case "placesCmd_paste": // If the clipboard contains a Places flavor it is definitely pasteable, - // otherwise we also allow pasting "text/unicode" and "text/x-moz-url" data. + // otherwise we also allow pasting "text/plain" and "text/x-moz-url" data. // We don't check if the data is valid here, because the clipboard may // contain very large blobs that would largely slowdown commands updating. // Of course later paste() should ignore any invalid data. @@ -178,7 +178,7 @@ PlacesController.prototype = { [ ...PlacesUIUtils.PLACES_FLAVORS, PlacesUtils.TYPE_X_MOZ_URL, - PlacesUtils.TYPE_UNICODE, + PlacesUtils.TYPE_PLAINTEXT, ], Ci.nsIClipboard.kGlobalClipboard ) @@ -1049,7 +1049,7 @@ PlacesController.prototype = { function addURIData(index) { addData(PlacesUtils.TYPE_X_MOZ_URL, index); - addData(PlacesUtils.TYPE_UNICODE, index); + addData(PlacesUtils.TYPE_PLAINTEXT, index); addData(PlacesUtils.TYPE_HTML, index); } @@ -1131,7 +1131,7 @@ PlacesController.prototype = { { type: PlacesUtils.TYPE_X_MOZ_PLACE, entries: [] }, { type: PlacesUtils.TYPE_X_MOZ_URL, entries: [] }, { type: PlacesUtils.TYPE_HTML, entries: [] }, - { type: PlacesUtils.TYPE_UNICODE, entries: [] }, + { type: PlacesUtils.TYPE_PLAINTEXT, entries: [] }, ]; // Avoid handling descendants of a copied node, the transactions take care @@ -1264,7 +1264,7 @@ PlacesController.prototype = { [ PlacesUtils.TYPE_X_MOZ_PLACE, PlacesUtils.TYPE_X_MOZ_URL, - PlacesUtils.TYPE_UNICODE, + PlacesUtils.TYPE_PLAINTEXT, ].forEach(type => xferable.addDataFlavor(type)); Services.clipboard.getData(xferable, Ci.nsIClipboard.kGlobalClipboard); @@ -1494,13 +1494,6 @@ var PlacesControllerDragHelper = { } } - // If no supported flavor is found, check if data includes text/plain - // contents. If so, request them as text/unicode, a conversion will happen - // automatically. - if (aFlavors.contains("text/plain")) { - return PlacesUtils.TYPE_UNICODE; - } - return null; }, @@ -1623,7 +1616,7 @@ var PlacesControllerDragHelper = { // Following flavors may contain duplicated data. let duplicable = new Map(); - duplicable.set(PlacesUtils.TYPE_UNICODE, new Set()); + duplicable.set(PlacesUtils.TYPE_PLAINTEXT, new Set()); duplicable.set(PlacesUtils.TYPE_X_MOZ_URL, new Set()); // Collect all data from the DataTransfer before processing it, as the diff --git a/browser/components/places/tests/browser/browser_toolbar_drop_text.js b/browser/components/places/tests/browser/browser_toolbar_drop_text.js index a11e7959281e..e35a3c6e1d22 100644 --- a/browser/components/places/tests/browser/browser_toolbar_drop_text.js +++ b/browser/components/places/tests/browser/browser_toolbar_drop_text.js @@ -133,7 +133,7 @@ add_task(async function test() { }; // Simulate a bookmark drop for all of the mime types and effects. - let mimeTypes = ["text/plain", "text/unicode", "text/x-moz-url"]; + let mimeTypes = ["text/plain", "text/x-moz-url"]; let effects = ["move", "copy", "link"]; for (let effect of effects) { for (let mimeType of mimeTypes) { diff --git a/browser/components/textrecognition/tests/browser/head.js b/browser/components/textrecognition/tests/browser/head.js index 819ae1b3a942..d3016375e2ea 100644 --- a/browser/components/textrecognition/tests/browser/head.js +++ b/browser/components/textrecognition/tests/browser/head.js @@ -19,11 +19,11 @@ function getTextFromClipboard() { Ci.nsITransferable ); transferable.init(window.docShell.QueryInterface(Ci.nsILoadContext)); - transferable.addDataFlavor("text/unicode"); + transferable.addDataFlavor("text/plain"); Services.clipboard.getData(transferable, Services.clipboard.kGlobalClipboard); const results = {}; - transferable.getTransferData("text/unicode", results); + transferable.getTransferData("text/plain", results); return results.value.QueryInterface(Ci.nsISupportsString)?.data ?? ""; } diff --git a/browser/components/urlbar/UrlbarInput.sys.mjs b/browser/components/urlbar/UrlbarInput.sys.mjs index bedc151e9553..7b95b316aa73 100644 --- a/browser/components/urlbar/UrlbarInput.sys.mjs +++ b/browser/components/urlbar/UrlbarInput.sys.mjs @@ -3604,7 +3604,7 @@ export class UrlbarInput { let title = this.window.gBrowser.contentTitle || href; event.dataTransfer.setData("text/x-moz-url", `${href}\n${title}`); - event.dataTransfer.setData("text/unicode", href); + event.dataTransfer.setData("text/plain", href); event.dataTransfer.setData("text/html", `${title}`); event.dataTransfer.effectAllowed = "copyLink"; event.stopPropagation(); @@ -3709,7 +3709,7 @@ function getDroppableData(event) { } } // Handle as text. - return event.dataTransfer.getData("text/unicode"); + return event.dataTransfer.getData("text/plain"); } /** diff --git a/browser/components/urlbar/tests/browser/browser_primary_selection_safe_on_new_tab.js b/browser/components/urlbar/tests/browser/browser_primary_selection_safe_on_new_tab.js index 47cdde447003..d2786be9093f 100644 --- a/browser/components/urlbar/tests/browser/browser_primary_selection_safe_on_new_tab.js +++ b/browser/components/urlbar/tests/browser/browser_primary_selection_safe_on_new_tab.js @@ -60,7 +60,7 @@ add_task(async function() { } let primaryAsText = SpecialPowers.getClipboardData( - "text/unicode", + "text/plain", SpecialPowers.Ci.nsIClipboard.kSelectionClipboard ); Assert.equal(primaryAsText, TEXT_FOR_PRIMARY); diff --git a/browser/components/urlbar/tests/browser/browser_unitConversion.js b/browser/components/urlbar/tests/browser/browser_unitConversion.js index ab057c8241e8..cd2d2d38b76a 100644 --- a/browser/components/urlbar/tests/browser/browser_unitConversion.js +++ b/browser/components/urlbar/tests/browser/browser_unitConversion.js @@ -60,7 +60,7 @@ add_task(async function test_selectByKey() { function assertClipboard() { Assert.equal( - SpecialPowers.getClipboardData("text/unicode"), + SpecialPowers.getClipboardData("text/plain"), "100 cm", "The result of conversion is copied to clipboard" ); diff --git a/browser/components/urlbar/tests/browser/browser_urlbar_selection.js b/browser/components/urlbar/tests/browser/browser_urlbar_selection.js index 85d9ecd3fefd..df86174cd95e 100644 --- a/browser/components/urlbar/tests/browser/browser_urlbar_selection.js +++ b/browser/components/urlbar/tests/browser/browser_urlbar_selection.js @@ -83,7 +83,7 @@ function checkPrimarySelection(expectedVal = "") { ) ) { let primaryAsText = SpecialPowers.getClipboardData( - "text/unicode", + "text/plain", SpecialPowers.Ci.nsIClipboard.kSelectionClipboard ); Assert.equal(primaryAsText, expectedVal); diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-features-source-tree.js b/devtools/client/debugger/test/mochitest/browser_dbg-features-source-tree.js index 5ad75454daa9..0b94c6f7da38 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg-features-source-tree.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg-features-source-tree.js @@ -110,7 +110,7 @@ add_task(async function testSimpleSourcesWithManualClickExpand() { info("Test the copy to clipboard context menu"); const mathMinTreeNode = findSourceNodeWithText(dbg, "math.min.js"); await triggerCopySourceContextMenu(dbg, mathMinTreeNode); - const clipboardData = SpecialPowers.getClipboardData("text/unicode"); + const clipboardData = SpecialPowers.getClipboardData("text/plain"); is( clipboardData, EXAMPLE_URL + "math.min.js", diff --git a/devtools/client/inspector/changes/test/browser_changes_copy_all_changes.js b/devtools/client/inspector/changes/test/browser_changes_copy_all_changes.js index c4fb36e37e2d..6e940a97ecbf 100644 --- a/devtools/client/inspector/changes/test/browser_changes_copy_all_changes.js +++ b/devtools/client/inspector/changes/test/browser_changes_copy_all_changes.js @@ -48,6 +48,6 @@ add_task(async function() { }); function checkClipboardData(expected) { - const actual = SpecialPowers.getClipboardData("text/unicode"); + const actual = SpecialPowers.getClipboardData("text/plain"); return decodeURIComponent(actual).trim() === expected.trim(); } diff --git a/devtools/client/inspector/changes/test/browser_changes_copy_declaration.js b/devtools/client/inspector/changes/test/browser_changes_copy_declaration.js index ef4897a215de..d6df3e69eca0 100644 --- a/devtools/client/inspector/changes/test/browser_changes_copy_declaration.js +++ b/devtools/client/inspector/changes/test/browser_changes_copy_declaration.js @@ -62,6 +62,6 @@ add_task(async function() { }); function checkClipboardData(expected) { - const actual = SpecialPowers.getClipboardData("text/unicode"); + const actual = SpecialPowers.getClipboardData("text/plain"); return actual.trim() === expected.trim(); } diff --git a/devtools/client/inspector/changes/test/browser_changes_copy_rule.js b/devtools/client/inspector/changes/test/browser_changes_copy_rule.js index ac70c372f7e0..689aa507d942 100644 --- a/devtools/client/inspector/changes/test/browser_changes_copy_rule.js +++ b/devtools/client/inspector/changes/test/browser_changes_copy_rule.js @@ -59,6 +59,6 @@ add_task(async function() { }); function checkClipboardData(expected) { - const actual = SpecialPowers.getClipboardData("text/unicode"); + const actual = SpecialPowers.getClipboardData("text/plain"); return actual.trim() === expected.trim(); } diff --git a/devtools/client/inspector/computed/test/head.js b/devtools/client/inspector/computed/test/head.js index 47b22532276f..d09039323b3c 100644 --- a/devtools/client/inspector/computed/test/head.js +++ b/devtools/client/inspector/computed/test/head.js @@ -237,7 +237,7 @@ async function copySomeTextAndCheckClipboard(view, positions, expectedPattern) { } function checkClipboard(expectedPattern) { - const actual = SpecialPowers.getClipboardData("text/unicode"); + const actual = SpecialPowers.getClipboardData("text/plain"); const expectedRegExp = new RegExp(expectedPattern, "g"); return expectedRegExp.test(actual); } @@ -249,7 +249,7 @@ function failClipboardCheck(expectedPattern) { expectedPattern = expectedPattern.replace(/\\\(/g, "("); expectedPattern = expectedPattern.replace(/\\\)/g, ")"); - let actual = SpecialPowers.getClipboardData("text/unicode"); + let actual = SpecialPowers.getClipboardData("text/plain"); // Trim the right hand side of our strings. This is because expectedPattern // accounts for windows sometimes adding a newline to our copied data. diff --git a/devtools/client/inspector/rules/test/browser_rules_copy_styles.js b/devtools/client/inspector/rules/test/browser_rules_copy_styles.js index 2ef6b3d08c2e..8bcda1403c3f 100644 --- a/devtools/client/inspector/rules/test/browser_rules_copy_styles.js +++ b/devtools/client/inspector/rules/test/browser_rules_copy_styles.js @@ -330,7 +330,7 @@ async function disableProperty(view, index) { } function checkClipboardData(expectedPattern) { - const actual = SpecialPowers.getClipboardData("text/unicode"); + const actual = SpecialPowers.getClipboardData("text/plain"); const expectedRegExp = new RegExp(expectedPattern, "g"); return expectedRegExp.test(actual); } @@ -342,7 +342,7 @@ function failedClipboard(expectedPattern) { expectedPattern = expectedPattern.replace(/\\\(/g, "("); expectedPattern = expectedPattern.replace(/\\\)/g, ")"); - let actual = SpecialPowers.getClipboardData("text/unicode"); + let actual = SpecialPowers.getClipboardData("text/plain"); // Trim the right hand side of our strings. This is because expectedPattern // accounts for windows sometimes adding a newline to our copied data. diff --git a/devtools/client/inspector/rules/test/browser_rules_select-and-copy-styles.js b/devtools/client/inspector/rules/test/browser_rules_select-and-copy-styles.js index 6ed8b5d4ad6d..3cf71c3f943c 100644 --- a/devtools/client/inspector/rules/test/browser_rules_select-and-copy-styles.js +++ b/devtools/client/inspector/rules/test/browser_rules_select-and-copy-styles.js @@ -182,7 +182,7 @@ async function checkCopyEditorValue(view) { } function checkClipboardData(expectedPattern) { - const actual = SpecialPowers.getClipboardData("text/unicode"); + const actual = SpecialPowers.getClipboardData("text/plain"); const expectedRegExp = new RegExp(expectedPattern, "g"); return expectedRegExp.test(actual); } @@ -194,7 +194,7 @@ function failedClipboard(expectedPattern) { expectedPattern = expectedPattern.replace(/\\\(/g, "("); expectedPattern = expectedPattern.replace(/\\\)/g, ")"); - let actual = SpecialPowers.getClipboardData("text/unicode"); + let actual = SpecialPowers.getClipboardData("text/plain"); // Trim the right hand side of our strings. This is because expectedPattern // accounts for windows sometimes adding a newline to our copied data. diff --git a/devtools/client/inspector/test/browser_inspector_highlighter-eyedropper-clipboard.js b/devtools/client/inspector/test/browser_inspector_highlighter-eyedropper-clipboard.js index 8e20a1de72e1..2ec49ab4463d 100644 --- a/devtools/client/inspector/test/browser_inspector_highlighter-eyedropper-clipboard.js +++ b/devtools/client/inspector/test/browser_inspector_highlighter-eyedropper-clipboard.js @@ -43,11 +43,11 @@ add_task(async function() { ok(true, "The eyedropper is now hidden"); info("Check that the clipboard still contains the copied color"); - is(SpecialPowers.getClipboardData("text/unicode"), "#ff0000"); + is(SpecialPowers.getClipboardData("text/plain"), "#ff0000"); info("Replace the clipboard content with another text"); SpecialPowers.clipboardCopyString("not-a-color"); - is(SpecialPowers.getClipboardData("text/unicode"), "not-a-color"); + is(SpecialPowers.getClipboardData("text/plain"), "not-a-color"); info("Click on the page again, check the clipboard was not updated"); await BrowserTestUtils.synthesizeMouseAtCenter( @@ -57,7 +57,7 @@ add_task(async function() { ); // Wait 500ms because nothing is observable when the test is successful. await wait(500); - is(SpecialPowers.getClipboardData("text/unicode"), "not-a-color"); + is(SpecialPowers.getClipboardData("text/plain"), "not-a-color"); finalize(); }); diff --git a/devtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js b/devtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js index f81a4b01db4a..2f32fba8b8f4 100644 --- a/devtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js +++ b/devtools/client/netmonitor/src/har/test/browser_net_har_copy_all_as_har.js @@ -155,7 +155,7 @@ async function testClearedRequests({ tab, monitor, toolbox }) { connector ); - const jsonString = SpecialPowers.getClipboardData("text/unicode"); + const jsonString = SpecialPowers.getClipboardData("text/plain"); const har = JSON.parse(jsonString); is(har.log.entries.length, 2, "There must be two requests"); is( @@ -233,6 +233,6 @@ async function reloadAndCopyAllAsHar({ connector ); - const jsonString = SpecialPowers.getClipboardData("text/unicode"); + const jsonString = SpecialPowers.getClipboardData("text/plain"); return JSON.parse(jsonString); } diff --git a/devtools/shared/platform/clipboard.js b/devtools/shared/platform/clipboard.js index 9cb960603f23..46ea6c5fe6a4 100644 --- a/devtools/shared/platform/clipboard.js +++ b/devtools/shared/platform/clipboard.js @@ -15,12 +15,12 @@ function copyString(string) { } /** - * Retrieve the current clipboard data matching the flavor "text/unicode". + * Retrieve the current clipboard data matching the flavor "text/plain". * * @return {String} Clipboard text content, null if no text clipboard data is available. */ function getText() { - const flavor = "text/unicode"; + const flavor = "text/plain"; const xferable = Cc["@mozilla.org/widget/transferable;1"].createInstance( Ci.nsITransferable diff --git a/dom/base/nsContentAreaDragDrop.cpp b/dom/base/nsContentAreaDragDrop.cpp index 7bf42580ecfa..0dd5d07f6db1 100644 --- a/dom/base/nsContentAreaDragDrop.cpp +++ b/dom/base/nsContentAreaDragDrop.cpp @@ -692,7 +692,7 @@ nsresult DragDataProducer::Produce(DataTransfer* aDataTransfer, bool* aCanDrag, if (NS_SUCCEEDED(rv)) { data->GetData(mInfoString); } - rv = transferable->GetTransferData(kUnicodeMime, getter_AddRefs(supports)); + rv = transferable->GetTransferData(kTextMime, getter_AddRefs(supports)); data = do_QueryInterface(supports); NS_ENSURE_SUCCESS(rv, rv); // require plain text at a minimum data->GetData(mTitleString); diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 6d0a17f1c39e..96586d8696aa 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -7785,9 +7785,7 @@ void nsContentUtils::CallOnAllRemoteChildren( bool nsContentUtils::IPCDataTransferItemHasKnownFlavor( const IPCDataTransferItem& aItem) { // Unknown types are converted to kCustomTypesMime. - // FIXME(bug 1776879) text/plain is converted to text/unicode still. - if (aItem.flavor().EqualsASCII(kCustomTypesMime) || - aItem.flavor().EqualsASCII(kUnicodeMime)) { + if (aItem.flavor().EqualsASCII(kCustomTypesMime)) { return true; } diff --git a/dom/base/nsCopySupport.cpp b/dom/base/nsCopySupport.cpp index 73abc81d11d7..e9ab744f7ce5 100644 --- a/dom/base/nsCopySupport.cpp +++ b/dom/base/nsCopySupport.cpp @@ -93,7 +93,7 @@ static nsresult EncodeForTextUnicode(nsIDocumentEncoder& aEncoder, // html content with pre-wrap style : text/plain. Otherwise text/html. see // nsHTMLCopyEncoder::SetSelection nsAutoString mimeType; - mimeType.AssignLiteral(kUnicodeMime); + mimeType.AssignLiteral("text/unicode"); // Do the first and potentially trial encoding as preformatted and raw. uint32_t flags = aAdditionalEncoderFlags | @@ -171,7 +171,7 @@ static nsresult EncodeAsTextHTMLWithContext( } struct EncodedDocumentWithContext { - // When determening `mSerializationForTextUnicode`, `text/unicode` is passed + // When determining `mSerializationForTextUnicode`, `text/unicode` is passed // as mime type to the encoder. It uses this as a switch to decide whether to // encode the document as `text/html` or `text/plain`. It is `true` iff // `text/html` was used. @@ -274,14 +274,13 @@ static nsresult CreateTransferable( if (!aEncodedDocumentWithContext.mSerializationForTextUnicode.IsEmpty()) { // unicode text - // Add the unicode DataFlavor to the transferable + // Add the plain text DataFlavor to the transferable // If we didn't have this, then nsDataObj::GetData matches - // text/unicode against the kURLMime flavour which is not desirable + // text/plain against the kURLMime flavour which is not desirable // (eg. when pasting into Notepad) - rv = - AppendString(aTransferable, - aEncodedDocumentWithContext.mSerializationForTextUnicode, - kUnicodeMime); + rv = AppendString( + aTransferable, + aEncodedDocumentWithContext.mSerializationForTextUnicode, kTextMime); NS_ENSURE_SUCCESS(rv, rv); } @@ -308,10 +307,9 @@ static nsresult CreateTransferable( } else { if (!aEncodedDocumentWithContext.mSerializationForTextUnicode.IsEmpty()) { // Add the unicode DataFlavor to the transferable - rv = - AppendString(aTransferable, - aEncodedDocumentWithContext.mSerializationForTextUnicode, - kUnicodeMime); + rv = AppendString( + aTransferable, + aEncodedDocumentWithContext.mSerializationForTextUnicode, kTextMime); NS_ENSURE_SUCCESS(rv, rv); } } @@ -475,7 +473,7 @@ nsresult nsCopySupport::ImageCopy(nsIImageLoadingContent* aImageElement, NS_ENSURE_SUCCESS(rv, rv); // append the string to the transferable - rv = AppendString(trans, NS_ConvertUTF8toUTF16(location), kUnicodeMime); + rv = AppendString(trans, NS_ConvertUTF8toUTF16(location), kTextMime); NS_ENSURE_SUCCESS(rv, rv); } diff --git a/dom/base/test/copypaste.js b/dom/base/test/copypaste.js index 02d09e56f144..fd40e5baacbe 100644 --- a/dom/base/test/copypaste.js +++ b/dom/base/test/copypaste.js @@ -50,8 +50,8 @@ async function testCopyPaste(isXHTML) { ); if (!suppressUnicodeCheck) { ok( - clipboard.hasDataMatchingFlavors(["text/unicode"], 1), - "check text/unicode" + clipboard.hasDataMatchingFlavors(["text/plain"], 1), + "check text/plain" ); } if (!suppressHTMLCheck) { @@ -159,7 +159,7 @@ async function testCopyPaste(isXHTML) { await copyChildrenToClipboard("draggable"); testSelectionToString("This is a draggable bit of text."); - testClipboardValue("text/unicode", "This is a draggable bit of text."); + testClipboardValue("text/plain", "This is a draggable bit of text."); testHtmlClipboardValue( "text/html", '
This is a draggable bit of text.
' @@ -168,7 +168,7 @@ async function testCopyPaste(isXHTML) { await copyChildrenToClipboard("alist"); testSelectionToString(" bla\n\n foo\n bar\n\n"); - testClipboardValue("text/unicode", " bla\n\n foo\n bar\n\n"); + testClipboardValue("text/plain", " bla\n\n foo\n bar\n\n"); testHtmlClipboardValue( "text/html", '
\n bla\n \n
' @@ -177,7 +177,7 @@ async function testCopyPaste(isXHTML) { await copyChildrenToClipboard("blist"); testSelectionToString(" mozilla\n\n foo\n bar\n\n"); - testClipboardValue("text/unicode", " mozilla\n\n foo\n bar\n\n"); + testClipboardValue("text/plain", " mozilla\n\n foo\n bar\n\n"); testHtmlClipboardValue( "text/html", '
\n mozilla\n
    \n
  1. foo
  2. \n \n
  3. bar
  4. \n
\n
' @@ -187,7 +187,7 @@ async function testCopyPaste(isXHTML) { await copyChildrenToClipboard("clist"); testSelectionToString(" mzla\n\n foo\n bazzinga!\n bar\n\n"); testClipboardValue( - "text/unicode", + "text/plain", " mzla\n\n foo\n bazzinga!\n bar\n\n" ); testHtmlClipboardValue( @@ -198,7 +198,7 @@ async function testCopyPaste(isXHTML) { await copyChildrenToClipboard("div4"); testSelectionToString(" Tt t t "); - testClipboardValue("text/unicode", " Tt t t "); + testClipboardValue("text/plain", " Tt t t "); if (isXHTML) { testHtmlClipboardValue( "text/html", @@ -219,7 +219,7 @@ async function testCopyPaste(isXHTML) { await copyChildrenToClipboard("div5"); testSelectionToString(" T "); - testClipboardValue("text/unicode", " T "); + testClipboardValue("text/plain", " T "); if (isXHTML) { testHtmlClipboardValue( "text/html", @@ -248,7 +248,7 @@ async function testCopyPaste(isXHTML) { testSelectionToString(""); // START Disabled due to bug 564688 if (false) { - testClipboardValue("text/unicode", ""); + testClipboardValue("text/plain", ""); testClipboardValue("text/html", ""); } // END Disabled due to bug 564688 @@ -264,7 +264,7 @@ async function testCopyPaste(isXHTML) { testSelectionToString(""); // START Disabled due to bug 564688 if (false) { - testClipboardValue("text/unicode", ""); + testClipboardValue("text/plain", ""); testClipboardValue("text/html", ""); } // END Disabled due to bug 564688 @@ -280,7 +280,7 @@ async function testCopyPaste(isXHTML) { testSelectionToString(""); // START Disabled due to bug 564688 if (false) { - testClipboardValue("text/unicode", ""); + testClipboardValue("text/plain", ""); testClipboardValue("text/html", ""); } // END Disabled due to bug 564688 @@ -294,7 +294,7 @@ async function testCopyPaste(isXHTML) { suppressUnicodeCheckIfHidden ); testSelectionToString("div9"); - testClipboardValue("text/unicode", "div9"); + testClipboardValue("text/plain", "div9"); testHtmlClipboardValue("text/html", "div9"); testInnerHTML("div9", "div9"); @@ -462,20 +462,20 @@ async function testCopyPaste(isXHTML) { await copyChildrenToClipboard("div13"); testSelectionToString("__"); - testClipboardValue("text/unicode", "__"); + testClipboardValue("text/plain", "__"); testHtmlClipboardValue("text/html", '
__
'); testPasteText("__"); // ============ converting cell boundaries to tabs in tables await copyToClipboard($("tr1")); - testClipboardValue("text/unicode", "foo\tbar"); + testClipboardValue("text/plain", "foo\tbar"); if (!isXHTML) { // ============ spanning multiple rows await copyRangeToClipboard($("tr2"), 0, $("tr3"), 0); - testClipboardValue("text/unicode", "1\t2\n3\t4\n"); + testClipboardValue("text/plain", "1\t2\n3\t4\n"); testHtmlClipboardValue( "text/html", '
12
34
' @@ -487,7 +487,7 @@ async function testCopyPaste(isXHTML) { addRange($("tr2"), 0, $("tr2"), 2); addRange($("tr3"), 0, $("tr3"), 2); await copySelectionToClipboard(); - testClipboardValue("text/unicode", "1\t2\n5\t6"); + testClipboardValue("text/plain", "1\t2\n5\t6"); testHtmlClipboardValue( "text/html", '
12
56
' @@ -502,7 +502,7 @@ async function testCopyPaste(isXHTML) { $("div11").childNodes[1], 2 ); - testClipboardValue("text/unicode", "Xdiv11"); + testClipboardValue("text/plain", "Xdiv11"); testHtmlClipboardValue("text/html", "

Xdiv11

"); await new Promise(resolve => { @@ -520,7 +520,7 @@ async function testCopyPaste(isXHTML) { 2 ); - testClipboardValue("text/unicode", "Xdiv12"); + testClipboardValue("text/plain", "Xdiv12"); testHtmlClipboardValue("text/html", "

Xdiv12

"); await new Promise(resolve => { setTimeout(resolve, 0); @@ -539,18 +539,18 @@ async function testCopyPaste(isXHTML) { // Ruby annotation is included when selecting inside ruby. await copyRangeToClipboard(ruby1, 0, ruby1, 6); - testClipboardValue("text/unicode", "aabb(AABB)"); + testClipboardValue("text/plain", "aabb(AABB)"); // Ruby annotation is ignored when selecting across ruby. await copyRangeToClipboard(ruby1Container, 0, ruby1Container, 3); - testClipboardValue("text/unicode", "XaabbY"); + testClipboardValue("text/plain", "XaabbY"); // ... unless converter.html2txt.always_include_ruby is set await SpecialPowers.pushPrefEnv({ set: [["converter.html2txt.always_include_ruby", true]], }); await copyRangeToClipboard(ruby1Container, 0, ruby1Container, 3); - testClipboardValue("text/unicode", "Xaabb(AABB)Y"); + testClipboardValue("text/plain", "Xaabb(AABB)Y"); await SpecialPowers.popPrefEnv(); } } diff --git a/dom/base/test/test_bug116083.html b/dom/base/test/test_bug116083.html index 2946db60df45..a1736d6cce6f 100644 --- a/dom/base/test/test_bug116083.html +++ b/dom/base/test/test_bug116083.html @@ -59,8 +59,8 @@ function hasExpectedFlavors() { var cb = Cc["@mozilla.org/widget/clipboard;1"]. getService(Ci.nsIClipboard); - ok(cb.hasDataMatchingFlavors(["text/unicode"], cb.kGlobalClipboard), - "The clipboard has text/unicode"); + ok(cb.hasDataMatchingFlavors(["text/plain"], cb.kGlobalClipboard), + "The clipboard has text/plain"); ok(cb.hasDataMatchingFlavors(["text/html"], cb.kGlobalClipboard), "The clipboard has text/html"); diff --git a/dom/base/test/test_bug166235.html b/dom/base/test/test_bug166235.html index 4ea3f7de89b7..9743d725f680 100644 --- a/dom/base/test/test_bug166235.html +++ b/dom/base/test/test_bug166235.html @@ -50,7 +50,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=816298 window.getSelection().selectAllChildren(document.getElementById(id)); documentViewer.copySelection(); - is(clipboard.hasDataMatchingFlavors(["text/unicode"], 1), true); + is(clipboard.hasDataMatchingFlavors(["text/plain"], 1), true); is(clipboard.hasDataMatchingFlavors(["text/html"], 1), true); } function getClipboardData(mime) { @@ -110,7 +110,7 @@ var clipboardHTML = [ '

This text should be copied.

', ]; -// expected results for clipboard text/unicode +// expected results for clipboard text/plain var clipboardUnicode = [ 'This text should be copied.', 'This text should be copied.', @@ -145,7 +145,7 @@ for (var i = 0; i < originalStrings.length; i++) { copyChildrenToClipboard(id); is(window.getSelection().toString(), originalStrings[i], id + ' Selection.toString()'); testHtmlClipboardValue("text/html", clipboardHTML[i], id); - testClipboardValue("text/unicode", clipboardUnicode[i], id); + testClipboardValue("text/plain", clipboardUnicode[i], id); testInnerHTML(id, innerHTMLStrings[i]); testPasteText(textareaStrings[i], id + '.innerHTML'); } diff --git a/dom/base/test/test_clipboard_nbsp.html b/dom/base/test/test_clipboard_nbsp.html index 93d60934bec8..a40c7246f64e 100644 --- a/dom/base/test/test_clipboard_nbsp.html +++ b/dom/base/test/test_clipboard_nbsp.html @@ -80,7 +80,7 @@ async function clipboardTextForElementId(aDomId, aExpectedString) { function setup() { synthesizeKey("C", {accelKey: true}); }, - "text/unicode"); + "text/plain"); return copiedText; } diff --git a/dom/base/test/test_copyimage.html b/dom/base/test/test_copyimage.html index 484e5639f1a7..0badf940e5b9 100644 --- a/dom/base/test/test_copyimage.html +++ b/dom/base/test/test_copyimage.html @@ -57,15 +57,15 @@ function testCopyImage () { //--------- Let's check the content of the clipboard now. - // Does the clipboard contain text/unicode data ? - ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard), "clipboard contains unicode text"); + // Does the clipboard contain text/plain data ? + ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard), "clipboard contains unicode text"); // Does the clipboard contain text/html data ? ok(clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard), "clipboard contains html text"); // Does the clipboard contain image data ? ok(clipboard.hasDataMatchingFlavors(["image/png"], clipboard.kGlobalClipboard), "clipboard contains image"); - // Is the text/uncodie data correct ? - testClipboardValue('text/unicode', 'about:logo'); + // Is the text/plain data correct ? + testClipboardValue('text/plain', 'about:logo'); // Is the text/html data correct ? var expected = ''; if (navigator.platform.includes("Win")) { diff --git a/dom/base/test/test_copypaste.xhtml b/dom/base/test/test_copypaste.xhtml index 370d8aebedb5..ebc137156062 100644 --- a/dom/base/test/test_copypaste.xhtml +++ b/dom/base/test/test_copypaste.xhtml @@ -6,10 +6,10 @@ This test is different from test_copypaste.html in two ways: 1. The text/html clipboard flavor isn't tested, since nsCopySupport doesn't produce it for XHTML. - 2. The text/unicode flavor isn't tested when the selection is in hidden + 2. The text/plain flavor isn't tested when the selection is in hidden elements, since nsCopySupport doesn't produce text/plain for hidden elements, and unlike HTML, neither does it produce text/_moz_htmlcontext - and text/_moz_htmlinfo, which the clipboard converts to text/unicode. + and text/_moz_htmlinfo, which the clipboard converts to text/plain. --> diff --git a/dom/base/test/test_copypaste_disabled.html b/dom/base/test/test_copypaste_disabled.html index 2accb4a9dddc..06dbdbc77991 100644 --- a/dom/base/test/test_copypaste_disabled.html +++ b/dom/base/test/test_copypaste_disabled.html @@ -82,7 +82,7 @@ waitUntilApzStable().then(async function() { let element = doc.getElementById(id); dragSelect(element, 0, 60); await copySelectionToClipboard(); - testClipboardValue("text/unicode", element.value.substr(0, 3)); + testClipboardValue("text/plain", element.value.substr(0, 3)); } } diff --git a/dom/base/test/useractivation/file_clipboard_common.js b/dom/base/test/useractivation/file_clipboard_common.js index e205819c8816..10320b1ad157 100644 --- a/dom/base/test/useractivation/file_clipboard_common.js +++ b/dom/base/test/useractivation/file_clipboard_common.js @@ -91,7 +91,7 @@ function cutCopyAll( aSetup, aNext, aNext, - "text/unicode", + "text/plain", WATCH_TIMEOUT, true ); diff --git a/dom/events/Clipboard.cpp b/dom/events/Clipboard.cpp index e3cc580a3545..5b099586f1e8 100644 --- a/dom/events/Clipboard.cpp +++ b/dom/events/Clipboard.cpp @@ -97,7 +97,7 @@ void Clipboard::ReadRequest::Answer() { // Mandatory data types defined in // https://w3c.github.io/clipboard-apis/#mandatory-data-types-x AutoTArray{nsDependentCString(kHTMLMime), - nsDependentCString(kUnicodeMime), + nsDependentCString(kTextMime), nsDependentCString(kPNGImageMime)}, nsIClipboard::kGlobalClipboard) ->Then( @@ -123,10 +123,7 @@ void Clipboard::ReadRequest::Answer() { RefPtr entry = MakeRefPtr( - format.EqualsLiteral(kUnicodeMime) - ? NS_ConvertUTF8toUTF16(kTextMime) - : NS_ConvertUTF8toUTF16(format), - format); + NS_ConvertUTF8toUTF16(format), format); entry->LoadData(*global, *trans); entries.AppendElement(std::move(entry)); } @@ -152,7 +149,7 @@ void Clipboard::ReadRequest::Answer() { } trans->Init(nullptr); - trans->AddDataFlavor(kUnicodeMime); + trans->AddDataFlavor(kTextMime); clipboardService->AsyncGetData(trans, nsIClipboard::kGlobalClipboard) ->Then( GetMainThreadSerialEventTarget(), __func__, @@ -160,7 +157,7 @@ void Clipboard::ReadRequest::Answer() { [trans, p]() { nsCOMPtr data; nsresult rv = - trans->GetTransferData(kUnicodeMime, getter_AddRefs(data)); + trans->GetTransferData(kTextMime, getter_AddRefs(data)); nsAutoString str; if (!NS_WARN_IF(NS_FAILED(rv))) { @@ -681,7 +678,7 @@ already_AddRefed Clipboard::WriteText(const nsAString& aData, nsTArray> items; items.AppendElement(MakeRefPtr( - NS_LITERAL_STRING_FROM_CSTRING(kTextMime), nsLiteralCString(kUnicodeMime), + NS_LITERAL_STRING_FROM_CSTRING(kTextMime), nsLiteralCString(kTextMime), std::move(data))); nsTArray> sequence; diff --git a/dom/events/ClipboardItem.cpp b/dom/events/ClipboardItem.cpp index 62d90aef8fcf..391e380cec59 100644 --- a/dom/events/ClipboardItem.cpp +++ b/dom/events/ClipboardItem.cpp @@ -22,15 +22,7 @@ NS_IMPL_CYCLE_COLLECTION(ClipboardItem::ItemEntry, mData, ClipboardItem::ItemEntry::ItemEntry(const nsAString& aType, const nsACString& aFormat) - : mType(aType), mFormat(aFormat) { - // XXX https://bugzilla.mozilla.org/show_bug.cgi?id=1776879. - // In most of cases, the mType and mFormat are the same, execpt for plain - // text. We expose it as "text/plain" to the web, but we use "text/unicode" - // internally to retrieve from system clipboard. - MOZ_ASSERT_IF( - !mType.Equals(NS_ConvertUTF8toUTF16(mFormat)), - mType.EqualsLiteral(kTextMime) && mFormat.EqualsLiteral(kUnicodeMime)); -} + : mType(aType), mFormat(aFormat) {} void ClipboardItem::ItemEntry::SetData(already_AddRefed&& aBlob) { // XXX maybe we could consider adding a method to check whether the union @@ -190,9 +182,7 @@ already_AddRefed ClipboardItem::Constructor( nsTArray> items; for (const auto& entry : aItems.Entries()) { - nsAutoCString format = entry.mKey.EqualsLiteral(kTextMime) - ? nsAutoCString(kUnicodeMime) - : NS_ConvertUTF16toUTF8(entry.mKey); + nsAutoCString format = NS_ConvertUTF16toUTF8(entry.mKey); items.AppendElement( MakeRefPtr(entry.mKey, format, entry.mValue)); } diff --git a/dom/events/DataTransfer.cpp b/dom/events/DataTransfer.cpp index 4d7fd691e345..60b905e15370 100644 --- a/dom/events/DataTransfer.cpp +++ b/dom/events/DataTransfer.cpp @@ -622,8 +622,8 @@ already_AddRefed DataTransfer::MozCloneForEvent( // The order of the types matters. `kFileMime` needs to be one of the first two // types. static const char* kNonPlainTextExternalFormats[] = { - kCustomTypesMime, kFileMime, kHTMLMime, kRTFMime, kURLMime, - kURLDataMime, kUnicodeMime, kPNGImageMime, kPDFJSMime}; + kCustomTypesMime, kFileMime, kHTMLMime, kRTFMime, kURLMime, + kURLDataMime, kTextMime, kPNGImageMime, kPDFJSMime}; /* static */ void DataTransfer::GetExternalClipboardFormats(const int32_t& aWhichClipboard, @@ -643,12 +643,12 @@ void DataTransfer::GetExternalClipboardFormats(const int32_t& aWhichClipboard, if (aPlainTextOnly) { bool hasType; - AutoTArray unicodeMime = {nsDependentCString(kUnicodeMime)}; - nsresult rv = clipboard->HasDataMatchingFlavors(unicodeMime, - aWhichClipboard, &hasType); + AutoTArray textMime = {nsDependentCString(kTextMime)}; + nsresult rv = + clipboard->HasDataMatchingFlavors(textMime, aWhichClipboard, &hasType); NS_SUCCEEDED(rv); if (hasType) { - aResult->AppendElement(kUnicodeMime); + aResult->AppendElement(kTextMime); } return; } @@ -685,9 +685,9 @@ void DataTransfer::GetExternalTransferableFormats( aTransferable->FlavorsTransferableCanExport(flavors); if (aPlainTextOnly) { - auto index = flavors.IndexOf(nsLiteralCString(kUnicodeMime)); + auto index = flavors.IndexOf(nsLiteralCString(kTextMime)); if (index != flavors.NoIndex) { - aResult->AppendElement(nsLiteralCString(kUnicodeMime)); + aResult->AppendElement(nsLiteralCString(kTextMime)); } return; } @@ -1084,27 +1084,20 @@ already_AddRefed DataTransfer::GetTransferable( continue; } - // The underlying drag code uses text/unicode, so use that instead of - // text/plain - const char* format; - NS_ConvertUTF16toUTF8 utf8format(type); - if (utf8format.EqualsLiteral(kTextMime)) { - format = kUnicodeMime; - } else { - format = utf8format.get(); - } + NS_ConvertUTF16toUTF8 format(type); // If a converter is set for a format, set the converter for the // transferable and don't add the item nsCOMPtr converter = do_QueryInterface(convertedData); if (converter) { - transferable->AddDataFlavor(format); + transferable->AddDataFlavor(format.get()); transferable->SetConverter(converter); continue; } - nsresult rv = transferable->SetTransferData(format, convertedData); + nsresult rv = + transferable->SetTransferData(format.get(), convertedData); if (NS_FAILED(rv)) { return nullptr; } @@ -1225,7 +1218,7 @@ void DataTransfer::SetDataWithPrincipalFromOtherProcess( void DataTransfer::GetRealFormat(const nsAString& aInFormat, nsAString& aOutFormat) const { - // treat text/unicode as equivalent to text/plain + // For compatibility, treat text/unicode as equivalent to text/plain nsAutoString lowercaseFormat; nsContentUtils::ASCIIToLower(aInFormat, lowercaseFormat); if (lowercaseFormat.EqualsLiteral("text") || @@ -1248,7 +1241,7 @@ nsresult DataTransfer::CacheExternalData(const char* aFormat, uint32_t aIndex, ErrorResult rv; RefPtr item; - if (strcmp(aFormat, kUnicodeMime) == 0) { + if (strcmp(aFormat, kTextMime) == 0) { item = mItems->SetDataWithPrincipal(u"text/plain"_ns, nullptr, aIndex, aPrincipal, false, aHidden, rv); if (NS_WARN_IF(rv.Failed())) { @@ -1298,8 +1291,8 @@ void DataTransfer::CacheExternalDragFormats() { // XXXndeakin there are some other formats but those are platform specific. // NOTE: kFileMime must have index 0 // TODO: should this be `kNonPlainTextExternalFormats` instead? - static const char* formats[] = {kFileMime, kHTMLMime, kURLMime, - kURLDataMime, kUnicodeMime, kPNGImageMime}; + static const char* formats[] = {kFileMime, kHTMLMime, kURLMime, + kURLDataMime, kTextMime, kPNGImageMime}; uint32_t count; dragSession->GetNumDropItems(&count); @@ -1350,10 +1343,10 @@ void DataTransfer::CacheExternalClipboardFormats(bool aPlainTextOnly) { } if (aPlainTextOnly) { - // The only thing that will be in types is kUnicodeMime + // The only thing that will be in types is kTextMime MOZ_ASSERT(typesArray.IsEmpty() || typesArray.Length() == 1); if (typesArray.Length() == 1) { - CacheExternalData(kUnicodeMime, 0, sysPrincipal, false); + CacheExternalData(kTextMime, 0, sysPrincipal, false); } return; } diff --git a/dom/events/DataTransfer.h b/dom/events/DataTransfer.h index c72d3a0d6d0f..7a3cd4986070 100644 --- a/dom/events/DataTransfer.h +++ b/dom/events/DataTransfer.h @@ -365,7 +365,7 @@ class DataTransfer final : public nsISupports, public nsWrapperCache { DataTransfer** aResult); // converts some formats used for compatibility in aInFormat into aOutFormat. - // Text and text/unicode become text/plain, and URL becomes text/uri-list + // Text becomes text/plain, and URL becomes text/uri-list void GetRealFormat(const nsAString& aInFormat, nsAString& aOutFormat) const; static bool PrincipalMaySetData(const nsAString& aFormat, nsIVariant* aData, diff --git a/dom/events/DataTransferItem.cpp b/dom/events/DataTransferItem.cpp index 0b7105a7ce95..94869b4c4ee1 100644 --- a/dom/events/DataTransferItem.cpp +++ b/dom/events/DataTransferItem.cpp @@ -150,9 +150,7 @@ void DataTransferItem::FillInExternalData() { NS_ConvertUTF16toUTF8 utf8format(mType); const char* format = utf8format.get(); - if (strcmp(format, "text/plain") == 0) { - format = kUnicodeMime; - } else if (strcmp(format, "text/uri-list") == 0) { + if (strcmp(format, "text/uri-list") == 0) { format = kURLDataMime; } diff --git a/dom/events/test/clipboard/test_async_clipboard.xhtml b/dom/events/test/clipboard/test_async_clipboard.xhtml index 4f531f3d7b27..787821efc3ea 100644 --- a/dom/events/test/clipboard/test_async_clipboard.xhtml +++ b/dom/events/test/clipboard/test_async_clipboard.xhtml @@ -24,10 +24,6 @@ "resource://gre/modules/PlacesUtils.jsm" ); - // Some of the clipboard code requires reading or writing "text/unicode" when - // actually "text/plain" is desired. - const kTextUnicodeMimeType = "text/unicode"; - const kTextPlainMimeType = "text/plain"; function clearClipboard() { @@ -38,7 +34,7 @@ let expected = "x"; await SimpleTest.promiseClipboardChange(expected, () => { SpecialPowers.clipboardCopyString(expected); - }, kTextUnicodeMimeType); + }, kTextPlainMimeType); let items = await navigator.clipboard.read(); is(items.length, 1, "read() read exactly one item"); const actual = await items[0].getType(kTextPlainMimeType).then(blob => blob.text()); @@ -54,7 +50,7 @@ // eslint-disable-next-line no-undef let item = new ClipboardItem({[kTextPlainMimeType]: expected}); await navigator.clipboard.write([item]); - let actual = SpecialPowers.getClipboardData(kTextUnicodeMimeType); + let actual = SpecialPowers.getClipboardData(kTextPlainMimeType); is(actual, expected, "write() wrote the right thing"); } @@ -62,7 +58,7 @@ let expected = "x"; await SimpleTest.promiseClipboardChange(expected, () => { SpecialPowers.clipboardCopyString(expected); - }, kTextUnicodeMimeType); + }, kTextPlainMimeType); let actual = await navigator.clipboard.readText(); is(actual, expected, "readText() read the right thing"); } @@ -74,7 +70,7 @@ let expected = "x"; await navigator.clipboard.writeText(expected); - let actual = SpecialPowers.getClipboardData(kTextUnicodeMimeType); + let actual = SpecialPowers.getClipboardData(kTextPlainMimeType); is(actual, expected, "writeText() wrote the right thing"); } diff --git a/dom/events/test/test_bug1327798.html b/dom/events/test/test_bug1327798.html index 9130353c759a..ac903654f17b 100644 --- a/dom/events/test/test_bug1327798.html +++ b/dom/events/test/test_bug1327798.html @@ -26,8 +26,8 @@ SimpleTest.waitForFocus(() => { //--------- now check the content of the clipboard var clipboard = SpecialPowers.Cc["@mozilla.org/widget/clipboard;1"] .getService(SpecialPowers.Ci.nsIClipboard); - // does the clipboard contain text/unicode data ? - ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard), + // does the clipboard contain text/plain data ? + ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard), "clipboard contains unicode text"); // does the clipboard contain text/html data ? ok(clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard), diff --git a/dom/events/test/test_dragstart.html b/dom/events/test/test_dragstart.html index c1d482874e21..680d162868b8 100644 --- a/dom/events/test/test_dragstart.html +++ b/dom/events/test/test_dragstart.html @@ -142,13 +142,14 @@ function doDragStartSelection(event) is(dt.getData("text/html"), "
This is a draggable bit of text.
", "initial selection text/html"); - // text/unicode and Text are available for compatibility. They retrieve the - // text/plain data - is(dt.getData("text/unicode"), "This is a draggable bit of text.", "initial selection text/unicode"); + // text/plain and Text are available for compatibility. They retrieve the + // text/plain data. text/unicode is also for compatibility and retreives the plain text. + is(dt.getData("text/plain"), "This is a draggable bit of text.", "initial selection text/plain"); is(dt.getData("Text"), "This is a draggable bit of text.", "initial selection Text"); is(dt.getData("TEXT"), "This is a draggable bit of text.", "initial selection TEXT"); - is(dt.getData("text/UNICODE"), "This is a draggable bit of text.", "initial selection text/UNICODE"); - + is(dt.getData("text/PLAIN"), "This is a draggable bit of text.", "initial selection text/PLAIN"); + is(dt.getData("text/unicode"), "This is a draggable bit of text.", "initial selection text/unicode"); + is(SpecialPowers.wrap(dt).mozItemCount, 1, "initial selection item count"); dt.clearData("text/plain"); diff --git a/dom/events/test/test_paste_image.html b/dom/events/test/test_paste_image.html index 8b173f8da56a..8398ed35e6a4 100644 --- a/dom/events/test/test_paste_image.html +++ b/dom/events/test/test_paste_image.html @@ -88,8 +88,8 @@ //--------- now check the content of the clipboard var clipboard = SpecialPowers.Cc["@mozilla.org/widget/clipboard;1"] .getService(SpecialPowers.Ci.nsIClipboard); - // does the clipboard contain text/unicode data ? - ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard), + // does the clipboard contain text/plain data ? + ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard), "clipboard contains unicode text"); // does the clipboard contain text/html data ? ok(clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard), diff --git a/dom/ipc/tests/browser_child_clipboard_restricted.js b/dom/ipc/tests/browser_child_clipboard_restricted.js index bf933dfe4b7f..d53cb9f3e91f 100644 --- a/dom/ipc/tests/browser_child_clipboard_restricted.js +++ b/dom/ipc/tests/browser_child_clipboard_restricted.js @@ -23,8 +23,8 @@ add_task(async function() { trans.addDataFlavor("text/unknown"); trans.setTransferData("text/unknown", string); - trans.addDataFlavor("text/unicode"); - trans.setTransferData("text/unicode", string); + trans.addDataFlavor("text/plain"); + trans.setTransferData("text/plain", string); // Write to clipboard. Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard); @@ -34,7 +34,7 @@ add_task(async function() { for (var i = 0; i < 20; i++) { if ( Services.clipboard.hasDataMatchingFlavors( - ["text/unicode"], + ["text/plain"], Services.clipboard.kGlobalClipboard ) ) { @@ -57,16 +57,16 @@ add_task(async function() { ok( Services.clipboard.hasDataMatchingFlavors( - ["text/unicode"], + ["text/plain"], Services.clipboard.kGlobalClipboard ), - "clipboard should have text/unicode" + "clipboard should have text/plain" ); is( - readClipboard("text/unicode"), + readClipboard("text/plain"), "blablabla", - "matching string for text/unicode" + "matching string for text/plain" ); ok( diff --git a/dom/serializers/nsDocumentEncoder.cpp b/dom/serializers/nsDocumentEncoder.cpp index e8acd399af92..3fbbb942546b 100644 --- a/dom/serializers/nsDocumentEncoder.cpp +++ b/dom/serializers/nsDocumentEncoder.cpp @@ -1551,7 +1551,7 @@ nsHTMLCopyEncoder::Init(Document* aDocument, const nsAString& aMimeType, mIsCopying = true; mDocument = aDocument; - // Hack, hack! Traditionally, the caller passes text/unicode, which is + // Hack, hack! Traditionally, the caller passes text/plain, which is // treated as "guess text/html or text/plain" in this context. (It has a // different meaning in other contexts. Sigh.) From now on, "text/plain" // means forcing text/plain instead of guessing. diff --git a/dom/tests/mochitest/general/test_paste_selection.html b/dom/tests/mochitest/general/test_paste_selection.html index 3b38c40d495b..b39915d1659e 100644 --- a/dom/tests/mochitest/general/test_paste_selection.html +++ b/dom/tests/mochitest/general/test_paste_selection.html @@ -20,8 +20,8 @@ var supportsSelectionClipboard = SpecialPowers.supportsSelectionClipboard(); function checkSelectionClipboardText(count) { if ((!supportsSelectionClipboard || - SpecialPowers.getClipboardData("text/unicode", SpecialPowers.Ci.nsIClipboard.kSelectionClipboard) == "COPY TEXT") && - SpecialPowers.getClipboardData("text/unicode", SpecialPowers.Ci.nsIClipboard.kGlobalClipboard) == "CLIPBOARD") { + SpecialPowers.getClipboardData("text/plain", SpecialPowers.Ci.nsIClipboard.kSelectionClipboard) == "COPY TEXT") && + SpecialPowers.getClipboardData("text/plain", SpecialPowers.Ci.nsIClipboard.kGlobalClipboard) == "CLIPBOARD") { pasteArea(); return; } diff --git a/dom/tests/mochitest/general/window_clipboard_events.html b/dom/tests/mochitest/general/window_clipboard_events.html index 7b720e2801e9..ee88cc5fa0c2 100644 --- a/dom/tests/mochitest/general/window_clipboard_events.html +++ b/dom/tests/mochitest/general/window_clipboard_events.html @@ -102,7 +102,7 @@ async function reset() { } function getClipboardText() { - return SpecialPowers.getClipboardData("text/unicode"); + return SpecialPowers.getClipboardData("text/plain"); } function getHTMLEditor() { diff --git a/dom/tests/mochitest/keyhandling/test_editor.xhtml b/dom/tests/mochitest/keyhandling/test_editor.xhtml index f8fdee41302b..9ddbe4adc0bd 100644 --- a/dom/tests/mochitest/keyhandling/test_editor.xhtml +++ b/dom/tests/mochitest/keyhandling/test_editor.xhtml @@ -190,7 +190,7 @@ info("cut"); await synthesizeKey(VK.X, { accelKey: true }, "x"); await checkElement(editor, 0, "", ""); - let text = SpecialPowers.getClipboardData("text/unicode"); + let text = SpecialPowers.getClipboardData("text/plain"); is(text, "Test text", "Should have cut to the clipboard"); SpecialPowers.clipboardCopyString("New text"); diff --git a/dom/tests/mochitest/keyhandling/test_input.html b/dom/tests/mochitest/keyhandling/test_input.html index e9c5a8697828..f4ec1dddf56f 100644 --- a/dom/tests/mochitest/keyhandling/test_input.html +++ b/dom/tests/mochitest/keyhandling/test_input.html @@ -146,7 +146,7 @@ async function startTest() { info("cut"); await synthesizeKey(VK.X, { accelKey: true }, "x", "input"); await checkElement(input, 0, 0, ""); - let text = SpecialPowers.getClipboardData("text/unicode"); + let text = SpecialPowers.getClipboardData("text/plain"); is(text, "Test text", "Should have cut to the clipboard"); SpecialPowers.clipboardCopyString("New text"); diff --git a/dom/tests/mochitest/keyhandling/test_textarea.html b/dom/tests/mochitest/keyhandling/test_textarea.html index 57506790fc40..613baac0c95d 100644 --- a/dom/tests/mochitest/keyhandling/test_textarea.html +++ b/dom/tests/mochitest/keyhandling/test_textarea.html @@ -146,7 +146,7 @@ async function startTest() { info("cut"); await synthesizeKey(VK.X, { accelKey: true }, "x", "input"); await checkElement(input, 0, 0, ""); - let text = SpecialPowers.getClipboardData("text/unicode"); + let text = SpecialPowers.getClipboardData("text/plain"); is(text, "Test text", "Should have cut to the clipboard"); SpecialPowers.clipboardCopyString("New text"); diff --git a/editor/libeditor/EditorUtils.cpp b/editor/libeditor/EditorUtils.cpp index 1bfb94df02f6..d02d234b2300 100644 --- a/editor/libeditor/EditorUtils.cpp +++ b/editor/libeditor/EditorUtils.cpp @@ -221,10 +221,10 @@ EditorUtils::CreateTransferableForPlainText(const Document& aDocument) { NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "nsITransferable::Init() failed, but ignored"); - rvIgnored = transferable->AddDataFlavor(kUnicodeMime); + rvIgnored = transferable->AddDataFlavor(kTextMime); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), - "nsITransferable::AddDataFlavor(kUnicodeMime) failed, but ignored"); + "nsITransferable::AddDataFlavor(kTextMime) failed, but ignored"); rvIgnored = transferable->AddDataFlavor(kMozTextInternal); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), diff --git a/editor/libeditor/EditorUtils.h b/editor/libeditor/EditorUtils.h index 6d2e7646a241..5e96d8f1cf19 100644 --- a/editor/libeditor/EditorUtils.h +++ b/editor/libeditor/EditorUtils.h @@ -432,7 +432,7 @@ class EditorUtils final { const nsINode& aParentNode, uint32_t aOffset); /** - * Create an nsITransferable instance which has kUnicodeMime and + * Create an nsITransferable instance which has kTextMime and * kMozTextInternal flavors. */ static Result, nsresult> diff --git a/editor/libeditor/HTMLEditorDataTransfer.cpp b/editor/libeditor/HTMLEditorDataTransfer.cpp index 0d08d4cc535c..1845822ad2c4 100644 --- a/editor/libeditor/HTMLEditorDataTransfer.cpp +++ b/editor/libeditor/HTMLEditorDataTransfer.cpp @@ -1463,10 +1463,10 @@ void HTMLEditor::HTMLTransferablePreparer::AddDataFlavorsInBestOrder( break; } } - DebugOnly rvIgnored = aTransferable.AddDataFlavor(kUnicodeMime); + DebugOnly rvIgnored = aTransferable.AddDataFlavor(kTextMime); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), - "nsITransferable::AddDataFlavor(kUnicodeMime) failed, but ignored"); + "nsITransferable::AddDataFlavor(kTextMime) failed, but ignored"); rvIgnored = aTransferable.AddDataFlavor(kMozTextInternal); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), @@ -2035,7 +2035,7 @@ nsresult HTMLEditor::InsertFromTransferableAtSelection( } } if (bestFlavor.EqualsLiteral(kHTMLMime) || - bestFlavor.EqualsLiteral(kUnicodeMime) || + bestFlavor.EqualsLiteral(kTextMime) || bestFlavor.EqualsLiteral(kMozTextInternal)) { nsAutoString stuffToPaste; if (!GetString(genericDataObj, stuffToPaste)) { @@ -2542,8 +2542,8 @@ nsresult HTMLEditor::PasteNoFormattingAsAction(int32_t aSelectionType, // The following arrays contain the MIME types that we can paste. The arrays // are used by CanPaste() and CanPasteTransferable() below. -static const char* textEditorFlavors[] = {kUnicodeMime}; -static const char* textHtmlEditorFlavors[] = {kUnicodeMime, kHTMLMime, +static const char* textEditorFlavors[] = {kTextMime}; +static const char* textHtmlEditorFlavors[] = {kTextMime, kHTMLMime, kJPEGImageMime, kJPGImageMime, kPNGImageMime, kGIFImageMime}; @@ -2792,10 +2792,10 @@ nsresult HTMLEditor::PasteAsPlaintextQuotation(int32_t aSelectionType) { "nsITransferable::Init() failed, but ignored"); // We only handle plaintext pastes here - rvIgnored = transferable->AddDataFlavor(kUnicodeMime); + rvIgnored = transferable->AddDataFlavor(kTextMime); NS_WARNING_ASSERTION( NS_SUCCEEDED(rvIgnored), - "nsITransferable::AddDataFlavor(kUnicodeMime) failed, but ignored"); + "nsITransferable::AddDataFlavor(kTextMime) failed, but ignored"); // Get the Data from the clipboard rvIgnored = clipboard->GetData(transferable, aSelectionType); @@ -2813,7 +2813,7 @@ nsresult HTMLEditor::PasteAsPlaintextQuotation(int32_t aSelectionType) { return rv; } - if (!flavor.EqualsLiteral(kUnicodeMime)) { + if (!flavor.EqualsLiteral(kTextMime)) { return NS_OK; } diff --git a/editor/libeditor/TextEditor.cpp b/editor/libeditor/TextEditor.cpp index cb9c4d6f96d2..1527013a9cde 100644 --- a/editor/libeditor/TextEditor.cpp +++ b/editor/libeditor/TextEditor.cpp @@ -593,8 +593,7 @@ nsresult TextEditor::PasteAsQuotationAsAction(int32_t aClipboardType, return EditorBase::ToGenericNSResult(rv); } - if (!flav.EqualsLiteral(kUnicodeMime) && - !flav.EqualsLiteral(kMozTextInternal)) { + if (!flav.EqualsLiteral(kTextMime) && !flav.EqualsLiteral(kMozTextInternal)) { return NS_OK; } diff --git a/editor/libeditor/TextEditorDataTransfer.cpp b/editor/libeditor/TextEditorDataTransfer.cpp index 490fd81cd483..cd25aca68a38 100644 --- a/editor/libeditor/TextEditorDataTransfer.cpp +++ b/editor/libeditor/TextEditorDataTransfer.cpp @@ -53,7 +53,7 @@ nsresult TextEditor::InsertTextFromTransferable( NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), "nsITransferable::GetAnyDataTransferData() failed, but ignored"); - if (NS_SUCCEEDED(rv) && (bestFlavor.EqualsLiteral(kUnicodeMime) || + if (NS_SUCCEEDED(rv) && (bestFlavor.EqualsLiteral(kTextMime) || bestFlavor.EqualsLiteral(kMozTextInternal))) { AutoTransactionsConserveSelection dontChangeMySelection(*this); @@ -271,8 +271,7 @@ bool TextEditor::CanPaste(int32_t aClipboardType) const { } // the flavors that we can deal with - AutoTArray textEditorFlavors = { - nsDependentCString(kUnicodeMime)}; + AutoTArray textEditorFlavors = {nsDependentCString(kTextMime)}; bool haveFlavors; rv = clipboard->HasDataMatchingFlavors(textEditorFlavors, aClipboardType, @@ -294,10 +293,9 @@ bool TextEditor::CanPasteTransferable(nsITransferable* aTransferable) { } nsCOMPtr data; - nsresult rv = - aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(data)); + nsresult rv = aTransferable->GetTransferData(kTextMime, getter_AddRefs(data)); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), - "nsITransferable::GetTransferData(kUnicodeMime) failed"); + "nsITransferable::GetTransferData(kTextMime) failed"); return NS_SUCCEEDED(rv) && data; } diff --git a/editor/libeditor/tests/test_bug525389.html b/editor/libeditor/tests/test_bug525389.html index 3ecb8c8b2c61..f547b8c4925a 100644 --- a/editor/libeditor/tests/test_bug525389.html +++ b/editor/libeditor/tests/test_bug525389.html @@ -60,7 +60,7 @@ async function runTest() { if (asHTML) { trans.addDataFlavor("text/html"); } else { - trans.addDataFlavor("text/unicode"); + trans.addDataFlavor("text/plain"); } var clip = SpecialPowers.Services.clipboard; clip.getData(trans, Ci.nsIClipboard.kGlobalClipboard); @@ -103,9 +103,9 @@ async function runTest() { // ssData.data = doc.body.innerHTML; // trans.setTransferData("text/html", ssData); // } else { - // trans.addDataFlavor("text/unicode"); + // trans.addDataFlavor("text/plain"); // ssData.data = doc.body.innerHTML; - // trans.setTransferData("text/unicode", ssData); + // trans.setTransferData("text/plain", ssData); // } // // return trans; diff --git a/editor/libeditor/tests/test_bug795418-2.html b/editor/libeditor/tests/test_bug795418-2.html index 1360b2e550c5..66330b4f79a0 100644 --- a/editor/libeditor/tests/test_bug795418-2.html +++ b/editor/libeditor/tests/test_bug795418-2.html @@ -76,7 +76,7 @@ SimpleTest.waitForFocus(function() { SimpleTest.finish(); }, // TODO: bug 1686012 - SpecialPowers.isHeadless ? "text/unicode" : "text/html" + SpecialPowers.isHeadless ? "text/plain" : "text/html" ); }); diff --git a/editor/libeditor/tests/test_cut_copy_password.html b/editor/libeditor/tests/test_cut_copy_password.html index e15682cf97a2..4e0319d68c7a 100644 --- a/editor/libeditor/tests/test_cut_copy_password.html +++ b/editor/libeditor/tests/test_cut_copy_password.html @@ -37,15 +37,15 @@ SimpleTest.waitForFocus(async () => { input.setSelectionRange(0, 6); ok(true, "Trying to copy masked password..."); await copyToClipboard(null); - isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef", + isnot(SpecialPowers.getClipboardData("text/plain"), "abcdef", "Copying masked password shouldn't copy raw value into the clipboard"); - isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`, + isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`, "Copying masked password shouldn't copy masked value into the clipboard"); ok(true, "Trying to cut masked password..."); await cutToClipboard(null); - isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef", + isnot(SpecialPowers.getClipboardData("text/plain"), "abcdef", "Cutting masked password shouldn't copy raw value into the clipboard"); - isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`, + isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`, "Cutting masked password shouldn't copy masked value into the clipboard"); is(input.value, "abcdef", "Cutting masked password shouldn't modify the value"); @@ -54,19 +54,19 @@ SimpleTest.waitForFocus(async () => { input.setSelectionRange(0, 6); ok(true, "Trying to copy partially masked password..."); await copyToClipboard(null); - isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef", + isnot(SpecialPowers.getClipboardData("text/plain"), "abcdef", "Copying partially masked password shouldn't copy raw value into the clipboard"); - isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}cd${kMask}${kMask}`, + isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}cd${kMask}${kMask}`, "Copying partially masked password shouldn't copy partially masked value into the clipboard"); - isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`, + isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`, "Copying partially masked password shouldn't copy masked value into the clipboard"); ok(true, "Trying to cut partially masked password..."); await cutToClipboard(null); - isnot(SpecialPowers.getClipboardData("text/unicode"), "abcdef", + isnot(SpecialPowers.getClipboardData("text/plain"), "abcdef", "Cutting partially masked password shouldn't copy raw value into the clipboard"); - isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}cd${kMask}${kMask}`, + isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}cd${kMask}${kMask}`, "Cutting partially masked password shouldn't copy partially masked value into the clipboard"); - isnot(SpecialPowers.getClipboardData("text/unicode"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`, + isnot(SpecialPowers.getClipboardData("text/plain"), `${kMask}${kMask}${kMask}${kMask}${kMask}${kMask}`, "Cutting partially masked password shouldn't copy masked value into the clipboard"); is(input.value, "abcdef", "Cutting partially masked password shouldn't modify the value"); diff --git a/editor/libeditor/tests/test_password_paste.html b/editor/libeditor/tests/test_password_paste.html index 4f2e124077fa..817de9b277d3 100644 --- a/editor/libeditor/tests/test_password_paste.html +++ b/editor/libeditor/tests/test_password_paste.html @@ -34,7 +34,7 @@ function pasteText(str) { let s = Cc["@mozilla.org/supports-string;1"]. createInstance(Ci.nsISupportsString); s.data = str; - trans.setTransferData("text/unicode", s); + trans.setTransferData("text/plain", s); let inputEvent = null; window.addEventListener("input", aEvent => { inputEvent = aEvent; }, {once: true}); getEditor().pasteTransferable(trans); diff --git a/editor/spellchecker/tests/test_bug596333.html b/editor/spellchecker/tests/test_bug596333.html index 617037995056..ce6714565bfc 100644 --- a/editor/spellchecker/tests/test_bug596333.html +++ b/editor/spellchecker/tests/test_bug596333.html @@ -49,7 +49,7 @@ function paste(str) { trans.init(getLoadContext()); var s = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString); s.data = str; - trans.setTransferData("text/unicode", s); + trans.setTransferData("text/plain", s); let beforeInputEvent = null; let inputEvent = null; diff --git a/gfx/tests/browser/browser_native_font_cache_macos.js b/gfx/tests/browser/browser_native_font_cache_macos.js index 6bef437b624b..919a5c7a72b4 100644 --- a/gfx/tests/browser/browser_native_font_cache_macos.js +++ b/gfx/tests/browser/browser_native_font_cache_macos.js @@ -68,7 +68,7 @@ add_task(async () => { dump("********************\n"); resolve(""); }, - "text/unicode", + "text/plain", REPORT_TIMEOUT_MS ); }); diff --git a/mobile/android/actors/SelectionActionDelegateChild.jsm b/mobile/android/actors/SelectionActionDelegateChild.jsm index e8f5cf81082d..166485a5ae91 100644 --- a/mobile/android/actors/SelectionActionDelegateChild.jsm +++ b/mobile/android/actors/SelectionActionDelegateChild.jsm @@ -72,7 +72,7 @@ class SelectionActionDelegateChild extends GeckoViewActorChild { predicate: e => e.selectionEditable && Services.clipboard.hasDataMatchingFlavors( - ["text/unicode"], + ["text/plain"], Ci.nsIClipboard.kGlobalClipboard ), perform: _ => this._performPaste(), diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/Clipboard.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/Clipboard.java index 9de47406aa3f..525a85f4da08 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/Clipboard.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/Clipboard.java @@ -15,7 +15,7 @@ import org.mozilla.gecko.annotation.WrapForJNI; public final class Clipboard { private static final String HTML_MIME = "text/html"; - private static final String UNICODE_MIME = "text/unicode"; + private static final String PLAINTEXT_MIME = "text/plain"; private static final String LOGTAG = "GeckoClipboard"; private Clipboard() {} @@ -27,14 +27,14 @@ public final class Clipboard { * @return a plain text string of clipboard data. */ public static String getText(final Context context) { - return getData(context, UNICODE_MIME); + return getData(context, PLAINTEXT_MIME); } /** * Get the data on the primary clip on clipboard * * @param context application context - * @param mimeType the mime type we want. This supports text/html and text/unicode only. If other + * @param mimeType the mime type we want. This supports text/html and text/plain only. If other * type, we do nothing. * @return a string into clipboard. */ @@ -57,7 +57,7 @@ public final class Clipboard { } return data.toString(); } - if (UNICODE_MIME.equals(mimeType)) { + if (PLAINTEXT_MIME.equals(mimeType)) { try { return clip.getItemAt(0).coerceToText(context).toString(); } catch (final SecurityException e) { @@ -130,7 +130,7 @@ public final class Clipboard { @WrapForJNI(calledFrom = "gecko") public static boolean hasData(final Context context, final String mimeType) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) { - if (HTML_MIME.equals(mimeType) || UNICODE_MIME.equals(mimeType)) { + if (HTML_MIME.equals(mimeType) || PLAINTEXT_MIME.equals(mimeType)) { return !TextUtils.isEmpty(getData(context, mimeType)); } return false; @@ -155,7 +155,7 @@ public final class Clipboard { return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML); } - if (UNICODE_MIME.equals(mimeType)) { + if (PLAINTEXT_MIME.equals(mimeType)) { // We cannot check content in data at this time to avoid toast message. return description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML) || description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); diff --git a/testing/mochitest/tests/SimpleTest/SimpleTest.js b/testing/mochitest/tests/SimpleTest/SimpleTest.js index 12c8b3f6eafc..c4d92960aa45 100644 --- a/testing/mochitest/tests/SimpleTest/SimpleTest.js +++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js @@ -1063,7 +1063,7 @@ const kTextHtmlSuffixClipboardDataWindows = * Polls the clipboard waiting for the expected value. A known value different than * the expected value is put on the clipboard first (and also polled for) so we * can be sure the value we get isn't just the expected value because it was already - * on the clipboard. This only uses the global clipboard and only for text/unicode + * on the clipboard. This only uses the global clipboard and only for text/plain * values. * * @param {String|Function} aExpectedStringOrValidatorFn @@ -1087,7 +1087,7 @@ const kTextHtmlSuffixClipboardDataWindows = * @param {Function} aFailureFn * A function called if the expected value isn't found on the clipboard * within 5s. It can also be called if the known value can't be found. - * @param {String} [aFlavor="text/unicode"] + * @param {String} [aFlavor="text/plain"] * The flavor to look for. * @param {Number} [aTimeout=5000] * The timeout (in milliseconds) to wait for a clipboard change. @@ -1131,7 +1131,7 @@ SimpleTest.promiseClipboardChange = async function( aExpectFailure, aDontInitializeClipboardIfExpectFailure ) { - let requestedFlavor = aFlavor || "text/unicode"; + let requestedFlavor = aFlavor || "text/plain"; // The known value we put on the clipboard before running aSetupFn let initialVal = "waitForClipboard-known-value-" + Math.random(); @@ -1223,7 +1223,7 @@ SimpleTest.promiseClipboardChange = async function( function(aData) { return aData == preExpectedVal; }, - "text/unicode", + "text/plain", false ); diff --git a/toolkit/components/aboutmemory/tests/test_aboutmemory3.xhtml b/toolkit/components/aboutmemory/tests/test_aboutmemory3.xhtml index 50112f133077..1391af38b716 100644 --- a/toolkit/components/aboutmemory/tests/test_aboutmemory3.xhtml +++ b/toolkit/components/aboutmemory/tests/test_aboutmemory3.xhtml @@ -99,7 +99,7 @@ // differences. synthesizeKey("A", {accelKey: true}); synthesizeKey("C", {accelKey: true}); - let actual = SpecialPowers.getClipboardData("text/unicode"); + let actual = SpecialPowers.getClipboardData("text/plain"); actual = actual.replace(/\(pid \d+\)/g, "(pid NNN)"); if (actual.trim() === aExpected.trim()) { diff --git a/toolkit/components/aboutmemory/tests/test_aboutmemory4.xhtml b/toolkit/components/aboutmemory/tests/test_aboutmemory4.xhtml index 91edc7cbb3c8..9d9db694f2af 100644 --- a/toolkit/components/aboutmemory/tests/test_aboutmemory4.xhtml +++ b/toolkit/components/aboutmemory/tests/test_aboutmemory4.xhtml @@ -50,7 +50,7 @@ // differences. synthesizeKey("A", {accelKey: true}); synthesizeKey("C", {accelKey: true}); - let actual = SpecialPowers.getClipboardData("text/unicode"); + let actual = SpecialPowers.getClipboardData("text/plain"); actual = actual.replace(/\(pid \d+\)/, "(pid NNN)"); if (actual.trim() === aExpected.trim()) { diff --git a/toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml b/toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml index dcec9620aa7e..f7c0ce3d441b 100644 --- a/toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml +++ b/toolkit/components/aboutmemory/tests/test_aboutmemory5.xhtml @@ -105,7 +105,7 @@ // differences. synthesizeKey("A", {accelKey: true}); synthesizeKey("C", {accelKey: true}); - let actual = SpecialPowers.getClipboardData("text/unicode"); + let actual = SpecialPowers.getClipboardData("text/plain"); // If we have more than 1000 chars, we've probably successfully // copy+pasted. diff --git a/toolkit/components/extensions/test/mochitest/test_ext_async_clipboard.html b/toolkit/components/extensions/test/mochitest/test_ext_async_clipboard.html index c3b8da8a8c60..458dc65d990d 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_async_clipboard.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_async_clipboard.html @@ -179,7 +179,7 @@ add_task(async function test_contentscript_clipboard_permission_writetext() { await extension.startup(); let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html"); await extension.awaitMessage("ready"); - const actual = SpecialPowers.getClipboardData("text/unicode"); + const actual = SpecialPowers.getClipboardData("text/plain"); is(actual, "HI", "right string copied by write"); win.close(); await extension.unload(); @@ -219,7 +219,7 @@ add_task(async function test_contentscript_clipboard_permission_readtext() { }; await SimpleTest.promiseClipboardChange("HI", () => { SpecialPowers.clipboardCopyString("HI"); - }, "text/unicode"); + }, "text/plain"); let extension = ExtensionTestUtils.loadExtension(extensionData); await extension.startup(); let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html"); @@ -262,7 +262,7 @@ add_task(async function test_contentscript_clipboard_permission_write() { await extension.startup(); let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html"); await extension.awaitMessage("ready"); - const actual = SpecialPowers.getClipboardData("text/unicode"); + const actual = SpecialPowers.getClipboardData("text/plain"); is(actual, "HI", "right string copied by write"); win.close(); await extension.unload(); @@ -303,7 +303,7 @@ add_task(async function test_contentscript_clipboard_permission_read() { }; await SimpleTest.promiseClipboardChange("HELLO", () => { SpecialPowers.clipboardCopyString("HELLO"); - }, "text/unicode"); + }, "text/plain"); let extension = ExtensionTestUtils.loadExtension(extensionData); await extension.startup(); let win = window.open("https://example.com/tests/toolkit/components/extensions/test/mochitest/file_sample.html"); diff --git a/toolkit/components/pdfjs/test/browser_pdfjs_download_button.js b/toolkit/components/pdfjs/test/browser_pdfjs_download_button.js index 312ff16b817a..bd8bad1069e7 100644 --- a/toolkit/components/pdfjs/test/browser_pdfjs_download_button.js +++ b/toolkit/components/pdfjs/test/browser_pdfjs_download_button.js @@ -101,7 +101,7 @@ add_task(async function test_downloading_pdf_nonprivate_window() { SpecialPowers.clipboardCopyString(""); DownloadsCommon.copyDownloadLink(dl); - const copiedUrl = SpecialPowers.getClipboardData("text/unicode"); + const copiedUrl = SpecialPowers.getClipboardData("text/plain"); is(copiedUrl, pdfUrl, "The copied url must be the original one"); is( diff --git a/toolkit/components/places/PlacesUtils.sys.mjs b/toolkit/components/places/PlacesUtils.sys.mjs index 4924408142a3..f69ee570e592 100644 --- a/toolkit/components/places/PlacesUtils.sys.mjs +++ b/toolkit/components/places/PlacesUtils.sys.mjs @@ -430,7 +430,7 @@ export var PlacesUtils = { // Place entries formatted as HTML anchors TYPE_HTML: "text/html", // Place entries as raw URL text - TYPE_UNICODE: "text/unicode", + TYPE_PLAINTEXT: "text/plain", // Used to track the action that populated the clipboard. TYPE_X_MOZ_PLACE_ACTION: "text/x-moz-place-action", @@ -1102,7 +1102,7 @@ export var PlacesUtils = { } } - // Otherwise, we wrap as TYPE_UNICODE. + // Otherwise, we wrap as TYPE_PLAINTEXT. return gatherDataFromNode(aNode, gatherDataText); }, @@ -1158,11 +1158,11 @@ export var PlacesUtils = { } break; } - case this.TYPE_UNICODE: { + case this.TYPE_PLAINTEXT: { let parts = blob.split("\n"); for (let i = 0; i < parts.length; i++) { let uriString = parts[i]; - // text/uri-list is converted to TYPE_UNICODE but it could contain + // text/uri-list is converted to TYPE_PLAINTEXT but it could contain // comments line prepended by #, we should skip them, as well as // empty uris. if (uriString.substr(0, 1) == "\x23" || uriString == "") { diff --git a/toolkit/components/places/tests/unit/test_PlacesUtils_unwrapNodes_place.js b/toolkit/components/places/tests/unit/test_PlacesUtils_unwrapNodes_place.js index 9b6e842a8929..bbff4c8cac16 100644 --- a/toolkit/components/places/tests/unit/test_PlacesUtils_unwrapNodes_place.js +++ b/toolkit/components/places/tests/unit/test_PlacesUtils_unwrapNodes_place.js @@ -20,9 +20,9 @@ add_task(function() { PlacesUtils.TYPE_X_MOZ_URL, ], // Single url. - ["place:type=0&sort=1:", PlacesUtils.TYPE_UNICODE], + ["place:type=0&sort=1:", PlacesUtils.TYPE_PLAINTEXT], // Multiple urls. - ["place:type=0&sort=1:\nplace:type=0&sort=1", PlacesUtils.TYPE_UNICODE], + ["place:type=0&sort=1:\nplace:type=0&sort=1", PlacesUtils.TYPE_PLAINTEXT], ]; for (let [blob, type] of tests) { Assert.deepEqual( diff --git a/toolkit/components/reader/test/browser_drag_url_readerMode.js b/toolkit/components/reader/test/browser_drag_url_readerMode.js index 35c9d4b51851..e8a157c52723 100644 --- a/toolkit/components/reader/test/browser_drag_url_readerMode.js +++ b/toolkit/components/reader/test/browser_drag_url_readerMode.js @@ -45,7 +45,7 @@ add_task(async function test_readerModeURLDrag() { urlBarContainer.click(); urlbar.dispatchEvent(urlEvent); - let newUrl = urlEvent.dataTransfer.getData("text/unicode"); + let newUrl = urlEvent.dataTransfer.getData("text/plain"); ok(!newUrl.includes("about:reader"), "URL does not contain about:reader"); Assert.equal(newUrl, oldUrl, "URL is the same"); diff --git a/toolkit/content/aboutSupport.js b/toolkit/content/aboutSupport.js index 0be6d3752ca3..27c1b68c7492 100644 --- a/toolkit/content/aboutSupport.js +++ b/toolkit/content/aboutSupport.js @@ -1377,8 +1377,8 @@ function copyRawDataToClipboard(button) { "@mozilla.org/widget/transferable;1" ].createInstance(Ci.nsITransferable); transferable.init(getLoadContext()); - transferable.addDataFlavor("text/unicode"); - transferable.setTransferData("text/unicode", str); + transferable.addDataFlavor("text/plain"); + transferable.setTransferData("text/plain", str); Services.clipboard.setData( transferable, null, @@ -1422,9 +1422,9 @@ async function copyContentsToClipboard() { transferable.setTransferData("text/html", ssHtml); // Add the plain text flavor. - transferable.addDataFlavor("text/unicode"); + transferable.addDataFlavor("text/plain"); ssText.data = dataText; - transferable.setTransferData("text/unicode", ssText); + transferable.setTransferData("text/plain", ssText); // Store the data into the clipboard. Services.clipboard.setData( diff --git a/toolkit/modules/Finder.sys.mjs b/toolkit/modules/Finder.sys.mjs index eb27a12cdf8b..a0a82c367537 100644 --- a/toolkit/modules/Finder.sys.mjs +++ b/toolkit/modules/Finder.sys.mjs @@ -821,12 +821,12 @@ export function GetClipboardSearchString(aLoadContext) { Ci.nsITransferable ); trans.init(aLoadContext); - trans.addDataFlavor("text/unicode"); + trans.addDataFlavor("text/plain"); Services.clipboard.getData(trans, Ci.nsIClipboard.kFindClipboard); let data = {}; - trans.getTransferData("text/unicode", data); + trans.getTransferData("text/plain", data); if (data.value) { data = data.value.QueryInterface(Ci.nsISupportsString); searchString = data.toString(); diff --git a/toolkit/mozapps/extensions/internal/AddonRepository.jsm b/toolkit/mozapps/extensions/internal/AddonRepository.jsm index 548669c73171..589ba53c4ec4 100644 --- a/toolkit/mozapps/extensions/internal/AddonRepository.jsm +++ b/toolkit/mozapps/extensions/internal/AddonRepository.jsm @@ -105,7 +105,7 @@ function convertHTMLToPlainText(html) { input.data = html.replace(/\n/g, "
"); var output = {}; - converter.convert("text/html", input, "text/unicode", output); + converter.convert("text/html", input, "text/plain", output); if (output.value instanceof Ci.nsISupportsString) { return output.value.data.replace(/\r\n/g, "\n"); diff --git a/widget/android/nsClipboard.cpp b/widget/android/nsClipboard.cpp index 0dd79ff2ec1a..b9d665746a95 100644 --- a/widget/android/nsClipboard.cpp +++ b/widget/android/nsClipboard.cpp @@ -15,7 +15,7 @@ using namespace mozilla; NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard) /* The Android clipboard only supports text and doesn't support mime types - * so we assume all clipboard data is text/unicode for now. Documentation + * so we assume all clipboard data is text/plain for now. Documentation * indicates that support for other data types is planned for future * releases. */ @@ -38,10 +38,10 @@ nsClipboard::SetData(nsITransferable* aTransferable, nsIClipboardOwner* anOwner, nsAutoString text; for (auto& flavorStr : flavors) { - if (flavorStr.EqualsLiteral(kUnicodeMime)) { + if (flavorStr.EqualsLiteral(kTextMime)) { nsCOMPtr item; nsresult rv = - aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(item)); + aTransferable->GetTransferData(kTextMime, getter_AddRefs(item)); if (NS_WARN_IF(NS_FAILED(rv))) { continue; } @@ -89,7 +89,7 @@ nsClipboard::GetData(nsITransferable* aTransferable, int32_t aWhichClipboard) { aTransferable->FlavorsTransferableCanImport(flavors); for (auto& flavorStr : flavors) { - if (flavorStr.EqualsLiteral(kUnicodeMime) || + if (flavorStr.EqualsLiteral(kTextMime) || flavorStr.EqualsLiteral(kHTMLMime)) { auto text = java::Clipboard::GetData( java::GeckoAppShell::GetApplicationContext(), flavorStr); diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 4619ca5d04d6..a8475c785e9c 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -4513,7 +4513,7 @@ static CFTypeRefPtr GetPasteLocation(NSPasteboard* aPasteboard) { if (NS_FAILED(rv)) return NO; trans->Init(nullptr); - trans->AddDataFlavor(kUnicodeMime); + trans->AddDataFlavor(kTextMime); trans->AddDataFlavor(kHTMLMime); rv = nsClipboard::TransferableFromPasteboard(trans, pboard); diff --git a/widget/cocoa/nsClipboard.mm b/widget/cocoa/nsClipboard.mm index f700646264dc..3a1f7822f8f5 100644 --- a/widget/cocoa/nsClipboard.mm +++ b/widget/cocoa/nsClipboard.mm @@ -146,7 +146,9 @@ nsresult nsClipboard::TransferableFromPasteboard(nsITransferable* aTransferable, } NSData* stringData; - if ([pboardType isEqualToString:[UTIHelper stringFromPboardType:NSPasteboardTypeRTF]]) { + bool isRTF = + [pboardType isEqualToString:[UTIHelper stringFromPboardType:NSPasteboardTypeRTF]]; + if (isRTF) { stringData = [pString dataUsingEncoding:NSASCIIStringEncoding]; } else { stringData = [pString dataUsingEncoding:NSUnicodeStringEncoding]; @@ -160,7 +162,7 @@ nsresult nsClipboard::TransferableFromPasteboard(nsITransferable* aTransferable, // The DOM only wants LF, so convert from MacOS line endings to DOM line endings. int32_t signedDataLength = dataLength; - nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(flavorStr, &clipboardDataPtr, + nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(isRTF, &clipboardDataPtr, &signedDataLength); dataLength = signedDataLength; @@ -700,7 +702,7 @@ NSDictionary* nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTran } bool nsClipboard::IsStringType(const nsCString& aMIMEType, NSString** aPboardType) { - if (aMIMEType.EqualsLiteral(kUnicodeMime)) { + if (aMIMEType.EqualsLiteral(kTextMime)) { *aPboardType = [UTIHelper stringFromPboardType:NSPasteboardTypeString]; return true; } else if (aMIMEType.EqualsLiteral(kRTFMime)) { diff --git a/widget/cocoa/nsCocoaUtils.mm b/widget/cocoa/nsCocoaUtils.mm index 4eb4383ff034..94d72d0b03c9 100644 --- a/widget/cocoa/nsCocoaUtils.mm +++ b/widget/cocoa/nsCocoaUtils.mm @@ -1693,7 +1693,7 @@ void nsCocoaUtils::SetTransferDataForTypeFromPasteboardItem(nsITransferable* aTr } NSString* pString = nil; - if (aFlavor.EqualsLiteral(kUnicodeMime)) { + if (aFlavor.EqualsLiteral(kTextMime)) { pString = nsCocoaUtils::GetStringForTypeFromPasteboardItem( aItem, [UTIHelper stringFromPboardType:NSPasteboardTypeString]); } else if (aFlavor.EqualsLiteral(kHTMLMime)) { @@ -1720,7 +1720,8 @@ void nsCocoaUtils::SetTransferDataForTypeFromPasteboardItem(nsITransferable* aTr } if (pString) { NSData* stringData; - if (aFlavor.EqualsLiteral(kRTFMime)) { + bool isRTF = aFlavor.EqualsLiteral(kRTFMime); + if (isRTF) { stringData = [pString dataUsingEncoding:NSASCIIStringEncoding]; } else { stringData = [pString dataUsingEncoding:NSUnicodeStringEncoding]; @@ -1734,8 +1735,7 @@ void nsCocoaUtils::SetTransferDataForTypeFromPasteboardItem(nsITransferable* aTr // The DOM only wants LF, so convert from MacOS line endings to DOM line endings. int32_t signedDataLength = dataLength; - nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(aFlavor, &clipboardDataPtr, - &signedDataLength); + nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(isRTF, &clipboardDataPtr, &signedDataLength); dataLength = signedDataLength; // skip BOM (Byte Order Mark to distinguish little or big endian) diff --git a/widget/cocoa/nsDragService.mm b/widget/cocoa/nsDragService.mm index 4a78bea60194..4ac5c3cbc0d9 100644 --- a/widget/cocoa/nsDragService.mm +++ b/widget/cocoa/nsDragService.mm @@ -348,7 +348,7 @@ nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) { if (dataFlavor.EqualsLiteral(kFileMime)) { type = [UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL]; allowFileURL = true; - } else if (dataFlavor.EqualsLiteral(kUnicodeMime)) { + } else if (dataFlavor.EqualsLiteral(kTextMime)) { type = [UTIHelper stringFromPboardType:NSPasteboardTypeString]; } else if (dataFlavor.EqualsLiteral(kHTMLMime)) { type = [UTIHelper stringFromPboardType:NSPasteboardTypeHTML]; diff --git a/widget/gtk/nsClipboard.cpp b/widget/gtk/nsClipboard.cpp index 98869601ae78..b2b6ef336b58 100644 --- a/widget/gtk/nsClipboard.cpp +++ b/widget/gtk/nsClipboard.cpp @@ -282,8 +282,8 @@ nsClipboard::SetData(nsITransferable* aTransferable, nsIClipboardOwner* aOwner, nsCString& flavorStr = flavors[i]; LOGCLIP(" processing target %s\n", flavorStr.get()); - // Special case text/unicode since we can handle all of the string types. - if (flavorStr.EqualsLiteral(kUnicodeMime)) { + // Special case text/plain since we can handle all of the string types. + if (flavorStr.EqualsLiteral(kTextMime)) { LOGCLIP(" adding TEXT targets\n"); gtk_target_list_add_text_targets(list, 0); continue; @@ -473,7 +473,7 @@ static bool TransferableSetHTML(nsITransferable* aTransferable, Span aData) { nsLiteralCString mimeType(kHTMLMime); - // Convert text/html into our unicode format + // Convert text/html into our text format nsAutoCString charset; if (!GetHTMLCharset(aData, charset)) { // Fall back to utf-8 in case html/data is missing kHTMLMarkupPrefix. @@ -577,27 +577,27 @@ nsClipboard::GetData(nsITransferable* aTransferable, int32_t aWhichClipboard) { return NS_OK; } - // Special case text/unicode since we can convert any - // string into text/unicode - if (flavorStr.EqualsLiteral(kUnicodeMime)) { - LOGCLIP(" Getting unicode %s MIME clipboard data\n", flavorStr.get()); + // Special case text/plain since we can convert any + // string into text/plain + if (flavorStr.EqualsLiteral(kTextMime)) { + LOGCLIP(" Getting text %s MIME clipboard data\n", flavorStr.get()); auto clipboardData = mContext->GetClipboardText(aWhichClipboard); if (!clipboardData) { - LOGCLIP(" failed to get unicode data\n"); - // If the type was text/unicode and we couldn't get + LOGCLIP(" failed to get text data\n"); + // If the type was text/plain and we couldn't get // text off the clipboard, run the next loop // iteration. continue; } - // Convert utf-8 into our unicode format. + // Convert utf-8 into our text format. NS_ConvertUTF8toUTF16 ucs2string(clipboardData.get()); SetTransferableData(aTransferable, flavorStr, (const char*)ucs2string.BeginReading(), ucs2string.Length() * 2); - LOGCLIP(" got unicode data, length %zd\n", ucs2string.Length()); + LOGCLIP(" got text data, length %zd\n", ucs2string.Length()); return NS_OK; } @@ -706,14 +706,14 @@ static RefPtr AsyncGetTextImpl(nsITransferable* aTransferable, // Convert utf-8 into our unicode format. NS_ConvertUTF8toUTF16 utf16string(aText, dataLength); - nsLiteralCString flavor(kUnicodeMime); + nsLiteralCString flavor(kTextMime); SetTransferableData(ref->mTransferable, flavor, (const char*)utf16string.BeginReading(), utf16string.Length() * 2); LOGCLIP(" text is set, length = %d", (int)dataLength); ref->mDataPromise->Resolve(true, __func__); }, - new DataPromiseHandler(aTransferable, dataPromise, kUnicodeMime)); + new DataPromiseHandler(aTransferable, dataPromise, kTextMime)); return dataPromise; } @@ -812,9 +812,9 @@ static RefPtr AsyncGetDataFlavor(nsITransferable* aTransferable, return AsyncGetDataImpl(aTransferable, aWhichClipboard, aFlavorStr.get(), DATATYPE_IMAGE); } - // Special case text/unicode since we can convert any - // string into text/unicode - if (aFlavorStr.EqualsLiteral(kUnicodeMime)) { + // Special case text/plain since we can convert any + // string into text/plain + if (aFlavorStr.EqualsLiteral(kTextMime)) { LOGCLIP(" Getting unicode clipboard data"); return AsyncGetTextImpl(aTransferable, aWhichClipboard); } @@ -984,12 +984,12 @@ nsClipboard::HasDataMatchingFlavors(const nsTArray& aFlavorList, // Walk through the provided types and try to match it to a // provided type. for (auto& flavor : aFlavorList) { - // We special case text/unicode here. - if (flavor.EqualsLiteral(kUnicodeMime) && + // We special case text/plain here. + if (flavor.EqualsLiteral(kTextMime) && gtk_targets_include_text(targets.AsSpan().data(), targets.AsSpan().Length())) { *_retval = true; - LOGCLIP(" has kUnicodeMime\n"); + LOGCLIP(" has kTextMime\n"); return NS_OK; } for (const auto& target : targets.AsSpan()) { @@ -1041,11 +1041,10 @@ RefPtr nsClipboard::AsyncHasDataMatchingFlavors( if (targetsNum) { for (auto& flavor : handler->mAcceptedFlavorList) { LOGCLIP(" looking for %s", flavor.get()); - // We can convert any text to unicode. - if (flavor.EqualsLiteral(kUnicodeMime) && + if (flavor.EqualsLiteral(kTextMime) && gtk_targets_include_text(targets, targetsNum)) { results.AppendElement(flavor); - LOGCLIP(" has kUnicodeMime\n"); + LOGCLIP(" has kTextMime\n"); continue; } for (int i = 0; i < targetsNum; i++) { @@ -1085,7 +1084,7 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, GtkSelectionData* aSelectionData) { // Someone has asked us to hand them something. The first thing // that we want to do is see if that something includes text. If - // it does, try to give it text/unicode after converting it to + // it does, try to give it text/plain after converting it to // utf-8. int32_t whichClipboard; @@ -1119,13 +1118,13 @@ void nsClipboard::SelectionGetEvent(GtkClipboard* aClipboard, // Check to see if the selection data is some text type. if (gtk_targets_include_text(&selectionTarget, 1)) { - LOGCLIP(" providing text/unicode data\n"); + LOGCLIP(" providing text/plain data\n"); // Try to convert our internal type into a text string. Get // the transferable for this clipboard and try to get the - // text/unicode type for it. - rv = trans->GetTransferData("text/unicode", getter_AddRefs(item)); + // text/plain type for it. + rv = trans->GetTransferData("text/plain", getter_AddRefs(item)); if (NS_FAILED(rv) || !item) { - LOGCLIP(" GetTransferData() failed to get text/unicode!\n"); + LOGCLIP(" GetTransferData() failed to get text/plain!\n"); return; } diff --git a/widget/gtk/nsDragService.cpp b/widget/gtk/nsDragService.cpp index a648e5772571..a6507995066c 100644 --- a/widget/gtk/nsDragService.cpp +++ b/widget/gtk/nsDragService.cpp @@ -797,7 +797,13 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) { // format. SetTransferData() implicitly handles conversions. for (uint32_t i = 0; i < flavors.Length(); ++i) { nsCString& flavorStr = flavors[i]; - GdkAtom gdkFlavor = gdk_atom_intern(flavorStr.get(), FALSE); + + GdkAtom gdkFlavor; + if (flavorStr.EqualsLiteral(kTextMime)) { + gdkFlavor = gdk_atom_intern(gTextPlainUTF8Type, FALSE); + } else { + gdkFlavor = gdk_atom_intern(flavorStr.get(), FALSE); + } LOGDRAGSERVICE(" we're getting data %s (gdk flavor %p)\n", flavorStr.get(), gdkFlavor); bool dataFound = false; @@ -854,46 +860,15 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) { } } - // if we are looking for text/unicode and we fail to find it - // on the clipboard first, try again with text/plain. If that - // is present, convert it to unicode. - if (flavorStr.EqualsLiteral(kUnicodeMime)) { - LOGDRAGSERVICE(" conversion %s => %s", kUnicodeMime, - gTextPlainUTF8Type); - gdkFlavor = gdk_atom_intern(gTextPlainUTF8Type, FALSE); + // If we are looking for text/plain, try again with non utf-8 text. + if (flavorStr.EqualsLiteral(kTextMime)) { + LOGDRAGSERVICE(" conversion %s => %s", kTextMime, kTextMime); + gdkFlavor = gdk_atom_intern(kTextMime, FALSE); GetTargetDragData(gdkFlavor, dragFlavors); if (mTargetDragData) { - const char* castedText = reinterpret_cast(mTargetDragData); - char16_t* convertedText = nullptr; - NS_ConvertUTF8toUTF16 ucs2string(castedText, mTargetDragDataLen); - convertedText = ToNewUnicode(ucs2string, mozilla::fallible); - if (convertedText) { - // out with the old, in with the new - g_free(mTargetDragData); - mTargetDragData = convertedText; - mTargetDragDataLen = ucs2string.Length() * 2; - dataFound = true; - } // if plain text data on clipboard - } else { - LOGDRAGSERVICE(" conversion %s => %s", kUnicodeMime, kTextMime); - gdkFlavor = gdk_atom_intern(kTextMime, FALSE); - GetTargetDragData(gdkFlavor, dragFlavors); - if (mTargetDragData) { - const char* castedText = reinterpret_cast(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 + dataFound = true; + } // if plain text flavor present + } // if looking for text/plain // if we are looking for text/x-moz-url and we failed to find // it on the clipboard, try again with text/uri-list, and then @@ -945,6 +920,18 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) { LOGDRAGSERVICE(" actual data found %s\n", GUniquePtr(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(mTargetDragData); + NS_ConvertUTF8toUTF16 ucs2string(text, mTargetDragDataLen); + char16_t* convertedText = ToNewUnicode(ucs2string, mozilla::fallible); + if (convertedText) { + g_free(mTargetDragData); + mTargetDragData = convertedText; + mTargetDragDataLen = ucs2string.Length() * 2; + } + } + if (flavorStr.EqualsLiteral(kJPEGImageMime) || flavorStr.EqualsLiteral(kJPGImageMime) || flavorStr.EqualsLiteral(kPNGImageMime) || @@ -963,7 +950,7 @@ nsDragService::GetData(nsITransferable* aTransferable, uint32_t aItemIndex) { // the DOM only wants LF, so convert from MacOS line endings // to DOM line endings. nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks( - flavorStr, &mTargetDragData, + flavorStr.EqualsLiteral(kRTFMime), &mTargetDragData, reinterpret_cast(&mTargetDragDataLen)); } @@ -1062,11 +1049,6 @@ nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) { (strcmp(aDataFlavor, kURLMime) == 0)) { *_retval = true; } - // check for auto text/plain -> text/unicode mapping - else if (strcmp(name.get(), kTextMime) == 0 && - (strcmp(aDataFlavor, kUnicodeMime) == 0)) { - *_retval = true; - } if (*_retval) { LOGDRAGSERVICE(" supported, with converting %s => %s", name.get(), @@ -1374,13 +1356,9 @@ GtkTargetList* nsDragService::GetSourceList(void) { if (flavorStr.EqualsLiteral(kFileMime)) { TargetArrayAddTarget(targetArray, gTextUriListType); } - // Check to see if this is text/unicode. - // If it is, add text/plain - // since we automatically support text/plain - // if we support text/unicode. - else if (flavorStr.EqualsLiteral(kUnicodeMime)) { + // Check to see if this is text/plain. + else if (flavorStr.EqualsLiteral(kTextMime)) { TargetArrayAddTarget(targetArray, gTextPlainUTF8Type); - TargetArrayAddTarget(targetArray, kTextMime); } // Check to see if this is the x-moz-url type. // If it is, add _NETSCAPE_URL @@ -2051,7 +2029,7 @@ void nsDragService::SourceDataGet(GtkWidget* aWidget, GdkDragContext* aContext, if (mimeFlavor.EqualsLiteral(kTextMime) || mimeFlavor.EqualsLiteral(gTextPlainUTF8Type)) { - SourceDataGetText(item, nsDependentCString(kUnicodeMime), + SourceDataGetText(item, nsDependentCString(kTextMime), /* aNeedToDoConversionToPlainText */ true, aSelectionData); // no fallback for text mime types diff --git a/widget/headless/HeadlessClipboard.cpp b/widget/headless/HeadlessClipboard.cpp index 33983e6330e0..21383b4cac62 100644 --- a/widget/headless/HeadlessClipboard.cpp +++ b/widget/headless/HeadlessClipboard.cpp @@ -29,8 +29,7 @@ HeadlessClipboard::SetData(nsITransferable* aTransferable, // Only support plain text for now. nsCOMPtr clip; - nsresult rv = - aTransferable->GetTransferData(kUnicodeMime, getter_AddRefs(clip)); + nsresult rv = aTransferable->GetTransferData(kTextMime, getter_AddRefs(clip)); if (NS_FAILED(rv)) { return rv; } @@ -60,7 +59,7 @@ HeadlessClipboard::GetData(nsITransferable* aTransferable, return rv; } nsCOMPtr genericDataWrapper = do_QueryInterface(dataWrapper); - rv = aTransferable->SetTransferData(kUnicodeMime, genericDataWrapper); + rv = aTransferable->SetTransferData(kTextMime, genericDataWrapper); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } @@ -86,7 +85,7 @@ HeadlessClipboard::HasDataMatchingFlavors( } // Retrieve the union of all aHasType in aFlavorList for (auto& flavor : aFlavorList) { - if (flavor.EqualsLiteral(kUnicodeMime) && mClipboard->HasText()) { + if (flavor.EqualsLiteral(kTextMime) && mClipboard->HasText()) { *aHasType = true; break; } diff --git a/widget/headless/tests/test_headless_clipboard.js b/widget/headless/tests/test_headless_clipboard.js index 24fb6fc50fc2..862e3430017c 100644 --- a/widget/headless/tests/test_headless_clipboard.js +++ b/widget/headless/tests/test_headless_clipboard.js @@ -10,13 +10,13 @@ function getString(clipboard) { Ci.nsITransferable ); trans.init(null); - trans.addDataFlavor("text/unicode"); + trans.addDataFlavor("text/plain"); clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard); try { var data = {}; - trans.getTransferData("text/unicode", data); + trans.getTransferData("text/plain", data); if (data) { data = data.value.QueryInterface(Ci.nsISupportsString); diff --git a/widget/nsClipboardHelper.cpp b/widget/nsClipboardHelper.cpp index 58ac904ed956..9d7078b85712 100644 --- a/widget/nsClipboardHelper.cpp +++ b/widget/nsClipboardHelper.cpp @@ -73,7 +73,7 @@ nsClipboardHelper::CopyStringToClipboard(const nsAString& aString, } // Add the text data flavor to the transferable - rv = trans->AddDataFlavor(kUnicodeMime); + rv = trans->AddDataFlavor(kTextMime); NS_ENSURE_SUCCESS(rv, rv); // get wStrings to hold clip data @@ -93,7 +93,7 @@ nsClipboardHelper::CopyStringToClipboard(const nsAString& aString, NS_ENSURE_TRUE(genericData, NS_ERROR_FAILURE); // set the transfer data - rv = trans->SetTransferData(kUnicodeMime, genericData); + rv = trans->SetTransferData(kTextMime, genericData); NS_ENSURE_SUCCESS(rv, rv); // put the transferable on the clipboard diff --git a/widget/nsHTMLFormatConverter.cpp b/widget/nsHTMLFormatConverter.cpp index 59ec15c7c1bf..4898fd2c8b59 100644 --- a/widget/nsHTMLFormatConverter.cpp +++ b/widget/nsHTMLFormatConverter.cpp @@ -46,7 +46,7 @@ nsHTMLFormatConverter::GetInputDataFlavors(nsTArray& aFlavors) { NS_IMETHODIMP nsHTMLFormatConverter::GetOutputDataFlavors(nsTArray& aFlavors) { aFlavors.AppendElement(nsLiteralCString(kHTMLMime)); - aFlavors.AppendElement(nsLiteralCString(kUnicodeMime)); + aFlavors.AppendElement(nsLiteralCString(kTextMime)); return NS_OK; } @@ -63,10 +63,11 @@ nsHTMLFormatConverter::CanConvert(const char* aFromDataFlavor, *_retval = false; if (!nsCRT::strcmp(aFromDataFlavor, kHTMLMime)) { - if (!nsCRT::strcmp(aToDataFlavor, kHTMLMime)) + if (!nsCRT::strcmp(aToDataFlavor, kHTMLMime)) { *_retval = true; - else if (!nsCRT::strcmp(aToDataFlavor, kUnicodeMime)) + } else if (!nsCRT::strcmp(aToDataFlavor, kTextMime)) { *_retval = true; + } #if NOT_NOW // pinkerton // no one uses this flavor right now, so it's just slowing things down. If @@ -120,7 +121,7 @@ nsHTMLFormatConverter::Convert(const char* aFromDataFlavor, dataWrapper0->GetData(dataStr); // COPY #1 // note: conversion to text/plain is done inside the clipboard. we do not // need to worry about it here. - if (toFlavor.Equals(kHTMLMime) || toFlavor.Equals(kUnicodeMime)) { + if (toFlavor.Equals(kHTMLMime) || toFlavor.Equals(kTextMime)) { nsresult res; if (toFlavor.Equals(kHTMLMime)) { int32_t dataLen = dataStr.Length() * 2; diff --git a/widget/nsITransferable.idl b/widget/nsITransferable.idl index d3a914694e50..e761d5923141 100644 --- a/widget/nsITransferable.idl +++ b/widget/nsITransferable.idl @@ -23,7 +23,6 @@ interface nsIPrincipal; // by the entire app. #define kTextMime "text/plain" #define kRTFMime "text/rtf" -#define kUnicodeMime "text/unicode" #define kMozTextInternal "text/x-moz-text-internal" // text data which isn't suppoed to be parsed by other apps. #define kHTMLMime "text/html" #define kAOLMailMime "AOLMAIL" diff --git a/widget/nsPrimitiveHelpers.cpp b/widget/nsPrimitiveHelpers.cpp index 4bcbc4a40820..ea36f32d724a 100644 --- a/widget/nsPrimitiveHelpers.cpp +++ b/widget/nsPrimitiveHelpers.cpp @@ -43,8 +43,7 @@ void nsPrimitiveHelpers ::CreatePrimitiveForData(const nsACString& aFlavor, nsISupports** aPrimitive) { if (!aPrimitive) return; - if (aFlavor.EqualsLiteral(kTextMime) || - aFlavor.EqualsLiteral(kNativeHTMLMime) || + if (aFlavor.EqualsLiteral(kNativeHTMLMime) || aFlavor.EqualsLiteral(kRTFMime) || aFlavor.EqualsLiteral(kCustomTypesMime)) { nsCOMPtr primitive = @@ -97,8 +96,7 @@ void nsPrimitiveHelpers ::CreatePrimitiveForCFHTML(const void* aDataBuff, void* utf8 = moz_xmalloc(*aDataLen); memcpy(utf8, aDataBuff, *aDataLen); int32_t signedLen = static_cast(*aDataLen); - nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks( - nsDependentCString(kTextMime), &utf8, &signedLen); + nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(true, &utf8, &signedLen); *aDataLen = signedLen; nsAutoString str( @@ -125,8 +123,7 @@ void nsPrimitiveHelpers::CreateDataFromPrimitive(const nsACString& aFlavor, *aDataBuff = nullptr; *aDataLen = 0; - if (aFlavor.EqualsLiteral(kTextMime) || - aFlavor.EqualsLiteral(kCustomTypesMime)) { + if (aFlavor.EqualsLiteral(kCustomTypesMime)) { nsCOMPtr plainText(do_QueryInterface(aPrimitive)); if (plainText) { nsAutoCString data; @@ -156,13 +153,14 @@ void nsPrimitiveHelpers::CreateDataFromPrimitive(const nsACString& aFlavor, // NOTE: this assumes that it can use 'free' to dispose of the old buffer. // nsresult nsLinebreakHelpers ::ConvertPlatformToDOMLinebreaks( - const nsACString& inFlavor, void** ioData, int32_t* ioLengthInBytes) { + bool aIsSingleByteChars, void** ioData, int32_t* ioLengthInBytes) { NS_ASSERTION(ioData && *ioData && ioLengthInBytes, "Bad Params"); if (!(ioData && *ioData && ioLengthInBytes)) return NS_ERROR_INVALID_ARG; nsresult retVal = NS_OK; - if (inFlavor.EqualsLiteral(kTextMime) || inFlavor.EqualsLiteral(kRTFMime)) { + // RTF and CF_HTML on Windows are transfered as single-byte characters. + if (aIsSingleByteChars) { char* buffAsChars = reinterpret_cast(*ioData); char* oldBuffer = buffAsChars; retVal = nsLinebreakConverter::ConvertLineBreaksInSitu( @@ -174,8 +172,6 @@ nsresult nsLinebreakHelpers ::ConvertPlatformToDOMLinebreaks( free(oldBuffer); *ioData = buffAsChars; } - } else if (inFlavor.EqualsLiteral("image/jpeg")) { - // I'd assume we don't want to do anything for binary data.... } else { char16_t* buffAsUnichar = reinterpret_cast(*ioData); char16_t* oldBuffer = buffAsUnichar; diff --git a/widget/nsPrimitiveHelpers.h b/widget/nsPrimitiveHelpers.h index 33e2163b08fd..54a903b444ba 100644 --- a/widget/nsPrimitiveHelpers.h +++ b/widget/nsPrimitiveHelpers.h @@ -45,7 +45,7 @@ class nsLinebreakHelpers { // taken care of internally, see the note below). // // NOTE: this assumes that it can use 'free' to dispose of the old buffer. - static nsresult ConvertPlatformToDOMLinebreaks(const nsACString& inFlavor, + static nsresult ConvertPlatformToDOMLinebreaks(bool aIsSingleByteChars, void** ioData, int32_t* ioLengthInBytes); diff --git a/widget/tests/test_bug1123480.xhtml b/widget/tests/test_bug1123480.xhtml index 8a80cd6bfbf6..c84a9c1d59eb 100644 --- a/widget/tests/test_bug1123480.xhtml +++ b/widget/tests/test_bug1123480.xhtml @@ -111,8 +111,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1123480 var Suppstr = nsSupportsString(); Suppstr.data = Ipsum; Transfer.init(Loadctx); - Transfer.addDataFlavor("text/unicode"); - Transfer.setTransferData("text/unicode", Suppstr); + Transfer.addDataFlavor("text/plain"); + Transfer.setTransferData("text/plain", Suppstr); // Enabled private browsing mode should not cache any selection to disk; disabled should if (private) { @@ -132,7 +132,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1123480 // Sanitize the environment. Suppstr = nsSupportsString(); Suppstr.data = SHORT_STRING_NO_CACHE; - Transfer.setTransferData("text/unicode", Suppstr); + Transfer.setTransferData("text/plain", Suppstr); await new Promise(resolve => setTimeout(resolve, 0)); is(getClipboardCacheFDCount(), initialFdCount, "should drop the cache file, if any."); diff --git a/widget/tests/test_bug673301.xhtml b/widget/tests/test_bug673301.xhtml index e2f09854b9c2..663f18397e46 100644 --- a/widget/tests/test_bug673301.xhtml +++ b/widget/tests/test_bug673301.xhtml @@ -21,13 +21,13 @@ var transferable = Cc['@mozilla.org/widget/transferable;1'] .createInstance(Ci.nsITransferable); transferable.init(getLoadContext()); -transferable.addDataFlavor("text/unicode"); -transferable.setTransferData("text/unicode", document); +transferable.addDataFlavor("text/plain"); +transferable.setTransferData("text/plain", document); Services.clipboard.setData(transferable, null, Ci.nsIClipboard.kGlobalClipboard); -transferable.setTransferData("text/unicode", null); +transferable.setTransferData("text/plain", null); -SimpleTest.ok(true, "Didn't crash setting non-text data for text/unicode type"); +SimpleTest.ok(true, "Didn't crash setting non-text data for text/plain type"); diff --git a/widget/tests/test_clipboard.xhtml b/widget/tests/test_clipboard.xhtml index 703c6258beb3..e3171725a8c2 100644 --- a/widget/tests/test_clipboard.xhtml +++ b/widget/tests/test_clipboard.xhtml @@ -31,11 +31,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=948065 let trans = Cc['@mozilla.org/widget/transferable;1'] .createInstance(Ci.nsITransferable); trans.init(getLoadContext()); - trans.addDataFlavor("text/unicode"); + trans.addDataFlavor("text/plain"); clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard); let str = {}; try { - trans.getTransferData('text/unicode', str); + trans.getTransferData('text/plain', str); } catch (e) { str = ''; } diff --git a/widget/tests/test_clipboard_cache.xhtml b/widget/tests/test_clipboard_cache.xhtml index 558f984bc758..c353b7c00bdd 100644 --- a/widget/tests/test_clipboard_cache.xhtml +++ b/widget/tests/test_clipboard_cache.xhtml @@ -58,17 +58,17 @@ clipboardTypes.forEach(function(type) { add_task(function test_clipboard_hasDataMatchingFlavors() { info(`Test write data to clipboard type ${type}`); - // Write text/unicode data to main clipboard. - writeStringToClipboard(GenerateRandomString(), "text/unicode", clipboard.kGlobalClipboard); - ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard), - "Should have text/unicode flavor"); + // Write text/plain data to main clipboard. + writeStringToClipboard(GenerateRandomString(), "text/plain", clipboard.kGlobalClipboard); + ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard), + "Should have text/plain flavor"); ok(!clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard), "Should not have text/html flavor"); // Write text/html data to other clipboard. writeStringToClipboard(GenerateRandomString(), "text/html", type); - ok(clipboard.hasDataMatchingFlavors(["text/unicode"], clipboard.kGlobalClipboard), - "Should have text/unicode flavor"); + ok(clipboard.hasDataMatchingFlavors(["text/plain"], clipboard.kGlobalClipboard), + "Should have text/plain flavor"); ok(!clipboard.hasDataMatchingFlavors(["text/html"], clipboard.kGlobalClipboard), "Should not have text/html flavor"); diff --git a/widget/tests/test_transferable_overflow.xhtml b/widget/tests/test_transferable_overflow.xhtml index 7add6a695025..5c6ff443c4e5 100644 --- a/widget/tests/test_transferable_overflow.xhtml +++ b/widget/tests/test_transferable_overflow.xhtml @@ -24,12 +24,12 @@ function assignTextToTransferable(transferable, string) { var Suppstr = nsSupportsString(); Suppstr.data = string; - transferable.setTransferData("text/unicode", Suppstr); + transferable.setTransferData("text/plain", Suppstr); } function checkTransferableText(transferable, expectedString, description) { var data = {}; - transferable.getTransferData("text/unicode", data); + transferable.getTransferData("text/plain", data); var actualValue = data.value.QueryInterface(Ci.nsISupportsString).data; // Use ok + shortenString instead of is(...) to avoid dumping millions of characters in the output. ok(actualValue === expectedString, description + ": text should match. " + @@ -89,7 +89,7 @@ var Loadctx = PrivateBrowsingUtils.privacyContextFromWindow(win); var Transfer = nsTransferable(); Transfer.init(Loadctx); - Transfer.addDataFlavor("text/unicode"); + Transfer.addDataFlavor("text/plain"); var initialFdCount = isFDCountingSupported() ? getClipboardCacheFDCount() : -1; assignTextToTransferable(Transfer, BIG_STRING); @@ -117,7 +117,7 @@ var Transfer2 = nsTransferable(); Transfer2.init(Loadctx); - Transfer2.addDataFlavor("text/unicode"); + Transfer2.addDataFlavor("text/plain"); // Iniitalize with a small string, so we can see that mData -> mCacheFD works. assignTextToTransferable(Transfer2, SMALL_STRING); diff --git a/widget/windows/nsClipboard.cpp b/widget/windows/nsClipboard.cpp index 48008e603751..305d368ea22b 100644 --- a/widget/windows/nsClipboard.cpp +++ b/widget/windows/nsClipboard.cpp @@ -99,8 +99,6 @@ UINT nsClipboard::GetFormat(const char* aMimeStr, bool aMapHTMLMime) { UINT format; if (strcmp(aMimeStr, kTextMime) == 0) { - format = CF_TEXT; - } else if (strcmp(aMimeStr, kUnicodeMime) == 0) { format = CF_UNICODETEXT; } else if (strcmp(aMimeStr, kRTFMime) == 0) { format = ::RegisterClipboardFormat(L"Rich Text Format"); @@ -210,9 +208,9 @@ nsresult nsClipboard::SetupNativeDataObject( // Do various things internal to the implementation, like map one // flavor to another or add additional flavors based on what's required // for the win32 impl. - if (flavorStr.EqualsLiteral(kUnicodeMime)) { - // if we find text/unicode, also advertise text/plain (which we will - // convert on our own in nsDataObj::GetText(). + if (flavorStr.EqualsLiteral(kTextMime)) { + // if we find text/plain, also add CF_TEXT, but we can add it for + // text/plain as well. FORMATETC textFE; SET_FORMATETC(textFE, CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL); dObj->AddDataFlavor(kTextMime, &textFE); @@ -888,7 +886,7 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject* aDataObject, // when directly asking for the flavor. Let's try digging around in other // flavors to help satisfy our craving for data. if (!dataFound) { - if (flavorStr.EqualsLiteral(kUnicodeMime)) { + if (flavorStr.EqualsLiteral(kTextMime)) { dataFound = FindUnicodeFromPlainText(aDataObject, anIndex, &data, &dataLen); } else if (flavorStr.EqualsLiteral(kURLMime)) { @@ -954,14 +952,15 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject* aDataObject, } else { // Treat custom types as a string of bytes. if (!flavorStr.EqualsLiteral(kCustomTypesMime)) { + bool isRTF = flavorStr.EqualsLiteral(kRTFMime); // we probably have some form of text. The DOM only wants LF, so // convert from Win32 line endings to DOM line endings. int32_t signedLen = static_cast(dataLen); - nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(flavorStr, &data, + nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks(isRTF, &data, &signedLen); dataLen = signedLen; - if (flavorStr.EqualsLiteral(kRTFMime)) { + if (isRTF) { // RTF on Windows is known to sometimes deliver an extra null byte. if (dataLen > 0 && static_cast(data)[dataLen - 1] == '\0') { dataLen--; @@ -1049,20 +1048,21 @@ bool nsClipboard ::FindPlatformHTML(IDataObject* inDataObject, UINT inIndex, // // FindUnicodeFromPlainText // -// we are looking for text/unicode and we failed to find it on the clipboard -// first, try again with text/plain. If that is present, convert it to unicode. +// Looks for CF_TEXT on the clipboard and converts it into an UTF-16 string +// if present. Returns this string in outData, and its length in outDataLen. +// XXXndeakin Windows converts between CF_UNICODE and CF_TEXT automatically +// so it doesn't seem like this is actually needed. // bool nsClipboard ::FindUnicodeFromPlainText(IDataObject* inDataObject, UINT inIndex, void** outData, uint32_t* outDataLen) { MOZ_LOG(gWin32ClipboardLog, LogLevel::Debug, ("%s", __FUNCTION__)); - // we are looking for text/unicode and we failed to find it on the clipboard - // first, try again with text/plain. If that is present, convert it to + // We are looking for text/plain and we failed to find it on the clipboard + // first, so try again with CF_TEXT. If that is present, convert it to // unicode. - nsresult rv = - GetNativeDataOffClipboard(inDataObject, inIndex, GetFormat(kTextMime), - nullptr, outData, outDataLen); + nsresult rv = GetNativeDataOffClipboard(inDataObject, inIndex, CF_TEXT, + nullptr, outData, outDataLen); if (NS_FAILED(rv) || !*outData) { return false; } @@ -1303,30 +1303,10 @@ NS_IMETHODIMP nsClipboard::HasDataMatchingFlavors( } for (auto& flavor : aFlavorList) { -#ifdef DEBUG - if (flavor.EqualsLiteral(kTextMime)) { - NS_WARNING( - "DO NOT USE THE text/plain DATA FLAVOR ANY MORE. USE text/unicode " - "INSTEAD"); - } -#endif - UINT format = GetFormat(flavor.get()); if (IsClipboardFormatAvailable(format)) { *_retval = true; break; - } else { - // We haven't found the exact flavor the client asked for, but maybe we - // can still find it from something else that's on the clipboard... - if (flavor.EqualsLiteral(kUnicodeMime)) { - // client asked for unicode and it wasn't present, check if we have - // CF_TEXT. We'll handle the actual data substitution in the data - // object. - if (IsClipboardFormatAvailable(GetFormat(kTextMime))) { - *_retval = true; - break; - } - } } } diff --git a/widget/windows/nsDataObj.cpp b/widget/windows/nsDataObj.cpp index 90b8ba3c28bc..c58e6a0a7f85 100644 --- a/widget/windows/nsDataObj.cpp +++ b/widget/windows/nsDataObj.cpp @@ -1428,26 +1428,19 @@ HRESULT nsDataObj::GetText(const nsACString& aDataFlavor, FORMATETC& aFE, STGMEDIUM& aSTG) { void* data = nullptr; - // if someone asks for text/plain, look up text/unicode instead in the - // transferable. - const char* flavorStr; - const nsPromiseFlatCString& flat = PromiseFlatCString(aDataFlavor); - if (aDataFlavor.EqualsLiteral("text/plain")) - flavorStr = kUnicodeMime; - else - flavorStr = flat.get(); + const nsPromiseFlatCString& flavorStr = PromiseFlatCString(aDataFlavor); // NOTE: CreateDataFromPrimitive creates new memory, that needs to be deleted nsCOMPtr genericDataWrapper; nsresult rv = mTransferable->GetTransferData( - flavorStr, getter_AddRefs(genericDataWrapper)); + flavorStr.get(), getter_AddRefs(genericDataWrapper)); if (NS_FAILED(rv) || !genericDataWrapper) { return E_FAIL; } uint32_t len; - nsPrimitiveHelpers::CreateDataFromPrimitive(nsDependentCString(flavorStr), - genericDataWrapper, &data, &len); + nsPrimitiveHelpers::CreateDataFromPrimitive( + nsDependentCString(flavorStr.get()), genericDataWrapper, &data, &len); if (!data) return E_FAIL; HGLOBAL hGlobalMemory = nullptr; diff --git a/widget/windows/nsDragService.cpp b/widget/windows/nsDragService.cpp index c0b41b75f38d..77949051747f 100644 --- a/widget/windows/nsDragService.cpp +++ b/widget/windows/nsDragService.cpp @@ -451,13 +451,6 @@ NS_IMETHODIMP nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) { if (!aDataFlavor || !mDataObject || !_retval) return NS_ERROR_FAILURE; -#ifdef DEBUG - if (strcmp(aDataFlavor, kTextMime) == 0) - NS_WARNING( - "DO NOT USE THE text/plain DATA FLAVOR ANY MORE. USE text/unicode " - "INSTEAD"); -#endif - *_retval = false; FORMATETC fe; @@ -494,12 +487,12 @@ nsDragService::IsDataFlavorSupported(const char* aDataFlavor, bool* _retval) { // We haven't found the exact flavor the client asked for, but // maybe we can still find it from something else that's on the // clipboard - if (strcmp(aDataFlavor, kUnicodeMime) == 0) { - // client asked for unicode and it wasn't present, check if we + if (strcmp(aDataFlavor, kTextMime) == 0) { + // If unicode wasn't there, it might exist as CF_TEXT, client asked + // for unicode and it wasn't present, check if we // have CF_TEXT. We'll handle the actual data substitution in // the data object. - format = nsClipboard::GetFormat(kTextMime); - SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1, + SET_FORMATETC(fe, CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI); if (mDataObject->QueryGetData(&fe) == S_OK) *_retval = true; // found it! diff --git a/widget/windows/tests/TestWinDND.cpp b/widget/windows/tests/TestWinDND.cpp index 51e43cf19e91..5ede12aac413 100644 --- a/widget/windows/tests/TestWinDND.cpp +++ b/widget/windows/tests/TestWinDND.cpp @@ -177,7 +177,7 @@ nsresult GetTransferableText(nsCOMPtr& pTransferable) { pTransferable = do_CreateInstance("@mozilla.org/widget/transferable;1"); pTransferable->Init(nullptr); - rv = pTransferable->SetTransferData("text/unicode", genericWrapper, + rv = pTransferable->SetTransferData("text/plain", genericWrapper, mozString.Length() * sizeof(char16_t)); return rv; } @@ -194,7 +194,7 @@ nsresult GetTransferableTextTwo(nsCOMPtr& pTransferable) { pTransferable = do_CreateInstance("@mozilla.org/widget/transferable;1"); pTransferable->Init(nullptr); - rv = pTransferable->SetTransferData("text/unicode", genericWrapper, + rv = pTransferable->SetTransferData("text/plain", genericWrapper, mozString.Length() * sizeof(char16_t)); return rv; }