android-components icon indicating copy to clipboard operation
android-components copied to clipboard

Unable to download data: urls

Open csadilek opened this issue 6 years ago • 3 comments

We currently can't consume downloads from data urls e.g.

<a href="data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" type="text/plain" download="test.txt">Test</a>

This is also the cause of the uBlock "Back up to file" functionality not working: https://github.com/gorhill/uBlock/blob/08d370d32e648c2823e1bc31fcd9f7e1f96d155a/platform/chromium/vapi-common.js#L172

This is similar to: https://github.com/mozilla-mobile/android-components/issues/1159

 java.lang.IllegalArgumentException: URI scheme must be http or https
        at org.mozilla.geckoview.GeckoWebExecutor.fetch(GeckoWebExecutor.java:128)
        at mozilla.components.browser.engine.gecko.fetch.GeckoViewFetchClient.fetch(GeckoViewFetchClient.kt:57)
        at mozilla.components.feature.downloads.AbstractFetchDownloadService.performDownload$feature_downloads_debug(AbstractFetchDownloadService.kt:326)
        at mozilla.components.feature.downloads.AbstractFetchDownloadService.startDownloadJob$feature_downloads_debug(AbstractFetchDownloadService.kt:292)
        at mozilla.components.feature.downloads.AbstractFetchDownloadService$onStartCommand$1.invokeSuspend(AbstractFetchDownloadService.kt:205)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)

┆Issue is synchronized with this Jira Task

csadilek avatar Mar 18 '20 18:03 csadilek

@snorp says this should be handled in AC itself

agi90 avatar Mar 30 '20 22:03 agi90

Yeah, data URLs are pretty straightforward, so you don't need GV to do anything for you. The MDN page should have everything you need here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

snorp avatar Mar 30 '20 22:03 snorp

@snorp @agi90 We could add support for data URIs ourselves, yes. Just figured we'd want the same solution/API as for blob:// which was filed against GV? I am OK doing it though, might even add support for it to our fetch library. This way the download code doesn't need to change.

However, I would still need onExternalResponse to be triggered for the download. At least, for the uBlock options page I don't see it being invoked. Should it be? https://github.com/gorhill/uBlock/blob/08d370d32e648c2823e1bc31fcd9f7e1f96d155a/platform/chromium/vapi-common.js#L172

If so, I can file that separately.

csadilek avatar Mar 30 '20 23:03 csadilek