Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 1c19ff8379e1fa2a96799943e6d0e6b503f66ffa
https://github.com/WebKit/WebKit/commit/1c19ff8379e1fa2a96799943e6d0e6b503f66ffa
Author: Sihui Liu <[email protected]>
Date: 2026-04-28 (Tue, 28 Apr 2026)
Changed paths:
M Source/WebKit/Shared/WebsiteData/WebsiteDataFetchOption.h
M Source/WebKit/Shared/WebsiteData/WebsiteDataFetchOption.serialization.in
M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm
M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionControllerCocoa.mm
M Source/WebKit/UIProcess/Extensions/WebExtensionContext.h
M Source/WebKit/UIProcess/Extensions/WebExtensionController.cpp
M Source/WebKit/UIProcess/Extensions/WebExtensionController.h
M Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp
M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/IPCTestingAPI.mm
M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIScripting.mm
Log Message:
-----------
Clean up stale web extension origin data after migration
https://bugs.webkit.org/show_bug.cgi?id=313295
rdar://175484888
Reviewed by Timothy Hatcher.
Each time a web extension loads, it gets a new unique base URL (e.g.
webkit-extension://<new-uuid>/).
moveLocalStorageIfNeeded renames localStorage and IndexedDB from the old origin
to the new one, but leaves behind all
other data (service worker registrations, DOM cache, etc.) for the old origin.
Over time these stale origins accumulate
and slow down storage initialization, as NetworkStorageManager::getAllOrigins
must traverse every origin directory.
This patch makes two changes:
1. After renaming localStorage/IndexedDB, delete all remaining website data for
the previous origin so no stale data
accumulates going forward.
2. On the first extension load per controller lifetime, fetch all origins from
the data store, identify any web
extension origins that don't belong to a currently loaded extension, and remove
them. This cleans up stale origins that
accumulated before the going-forward fix.
To support this, add a new WebsiteDataFetchOption::IncludeAllOrigins that
bypasses the displayNameForOrigin filter in
WebsiteDataStore::fetchDataAndApply, which otherwise silently drops origins
with custom URL schemes like
safari-web-extension://.
Also, update moveLocalStorageIfNeeded return early when there is no previous
base URL -- this helps avoid round-trip IPC
to network process when migration will not happen and it is needed to avoid
crash in removeWebsiteDataForOrigin. With
this change, update
TestWebKitAPI.WKWebExtensionAPIScripting.MigrateScriptDataToNewFormat test to
copy the old-format
database files before loading the extension, since moveLocalStorageIfNeeded now
completes synchronously when there is no
previous base URL, changing the timing of loading scripts.
* Source/WebKit/Shared/WebsiteData/WebsiteDataFetchOption.h:
* Source/WebKit/Shared/WebsiteData/WebsiteDataFetchOption.serialization.in:
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm:
(WebKit::WebExtensionContext::load):
(WebKit::WebExtensionContext::moveLocalStorageIfNeeded):
(WebKit::allWebsiteDataTypes):
(WebKit::WebExtensionContext::removeWebsiteDataForOrigin):
(WebKit::WebExtensionContext::removeStaleExtensionWebsiteData):
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionControllerCocoa.mm:
(WebKit::WebExtensionController::activeExtensionURLs const):
* Source/WebKit/UIProcess/Extensions/WebExtensionContext.h:
* Source/WebKit/UIProcess/Extensions/WebExtensionController.cpp:
(WebKit::WebExtensionController::markDidRemoveStaleExtensionWebsiteData):
* Source/WebKit/UIProcess/Extensions/WebExtensionController.h:
* Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::fetchDataAndApply):
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/IPCTestingAPI.mm:
(SerializedTypeInfo)):
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/WKWebExtensionAPIScripting.mm:
(TestWebKitAPI::TEST(WKWebExtensionAPIScripting, MigrateScriptDataToNewFormat)):
Canonical link: https://commits.webkit.org/312231@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications