Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for icon_variants in Web Extensions.
https://webkit.org/b/278818 rdar://problem/134885372 Reviewed by NOBODY (OOPS!). Add support for `icon_variants` manifest parsing under the `WK_WEB_EXTENSIONS_ICON_VARIANTS` flag, with optimizations to ensure efficient icon loading. This change introduces `icon_variants` manifest parsing, explicitly supporting different icon sets, such as dark mode icons. To achieve this efficiently, icons are now cached by size, reducing disk I/O by avoiding repeated loads when the browser frequently requests the same icon. The cache is automatically invalidated when device scales change, such as when connecting or disconnecting a display with a different scale factor. Only the necessary icons are loaded based on the specific scale factor of all screens, halving the image loads compared to previous behavior. This ensures that even as more extensions adopt dark mode icons, typical image loads remain at two images (light and dark). Proposal: https://github.com/w3c/webextensions/blob/main/proposals/dark_mode_extension_icons.md WECG issue: w3c/webextensions#229 * Source/WTF/wtf/PlatformEnableCocoa.h: Added ENABLE_WK_WEB_EXTENSIONS_ICON_VARIANTS. * Source/WebCore/en.lproj/Localizable.strings: Updated. * Source/WebKit/Platform/cocoa/CocoaHelpers.h: * Source/WebKit/Platform/cocoa/CocoaHelpers.mm: (WebKit::availableScreenScales): Added. (WebKit::largestDisplayScale): Added. * Source/WebKit/Platform/spi/ios/UIKitSPI.h: * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionActionCocoa.mm: (WebKit::WebExtensionAction::icon): * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm: (WebKit::WebExtension::icon): (WebKit::WebExtension::actionIcon): (WebKit::WebExtension::populateActionPropertiesIfNeeded): (WebKit::WebExtension::populateSidebarActionProperties): (WebKit::WebExtension::populateSidePanelProperties): (WebKit::WebExtension::imageForPath): (WebKit::WebExtension::bestSizeInIconsDictionary): Added. (WebKit::WebExtension::pathForBestImageInIconsDictionary): (WebKit::WebExtension::bestImageInIconsDictionary): (WebKit::WebExtension::bestImageForIconsDictionaryManifestKey): (WebKit::toColorSchemes): Added. (WebKit::WebExtension::iconsDictionaryForBestIconVariant): Added. (WebKit::WebExtension::bestImageForIconVariants): Added. (WebKit::WebExtension::bestImageForIconVariantsManifestKey): Added. * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionMenuItemCocoa.mm: (WebKit::WebExtensionMenuItem::icon const): * Source/WebKit/UIProcess/Extensions/WebExtension.h: * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtension.mm: (TestWebKitAPI::TEST(WKWebExtension, MultipleIconVariants)): Added. (TestWebKitAPI::TEST(WKWebExtension, SingleIconVariant)): Added. (TestWebKitAPI::TEST(WKWebExtension, AnySizeIconVariant)): Added. (TestWebKitAPI::TEST(WKWebExtension, NoIconVariants)): Added. (TestWebKitAPI::TEST(WKWebExtension, IconsAndIconVariantsSpecified)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionIconVariantsMultiple)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionIconSingleVariant)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionIconAnySizeVariant)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionNoIconVariants)): Added. (TestWebKitAPI::TEST(WKWebExtension, ActionIconsAndIconVariantsSpecified)): Added. * Tools/TestWebKitAPI/cocoa/WebExtensionUtilities.h: * Tools/TestWebKitAPI/cocoa/WebExtensionUtilities.mm: (TestWebKitAPI::Util::performWithAppearance): Added. (TestWebKitAPI::Util::pixelColor): Added. (TestWebKitAPI::Util::toSRGBColor): Added. (TestWebKitAPI::Util::compareColors): Added.
- Loading branch information