Commit 7be56ce4 authored by Christian Sadilek's avatar Christian Sadilek
Browse files

For #11798: Allow sharing of reader view pages

parent 04aee11d
......@@ -24,6 +24,7 @@ import mozilla.components.concept.sync.Device
import mozilla.components.concept.sync.TabData
import mozilla.components.feature.accounts.push.SendTabUseCases
import mozilla.components.feature.share.RecentAppsStorage
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event
......@@ -172,7 +173,20 @@ class DefaultShareController(
fun getShareText() = shareData.joinToString("\n\n") { data ->
val url = data.url.orEmpty()
if (url.isExtensionUrl()) {
// Sharing moz-extension:// URLs is not practical in general, as
// they will only work on the current device.
// We solve this for URLs from our reader extension as they contain
// the original URL as a query parameter. This is a workaround for
// now and needs a clean fix once we have a reader specific protocol
// e.g. ext+reader://
Uri.parse(url).getQueryParameter("url") ?: url
} else {
// Navigation between app fragments uses ShareTab as arguments. SendTabUseCases uses TabData.
......@@ -272,6 +272,22 @@ class ShareControllerTest {
assertEquals(textToShare, controller.getShareText())
fun `getShareText attempts to use original URL for reader pages`() {
val shareData = listOf(
ShareData(url = "moz-extension://eb8df45a-895b-4f3a-896a-c0c71ae4/page.html"),
ShareData(url = "moz-extension://eb8df45a-895b-4f3a-896a-c0c71ae5/page.html?url=url0"),
ShareData(url = "url1")
val controller = DefaultShareController(
context, shareData, sendTabUseCases, snackbar, navController,
recentAppStorage, testCoroutineScope, dismiss
val expectedShareText = "${shareData[0].url}\n\nurl0\n\n${shareData[2].url}"
assertEquals(expectedShareText, controller.getShareText())
fun `ShareTab#toTabData maps a list of ShareTab to a TabData list`() {
var tabData: List<TabData>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment