Changeset 206801 in webkit


Ignore:
Timestamp:
Oct 4, 2016, 6:02:27 PM (9 years ago)
Author:
aestes@apple.com
Message:

[iOS] Crash in WebResourceLoaderQuickLookDelegate when the client cancels the navigation to a QuickLook resource
https://bugs.webkit.org/show_bug.cgi?id=162950
<rdar://problem/23759114>

Reviewed by Brady Eidson.

Source/WebCore:

When we receive data from QLPreviewConverter for the first time, we call
ResourceLoader::didReceiveResponse() with the preview NSURLResponse from QuickLook. If the
client decides to cancel this navigation in decidePolicyForResponse(),
WebResourceLoaderQuickLookDelegate will end up with a null _resourceLoader after
didReceiveResponse() returns. This change adds null checks in the methods that use
_resourceLoader after calling -_sendDidReceiveResponseIfNecessary.

New API test: QuickLook.CancelNavigationAfterResponse

  • platform/network/ios/QuickLook.mm:

(-[WebResourceLoaderQuickLookDelegate connection:didReceiveDataArray:]): Changed to only
call ResourceLoader::didReceiveDataArray() if _resourceLoader is non-null.
(-[WebResourceLoaderQuickLookDelegate connection:didReceiveData:lengthReceived:]): Ditto for
ResourceLoader::didReceiveData().
(-[WebResourceLoaderQuickLookDelegate connection:didFailWithError:]): Ditto for
ResourceLoader::didFail().

Tools:

Added a new API test.

  • TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm: Sorted imports and removed redundant

initialization of static bools.
(runTest): Factored out the common test logic between QuickLook.NavigationDelegate and
QuickLook.CancelNavigationAfterResponse.
(TEST): Added QuickLook.CancelNavigationAfterResponse.
(-[QuickLookDecidePolicyDelegate
webView:decidePolicyForNavigationResponse:decisionHandler:]): Canceled the navigation.
(-[QuickLookDecidePolicyDelegate webView:didFailProvisionalNavigation:withError:]): Set
isDone to true.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206796 r206801  
     12016-10-04  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Crash in WebResourceLoaderQuickLookDelegate when the client cancels the navigation to a QuickLook resource
     4        https://bugs.webkit.org/show_bug.cgi?id=162950
     5        <rdar://problem/23759114>
     6
     7        Reviewed by Brady Eidson.
     8
     9        When we receive data from QLPreviewConverter for the first time, we call
     10        ResourceLoader::didReceiveResponse() with the preview NSURLResponse from QuickLook. If the
     11        client decides to cancel this navigation in decidePolicyForResponse(),
     12        WebResourceLoaderQuickLookDelegate will end up with a null _resourceLoader after
     13        didReceiveResponse() returns. This change adds null checks in the methods that use
     14        _resourceLoader after calling -_sendDidReceiveResponseIfNecessary.
     15
     16        New API test: QuickLook.CancelNavigationAfterResponse
     17
     18        * platform/network/ios/QuickLook.mm:
     19        (-[WebResourceLoaderQuickLookDelegate connection:didReceiveDataArray:]): Changed to only
     20        call ResourceLoader::didReceiveDataArray() if _resourceLoader is non-null.
     21        (-[WebResourceLoaderQuickLookDelegate connection:didReceiveData:lengthReceived:]): Ditto for
     22        ResourceLoader::didReceiveData().
     23        (-[WebResourceLoaderQuickLookDelegate connection:didFailWithError:]): Ditto for
     24        ResourceLoader::didFail().
     25
    1262016-10-04  Chris Dumez  <cdumez@apple.com>
    227
  • trunk/Source/WebCore/platform/network/ios/QuickLook.mm

    r199669 r206801  
    11/*
    2  * Copyright (C) 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009-2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    310310        return;
    311311
    312     _resourceLoader->didReceiveDataArray(reinterpret_cast<CFArrayRef>(dataArray));
     312    if (_resourceLoader)
     313        _resourceLoader->didReceiveDataArray(reinterpret_cast<CFArrayRef>(dataArray));
    313314}
    314315#endif
     
    328329    if (![data length])
    329330        return;
    330     _resourceLoader->didReceiveData(reinterpret_cast<const char*>([data bytes]), [data length], lengthReceived, DataPayloadBytes);
     331
     332    if (_resourceLoader)
     333        _resourceLoader->didReceiveData(reinterpret_cast<const char*>([data bytes]), [data length], lengthReceived, DataPayloadBytes);
    331334}
    332335
     
    349352        return;
    350353
    351     _resourceLoader->didFail(ResourceError(error));
     354    if (_resourceLoader)
     355        _resourceLoader->didFail(ResourceError(error));
    352356}
    353357
  • trunk/Tools/ChangeLog

    r206800 r206801  
     12016-10-04  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Crash in WebResourceLoaderQuickLookDelegate when the client cancels the navigation to a QuickLook resource
     4        https://bugs.webkit.org/show_bug.cgi?id=162950
     5        <rdar://problem/23759114>
     6
     7        Reviewed by Brady Eidson.
     8
     9        Added a new API test.
     10
     11        * TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm: Sorted imports and removed redundant
     12        initialization of static bools.
     13        (runTest): Factored out the common test logic between QuickLook.NavigationDelegate and
     14        QuickLook.CancelNavigationAfterResponse.
     15        (TEST): Added QuickLook.CancelNavigationAfterResponse.
     16        (-[QuickLookDecidePolicyDelegate
     17        webView:decidePolicyForNavigationResponse:decisionHandler:]): Canceled the navigation.
     18        (-[QuickLookDecidePolicyDelegate webView:didFailProvisionalNavigation:withError:]): Set
     19        isDone to true.
     20
    1212016-10-04  Ryosuke Niwa  <rniwa@webkit.org>
    222
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/QuickLook.mm

    r189997 r206801  
    11/*
    2  * Copyright (C) 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828#if PLATFORM(IOS)
    2929
     30#import "PlatformUtilities.h"
    3031#import <WebKit/WKNavigationDelegatePrivate.h>
    3132#import <WebKit/WKWebView.h>
    3233#import <wtf/RetainPtr.h>
    33 #import "PlatformUtilities.h"
    3434
    35 static bool isDone = false;
    36 static bool didStartQuickLookLoad = false;
    37 static bool didFinishQuickLookLoad = false;
     35static bool isDone;
     36static bool didStartQuickLookLoad;
     37static bool didFinishQuickLookLoad;
    3838
    3939@interface QuickLookNavigationDelegate : NSObject <WKNavigationDelegatePrivate>
     
    6262@end
    6363
    64 TEST(QuickLook, NavigationDelegate)
     64static void runTest(Class navigationDelegateClass)
    6565{
    6666    auto webView = adoptNS([[WKWebView alloc] init]);
    67     auto navigationDelegate = adoptNS([[QuickLookNavigationDelegate alloc] init]);
     67    auto navigationDelegate = adoptNS([[navigationDelegateClass alloc] init]);
    6868    [webView setNavigationDelegate:navigationDelegate.get()];
    6969    [webView loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"pages" withExtension:@"pages" subdirectory:@"TestWebKitAPI.resources"]]];
    7070
     71    isDone = false;
    7172    TestWebKitAPI::Util::run(&isDone);
     73}
    7274
     75TEST(QuickLook, NavigationDelegate)
     76{
     77    runTest([QuickLookNavigationDelegate class]);
    7378    EXPECT_TRUE(didStartQuickLookLoad);
    7479    EXPECT_TRUE(didFinishQuickLookLoad);
    7580}
    7681
     82@interface QuickLookDecidePolicyDelegate : NSObject <WKNavigationDelegate>
     83@end
     84
     85@implementation QuickLookDecidePolicyDelegate
     86
     87- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
     88{
     89    decisionHandler(WKNavigationResponsePolicyCancel);
     90}
     91
     92- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error
     93{
     94    isDone = true;
     95}
     96
     97@end
     98
     99TEST(QuickLook, CancelNavigationAfterResponse)
     100{
     101    runTest([QuickLookDecidePolicyDelegate class]);
     102}
     103
    77104#endif // PLATFORM(IOS)
Note: See TracChangeset for help on using the changeset viewer.