Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Unable to download data: urls #6314

Closed
csadilek opened this issue Mar 18, 2020 · 3 comments
Closed

Unable to download data: urls #6314

csadilek opened this issue Mar 18, 2020 · 3 comments
Assignees
Labels
🐞 bug Something isn't working <download> Component: feature-download

Comments

@csadilek
Copy link
Contributor

csadilek commented Mar 18, 2020

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: #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

@agi90
Copy link
Contributor

agi90 commented Mar 30, 2020

@snorp says this should be handled in AC itself

@snorp
Copy link
Contributor

snorp commented Mar 30, 2020

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

@csadilek
Copy link
Contributor Author

csadilek commented Mar 30, 2020

@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 csadilek self-assigned this Mar 31, 2020
csadilek added a commit to csadilek/android-components that referenced this issue Mar 31, 2020
csadilek added a commit to csadilek/android-components that referenced this issue Mar 31, 2020
csadilek added a commit to csadilek/android-components that referenced this issue Apr 2, 2020
bors bot pushed a commit that referenced this issue Apr 2, 2020
6475: Closes #6314: Support fetching / downloading data URIs r=Amejia481,pocmo a=csadilek

With this we can fetch from data URIs and downloads "just work" (we don't require any special handling). So, e.g. this works now (which is also used by uBlock to save backups):

```html
<a href="data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" download="backup.txt">Backup</a>
```
https://github.com/gorhill/uBlock/blob/08d370d32e648c2823e1bc31fcd9f7e1f96d155a/platform/chromium/vapi-common.js#L172

GV didn't want to add API for it so I took a stab at adding this to our fetch libs: #6314 (comment)

@pocmo can you take a look since we looked at download stuff today :). I've time-boxed this and limited to base64 encoded URIs. The device and unit tests pass and the download works / can be tested here:

https://jsfiddle.net/nue9rg0L/2/

Co-authored-by: Christian Sadilek <[email protected]>
bors bot pushed a commit that referenced this issue Apr 2, 2020
6475: Closes #6314: Support fetching / downloading data URIs r=Amejia481,pocmo a=csadilek

With this we can fetch from data URIs and downloads "just work" (we don't require any special handling). So, e.g. this works now (which is also used by uBlock to save backups):

```html
<a href="data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==" download="backup.txt">Backup</a>
```
https://github.com/gorhill/uBlock/blob/08d370d32e648c2823e1bc31fcd9f7e1f96d155a/platform/chromium/vapi-common.js#L172

GV didn't want to add API for it so I took a stab at adding this to our fetch libs: #6314 (comment)

@pocmo can you take a look since we looked at download stuff today :). I've time-boxed this and limited to base64 encoded URIs. The device and unit tests pass and the download works / can be tested here:

https://jsfiddle.net/nue9rg0L/2/

Co-authored-by: Christian Sadilek <[email protected]>
@bors bors bot closed this as completed in facd604 Apr 2, 2020
csadilek added a commit to csadilek/android-components that referenced this issue Apr 7, 2020
csadilek added a commit to csadilek/android-components that referenced this issue Apr 7, 2020
bors bot pushed a commit that referenced this issue Apr 7, 2020
6561: Issue #6314: Support fetching non base64 encoded data URIs r=Amejia481 a=csadilek

Simple change to support data URI that are not base64 encoded. With this backup/restore is now finally working in uBlock.

6562: Merge day! r=jonalmeida a=pocmo

Happy merge day everyone. 🍰 

Co-authored-by: Christian Sadilek <[email protected]>
Co-authored-by: Sebastian Kaspari <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working <download> Component: feature-download
Projects
None yet
Development

No branches or pull requests

3 participants