InjectedBundleNodeHandle::renderedImage() needs to be exposed from the Cocoa WebAPI...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Apr 2015 20:12:25 +0000 (20:12 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Apr 2015 20:12:25 +0000 (20:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143341.

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2015-04-03
Reviewed by Anders Carlsson.

* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.h:
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:
(-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:]): Expose rendered
image injected bundle API from the Cocoa layer. A node in the page can be
rendered to an NSImage on MacOS and to a UIImage on iOS.

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.h
Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm

index 19d38d0c6059b9729b1661d81afe0d1bc773088c..58226103e61ee8d933709d41b7ebcc6276ce0130 100644 (file)
@@ -1,3 +1,16 @@
+2015-04-03  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        InjectedBundleNodeHandle::renderedImage() needs to be exposed from the Cocoa WebAPI layer.
+        https://bugs.webkit.org/show_bug.cgi?id=143341.
+
+        Reviewed by Anders Carlsson.
+
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.h:
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:
+        (-[WKWebProcessPlugInNodeHandle renderedImageWithOptions:]): Expose rendered
+        image injected bundle API from the Cocoa layer. A node in the page can be
+        rendered to an NSImage on MacOS and to a UIImage on iOS.
+
 2015-04-03  Chris Dumez  <cdumez@apple.com>
 
         [WK2][iOS] We should prevent NetworkProcess suspension while it has pending SQL transactions
 2015-04-03  Chris Dumez  <cdumez@apple.com>
 
         [WK2][iOS] We should prevent NetworkProcess suspension while it has pending SQL transactions
index e55f58c3aba48a2bc3e8d16a9a96df71e6c726b3..a9a0c9f55b3d703125f0efb3abd2d25cfa2050e8 100644 (file)
 
 #import <Foundation/Foundation.h>
 #import <JavaScriptCore/JavaScriptCore.h>
 
 #import <Foundation/Foundation.h>
 #import <JavaScriptCore/JavaScriptCore.h>
+#import <WebKit/WKImage.h>
+
+#if TARGET_OS_IPHONE
+#import <UIKit/UIImage.h>
+#endif
 
 @class WKWebProcessPlugInFrame;
 
 
 @class WKWebProcessPlugInFrame;
 
@@ -38,6 +43,12 @@ WK_CLASS_AVAILABLE(10_10, 8_0)
 + (WKWebProcessPlugInNodeHandle *)nodeHandleWithJSValue:(JSValue *)value inContext:(JSContext *)context;
 - (WKWebProcessPlugInFrame *)htmlIFrameElementContentFrame;
 
 + (WKWebProcessPlugInNodeHandle *)nodeHandleWithJSValue:(JSValue *)value inContext:(JSContext *)context;
 - (WKWebProcessPlugInFrame *)htmlIFrameElementContentFrame;
 
+#if TARGET_OS_IPHONE
+- (UIImage *)renderedImageWithOptions:(WKSnapshotOptions)options WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+#else
+- (NSImage *)renderedImageWithOptions:(WKSnapshotOptions)options WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+#endif
+
 @property (nonatomic, readonly) CGRect elementBounds;
 @property (nonatomic) BOOL HTMLInputElementIsAutoFilled;
 @property (nonatomic, readonly) BOOL HTMLInputElementIsUserEdited;
 @property (nonatomic, readonly) CGRect elementBounds;
 @property (nonatomic) BOOL HTMLInputElementIsAutoFilled;
 @property (nonatomic, readonly) BOOL HTMLInputElementIsUserEdited;
index 4bad43483a2738ba022afc154662430d99632f8c..d57d04584ebcbb05587863ed25ebebee7b4d71f2 100644 (file)
@@ -28,6 +28,7 @@
 
 #import "WKWebProcessPlugInFrameInternal.h"
 #import <WebCore/IntRect.h>
 
 #import "WKWebProcessPlugInFrameInternal.h"
 #import <WebCore/IntRect.h>
+#import <WebKit/WebImage.h>
 
 #if WK_API_ENABLED
 
 
 #if WK_API_ENABLED
 
@@ -63,6 +64,28 @@ using namespace WebKit;
     return [wrapper(*frame.release().leakRef()) autorelease];
 }
 
     return [wrapper(*frame.release().leakRef()) autorelease];
 }
 
+#if PLATFORM(IOS)
+- (UIImage *)renderedImageWithOptions:(WKSnapshotOptions)options
+{
+    RefPtr<WebImage> image = _nodeHandle->renderedImage(options);
+    if (!image || !image->bitmap())
+        return nil;
+
+    return [[[UIImage alloc] initWithCGImage:image->bitmap()->makeCGImage().get()] autorelease];
+}
+#endif
+
+#if PLATFORM(MAC)
+- (NSImage *)renderedImageWithOptions:(WKSnapshotOptions)options
+{
+    RefPtr<WebImage> image = _nodeHandle->renderedImage(options);
+    if (!image || !image->bitmap())
+        return nil;
+
+    return [[[NSImage alloc] initWithCGImage:image->bitmap()->makeCGImage().get() size:NSZeroSize] autorelease];
+}
+#endif
+
 - (CGRect)elementBounds
 {
     return _nodeHandle->elementBounds();
 - (CGRect)elementBounds
 {
     return _nodeHandle->elementBounds();