Title: [249697] branches/safari-608-branch
Revision
249697
Author
alanc...@apple.com
Date
2019-09-09 20:19:56 -0700 (Mon, 09 Sep 2019)

Log Message

Cherry-pick r249584. rdar://problem/55202935

    Marking up a note on iOS results in a PDF with no contents
    https://bugs.webkit.org/show_bug.cgi?id=201530
    <rdar://problem/53686019>

    Reviewed by Andy Estes.

    Source/WebKit:

    * Platform/IPC/Connection.cpp:
    (IPC::Connection::Connection):
    (IPC::Connection::waitForMessage):
    (IPC::Connection::connectionDidClose):
    * Platform/IPC/Connection.h:
    If the main thread is blocked when the Web Content process dies, and
    something eventually calls waitForAndDispatchImmediately without
    returning control to the main run loop, we will wait for the full timeout,
    because a) the code to mark the connection invalid is dispatched
    to the main thread, and b) the secondary thread that is informed of
    the Web Content process dying did not yet have a "waiting for" message
    to mark as interrupted (because it wasn't waiting yet).

    Fix this race by adding a bit that is set under the waitForMessage lock
    on the secondary thread when the connection is invalidated, identically
    to m_shouldWaitForSyncReplies, which solves the same problem for sync
    messages.

    Read the new bit when we are about to start waiting, and bail if it is set.
    It's OK to not read it inside the loop because we are guaranteed to have
    waitForMessage set at that point, so the normal interruption bit will work.

    * UIProcess/ios/WKContentView.mm:
    (-[WKContentView _processDidExit]):
    Reset _isPrintingToPDF; the Web Content process is never going to get
    back to us if it crashes.

    (-[WKContentView _wk_pageCountForPrintFormatter:]):
    Do not bail from starting a printing operation if one is already occurring.
    This fixes the original bug, because Markup ends up invalidating the page
    count at least one extra time before asking for the printed document.
    Instead of maintaining the fragile requirement that you cannot recompute
    the page count while printing, just let it happen. In order to make this
    work safely, synchronously wait for the previous printed result before
    continuing with the next print.

    We could do more coalescing here if need be, but calls to -_recalcPageCount
    are not high in volume.

    Tools:

    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
    * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm:
    Add some tests for WKWebViewPrintFormatter; specifically that it is
    possible to _recalcPageCount twice in quick succession, and that
    we don't hang if we start painting the printed content immediately
    after a Web Content process crash.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-608-branch/Source/WebKit/ChangeLog (249696 => 249697)


--- branches/safari-608-branch/Source/WebKit/ChangeLog	2019-09-10 03:19:52 UTC (rev 249696)
+++ branches/safari-608-branch/Source/WebKit/ChangeLog	2019-09-10 03:19:56 UTC (rev 249697)
@@ -1,5 +1,114 @@
 2019-09-09  Kocsen Chung  <kocsen_ch...@apple.com>
 
+        Cherry-pick r249584. rdar://problem/55202935
+
+    Marking up a note on iOS results in a PDF with no contents
+    https://bugs.webkit.org/show_bug.cgi?id=201530
+    <rdar://problem/53686019>
+    
+    Reviewed by Andy Estes.
+    
+    Source/WebKit:
+    
+    * Platform/IPC/Connection.cpp:
+    (IPC::Connection::Connection):
+    (IPC::Connection::waitForMessage):
+    (IPC::Connection::connectionDidClose):
+    * Platform/IPC/Connection.h:
+    If the main thread is blocked when the Web Content process dies, and
+    something eventually calls waitForAndDispatchImmediately without
+    returning control to the main run loop, we will wait for the full timeout,
+    because a) the code to mark the connection invalid is dispatched
+    to the main thread, and b) the secondary thread that is informed of
+    the Web Content process dying did not yet have a "waiting for" message
+    to mark as interrupted (because it wasn't waiting yet).
+    
+    Fix this race by adding a bit that is set under the waitForMessage lock
+    on the secondary thread when the connection is invalidated, identically
+    to m_shouldWaitForSyncReplies, which solves the same problem for sync
+    messages.
+    
+    Read the new bit when we are about to start waiting, and bail if it is set.
+    It's OK to not read it inside the loop because we are guaranteed to have
+    waitForMessage set at that point, so the normal interruption bit will work.
+    
+    * UIProcess/ios/WKContentView.mm:
+    (-[WKContentView _processDidExit]):
+    Reset _isPrintingToPDF; the Web Content process is never going to get
+    back to us if it crashes.
+    
+    (-[WKContentView _wk_pageCountForPrintFormatter:]):
+    Do not bail from starting a printing operation if one is already occurring.
+    This fixes the original bug, because Markup ends up invalidating the page
+    count at least one extra time before asking for the printed document.
+    Instead of maintaining the fragile requirement that you cannot recompute
+    the page count while printing, just let it happen. In order to make this
+    work safely, synchronously wait for the previous printed result before
+    continuing with the next print.
+    
+    We could do more coalescing here if need be, but calls to -_recalcPageCount
+    are not high in volume.
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm:
+    Add some tests for WKWebViewPrintFormatter; specifically that it is
+    possible to _recalcPageCount twice in quick succession, and that
+    we don't hang if we start painting the printed content immediately
+    after a Web Content process crash.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249584 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-09-06  Tim Horton  <timothy_hor...@apple.com>
+
+            Marking up a note on iOS results in a PDF with no contents
+            https://bugs.webkit.org/show_bug.cgi?id=201530
+            <rdar://problem/53686019>
+
+            Reviewed by Andy Estes.
+
+            * Platform/IPC/Connection.cpp:
+            (IPC::Connection::Connection):
+            (IPC::Connection::waitForMessage):
+            (IPC::Connection::connectionDidClose):
+            * Platform/IPC/Connection.h:
+            If the main thread is blocked when the Web Content process dies, and
+            something eventually calls waitForAndDispatchImmediately without
+            returning control to the main run loop, we will wait for the full timeout,
+            because a) the code to mark the connection invalid is dispatched
+            to the main thread, and b) the secondary thread that is informed of
+            the Web Content process dying did not yet have a "waiting for" message
+            to mark as interrupted (because it wasn't waiting yet).
+
+            Fix this race by adding a bit that is set under the waitForMessage lock
+            on the secondary thread when the connection is invalidated, identically
+            to m_shouldWaitForSyncReplies, which solves the same problem for sync
+            messages.
+
+            Read the new bit when we are about to start waiting, and bail if it is set.
+            It's OK to not read it inside the loop because we are guaranteed to have
+            waitForMessage set at that point, so the normal interruption bit will work.
+
+            * UIProcess/ios/WKContentView.mm:
+            (-[WKContentView _processDidExit]):
+            Reset _isPrintingToPDF; the Web Content process is never going to get
+            back to us if it crashes.
+
+            (-[WKContentView _wk_pageCountForPrintFormatter:]):
+            Do not bail from starting a printing operation if one is already occurring.
+            This fixes the original bug, because Markup ends up invalidating the page
+            count at least one extra time before asking for the printed document.
+            Instead of maintaining the fragile requirement that you cannot recompute
+            the page count while printing, just let it happen. In order to make this
+            work safely, synchronously wait for the previous printed result before
+            continuing with the next print.
+
+            We could do more coalescing here if need be, but calls to -_recalcPageCount
+            are not high in volume.
+
+2019-09-09  Kocsen Chung  <kocsen_ch...@apple.com>
+
         Cherry-pick r249514. rdar://problem/55182886
 
     MobileSafari may crash when invoking the C++ lambda in -[WKContentView _shareForWebView:]

Modified: branches/safari-608-branch/Source/WebKit/Platform/IPC/Connection.cpp (249696 => 249697)


--- branches/safari-608-branch/Source/WebKit/Platform/IPC/Connection.cpp	2019-09-10 03:19:52 UTC (rev 249696)
+++ branches/safari-608-branch/Source/WebKit/Platform/IPC/Connection.cpp	2019-09-10 03:19:56 UTC (rev 249697)
@@ -272,6 +272,7 @@
     , m_inDispatchMessageMarkedDispatchWhenWaitingForSyncReplyCount(0)
     , m_didReceiveInvalidMessage(false)
     , m_shouldWaitForSyncReplies(true)
+    , m_shouldWaitForMessages(true)
 {
     ASSERT(RunLoop::isMain());
     allConnections().add(m_uniqueID, this);
@@ -523,6 +524,11 @@
         if (m_waitingForMessage)
             return nullptr;
 
+        // If the connection is already invalidated, don't even start waiting.
+        // Once m_waitingForMessage is set, messageWaitingInterrupted will cover this instead.
+        if (!m_shouldWaitForMessages)
+            return nullptr;
+
         m_waitingForMessage = &waitingForMessage;
     }
 
@@ -845,6 +851,10 @@
 
     {
         std::lock_guard<Lock> lock(m_waitForMessageMutex);
+
+        ASSERT(m_shouldWaitForMessages);
+        m_shouldWaitForMessages = false;
+
         if (m_waitingForMessage)
             m_waitingForMessage->messageWaitingInterrupted = true;
     }

Modified: branches/safari-608-branch/Source/WebKit/Platform/IPC/Connection.h (249696 => 249697)


--- branches/safari-608-branch/Source/WebKit/Platform/IPC/Connection.h	2019-09-10 03:19:52 UTC (rev 249696)
+++ branches/safari-608-branch/Source/WebKit/Platform/IPC/Connection.h	2019-09-10 03:19:56 UTC (rev 249697)
@@ -365,6 +365,7 @@
 
     Lock m_syncReplyStateMutex;
     bool m_shouldWaitForSyncReplies;
+    bool m_shouldWaitForMessages;
     struct PendingSyncReply;
     Vector<PendingSyncReply> m_pendingSyncReplies;
 

Modified: branches/safari-608-branch/Source/WebKit/UIProcess/ios/WKContentView.mm (249696 => 249697)


--- branches/safari-608-branch/Source/WebKit/UIProcess/ios/WKContentView.mm	2019-09-10 03:19:52 UTC (rev 249696)
+++ branches/safari-608-branch/Source/WebKit/UIProcess/ios/WKContentView.mm	2019-09-10 03:19:56 UTC (rev 249697)
@@ -557,6 +557,8 @@
 #if HAVE(VISIBILITY_PROPAGATION_VIEW)
     [self _removeVisibilityPropagationView];
 #endif
+
+    _isPrintingToPDF = NO;
 }
 
 - (void)_processWillSwap
@@ -702,7 +704,7 @@
 - (NSUInteger)_wk_pageCountForPrintFormatter:(_WKWebViewPrintFormatter *)printFormatter
 {
     if (_isPrintingToPDF)
-        return 0;
+        [self _waitForDrawToPDFCallback];
 
     uint64_t frameID;
     if (_WKFrameHandle *handle = printFormatter.frameToPrint)
@@ -745,14 +747,21 @@
     });
 }
 
+- (BOOL)_waitForDrawToPDFCallback
+{
+    if (!_page->process().connection()->waitForAndDispatchImmediately<Messages::WebPageProxy::DrawToPDFCallback>(_page->webPageID(), Seconds::infinity())) {
+        ASSERT_NOT_REACHED();
+        return false;
+    }
+    ASSERT(!_isPrintingToPDF);
+    return true;
+}
+
 - (CGPDFDocumentRef)_wk_printedDocument
 {
     if (_isPrintingToPDF) {
-        if (!_page->process().connection()->waitForAndDispatchImmediately<Messages::WebPageProxy::DrawToPDFCallback>(_page->pageID(), Seconds::infinity())) {
-            ASSERT_NOT_REACHED();
+        if (![self _waitForDrawToPDFCallback])
             return nullptr;
-        }
-        ASSERT(!_isPrintingToPDF);
     }
 
     return _printedDocument.get();

Modified: branches/safari-608-branch/Tools/ChangeLog (249696 => 249697)


--- branches/safari-608-branch/Tools/ChangeLog	2019-09-10 03:19:52 UTC (rev 249696)
+++ branches/safari-608-branch/Tools/ChangeLog	2019-09-10 03:19:56 UTC (rev 249697)
@@ -1,5 +1,82 @@
 2019-09-09  Kocsen Chung  <kocsen_ch...@apple.com>
 
+        Cherry-pick r249584. rdar://problem/55202935
+
+    Marking up a note on iOS results in a PDF with no contents
+    https://bugs.webkit.org/show_bug.cgi?id=201530
+    <rdar://problem/53686019>
+    
+    Reviewed by Andy Estes.
+    
+    Source/WebKit:
+    
+    * Platform/IPC/Connection.cpp:
+    (IPC::Connection::Connection):
+    (IPC::Connection::waitForMessage):
+    (IPC::Connection::connectionDidClose):
+    * Platform/IPC/Connection.h:
+    If the main thread is blocked when the Web Content process dies, and
+    something eventually calls waitForAndDispatchImmediately without
+    returning control to the main run loop, we will wait for the full timeout,
+    because a) the code to mark the connection invalid is dispatched
+    to the main thread, and b) the secondary thread that is informed of
+    the Web Content process dying did not yet have a "waiting for" message
+    to mark as interrupted (because it wasn't waiting yet).
+    
+    Fix this race by adding a bit that is set under the waitForMessage lock
+    on the secondary thread when the connection is invalidated, identically
+    to m_shouldWaitForSyncReplies, which solves the same problem for sync
+    messages.
+    
+    Read the new bit when we are about to start waiting, and bail if it is set.
+    It's OK to not read it inside the loop because we are guaranteed to have
+    waitForMessage set at that point, so the normal interruption bit will work.
+    
+    * UIProcess/ios/WKContentView.mm:
+    (-[WKContentView _processDidExit]):
+    Reset _isPrintingToPDF; the Web Content process is never going to get
+    back to us if it crashes.
+    
+    (-[WKContentView _wk_pageCountForPrintFormatter:]):
+    Do not bail from starting a printing operation if one is already occurring.
+    This fixes the original bug, because Markup ends up invalidating the page
+    count at least one extra time before asking for the printed document.
+    Instead of maintaining the fragile requirement that you cannot recompute
+    the page count while printing, just let it happen. In order to make this
+    work safely, synchronously wait for the previous printed result before
+    continuing with the next print.
+    
+    We could do more coalescing here if need be, but calls to -_recalcPageCount
+    are not high in volume.
+    
+    Tools:
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm:
+    Add some tests for WKWebViewPrintFormatter; specifically that it is
+    possible to _recalcPageCount twice in quick succession, and that
+    we don't hang if we start painting the printed content immediately
+    after a Web Content process crash.
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249584 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-09-06  Tim Horton  <timothy_hor...@apple.com>
+
+            Marking up a note on iOS results in a PDF with no contents
+            https://bugs.webkit.org/show_bug.cgi?id=201530
+            <rdar://problem/53686019>
+
+            Reviewed by Andy Estes.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm:
+            Add some tests for WKWebViewPrintFormatter; specifically that it is
+            possible to _recalcPageCount twice in quick succession, and that
+            we don't hang if we start painting the printed content immediately
+            after a Web Content process crash.
+
+2019-09-09  Kocsen Chung  <kocsen_ch...@apple.com>
+
         Cherry-pick r249514. rdar://problem/55182886
 
     MobileSafari may crash when invoking the C++ lambda in -[WKContentView _shareForWebView:]

Modified: branches/safari-608-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (249696 => 249697)


--- branches/safari-608-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-10 03:19:52 UTC (rev 249696)
+++ branches/safari-608-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-10 03:19:56 UTC (rev 249697)
@@ -105,6 +105,7 @@
 		290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 290F4274172A1FDE00939FF0 /* custom-protocol-sync-xhr.html */; };
 		297234B7173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 297234B5173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp */; };
 		2D00065F1C1F589A0088E6A7 /* WKPDFViewResizeCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */; };
+		2D01D06E23218FEE0039AA3A /* WKWebViewPrintFormatter.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D01D06D23218FEE0039AA3A /* WKWebViewPrintFormatter.mm */; };
 		2D08E9372267D0F4002518DA /* ReparentWebViewTimeout.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D08E9362267D0F3002518DA /* ReparentWebViewTimeout.mm */; };
 		2D1646E21D1862CD00015A1A /* DeferredViewInWindowStateChange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1646E11D1862CD00015A1A /* DeferredViewInWindowStateChange.mm */; };
 		2D21FE591F04642900B58E7D /* WKPDFViewStablePresentationUpdateCallback.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D21FE581F04642800B58E7D /* WKPDFViewStablePresentationUpdateCallback.mm */; };
@@ -1534,6 +1535,7 @@
 		29AB8AA2164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestBrowsingContextLoadDelegate.mm; sourceTree = "<group>"; };
 		29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestBrowsingContextLoadDelegate.h; sourceTree = "<group>"; };
 		2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPDFViewResizeCrash.mm; sourceTree = "<group>"; };
+		2D01D06D23218FEE0039AA3A /* WKWebViewPrintFormatter.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewPrintFormatter.mm; sourceTree = "<group>"; };
 		2D08E9362267D0F3002518DA /* ReparentWebViewTimeout.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ReparentWebViewTimeout.mm; sourceTree = "<group>"; };
 		2D1646E11D1862CD00015A1A /* DeferredViewInWindowStateChange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DeferredViewInWindowStateChange.mm; path = WebKit/DeferredViewInWindowStateChange.mm; sourceTree = "<group>"; };
 		2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestNavigationDelegate.h; path = cocoa/TestNavigationDelegate.h; sourceTree = "<group>"; };
@@ -2888,6 +2890,7 @@
 				CE449E1021AE0F7200E7ADA1 /* WKWebViewFindString.mm */,
 				F4106C6821ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm */,
 				D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */,
+				2D01D06D23218FEE0039AA3A /* WKWebViewPrintFormatter.mm */,
 				37A9DBE7213B4C9300D261A2 /* WKWebViewServerTrustKVC.mm */,
 				93F56DA81E5F9181003EDE84 /* WKWebViewSnapshot.mm */,
 				CD7F89DB22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm */,
@@ -4753,6 +4756,7 @@
 				D34E08761E4E42E1005FF14A /* WKWebViewGetContents.mm in Sources */,
 				F4FA91811E61849B007B8C1D /* WKWebViewMacEditingTests.mm in Sources */,
 				1CACADA1230620AE0007D54C /* WKWebViewOpaque.mm in Sources */,
+				2D01D06E23218FEE0039AA3A /* WKWebViewPrintFormatter.mm in Sources */,
 				37A9DBE9213B4C9300D261A2 /* WKWebViewServerTrustKVC.mm in Sources */,
 				93F56DA91E5F919D003EDE84 /* WKWebViewSnapshot.mm in Sources */,
 				CD7F89DC22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm in Sources */,

Added: branches/safari-608-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm (0 => 249697)


--- branches/safari-608-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm	                        (rev 0)
+++ branches/safari-608-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewPrintFormatter.mm	2019-09-10 03:19:56 UTC (rev 249697)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
+#import "TestWKWebView.h"
+#import <WebKit/WebKit.h>
+#import <WebKit/WebKitPrivate.h>
+#import <WebKit/_WKWebViewPrintFormatter.h>
+#import <wtf/RetainPtr.h>
+
+@interface UIPrintFormatter ()
+- (NSInteger)_recalcPageCount;
+@end
+
+@interface UIPrintPageRenderer ()
+@property (nonatomic) CGRect paperRect;
+@property (nonatomic) CGRect printableRect;
+@end
+
+TEST(WKWebView, PrintFormatterCanRecalcPageCountWhilePrinting)
+{
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+    [webView waitForNextPresentationUpdate];
+
+    RetainPtr<_WKWebViewPrintFormatter> printFormatter = [webView _webViewPrintFormatter];
+    [printFormatter setSnapshotFirstPage:YES];
+
+    RetainPtr<UIPrintPageRenderer> printPageRenderer = adoptNS([[UIPrintPageRenderer alloc] init]);
+    
+    [printPageRenderer addPrintFormatter:printFormatter.get() startingAtPageAtIndex:0];
+
+    [printPageRenderer setPaperRect:CGRectMake(0, 0, 100, 100)];
+    [printPageRenderer setPrintableRect:CGRectMake(0, 0, 100, 100)];
+
+    EXPECT_EQ([printFormatter _recalcPageCount], 1);
+    EXPECT_EQ([printFormatter _recalcPageCount], 1);
+}
+
+
+TEST(WKWebView, PrintFormatterHangsIfWebProcessCrashesBeforeWaiting)
+{
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+    [webView waitForNextPresentationUpdate];
+
+    RetainPtr<_WKWebViewPrintFormatter> printFormatter = [webView _webViewPrintFormatter];
+
+    RetainPtr<UIPrintPageRenderer> printPageRenderer = adoptNS([[UIPrintPageRenderer alloc] init]);
+
+    [printPageRenderer addPrintFormatter:printFormatter.get() startingAtPageAtIndex:0];
+
+    [printPageRenderer setPaperRect:CGRectMake(0, 0, 100, 100)];
+    [printPageRenderer setPrintableRect:CGRectMake(0, 0, 100, 100)];
+
+    RetainPtr<UIGraphicsImageRenderer> graphicsRenderer = adoptNS([[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(100, 100)]);
+
+    EXPECT_EQ([printFormatter _recalcPageCount], 1);
+
+    [webView _killWebContentProcess];
+
+    [graphicsRenderer imageWithActions:^(UIGraphicsImageRendererContext *rendererContext) {
+        UIGraphicsPushContext(rendererContext.CGContext);
+        [printFormatter drawInRect:CGRectMake(0, 0, 100, 100) forPageAtIndex:0];
+        UIGraphicsPopContext();
+    }];
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to