Changeset 273181 in webkit


Ignore:
Timestamp:
Feb 19, 2021 4:26:29 PM (3 years ago)
Author:
commit-queue@webkit.org
Message:

NSError returned by WebKit API should actually conform to NSSecureCoding
https://bugs.webkit.org/show_bug.cgi?id=222204
<rdar://problem/63893583>

Patch by Alex Christensen <achristensen@webkit.org> on 2021-02-19
Reviewed by Chris Dumez.

Source/WebKit:

When an NSError is encoded, its userInfo is encoded, which means everything we put in userInfo should be encodable.
WKReloadFrameErrorRecoveryAttempter was not, so let's make it! When encoded, it will just encode nothing.
When decoded, it will produce a WKReloadFrameErrorRecoveryAttempter that does nothing, which is valid behavior,
and more desirable than crashing.

  • UIProcess/Cocoa/WKReloadFrameErrorRecoveryAttempter.h:
  • UIProcess/Cocoa/WKReloadFrameErrorRecoveryAttempter.mm:

(-[WKReloadFrameErrorRecoveryAttempter encodeWithCoder:]):
(-[WKReloadFrameErrorRecoveryAttempter initWithCoder:]):
(+[WKReloadFrameErrorRecoveryAttempter supportsSecureCoding]):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/cocoa/TestNavigationDelegate.h:
  • TestWebKitAPI/cocoa/TestNavigationDelegate.mm:

(-[TestNavigationDelegate waitForDidFailProvisionalNavigation]):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r273180 r273181  
     12021-02-19  Alex Christensen  <achristensen@webkit.org>
     2
     3        NSError returned by WebKit API should actually conform to NSSecureCoding
     4        https://bugs.webkit.org/show_bug.cgi?id=222204
     5        <rdar://problem/63893583>
     6
     7        Reviewed by Chris Dumez.
     8
     9        When an NSError is encoded, its userInfo is encoded, which means everything we put in userInfo should be encodable.
     10        WKReloadFrameErrorRecoveryAttempter was not, so let's make it!  When encoded, it will just encode nothing.
     11        When decoded, it will produce a WKReloadFrameErrorRecoveryAttempter that does nothing, which is valid behavior,
     12        and more desirable than crashing.
     13
     14        * UIProcess/Cocoa/WKReloadFrameErrorRecoveryAttempter.h:
     15        * UIProcess/Cocoa/WKReloadFrameErrorRecoveryAttempter.mm:
     16        (-[WKReloadFrameErrorRecoveryAttempter encodeWithCoder:]):
     17        (-[WKReloadFrameErrorRecoveryAttempter initWithCoder:]):
     18        (+[WKReloadFrameErrorRecoveryAttempter supportsSecureCoding]):
     19
    1202021-02-19  Alex Christensen  <achristensen@webkit.org>
    221
  • trunk/Source/WebKit/UIProcess/Cocoa/WKReloadFrameErrorRecoveryAttempter.h

    r242339 r273181  
    2424 */
    2525
     26#import "_WKErrorRecoveryAttempting.h"
    2627#import <WebKit/WKFoundation.h>
    27 
    2828#import <wtf/Forward.h>
    2929
     
    3131@class _WKFrameHandle;
    3232
    33 @interface WKReloadFrameErrorRecoveryAttempter : NSObject
     33@interface WKReloadFrameErrorRecoveryAttempter : NSObject<_WKErrorRecoveryAttempting, NSSecureCoding>
    3434
    3535- (id)initWithWebView:(WKWebView *)webView frameHandle:(_WKFrameHandle *)frameHandle urlString:(const String&)urlString;
  • trunk/Source/WebKit/UIProcess/Cocoa/WKReloadFrameErrorRecoveryAttempter.mm

    r254409 r273181  
    3737#import <wtf/WeakObjCPtr.h>
    3838
    39 @interface WKReloadFrameErrorRecoveryAttempter () <_WKErrorRecoveryAttempting>
     39@interface WKReloadFrameErrorRecoveryAttempter ()
    4040@end
    4141
     
    7272}
    7373
     74- (void)encodeWithCoder:(NSCoder *)coder
     75{
     76}
     77
     78- (instancetype)initWithCoder:(NSCoder *)coder
     79{
     80    return [super init];
     81}
     82
     83+ (BOOL)supportsSecureCoding
     84{
     85    return YES;
     86}
     87
    7488@end
  • trunk/Tools/ChangeLog

    r273167 r273181  
     12021-02-19  Alex Christensen  <achristensen@webkit.org>
     2
     3        NSError returned by WebKit API should actually conform to NSSecureCoding
     4        https://bugs.webkit.org/show_bug.cgi?id=222204
     5        <rdar://problem/63893583>
     6
     7        Reviewed by Chris Dumez.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:
     10        (TestWebKitAPI::TEST):
     11        * TestWebKitAPI/cocoa/TestNavigationDelegate.h:
     12        * TestWebKitAPI/cocoa/TestNavigationDelegate.mm:
     13        (-[TestNavigationDelegate waitForDidFailProvisionalNavigation]):
     14
    1152021-02-16  Jiewen Tan  <jiewen_tan@apple.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm

    r273062 r273181  
    574574}
    575575
     576TEST(WebKit, ErrorSecureCoding)
     577{
     578    HTTPServer server({{ "/", { HTTPResponse::TerminateConnection::Yes }}});
     579    auto webView = [[WKWebView new] autorelease];
     580    auto delegate = [[TestNavigationDelegate new] autorelease];
     581    webView.navigationDelegate = delegate;
     582    [webView loadRequest:server.request()];
     583    NSError *error = [delegate waitForDidFailProvisionalNavigation];
     584
     585    EXPECT_WK_STREQ(NSStringFromClass([error.userInfo[_WKRecoveryAttempterErrorKey] class]), @"WKReloadFrameErrorRecoveryAttempter");
     586    auto archiver = adoptNS([[NSKeyedArchiver alloc] initRequiringSecureCoding:YES]);
     587    [archiver encodeObject:error forKey:NSKeyedArchiveRootObjectKey];
     588    [archiver finishEncoding];
     589    auto unarchiver = adoptNS([[NSKeyedUnarchiver alloc] initForReadingFromData:archiver.get().encodedData error:nullptr]);
     590    NSError *decodedError = [unarchiver decodeObjectOfClasses:[NSSet setWithObjects:[NSDictionary class], [NSString class], [NSError class], NSClassFromString(@"WKReloadFrameErrorRecoveryAttempter"), nil] forKey:NSKeyedArchiveRootObjectKey];
     591    EXPECT_EQ(decodedError.code, NSURLErrorNetworkConnectionLost);
     592    EXPECT_WK_STREQ(decodedError.domain, NSURLErrorDomain);
     593    EXPECT_WK_STREQ(NSStringFromClass([decodedError.userInfo[_WKRecoveryAttempterErrorKey] class]), @"WKReloadFrameErrorRecoveryAttempter");
     594}
     595
    576596// FIXME: Find out why these tests time out on Mojave.
    577597#if !PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500
  • trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h

    r269703 r273181  
    4343- (void)waitForDidFinishNavigation;
    4444- (void)waitForDidFinishNavigationWithPreferences:(WKWebpagePreferences *)preferences;
    45 - (void)waitForDidFailProvisionalNavigation;
     45- (NSError *)waitForDidFailProvisionalNavigation;
    4646
    4747@end
  • trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm

    r269703 r273181  
    3131#import <wtf/RetainPtr.h>
    3232
    33 @implementation TestNavigationDelegate
     33@implementation TestNavigationDelegate {
     34    RetainPtr<NSError> _navigationError;
     35}
    3436
    3537- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction preferences:(WKWebpagePreferences *)preferences decisionHandler:(void (^)(WKNavigationActionPolicy, WKWebpagePreferences *))decisionHandler
     
    152154}
    153155
    154 - (void)waitForDidFailProvisionalNavigation
     156- (NSError *)waitForDidFailProvisionalNavigation
    155157{
    156158    EXPECT_FALSE(self.didFailProvisionalNavigation);
    157159
    158160    __block bool finished = false;
    159     self.didFailProvisionalNavigation = ^(WKWebView *, WKNavigation *, NSError *) {
     161    self.didFailProvisionalNavigation = ^(WKWebView *, WKNavigation *, NSError *error) {
     162        _navigationError = error;
    160163        finished = true;
    161164    };
     
    164167
    165168    self.didFailProvisionalNavigation = nil;
     169    return _navigationError.autorelease();
    166170}
    167171
Note: See TracChangeset for help on using the changeset viewer.