Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 5bc842de99ab753aaca529954c45711dbbed7bbe
      
https://github.com/WebKit/WebKit/commit/5bc842de99ab753aaca529954c45711dbbed7bbe
  Author: Richard Robinson <[email protected]>
  Date:   2025-06-17 (Tue, 17 Jun 2025)

  Changed paths:
    A Source/WebKit/UIProcess/API/Swift/WebPage+Transferable.swift
    M Source/WebKit/UIProcess/API/Swift/WebPage.swift
    M Source/WebKit/WebKit.xcodeproj/project.pbxproj
    M Source/WebKit/_WebKit_SwiftUI/API/WebPage+SwiftUI.swift
    M Tools/SwiftBrowser/Source/ViewModel/BrowserViewModel.swift
    M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
    A Tools/TestWebKitAPI/Tests/WebKit Swift/WebPageTransferableTests.swift

  Log Message:
  -----------
  [SwiftUI] Conform WebPage to Transferable
https://bugs.webkit.org/show_bug.cgi?id=294528
rdar://152695298

Reviewed by Aditya Keerthi.

`WebPage` has several ad-hoc functions to produce web archives, PDFs, and 
images. Instead of these
functions, this PR conforms `WebPage` to `Transferable`, which offers several 
conveniences
and enhanced functionality, as well as being a substantially more modern API 
design.

This change involves three major parts:

1) Conform `WebPage` to the `Transferable` protocol. This provides a lot of 
conveniences to the developer;
in particular, it will now be possible to directly use a WebPage directly when 
performing operations that
are done on `Transferable` types such as drag and drop and copy and paste. 
Additionally, this makes it possible
for new exportable types to be added in WebKit without having to make any API 
modifications. Developers can also
directly use the conformance by using the `exported(as:)` function, providing 
uniformity both within WebKit itself
and amongst other types that conform to `Transferable`.

2) The current `WebPage`/`WKWebView` API provides several configuration options 
for generating PDFs and images.
If `WebPage` were to just conform to `Transferable`, these customization 
options would be lost. To maintain parity,
an overload of `exported(as:)` is provided by WebKit itself, with the parameter 
describing the exported type along
with its configuration. Data created using the normal `Transferable` 
conformance will use the default configurations.

3) Remove the existing functions from `WebPage`, since they will be obviated by 
the `Transferable` conformance.

As an implementation detail, `WebPage` can also add support for several other 
content types, such as URL, rich text,
and link presentation metadata, in addition to pdf, web archive, and image. 
This does not directly impact the API
surface but is good to note.

* Source/WebKit/UIProcess/API/Swift/WebPage+Transferable.swift: Added.

Conform WebPage to Transferable; to do so, WebPage implements the 
`transferRepresentaion` rquirement. This provides
different content types that a WebPage can be exported to; specifically, web 
archive data, pdf, image, and URL.

* Source/WebKit/UIProcess/API/Swift/WebPage.swift:

When a WebPage is used without a WebView, it needs to have some non-zero size 
so that representations such as PDF
and image can actually be created. If a WebPage is not bound to a WebView, it's 
frame is now set to a fixed size.

Also, remove the old PDF and web archive data functions.

* Source/WebKit/_WebKit_SwiftUI/API/WebPage+SwiftUI.swift:

Remove the old snapshot function.

* Tools/SwiftBrowser/Source/ViewModel/BrowserViewModel.swift:

Update the test app.

* Tools/TestWebKitAPI/Tests/WebKit Swift/WebPageTransferableTests.swift: Added.

Add several tests to test the Transferable functionality.

Canonical link: https://commits.webkit.org/296332@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to