Skip to content

Commit 652c6c9

Browse files
committed
Add a mechanism to use external provider of selection clipboard access #3489
1 parent 456e593 commit 652c6c9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

webextensions/common/retrieve-url.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,28 @@ export async function fromDragEvent(event) {
8585
return sanitizeURLs(urls);
8686
}
8787

88-
export async function fromClipboard() {
88+
let mSelectionClipboardProvider = null;
89+
90+
/* provider should have two methods:
91+
isAvailable(): returns boolean which indicates the selection clipboard is available or not.
92+
getTextData(): returns a string from the selection clipboard.
93+
*/
94+
export function registerSelectionClipboardProvider(provider) {
95+
mSelectionClipboardProvider = provider;
96+
}
97+
98+
export async function fromClipboard({ selection } = {}) {
8999
const urls = [];
100+
101+
if (selection && mSelectionClipboardProvider) {
102+
if (await mSelectionClipboardProvider.isAvailable()) {
103+
const maybeUrlString = await mSelectionClipboardProvider.getTextData();
104+
if (maybeUrlString)
105+
urls.push(...fromData(maybeUrlString, 'text/plain'));
106+
return sanitizeURLs(urls);
107+
}
108+
}
109+
90110
if (!(await Permissions.isGranted(Permissions.CLIPBOARD_READ)) ||
91111
typeof navigator.clipboard.read != 'function')
92112
return urls;

webextensions/sidebar/mouse-event-listener.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ async function handleDefaultMouseUp({ lastMousedown, tab, event }) {
562562
const activeTab = Tab.getActiveTab(mTargetWindow);
563563
const cookieStoreId = (actionForNewTabCommand == Constants.kNEWTAB_OPEN_AS_NEXT_SIBLING_WITH_INHERITED_CONTAINER) ? activeTab.cookieStoreId : null
564564
const urls = lastMousedown.detail.isMiddleClick && configs.middleClickPasteURLOnNewTabButton ?
565-
(await RetrieveURL.fromClipboard()) :
565+
(await RetrieveURL.fromClipboard({ selection: true })) :
566566
[];
567567
log('urls: ', urls);
568568
handleNewTabAction(event, {

0 commit comments

Comments
 (0)