-
Notifications
You must be signed in to change notification settings - Fork 66
Introduce canShareFiles #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Note: I am not sure of the best way to word the definition. This is an incomplete early draft seeking feedback.
@@ -103,15 +103,21 @@ <h3> | |||
</h3> | |||
<pre class="idl"> | |||
partial interface Navigator { | |||
[SecureContext] boolean canShareFiles(sequence<USVString> file_types); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I don't see much advantage of allowing a sequence. As this is a synchronous check, it's better to only allow a single value. Then there is no ambiguity about which passed value is supported and which is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should generalize the name too... to canShareType()
Each user agent should have an `allowlist` of permitted MIME types | ||
and file extensions or file names. These may contain wildcards, for | ||
example `*.txt` or `text/*`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should only support mime types, not file extensions.
I'd be against using wildcards in the manner suggested here. Let's just stick to well-formed/valid MIME Types per:
https://mimesniff.spec.whatwg.org
Additionally, we should have a list of allowed types that we all agree on, otherwise this API has the potential to becomes a fingerprinting vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree this needs more details, also for web developers who should have some assurances about the capabilities.
<li>If a file type is being blocked due to security considerations, | ||
return <a>a promise rejected with</a> with a {{"NotAllowedError"}} | ||
{{DOMException}}. | ||
<li>If |data|'s {{ShareData/files}} member is present and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The support check should be split out into its own algorithm (see #177).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note here, we need to do the same check as in #177 to make sure {files: []}
gets rejected, but passing {text: "hi", files: []}
is ok.
argument |file_types|, run the following steps: | ||
</p> | ||
<ol class="algorithm"> | ||
<li>For each |file_type| in |file_types|, if |file_type| does not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want a permissions policy check here. If not allowed, throw NotAllowedError.
<li>If |data|'s {{ShareData/files}} member is present and | ||
{{Navigator/canShareFiles()}} returns false when called with the | ||
files' extensions and content types, return <a>a promise rejected | ||
with</a> with a {{"NotAllowedError"}} {{DOMException}}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a {{TypeError}} instead, as the type is not allowed to be shared.
Thanks for putting this together @ericwilligers! This is a really good starting point. |
</p> | ||
<ol class="algorithm"> | ||
<li>For each |file_type| in |file_types|, if |file_type| does not | ||
match any entry in the user agent's `allowlist`, return `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -103,15 +103,21 @@ <h3> | |||
</h3> | |||
<pre class="idl"> | |||
partial interface Navigator { | |||
[SecureContext] boolean canShareFiles(sequence<USVString> file_types); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably just want a regular DOMString
.
[SecureContext] boolean canShareFiles(sequence<USVString> file_types); | |
[SecureContext] boolean canShareFiles(sequence<DOMString> file_types); |
{{DOMException}}. | ||
<li>If |data|'s {{ShareData/files}} member is present and | ||
{{Navigator/canShareFiles()}} returns false when called with the | ||
files' extensions and content types, return <a>a promise rejected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This needs to be spec'ed as a for each |file:File| in files:
, the check each file's content type separately.
Discussed at TPAC 2020. @NotWoods suggests that we do something like this but call it |
We discussed A design we settled on is to change partial interface Navigator {
boolean canShare(ShareCategory category, optional any option);
};
enum ShareCategory {
"files"
} The type of the second parameter would change based on the first argument, similar to // check if file sharing is supported
if (navigator.canShare("files") { ... }
// check if image sharing is supported
if (navigator.canShare("files", "image/*") { ... } |
Re: |
Actually, playing around a bit... just |
I've updated #177 to specify [SecureContext]
boolean canShare(optional ShareData data = {});
[SecureContext]
boolean canShare(DOMString name, optional CanShareQuery options = {}); Then we can just encourage developers to use the Let me know what you think... |
Can we simply leave the previous version as a Chromium-only variant rather than including it in the spec? |
We can, but that might end up having web compat issues (for Gecko)... I guess it somewhat depends on what the Webkit folks want to do also. Safari shipped with The above allows us to move away from the original version in somewhat sane way without breaking too much content (although the usage stats suggest that usage of cc @othermaciej |
Closing, as we not implemented by anyone. Looks like we are sticking with |
Note: I am not sure of the best way to word the definition.
This is an incomplete early draft seeking feedback.
For normative changes, the following tasks have been completed:
Implementation commitment:
Preview | Diff