Title: [249224] trunk
Revision
249224
Author
[email protected]
Date
2019-08-28 16:07:40 -0700 (Wed, 28 Aug 2019)

Log Message

Null check webFrame when creating a print preview to prevent a crash.
https://bugs.webkit.org/show_bug.cgi?id=201237
<rdar://problem/51618863>

Reviewed by Tim Horton.

Source/WebKit:

Move and expend a null check to keep from crashing when making a print preview.

* UIProcess/mac/WKPrintingView.mm:
(-[WKPrintingView _drawPreview:]):
(-[WKPrintingView drawRect:]):

Tools:

Test to verify that if we don't have the WebPageProxy, we will not crash when making a print preview.

* TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (249223 => 249224)


--- trunk/Source/WebKit/ChangeLog	2019-08-28 22:52:29 UTC (rev 249223)
+++ trunk/Source/WebKit/ChangeLog	2019-08-28 23:07:40 UTC (rev 249224)
@@ -1,3 +1,17 @@
+2019-08-28  Megan Gardner  <[email protected]>
+
+        Null check webFrame when creating a print preview to prevent a crash.
+        https://bugs.webkit.org/show_bug.cgi?id=201237
+        <rdar://problem/51618863>
+
+        Reviewed by Tim Horton.
+
+        Move and expend a null check to keep from crashing when making a print preview.
+
+        * UIProcess/mac/WKPrintingView.mm:
+        (-[WKPrintingView _drawPreview:]):
+        (-[WKPrintingView drawRect:]):
+
 2019-08-28  Said Abou-Hallawa  <[email protected]>
 
         All image drawing functions should take an argument of type ImagePaintingOptions

Modified: trunk/Source/WebKit/UIProcess/mac/WKPrintingView.mm (249223 => 249224)


--- trunk/Source/WebKit/UIProcess/mac/WKPrintingView.mm	2019-08-28 22:52:29 UTC (rev 249223)
+++ trunk/Source/WebKit/UIProcess/mac/WKPrintingView.mm	2019-08-28 23:07:40 UTC (rev 249224)
@@ -504,6 +504,9 @@
 - (void)_drawPreview:(NSRect)nsRect
 {
     ASSERT(RunLoop::isMain());
+    
+    if (!_webFrame || !_webFrame->page())
+        return;
 
     WebCore::IntRect scaledPrintingRect(nsRect);
     scaledPrintingRect.scale(1 / _totalScaleFactorForPrinting);
@@ -519,9 +522,6 @@
                 _latestExpectedPreviewCallback = existingCallback;
             } else {
                 // Preview isn't available yet, request it asynchronously.
-                if (!_webFrame->page())
-                    return;
-
                 // Return to printing mode if we're already back to screen (e.g. due to window resizing).
                 _webFrame->page()->beginPrinting(_webFrame.get(), WebKit::PrintInfo([_printOperation printInfo]));
 

Modified: trunk/Tools/ChangeLog (249223 => 249224)


--- trunk/Tools/ChangeLog	2019-08-28 22:52:29 UTC (rev 249223)
+++ trunk/Tools/ChangeLog	2019-08-28 23:07:40 UTC (rev 249224)
@@ -1,3 +1,16 @@
+2019-08-28  Megan Gardner  <[email protected]>
+
+        Null check webFrame when creating a print preview to prevent a crash.
+        https://bugs.webkit.org/show_bug.cgi?id=201237
+        <rdar://problem/51618863>
+
+        Reviewed by Tim Horton.
+
+        Test to verify that if we don't have the WebPageProxy, we will not crash when making a print preview.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
+        (TEST):
+
 2019-08-28  Jonathan Bedard  <[email protected]>
 
         results.webkit.org: Move drawer to the right, open by default

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm (249223 => 249224)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm	2019-08-28 22:52:29 UTC (rev 249223)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm	2019-08-28 23:07:40 UTC (rev 249224)
@@ -427,6 +427,21 @@
     TestWebKitAPI::Util::run(&drawFooterCalled);
 }
 
+TEST(WebKit, PrintPreview)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    auto delegate = adoptNS([[PrintDelegate alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+    [webView loadHTMLString:@"<head><title>test_title</title></head><body _onload_='print()'>hello world!</body>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
+    TestWebKitAPI::Util::run(&done);
+
+    NSPrintOperation *operation = [webView _printOperationWithPrintInfo:[NSPrintInfo sharedPrintInfo]];
+    NSPrintOperation.currentOperation = operation;
+    auto previewView = [operation view];
+    [webView _close];
+    [previewView drawRect:CGRectMake(0, 0, 10, 10)];
+}
+
 @interface NotificationDelegate : NSObject <WKUIDelegatePrivate> {
     bool _allowNotifications;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to