Title: [211915] trunk
- Revision
- 211915
- Author
- aes...@apple.com
- Date
- 2017-02-08 17:57:21 -0800 (Wed, 08 Feb 2017)
Log Message
Custom protocols should not continue loading after a network process crash
https://bugs.webkit.org/show_bug.cgi?id=168028
<rdar://problem/27607520>
Reviewed by Brady Eidson.
Source/WebKit2:
WKCustomProtocolLoaders are meant to be owned by CustomProtocolManagerProxy and have their
loads cancelled when CustomProtocolManagerProxy is destroyed. However, WKCustomProtocolLoader
creates a NSURLConnection for which it is the client, so NSURLConnection retains it for the
duration of the load.
These loaders should be explicitly cancelled when their CustomProtocolManagerProxy is destroyed.
New API test: WebKit2CustomProtocolsTest.CloseDuringCustomProtocolLoad
* UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm:
(-[WKCustomProtocolLoader customProtocolManagerProxyDestroyed]): Added. Cancels the
_urlConnection and sets _customProtocolManagerProxy to nullptr.
(WebKit::CustomProtocolManagerProxy::~CustomProtocolManagerProxy):
Called -customProtocolManagerProxyDestroyed on every loader in m_loaderMap.
Tools:
* TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm:
(processGroup):
(-[CloseWhileStartingProtocol startLoading]):
(-[CloseWhileStartingProtocol stopLoading]):
(TestWebKitAPI::runTest):
(TestWebKitAPI::TEST):
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (211914 => 211915)
--- trunk/Source/WebKit2/ChangeLog 2017-02-09 01:56:26 UTC (rev 211914)
+++ trunk/Source/WebKit2/ChangeLog 2017-02-09 01:57:21 UTC (rev 211915)
@@ -1,3 +1,26 @@
+2017-02-08 Andy Estes <aes...@apple.com>
+
+ Custom protocols should not continue loading after a network process crash
+ https://bugs.webkit.org/show_bug.cgi?id=168028
+ <rdar://problem/27607520>
+
+ Reviewed by Brady Eidson.
+
+ WKCustomProtocolLoaders are meant to be owned by CustomProtocolManagerProxy and have their
+ loads cancelled when CustomProtocolManagerProxy is destroyed. However, WKCustomProtocolLoader
+ creates a NSURLConnection for which it is the client, so NSURLConnection retains it for the
+ duration of the load.
+
+ These loaders should be explicitly cancelled when their CustomProtocolManagerProxy is destroyed.
+
+ New API test: WebKit2CustomProtocolsTest.CloseDuringCustomProtocolLoad
+
+ * UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm:
+ (-[WKCustomProtocolLoader customProtocolManagerProxyDestroyed]): Added. Cancels the
+ _urlConnection and sets _customProtocolManagerProxy to nullptr.
+ (WebKit::CustomProtocolManagerProxy::~CustomProtocolManagerProxy):
+ Called -customProtocolManagerProxyDestroyed on every loader in m_loaderMap.
+
2017-02-08 Dan Bernstein <m...@apple.com>
[Cocoa] WKRemoteObjectCoder doesn’t handle CGSize
Modified: trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm (211914 => 211915)
--- trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm 2017-02-09 01:56:26 UTC (rev 211914)
+++ trunk/Source/WebKit2/UIProcess/Network/CustomProtocols/mac/CustomProtocolManagerProxyMac.mm 2017-02-09 01:57:21 UTC (rev 211915)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -49,6 +49,7 @@
NSURLConnection *_urlConnection;
}
- (id)initWithCustomProtocolManagerProxy:(CustomProtocolManagerProxy*)customProtocolManagerProxy customProtocolID:(uint64_t)customProtocolID request:(NSURLRequest *)request connection:(Connection *)connection;
+- (void)customProtocolManagerProxyDestroyed;
@end
@implementation WKCustomProtocolLoader
@@ -84,6 +85,13 @@
[super dealloc];
}
+- (void)customProtocolManagerProxyDestroyed
+{
+ ASSERT(_customProtocolManagerProxy);
+ _customProtocolManagerProxy = nullptr;
+ [_urlConnection cancel];
+}
+
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
ResourceError coreError(error);
@@ -139,6 +147,8 @@
CustomProtocolManagerProxy::~CustomProtocolManagerProxy()
{
+ for (auto& loader : m_loaderMap)
+ [loader.value customProtocolManagerProxyDestroyed];
m_childProcessProxy->removeMessageReceiver(Messages::CustomProtocolManagerProxy::messageReceiverName());
}
Modified: trunk/Tools/ChangeLog (211914 => 211915)
--- trunk/Tools/ChangeLog 2017-02-09 01:56:26 UTC (rev 211914)
+++ trunk/Tools/ChangeLog 2017-02-09 01:57:21 UTC (rev 211915)
@@ -1,3 +1,18 @@
+2017-02-08 Andy Estes <aes...@apple.com>
+
+ Custom protocols should not continue loading after a network process crash
+ https://bugs.webkit.org/show_bug.cgi?id=168028
+ <rdar://problem/27607520>
+
+ Reviewed by Brady Eidson.
+
+ * TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm:
+ (processGroup):
+ (-[CloseWhileStartingProtocol startLoading]):
+ (-[CloseWhileStartingProtocol stopLoading]):
+ (TestWebKitAPI::runTest):
+ (TestWebKitAPI::TEST):
+
2017-02-08 Dan Bernstein <m...@apple.com>
[Cocoa] WKRemoteObjectCoder doesn’t handle CGSize
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm (211914 => 211915)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm 2017-02-09 01:56:26 UTC (rev 211914)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2ObjC/CustomProtocolsTest.mm 2017-02-09 01:57:21 UTC (rev 211915)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -32,11 +32,13 @@
#import "PlatformUtilities.h"
#import "TestBrowsingContextLoadDelegate.h"
#import "TestProtocol.h"
+#import <WebKit/WKContextPrivate.h>
+#import <WebKit/WKProcessGroupPrivate.h>
#import <wtf/RetainPtr.h>
#if WK_API_ENABLED && PLATFORM(MAC)
-static bool testFinished = false;
+static bool testFinished;
@interface CustomProtocolsLoadDelegate : NSObject <WKBrowsingContextLoadDelegate>
@end
@@ -66,23 +68,70 @@
@end
+static WKProcessGroup *processGroup()
+{
+ static WKProcessGroup *processGroup = [[WKProcessGroup alloc] init];
+ return processGroup;
+}
+
+@interface CloseWhileStartingProtocol : TestProtocol
+@end
+
+@implementation CloseWhileStartingProtocol
+
+- (void)startLoading
+{
+ dispatch_async(dispatch_get_main_queue(), ^ {
+ WKContextClientV0 client;
+ memset(&client, 0, sizeof(client));
+ client.base.clientInfo = self;
+ client.networkProcessDidCrash = [](WKContextRef context, const void* clientInfo) {
+ auto protocol = (CloseWhileStartingProtocol *)clientInfo;
+ [protocol.client URLProtocol:protocol didFailWithError:[NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil]];
+ };
+ WKContextSetClient([processGroup() _contextRef], &client.base);
+
+ kill(WKContextGetNetworkProcessIdentifier([processGroup() _contextRef]), SIGKILL);
+ [self.client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:nil]];
+ });
+}
+
+- (void)stopLoading
+{
+ dispatch_async(dispatch_get_main_queue(), ^ {
+ testFinished = true;
+ });
+}
+
+@end
+
namespace TestWebKitAPI {
-TEST(WebKit2CustomProtocolsTest, MainResource)
+static void runTest()
{
- [TestProtocol registerWithScheme:@"http"];
-
- RetainPtr<WKProcessGroup> processGroup = adoptNS([[WKProcessGroup alloc] init]);
RetainPtr<WKBrowsingContextGroup> browsingContextGroup = adoptNS([[WKBrowsingContextGroup alloc] initWithIdentifier:@"TestIdentifier"]);
- RetainPtr<WKView> wkView = adoptNS([[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup.get() browsingContextGroup:browsingContextGroup.get()]);
+ RetainPtr<WKView> wkView = adoptNS([[WKView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) processGroup:processGroup() browsingContextGroup:browsingContextGroup.get()]);
RetainPtr<CustomProtocolsLoadDelegate> loadDelegate = adoptNS([[CustomProtocolsLoadDelegate alloc] init]);
[wkView browsingContextController].loadDelegate = loadDelegate.get();
[[wkView browsingContextController] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@://redirect?test", [TestProtocol scheme]]]]];
Util::run(&testFinished);
+}
+
+TEST(WebKit2CustomProtocolsTest, MainResource)
+{
+ [TestProtocol registerWithScheme:@"http"];
+ runTest();
[TestProtocol unregister];
}
+TEST(WebKit2CustomProtocolsTest, CloseDuringCustomProtocolLoad)
+{
+ [CloseWhileStartingProtocol registerWithScheme:@"http"];
+ runTest();
+ [CloseWhileStartingProtocol unregister];
+}
+
} // namespace TestWebKitAPI
#endif // WK_API_ENABLED
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes