Changeset 244246 in webkit


Ignore:
Timestamp:
Apr 14, 2019 9:08:23 AM (5 years ago)
Author:
aestes@apple.com
Message:

[Cocoa] WKCustomProtocolLoader should store a WeakPtr to its LegacyCustomProtocolManagerProxy
https://bugs.webkit.org/show_bug.cgi?id=196893
<rdar://problem/48318983>

Reviewed by Anders Carlsson.

In addition to manually invalidating each WKCustomProtocolLoader's _customProtocolManagerProxy
pointer when the LegacyCustomProtocolManagerClient is invalidated, use a WeakPtr in case the
LegacyCustomProtocolManagerProxy is ever destroyed without first invalidating the client.
Also add null pointer checks to NSURLConnectionDelegate methods, which might be called after
the LegacyCustomProtocolManagerProxy has been destroyed.

  • UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm:

(-[WKCustomProtocolLoader initWithLegacyCustomProtocolManagerProxy:customProtocolID:request:]):
(-[WKCustomProtocolLoader cancel]):
(-[WKCustomProtocolLoader connection:didFailWithError:]):
(-[WKCustomProtocolLoader connection:didReceiveResponse:]):
(-[WKCustomProtocolLoader connection:didReceiveData:]):
(-[WKCustomProtocolLoader connection:willSendRequest:redirectResponse:]):
(-[WKCustomProtocolLoader connectionDidFinishLoading:]):
(WebKit::LegacyCustomProtocolManagerClient::startLoading):
(WebKit::LegacyCustomProtocolManagerClient::invalidate):
(-[WKCustomProtocolLoader customProtocolManagerProxyDestroyed]): Deleted.

  • UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.h:
Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r244245 r244246  
     12019-04-14  Andy Estes  <aestes@apple.com>
     2
     3        [Cocoa] WKCustomProtocolLoader should store a WeakPtr to its LegacyCustomProtocolManagerProxy
     4        https://bugs.webkit.org/show_bug.cgi?id=196893
     5        <rdar://problem/48318983>
     6
     7        Reviewed by Anders Carlsson.
     8
     9        In addition to manually invalidating each WKCustomProtocolLoader's _customProtocolManagerProxy
     10        pointer when the LegacyCustomProtocolManagerClient is invalidated, use a WeakPtr in case the
     11        LegacyCustomProtocolManagerProxy is ever destroyed without first invalidating the client.
     12        Also add null pointer checks to NSURLConnectionDelegate methods, which might be called after
     13        the LegacyCustomProtocolManagerProxy has been destroyed.
     14
     15        * UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm:
     16        (-[WKCustomProtocolLoader initWithLegacyCustomProtocolManagerProxy:customProtocolID:request:]):
     17        (-[WKCustomProtocolLoader cancel]):
     18        (-[WKCustomProtocolLoader connection:didFailWithError:]):
     19        (-[WKCustomProtocolLoader connection:didReceiveResponse:]):
     20        (-[WKCustomProtocolLoader connection:didReceiveData:]):
     21        (-[WKCustomProtocolLoader connection:willSendRequest:redirectResponse:]):
     22        (-[WKCustomProtocolLoader connectionDidFinishLoading:]):
     23        (WebKit::LegacyCustomProtocolManagerClient::startLoading):
     24        (WebKit::LegacyCustomProtocolManagerClient::invalidate):
     25        (-[WKCustomProtocolLoader customProtocolManagerProxyDestroyed]): Deleted.
     26        * UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.h:
     27
    1282019-04-14  Don Olmstead  <don.olmstead@sony.com>
    229
  • trunk/Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm

    r235935 r244246  
    3535@interface WKCustomProtocolLoader : NSObject <NSURLConnectionDelegate> {
    3636@private
    37     WebKit::LegacyCustomProtocolManagerProxy* _customProtocolManagerProxy;
     37    WeakPtr<WebKit::LegacyCustomProtocolManagerProxy> _customProtocolManagerProxy;
    3838    uint64_t _customProtocolID;
    3939    NSURLCacheStoragePolicy _storagePolicy;
    4040    NSURLConnection *_urlConnection;
    4141}
    42 - (id)initWithLegacyCustomProtocolManagerProxy:(WebKit::LegacyCustomProtocolManagerProxy*)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request;
    43 - (void)customProtocolManagerProxyDestroyed;
     42- (id)initWithLegacyCustomProtocolManagerProxy:(WebKit::LegacyCustomProtocolManagerProxy&)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request;
     43- (void)cancel;
    4444@end
    4545
    4646@implementation WKCustomProtocolLoader
    4747
    48 - (id)initWithLegacyCustomProtocolManagerProxy:(WebKit::LegacyCustomProtocolManagerProxy*)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request
     48- (id)initWithLegacyCustomProtocolManagerProxy:(WebKit::LegacyCustomProtocolManagerProxy&)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request
    4949{
    5050    self = [super init];
     
    5252        return nil;
    5353
    54     ASSERT(customProtocolManagerProxy);
    5554    ASSERT(request);
    56     _customProtocolManagerProxy = customProtocolManagerProxy;
     55    _customProtocolManagerProxy = makeWeakPtr(customProtocolManagerProxy);
    5756    _customProtocolID = customProtocolID;
    5857    _storagePolicy = NSURLCacheStorageNotAllowed;
     
    7372}
    7473
    75 - (void)customProtocolManagerProxyDestroyed
     74- (void)cancel
    7675{
    7776    ASSERT(_customProtocolManagerProxy);
     
    8281- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    8382{
     83    if (!_customProtocolManagerProxy)
     84        return;
     85
    8486    WebCore::ResourceError coreError(error);
    8587    _customProtocolManagerProxy->didFailWithError(_customProtocolID, coreError);
     
    9698- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    9799{
     100    if (!_customProtocolManagerProxy)
     101        return;
     102
    98103    WebCore::ResourceResponse coreResponse(response);
    99104    _customProtocolManagerProxy->didReceiveResponse(_customProtocolID, coreResponse, _storagePolicy);
     
    102107- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    103108{
     109    if (!_customProtocolManagerProxy)
     110        return;
     111
    104112    IPC::DataReference coreData(static_cast<const uint8_t*>([data bytes]), [data length]);
    105113    _customProtocolManagerProxy->didLoadData(_customProtocolID, coreData);
     
    108116- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
    109117{
     118    if (!_customProtocolManagerProxy)
     119        return nil;
     120
    110121    if (redirectResponse) {
    111122        _customProtocolManagerProxy->wasRedirectedToRequest(_customProtocolID, request, redirectResponse);
     
    117128- (void)connectionDidFinishLoading:(NSURLConnection *)connection
    118129{
     130    if (!_customProtocolManagerProxy)
     131        return;
     132
    119133    _customProtocolManagerProxy->didFinishLoading(_customProtocolID);
    120134    _customProtocolManagerProxy->stopLoading(_customProtocolID);
     
    132146        return;
    133147
    134     WKCustomProtocolLoader *loader = [[WKCustomProtocolLoader alloc] initWithLegacyCustomProtocolManagerProxy:&manager customProtocolID:customProtocolID request:request];
     148    WKCustomProtocolLoader *loader = [[WKCustomProtocolLoader alloc] initWithLegacyCustomProtocolManagerProxy:manager customProtocolID:customProtocolID request:request];
    135149    ASSERT(loader);
    136150    ASSERT(!m_loaderMap.contains(customProtocolID));
     
    149163        auto loader = m_loaderMap.take(m_loaderMap.begin()->key);
    150164        ASSERT(loader);
    151         [loader customProtocolManagerProxyDestroyed];
     165        [loader cancel];
    152166    }
    153167}
  • trunk/Source/WebKit/UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.h

    r219664 r244246  
    2828#include "MessageReceiver.h"
    2929
     30#include <wtf/WeakPtr.h>
     31
    3032#if PLATFORM(COCOA)
    3133#include <wtf/HashMap.h>
     
    4850class NetworkProcessProxy;
    4951
    50 class LegacyCustomProtocolManagerProxy : public IPC::MessageReceiver {
     52class LegacyCustomProtocolManagerProxy : public CanMakeWeakPtr<LegacyCustomProtocolManagerProxy>, public IPC::MessageReceiver {
    5153public:
    5254    LegacyCustomProtocolManagerProxy(NetworkProcessProxy&);
Note: See TracChangeset for help on using the changeset viewer.