Changeset 218409 in webkit


Ignore:
Timestamp:
Jun 16, 2017 1:34:47 PM (7 years ago)
Author:
beidson@apple.com
Message:

REGRESSION (r218015) IconLoaders for already-cached resources expect to be asynchronous, no longer are.
<rdar://problem/32817519> and https://bugs.webkit.org/show_bug.cgi?id=173478

Reviewed by Daniel Bates.

Source/WebCore:

Covered by API test.

Being synchronous is actually better as it's resolved another issue or two.
But only if we can actually deliver the data without crashing first.
So let's do that.

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::didGetLoadDecisionForIcon): Put the IconLoader in the set of active icon loaders

before actually starting the icon loading.

Tools:

  • TestWebKitAPI/Tests/WebKit2Cocoa/IconLoadingDelegate.mm:
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r218407 r218409  
     12017-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
    1182017-06-16  Jeremy Jones  <jeremyj@apple.com>
    219
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r218278 r218409  
    16821682
    16831683    auto iconLoader = std::make_unique<IconLoader>(*this, icon.url);
    1684     iconLoader->startLoading();
     1684    auto* rawIconLoader = iconLoader.get();
    16851685    m_iconLoaders.set(WTFMove(iconLoader), newCallbackID);
     1686
     1687    rawIconLoader->startLoading();
    16861688}
    16871689
  • trunk/Tools/ChangeLog

    r218406 r218409  
     12017-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
    1102017-06-16  Chris Dumez  <cdumez@apple.com>
    211
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IconLoadingDelegate.mm

    r218278 r218409  
    4040
    4141static bool doneWithIcons;
     42static bool receivedFaviconDataCallback;
     43static bool alreadyProvidedIconData;
     44static RetainPtr<NSData> receivedFaviconData;
    4245
    4346@interface IconLoadingDelegate : NSObject <_WKIconLoadingDelegate>
     
    6770        doneWithIcons = true;
    6871
    69     completionHandler(nil);
     72    if (parameters.iconType == WKLinkIconTypeFavicon) {
     73        completionHandler([](NSData *iconData) {
     74            receivedFaviconData = iconData;
     75            receivedFaviconDataCallback = true;
     76        });
     77    } else
     78        completionHandler(nil);
    7079}
    7180
     
    7382
    7483@interface IconLoadingSchemeHandler : NSObject <WKURLSchemeHandler>
    75 - (instancetype)initWithData:(NSData *)data mimeType:(NSString *)inMIMEType;
     84- (instancetype)initWithData:(NSData *)data;
     85- (void)setFaviconData:(NSData *)data;
    7686@end
    7787
    7888@implementation IconLoadingSchemeHandler {
    79     RetainPtr<NSData> resourceData;
    80     RetainPtr<NSString> mimeType;
     89    RetainPtr<NSData> mainResourceData;
     90    RetainPtr<NSData> faviconData;
    8191}
    8292
    83 - (instancetype)initWithData:(NSData *)data mimeType:(NSString *)inMIMEType
     93- (instancetype)initWithData:(NSData *)data
    8494{
    8595    self = [super init];
     
    8797        return nil;
    8898
    89     resourceData = data;
    90     mimeType = inMIMEType;
     99    mainResourceData = data;
    91100
    92101    return self;
    93102}
    94103
     104- (void)setFaviconData:(NSData *)data
     105{
     106    faviconData = data;
     107}
     108
    95109- (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task
    96110{
    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
    98124    [task didReceiveResponse:response.get()];
    99     [task didReceiveData:resourceData.get()];
     125    [task didReceiveData:data];
    100126    [task didFinish];
    101127}
     
    117143    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    118144
    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)]]);
    120146    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"testing"];
    121147
     
    131157}
    132158
     159static const char mainBytes2[] =
     160"Oh, hello there!";
     161
     162TEST(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
    133199#endif
Note: See TracChangeset for help on using the changeset viewer.