w3c / web-share-target

Web API proposal for receiving shared data
https://w3c.github.io/web-share-target/
Other
191 stars 20 forks source link

Android and Web Share Target have different model for text sharing #81

Open HenryJian opened 5 years ago

HenryJian commented 5 years ago

The current WST specs distinguishes between sharing a text file (WST v2) and sharing naked text (WST v1). However, Android doesn't make such distinction. An apk with a <data android:mimeType="text/plain"/> inside its <intent-filter> will respond to both text file sharing and naked text sharing.

This causes problems for installed web apps on Android (through "add to home screen" on Chrome):

  1. WST handles text files but not naked text: When a user shares naked text, the installed web app shows up in the list of share targets, , but it won't do anything because WST isn't expecting naked text.

  2. WST handles naked text but not text files: Similarly, when a user shares text files, the installed web app shows up in the list of share targets, but it won't do anything because WST isn't expecting text files.

One solution to this is the user agent convert between text files and naked text behind the scene. For case 1, user agent writes the naked text to a text file. Caveat: filename will be empty. For case 2, user agent reads the file to get the naked text. Caveats: First, if user shares multiple files, form data/url search param will have multiple entries with the same "share-text" key. Thus, on the receiving end, form_data.get("share-text") or url_search_param.get("share-text") will return an array, instead of a string. Second, if data is encoded in url search parameter and user shares a big file, we may need to truncate file content because of url size limit

ewilligers commented 5 years ago

For case 1, we can generate a temporary file name: share 123456 .txt

For case 2, we can append the text file contents into a single string, and truncate. This keeps with the existing Web Share design of the text field being a single string.

Truncation occurs if method=GET. We can add a warning to the spec (PR).