Changeset 255132 in webkit


Ignore:
Timestamp:
Jan 26, 2020 2:15:17 PM (4 years ago)
Author:
Darin Adler
Message:

Protect against crashes during WKWebView init function when methods are called before the view is fully initialized
https://bugs.webkit.org/show_bug.cgi?id=206799
rdar://problem/58871371

Reviewed by Sam Weinig.

Part way through creating WKWebView, some methods can be called and they need to be careful
not to use anything that may not be initialized yet.

  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView dealloc]): Check _page for null, since this might happen if the superclass's
init method returned nil.

  • UIProcess/API/ios/WKWebViewIOS.mm:

(-[WKWebView _frameOrBoundsChanged]): Check _page for null, since this might be called
before object initialization is complete.
(-[WKWebView setSemanticContentAttribute:]): Ditto.

  • UIProcess/API/mac/WKWebViewMac.mm:

(-[WKWebView setFrameSize:]): Check _impl for null since this might be called before
oject initialization is complete.
(-[WKWebView setUserInterfaceLayoutDirection:]): Ditto.
(-[WKWebView renewGState]): Ditto.

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r255131 r255132  
     12020-01-26  Darin Adler  <darin@apple.com>
     2
     3        Protect against crashes during WKWebView init function when methods are called before the view is fully initialized
     4        https://bugs.webkit.org/show_bug.cgi?id=206799
     5        rdar://problem/58871371
     6
     7        Reviewed by Sam Weinig.
     8
     9        Part way through creating WKWebView, some methods can be called and they need to be careful
     10        not to use anything that may not be initialized yet.
     11
     12        * UIProcess/API/Cocoa/WKWebView.mm:
     13        (-[WKWebView dealloc]): Check _page for null, since this might happen if the superclass's
     14        init method returned nil.
     15
     16        * UIProcess/API/ios/WKWebViewIOS.mm:
     17        (-[WKWebView _frameOrBoundsChanged]): Check _page for null, since this might be called
     18        before object initialization is complete.
     19        (-[WKWebView setSemanticContentAttribute:]): Ditto.
     20
     21        * UIProcess/API/mac/WKWebViewMac.mm:
     22        (-[WKWebView setFrameSize:]): Check _impl for null since this might be called before
     23        oject initialization is complete.
     24        (-[WKWebView setUserInterfaceLayoutDirection:]): Ditto.
     25        (-[WKWebView renewGState]): Ditto.
     26
    1272020-01-26  Said Abou-Hallawa  <said@apple.com>
    228
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r255054 r255132  
    11/*
    2  * Copyright (C) 2014-2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    592592    [_contentView _webViewDestroyed];
    593593
    594     if (_remoteObjectRegistry)
     594    if (_page && _remoteObjectRegistry)
    595595        _page->process().processPool().removeMessageReceiver(Messages::RemoteObjectRegistry::messageReceiverName(), _page->identifier());
    596596#endif
    597597
    598     _page->close();
     598    if (_page)
     599        _page->close();
    599600
    600601#if PLATFORM(IOS_FAMILY)
     
    607608#endif
    608609
    609     pageToViewMap().remove(_page.get());
     610    if (_page)
     611        pageToViewMap().remove(_page.get());
    610612
    611613    [super dealloc];
  • trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm

    r255054 r255132  
    11/*
    2  * Copyright (C) 2014-2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    17601760
    17611761        BOOL sizeChanged = NO;
    1762         if (auto drawingArea = _page->drawingArea())
    1763             sizeChanged = drawingArea->setSize(WebCore::IntSize(bounds.size));
     1762        if (_page) {
     1763            if (auto drawingArea = _page->drawingArea())
     1764                sizeChanged = drawingArea->setSize(WebCore::IntSize(bounds.size));
     1765        }
    17641766
    17651767        if (sizeChanged & [self usesStandardContentView])
     
    23792381    [super setSemanticContentAttribute:contentAttribute];
    23802382
    2381     _page->setUserInterfaceLayoutDirection(toUserInterfaceLayoutDirection(contentAttribute));
     2383    if (_page)
     2384        _page->setUserInterfaceLayoutDirection(toUserInterfaceLayoutDirection(contentAttribute));
    23822385}
    23832386
  • trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm

    r254409 r255132  
    11/*
    2  * Copyright (C) 2014-2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    136136    [super setFrameSize:size];
    137137    [_safeBrowsingWarning setFrame:self.bounds];
    138     _impl->setFrameSize(NSSizeToCGSize(size));
     138    if (_impl)
     139        _impl->setFrameSize(NSSizeToCGSize(size));
    139140}
    140141
     
    142143{
    143144    [super setUserInterfaceLayoutDirection:userInterfaceLayoutDirection];
    144 
    145     _impl->setUserInterfaceLayoutDirection(userInterfaceLayoutDirection);
     145    if (_impl)
     146        _impl->setUserInterfaceLayoutDirection(userInterfaceLayoutDirection);
    146147}
    147148
     
    150151ALLOW_DEPRECATED_IMPLEMENTATIONS_END
    151152{
    152     _impl->renewGState();
     153    if (_impl)
     154        _impl->renewGState();
    153155    [super renewGState];
    154156}
Note: See TracChangeset for help on using the changeset viewer.