Changeset 218409 in webkit
- Timestamp:
- Jun 16, 2017 1:34:47 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r218407 r218409 1 2017-06-16 Brady Eidson <beidson@apple.com> 2 3 REGRESSION (r218015) IconLoaders for already-cached resources expect to be asynchronous, no longer are. 4 <rdar://problem/32817519> and https://bugs.webkit.org/show_bug.cgi?id=173478 5 6 Reviewed by Daniel Bates. 7 8 Covered by API test. 9 10 Being synchronous is actually better as it's resolved another issue or two. 11 But only if we can actually deliver the data without crashing first. 12 So let's do that. 13 14 * loader/DocumentLoader.cpp: 15 (WebCore::DocumentLoader::didGetLoadDecisionForIcon): Put the IconLoader in the set of active icon loaders 16 before actually starting the icon loading. 17 1 18 2017-06-16 Jeremy Jones <jeremyj@apple.com> 2 19 -
trunk/Source/WebCore/loader/DocumentLoader.cpp
r218278 r218409 1682 1682 1683 1683 auto iconLoader = std::make_unique<IconLoader>(*this, icon.url); 1684 iconLoader->startLoading();1684 auto* rawIconLoader = iconLoader.get(); 1685 1685 m_iconLoaders.set(WTFMove(iconLoader), newCallbackID); 1686 1687 rawIconLoader->startLoading(); 1686 1688 } 1687 1689 -
trunk/Tools/ChangeLog
r218406 r218409 1 2017-06-16 Brady Eidson <beidson@apple.com> 2 3 REGRESSION (r218015) IconLoaders for already-cached resources expect to be asynchronous, no longer are. 4 <rdar://problem/32817519> and https://bugs.webkit.org/show_bug.cgi?id=173478 5 6 Reviewed by Daniel Bates. 7 8 * TestWebKitAPI/Tests/WebKit2Cocoa/IconLoadingDelegate.mm: 9 1 10 2017-06-16 Chris Dumez <cdumez@apple.com> 2 11 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IconLoadingDelegate.mm
r218278 r218409 40 40 41 41 static bool doneWithIcons; 42 static bool receivedFaviconDataCallback; 43 static bool alreadyProvidedIconData; 44 static RetainPtr<NSData> receivedFaviconData; 42 45 43 46 @interface IconLoadingDelegate : NSObject <_WKIconLoadingDelegate> … … 67 70 doneWithIcons = true; 68 71 69 completionHandler(nil); 72 if (parameters.iconType == WKLinkIconTypeFavicon) { 73 completionHandler([](NSData *iconData) { 74 receivedFaviconData = iconData; 75 receivedFaviconDataCallback = true; 76 }); 77 } else 78 completionHandler(nil); 70 79 } 71 80 … … 73 82 74 83 @interface IconLoadingSchemeHandler : NSObject <WKURLSchemeHandler> 75 - (instancetype)initWithData:(NSData *)data mimeType:(NSString *)inMIMEType; 84 - (instancetype)initWithData:(NSData *)data; 85 - (void)setFaviconData:(NSData *)data; 76 86 @end 77 87 78 88 @implementation IconLoadingSchemeHandler { 79 RetainPtr<NSData> resourceData;80 RetainPtr<NS String> mimeType;89 RetainPtr<NSData> mainResourceData; 90 RetainPtr<NSData> faviconData; 81 91 } 82 92 83 - (instancetype)initWithData:(NSData *)data mimeType:(NSString *)inMIMEType93 - (instancetype)initWithData:(NSData *)data 84 94 { 85 95 self = [super init]; … … 87 97 return nil; 88 98 89 resourceData = data; 90 mimeType = inMIMEType; 99 mainResourceData = data; 91 100 92 101 return self; 93 102 } 94 103 104 - (void)setFaviconData:(NSData *)data 105 { 106 faviconData = data; 107 } 108 95 109 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task 96 110 { 97 RetainPtr<NSURLResponse> response = adoptNS([[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:mimeType.get() expectedContentLength:1 textEncodingName:nil]); 111 RetainPtr<NSURLResponse> response; 112 NSData *data = nil; 113 114 if ([[task.request.URL absoluteString] isEqual:@"testing:///favicon.ico"]) { 115 EXPECT_FALSE(alreadyProvidedIconData); 116 response = adoptNS([[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"image/png" expectedContentLength:1 textEncodingName:nil]); 117 data = faviconData.get(); 118 alreadyProvidedIconData = true; 119 } else { 120 response = adoptNS([[NSURLResponse alloc] initWithURL:task.request.URL MIMEType:@"text/html" expectedContentLength:1 textEncodingName:nil]); 121 data = mainResourceData.get(); 122 } 123 98 124 [task didReceiveResponse:response.get()]; 99 [task didReceiveData: resourceData.get()];125 [task didReceiveData:data]; 100 126 [task didFinish]; 101 127 } … … 117 143 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 118 144 119 RetainPtr<IconLoadingSchemeHandler> handler = adoptNS([[IconLoadingSchemeHandler alloc] initWithData:[NSData dataWithBytesNoCopy:(void*)mainBytes length:sizeof(mainBytes)] mimeType:@"text/html"]);145 RetainPtr<IconLoadingSchemeHandler> handler = adoptNS([[IconLoadingSchemeHandler alloc] initWithData:[NSData dataWithBytesNoCopy:(void*)mainBytes length:sizeof(mainBytes)]]); 120 146 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"testing"]; 121 147 … … 131 157 } 132 158 159 static const char mainBytes2[] = 160 "Oh, hello there!"; 161 162 TEST(IconLoading, AlreadyCachedIcon) 163 { 164 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 165 166 NSData *mainData = [NSData dataWithBytesNoCopy:(void*)mainBytes2 length:sizeof(mainBytes2)]; 167 RetainPtr<IconLoadingSchemeHandler> handler = adoptNS([[IconLoadingSchemeHandler alloc] initWithData:mainData]); 168 169 NSURL *url = [[NSBundle mainBundle] URLForResource:@"large-red-square-image" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]; 170 RetainPtr<NSData *> iconDataFromDisk = [NSData dataWithContentsOfURL:url]; 171 [handler.get() setFaviconData:iconDataFromDisk.get()]; 172 173 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"testing"]; 174 175 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 176 RetainPtr<IconLoadingDelegate> iconDelegate = adoptNS([[IconLoadingDelegate alloc] init]); 177 178 webView.get()._iconLoadingDelegate = iconDelegate.get(); 179 180 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"testing:///main"]]; 181 [webView loadRequest:request]; 182 183 TestWebKitAPI::Util::run(&receivedFaviconDataCallback); 184 185 EXPECT_TRUE([iconDataFromDisk.get() isEqual:receivedFaviconData.get()]); 186 187 receivedFaviconDataCallback = false; 188 receivedFaviconData = nil; 189 190 // Load another main resource that results in the same icon being loaded (which should come from the memory cache). 191 request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"testing:///main2"]]; 192 [webView loadRequest:request]; 193 194 TestWebKitAPI::Util::run(&receivedFaviconDataCallback); 195 196 EXPECT_TRUE([iconDataFromDisk.get() isEqual:receivedFaviconData.get()]); 197 } 198 133 199 #endif
Note: See TracChangeset
for help on using the changeset viewer.