Title: [231646] branches/safari-605-branch
Revision
231646
Author
[email protected]
Date
2018-05-10 10:43:51 -0700 (Thu, 10 May 2018)

Log Message

Cherry-pick r226610. rdar://problem/39987479

    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):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226610 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-605-branch/Source/WebKit/ChangeLog (231645 => 231646)


--- branches/safari-605-branch/Source/WebKit/ChangeLog	2018-05-10 17:43:48 UTC (rev 231645)
+++ branches/safari-605-branch/Source/WebKit/ChangeLog	2018-05-10 17:43:51 UTC (rev 231646)
@@ -1,5 +1,53 @@
 2018-05-10  Jason Marcell  <[email protected]>
 
+        Cherry-pick r226610. rdar://problem/39987479
+
+    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):
+    
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226610 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-05-10  Jason Marcell  <[email protected]>
+
         Apply patch. rdar://problem/39987479
 
     Load hangs if the WebProcess fails to launch https://bugs.webkit.org/show_bug.cgi?id=185225 <rdar://problem/38249058>

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h (231645 => 231646)


--- branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h	2018-05-10 17:43:48 UTC (rev 231645)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKNavigationDelegatePrivate.h	2018-05-10 17:43:51 UTC (rev 231646)
@@ -41,6 +41,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);
 
@@ -82,6 +89,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: branches/safari-605-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.h (231645 => 231646)


--- branches/safari-605-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2018-05-10 17:43:48 UTC (rev 231645)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2018-05-10 17:43:51 UTC (rev 231646)
@@ -197,6 +197,7 @@
         bool webViewRenderingProgressDidChange : 1;
         bool webViewDidReceiveAuthenticationChallengeCompletionHandler : 1;
         bool webViewWebContentProcessDidTerminate : 1;
+        bool webViewWebContentProcessDidTerminateWithReason : 1;
         bool webViewCanAuthenticateAgainstProtectionSpace : 1;
         bool webViewDidReceiveAuthenticationChallenge : 1;
         bool webViewWebProcessDidCrash : 1;

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (231645 => 231646)


--- branches/safari-605-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-05-10 17:43:48 UTC (rev 231645)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-05-10 17:43:51 UTC (rev 231646)
@@ -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:)];
@@ -894,9 +895,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();
@@ -903,6 +922,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];
@@ -909,8 +933,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: branches/safari-605-branch/Tools/ChangeLog (231645 => 231646)


--- branches/safari-605-branch/Tools/ChangeLog	2018-05-10 17:43:48 UTC (rev 231645)
+++ branches/safari-605-branch/Tools/ChangeLog	2018-05-10 17:43:51 UTC (rev 231646)
@@ -1,5 +1,48 @@
 2018-05-10  Jason Marcell  <[email protected]>
 
+        Cherry-pick r226610. rdar://problem/39987479
+
+    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):
+    
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226610 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-05-10  Jason Marcell  <[email protected]>
+
         Apply patch. rdar://problem/39987479
 
     Load hangs if the WebProcess fails to launch https://bugs.webkit.org/show_bug.cgi?id=185225 <rdar://problem/38249058>

Modified: branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm (231645 => 231646)


--- branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm	2018-05-10 17:43:48 UTC (rev 231645)
+++ branches/safari-605-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/Navigation.mm	2018-05-10 17:43:51 UTC (rev 231646)
@@ -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