[webkit-changes] [WebKit/WebKit] 39925c: [WebKit] Add an option key to prevent network load...

Wenson Hsieh noreply at github.com
Tue Nov 14 22:58:03 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 39925c5d4c4ef3ff0ba785efc1b5d46a242ecf99
      https://github.com/WebKit/WebKit/commit/39925c5d4c4ef3ff0ba785efc1b5d46a242ecf99
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2023-11-14 (Tue, 14 Nov 2023)

  Changed paths:
    M Source/WebKit/UIProcess/API/Cocoa/NSAttributedString.mm
    M Source/WebKit/UIProcess/API/Cocoa/NSAttributedStringPrivate.h
    M Tools/TestWebKitAPI/SourcesCocoa.txt
    M Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm
    A Tools/TestWebKitAPI/cocoa/TestResourceLoadDelegate.h
    A Tools/TestWebKitAPI/cocoa/TestResourceLoadDelegate.mm

  Log Message:
  -----------
  [WebKit] Add an option key to prevent network loads when serializing attributed strings
https://bugs.webkit.org/show_bug.cgi?id=264745
rdar://118309399

Reviewed by Tim Horton.

Add support for a `NSAttributedStringDocumentReadingOptionKey` which allows clients to serialize
attributed strings from web content, without loading any requests over the network. This is
particularly ideal for clients such as UIFoundation, when serializing HTML markup and/or web archive
data, which otherwise has the potential to trigger arbitrary resource loads upon conversion.

Note that we add an opt-in flag for network loads, because we want to eventually default to *not*
loading content from over the network when serializing attributed strings. Given this eventual plan,
it makes more sense for an app to need to explicitly opt _in_ to network loads, rather than opt out.

Test: WKWebView.DoNotAllowNetworkLoads

* Source/WebKit/UIProcess/API/Cocoa/NSAttributedString.mm:
(+[_WKAttributedStringWebViewCache configuration]):

Respect the new `_WKAllowNetworkLoadsOption` option by setting `_allowedNetworkHosts` to an empty
set on the configuration, if the value is false-y.

(+[_WKAttributedStringWebViewCache maybeUpdateShouldAllowNetworkLoads:]):
(+[_WKAttributedStringWebViewCache maybeConsumeBundlePaths:]):
(+[_WKAttributedStringWebViewCache invalidateGlobalConfigurationIfNeeded:]):

Refactor this logic to update the global configuration (and clear any cached web views if needed),
if either network load disablement or the allowed file URL list changes.

(+[NSAttributedString _loadFromHTMLWithOptions:contentLoader:completionHandler:]):
* Source/WebKit/UIProcess/API/Cocoa/NSAttributedStringPrivate.h:
* Tools/TestWebKitAPI/SourcesCocoa.txt:
* Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadDelegate.mm:

Lift the `TestResourceLoadDelegate` class out of this API test and into a separate helper file, so
that we can use it in a different API test suite (see below).

(-[TestResourceLoadDelegate webView:resourceLoad:didSendRequest:]): Deleted.
(-[TestResourceLoadDelegate webView:resourceLoad:didPerformHTTPRedirection:newRequest:]): Deleted.
(-[TestResourceLoadDelegate webView:resourceLoad:didReceiveChallenge:]): Deleted.
(-[TestResourceLoadDelegate webView:resourceLoad:didReceiveResponse:]): Deleted.
(-[TestResourceLoadDelegate webView:resourceLoad:didCompleteWithError:response:]): Deleted.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm:

Add a new API test to exercise the case where `_WKAllowNetworkLoadsOption` is set to `@NO`, by
adding a resource load delegate to the web view to listen for any attempted network access. When
this new option is set, we should never get a call to the `didSendRequest:` delegate method.

* Tools/TestWebKitAPI/cocoa/TestResourceLoadDelegate.h: Added.
* Tools/TestWebKitAPI/cocoa/TestResourceLoadDelegate.mm: Added.
(-[TestResourceLoadDelegate webView:resourceLoad:didSendRequest:]):
(-[TestResourceLoadDelegate webView:resourceLoad:didPerformHTTPRedirection:newRequest:]):
(-[TestResourceLoadDelegate webView:resourceLoad:didReceiveChallenge:]):
(-[TestResourceLoadDelegate webView:resourceLoad:didReceiveResponse:]):
(-[TestResourceLoadDelegate webView:resourceLoad:didCompleteWithError:response:]):

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




More information about the webkit-changes mailing list