Skip to content

Commit

Permalink
REGRESSION (273393@main): Elevated CPU use in UIProcess and NetworkPr…
Browse files Browse the repository at this point in the history
…ocess due to always sending resource load messages to UIProcess.

https://webkit.org/b/273582
rdar://127380142

Reviewed by Brian Weinstein.

Only send the resource messages if the page has loaded extensions, not just an extension controller.
The NetworkResourceLoadParameters are sent over for each scheduled load, so it is always accurate.
Renamed the struct field from pageHasExtensionController to pageHasLoadedWebExtensions.

* Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.cpp:
(WebKit::NetworkResourceLoadParameters::NetworkResourceLoadParameters):
* Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h:
* Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.serialization.in:
* Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::shouldSendResourceLoadMessages const):
* Source/WebKit/WebProcess/Extensions/WebExtensionControllerProxy.h:
* Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::addParametersShared):

Canonical link: https://commits.webkit.org/278248@main
  • Loading branch information
xeenon committed May 2, 2024
1 parent 7a4bc6f commit 75ca801
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ NetworkResourceLoadParameters::NetworkResourceLoadParameters(
, std::optional<UserContentControllerIdentifier> userContentControllerIdentifier
#endif
#if ENABLE(WK_WEB_EXTENSIONS)
, bool pageHasExtensionController
, bool pageHasLoadedWebExtensions
#endif
, bool linkPreconnectEarlyHintsEnabled
, bool shouldRecordFrameLoadForStorageAccess
Expand Down Expand Up @@ -109,7 +109,7 @@ NetworkResourceLoadParameters::NetworkResourceLoadParameters(
, userContentControllerIdentifier(userContentControllerIdentifier)
#endif
#if ENABLE(WK_WEB_EXTENSIONS)
, pageHasExtensionController(pageHasExtensionController)
, pageHasLoadedWebExtensions(pageHasLoadedWebExtensions)
#endif
, linkPreconnectEarlyHintsEnabled(linkPreconnectEarlyHintsEnabled)
, shouldRecordFrameLoadForStorageAccess(shouldRecordFrameLoadForStorageAccess)
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/NetworkProcess/NetworkResourceLoadParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class NetworkResourceLoadParameters : public NetworkLoadParameters {
, std::optional<UserContentControllerIdentifier>
#endif
#if ENABLE(WK_WEB_EXTENSIONS)
, bool pageHasExtensionController
, bool pageHasLoadedWebExtensions
#endif
, bool linkPreconnectEarlyHintsEnabled
, bool shouldRecordFrameLoadForStorageAccess
Expand Down Expand Up @@ -138,7 +138,7 @@ class NetworkResourceLoadParameters : public NetworkLoadParameters {
#endif

#if ENABLE(WK_WEB_EXTENSIONS)
bool pageHasExtensionController { false };
bool pageHasLoadedWebExtensions { false };
#endif

bool linkPreconnectEarlyHintsEnabled { false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class WebKit::NetworkResourceLoadParameters : WebKit::NetworkLoadParameters {
#endif

#if ENABLE(WK_WEB_EXTENSIONS)
bool pageHasExtensionController;
bool pageHasLoadedWebExtensions;
#endif

bool linkPreconnectEarlyHintsEnabled;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ bool NetworkResourceLoader::shouldSendResourceLoadMessages() const
return true;

#if ENABLE(WK_WEB_EXTENSIONS)
if (m_parameters.pageHasExtensionController)
if (m_parameters.pageHasLoadedWebExtensions)
return true;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class WebExtensionControllerProxy final : public RefCounted<WebExtensionControll
void didFailLoadForFrame(WebPage&, WebFrame&, const URL&);

RefPtr<WebExtensionContextProxy> extensionContext(const String& uniqueIdentifier) const;
RefPtr<WebExtensionContextProxy> extensionContext(const URL&) const;
RefPtr<WebExtensionContextProxy> extensionContext(WebFrame&, WebCore::DOMWrapperWorld&) const;

bool hasLoadedContexts() const { return !m_extensionContexts.isEmpty(); }
const WebExtensionContextProxySet& extensionContexts() const { return m_extensionContexts; }
#endif

private:
Expand All @@ -84,12 +89,6 @@ class WebExtensionControllerProxy final : public RefCounted<WebExtensionControll
#if PLATFORM(COCOA)
void load(const WebExtensionContextParameters&);
void unload(WebExtensionContextIdentifier);

RefPtr<WebExtensionContextProxy> extensionContext(const URL&) const;
RefPtr<WebExtensionContextProxy> extensionContext(WebFrame&, WebCore::DOMWrapperWorld&) const;

bool hasLoadedContexts() const { return !m_extensionContexts.isEmpty(); }
const WebExtensionContextProxySet& extensionContexts() const { return m_extensionContexts; }
#endif

WebExtensionControllerIdentifier m_identifier;
Expand Down
10 changes: 8 additions & 2 deletions Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
#include <WebCore/QuickLook.h>
#endif

#if ENABLE(WK_WEB_EXTENSIONS)
#include "WebExtensionControllerProxy.h"
#endif

#define WEBLOADERSTRATEGY_RELEASE_LOG_BASIC(fmt, ...) RELEASE_LOG(Network, "%p - WebLoaderStrategy::" fmt, this, ##__VA_ARGS__)
#define WEBLOADERSTRATEGY_RELEASE_LOG_ERROR_BASIC(fmt, ...) RELEASE_LOG_ERROR(Network, "%p - WebLoaderStrategy::" fmt, this, ##__VA_ARGS__)

Expand Down Expand Up @@ -340,8 +344,10 @@ static void addParametersShared(const LocalFrame* frame, NetworkResourceLoadPara
page->logMediaDiagnosticMessage(parameters.request.httpBody());

#if ENABLE(WK_WEB_EXTENSIONS)
if (auto* webPage = WebPage::fromCorePage(*page))
parameters.pageHasExtensionController = webPage->webExtensionControllerProxy();
if (RefPtr webPage = WebPage::fromCorePage(*page)) {
if (RefPtr extensionControllerProxy = webPage->webExtensionControllerProxy())
parameters.pageHasLoadedWebExtensions = extensionControllerProxy->hasLoadedContexts();
}
#endif
}

Expand Down

0 comments on commit 75ca801

Please sign in to comment.