Skip to content

Commit dbad0ee

Browse files
[WebInspector] minimize the number of data kept in m_requestIdToResourceDataMap after content eviction
https://bugs.webkit.org/show_bug.cgi?id=290161 Reviewed by Devin Rousso. After eviction of the content of the resource data due to exceeding the threshold for maximum memory usage for gathered resources, WebKit still keeps the structure of resource data in `m_requestIdToResourceDataMap` because it is the primary structure used to track all other metadata used by Web Inspector. We can minimize the data kept there after eviction by resetting the decoder which is not needed if we remove the content of resource data. Additionally in case of platforms different than Cocoa we can skip storing the certificate info because it is not used. The certificate info is used only if supportsShowCertificate(), which is true only in case of Cocoa platform. This change adds a web preference `InspectorSupportsShowingCertificate` which is true only in case of Cocoa and Win platform and enabling storing of the certificate info for resource data in Web Inspector. * Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml: * Source/WebCore/inspector/InspectorFrontendHost.cpp: (WebCore::InspectorFrontendHost::supportsShowCertificate const): * Source/WebCore/inspector/NetworkResourcesData.cpp: (WebCore::NetworkResourcesData::ResourceData::evictContent): (WebCore::NetworkResourcesData::NetworkResourcesData): (WebCore::NetworkResourcesData::responseReceived): (WebCore::NetworkResourcesData::setResourceContent): (WebCore::NetworkResourcesData::maybeAddResourceData): (WebCore::NetworkResourcesData::maybeDecodeDataToContent): (WebCore::NetworkResourcesData::ensureFreeSpace): * Source/WebCore/inspector/NetworkResourcesData.h: (WebCore::NetworkResourcesData::Settings::Settings): * Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp: (WebCore::InspectorNetworkAgent::InspectorNetworkAgent): * Source/WebCore/inspector/agents/InspectorNetworkAgent.h: * Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp: (WebCore::PageNetworkAgent::PageNetworkAgent): * Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.cpp: (WebCore::WorkerNetworkAgent::WorkerNetworkAgent): Canonical link: https://commits.webkit.org/293535@main
1 parent 7278d48 commit dbad0ee

8 files changed

Lines changed: 46 additions & 28 deletions

File tree

Source/WTF/Scripts/Preferences/WebPreferences.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,19 @@ InspectorStartsAttached:
10211021
WebKit:
10221022
default: true
10231023

1024+
InspectorSupportsShowingCertificate:
1025+
type: bool
1026+
status: embedder
1027+
defaultValue:
1028+
WebKitLegacy:
1029+
default: false
1030+
WebKit:
1031+
"PLATFORM(COCOA) || PLATFORM(WIN)": true
1032+
default: false
1033+
WebCore:
1034+
"PLATFORM(COCOA) || PLATFORM(WIN)": true
1035+
default: false
1036+
10241037
InspectorWindowFrame:
10251038
type: String
10261039
webcoreBinding: none

Source/WebCore/inspector/InspectorFrontendHost.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -634,11 +634,7 @@ void InspectorFrontendHost::setAllowsInspectingInspector(bool allow)
634634

635635
bool InspectorFrontendHost::supportsShowCertificate() const
636636
{
637-
#if PLATFORM(COCOA)
638-
return true;
639-
#else
640-
return false;
641-
#endif
637+
return m_frontendPage->settings().inspectorSupportsShowingCertificate();
642638
}
643639

644640
bool InspectorFrontendHost::showCertificate(const String& serializedCertificate)

Source/WebCore/inspector/NetworkResourcesData.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ namespace WebCore {
4040

4141
using namespace Inspector;
4242

43-
static const unsigned maximumSingleResourceContentSizeMB = 50; // 50MB
44-
4543
NetworkResourcesData::ResourceData::ResourceData(const String& requestId, const String& loaderId)
4644
: m_requestId(requestId)
4745
, m_loaderId(loaderId)
@@ -76,6 +74,7 @@ unsigned NetworkResourcesData::ResourceData::removeContent()
7674
unsigned NetworkResourcesData::ResourceData::evictContent()
7775
{
7876
m_isContentEvicted = true;
77+
setDecoder(nullptr);
7978
return removeContent();
8079
}
8180

@@ -113,9 +112,8 @@ void NetworkResourcesData::ResourceData::decodeDataToContent()
113112
ASSERT(m_content.sizeInBytes() >= buffer->size());
114113
}
115114

116-
NetworkResourcesData::NetworkResourcesData(uint32_t maximumResourcesContentSize)
117-
: m_maximumResourcesContentSize(maximumResourcesContentSize * MB)
118-
, m_maximumSingleResourceContentSize(maximumSingleResourceContentSizeMB * MB)
115+
NetworkResourcesData::NetworkResourcesData(const Settings& settings)
116+
: m_settings(settings)
119117
{
120118
}
121119

@@ -160,8 +158,10 @@ void NetworkResourcesData::responseReceived(const String& requestId, const Strin
160158
if (InspectorNetworkAgent::shouldTreatAsText(response.mimeType()))
161159
resourceData->setDecoder(InspectorNetworkAgent::createTextDecoder(response.mimeType(), response.textEncodingName()));
162160

163-
if (auto& certificateInfo = response.certificateInfo())
164-
resourceData->setCertificateInfo(certificateInfo);
161+
if (m_settings.supportsShowingCertificate) {
162+
if (auto& certificateInfo = response.certificateInfo())
163+
resourceData->setCertificateInfo(certificateInfo);
164+
}
165165
}
166166

167167
void NetworkResourcesData::setResourceType(const String& requestId, InspectorPageAgent::ResourceType type)
@@ -190,7 +190,7 @@ void NetworkResourcesData::setResourceContent(const String& requestId, const Str
190190
return;
191191

192192
size_t dataLength = content.sizeInBytes();
193-
if (dataLength > m_maximumSingleResourceContentSize)
193+
if (dataLength > m_settings.maximumSingleResourceContentSize)
194194
return;
195195
if (resourceData->isContentEvicted())
196196
return;
@@ -229,7 +229,7 @@ NetworkResourcesData::ResourceData const* NetworkResourcesData::maybeAddResource
229229
if (!shouldBufferResourceData(*resourceData))
230230
return resourceData;
231231

232-
if (resourceData->dataLength() + data.size() > m_maximumSingleResourceContentSize)
232+
if (resourceData->dataLength() + data.size() > m_settings.maximumSingleResourceContentSize)
233233
m_contentSize -= resourceData->evictContent();
234234
if (resourceData->isContentEvicted())
235235
return resourceData;
@@ -257,7 +257,7 @@ void NetworkResourcesData::maybeDecodeDataToContent(const String& requestId)
257257

258258
resourceData->decodeDataToContent();
259259
byteCount = resourceData->content().sizeInBytes();
260-
if (byteCount > m_maximumSingleResourceContentSize) {
260+
if (byteCount > m_settings.maximumSingleResourceContentSize) {
261261
resourceData->evictContent();
262262
return;
263263
}
@@ -365,11 +365,11 @@ void NetworkResourcesData::ensureNoDataForRequestId(const String& requestId)
365365

366366
bool NetworkResourcesData::ensureFreeSpace(size_t size)
367367
{
368-
if (size > m_maximumResourcesContentSize)
368+
if (size > m_settings.maximumResourcesContentSize)
369369
return false;
370370

371-
ASSERT(m_maximumResourcesContentSize >= m_contentSize);
372-
while (size > m_maximumResourcesContentSize - m_contentSize) {
371+
ASSERT(m_settings.maximumResourcesContentSize >= m_contentSize);
372+
while (size > m_settings.maximumResourcesContentSize - m_contentSize) {
373373
String requestId = m_requestIdsDeque.takeFirst();
374374
ResourceData* resourceData = resourceDataForRequestId(requestId);
375375
if (resourceData)

Source/WebCore/inspector/NetworkResourcesData.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "InspectorPageAgent.h"
3333
#include "SharedBuffer.h"
34+
#include "TextResourceDecoder.h"
3435
#include <wtf/ListHashSet.h>
3536
#include <wtf/RobinHoodHashMap.h>
3637
#include <wtf/WallTime.h>
@@ -40,7 +41,6 @@ namespace WebCore {
4041

4142
class CachedResource;
4243
class ResourceResponse;
43-
class TextResourceDecoder;
4444

4545
class NetworkResourcesData {
4646
WTF_MAKE_FAST_ALLOCATED;
@@ -132,7 +132,17 @@ class NetworkResourcesData {
132132
WallTime m_responseTimestamp;
133133
};
134134

135-
NetworkResourcesData(uint32_t maximumResourcesContentSize);
135+
struct Settings {
136+
Settings(size_t maxResourcesContentSize, bool showingCertificate)
137+
: maximumResourcesContentSize(maxResourcesContentSize * MB)
138+
, supportsShowingCertificate(showingCertificate)
139+
{ }
140+
size_t maximumResourcesContentSize;
141+
size_t maximumSingleResourceContentSize { 50 * MB };
142+
bool supportsShowingCertificate;
143+
};
144+
145+
NetworkResourcesData(const Settings&);
136146
~NetworkResourcesData();
137147

138148
void resourceCreated(const String& requestId, const String& loaderId, InspectorPageAgent::ResourceType);
@@ -159,8 +169,7 @@ class NetworkResourcesData {
159169
ListHashSet<String> m_requestIdsDeque;
160170
MemoryCompactRobinHoodHashMap<String, std::unique_ptr<ResourceData>> m_requestIdToResourceDataMap;
161171
size_t m_contentSize { 0 };
162-
size_t m_maximumResourcesContentSize;
163-
size_t m_maximumSingleResourceContentSize;
172+
Settings m_settings;
164173
};
165174

166175
} // namespace WebCore

Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include "LoaderStrategy.h"
5858
#include "MIMETypeRegistry.h"
5959
#include "MemoryCache.h"
60-
#include "NetworkResourcesData.h"
6160
#include "Page.h"
6261
#include "PlatformStrategies.h"
6362
#include "ProgressTracker.h"
@@ -180,12 +179,12 @@ Ref<Protocol::Network::WebSocketFrame> buildWebSocketMessage(const WebSocketFram
180179

181180
} // namespace
182181

183-
InspectorNetworkAgent::InspectorNetworkAgent(WebAgentContext& context, uint32_t maximumResourcesContentSize)
182+
InspectorNetworkAgent::InspectorNetworkAgent(WebAgentContext& context, const NetworkResourcesData::Settings& networkResourcesDataSettings)
184183
: InspectorAgentBase("Network"_s, context)
185184
, m_frontendDispatcher(makeUnique<Inspector::NetworkFrontendDispatcher>(context.frontendRouter))
186185
, m_backendDispatcher(Inspector::NetworkBackendDispatcher::create(context.backendDispatcher, this))
187186
, m_injectedScriptManager(context.injectedScriptManager)
188-
, m_resourcesData(makeUnique<NetworkResourcesData>(maximumResourcesContentSize))
187+
, m_resourcesData(makeUnique<NetworkResourcesData>(networkResourcesDataSettings))
189188
{
190189
}
191190

Source/WebCore/inspector/agents/InspectorNetworkAgent.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "InspectorInstrumentation.h"
3535
#include "InspectorPageAgent.h"
3636
#include "InspectorWebAgentBase.h"
37+
#include "NetworkResourcesData.h"
3738
#include "WebSocket.h"
3839
#include <JavaScriptCore/InspectorBackendDispatchers.h>
3940
#include <JavaScriptCore/InspectorFrontendDispatchers.h>
@@ -137,7 +138,7 @@ class InspectorNetworkAgent : public InspectorAgentBase, public Inspector::Netwo
137138
void searchInRequest(Inspector::Protocol::ErrorString&, const Inspector::Protocol::Network::RequestId&, const String& query, bool caseSensitive, bool isRegex, RefPtr<JSON::ArrayOf<Inspector::Protocol::GenericTypes::SearchMatch>>&);
138139

139140
protected:
140-
InspectorNetworkAgent(WebAgentContext&, uint32_t);
141+
InspectorNetworkAgent(WebAgentContext&, const NetworkResourcesData::Settings&);
141142

142143
virtual Inspector::Protocol::Network::LoaderId loaderIdentifier(DocumentLoader*) = 0;
143144
virtual Inspector::Protocol::Network::FrameId frameIdentifier(DocumentLoader*) = 0;

Source/WebCore/inspector/agents/page/PageNetworkAgent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace WebCore {
4242
using namespace Inspector;
4343

4444
PageNetworkAgent::PageNetworkAgent(PageAgentContext& context, InspectorClient* client)
45-
: InspectorNetworkAgent(context, context.inspectedPage.settings().inspectorMaximumResourcesContentSize())
45+
: InspectorNetworkAgent(context, { context.inspectedPage.settings().inspectorMaximumResourcesContentSize(), context.inspectedPage.settings().inspectorSupportsShowingCertificate() })
4646
, m_inspectedPage(context.inspectedPage)
4747
, m_client(client)
4848
{

Source/WebCore/inspector/agents/worker/WorkerNetworkAgent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace WebCore {
3636
using namespace Inspector;
3737

3838
WorkerNetworkAgent::WorkerNetworkAgent(WorkerAgentContext& context)
39-
: InspectorNetworkAgent(context, context.globalScope.settingsValues().inspectorMaximumResourcesContentSize)
39+
: InspectorNetworkAgent(context, { context.globalScope.settingsValues().inspectorMaximumResourcesContentSize, context.globalScope.settingsValues().inspectorSupportsShowingCertificate })
4040
, m_globalScope(context.globalScope)
4141
{
4242
ASSERT(context.globalScope.isContextThread());

0 commit comments

Comments
 (0)