Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: ad5c950167f181eee11e8de16b70e54bc789a609
      
https://github.com/WebKit/WebKit/commit/ad5c950167f181eee11e8de16b70e54bc789a609
  Author: Aditya Keerthi <[email protected]>
  Date:   2023-03-02 (Thu, 02 Mar 2023)

  Changed paths:
    M Source/WebKit/UIProcess/ios/WKPDFView.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm

  Log Message:
  -----------
  REGRESSION (259655@main): [iOS] Crash when opening a PDF after searching for 
text in a webpage
https://bugs.webkit.org/show_bug.cgi?id=253194
rdar://105784161

Reviewed by Wenson Hsieh, Megan Gardner and Tim Horton.

259655@main fixed find-in-PDF behavior by ensuring the `UIFindSession`'s
"searchable object" is always up-to-date.

When switching from a webpage to a PDF, WebKit switches the type of the
searchable object from `WKContentView` to `WKPDFView`. UIKit is not robust
against searchable object modification, as they cache the existence of
optional protocol methods and do not update the result when the object changes.
Consequently, optional protocol methods are called unconditionally on
`WKPDFView`, simply because `WKContentView` implements them.

Ideally, WebKit would recreate the `UIFindSession` itself when the searchable
object changes. However, this is not possible with existing API/SPI.

To fix, implement "optional" protocol methods that UIKit may end up calling
when searching for text. This prevents crashing due to unrecognized selectors.

* Source/WebKit/UIProcess/ios/WKPDFView.mm:
(-[WKPDFView supportsTextReplacement]):
(-[WKPDFView scrollRangeToVisible:inDocument:]):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:
(TEST):

Add a regression test that opens and closes the find panel on web content, loads
a PDF, and then attempts to open and close the find panel on the PDF content.

The test crashes without this patch.

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


_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to