Skip to content
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

Add Web Custom format #175

Merged
merged 8 commits into from
Sep 18, 2023
Merged

Add Web Custom format #175

merged 8 commits into from
Sep 18, 2023

Conversation

snianu
Copy link
Contributor

@snianu snianu commented May 5, 2022

Closes #165

For normative changes, the following tasks have been completed:

  • Modified Web platform tests (link to pull request)

Implementation commitment:


Preview | Diff

@snianu snianu requested a review from BoCupp-Microsoft May 5, 2022 22:50
@snianu
Copy link
Contributor Author

snianu commented May 5, 2022

@annevk @mbrodesser This PR has the web prefix changes. PTAL. Thanks!

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 18, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 20, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 20, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 20, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 23, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
@snianu snianu force-pushed the custom-format-spec branch from 3780878 to 897ad31 Compare May 23, 2022 18:11
@annevk
Copy link
Member

annevk commented May 24, 2022

Upon doing code inspection in Gecko we found that the legacy clipboard API might have some support for custom types as well. @EdgarChen is investigating this. We don't really want to end up with a situation where we have two incompatible custom types APIs.

It might be that other browsers have something similar as there were at least some hints of cross-browser collaboration?

@snianu
Copy link
Contributor Author

snianu commented May 24, 2022

@annevk Chromium and Safari have browser specific custom type that is undocumented and doesn't interop with other apps. The format parsing rules are convoluted since it uses browser specific pickling types for serialization/deserialization. This proposal aims to standardize the web custom formats and the format structure so its well documented and is interop across apps on a platform. This doesn't affect the existing pickling types.

In Firefox, I see that it allows writing custom types in setData, but I don't see any restriction on the number of custom types that can be registered. This is a major security issue on Windows and Linux because of the restriction on the number of clipboard formats that can be registered with the OS. This proposal addresses this issue by introducing a fixed set of web custom formats and a map that maps the mime types to native web custom formats.
image

Copy link
Contributor

@BoCupp-Microsoft BoCupp-Microsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! I think if you address these comments I'll be ready to approve for a merge.

index.bs Outdated
<h3 id="to-read-unsanitized-format"><dfn>read unsanitized format</dfn></h3>

: Input
:: |mimeType|, a string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you call this |customFormatKey| and include the parse a mime-type steps in this algorithm to transform that into a "web " prefixed and parsed name that can be used to construct the clipboard item. the name you construct should probably be an output parameter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, to make it clear what's an acceptable key, when parsing a mime-type, you actually use the ParseMimeTypeWithoutParameter function in Chromium, so can you clarify in the steps that you take the type and sub-type and concatenate those outputs from the parse a mime-type algorithm with '/', but throw away the parameters?

https://chromium-review.googlesource.com/c/chromium/src/+/3650952

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lastly, the parse a mime type can fail (by returning failure per the spec) so can you clarify that if failure is returned what you will do? I believe this function should also return failure and then you simply don't append anything to the collection of data used to construct the clipboarditems that will be given to the author.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be a bit more resilient to the parsing mime type errors, I added steps to ignore the mime types that returned failure during parsing.

index.bs Outdated Show resolved Hide resolved
index.bs Outdated Show resolved Hide resolved
index.bs Outdated
@@ -786,7 +786,7 @@ 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| MAY be sanitized, 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 types defined in the [=mandatory data types=] list, |data| MAY be sanitized, but image/png format has unsanitized payload to preserve meta data. For the [=/MIME type=]s that have a "web "("web" followed by U+0020 SPACE) prefix, [=read unsanitized format=] from the [=system clipboard=] and append the content of the format to |data|.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step is getting a bit long and does a lot. Also, it sounds like if data is a copy of the system clipboard data that there will be more than just the mandatory mime-types and web custom formats in data.

I believe we want a loop over the mandatory data types where we insert each into a data object that will be used to construct a single clipboarditem with multiple representations corresponding to each of those types.

Additionally, we want a step here to first read the JSON from the Web Custom Format Map, and then we can loop over its keys too. For each key we can obtain the name of the format corresponding to that mime-type on the system clipboard, read it, and then add its blob to data using a new key that is the result of running the key we got from the JSON through the parse a mime-type algorithm with "web " prepended.

Most of that can happen in the read helper function you have defined. Consider returning the "web " prefixed and parsed name from that method in addition to the blob itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two additional nits:

  1. Be sure to include MAY be sanitized as a step as you iterate over the mandatory data types to preserve what you added in your previous PR.
  2. Instead of looping over mandatory data types, you can loop over a set of data types supported by the user agent as a well-known format, which must at least include the mandatory data types listed in this spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these additional steps.

index.bs Outdated

1. If |idx| is greater than 100, then break from this loop.

1. Insert the |webCustomFormatMap| into the [=system clipboard=].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should say something like insert the JSON serialized representation of |webCustomFormatMap| into the clipboard.

Copy link
Contributor Author

@snianu snianu May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a step above to insert the mime type as key and |webCustomFormatIdx| as value into the |webCustomFormatMapString| using a JSON serializer.

index.bs Outdated

1. Let |webCustomFormatIdx| be the result of appending |idx| to |webCustomFormat|.

1. Insert |mimeType| as key and |webCustomFormatIdx| as value into the |webCustomFormatMap|.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before inserting mimeType, you should be stripping the "web " prefix. I think the what follows the space is guaranteed to be a parsed as a mime-type value per the steps in the construction of the clipboarditem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we didn't update the ClipboardItem constuctor. We have a step in there that runs the parse a mime-type algorithm, but it needs to test and allow for "web " prefixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@EdgarChen
Copy link

This proposal aims to standardize the web custom formats and the format structure so its well documented and is interop across apps on a platform. This doesn't affect the existing pickling types.

Do we care about the interop across legacy clipboard API and async clipboard API for custom type? E.g. write custom type via legacy clipboard API and read via async clipboard API, or vice versa.

@snianu
Copy link
Contributor Author

snianu commented May 31, 2022

Do we care about the interop across legacy clipboard API and async clipboard API for custom type?

@EdgarChen The async clipboard API model is fairly different, so I'm not sure if we can interop with legacy types. The web custom types are stored inside a JSON map structure, with fixed number of native web clipboard formats, and a well-defined format structure that helps the native apps parse the content of the format. At least in Chromium, the parsing of the custom types requires browser specific pickle types to serialize and deserialize the content, so it's not possible to add support for this format to the new web custom format.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 1, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 1, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 1, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 4, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 4, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 6, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
aarongable pushed a commit to chromium/chromium that referenced this pull request Jun 6, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3650952
Commit-Queue: Anupam Snigdha <[email protected]>
Reviewed-by: Alexander Timin <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Austin Sullivan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1011078}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 6, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3650952
Commit-Queue: Anupam Snigdha <[email protected]>
Reviewed-by: Alexander Timin <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Austin Sullivan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1011078}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 6, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3650952
Commit-Queue: Anupam Snigdha <[email protected]>
Reviewed-by: Alexander Timin <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Austin Sullivan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1011078}
@EdgarChen
Copy link

The web custom types are stored inside a JSON map structure, with fixed number of native web clipboard formats, and a well-defined format structure that helps the native apps parse the content of the format.

@snianu We could also write arbitrary type with "web" prefix via legacy API, e.g.

document.addEventListener("copy", function(e) {
  e.preventDefault();
  
  let clipboardData = e.clipboardData;
  clipboardData.setData("web text/foo", "foo");
  clipboardData.setData("text/bar", "bar");
});

I would expect the type with "web" prefix to follow the well-defined format/structure, too. So it could be interop with async clipobard API/browsers/native apps. for example, if we write the data into clipboard via above example and read clipboard data via async clipboard API

const items = await navigator.clipboard.read();
items[0].getType("web text/foo"); // get "foo"
items[0].getType("text/bar"); // promise reject 

(and vice versa)

Yes, this introduce a behavior changes in legacy API, but I think this also make web custom type less surprise to user? And the impact in legacy API should be small?

@snianu
Copy link
Contributor Author

snianu commented Jun 7, 2022

@EdgarChen While it's true that you could write custom types with "web " prefix using DataTransfer APIs, those custom types do not follow the same model - there isn't a restriction on the number of custom format types that can be written by the web authors, no web custom JSON map for mapping the web custom types to a fixed number of native web clipboard formats etc.
We don't want to make any changes in the legacy DataTransfer APIs as it has high regression risks and the model is fairly different there(at least in Chromium). The native apps on Windows do not know how to parse Chromium specific custom types, so it's not possible for them to exchange formats between web and native apps.
Chrome doesn't expose the custom mime types exactly as is - it exposes it via a Chromium specific custom format that uses browser specific parsing types, and it is not standardized, so the native apps don't understand how to parse this structure.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jun 10, 2022
…mats implementation., a=testonly

Automatic update from web-platform-tests
[Clipboard API] Clipboard Web Custom Formats implementation.

This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3650952
Commit-Queue: Anupam Snigdha <[email protected]>
Reviewed-by: Alexander Timin <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Austin Sullivan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1011078}

--

wpt-commits: b8ebea7f172334f5a5d9ac87860aec5f55becd26
wpt-pr: 34117

1. Let |firstItem| be |items|[0]

1. Run the [=read web custom format=] algorithm given |firstItem|.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per https://w3c.github.io/clipboard-apis/#dom-clipboarditem-types, type getter of ClipboardItem returns types array, but it is not clear how does types array be constructed. It would be nice that we could have some steps for that.

Not sure if this makes sense: maybe we could construct types array from list of representations, but which means we would need to read custom types first as we would like the custom types listed at the top.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. We should definitely add this to the spec.

mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this pull request Oct 14, 2022
This patch addresses the changes proposed by the EditingWG[1] and
agreed upon by all browser vendors. We are removing the `unsanitized`
option, and instead, adding custom format support for MIME types that
have "web " prefix in them.
Added few wpt tests to test these changes.
Below is a summary of the changes in this CL:
1. Removed `unsanitized` option from read/write methods.
2. If the custom format doesn't have a "web " prefix, then clipboard
   read/write fails.
3. Transient user activation is applicable to all supported formats -
   text/html, text/plain, image/png and web custom formats.
4. There are two "buckets" of clipboard formats. One for the
   well-known formats and the other for the web custom format. If the
   author doesn't specify the web format explicitly, then they don't
   get access to it. This means, we won't write web custom formats
   for well-known types implicitly if authors have not indicated that
   during the write call via a "web " prefix (e.g. "web text/html").
   Same  applies for reading web custom formats for well-known types-
   if there aren't any formats in the web custom format map, then we
   won't return any web custom formats i.e. text/html won't be
   automatically converted into "web text/html".

Spec: w3c/clipboard-apis#175
Explainer: https://github.com/w3c/editing/blob/gh-pages/docs/clipboard-pickling/explainer.md
i2p: https://groups.google.com/a/chromium.org/g/blink-dev/c/Lo7WBM_v_LY/m/LncCKkXeAwAJ
i2s: https://groups.google.com/a/chromium.org/g/blink-dev/c/k2rgX-4Cigc/m/P0RijrpzBAAJ?utm_medium=email&utm_source=footer&pli=1

1. Github issue: w3c/clipboard-apis#165

Bug: 106449

Change-Id: I86aae6a662089efeede2a01ac87cb698e9646df5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3650952
Commit-Queue: Anupam Snigdha <[email protected]>
Reviewed-by: Alexander Timin <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Austin Sullivan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1011078}
NOKEYCHECK=True
GitOrigin-RevId: a3b96a459cf17ddc683b510718bfcbe40ed08195
@polx
Copy link

polx commented Nov 15, 2022

Hello @snianu ,

I've tried to review the current state after I have seen your presentation at the TPAC.

Here are my rather nitty gritty comments:

  • sec 7.2 (ClipboardItem Interface): should is custom really be written in two words and not in one? The link in the version I could build did not work but that might be a local issue.
  • the spreadsheet example close to that is nice, could it not also include a custom type? (e.g. containing text/csv alternative?)
  • A web custom format has is custom set to true. => A representation in a web custom format has is custom set to true ?
  • 7.3.3: write algorithm: f type is not in the mandatory data types list and has "web ": did you not mean “or has...” ?
  • write blobs and option to the clipboard:
    • step 1: why is the variable called webCustomFormat ? It should be formats or something universal, right?
    • substeps under 2.2: "If formatString is empty then follow the below steps:": the steps here does not define a (non-empty) formatString; a value is however needed in order for the recipients to read (suggestion: “set formatString to a randomly chosen format name”)
    • step 2.3: Let payload be the result of UTF-8 decoding item’s underlying byte sequence. : this must be a misunderstanding as it would only apply to text. Maybe the whole section was about text? Then it was not readable
  • the steps of “write web custom formats” sound quite solid to me but why is it independent from the previous?

Tell me if I should make my comments more precise (e.g. with line numbers).

I am quite excited by the implementation found in Chromium (and blogged about it). I suspect that we are getting close to acceptance, at least provided that Mozilla will consider implementing as it seems it said at the start.

thanks and sorry to be slow to have reviewed.

Paul

@snianu
Copy link
Contributor Author

snianu commented Sep 18, 2023

Thanks @polx for the review and apologies for the delay!

A web custom format has is custom set to true. => A representation in a web custom format has is custom set to true ?

Note that in the spec it's referred to as [=representation/isCustom=]

step 1: why is the variable called webCustomFormat ? It should be formats or something universal, right?

This is referring to the custom format with a web prefix, so it can be anything. In the below step, we strip out the web prefix:
If |webCustomFormatString| has "web "("web" followed by U+0020 SPACE) prefix, then remove the "web " prefix and store the remaining string in |webCustomFormat|'s {{Blob/type}}'s [=MIME type/essence=], else abort all steps.

step 2.3: Let payload be the result of UTF-8 decoding item’s underlying byte sequence. : this must be a misunderstanding as it would only apply to text. Maybe the whole section was about text? Then it was not readable

This is by-design that we write raw bytes sequence to the clipboard for the custom formats so the reader has to know how to parse its content (which is also by-design).

the steps of “write web custom formats” sound quite solid to me but why is it independent from the previous?

This is because we need to perform an additional step to produce a native clipbaord format and insert the key-value pair into the webCustomFormatMap. This step is not performed for mandatory data types.

@snianu
Copy link
Contributor Author

snianu commented Sep 18, 2023

@sanketj could you please take a look at this PR so we can merge it into the clipboard repo? Thanks!

@snianu
Copy link
Contributor Author

snianu commented Sep 18, 2023

@garykac Thank you so much!

@snianu snianu merged commit eb4e99a into main Sep 18, 2023
1 check passed
github-actions bot added a commit that referenced this pull request Sep 18, 2023
SHA: eb4e99a
Reason: push, by snianu

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
index.bs Show resolved Hide resolved
mjbvz added a commit to mjbvz/vscode that referenced this pull request Jul 29, 2024
For web, our clipboard for resources currently is in-memory only. This prevents copying data between windows and can also cause us to get into odd states where the in-memory clipboard no longer matches what's the real clipboard

This change tried to migrate resources to use the  real clipboard thanks the custom web clipboard types: w3c/clipboard-apis#175

This feature only works in Chromium at the moment, but I believe other browsers have expressed intent to implement it too
mjbvz added a commit to mjbvz/vscode that referenced this pull request Jul 29, 2024
For web, our clipboard for resources currently is in-memory only. This prevents copying data between windows and can also cause us to get into odd states where the in-memory clipboard no longer matches what's the real clipboard

This change tried to migrate resources to use the  real clipboard thanks the custom web clipboard types: w3c/clipboard-apis#175

This feature only works in Chromium at the moment, but I believe other browsers have expressed intent to implement it too
mjbvz added a commit to microsoft/vscode that referenced this pull request Jul 30, 2024
For web, our clipboard for resources currently is in-memory only. This prevents copying data between windows and can also cause us to get into odd states where the in-memory clipboard no longer matches what's the real clipboard

This change tried to migrate resources to use the  real clipboard thanks the custom web clipboard types: w3c/clipboard-apis#175

This feature only works in Chromium at the moment, but I believe other browsers have expressed intent to implement it too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Arbitrary clipboard types
8 participants