Diff
Modified: trunk/Source/WebKit/ChangeLog (260666 => 260667)
--- trunk/Source/WebKit/ChangeLog 2020-04-24 20:57:23 UTC (rev 260666)
+++ trunk/Source/WebKit/ChangeLog 2020-04-24 21:02:48 UTC (rev 260667)
@@ -1,5 +1,34 @@
2020-04-24 David Kilzer <[email protected]>
+ Use CocoaImage platform abstraction for NSImage/UIImage
+ <https://webkit.org/b/210974>
+
+ Reviewed by Darin Adler.
+
+ * Platform/cocoa/CocoaImage.h: Add.
+ - Define CocoaImage here for cross-platform use. Don't use
+ OBJC_CLASS() here because this is an Objective-C header.
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView takeSnapshotWithConfiguration:completionHandler:]):
+ - Combine separate platform-specific methods into one method.
+ * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
+ - Combine separate platform-specific instance variables into
+ one instance variable.
+ (-[_WKActivatedElementInfo image]):
+ - Combine separate methods into one platform-specific method.
+ * UIProcess/QuickLookThumbnailLoader.h:
+ - Move cross-platform definition to CocoaImge.h.
+ * UIProcess/QuickLookThumbnailLoader.mm:
+ - Drive-by fix of soft-linking header include order.
+ * WebKit.xcodeproj/project.pbxproj:
+ - Add CocoaImage.h to the project.
+ * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:
+ (-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:]):
+ (-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:width:]):
+ - Combine separate platform-specific methods into one method.
+
+2020-04-24 David Kilzer <[email protected]>
+
IPC::Decoder should use create() pattern
<https://webkit.org/b/210949>
<rdar://problem/62144409>
Copied: trunk/Source/WebKit/Platform/cocoa/CocoaImage.h (from rev 260666, trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h) (0 => 260667)
--- trunk/Source/WebKit/Platform/cocoa/CocoaImage.h (rev 0)
+++ trunk/Source/WebKit/Platform/cocoa/CocoaImage.h 2020-04-24 21:02:48 UTC (rev 260667)
@@ -0,0 +1,32 @@
+/*
+* Copyright (C) 2020 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.
+*/
+
+#if USE(APPKIT)
+@class NSImage;
+using CocoaImage = NSImage;
+#else
+@class UIImage;
+using CocoaImage = UIImage;
+#endif
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (260666 => 260667)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2020-04-24 20:57:23 UTC (rev 260666)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2020-04-24 21:02:48 UTC (rev 260667)
@@ -31,6 +31,7 @@
#import "APIPageConfiguration.h"
#import "APISerializedScriptValue.h"
#import "AttributedString.h"
+#import "CocoaImage.h"
#import "CompletionHandlerCallChecker.h"
#import "ContentAsStringIncludesChildFrames.h"
#import "DiagnosticLoggingClient.h"
@@ -979,8 +980,7 @@
});
}
-#if PLATFORM(MAC)
-- (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(NSImage *, NSError *))completionHandler
+- (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(CocoaImage *, NSError *))completionHandler
{
CGRect rectInViewCoordinates = snapshotConfiguration && !CGRectIsNull(snapshotConfiguration.rect) ? snapshotConfiguration.rect : self.bounds;
CGFloat snapshotWidth;
@@ -990,6 +990,8 @@
snapshotWidth = self.bounds.size.width;
auto handler = makeBlockPtr(completionHandler);
+
+#if USE(APPKIT)
CGFloat imageScale = snapshotWidth / rectInViewCoordinates.size.width;
CGFloat imageHeight = imageScale * rectInViewCoordinates.size.height;
@@ -1011,35 +1013,23 @@
auto bitmap = WebKit::ShareableBitmap::create(imageHandle, WebKit::SharedMemory::Protection::ReadOnly);
RetainPtr<CGImageRef> cgImage = bitmap ? bitmap->makeCGImage() : nullptr;
- RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:NSMakeSize(snapshotWidth, imageHeight)]);
- handler(nsImage.get(), nil);
+ auto image = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:NSMakeSize(snapshotWidth, imageHeight)]);
+ handler(image.get(), nil);
});
-}
-
-#elif PLATFORM(IOS_FAMILY)
-- (void)takeSnapshotWithConfiguration:(WKSnapshotConfiguration *)snapshotConfiguration completionHandler:(void(^)(UIImage *, NSError *))completionHandler
-{
- CGRect rectInViewCoordinates = snapshotConfiguration && !CGRectIsNull(snapshotConfiguration.rect) ? snapshotConfiguration.rect : self.bounds;
- CGFloat snapshotWidth;
- if (snapshotConfiguration)
- snapshotWidth = snapshotConfiguration.snapshotWidth.doubleValue ?: rectInViewCoordinates.size.width;
- else
- snapshotWidth = self.bounds.size.width;
-
- auto handler = makeBlockPtr(completionHandler);
+#else
CGFloat deviceScale = _page->deviceScaleFactor();
RetainPtr<WKWebView> strongSelf = self;
auto callSnapshotRect = [strongSelf, rectInViewCoordinates, snapshotWidth, deviceScale, handler] {
[strongSelf _snapshotRect:rectInViewCoordinates intoImageOfWidth:(snapshotWidth * deviceScale) completionHandler:[strongSelf, handler, deviceScale](CGImageRef snapshotImage) {
RetainPtr<NSError> error;
- RetainPtr<UIImage> uiImage;
+ RetainPtr<UIImage> image;
if (!snapshotImage)
error = createNSError(WKErrorUnknown);
else
- uiImage = adoptNS([[UIImage alloc] initWithCGImage:snapshotImage scale:deviceScale orientation:UIImageOrientationUp]);
+ image = adoptNS([[UIImage alloc] initWithCGImage:snapshotImage scale:deviceScale orientation:UIImageOrientationUp]);
- handler(uiImage.get(), error.get());
+ handler(image.get(), error.get());
}];
};
@@ -1055,8 +1045,8 @@
}
callSnapshotRect();
});
+#endif
}
-#endif
- (void)setAllowsBackForwardNavigationGestures:(BOOL)allowsBackForwardNavigationGestures
{
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm (260666 => 260667)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm 2020-04-24 20:57:23 UTC (rev 260666)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm 2020-04-24 21:02:48 UTC (rev 260667)
@@ -26,17 +26,16 @@
#import "config.h"
#import "_WKActivatedElementInfoInternal.h"
+#import "CocoaImage.h"
#import "ShareableBitmap.h"
#import <wtf/RetainPtr.h>
-#if PLATFORM(IOS_FAMILY)
+#if USE(APPKIT)
+#import <AppKit/NSImage.h>
+#else
#import <UIKit/UIImage.h>
#endif
-#if PLATFORM(MAC)
-#import <AppKit/NSImage.h>
-#endif
-
@implementation _WKActivatedElementInfo {
RetainPtr<NSURL> _URL;
RetainPtr<NSURL> _imageURL;
@@ -44,13 +43,10 @@
WebCore::IntPoint _interactionLocation;
RetainPtr<NSString> _ID;
RefPtr<WebKit::ShareableBitmap> _image;
+ RetainPtr<CocoaImage> _cocoaImage;
#if PLATFORM(IOS_FAMILY)
- RetainPtr<UIImage> _uiImage;
RetainPtr<NSDictionary> _userInfo;
#endif
-#if PLATFORM(MAC)
- RetainPtr<NSImage> _nsImage;
-#endif
BOOL _animatedImage;
}
@@ -150,36 +146,24 @@
{
return _userInfo.get();
}
+#endif
-- (UIImage *)image
+- (CocoaImage *)image
{
- if (_uiImage)
- return [[_uiImage copy] autorelease];
+ if (_cocoaImage)
+ return [[_cocoaImage copy] autorelease];
if (!_image)
return nil;
- _uiImage = adoptNS([[UIImage alloc] initWithCGImage:_image->makeCGImageCopy().get()]);
- _image = nullptr;
-
- return [[_uiImage copy] autorelease];
-}
+#if USE(APPKIT)
+ _cocoaImage = adoptNS([[NSImage alloc] initWithCGImage:_image->makeCGImageCopy().get() size:NSSizeFromCGSize(_boundingRect.size)]);
+#else
+ _cocoaImage = adoptNS([[UIImage alloc] initWithCGImage:_image->makeCGImageCopy().get()]);
#endif
-
-#if PLATFORM(MAC)
-- (NSImage *)image
-{
- if (_nsImage)
- return [[_nsImage copy] autorelease];
-
- if (!_image)
- return nil;
-
- _nsImage = adoptNS([[NSImage alloc] initWithCGImage:_image->makeCGImageCopy().get() size:NSSizeFromCGSize(_boundingRect.size)]);
_image = nullptr;
- return [[_nsImage copy] autorelease];
+ return [[_cocoaImage copy] autorelease];
}
-#endif
@end
Modified: trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h (260666 => 260667)
--- trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h 2020-04-24 20:57:23 UTC (rev 260666)
+++ trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.h 2020-04-24 21:02:48 UTC (rev 260667)
@@ -25,13 +25,7 @@
#if HAVE(QUICKLOOK_THUMBNAILING)
-#if USE(APPKIT)
-@class NSImage;
-using CocoaImage = NSImage;
-#else
-@class UIImage;
-using CocoaImage = UIImage;
-#endif
+#import "CocoaImage.h"
@interface WKQLThumbnailQueueManager : NSObject
Modified: trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm (260666 => 260667)
--- trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm 2020-04-24 20:57:23 UTC (rev 260666)
+++ trunk/Source/WebKit/UIProcess/QuickLookThumbnailLoader.mm 2020-04-24 21:02:48 UTC (rev 260667)
@@ -28,10 +28,10 @@
#if HAVE(QUICKLOOK_THUMBNAILING)
+#import <wtf/FileSystem.h>
+
#import "QuickLookThumbnailingSoftLink.h"
-#import <wtf/FileSystem.h>
-
@implementation WKQLThumbnailQueueManager
- (instancetype)init
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (260666 => 260667)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2020-04-24 20:57:23 UTC (rev 260666)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2020-04-24 21:02:48 UTC (rev 260667)
@@ -932,6 +932,7 @@
41FAF5F51E3C0649001AE678 /* WebRTCResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FAF5F41E3C0641001AE678 /* WebRTCResolver.h */; };
41FAF5F81E3C1021001AE678 /* LibWebRTCResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 41FAF5F61E3C0B47001AE678 /* LibWebRTCResolver.h */; };
4459984222833E8700E61373 /* SyntheticEditingCommandType.h in Headers */ = {isa = PBXBuildFile; fileRef = 4459984122833E6000E61373 /* SyntheticEditingCommandType.h */; };
+ 4482734724528F6000A95493 /* CocoaImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 4482734624528F6000A95493 /* CocoaImage.h */; };
449D90DA21FDC30B00F677C0 /* LocalAuthenticationSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 449D90D821FD63FE00F677C0 /* LocalAuthenticationSoftLink.mm */; };
44E936FD2447C2D8009FA3E3 /* LegacyCustomProtocolID.h in Headers */ = {isa = PBXBuildFile; fileRef = 44E936FC2447C256009FA3E3 /* LegacyCustomProtocolID.h */; };
460F488F1F996F7100CF4B87 /* WebSWContextManagerConnectionMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460F488D1F996F6C00CF4B87 /* WebSWContextManagerConnectionMessageReceiver.cpp */; };
@@ -3524,6 +3525,7 @@
41FCD6BF23CE044000C62567 /* RemoteSampleBufferDisplayLayerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoteSampleBufferDisplayLayerManager.h; sourceTree = "<group>"; };
4450AEBF1DC3FAE5009943F2 /* SharedMemoryCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedMemoryCocoa.cpp; sourceTree = "<group>"; };
4459984122833E6000E61373 /* SyntheticEditingCommandType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SyntheticEditingCommandType.h; sourceTree = "<group>"; };
+ 4482734624528F6000A95493 /* CocoaImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoaImage.h; sourceTree = "<group>"; };
449D90D821FD63FE00F677C0 /* LocalAuthenticationSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalAuthenticationSoftLink.mm; sourceTree = "<group>"; };
44A481C621F2D27B00F2F919 /* ClientCertificateAuthenticationXPCConstants.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ClientCertificateAuthenticationXPCConstants.cpp; sourceTree = "<group>"; };
44E936FC2447C256009FA3E3 /* LegacyCustomProtocolID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LegacyCustomProtocolID.h; sourceTree = "<group>"; };
@@ -7690,6 +7692,7 @@
4450AEBE1DC3FAAC009943F2 /* cocoa */ = {
isa = PBXGroup;
children = (
+ 4482734624528F6000A95493 /* CocoaImage.h */,
BCE0937614FB128B001138D9 /* LayerHostingContext.h */,
BCE0937514FB128B001138D9 /* LayerHostingContext.mm */,
A1798B3D222D97A2000764BD /* PaymentAuthorizationPresenter.h */,
@@ -10737,6 +10740,7 @@
41897EDA1F415D8A0016FA42 /* CacheStorageEngineConnection.h in Headers */,
1AA2E51D12E4C05E00BC4966 /* CGUtilities.h in Headers */,
57B4B46020B504AC00D4AD79 /* ClientCertificateAuthenticationXPCConstants.h in Headers */,
+ 4482734724528F6000A95493 /* CocoaImage.h in Headers */,
CE11AD521CBC482F00681EE5 /* CodeSigning.h in Headers */,
37BEC4E119491486008B4286 /* CompletionHandlerCallChecker.h in Headers */,
37C4E9F6131C6E7E0029BD5A /* config.h in Headers */,
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm (260666 => 260667)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm 2020-04-24 20:57:23 UTC (rev 260666)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm 2020-04-24 21:02:48 UTC (rev 260667)
@@ -26,6 +26,7 @@
#import "config.h"
#import "WKWebProcessPlugInNodeHandleInternal.h"
+#import "CocoaImage.h"
#import "WKSharedAPICast.h"
#import "WKWebProcessPlugInFrameInternal.h"
#import <WebCore/HTMLTextFormControlElement.h>
@@ -54,13 +55,12 @@
return WebKit::wrapper(_nodeHandle->htmlIFrameElementContentFrame());
}
-#if PLATFORM(IOS_FAMILY)
-- (UIImage *)renderedImageWithOptions:(WKSnapshotOptions)options
+- (CocoaImage *)renderedImageWithOptions:(WKSnapshotOptions)options
{
return [self renderedImageWithOptions:options width:nil];
}
-- (UIImage *)renderedImageWithOptions:(WKSnapshotOptions)options width:(NSNumber *)width
+- (CocoaImage *)renderedImageWithOptions:(WKSnapshotOptions)options width:(NSNumber *)width
{
Optional<float> optionalWidth;
if (width)
@@ -70,30 +70,13 @@
if (!image)
return nil;
+#if USE(APPKIT)
+ return [[[NSImage alloc] initWithCGImage:image->bitmap().makeCGImage().get() size:NSZeroSize] autorelease];
+#else
return [[[UIImage alloc] initWithCGImage:image->bitmap().makeCGImage().get()] autorelease];
-}
#endif
-
-#if PLATFORM(MAC)
-- (NSImage *)renderedImageWithOptions:(WKSnapshotOptions)options
-{
- return [self renderedImageWithOptions:options width:nil];
}
-- (NSImage *)renderedImageWithOptions:(WKSnapshotOptions)options width:(NSNumber *)width
-{
- Optional<float> optionalWidth;
- if (width)
- optionalWidth = width.floatValue;
-
- RefPtr<WebKit::WebImage> image = _nodeHandle->renderedImage(WebKit::toSnapshotOptions(options), options & kWKSnapshotOptionsExcludeOverflow, optionalWidth);
- if (!image)
- return nil;
-
- return [[[NSImage alloc] initWithCGImage:image->bitmap().makeCGImage().get() size:NSZeroSize] autorelease];
-}
-#endif
-
- (CGRect)elementBounds
{
return _nodeHandle->elementBounds();