[webkit-changes] [WebKit/WebKit] 2ee4f3: [iOS] Don't show a Translate option in the edit me...

Wenson Hsieh noreply at github.com
Mon Feb 20 11:41:36 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 2ee4f3c0ed18c1ad7015b18cd374b7cfd4aa503b
      https://github.com/WebKit/WebKit/commit/2ee4f3c0ed18c1ad7015b18cd374b7cfd4aa503b
  Author: Wenson Hsieh <wenson_hsieh at apple.com>
  Date:   2023-02-20 (Mon, 20 Feb 2023)

  Changed paths:
    M Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
    M Source/WebCore/PAL/pal/PlatformMac.cmake
    A Source/WebCore/PAL/pal/cocoa/TranslationUIServicesSoftLink.h
    A Source/WebCore/PAL/pal/cocoa/TranslationUIServicesSoftLink.mm
    A Source/WebCore/PAL/pal/spi/cocoa/TranslationUIServicesSPI.h
    M Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
    M Source/WebKit/UIProcess/mac/WebViewImpl.mm
    M Source/WebKitLegacy/mac/WebView/WebView.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm

  Log Message:
  -----------
  [iOS] Don't show a Translate option in the edit menu if TranslationUIServices is unavailable
https://bugs.webkit.org/show_bug.cgi?id=252518
rdar://105163787

Reviewed by Aditya Keerthi.

Return NO from `-canPerformAction:withSender:` for the `@selector(_translate:)` action, in the case
where the TranslationUIServices framework is either unavailable, or the translation view controller
(`LTUITranslationViewController`) itself is unavailable — that is, if `+isAvailable` returns NO.

We also take this opportunity to refactor soft linking for TranslationUIServices, such that it's all
consolidated in Cocoa-specific files in PAL.

Covered by augmenting an existing API test: WebKit.CanInvokeTranslateWithTextSelection

* Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj:
* Source/WebCore/PAL/pal/PlatformMac.cmake:
* Source/WebCore/PAL/pal/cocoa/TranslationUIServicesSoftLink.h: Added.
* Source/WebCore/PAL/pal/cocoa/TranslationUIServicesSoftLink.mm: Added.
* Source/WebCore/PAL/pal/spi/cocoa/TranslationUIServicesSPI.h: Added.

Add support for the new SPI header and soft-linking headers, for `TranslationUIServices.framework`.

* Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView canPerformActionForWebView:withSender:]):

Implement the main fix here — consult `+isAvailable` and return NO if translation is unavailable.

* Source/WebKit/UIProcess/mac/WebViewImpl.mm:
(WebKit::WebViewImpl::canHandleContextMenuTranslation const):
(WebKit::WebViewImpl::handleContextMenuTranslation):
* Source/WebKitLegacy/mac/WebView/WebView.mm:
(+[WebView _canHandleContextMenuTranslation]):
(-[WebView _handleContextMenuTranslation:]):

Deploy the new PAL softlinking headers in existing macOS code.

* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEditActions.mm:
(TestWebKitAPI::TEST):

Adjust an existing test to also verify that we don't allow the translate menu action in the case
where `+isAvailable` returns NO.

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




More information about the webkit-changes mailing list