Bug 1953575 - remove duplicated clipboard code from firefox view, r=fxview-reviewers,sidebar-reviewers,nsharpley

Differential Revision: https://phabricator.services.mozilla.com/D241488
This commit is contained in:
Gijs Kruitbosch
2025-03-20 15:54:32 +00:00
parent c9d434d38b
commit 19f781c655
4 changed files with 10 additions and 58 deletions

View File

@@ -9,7 +9,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
Log: "resource://gre/modules/Log.sys.mjs",
PlacesUIUtils: "resource:///modules/PlacesUIUtils.sys.mjs",
PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs",
});
ChromeUtils.defineLazyGetter(lazy, "relativeTimeFormat", () => {
@@ -61,52 +60,6 @@ export function getImageUrl(icon, targetURI) {
return icon ? lazy.PlacesUIUtils.getImageURL(icon) : `page-icon:${targetURI}`;
}
/**
* This function doesn't just copy the link to the clipboard, it creates a
* URL object on the clipboard, so when it's pasted into an application that
* supports it, it displays the title as a link.
*/
export function placeLinkOnClipboard(title, uri) {
let node = {
type: 0,
title,
uri,
};
// Copied from doCommand/placesCmd_copy in PlacesUIUtils.sys.mjs
// This is a little hacky, but there is a lot of code in Places that handles
// clipboard stuff, so it's easier to reuse.
// This order is _important_! It controls how this and other applications
// select data to be inserted based on type.
let contents = [
{ type: lazy.PlacesUtils.TYPE_X_MOZ_URL, entries: [] },
{ type: lazy.PlacesUtils.TYPE_HTML, entries: [] },
{ type: lazy.PlacesUtils.TYPE_PLAINTEXT, entries: [] },
];
contents.forEach(function (content) {
content.entries.push(lazy.PlacesUtils.wrapNode(node, content.type));
});
let xferable = Cc["@mozilla.org/widget/transferable;1"].createInstance(
Ci.nsITransferable
);
xferable.init(null);
function addData(type, data) {
xferable.addDataFlavor(type);
xferable.setTransferData(type, lazy.PlacesUtils.toISupportsString(data));
}
contents.forEach(function (content) {
addData(content.type, content.entries.join(lazy.PlacesUtils.endl));
});
Services.clipboard.setData(xferable, null, Ci.nsIClipboard.kGlobalClipboard);
}
/**
* Get or create a logger, whose log-level is controlled by a pref
*

View File

@@ -9,11 +9,7 @@ import {
when,
} from "chrome://global/content/vendor/lit.all.mjs";
import { MozLitElement } from "chrome://global/content/lit-utils.mjs";
import {
getLogger,
placeLinkOnClipboard,
MAX_TABS_FOR_RECENT_BROWSING,
} from "./helpers.mjs";
import { getLogger, MAX_TABS_FOR_RECENT_BROWSING } from "./helpers.mjs";
import { searchTabList } from "./search-helpers.mjs";
import { ViewPage, ViewPageContent } from "./viewpage.mjs";
// eslint-disable-next-line import/no-unassigned-import
@@ -23,6 +19,7 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
BookmarkList: "resource://gre/modules/BookmarkList.sys.mjs",
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
ContextualIdentityService:
"resource://gre/modules/ContextualIdentityService.sys.mjs",
NewTabUtils: "resource://gre/modules/NewTabUtils.sys.mjs",
@@ -712,7 +709,7 @@ class OpenTabsContextMenu extends MozLitElement {
}
copyLink(e) {
placeLinkOnClipboard(this.triggerNode.title, this.triggerNode.url);
lazy.BrowserUtils.copyLink(this.triggerNode.url, this.triggerNode.title);
this.ownerViewPage.recordContextMenuTelemetry("copy-link", e);
}

View File

@@ -13,11 +13,10 @@ import "chrome://browser/content/firefoxview/fxview-search-textbox.mjs";
// eslint-disable-next-line import/no-unassigned-import
import "chrome://browser/content/firefoxview/fxview-tab-list.mjs";
import { placeLinkOnClipboard } from "./helpers.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
DeferredTask: "resource://gre/modules/DeferredTask.sys.mjs",
});
@@ -76,7 +75,7 @@ export class ViewPageContent extends MozLitElement {
}
copyLink(e) {
placeLinkOnClipboard(this.triggerNode.title, this.triggerNode.url);
lazy.BrowserUtils.copyLink(this.triggerNode.url, this.triggerNode.title);
this.recordContextMenuTelemetry("copy-link", e);
}

View File

@@ -13,7 +13,7 @@ const { LightweightThemeConsumer } = ChromeUtils.importESModule(
"resource://gre/modules/LightweightThemeConsumer.sys.mjs"
);
ChromeUtils.defineESModuleGetters(lazy, {
placeLinkOnClipboard: "chrome://browser/content/firefoxview/helpers.mjs",
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
});
export class SidebarPage extends MozLitElement {
@@ -127,7 +127,10 @@ export class SidebarPage extends MozLitElement {
break;
case "sidebar-history-context-copy-link":
case "sidebar-synced-tabs-context-copy-link":
lazy.placeLinkOnClipboard(this.triggerNode.title, this.triggerNode.url);
lazy.BrowserUtils.copyLink(
this.triggerNode.url,
this.triggerNode.title
);
break;
}
}