Changeset 272628 in webkit
- Timestamp:
- Feb 9, 2021, 5:29:32 PM (4 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r272627 r272628 1 2021-02-09 Alex Christensen <achristensen@webkit.org> 2 3 Use CompletionHandler instead of ImageCallback 4 https://bugs.webkit.org/show_bug.cgi?id=221626 5 6 Reviewed by Chris Dumez. 7 8 * UIProcess/API/Cocoa/WKWebView.mm: 9 (-[WKWebView takeSnapshotWithConfiguration:completionHandler:]): 10 * UIProcess/API/Cocoa/_WKThumbnailView.mm: 11 (-[_WKThumbnailView requestSnapshot]): 12 * UIProcess/API/ios/WKWebViewIOS.mm: 13 (-[WKWebView _snapshotRect:intoImageOfWidth:completionHandler:]): 14 * UIProcess/GenericCallback.h: 15 * UIProcess/WebPageProxy.cpp: 16 (WebKit::WebPageProxy::drawRectToImage): 17 (WebKit::WebPageProxy::takeSnapshot): 18 (WebKit::WebPageProxy::imageCallback): Deleted. 19 * UIProcess/WebPageProxy.h: 20 * UIProcess/WebPageProxy.messages.in: 21 * UIProcess/mac/WKPrintingView.mm: 22 (-[WKPrintingView _drawPreview:]): 23 * WebProcess/WebPage/WebPage.cpp: 24 (WebKit::WebPage::takeSnapshot): 25 (WebKit::WebPage::drawRectToImage): 26 * WebProcess/WebPage/WebPage.h: 27 * WebProcess/WebPage/WebPage.messages.in: 28 1 29 2021-02-09 Alex Christensen <achristensen@webkit.org> 2 30 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
r272592 r272628 841 841 } 842 842 843 #if USE(APPKIT)844 static WKErrorCode callbackErrorCode(WebKit::CallbackBase::Error error)845 {846 switch (error) {847 case WebKit::CallbackBase::Error::None:848 ASSERT_NOT_REACHED();849 return WKErrorUnknown;850 851 case WebKit::CallbackBase::Error::Unknown:852 return WKErrorUnknown;853 854 case WebKit::CallbackBase::Error::ProcessExited:855 return WKErrorWebContentProcessTerminated;856 857 case WebKit::CallbackBase::Error::OwnerWasInvalidated:858 return WKErrorWebViewInvalidated;859 }860 }861 #endif862 863 843 - (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler 864 844 { … … 1095 1075 // contains recent updates. If we ever have a UI-side snapshot mechanism on macOS, we will need to factor 1096 1076 // in snapshotConfiguration.afterScreenUpdates at that time. 1097 _page->takeSnapshot(WebCore::enclosingIntRect(rectInViewCoordinates), bitmapSize, WebKit::SnapshotOptionsInViewCoordinates, [handler, snapshotWidth, imageHeight](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error errorCode) { 1098 if (errorCode != WebKit::CallbackBase::Error::None) { 1099 auto error = createNSError(callbackErrorCode(errorCode)); 1100 handler(nil, error.get()); 1101 return; 1102 } 1103 1077 _page->takeSnapshot(WebCore::enclosingIntRect(rectInViewCoordinates), bitmapSize, WebKit::SnapshotOptionsInViewCoordinates, [handler, snapshotWidth, imageHeight](const WebKit::ShareableBitmap::Handle& imageHandle) { 1104 1078 auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly); 1105 1079 RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr; -
trunk/Source/WebKit/UIProcess/API/Cocoa/_WKThumbnailView.mm
r270069 r272628 142 142 _lastSnapshotScale = _scale; 143 143 _lastSnapshotMaximumSize = _maximumSnapshotSize; 144 _webPageProxy->takeSnapshot(snapshotRect, bitmapSize, options, [thumbnailView](const WebKit::ShareableBitmap::Handle& imageHandle , WebKit::CallbackBase::Error) {144 _webPageProxy->takeSnapshot(snapshotRect, bitmapSize, options, [thumbnailView](const WebKit::ShareableBitmap::Handle& imageHandle) { 145 145 auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly); 146 146 RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr; -
trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
r272322 r272628 3089 3089 } 3090 3090 3091 void(^copiedCompletionHandler)(CGImageRef) = [completionHandler copy]; 3092 _page->takeSnapshot(WebCore::enclosingIntRect(snapshotRectInContentCoordinates), WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebKit::SnapshotOptionsExcludeDeviceScaleFactor, [=](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) { 3093 if (imageHandle.isNull()) { 3094 copiedCompletionHandler(nullptr); 3095 [copiedCompletionHandler release]; 3096 return; 3097 } 3091 _page->takeSnapshot(WebCore::enclosingIntRect(snapshotRectInContentCoordinates), WebCore::expandedIntSize(WebCore::FloatSize(imageSize)), WebKit::SnapshotOptionsExcludeDeviceScaleFactor, [completionHandler = makeBlockPtr(completionHandler)](const WebKit::ShareableBitmap::Handle& imageHandle) { 3092 if (imageHandle.isNull()) 3093 return completionHandler(nil); 3098 3094 3099 3095 auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly); 3100 3096 3101 if (!bitmap) { 3102 copiedCompletionHandler(nullptr); 3103 [copiedCompletionHandler release]; 3104 return; 3105 } 3106 3107 RetainPtr<CGImageRef> cgImage; 3108 cgImage = bitmap->makeCGImage(); 3109 copiedCompletionHandler(cgImage.get()); 3110 [copiedCompletionHandler release]; 3097 if (!bitmap) 3098 return completionHandler(nil); 3099 3100 completionHandler(bitmap->makeCGImage().get()); 3111 3101 }); 3112 3102 } -
trunk/Source/WebKit/UIProcess/GenericCallback.h
r272606 r272628 156 156 157 157 typedef GenericCallback<> VoidCallback; 158 typedef GenericCallback<const ShareableBitmap::Handle&> ImageCallback;159 158 160 159 template<typename T> -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r272627 r272628 7117 7117 } 7118 7118 7119 void WebPageProxy::imageCallback(const ShareableBitmap::Handle& bitmapHandle, CallbackID callbackID)7120 {7121 auto callback = m_callbacks.take<ImageCallback>(callbackID);7122 if (!callback) {7123 // FIXME: Log error or assert.7124 return;7125 }7126 7127 callback->performCallbackWithReturnValue(bitmapHandle);7128 }7129 7130 7119 void WebPageProxy::stringCallback(const String& resultString, CallbackID callbackID) 7131 7120 { … … 8524 8513 8525 8514 #if PLATFORM(COCOA) 8526 void WebPageProxy::drawRectToImage(WebFrameProxy* frame, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, Ref<ImageCallback>&& callback) 8527 { 8528 if (!hasRunningProcess()) { 8529 callback->invalidate(); 8530 return; 8531 } 8532 8533 auto callbackID = callback->callbackID(); 8534 m_callbacks.put(WTFMove(callback)); 8535 send(Messages::WebPage::DrawRectToImage(frame->frameID(), printInfo, rect, imageSize, callbackID), printingSendOptions(m_isPerformingDOMPrintOperation)); 8515 uint64_t WebPageProxy::drawRectToImage(WebFrameProxy* frame, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&& callback) 8516 { 8517 return sendWithAsyncReply(Messages::WebPage::DrawRectToImage(frame->frameID(), printInfo, rect, imageSize), WTFMove(callback), printingSendOptions(m_isPerformingDOMPrintOperation)); 8536 8518 } 8537 8519 … … 8981 8963 #endif 8982 8964 8983 void WebPageProxy::takeSnapshot(IntRect rect, IntSize bitmapSize, SnapshotOptions options, WTF::Function<void (const ShareableBitmap::Handle&, CallbackBase::Error)>&& callbackFunction) 8984 { 8985 if (!hasRunningProcess()) { 8986 callbackFunction(ShareableBitmap::Handle(), CallbackBase::Error::Unknown); 8987 return; 8988 } 8989 8990 auto callbackID = m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::takeSnapshot"_s)); 8991 send(Messages::WebPage::TakeSnapshot(rect, bitmapSize, options, callbackID)); 8965 void WebPageProxy::takeSnapshot(IntRect rect, IntSize bitmapSize, SnapshotOptions options, CompletionHandler<void(const ShareableBitmap::Handle&)>&& callback) 8966 { 8967 sendWithAsyncReply(Messages::WebPage::TakeSnapshot(rect, bitmapSize, options), WTFMove(callback)); 8992 8968 } 8993 8969 -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r272627 r272628 1294 1294 uint64_t computePagesForPrinting(WebFrameProxy*, const PrintInfo&, CompletionHandler<void(const Vector<WebCore::IntRect>&, double, const WebCore::FloatBoxExtent&)>&&); 1295 1295 #if PLATFORM(COCOA) 1296 void drawRectToImage(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, Ref<ImageCallback>&&);1296 uint64_t drawRectToImage(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&); 1297 1297 void drawPagesToPDF(WebFrameProxy*, const PrintInfo&, uint32_t first, uint32_t count, Ref<DataCallback>&&); 1298 1298 void drawToPDF(WebCore::FrameIdentifier, const Optional<WebCore::FloatRect>&, CompletionHandler<void(const IPC::DataReference&)>&&); … … 1428 1428 void signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String& challengeString, const URL&, CompletionHandler<void(String)>&&); 1429 1429 1430 void takeSnapshot(WebCore::IntRect, WebCore::IntSize bitmapSize, SnapshotOptions, WTF::Function<void (const ShareableBitmap::Handle&, CallbackBase::Error)>&&);1430 void takeSnapshot(WebCore::IntRect, WebCore::IntSize bitmapSize, SnapshotOptions, CompletionHandler<void(const ShareableBitmap::Handle&)>&&); 1431 1431 1432 1432 void navigationGestureDidBegin(); … … 2157 2157 void voidCallback(CallbackID); 2158 2158 void dataCallback(const IPC::DataReference&, CallbackID); 2159 void imageCallback(const ShareableBitmap::Handle&, CallbackID);2160 2159 void stringCallback(const String&, CallbackID); 2161 2160 void invalidateStringCallback(CallbackID); -
trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in
r272627 r272628 166 166 VoidCallback(WebKit::CallbackID callbackID) 167 167 DataCallback(IPC::SharedBufferDataReference resultData, WebKit::CallbackID callbackID) 168 ImageCallback(WebKit::ShareableBitmap::Handle bitmapHandle, WebKit::CallbackID callbackID)169 168 StringCallback(String resultString, WebKit::CallbackID callbackID) 170 169 InvalidateStringCallback(WebKit::CallbackID callbackID) -
trunk/Source/WebKit/UIProcess/mac/WKPrintingView.mm
r272606 r272628 541 541 542 542 IPCCallbackContext* context = new IPCCallbackContext; 543 auto callback = WebKit::ImageCallback::create([context](const WebKit::ShareableBitmap::Handle& imageHandle, WebKit::CallbackBase::Error) {543 auto callback = [context](const WebKit::ShareableBitmap::Handle& imageHandle) { 544 544 std::unique_ptr<IPCCallbackContext> contextDeleter(context); 545 545 pageDidDrawToImage(imageHandle, context); 546 } );547 _latestExpectedPreviewCallback = callback->callbackID().toInteger();546 }; 547 _latestExpectedPreviewCallback = _webFrame->page()->drawRectToImage(_webFrame.get(), WebKit::PrintInfo([_printOperation.get() printInfo]), scaledPrintingRect, imageSize, WTFMove(callback)); 548 548 _expectedPreviewCallbacks.add(_latestExpectedPreviewCallback, scaledPrintingRect); 549 549 550 550 context->view = self; 551 context->callbackID = callback->callbackID().toInteger(); 552 553 _webFrame->page()->drawRectToImage(_webFrame.get(), WebKit::PrintInfo([_printOperation.get() printInfo]), scaledPrintingRect, imageSize, WTFMove(callback)); 551 context->callbackID = _latestExpectedPreviewCallback; 554 552 return; 555 553 } -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r272627 r272628 2426 2426 #endif // !PLATFORM(IOS_FAMILY) 2427 2427 2428 void WebPage::takeSnapshot(IntRect snapshotRect, IntSize bitmapSize, uint32_t options, C allbackID callbackID)2428 void WebPage::takeSnapshot(IntRect snapshotRect, IntSize bitmapSize, uint32_t options, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&& completionHandler) 2429 2429 { 2430 2430 SnapshotOptions snapshotOptions = static_cast<SnapshotOptions>(options); … … 2437 2437 image->bitmap().createHandle(handle, SharedMemory::Protection::ReadOnly); 2438 2438 2439 send(Messages::WebPageProxy::ImageCallback(handle, callbackID));2439 completionHandler(handle); 2440 2440 } 2441 2441 … … 5135 5135 } 5136 5136 5137 void WebPage::drawRectToImage(FrameIdentifier frameID, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, C allbackID callbackID)5137 void WebPage::drawRectToImage(FrameIdentifier frameID, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&& completionHandler) 5138 5138 { 5139 5139 WebFrame* frame = WebProcess::singleton().webFrame(frameID); … … 5153 5153 if (!bitmap) { 5154 5154 ASSERT_NOT_REACHED(); 5155 return ;5155 return completionHandler({ }); 5156 5156 } 5157 5157 auto graphicsContext = bitmap->createGraphicsContext(); … … 5182 5182 image->bitmap().createHandle(handle, SharedMemory::Protection::ReadOnly); 5183 5183 5184 send(Messages::WebPageProxy::ImageCallback(handle, callbackID));5184 completionHandler(handle); 5185 5185 } 5186 5186 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r272627 r272628 966 966 967 967 #if PLATFORM(COCOA) 968 void drawRectToImage(WebCore::FrameIdentifier, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, C allbackID);968 void drawRectToImage(WebCore::FrameIdentifier, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&); 969 969 void drawPagesToPDF(WebCore::FrameIdentifier, const PrintInfo&, uint32_t first, uint32_t count, CallbackID); 970 970 void drawPagesToPDFImpl(WebCore::FrameIdentifier, const PrintInfo&, uint32_t first, uint32_t count, RetainPtr<CFMutableDataRef>& pdfPageData); … … 1592 1592 void runJavaScriptInFrameInScriptWorld(WebCore::RunJavaScriptParameters&&, Optional<WebCore::FrameIdentifier>, const std::pair<ContentWorldIdentifier, String>& worldData, CompletionHandler<void(const IPC::DataReference&, const Optional<WebCore::ExceptionDetails>&)>&&); 1593 1593 void forceRepaint(CompletionHandler<void()>&&); 1594 void takeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, C allbackID);1594 void takeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&); 1595 1595 1596 1596 void preferencesDidChange(const WebPreferencesStore&); -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in
r272627 r272628 400 400 ComputePagesForPrinting(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) -> (Vector<WebCore::IntRect> pageRects, double totalScaleFactorForPrinting, WebCore::RectEdges<float> computedPageMargin) Async 401 401 #if PLATFORM(COCOA) 402 DrawRectToImage(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, WebCore::IntRect rect, WebCore::IntSize imageSize , WebKit::CallbackID callbackID)402 DrawRectToImage(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, WebCore::IntRect rect, WebCore::IntSize imageSize) -> (WebKit::ShareableBitmap::Handle image) Async 403 403 DrawPagesToPDF(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, uint32_t first, uint32_t count, WebKit::CallbackID callbackID) 404 404 #if PLATFORM(IOS_FAMILY) … … 492 492 GetSamplingProfilerOutput(WebKit::CallbackID callbackID) 493 493 494 TakeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options , WebKit::CallbackID callbackID)494 TakeSnapshot(WebCore::IntRect snapshotRect, WebCore::IntSize bitmapSize, uint32_t options) -> (WebKit::ShareableBitmap::Handle image) Async 495 495 #if PLATFORM(MAC) 496 496 PerformImmediateActionHitTestAtLocation(WebCore::FloatPoint location)
Note:
See TracChangeset
for help on using the changeset viewer.