Changeset 286073 in webkit
- Timestamp:
- Nov 19, 2021, 1:20:53 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/Modules/applicationmanifest/ApplicationManifest.h (modified) (2 diffs)
-
Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp (modified) (2 diffs)
-
Source/WebKit/ChangeLog (modified) (1 diff)
-
Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.h (modified) (3 diffs)
-
Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.mm (modified) (6 diffs)
-
Tools/ChangeLog (modified) (1 diff)
-
Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp (modified) (3 diffs)
-
Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplicationManifest.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r286068 r286073 1 2021-11-19 Brent Fulgham <bfulgham@apple.com> 2 3 Add support for web app manifest icons in WebKit/UI Process layer 4 https://bugs.webkit.org/show_bug.cgi?id=233350 5 <rdar://problem/84311569> 6 7 Reviewed by Chris Dumez. 8 9 This patch builds on the work in Bug 231339 and threads the new icons 10 feature through the WebKit layer. 11 12 This change modifies the parser to represent the 'sizes' member of the 13 icon as an array of strings, rather than a single string containing the 14 sizes as a set of space-separated items. This more closesly matches the 15 behavior of the WebKit API layer. 16 17 Tested by TestWebKitAPI. 18 19 * Modules/applicationmanifest/ApplicationManifest.h: 20 * Modules/applicationmanifest/ApplicationManifestParser.cpp: 21 (WebCore::ApplicationManifestParser::parseIcons): 22 1 23 2021-11-19 Antoine Quint <graouts@webkit.org> 2 24 -
trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifest.h
r285645 r286073 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 51 51 52 52 URL src; 53 Stringsizes;53 Vector<String> sizes; 54 54 String type; 55 55 OptionSet<Purpose> purposes; -
trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp
r285645 r286073 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 214 214 currentIcon.src = srcURL; 215 215 216 currentIcon.sizes = parseGenericString(iconJSON, "sizes"_s) ;216 currentIcon.sizes = parseGenericString(iconJSON, "sizes"_s).split(' '); 217 217 218 218 currentIcon.type = parseGenericString(iconJSON, "type"_s); -
trunk/Source/WebKit/ChangeLog
r286071 r286073 1 2021-11-19 Brent Fulgham <bfulgham@apple.com> 2 3 Add support for web app manifest icons in WebKit/UI Process layer 4 https://bugs.webkit.org/show_bug.cgi?id=233350 5 <rdar://problem/84311569> 6 7 Reviewed by Chris Dumez. 8 9 This patch builds on the work in Bug 231339 and threads the new icons 10 feature through the WebKit layer. 11 12 Note: This change also moves the implementation of _WKApplicationManifestIcon 13 earlier in the file since the implementation is needed for proper serialization 14 of the _WKApplicationManifest. 15 16 Tested by TestWebKitAPI (ApplicationManifest.Icons) test. 17 18 * UIProcess/API/Cocoa/_WKApplicationManifest.h: 19 * UIProcess/API/Cocoa/_WKApplicationManifest.mm: 20 (fromPurposes): New helper function. 21 (makeVectorElement): Ditto. 22 (-[_WKApplicationManifestIcon initWithCoder:]): Updated to call proper 23 serialization methods. 24 (-[_WKApplicationManifestIcon initWithCoreIcon:]): Added. 25 (-[_WKApplicationManifest initWithCoder:]): Updated to properly handle 26 serializing the object. 27 (-[_WKApplicationManifest icons]): Added. 28 1 29 2021-11-19 Per Arne <pvollan@apple.com> 2 30 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.h
r285645 r286073 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 58 58 @property (nonatomic, readonly, copy) NSURL *startURL; 59 59 @property (nonatomic, readonly) _WKApplicationManifestDisplayMode displayMode; 60 @property (nonatomic, readonly ) NSArray<_WKApplicationManifestIcon *> *icons WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));60 @property (nonatomic, readonly, copy) NSArray<_WKApplicationManifestIcon *> *icons WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 61 61 62 62 #if TARGET_OS_IPHONE … … 72 72 WK_CLASS_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)) 73 73 @interface _WKApplicationManifestIcon : NSObject <NSSecureCoding> 74 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959 74 75 @property (nonatomic, readonly, copy) NSURL *src; 76 @property (nonatomic, readonly, copy) NSArray<NSString *> *sizes; 77 @property (nonatomic, readonly, copy) NSString *type; 78 @property (nonatomic, readonly) NSArray<NSNumber *> *purposes; 79 75 80 @end 76 81 -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKApplicationManifest.mm
r285645 r286073 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 33 33 #import <WebCore/ColorCocoa.h> 34 34 #import <WebCore/WebCoreObjCExtras.h> 35 #import <wtf/cocoa/VectorCocoa.h> 35 36 36 37 #if PLATFORM(IOS_FAMILY) … … 42 43 #endif 43 44 45 static OptionSet<WebCore::ApplicationManifest::Icon::Purpose> fromPurposes(NSArray<NSNumber *> *purposes) 46 { 47 OptionSet<WebCore::ApplicationManifest::Icon::Purpose> purposeSet; 48 for (NSNumber *purposeNumber in purposes) { 49 auto purpose = static_cast<WebCore::ApplicationManifest::Icon::Purpose>(purposeNumber.integerValue); 50 purposeSet.add(purpose); 51 } 52 53 return purposeSet; 54 } 55 56 static RetainPtr<NSArray<NSNumber *>> fromPurposes(OptionSet<WebCore::ApplicationManifest::Icon::Purpose> purposes) 57 { 58 auto purposeArray = adoptNS([[NSMutableArray alloc] init]); 59 for (auto purpose : purposes) 60 [purposeArray addObject:[NSNumber numberWithUnsignedChar:static_cast<std::underlying_type<WebCore::ApplicationManifest::Icon::Purpose>::type>(purpose)]]; 61 return purposeArray; 62 } 63 44 64 static std::optional<WebCore::ApplicationManifest::Icon> makeVectorElement(const WebCore::ApplicationManifest::Icon*, id arrayElement) 45 65 { 46 47 66 if (![arrayElement isKindOfClass: _WKApplicationManifestIcon.class]) 48 67 return std::nullopt; 49 68 69 auto icon = dynamic_objc_cast<_WKApplicationManifestIcon>(arrayElement); 70 if (!icon) 71 return std::nullopt; 72 50 73 return WebCore::ApplicationManifest::Icon { 51 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959 74 icon.src, 75 makeVector<String>(icon.sizes), 76 icon.type, 77 fromPurposes(icon.purposes) 52 78 }; 53 79 } 54 80 81 @implementation _WKApplicationManifestIcon 82 83 + (BOOL)supportsSecureCoding 84 { 85 return YES; 86 } 87 88 - (instancetype)initWithCoder:(NSCoder *)coder 89 { 90 if (!(self = [self init])) 91 return nil; 92 93 _src = [[coder decodeObjectOfClass:[NSString class] forKey:@"src"] copy]; 94 _sizes = [[coder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [NSString class]]] forKey:@"sizes"] copy]; 95 _type = [[coder decodeObjectOfClass:[NSString class] forKey:@"type"] copy]; 96 _purposes = [[coder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [NSString class]]] forKey:@"purposes"] copy]; 97 98 return self; 99 } 100 101 - (instancetype)initWithCoreIcon:(const WebCore::ApplicationManifest::Icon *)icon 102 { 103 if (!(self = [[_WKApplicationManifestIcon alloc] init])) 104 return nil; 105 106 if (icon) { 107 _src = [icon->src copy]; 108 _sizes = createNSArray(icon->sizes, [] (auto& size) -> NSString * { 109 return size; 110 }).leakRef(); 111 _type = [icon->type copy]; 112 _purposes = fromPurposes(icon->purposes).leakRef(); 113 } 114 115 return self; 116 } 117 118 - (void)encodeWithCoder:(NSCoder *)coder 119 { 120 [coder encodeObject:_src forKey:@"src"]; 121 [coder encodeObject:_sizes forKey:@"sizes"]; 122 [coder encodeObject:_type forKey:@"type"]; 123 [coder encodeObject:_purposes forKey:@"purposes"]; 124 } 125 126 - (void)dealloc 127 { 128 if (WebCoreObjCScheduleDeallocateOnMainRunLoop(_WKApplicationManifestIcon.class, self)) 129 return; 130 131 [_src release]; 132 [_sizes release]; 133 [_type release]; 134 [_purposes release]; 135 136 [super dealloc]; 137 } 138 139 @end 140 141 55 142 @implementation _WKApplicationManifest 56 143 … … 64 151 - (instancetype)initWithCoder:(NSCoder *)aDecoder 65 152 { 66 NSString *name = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"name"];67 NSString *shortName = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"short_name"];68 NSString *description = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"description"];69 NSURL *scopeURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"scope"];153 String name = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"name"]; 154 String shortName = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"short_name"]; 155 String description = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"description"]; 156 URL scopeURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"scope"]; 70 157 NSInteger display = [aDecoder decodeIntegerForKey:@"display"]; 71 NSURL *startURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"start_url"];158 URL startURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"start_url"]; 72 159 CocoaColor *themeColor = [aDecoder decodeObjectOfClass:[CocoaColor class] forKey:@"theme_color"]; 73 160 NSArray<_WKApplicationManifestIcon *> *icons = [aDecoder decodeObjectOfClasses:[NSSet setWithArray:@[[NSArray class], [_WKApplicationManifestIcon class]]] forKey:@"icons"]; 74 161 75 162 WebCore::ApplicationManifest coreApplicationManifest { 76 WTF ::String(name),77 WTF ::String(shortName),78 WTF ::String(description),79 URL(scopeURL),163 WTFMove(name), 164 WTFMove(shortName), 165 WTFMove(description), 166 WTFMove(scopeURL), 80 167 static_cast<WebCore::ApplicationManifest::Display>(display), 81 URL(startURL),168 WTFMove(startURL), 82 169 WebCore::roundAndClampToSRGBALossy(themeColor.CGColor), 83 Vector<WebCore::ApplicationManifest::Icon>(makeVector<WebCore::ApplicationManifest::Icon>(icons)),170 makeVector<WebCore::ApplicationManifest::Icon>(icons), 84 171 }; 85 172 … … 175 262 - (NSArray<_WKApplicationManifestIcon *> *)icons 176 263 { 177 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959 178 return nil; 264 return createNSArray(_applicationManifest->applicationManifest().icons, [] (auto& coreIcon) -> id { 265 return adoptNS([[_WKApplicationManifestIcon alloc] initWithCoreIcon:&coreIcon]).autorelease(); 266 }).autorelease(); 179 267 } 180 268 … … 244 332 245 333 @end 246 247 @implementation _WKApplicationManifestIcon248 249 + (BOOL)supportsSecureCoding250 {251 return YES;252 }253 254 - (instancetype)initWithCoder:(NSCoder *)aDecoder255 {256 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959257 UNUSED_PARAM(aDecoder);258 [self release];259 return nil;260 }261 262 - (void)encodeWithCoder:(NSCoder *)aCoder263 {264 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959265 UNUSED_PARAM(aCoder);266 }267 268 - (void)dealloc269 {270 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=232959271 if (WebCoreObjCScheduleDeallocateOnMainRunLoop(_WKApplicationManifestIcon.class, self))272 return;273 [super dealloc];274 }275 276 @end -
trunk/Tools/ChangeLog
r286072 r286073 1 2021-11-19 Brent Fulgham <bfulgham@apple.com> 2 3 Add support for web app manifest icons in WebKit/UI Process layer 4 https://bugs.webkit.org/show_bug.cgi?id=233350 5 <rdar://problem/84311569> 6 7 Reviewed by Chris Dumez. 8 9 Add a new API test to exercise the _WKApplicationManifestIcon API. 10 11 * TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp: 12 (ApplicationManifestParserTest::testIconsSizes): 13 (TEST_F): 14 * TestWebKitAPI/Tests/WebKitCocoa/ApplicationManifest.mm: 15 (TestWebKitAPI::TEST): 16 1 17 2021-11-19 Robert Jenner <Jenner@apple.com> 2 18 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/ApplicationManifestParser.cpp
r285645 r286073 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 161 161 } 162 162 163 void testIconsSizes(const String &rawJSON, const String& expectedValue)163 void testIconsSizes(const String &rawJSON, size_t expectedCount, size_t testIndex, const String& expectedValue) 164 164 { 165 165 auto manifest = parseIconFirstTopLevelProperty("sizes", rawJSON); 166 166 auto value = manifest.icons[0].sizes; 167 EXPECT_STREQ(expectedValue.utf8().data(), value.utf8().data()); 167 EXPECT_EQ(expectedCount, value.size()); 168 EXPECT_TRUE(testIndex < value.size()); 169 EXPECT_STREQ(expectedValue.utf8().data(), value[testIndex].utf8().data()); 168 170 } 169 171 … … 369 371 testIconsSrc("\"icon.jpg\"", srcURL); 370 372 testIconsType("\"image/webp\"", "image/webp"); 371 testIconsSizes("\"256x256\"", "256x256"); 372 testIconsSizes("\"72x72 96x96\"", "72x72 96x96"); 373 testIconsSizes("\"256x256\"", 1, 0, "256x256"); 374 testIconsSizes("\"72x72 96x96\"", 2, 0, "72x72"); 375 testIconsSizes("\"72x72 96x96\"", 2, 1, "96x96"); 373 376 374 377 OptionSet<ApplicationManifest::Icon::Purpose> purposeAny { ApplicationManifest::Icon::Purpose::Any }; -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ApplicationManifest.mm
r282026 r286073 1 1 /* 2 * Copyright (C) 2017 Apple Inc. All rights reserved.2 * Copyright (C) 2017-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 279 279 } 280 280 281 TEST(ApplicationManifest, Icons) 282 { 283 static bool done = false; 284 285 NSArray *expectedIcons = @[ @{ 286 @"src": @"https://example.com/images/touch/homescreen32.png", 287 @"sizes": @"32x32", 288 @"type": @"image/png" 289 }, @{ 290 @"src": @"https://example.com/images/touch/homescreen48.png", 291 @"sizes": @"48x48", 292 @"type": @"image/png", 293 @"purpose": @"monochrome maskable" 294 }, @{ 295 @"src": @"https://example.com/images/touch/homescreen128.jpg", 296 @"sizes": @"96x96 128x128", 297 @"type": @"image/jpg", 298 @"purpose": @"monochrome" 299 }]; 300 301 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect]); 302 NSDictionary *manifestObject = @{ 303 @"name": @"A Web Application", 304 @"short_name": @"WebApp", 305 @"description": @"Hello.", 306 @"start_url": @"http://example.com/app/start", 307 @"scope": @"http://example.com/app", 308 @"theme_color": @"red", 309 @"icons": expectedIcons 310 }; 311 NSString *htmlString = [NSString stringWithFormat:@"<link rel=\"manifest\" href=\"data:text/plain;charset=utf-8;base64,%@\">", [[NSJSONSerialization dataWithJSONObject:manifestObject options:0 error:nil] base64EncodedStringWithOptions:0]]; 312 [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://example.com/app/index"]]; 313 [webView _test_waitForDidFinishNavigation]; 314 [webView _getApplicationManifestWithCompletionHandler:^(_WKApplicationManifest *manifest) { 315 EXPECT_TRUE([manifest.name isEqualToString:@"A Web Application"]); 316 EXPECT_TRUE([manifest.shortName isEqualToString:@"WebApp"]); 317 EXPECT_TRUE([manifest.applicationDescription isEqualToString:@"Hello."]); 318 EXPECT_TRUE([manifest.startURL isEqual:[NSURL URLWithString:@"http://example.com/app/start"]]); 319 EXPECT_TRUE([manifest.scope isEqual:[NSURL URLWithString:@"http://example.com/app"]]); 320 321 auto sRGBColorSpace = adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceSRGB)); 322 auto redColor = adoptCF(CGColorCreate(sRGBColorSpace.get(), redColorComponents)); 323 EXPECT_TRUE(CGColorEqualToColor(manifest.themeColor.CGColor, redColor.get())); 324 325 size_t iconIndex = 0; 326 for (_WKApplicationManifestIcon *icon in manifest.icons) { 327 NSDictionary *expectedIcon = expectedIcons[iconIndex]; 328 NSString *expectedURLString = [expectedIcon objectForKey:@"src"]; 329 EXPECT_TRUE([icon.src isEqual:[NSURL URLWithString:expectedURLString]]); 330 EXPECT_TRUE([icon.type isEqual:[expectedIcon objectForKey:@"type"]]); 331 332 switch (iconIndex) { 333 case 0: 334 EXPECT_EQ(icon.sizes.count, 1ul); 335 EXPECT_TRUE([icon.sizes[0] isEqual:[expectedIcon objectForKey:@"sizes"]]); 336 EXPECT_EQ(icon.purposes.count, 1ul); 337 EXPECT_EQ(icon.purposes[0].unsignedLongValue, 1ul); 338 break; 339 340 case 1: 341 EXPECT_EQ(icon.sizes.count, 1ul); 342 EXPECT_TRUE([icon.sizes[0] isEqual:[expectedIcon objectForKey:@"sizes"]]); 343 EXPECT_EQ(icon.purposes.count, 2ul); 344 EXPECT_EQ(icon.purposes[0].unsignedLongValue, 2ul); 345 EXPECT_EQ(icon.purposes[1].unsignedLongValue, 4ul); 346 break; 347 348 case 2: 349 EXPECT_EQ(icon.sizes.count, 2ul); 350 EXPECT_TRUE([icon.sizes[0] isEqual:@"96x96"]); 351 EXPECT_TRUE([icon.sizes[1] isEqual:@"128x128"]); 352 EXPECT_EQ(icon.purposes.count, 1ul); 353 EXPECT_EQ(icon.purposes[0].unsignedLongValue, 2ul); 354 break; 355 } 356 357 ++iconIndex; 358 } 359 done = true; 360 }]; 361 Util::run(&done); 362 } 363 281 364 } // namespace TestWebKitAPI 282 365
Note:
See TracChangeset
for help on using the changeset viewer.