[tbb-commits] [Git][tpo/applications/torbutton][maint-12.0] Bug 41520: (Regression) Rearranging bookmarks / place items by drag & drop doesn't work anymore
Richard Pospesel (@richard)
git at gitlab.torproject.org
Wed Dec 14 12:44:16 UTC 2022
Richard Pospesel pushed to branch maint-12.0 at The Tor Project / Applications / torbutton
Commits:
a5767f29 by hackademix at 2022-12-14T12:43:47+00:00
Bug 41520: (Regression) Rearranging bookmarks / place items by drag & drop doesn't work anymore
- - - - -
1 changed file:
- components/dragDropFilter.js
Changes:
=====================================
components/dragDropFilter.js
=====================================
@@ -13,6 +13,7 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
ComponentUtils: "resource://gre/modules/ComponentUtils.jsm",
});
+XPCOMUtils.defineLazyGlobalGetters(this, ["crypto"]);
// Module specific constants
const kMODULE_NAME = "Torbutton Drag and Drop Handler";
@@ -28,50 +29,55 @@ const URLISH_TYPES = Object.freeze([
"application/x-moz-file-promise-url",
]);
-/*
- Returns true if the text resembles a URL or even just a hostname
- in a way that may prompt the O.S. or other applications to send out a
- validation DNS query, if not a full request (e.g. " torproject.org",
- even with the leading whitespace).
-*/
-function isURLish(text) {
- // Ignore leading whitespace.
- text = text.trim();
-
- // Without any protocol or dot in the first chunk, this is unlikely
- // to be considered URLish (exception: localhost, but we don't care).
- if (!/^[a-z][a-z0-9+-]*:\/\//i.test(text)) {
- // no protocol
- if (!/^[^.\s\/]+\.[^.\s\/]/.test(text)) {
- // no dot
- return false;
+const MAIN_PROCESS =
+ Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_DEFAULT;
+
+const EMPTY_PAYLOAD = {};
+const OpaqueDrag = {
+ listening: false,
+ payload: EMPTY_PAYLOAD,
+ store(value, type) {
+ let opaqueKey = crypto.randomUUID();
+ this.payload = { opaqueKey, value, type };
+ if (!this.listening && MAIN_PROCESS) {
+ Services.ppmm.addMessageListener(
+ "DragDropFilter:GetOpaqueDrag",
+ () => this.payload
+ );
+ this.listening = true;
}
- // Prepare for hostname validation via relative URL building.
- text = `//${text}`;
- }
- // Validate URL or hostname.
- try {
- new URL(text, "https://localhost");
- return true;
- } catch (e) {
- // invalid URL, bail out
- }
- return false;
-}
-
-// Returns true if any chunk of text is URLish
-const hasURLish = text => text.split(/[^\p{L}_.-:\/%~@$-]+/u).some(isURLish);
+ return opaqueKey;
+ },
+ retrieve(key) {
+ let { opaqueKey, value, type } = this.payload;
+ if (opaqueKey === key) {
+ return { value, type };
+ }
+ if (!MAIN_PROCESS) {
+ this.payload = Services.cpmm.sendSyncMessage(
+ "DragDropFilter:GetOpaqueDrag"
+ )[0];
+ if (key === this.payload.opaqueKey) {
+ return this.retrieve(key);
+ }
+ }
+ return EMPTY_PAYLOAD;
+ },
+};
function DragDropFilter() {
this.logger = Cc["@torproject.org/torbutton-logger;1"].getService(
Ci.nsISupports
).wrappedJSObject;
this.logger.log(3, "Component Load 0: New DragDropFilter.");
-
- try {
- Services.obs.addObserver(this, "on-datatransfer-available");
- } catch (e) {
- this.logger.log(5, "Failed to register drag observer");
+ if (MAIN_PROCESS) {
+ // We want to update our status in the main process only, in order to
+ // serve the same opaque drag payload in every process.
+ try {
+ Services.obs.addObserver(this, "on-datatransfer-available");
+ } catch (e) {
+ this.logger.log(5, "Failed to register drag observer");
+ }
}
}
@@ -109,23 +115,38 @@ DragDropFilter.prototype = {
const types = aDataTransfer.mozTypesAt(i);
for (const type of types) {
this.logger.log(3, `Type is: ${type}.`);
- if (
- URLISH_TYPES.includes(type) ||
- ((type === "text/plain" || type === "text/html") &&
- hasURLish(aDataTransfer.getData(type)))
- ) {
+ if (URLISH_TYPES.includes(type)) {
this.logger.log(
3,
- `Removing transfer data ${aDataTransfer.getData(type)}`
+ `Removing transfer data ${aDataTransfer.mozGetDataAt(type, i)}`
);
+ const urlType = "text/x-moz-url";
+ // Fallback url type, to be parsed by this browser but not externally
+ const INTERNAL_FALLBACK = "application/x-torbrowser-opaque";
+ if (types.contains(urlType)) {
+ const link = aDataTransfer.mozGetDataAt(urlType, i);
+ const opaqueKey = OpaqueDrag.store(link, urlType);
+ aDataTransfer.mozSetDataAt(INTERNAL_FALLBACK, opaqueKey, i);
+ }
for (const type of types) {
- aDataTransfer.clearData(type);
+ if (
+ type !== INTERNAL_FALLBACK &&
+ type !== "text/x-moz-place" // don't touch bookmarks
+ ) {
+ aDataTransfer.mozClearDataAt(type, i);
+ }
}
break;
}
}
}
},
+
+ opaqueDrag: {
+ get(opaqueKey) {
+ return OpaqueDrag.retrieve(opaqueKey);
+ },
+ },
};
// Assign factory to global object.
View it on GitLab: https://gitlab.torproject.org/tpo/applications/torbutton/-/commit/a5767f29c0d509c6cb34527c091ae0c4bfc2f386
--
View it on GitLab: https://gitlab.torproject.org/tpo/applications/torbutton/-/commit/a5767f29c0d509c6cb34527c091ae0c4bfc2f386
You're receiving this email because of your account on gitlab.torproject.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20221214/62812002/attachment-0001.htm>
More information about the tbb-commits
mailing list