PDFs still don't snapshot properly in iOS Safari
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Apr 2015 18:01:15 +0000 (18:01 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Apr 2015 18:01:15 +0000 (18:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143976
<rdar://problem/18283459>

Reviewed by Anders Carlsson.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didLayoutForCustomContentProvider):
* UIProcess/WebPageProxy.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didFinishLoadingDataForCustomContentProviderWithSuggestedFilename:data:]):
Inform the client that we've passed all reasonable layout milestones
as soon as the custom content provider has been handed its data.
WKPDFView, the only custom content provider, synchronously lays out
its subviews upon initial receipt of data, so this works fine for it.
This ensures that clients that normally depend on layout milestones firing
won't break when a custom content view is installed.

(-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
Fall back to renderInContext: if the custom content view is not parented
when a snapshot is requested.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h

index 5eba412..31fbb3b 100644 (file)
@@ -1,3 +1,27 @@
+2015-04-21  Timothy Horton  <timothy_horton@apple.com>
+
+        PDFs still don't snapshot properly in iOS Safari
+        https://bugs.webkit.org/show_bug.cgi?id=143976
+        <rdar://problem/18283459>
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didLayoutForCustomContentProvider):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _didFinishLoadingDataForCustomContentProviderWithSuggestedFilename:data:]):
+        Inform the client that we've passed all reasonable layout milestones
+        as soon as the custom content provider has been handed its data.
+        WKPDFView, the only custom content provider, synchronously lays out
+        its subviews upon initial receipt of data, so this works fine for it.
+        This ensures that clients that normally depend on layout milestones firing
+        won't break when a custom content view is installed.
+
+        (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]):
+        Fall back to renderInContext: if the custom content view is not parented
+        when a snapshot is requested.
+
 2015-04-21  Dan Bernstein  <mitz@apple.com>
 
         Merged WKBackForwardListItem’s Internal category into the class extension in WKBackForwardListItemInternal.h.
index 7c15f5e..71f8905 100644 (file)
@@ -717,6 +717,10 @@ static CGSize roundScrollViewContentSize(const WebKit::WebPageProxy& page, CGSiz
 {
     ASSERT(_customContentView);
     [_customContentView web_setContentProviderData:data suggestedFilename:suggestedFilename];
+
+    // FIXME: It may make more sense for custom content providers to invoke this when they're ready,
+    // because there's no guarantee that all custom content providers will lay out synchronously.
+    _page->didLayoutForCustomContentProvider();
 }
 
 - (void)_setViewportMetaTagWidth:(float)newWidth
@@ -2637,7 +2641,15 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
         destinationRect.origin.y = -snapshotRectInContentCoordinates.origin.y * imageScale;
         destinationRect.size.width *= imageScale;
         destinationRect.size.height *= imageScale;
-        [customContentView drawViewHierarchyInRect:destinationRect afterScreenUpdates:NO];
+
+        if ([_customContentView window])
+            [customContentView drawViewHierarchyInRect:destinationRect afterScreenUpdates:NO];
+        else {
+            CGContextRef context = UIGraphicsGetCurrentContext();
+            CGContextTranslateCTM(context, destinationRect.origin.x, destinationRect.origin.y);
+            CGContextScaleCTM(context, imageScale, imageScale);
+            [customContentView.layer renderInContext:context];
+        }
 
         completionHandler([UIGraphicsGetImageFromCurrentImageContext() CGImage]);
 
index dbb0899..1f4e241 100644 (file)
@@ -3072,6 +3072,15 @@ void WebPageProxy::didFirstVisuallyNonEmptyLayoutForFrame(uint64_t frameID, cons
         m_pageClient.didFirstVisuallyNonEmptyLayoutForMainFrame();
 }
 
+void WebPageProxy::didLayoutForCustomContentProvider()
+{
+    LayoutMilestones milestones = DidFirstLayout | DidFirstVisuallyNonEmptyLayout | DidHitRelevantRepaintedObjectsAreaThreshold;
+    if (m_navigationClient)
+        m_navigationClient->renderingProgressDidChange(*this, milestones, nullptr);
+    else
+        m_loaderClient->didLayout(*this, milestones, nullptr);
+}
+
 void WebPageProxy::didLayout(uint32_t layoutMilestones, const UserData& userData)
 {
     if (m_navigationClient)
index 6e25096..c08b2b9 100644 (file)
@@ -1031,6 +1031,7 @@ public:
 #endif
 
     void didChangeBackgroundColor();
+    void didLayoutForCustomContentProvider();
 
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&);