Skip to content

Commit

Permalink
Add web custom format.
Browse files Browse the repository at this point in the history
  • Loading branch information
snianu committed May 5, 2022
1 parent 90bf6bb commit 3780878
Showing 1 changed file with 16 additions and 34 deletions.
50 changes: 16 additions & 34 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -786,15 +786,13 @@ urlPrefix: https://w3c.github.io/FileAPI/#dfn-; type: dfn;

1. Abort these steps.

1. Let |data| be a copy of the [=system clipboard data=] represented as [=clipboard items=]. For the MIME types defined in the [=mandatory data types=] list, |data| contains the sanitized copy of text/html format, but image/png format has unsanitized payload to preserve meta data.
1. Let |data| be a copy of the [=system clipboard data=] represented as [=clipboard items=]. For the [=/MIME type=]s defined in the [=mandatory data types=] list, |data| contains the content of text/html format, but image/png format has unsanitized payload to preserve meta data. For the [=/MIME type=]s that has a "web" prefix, [=read unsanitized format=] from the [=system clipboard=] and append the content of the format to |data|.

Issue: Some OSs contain multiple clipboard (e.g. Linux, "primary", "secondary", "selection"). Define from which of those data is read.

Note: As further described in [[#image-transcode]] this explicitly does not transcode images.
Rather the original unmodified image data should be exposed to the website.

Issue: Add definition of sanitized copy.

1. [=Queue a global task=] on the [=clipboard task source=], given |realm|'s [=Realm/global object=], to perform the below steps:

1. Let |items| be a [=sequence=]<{{ClipboardItem}}>.
Expand Down Expand Up @@ -951,19 +949,11 @@ urlPrefix: https://w3c.github.io/FileAPI/#dfn-; type: dfn;

1. Let |type| be the |blob|'s {{Blob/type}}.

1. If |type| is not in the [=mandatory data types=] list, then [=reject=] |p| with {{"NotAllowedError"}} {{DOMException}} in |realm| and abort these steps.

1. Let |cleanItem| be a sanitized copy of |blob|.

Issue: Add definition of sanitized copy.

1. If unable to create a sanitized copy, then follow the below steps:

1. [=Reject=] |p| with {{"NotAllowedError"}} DOMException in |realm|.
1. If |type| is not in either the [=mandatory data types=] list or has "web " prefix, then [=reject=] |p| with {{"NotAllowedError"}} {{DOMException}} in |realm| and abort these steps.

1. Abort these steps.
1. Append |blob| to |cleanItemList|.

1. Append |cleanItem| to |cleanItemList|.
Issue: Currently Safari does some sanitization for [=mandatory data types=]. See https://github.com/w3c/clipboard-apis/issues/150.

1. Let |option| be |clipboardItem|'s [=ClipboardItem/clipboard item=]'s [=presentation style=].

Expand Down Expand Up @@ -1609,18 +1599,26 @@ urlPrefix: https://w3c.github.io/FileAPI/#dfn-; type: dfn;
: Output
:: None

1. Let |webCustomFormats| be a [=sequence=]<{{Blob}}>.

1. For each |item| in |items|:

1. Let |formatString| be the result of running [=os specific well-known format=] given |item|'s {{Blob/type}}.

1. If |formatString| is empty then abort these steps.
1. If |formatString| is empty then follow the below steps:

1. If |formatString| has "web " prefix, then add |item| to |webCustomFormats|, else abort all steps.

1. Let |payload| be the result of [=UTF-8 decoding=] |item|'s underlying byte sequence.

1. Insert |payload| and |presentationStyle| into the [=system clipboard=] using |formatString| as the native clipboard format.

Issue: some OSs contain multiple clipboard (e.g. Linux, "primary", "secondary", "selection"). Define to which of those data is written.

1. For each |customItem| in |webCustomFormats|:

1. [=Write unsanitized format=] with |customItem| and |customItem|'s {{Blob/type}}'s [=MIME type/essence=].

</div><!-- algorithm -->

<div class="algorithm" data-algorithm="os-specific-well-known-format">
Expand All @@ -1638,67 +1636,51 @@ urlPrefix: https://w3c.github.io/FileAPI/#dfn-; type: dfn;
For Mac see https://developer.apple.com/documentation/appkit/nspasteboardtype
</p>

1. Let |wellKnownFormat| be a string.
1. Let |wellKnownFormat| be an empty string.

1. If |mimeType|'s [=MIME type/essence=] is "text/plain", then

On Windows, follow the convention described below:

1. Assign CF_UNICODETEXT to |wellKnownFormat|.

1. Return |wellKnownFormat|.

On MacOS, follow the convention described below:

1. Assign NSPasteboardTypeString to |wellKnownFormat|.

1. Return |wellKnownFormat|.

On Linux, ChromeOS, and Android, follow the convention described below:

1. Assign "text/plain" to |wellKnownFormat|.

1. Return |wellKnownFormat|.

1. Else, if |mimeType|'s [=MIME type/essence=] is "text/html", then

On Windows, follow the convention described below:

1. Assign CF_HTML to |wellKnownFormat|.

1. Return |wellKnownFormat|.

On MacOS, follow the convention described below:

1. Assign NSHTMLPboardType to |wellKnownFormat|.

1. Return |wellKnownFormat|.

On Linux, ChromeOS, and Android, follow the convention described below:

1. Assign "text/html" to |wellKnownFormat|.

1. Return |wellKnownFormat|.

1. Else, if |mimeType|'s [=MIME type/essence=] is "image/png", then

On Windows, follow the convention described below:

1. Assign "PNG" to |wellKnownFormat|.

1. Return |wellKnownFormat|.

On MacOS, follow the convention described below:

1. Assign NSPasteboardTypePNG to |wellKnownFormat|.

1. Return |wellKnownFormat|.

On Linux, ChromeOS, and Android, follow the convention described below:

1. Assign "image/png" to |wellKnownFormat|.

1. Return |wellKnownFormat|.
1. Return |wellKnownFormat|.

</div><!-- algorithm -->

Expand Down Expand Up @@ -1732,7 +1714,7 @@ urlPrefix: https://w3c.github.io/FileAPI/#dfn-; type: dfn;
<h3 id="to-write-unsanitized-format"><dfn>write unsanitized format</dfn></h3>

: Input
:: |items|, {{Blob}}s
:: |items|, a [=sequence=]&lt;{{Blob}}&gt;
:: |mimeType|, a string

1. Let |idx| be a number initialized to 0.
Expand Down

0 comments on commit 3780878

Please sign in to comment.