Title: [244246] trunk/Source/WebKit
- Revision
- 244246
- Author
- [email protected]
- Date
- 2019-04-14 09:08:23 -0700 (Sun, 14 Apr 2019)
Log 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:
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (244245 => 244246)
--- trunk/Source/WebKit/ChangeLog 2019-04-14 13:50:01 UTC (rev 244245)
+++ trunk/Source/WebKit/ChangeLog 2019-04-14 16:08:23 UTC (rev 244246)
@@ -1,3 +1,30 @@
+2019-04-14 Andy Estes <[email protected]>
+
+ [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:
+
2019-04-14 Don Olmstead <[email protected]>
[CMake] _javascript_Core derived sources should only be referenced inside _javascript_Core
Modified: trunk/Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm (244245 => 244246)
--- trunk/Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm 2019-04-14 13:50:01 UTC (rev 244245)
+++ trunk/Source/WebKit/UIProcess/Cocoa/LegacyCustomProtocolManagerClient.mm 2019-04-14 16:08:23 UTC (rev 244246)
@@ -34,26 +34,25 @@
@interface WKCustomProtocolLoader : NSObject <NSURLConnectionDelegate> {
@private
- WebKit::LegacyCustomProtocolManagerProxy* _customProtocolManagerProxy;
+ WeakPtr<WebKit::LegacyCustomProtocolManagerProxy> _customProtocolManagerProxy;
uint64_t _customProtocolID;
NSURLCacheStoragePolicy _storagePolicy;
NSURLConnection *_urlConnection;
}
-- (id)initWithLegacyCustomProtocolManagerProxy:(WebKit::LegacyCustomProtocolManagerProxy*)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request;
-- (void)customProtocolManagerProxyDestroyed;
+- (id)initWithLegacyCustomProtocolManagerProxy:(WebKit::LegacyCustomProtocolManagerProxy&)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request;
+- (void)cancel;
@end
@implementation WKCustomProtocolLoader
-- (id)initWithLegacyCustomProtocolManagerProxy:(WebKit::LegacyCustomProtocolManagerProxy*)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request
+- (id)initWithLegacyCustomProtocolManagerProxy:(WebKit::LegacyCustomProtocolManagerProxy&)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request
{
self = [super init];
if (!self)
return nil;
- ASSERT(customProtocolManagerProxy);
ASSERT(request);
- _customProtocolManagerProxy = customProtocolManagerProxy;
+ _customProtocolManagerProxy = makeWeakPtr(customProtocolManagerProxy);
_customProtocolID = customProtocolID;
_storagePolicy = NSURLCacheStorageNotAllowed;
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
@@ -72,7 +71,7 @@
[super dealloc];
}
-- (void)customProtocolManagerProxyDestroyed
+- (void)cancel
{
ASSERT(_customProtocolManagerProxy);
_customProtocolManagerProxy = nullptr;
@@ -81,6 +80,9 @@
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
+ if (!_customProtocolManagerProxy)
+ return;
+
WebCore::ResourceError coreError(error);
_customProtocolManagerProxy->didFailWithError(_customProtocolID, coreError);
_customProtocolManagerProxy->stopLoading(_customProtocolID);
@@ -95,6 +97,9 @@
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
+ if (!_customProtocolManagerProxy)
+ return;
+
WebCore::ResourceResponse coreResponse(response);
_customProtocolManagerProxy->didReceiveResponse(_customProtocolID, coreResponse, _storagePolicy);
}
@@ -101,6 +106,9 @@
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
+ if (!_customProtocolManagerProxy)
+ return;
+
IPC::DataReference coreData(static_cast<const uint8_t*>([data bytes]), [data length]);
_customProtocolManagerProxy->didLoadData(_customProtocolID, coreData);
}
@@ -107,6 +115,9 @@
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
+ if (!_customProtocolManagerProxy)
+ return nil;
+
if (redirectResponse) {
_customProtocolManagerProxy->wasRedirectedToRequest(_customProtocolID, request, redirectResponse);
return nil;
@@ -116,6 +127,9 @@
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
+ if (!_customProtocolManagerProxy)
+ return;
+
_customProtocolManagerProxy->didFinishLoading(_customProtocolID);
_customProtocolManagerProxy->stopLoading(_customProtocolID);
}
@@ -131,7 +145,7 @@
if (!request)
return;
- WKCustomProtocolLoader *loader = [[WKCustomProtocolLoader alloc] initWithLegacyCustomProtocolManagerProxy:&manager customProtocolID:customProtocolID request:request];
+ WKCustomProtocolLoader *loader = [[WKCustomProtocolLoader alloc] initWithLegacyCustomProtocolManagerProxy:manager customProtocolID:customProtocolID request:request];
ASSERT(loader);
ASSERT(!m_loaderMap.contains(customProtocolID));
m_loaderMap.add(customProtocolID, loader);
@@ -148,7 +162,7 @@
while (!m_loaderMap.isEmpty()) {
auto loader = m_loaderMap.take(m_loaderMap.begin()->key);
ASSERT(loader);
- [loader customProtocolManagerProxyDestroyed];
+ [loader cancel];
}
}
Modified: trunk/Source/WebKit/UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.h (244245 => 244246)
--- trunk/Source/WebKit/UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.h 2019-04-14 13:50:01 UTC (rev 244245)
+++ trunk/Source/WebKit/UIProcess/Network/CustomProtocols/LegacyCustomProtocolManagerProxy.h 2019-04-14 16:08:23 UTC (rev 244246)
@@ -27,6 +27,8 @@
#include "MessageReceiver.h"
+#include <wtf/WeakPtr.h>
+
#if PLATFORM(COCOA)
#include <wtf/HashMap.h>
#include <wtf/RetainPtr.h>
@@ -47,7 +49,7 @@
class NetworkProcessProxy;
-class LegacyCustomProtocolManagerProxy : public IPC::MessageReceiver {
+class LegacyCustomProtocolManagerProxy : public CanMakeWeakPtr<LegacyCustomProtocolManagerProxy>, public IPC::MessageReceiver {
public:
LegacyCustomProtocolManagerProxy(NetworkProcessProxy&);
~LegacyCustomProtocolManagerProxy();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes