Changeset 273075 in webkit
- Timestamp:
- Feb 18, 2021, 8:06:49 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r273074 r273075 1 2021-02-18 Alex Christensen <achristensen@webkit.org> 2 3 Add SPI for getting size of PDF document during printing 4 https://bugs.webkit.org/show_bug.cgi?id=222064 5 <rdar://problem/74370891> 6 7 Reviewed by Geoff Garen and Tim Horton. 8 9 When printing a PDF, we want to know its page size. If the print is initiated by the web process (such as when window.print is called 10 or if the PDF contains JavaScript that tells the browser to print it) then we would like that information with the print request so we 11 don't have to ask the web process, which is hung waiting for a synchronous message reply. If the print is initiated by the UI process 12 (such as if the user prints from a menu or keyboard shortcut) then we need a way to ask what the size of a PDF is. 13 14 I reused the SPI in WKUIDelegatePrivate because it was only briefly adopted before we knew we needed this and then reverted. 15 I'm also adding an SPI way to get from a WKPageRef to a WKWebView so this can be adopted without redoing all of Safari. 16 17 Covered by API tests. 18 19 * UIProcess/API/APIUIClient.h: 20 (API::UIClient::printFrame): 21 * UIProcess/API/C/WKPage.cpp: 22 (WKPageSetPageUIClient): 23 * UIProcess/API/Cocoa/WKUIDelegatePrivate.h: 24 * UIProcess/API/Cocoa/WKWebView.mm: 25 (-[WKWebView _getPDFFirstPageSizeInFrame:completionHandler:]): 26 * UIProcess/API/Cocoa/WKWebViewPrivate.h: 27 * UIProcess/Cocoa/UIDelegate.h: 28 * UIProcess/Cocoa/UIDelegate.mm: 29 (WebKit::UIDelegate::setDelegate): 30 (WebKit::UIDelegate::UIClient::printFrame): 31 * UIProcess/WebPageProxy.cpp: 32 (WebKit::WebPageProxy::printFrame): 33 (WebKit::WebPageProxy::getPDFFirstPageSize): 34 * UIProcess/WebPageProxy.h: 35 * UIProcess/WebPageProxy.messages.in: 36 * WebProcess/Plugins/PDF/PDFPlugin.h: 37 * WebProcess/Plugins/PDF/PDFPlugin.mm: 38 (WebKit::PDFPlugin::pdfDocumentSizeForPrinting const): 39 * WebProcess/Plugins/Plugin.cpp: 40 (WebKit::Plugin::pdfDocumentSizeForPrinting const): 41 * WebProcess/Plugins/Plugin.h: 42 * WebProcess/WebCoreSupport/WebChromeClient.cpp: 43 (WebKit::WebChromeClient::print): 44 * WebProcess/WebPage/Cocoa/WebPageCocoa.mm: 45 (WebKit::WebPage::getPDFFirstPageSize): 46 * WebProcess/WebPage/WebPage.cpp: 47 (WebKit::WebPage::getPDFFirstPageSize): 48 * WebProcess/WebPage/WebPage.h: 49 * WebProcess/WebPage/WebPage.messages.in: 50 1 51 2021-02-18 Kimmo Kinnunen <kkinnunen@apple.com> 2 52 -
trunk/Source/WebKit/UIProcess/API/APIUIClient.h
r272573 r273075 146 146 virtual void drawHeader(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, WebCore::FloatRect&&) { } 147 147 virtual void drawFooter(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, WebCore::FloatRect&&) { } 148 virtual void printFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, CompletionHandler<void()>&& completionHandler) { completionHandler(); }148 virtual void printFrame(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, const WebCore::FloatSize& pdfFirstPageSize, CompletionHandler<void()>&& completionHandler) { completionHandler(); } 149 149 150 150 virtual bool canRunModal() const { return false; } -
trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp
r272784 r273075 1972 1972 } 1973 1973 1974 void printFrame(WebPageProxy& page, WebFrameProxy& frame, CompletionHandler<void()>&& completionHandler) final1974 void printFrame(WebPageProxy& page, WebFrameProxy& frame, const WebCore::FloatSize&, CompletionHandler<void()>&& completionHandler) final 1975 1975 { 1976 1976 if (m_client.printFrame) -
trunk/Source/WebKit/UIProcess/API/C/mac/WKPagePrivateMac.h
r242325 r273075 36 36 #ifdef __OBJC__ 37 37 38 @class WKWebView; 38 39 @class _WKRemoteObjectRegistry; 39 40 … … 64 65 WK_EXPORT WKNavigation *WKPageLoadFileReturningNavigation(WKPageRef page, WKURLRef fileURL, WKURLRef resourceDirectoryURL); 65 66 67 WK_EXPORT WKWebView *WKPageGetWebView(WKPageRef page); 68 66 69 #endif // __OBJC__ 67 70 -
trunk/Source/WebKit/UIProcess/API/C/mac/WKPagePrivateMac.mm
r249962 r273075 33 33 #import "WKNavigationInternal.h" 34 34 #import "WKViewInternal.h" 35 #import "WKWebViewInternal.h" 35 36 #import "WebPageGroup.h" 36 37 #import "WebPageProxy.h" … … 148 149 } 149 150 151 WKWebView *WKPageGetWebView(WKPageRef page) 152 { 153 if (!page) 154 return nil; 155 return fromWebPageProxy(*WebKit::toImpl(page)); 156 } 157 150 158 #if PLATFORM(MAC) 151 159 bool WKPageIsPlayingVideoInEnhancedFullscreen(WKPageRef pageRef) -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
r271813 r273075 108 108 109 109 - (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame; 110 - (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame completionHandler:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(11.0), ios(14.0));110 - (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame pdfFirstPageSize:(CGSize)size completionHandler:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 111 111 112 112 - (void)_webViewClose:(WKWebView *)webView; -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r273040 r273075 2260 2260 } 2261 2261 2262 - (void)_getPDFFirstPageSizeInFrame:(_WKFrameHandle *)frame completionHandler:(void(^)(CGSize))completionHandler 2263 { 2264 _page->getPDFFirstPageSize(frame->_frameHandle->frameID(), [completionHandler = makeBlockPtr(completionHandler)](WebCore::FloatSize size) { 2265 completionHandler(static_cast<CGSize>(size)); 2266 }); 2267 } 2268 2262 2269 - (NSData *)_sessionStateData 2263 2270 { -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
r273040 r273075 351 351 352 352 - (void)_takePDFSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void (^)(NSData *pdfSnapshotData, NSError *error))completionHandler WK_API_AVAILABLE(macos(10.15.4), ios(13.4)); 353 - (void)_getPDFFirstPageSizeInFrame:(_WKFrameHandle *)frame completionHandler:(void(^)(CGSize))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 353 354 354 355 - (void)_getProcessDisplayNameWithCompletionHandler:(void (^)(NSString *))completionHandler WK_API_AVAILABLE(macos(11.0), ios(14.0)); -
trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp
r272574 r273075 330 330 } 331 331 332 void printFrame(WebPageProxy&, WebFrameProxy& frame, CompletionHandler<void()>&& completionHandler) final332 void printFrame(WebPageProxy&, WebFrameProxy& frame, const WebCore::FloatSize&, CompletionHandler<void()>&& completionHandler) final 333 333 { 334 334 webkitWebViewPrintFrame(m_webView, &frame); -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h
r271424 r273075 138 138 void checkUserMediaPermissionForOrigin(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionCheckProxy&) final; 139 139 void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) final; 140 void printFrame(WebPageProxy&, WebFrameProxy&, CompletionHandler<void()>&&) final;140 void printFrame(WebPageProxy&, WebFrameProxy&, const WebCore::FloatSize& pdfFirstPageSize, CompletionHandler<void()>&&) final; 141 141 #if PLATFORM(IOS_FAMILY) 142 142 #if HAVE(APP_LINKS) … … 218 218 bool webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded : 1; 219 219 bool webViewPrintFrame : 1; 220 bool webViewPrintFrame CompletionHandler : 1;220 bool webViewPrintFramePDFFirstPageSizeCompletionHandler : 1; 221 221 bool webViewDidClose : 1; 222 222 bool webViewClose : 1; -
trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
r271424 r273075 145 145 m_delegateMethods.webViewDecideWebApplicationCacheQuotaForSecurityOriginCurrentQuotaTotalBytesNeeded = [delegate respondsToSelector:@selector(_webView:decideWebApplicationCacheQuotaForSecurityOrigin:currentQuota:totalBytesNeeded:decisionHandler:)]; 146 146 m_delegateMethods.webViewPrintFrame = [delegate respondsToSelector:@selector(_webView:printFrame:)]; 147 m_delegateMethods.webViewPrintFrame CompletionHandler = [delegate respondsToSelector:@selector(_webView:printFrame:completionHandler:)];147 m_delegateMethods.webViewPrintFramePDFFirstPageSizeCompletionHandler = [delegate respondsToSelector:@selector(_webView:printFrame:pdfFirstPageSize:completionHandler:)]; 148 148 m_delegateMethods.webViewDidClose = [delegate respondsToSelector:@selector(webViewDidClose:)]; 149 149 m_delegateMethods.webViewClose = [delegate respondsToSelector:@selector(_webViewClose:)]; … … 1194 1194 } 1195 1195 1196 void UIDelegate::UIClient::printFrame(WebPageProxy&, WebFrameProxy& webFrameProxy, CompletionHandler<void()>&& completionHandler)1196 void UIDelegate::UIClient::printFrame(WebPageProxy&, WebFrameProxy& webFrameProxy, const WebCore::FloatSize& pdfFirstPageSize, CompletionHandler<void()>&& completionHandler) 1197 1197 { 1198 1198 if (!m_uiDelegate) … … 1204 1204 1205 1205 auto handle = API::FrameHandle::create(webFrameProxy.frameID()); 1206 if (m_uiDelegate->m_delegateMethods.webViewPrintFrame CompletionHandler) {1207 auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:printFrame: completionHandler:));1208 [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() printFrame:wrapper(handle) completionHandler:makeBlockPtr([checker = WTFMove(checker), completionHandler = WTFMove(completionHandler)] () mutable {1206 if (m_uiDelegate->m_delegateMethods.webViewPrintFramePDFFirstPageSizeCompletionHandler) { 1207 auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:printFrame:pdfFirstPageSize:completionHandler:)); 1208 [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate->m_webView.get().get() printFrame:wrapper(handle) pdfFirstPageSize:static_cast<CGSize>(pdfFirstPageSize) completionHandler:makeBlockPtr([checker = WTFMove(checker), completionHandler = WTFMove(completionHandler)] () mutable { 1209 1209 if (checker->completionHandlerHasBeenCalled()) 1210 1210 return; -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r273048 r273075 5925 5925 } 5926 5926 5927 void WebPageProxy::printFrame(FrameIdentifier frameID, const String& title, CompletionHandler<void()>&& completionHandler)5927 void WebPageProxy::printFrame(FrameIdentifier frameID, const String& title, const WebCore::FloatSize& pdfFirstPageSize, CompletionHandler<void()>&& completionHandler) 5928 5928 { 5929 5929 ASSERT(!m_isPerformingDOMPrintOperation); … … 5935 5935 frame->didChangeTitle(title); 5936 5936 5937 m_uiClient->printFrame(*this, *frame, [this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)] () mutable {5937 m_uiClient->printFrame(*this, *frame, pdfFirstPageSize, [this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)] () mutable { 5938 5938 endPrinting(); // Send a message synchronously while m_isPerformingDOMPrintOperation is still true. 5939 5939 m_isPerformingDOMPrintOperation = false; … … 8546 8546 #endif // PLATFORM(COCOA) 8547 8547 8548 void WebPageProxy::getPDFFirstPageSize(WebCore::FrameIdentifier frameID, CompletionHandler<void(WebCore::FloatSize)>&& completionHandler) 8549 { 8550 sendWithAsyncReply(Messages::WebPage::GetPDFFirstPageSize(frameID), WTFMove(completionHandler)); 8551 } 8552 8548 8553 void WebPageProxy::updateBackingStoreDiscardableState() 8549 8554 { -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r273023 r273075 1290 1290 void endPrinting(); 1291 1291 uint64_t computePagesForPrinting(WebFrameProxy*, const PrintInfo&, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&&); 1292 void getPDFFirstPageSize(WebCore::FrameIdentifier, CompletionHandler<void(WebCore::FloatSize)>&&); 1292 1293 #if PLATFORM(COCOA) 1293 1294 uint64_t drawRectToImage(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&); … … 1990 1991 void showShareSheet(const WebCore::ShareDataWithParsedURL&, CompletionHandler<void(bool)>&&); 1991 1992 void showContactPicker(const WebCore::ContactsRequestData&, CompletionHandler<void(Optional<Vector<WebCore::ContactInfo>>&&)>&&); 1992 void printFrame(WebCore::FrameIdentifier, const String&, CompletionHandler<void()>&&);1993 void printFrame(WebCore::FrameIdentifier, const String&, const WebCore::FloatSize&, CompletionHandler<void()>&&); 1993 1994 void exceededDatabaseQuota(WebCore::FrameIdentifier, const String& originIdentifier, const String& databaseName, const String& displayName, uint64_t currentQuota, uint64_t currentOriginUsage, uint64_t currentDatabaseUsage, uint64_t expectedUsage, Messages::WebPageProxy::ExceededDatabaseQuotaDelayedReply&&); 1994 1995 void reachedApplicationCacheOriginQuota(const String& originIdentifier, uint64_t currentQuota, uint64_t totalBytesNeeded, Messages::WebPageProxy::ReachedApplicationCacheOriginQuotaDelayedReply&&); -
trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in
r272925 r273075 71 71 ShowShareSheet(struct WebCore::ShareDataWithParsedURL shareData) -> (bool granted) Async 72 72 ShowContactPicker(struct WebCore::ContactsRequestData requestData) -> (Optional<Vector<WebCore::ContactInfo>> info) Async 73 PrintFrame(WebCore::FrameIdentifier frameID, String title ) -> () Synchronous73 PrintFrame(WebCore::FrameIdentifier frameID, String title, WebCore::FloatSize pdfFirstPageSize) -> () Synchronous 74 74 RunModal() 75 75 NotifyScrollerThumbIsVisibleInRect(WebCore::IntRect scrollerThumb) -
trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h
r272324 r273075 214 214 215 215 RetainPtr<PDFDocument> pdfDocumentForPrinting() const final { return m_pdfDocument; } 216 WebCore::FloatSize pdfDocumentSizeForPrinting() const final; 216 217 NSObject *accessibilityObject() const final; 217 218 id accessibilityAssociatedPluginParentForElement(WebCore::Element*) const final; -
trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm
r271124 r273075 1551 1551 } 1552 1552 1553 FloatSize PDFPlugin::pdfDocumentSizeForPrinting() const 1554 { 1555 return FloatSize([[m_pdfDocument pageAtIndex:0] boundsForBox:kPDFDisplayBoxCropBox].size); 1556 } 1557 1553 1558 JSObjectRef PDFPlugin::makeJSPDFDoc(JSContextRef ctx) 1554 1559 { -
trunk/Source/WebKit/WebProcess/Plugins/Plugin.cpp
r268989 r273075 128 128 } 129 129 130 #if PLATFORM(COCOA) 131 WebCore::FloatSize Plugin::pdfDocumentSizeForPrinting() const 132 { 133 return { }; 134 } 135 #endif 136 130 137 } // namespace WebKit -
trunk/Source/WebKit/WebProcess/Plugins/Plugin.h
r269785 r273075 56 56 class Element; 57 57 class FloatPoint; 58 class FloatSize; 58 59 class GraphicsContext; 59 60 class IntPoint; … … 276 277 #if PLATFORM(COCOA) 277 278 virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; } 279 virtual WebCore::FloatSize pdfDocumentSizeForPrinting() const; 278 280 virtual NSObject *accessibilityObject() const { return 0; } 279 281 virtual id accessibilityAssociatedPluginParentForElement(WebCore::Element*) const { return nullptr; } -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
r272925 r273075 40 40 #include "NetworkProcessConnection.h" 41 41 #include "PageBanner.h" 42 #include "PluginView.h" 42 43 #include "RemoteRenderingBackendProxy.h" 43 44 #include "SharedBufferCopy.h" … … 737 738 #endif 738 739 740 WebCore::FloatSize pdfFirstPageSize; 741 #if PLATFORM(COCOA) 742 if (auto* pluginView = WebPage::pluginViewForFrame(&frame)) { 743 if (auto* plugin = pluginView->plugin()) 744 pdfFirstPageSize = plugin->pdfDocumentSizeForPrinting(); 745 } 746 #endif 747 739 748 auto truncatedTitle = truncateFromEnd(title, maxTitleLength); 740 m_page.sendSyncWithDelayedReply(Messages::WebPageProxy::PrintFrame(webFrame->frameID(), truncatedTitle.string ), Messages::WebPageProxy::PrintFrame::Reply());749 m_page.sendSyncWithDelayedReply(Messages::WebPageProxy::PrintFrame(webFrame->frameID(), truncatedTitle.string, pdfFirstPageSize), Messages::WebPageProxy::PrintFrame::Reply()); 741 750 } 742 751 -
trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm
r272605 r273075 417 417 } 418 418 419 void WebPage::getPDFFirstPageSize(WebCore::FrameIdentifier frameID, CompletionHandler<void(WebCore::FloatSize)>&& completionHandler) 420 { 421 auto* webFrame = WebProcess::singleton().webFrame(frameID); 422 if (!webFrame) 423 return completionHandler({ }); 424 425 auto* coreFrame = webFrame->coreFrame(); 426 if (!coreFrame) 427 return completionHandler({ }); 428 429 auto* pluginView = pluginViewForFrame(coreFrame); 430 if (!pluginView) 431 return completionHandler({ }); 432 433 auto* plugin = pluginView->plugin(); 434 if (!plugin) 435 return completionHandler({ }); 436 437 completionHandler(FloatSize(plugin->pdfDocumentSizeForPrinting())); 438 } 439 419 440 } // namespace WebKit 420 441 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r273023 r273075 7143 7143 7144 7144 #if !PLATFORM(COCOA) 7145 void WebPage::getPDFFirstPageSize(WebCore::FrameIdentifier, CompletionHandler<void(WebCore::FloatSize)>&& completionHandler) 7146 { 7147 completionHandler({ }); 7148 } 7149 7145 7150 void WebPage::getProcessDisplayName(CompletionHandler<void(String&&)>&& completionHandler) 7146 7151 { -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r273023 r273075 1509 1509 void loadSimulatedRequestAndResponse(LoadParameters&&, WebCore::ResourceResponse&&); 1510 1510 void navigateToPDFLinkWithSimulatedClick(const String& url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint); 1511 void getPDFFirstPageSize(WebCore::FrameIdentifier, CompletionHandler<void(WebCore::FloatSize)>&&); 1511 1512 void reload(uint64_t navigationID, uint32_t reloadOptions, SandboxExtension::Handle&&); 1512 1513 void goToBackForwardItem(uint64_t navigationID, const WebCore::BackForwardItemIdentifier&, WebCore::FrameLoadType, WebCore::ShouldTreatAsContinuingLoad, Optional<WebsitePoliciesData>&&); -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r273023 r273075 184 184 185 185 NavigateToPDFLinkWithSimulatedClick(String url, WebCore::IntPoint documentPoint, WebCore::IntPoint screenPoint) 186 GetPDFFirstPageSize(WebCore::FrameIdentifier frameID) -> (WebCore::FloatSize size) Async 186 187 187 188 Reload(uint64_t navigationID, uint32_t reloadOptions, WebKit::SandboxExtension::Handle sandboxExtensionHandle) -
trunk/Tools/ChangeLog
r273067 r273075 1 2021-02-18 Alex Christensen <achristensen@webkit.org> 2 3 Add SPI for getting size of PDF document during printing 4 https://bugs.webkit.org/show_bug.cgi?id=222064 5 <rdar://problem/74370891> 6 7 Reviewed by Geoff Garen and Tim Horton. 8 9 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 10 * TestWebKitAPI/Tests/WebKit/test_print.pdf: Added. 11 * TestWebKitAPI/Tests/WebKitCocoa/WKPDFView.mm: 12 (-[PrintUIDelegate _webView:printFrame:pdfFirstPageSize:completionHandler:]): 13 (-[PrintUIDelegate waitForPageSize]): 14 (-[PrintUIDelegate lastPrintedFrame]): 15 (TEST): 16 1 17 2021-02-18 Antoine Quint <graouts@webkit.org> 2 18 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r273067 r273075 462 462 5C69BDD51F82A7EF000F4F4B /* JavaScriptDuringNavigation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C69BDD41F82A7EB000F4F4B /* JavaScriptDuringNavigation.mm */; }; 463 463 5C6E27A7224EEBEA00128736 /* URLCanonicalization.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C6E27A6224EEBEA00128736 /* URLCanonicalization.mm */; }; 464 5C7101C725DD98B600686200 /* test_print.pdf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5C7101C625DD988700686200 /* test_print.pdf */; }; 464 465 5C7148952123A40A00FDE3C5 /* WKWebsiteDatastore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C7148942123A40700FDE3C5 /* WKWebsiteDatastore.mm */; }; 465 466 5C75716122124C5200B9E5AC /* BundleRetainPagePlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C75715F221249BD00B9E5AC /* BundleRetainPagePlugIn.mm */; }; … … 1651 1652 524BBCA119E30C77002F1AF1 /* test.mp4 in Copy Resources */, 1652 1653 7AE9E5091AE5AE8B00CF874B /* test.pdf in Copy Resources */, 1654 5C7101C725DD98B600686200 /* test_print.pdf in Copy Resources */, 1653 1655 2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */, 1654 1656 F4CD74C620FDACFA00DE3794 /* text-with-async-script.html in Copy Resources */, … … 2249 2251 5C69BDD41F82A7EB000F4F4B /* JavaScriptDuringNavigation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JavaScriptDuringNavigation.mm; sourceTree = "<group>"; }; 2250 2252 5C6E27A6224EEBEA00128736 /* URLCanonicalization.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = URLCanonicalization.mm; sourceTree = "<group>"; }; 2253 5C7101C625DD988700686200 /* test_print.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = test_print.pdf; sourceTree = "<group>"; }; 2251 2254 5C7148942123A40700FDE3C5 /* WKWebsiteDatastore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebsiteDatastore.mm; sourceTree = "<group>"; }; 2252 2255 5C72E8CD244FFCE300381EB7 /* TestLegacyDownloadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestLegacyDownloadDelegate.h; path = cocoa/TestLegacyDownloadDelegate.h; sourceTree = "<group>"; }; … … 4232 4235 7673499A1930182E00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp */, 4233 4236 1AE72F47173EB214006362F0 /* TerminateTwice.cpp */, 4237 5C7101C625DD988700686200 /* test_print.pdf */, 4234 4238 CE3524F11B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing.cpp */, 4235 4239 CE3524F21B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp */, -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm
r273062 r273075 450 450 } 451 451 452 - (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame completionHandler:(void (^)(void))completionHandler452 - (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame pdfFirstPageSize:(CGSize)size completionHandler:(void (^)(void))completionHandler 453 453 { 454 454 completionHandler(); -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKPDFView.mm
r273062 r273075 44 44 #endif 45 45 46 #if PLATFORM(IOS) || ENABLE(UI_PROCESS_PDF_HUD) 46 #if PLATFORM(IOS) || ENABLE(UI_PROCESS_PDF_HUD) || PLATFORM(MAC) 47 47 static NSData *pdfData() 48 48 { … … 373 373 } 374 374 375 #endif // ENABLE(UI_PROCESS_PDF_HUD) 376 377 #if PLATFORM(MAC) 378 379 @interface PrintUIDelegate : NSObject <WKUIDelegate> 380 381 - (NSSize)waitForPageSize; 382 - (_WKFrameHandle *)lastPrintedFrame; 383 384 @end 385 386 @implementation PrintUIDelegate { 387 NSSize _pageSize; 388 bool _receivedSize; 389 RetainPtr<_WKFrameHandle> _lastPrintedFrame; 390 } 391 392 - (void)_webView:(WKWebView *)webView printFrame:(_WKFrameHandle *)frame pdfFirstPageSize:(CGSize)size completionHandler:(void (^)(void))completionHandler 393 { 394 _pageSize = size; 395 _receivedSize = true; 396 _lastPrintedFrame = frame; 397 completionHandler(); 398 } 399 400 - (NSSize)waitForPageSize 401 { 402 _receivedSize = false; 403 while (!_receivedSize) 404 TestWebKitAPI::Util::spinRunLoop(); 405 return _pageSize; 406 } 407 408 - (_WKFrameHandle *)lastPrintedFrame 409 { 410 return _lastPrintedFrame.get(); 411 } 412 413 @end 414 415 TEST(PDF, PrintSize) 416 { 417 auto configuration = [[WKWebViewConfiguration new] autorelease]; 418 auto schemeHandler = [[TestURLSchemeHandler new] autorelease]; 419 [configuration setURLSchemeHandler:schemeHandler forURLScheme:@"test"]; 420 auto webView = [[[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration] autorelease]; 421 auto delegate = [[PrintUIDelegate new] autorelease]; 422 webView.UIDelegate = delegate; 423 424 schemeHandler.startURLSchemeTaskHandler = ^(WKWebView *, id<WKURLSchemeTask> task) { 425 auto url = task.request.URL; 426 NSData *data; 427 NSString *mimeType; 428 if ([url.path isEqualToString:@"/main.html"]) { 429 mimeType = @"text/html"; 430 const char* html = "<br/><iframe src='test.pdf' id='pdfframe'></iframe>"; 431 data = [NSData dataWithBytes:html length:strlen(html)]; 432 } else if ([url.path isEqualToString:@"/test.pdf"]) { 433 mimeType = @"application/pdf"; 434 data = pdfData(); 435 } else { 436 EXPECT_WK_STREQ(url.path, "/test_print.pdf"); 437 mimeType = @"application/pdf"; 438 data = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"test_print" withExtension:@"pdf" subdirectory:@"TestWebKitAPI.resources"]]; 439 } 440 NSURLResponse *response = [[[NSURLResponse alloc] initWithURL:url MIMEType:mimeType expectedContentLength:data.length textEncodingName:nil] autorelease]; 441 [task didReceiveResponse:response]; 442 [task didReceiveData:data]; 443 [task didFinish]; 444 }; 445 446 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"test:///test_print.pdf"]]]; 447 auto size = [delegate waitForPageSize]; 448 EXPECT_EQ(size.height, 792.0); 449 EXPECT_EQ(size.width, 612.0); 450 451 __block bool receivedSize = false; 452 [webView _getPDFFirstPageSizeInFrame:webView._mainFrame completionHandler:^(CGSize requestedSize) { 453 EXPECT_EQ(requestedSize.height, 792.0); 454 EXPECT_EQ(requestedSize.width, 612.0); 455 receivedSize = true; 456 }]; 457 TestWebKitAPI::Util::run(&receivedSize); 458 459 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"test:///main.html"]]]; 460 [webView _test_waitForDidFinishNavigation]; 461 [webView evaluateJavaScript:@"window.print()" completionHandler:nil]; 462 auto mainFrameSize = [delegate waitForPageSize]; 463 EXPECT_EQ(mainFrameSize.height, 0.0); 464 EXPECT_EQ(mainFrameSize.width, 0.0); 465 466 receivedSize = false; 467 [webView _getPDFFirstPageSizeInFrame:webView._mainFrame completionHandler:^(CGSize requestedSize) { 468 EXPECT_EQ(requestedSize.height, 0.0); 469 EXPECT_EQ(requestedSize.width, 0.0); 470 receivedSize = true; 471 }]; 472 TestWebKitAPI::Util::run(&receivedSize); 473 474 [webView evaluateJavaScript:@"pdfframe.contentWindow.print()" completionHandler:nil]; 475 auto pdfFrameSize = [delegate waitForPageSize]; 476 EXPECT_NEAR(pdfFrameSize.height, 28.799999, .00001); 477 EXPECT_NEAR(pdfFrameSize.width, 129.600006, .00001); 478 479 receivedSize = false; 480 [webView _getPDFFirstPageSizeInFrame:delegate.lastPrintedFrame completionHandler:^(CGSize requestedSize) { 481 EXPECT_NEAR(requestedSize.height, 28.799999, .00001); 482 EXPECT_NEAR(requestedSize.width, 129.600006, .00001); 483 receivedSize = true; 484 }]; 485 TestWebKitAPI::Util::run(&receivedSize); 486 } 487 375 488 #endif
Note:
See TracChangeset
for help on using the changeset viewer.