Title: [226610] trunk
Revision
226610
Author
[email protected]
Date
2018-01-08 19:27:20 -0800 (Mon, 08 Jan 2018)

Log Message

Add WKNavigationDelegate SPI exposing WebProcess crash reason
https://bugs.webkit.org/show_bug.cgi?id=181410
<rdar://problem/36167199>

Reviewed by Wenson Hsieh.

Source/WebKit:

We exposed it in the C SPI.

* UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h:
* UIProcess/Cocoa/NavigationState.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::setNavigationDelegate):
(WebKit::toWKProcessTerminationReason):
(WebKit::NavigationState::NavigationClient::processDidTerminate):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm:
(-[CrashReasonDelegate _webView:webContentProcessDidTerminateWithReason:]):
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (226609 => 226610)


--- trunk/Source/WebKit/ChangeLog	2018-01-09 03:26:18 UTC (rev 226609)
+++ trunk/Source/WebKit/ChangeLog	2018-01-09 03:27:20 UTC (rev 226610)
@@ -1,5 +1,22 @@
 2018-01-08  Alex Christensen  <[email protected]>
 
+        Add WKNavigationDelegate SPI exposing WebProcess crash reason
+        https://bugs.webkit.org/show_bug.cgi?id=181410
+        <rdar://problem/36167199>
+
+        Reviewed by Wenson Hsieh.
+
+        We exposed it in the C SPI.
+
+        * UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h:
+        * UIProcess/Cocoa/NavigationState.h:
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::setNavigationDelegate):
+        (WebKit::toWKProcessTerminationReason):
+        (WebKit::NavigationState::NavigationClient::processDidTerminate):
+
+2018-01-08  Alex Christensen  <[email protected]>
+
         Make ObjC SPI equivalent to WKPageNavigationClient.decidePolicyForPluginLoad
         https://bugs.webkit.org/show_bug.cgi?id=181413
         <rdar://problem/36169005>

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h (226609 => 226610)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h	2018-01-09 03:26:18 UTC (rev 226609)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h	2018-01-09 03:27:20 UTC (rev 226610)
@@ -48,6 +48,13 @@
 } WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 #endif
 
+typedef NS_ENUM(NSInteger, _WKProcessTerminationReason) {
+    _WKProcessTerminationReasonExceededMemoryLimit,
+    _WKProcessTerminationReasonExceededCPULimit,
+    _WKProcessTerminationReasonRequestedByClient,
+    _WKProcessTerminationReasonCrash,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 static const WKNavigationActionPolicy _WKNavigationActionPolicyDownload = (WKNavigationActionPolicy)(WKNavigationActionPolicyAllow + 1);
 static const WKNavigationActionPolicy WK_API_AVAILABLE(macosx(10.11), ios(9.0)) _WKNavigationActionPolicyAllowWithoutTryingAppLink = (WKNavigationActionPolicy)(WKNavigationActionPolicyAllow + 2);
 
@@ -89,6 +96,7 @@
 - (void)_webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 - (void)_webView:(WKWebView *)webView URL:(NSURL *)url contentRuleListIdentifiers:(NSArray<NSString *> *)identifiers notifications:(NSArray<NSString *> *)notifications WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_webView:(WKWebView *)webView webContentProcessDidTerminateWithReason:(_WKProcessTerminationReason)reason WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 #if TARGET_OS_IPHONE
 - (void)_webView:(WKWebView *)webView didStartLoadForQuickLookDocumentInMainFrameWithFileName:(NSString *)fileName uti:(NSString *)uti;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h (226609 => 226610)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2018-01-09 03:26:18 UTC (rev 226609)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2018-01-09 03:27:20 UTC (rev 226610)
@@ -198,6 +198,7 @@
         bool webViewRenderingProgressDidChange : 1;
         bool webViewDidReceiveAuthenticationChallengeCompletionHandler : 1;
         bool webViewWebContentProcessDidTerminate : 1;
+        bool webViewWebContentProcessDidTerminateWithReason : 1;
         bool webViewCanAuthenticateAgainstProtectionSpace : 1;
         bool webViewDidReceiveAuthenticationChallenge : 1;
         bool webViewWebProcessDidCrash : 1;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (226609 => 226610)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-01-09 03:26:18 UTC (rev 226609)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-01-09 03:27:20 UTC (rev 226610)
@@ -162,6 +162,7 @@
     m_navigationDelegateMethods.webViewRenderingProgressDidChange = [delegate respondsToSelector:@selector(_webView:renderingProgressDidChange:)];
     m_navigationDelegateMethods.webViewDidReceiveAuthenticationChallengeCompletionHandler = [delegate respondsToSelector:@selector(webView:didReceiveAuthenticationChallenge:completionHandler:)];
     m_navigationDelegateMethods.webViewWebContentProcessDidTerminate = [delegate respondsToSelector:@selector(webViewWebContentProcessDidTerminate:)];
+    m_navigationDelegateMethods.webViewWebContentProcessDidTerminateWithReason = [delegate respondsToSelector:@selector(_webView:webContentProcessDidTerminateWithReason:)];
     m_navigationDelegateMethods.webViewCanAuthenticateAgainstProtectionSpace = [delegate respondsToSelector:@selector(_webView:canAuthenticateAgainstProtectionSpace:)];
     m_navigationDelegateMethods.webViewDidReceiveAuthenticationChallenge = [delegate respondsToSelector:@selector(_webView:didReceiveAuthenticationChallenge:)];
     m_navigationDelegateMethods.webViewWebProcessDidCrash = [delegate respondsToSelector:@selector(_webViewWebProcessDidCrash:)];
@@ -939,9 +940,27 @@
 #pragma clang diagnostic pop
 }
 
-void NavigationState::NavigationClient::processDidTerminate(WebPageProxy& page, ProcessTerminationReason)
+static _WKProcessTerminationReason wkProcessTerminationReason(ProcessTerminationReason reason)
 {
-    if (!m_navigationState.m_navigationDelegateMethods.webViewWebContentProcessDidTerminate && !m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidCrash)
+    switch (reason) {
+    case ProcessTerminationReason::ExceededMemoryLimit:
+        return _WKProcessTerminationReasonExceededMemoryLimit;
+    case ProcessTerminationReason::ExceededCPULimit:
+        return _WKProcessTerminationReasonExceededCPULimit;
+    case ProcessTerminationReason::RequestedByClient:
+        return _WKProcessTerminationReasonRequestedByClient;
+    case ProcessTerminationReason::Crash:
+        return _WKProcessTerminationReasonCrash;
+    }
+    ASSERT_NOT_REACHED();
+    return _WKProcessTerminationReasonCrash;
+}
+
+void NavigationState::NavigationClient::processDidTerminate(WebPageProxy& page, ProcessTerminationReason reason)
+{
+    if (!m_navigationState.m_navigationDelegateMethods.webViewWebContentProcessDidTerminate
+        && !m_navigationState.m_navigationDelegateMethods.webViewWebContentProcessDidTerminateWithReason
+        && !m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidCrash)
         return;
 
     auto navigationDelegate = m_navigationState.m_navigationDelegate.get();
@@ -948,6 +967,11 @@
     if (!navigationDelegate)
         return;
 
+    if (m_navigationState.m_navigationDelegateMethods.webViewWebContentProcessDidTerminateWithReason) {
+        [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate.get()) _webView:m_navigationState.m_webView webContentProcessDidTerminateWithReason:wkProcessTerminationReason(reason)];
+        return;
+    }
+
     // We prefer webViewWebContentProcessDidTerminate: over _webViewWebProcessDidCrash:.
     if (m_navigationState.m_navigationDelegateMethods.webViewWebContentProcessDidTerminate) {
         [navigationDelegate webViewWebContentProcessDidTerminate:m_navigationState.m_webView];
@@ -954,8 +978,8 @@
         return;
     }
 
-    if (m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidCrash)
-        [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate.get()) _webViewWebProcessDidCrash:m_navigationState.m_webView];
+    ASSERT(m_navigationState.m_navigationDelegateMethods.webViewWebProcessDidCrash);
+    [static_cast<id <WKNavigationDelegatePrivate>>(navigationDelegate.get()) _webViewWebProcessDidCrash:m_navigationState.m_webView];
 }
 
 void NavigationState::NavigationClient::processDidBecomeResponsive(WebPageProxy& page)

Modified: trunk/Tools/ChangeLog (226609 => 226610)


--- trunk/Tools/ChangeLog	2018-01-09 03:26:18 UTC (rev 226609)
+++ trunk/Tools/ChangeLog	2018-01-09 03:27:20 UTC (rev 226610)
@@ -1,5 +1,17 @@
 2018-01-08  Alex Christensen  <[email protected]>
 
+        Add WKNavigationDelegate SPI exposing WebProcess crash reason
+        https://bugs.webkit.org/show_bug.cgi?id=181410
+        <rdar://problem/36167199>
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm:
+        (-[CrashReasonDelegate _webView:webContentProcessDidTerminateWithReason:]):
+        (TEST):
+
+2018-01-08  Alex Christensen  <[email protected]>
+
         Add SPI for WKOpenPanelParameters._acceptedMIMETypes and _acceptedFileExtensions
         https://bugs.webkit.org/show_bug.cgi?id=181408
         <rdar://problem/35884960>

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm (226609 => 226610)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm	2018-01-09 03:26:18 UTC (rev 226609)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm	2018-01-09 03:27:20 UTC (rev 226610)
@@ -144,6 +144,32 @@
     TestWebKitAPI::Util::run(&isDone);
 }
 
+@interface CrashReasonDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation CrashReasonDelegate
+
+- (void)_webView:(WKWebView *)webView webContentProcessDidTerminateWithReason:(_WKProcessTerminationReason)reason
+{
+    EXPECT_EQ(reason, _WKProcessTerminationReasonRequestedByClient);
+    isDone = true;
+}
+
+@end
+
+TEST(WKNavigation, CrashReason)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    
+    auto delegate = adoptNS([[CrashReasonDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+    
+    [webView loadHTMLString:@"<html>start the web process</html>" baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+    [webView _killWebContentProcessAndResetState];
+    
+    TestWebKitAPI::Util::run(&isDone);
+}
+
 @interface DecidePolicyForPageCacheNavigationDelegate : NSObject <WKNavigationDelegate>
 @property (nonatomic) BOOL decidedPolicyForBackForwardNavigation;
 @end
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to