Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Web Extension support for loading images and parsing
icons
, `ac…
…tion`, `browser_action`, and `page_action`. https://bugs.webkit.org/show_bug.cgi?id=246168 Reviewed by Brian Weinstein. Added support for loading and validating resources from the extension. This is now used for loading the manifest.json file and also icons. The icons are generated using the platform's image class. On macOS the 1x and 2x sizes are retrieved and put into a single NSImage. On iOS the largest scale factor is used based on the main UIScreen scale. SVG images are also supported via some SPIs. This loading mechanism is now also used for the special "_generated_background_page.html" path. It will also be used to load content scripts and stylesheets for injected content. * Source/WTF/wtf/PlatformUse.h: Added USE_NSIMAGE_FOR_SVG_SUPPORT define. * Source/WTF/wtf/spi/cocoa/SecuritySPI.h: Added SecCodeValidateFileResource. * Source/WebCore/PAL/pal/spi/mac/NSImageSPI.h: Added _NSSVGImageRep class. * Source/WebCore/en.lproj/Localizable.strings: Updated with update-webkit-localizable-strings. * Source/WebCore/platform/LocalizedStrings.h: Exported formatLocalizedString to use in WebKit. * Source/WebKit/Platform/spi/Cocoa/CoreSVGSPI.h: Added. * Source/WebKit/Platform/spi/Cocoa/FoundationSPI.h: Added. * Source/WebKit/Platform/spi/ios/UIKitSPI.h: Added _imageWithCGSVGDocument: method to UIImage. * Source/WebKit/UIProcess/API/Cocoa/_WKWebExtension.h: Simplify the exposed enum values for _WKWebExtensionError to reduce API surface and stay nimble. * Source/WebKit/UIProcess/API/Cocoa/_WKWebExtension.mm: (-[_WKWebExtension _initWithManifestDictionary:]): (-[_WKWebExtension _initWithManifestDictionary:resources:]): Added. (-[_WKWebExtension _initWithResources:]): Renamed from _initWithManifestData:. (-[_WKWebExtension displayActionLabel]): Added. (-[_WKWebExtension iconForSize:]): Added. (-[_WKWebExtension actionIconForSize:]): Added. * Source/WebKit/UIProcess/API/Cocoa/_WKWebExtensionPrivate.h: * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm: (WebKit::WebExtension::WebExtension): (WebKit::WebExtension::manifest): (WebKit::WebExtension::bundleStaticCode): Added. (WebKit::WebExtension::validateResourceData): Added. (WebKit::WebExtension::resourceFileURLForPath): Added. (WebKit::WebExtension::resourceDataForPath): Added. (WebKit::WebExtension::createError): Tweaked strings and API enum values used. (WebKit::WebExtension::errors): Call populateActionPropertiesIfNeeded. (WebKit::WebExtension::icon): Added. (WebKit::WebExtension::actionIcon): Added. (WebKit::WebExtension::displayActionLabel): Added. (WebKit::WebExtension::actionPopupPath): Added. (WebKit::WebExtension::populateActionPropertiesIfNeeded): Added. (WebKit::WebExtension::imageForPath): Added. (WebKit::WebExtension::pathForBestImageInIconsDictionary): Added. (WebKit::WebExtension::bestImageInIconsDictionary): Added. (WebKit::WebExtension::bestImageForIconsDictionaryManifestKey): Added. * Source/WebKit/UIProcess/Extensions/WebExtension.h: * Source/WebKit/WebKit.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtension.mm: Added ActionParsing test and tweaks error enum names. Canonical link: https://commits.webkit.org/255284@main
- Loading branch information
Showing
15 changed files
with
811 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if USE(APPLE_INTERNAL_SDK) | ||
|
||
#include <CoreSVG/CGSVGDocument.h> | ||
|
||
#else | ||
|
||
WTF_EXTERN_C_BEGIN | ||
|
||
typedef struct CGSVGDocument *CGSVGDocumentRef; | ||
|
||
CGSVGDocumentRef CGSVGDocumentCreateFromData(CFDataRef, CFDictionaryRef); | ||
void CGSVGDocumentRelease(CGSVGDocumentRef); | ||
|
||
WTF_EXTERN_C_END | ||
|
||
#endif // USE(APPLE_INTERNAL_SDK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2022 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#if USE(APPLE_INTERNAL_SDK) | ||
|
||
#include <Foundation/NSPrivateDecls.h> | ||
|
||
#else | ||
|
||
@interface NSBundle () | ||
- (CFBundleRef)_cfBundle; | ||
@end | ||
|
||
#endif // USE(APPLE_INTERNAL_SDK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.