[webkit-changes] [WebKit/WebKit] 65e9ef: Web Inspector: When there is a UA override on Safa...

Abrar Rahman Protyasha noreply at github.com
Fri Jan 12 17:49:44 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 65e9ef262a036ce065c7ccb94a9e6bf4ae057529
      https://github.com/WebKit/WebKit/commit/65e9ef262a036ce065c7ccb94a9e6bf4ae057529
  Author: Abrar Rahman Protyasha <a_protyasha at apple.com>
  Date:   2024-01-12 (Fri, 12 Jan 2024)

  Changed paths:
    M Source/WebCore/loader/FrameLoader.cpp
    M Source/WebCore/loader/LocalFrameLoaderClient.h
    M Source/WebKit/UIProcess/WebPageProxy.cpp
    M Source/WebKit/UIProcess/WebPageProxy.h
    M Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.cpp
    M Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.h
    M Source/WebKit/WebProcess/WebPage/WebPage.cpp
    M Source/WebKit/WebProcess/WebPage/WebPage.h
    M Source/WebKit/WebProcess/WebPage/WebPage.messages.in
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm

  Log Message:
  -----------
  Web Inspector: When there is a UA override on Safari, choosing a UA override in Develop Menu is not working
https://bugs.webkit.org/show_bug.cgi?id=265575
rdar://118981832

Reviewed by Wenson Hsieh.

`FrameLoader` does not consult `WebLocalFrameLoaderClient` for the UA
string if the client app adjusts the UA for a website using the
site-specific quirk mechanism, culprit to this line:

```
    // From FrameLoader::userAgent()
    if (userAgent.isEmpty())
        userAgent = m_client->userAgent(url);
```

Unfortunately, `WebLocalFrameLoaderClient` consults the `WebPage` for
the UA string, so that is the only source of truth for any potential UA
overrides, such as the UA override from Safari's develop menu.

This commit introduces a bit more fidelity in the UA resolution logic in
`FrameLoader::userAgent`, such that we initially respect any
site-specific quirks, but also take into account the possibility that
the client has overriden the user agent. We relay this information down
to `FrameLoader` by introducing an IPC message to the WebPage which
tells it that a custom UA string has been set. If that is the case, we
respect `WebLocalFrameLoaderClient` for the UA string even in the
presence of a site-specific quirk.

This commit also adds a new test case to exercise this change in the
`WebpagePreferences` API test suite, as well as refactoring some code in
said test file for more sane UA constants management.

* Source/WebCore/loader/FrameLoader.cpp:
(WebCore::FrameLoader::userAgent const):
* Source/WebCore/loader/LocalFrameLoaderClient.h:
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setUserAgent):
(WebKit::WebPageProxy::setCustomUserAgent):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.cpp:
(WebKit::WebLocalFrameLoaderClient::hasCustomUserAgent const):
* Source/WebKit/WebProcess/WebCoreSupport/WebLocalFrameLoaderClient.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setHasCustomUserAgent):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::hasCustomUserAgent const):
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
(-[CustomUserAgentDelegate _webView:decidePolicyForNavigationAction:preferences:userInfo:decisionHandler:]):
(-[CustomJavaScriptUserAgentDelegate webView:decidePolicyForNavigationAction:preferences:decisionHandler:]):

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




More information about the webkit-changes mailing list