Skip to content

Commit 9c2e745

Browse files
committed
Bug 1776879, replace text/unicode for clipboard and drag and drop and use text/plain directly, r=edgar,mak,stransky,geckoview-reviewers,extension-reviewers,zombie,m_kato
Most usage is a straight replacement but gtk needs extra changes as it transfers plain text in UTF8 natively and needs to be converted into UTF16, and Windows uses single-byte characters for RTF and CF_HTML formats so we preserve this. Differential Revision: https://phabricator.services.mozilla.com/D158587
1 parent c80ccbf commit 9c2e745

File tree

101 files changed

+349
-448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+349
-448
lines changed

accessible/tests/mochitest/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,11 +847,11 @@ function getTextFromClipboard() {
847847
return "";
848848
}
849849

850-
trans.addDataFlavor("text/unicode");
850+
trans.addDataFlavor("text/plain");
851851
Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard);
852852

853853
var str = {};
854-
trans.getTransferData("text/unicode", str);
854+
trans.getTransferData("text/plain", str);
855855

856856
if (str) {
857857
str = str.value.QueryInterface(Ci.nsISupportsString);

browser/base/content/browser-places.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ var PlacesToolbarHelper = {
13791379
}
13801380

13811381
addData(PlacesUtils.TYPE_X_MOZ_URL, 0);
1382-
addData(PlacesUtils.TYPE_UNICODE, 0);
1382+
addData(PlacesUtils.TYPE_PLAINTEXT, 0);
13831383
addData(PlacesUtils.TYPE_HTML, 0);
13841384
},
13851385
};

browser/base/content/browser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,7 +3176,7 @@ function readFromClipboard() {
31763176
);
31773177
trans.init(getLoadContext());
31783178

3179-
trans.addDataFlavor("text/unicode");
3179+
trans.addDataFlavor("text/plain");
31803180

31813181
// If available, use selection clipboard, otherwise global one
31823182
let clipboard = Services.clipboard;
@@ -3187,7 +3187,7 @@ function readFromClipboard() {
31873187
}
31883188

31893189
var data = {};
3190-
trans.getTransferData("text/unicode", data);
3190+
trans.getTransferData("text/plain", data);
31913191

31923192
if (data) {
31933193
data = data.value.QueryInterface(Ci.nsISupportsString);

browser/base/content/test/contextMenu/browser_contextmenu_contenteditable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ add_task(async function test_contenteditable() {
9393
"text/html",
9494
PlacesUtils.toISupportsString("<strong>Bold text</strong>")
9595
);
96-
xferable.addDataFlavor("text/unicode");
96+
xferable.addDataFlavor("text/plain");
9797
xferable.setTransferData(
98-
"text/unicode",
98+
"text/plain",
9999
PlacesUtils.toISupportsString("Bold text")
100100
);
101101
Services.clipboard.setData(

browser/base/content/test/general/browser_bug1297539.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function getTransferableFromClipboard(asHTML) {
2929
if (asHTML) {
3030
trans.addDataFlavor("text/html");
3131
} else {
32-
trans.addDataFlavor("text/unicode");
32+
trans.addDataFlavor("text/plain");
3333
}
3434
Services.clipboard.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
3535
return trans;

browser/base/content/test/general/browser_clipboard_pastefile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ function setClipboard(path) {
1616
trans.addDataFlavor("application/x-moz-file");
1717
trans.setTransferData("application/x-moz-file", file);
1818

19-
trans.addDataFlavor("text/unicode");
19+
trans.addDataFlavor("text/plain");
2020
const str = Cc["@mozilla.org/supports-string;1"].createInstance(
2121
Ci.nsISupportsString
2222
);
2323
str.data = "Alternate";
24-
trans.setTransferData("text/unicode", str);
24+
trans.setTransferData("text/plain", str);
2525

2626
// Write to clipboard.
2727
Services.clipboard.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard);

browser/components/downloads/content/allDownloadsView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ DownloadsPlacesView.prototype = {
639639
);
640640
trans.init(null);
641641

642-
let flavors = ["text/x-moz-url", "text/unicode"];
642+
let flavors = ["text/x-moz-url", "text/plain"];
643643
flavors.forEach(trans.addDataFlavor);
644644

645645
Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard);

browser/components/downloads/content/downloads.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ var DownloadsPanel = {
471471
Ci.nsITransferable
472472
);
473473
trans.init(null);
474-
let flavors = ["text/x-moz-url", "text/unicode"];
474+
let flavors = ["text/x-moz-url", "text/plain"];
475475
flavors.forEach(trans.addDataFlavor);
476476
Services.clipboard.getData(trans, Services.clipboard.kGlobalClipboard);
477477
// Getting the data or creating the nsIURI might fail

browser/components/places/PlacesUIUtils.sys.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ export var PlacesUIUtils = {
17931793
let contents = [
17941794
{ type: lazy.PlacesUtils.TYPE_X_MOZ_URL, entries: [] },
17951795
{ type: lazy.PlacesUtils.TYPE_HTML, entries: [] },
1796-
{ type: lazy.PlacesUtils.TYPE_UNICODE, entries: [] },
1796+
{ type: lazy.PlacesUtils.TYPE_PLAINTEXT, entries: [] },
17971797
];
17981798

17991799
contents.forEach(function(content) {
@@ -2034,7 +2034,7 @@ XPCOMUtils.defineLazyGetter(PlacesUIUtils, "URI_FLAVORS", () => {
20342034
return [
20352035
lazy.PlacesUtils.TYPE_X_MOZ_URL,
20362036
TAB_DROP_TYPE,
2037-
lazy.PlacesUtils.TYPE_UNICODE,
2037+
lazy.PlacesUtils.TYPE_PLAINTEXT,
20382038
];
20392039
});
20402040
XPCOMUtils.defineLazyGetter(PlacesUIUtils, "SUPPORTED_FLAVORS", () => {
@@ -2271,7 +2271,7 @@ function getTransactionsForCopy(items, insertionIndex, insertionParentGuid) {
22712271
});
22722272
} else {
22732273
let title =
2274-
item.type != lazy.PlacesUtils.TYPE_UNICODE ? item.title : item.uri;
2274+
item.type != lazy.PlacesUtils.TYPE_PLAINTEXT ? item.title : item.uri;
22752275
transaction = lazy.PlacesTransactions.NewBookmark({
22762276
index,
22772277
parentGuid: insertionParentGuid,

browser/components/places/content/controller.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ PlacesController.prototype = {
168168
case "cmd_paste":
169169
case "placesCmd_paste":
170170
// If the clipboard contains a Places flavor it is definitely pasteable,
171-
// otherwise we also allow pasting "text/unicode" and "text/x-moz-url" data.
171+
// otherwise we also allow pasting "text/plain" and "text/x-moz-url" data.
172172
// We don't check if the data is valid here, because the clipboard may
173173
// contain very large blobs that would largely slowdown commands updating.
174174
// Of course later paste() should ignore any invalid data.
@@ -178,7 +178,7 @@ PlacesController.prototype = {
178178
[
179179
...PlacesUIUtils.PLACES_FLAVORS,
180180
PlacesUtils.TYPE_X_MOZ_URL,
181-
PlacesUtils.TYPE_UNICODE,
181+
PlacesUtils.TYPE_PLAINTEXT,
182182
],
183183
Ci.nsIClipboard.kGlobalClipboard
184184
)
@@ -1049,7 +1049,7 @@ PlacesController.prototype = {
10491049

10501050
function addURIData(index) {
10511051
addData(PlacesUtils.TYPE_X_MOZ_URL, index);
1052-
addData(PlacesUtils.TYPE_UNICODE, index);
1052+
addData(PlacesUtils.TYPE_PLAINTEXT, index);
10531053
addData(PlacesUtils.TYPE_HTML, index);
10541054
}
10551055

@@ -1131,7 +1131,7 @@ PlacesController.prototype = {
11311131
{ type: PlacesUtils.TYPE_X_MOZ_PLACE, entries: [] },
11321132
{ type: PlacesUtils.TYPE_X_MOZ_URL, entries: [] },
11331133
{ type: PlacesUtils.TYPE_HTML, entries: [] },
1134-
{ type: PlacesUtils.TYPE_UNICODE, entries: [] },
1134+
{ type: PlacesUtils.TYPE_PLAINTEXT, entries: [] },
11351135
];
11361136

11371137
// Avoid handling descendants of a copied node, the transactions take care
@@ -1264,7 +1264,7 @@ PlacesController.prototype = {
12641264
[
12651265
PlacesUtils.TYPE_X_MOZ_PLACE,
12661266
PlacesUtils.TYPE_X_MOZ_URL,
1267-
PlacesUtils.TYPE_UNICODE,
1267+
PlacesUtils.TYPE_PLAINTEXT,
12681268
].forEach(type => xferable.addDataFlavor(type));
12691269

12701270
Services.clipboard.getData(xferable, Ci.nsIClipboard.kGlobalClipboard);
@@ -1494,13 +1494,6 @@ var PlacesControllerDragHelper = {
14941494
}
14951495
}
14961496

1497-
// If no supported flavor is found, check if data includes text/plain
1498-
// contents. If so, request them as text/unicode, a conversion will happen
1499-
// automatically.
1500-
if (aFlavors.contains("text/plain")) {
1501-
return PlacesUtils.TYPE_UNICODE;
1502-
}
1503-
15041497
return null;
15051498
},
15061499

@@ -1623,7 +1616,7 @@ var PlacesControllerDragHelper = {
16231616

16241617
// Following flavors may contain duplicated data.
16251618
let duplicable = new Map();
1626-
duplicable.set(PlacesUtils.TYPE_UNICODE, new Set());
1619+
duplicable.set(PlacesUtils.TYPE_PLAINTEXT, new Set());
16271620
duplicable.set(PlacesUtils.TYPE_X_MOZ_URL, new Set());
16281621

16291622
// Collect all data from the DataTransfer before processing it, as the

0 commit comments

Comments
 (0)