Bug 143341

Summary: InjectedBundleNodeHandle::renderedImage() needs to be exposed from the Cocoa WebAPI layer
Product: WebKit Reporter: Said Abou-Hallawa <sabouhallawa>
Component: WebKit2Assignee: Said Abou-Hallawa <sabouhallawa>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, commit-queue, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch none

Description Said Abou-Hallawa 2015-04-02 13:31:22 PDT
A given node in the web page can render itself to an NSImage or UIImage. This can be useful for the UI process to draw complex static html elements (e.g. table, SVG etc) without having to create a WKView for the drawing. All it needs is to create a background WebProcess, load a local web page, get the node of a specific item and draw it to a bitmap.
Comment 1 Said Abou-Hallawa 2015-04-02 13:35:59 PDT
Created attachment 250004 [details]
Patch
Comment 2 Darin Adler 2015-04-02 13:49:42 PDT
Comment on attachment 250004 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=250004&action=review

> Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.h:46
> +#if TARGET_OS_IPHONE
> +- (UIImage *)renderedImage:(WKSnapshotOptions)options;
> +#else
> +- (NSImage *)renderedImage:(WKSnapshotOptions)options;
> +#endif

I think we need new availability annotation when we add a new method.

> Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:74
> +    return [[UIImage alloc] initWithCGImage:image->bitmap()->makeCGImage().get()];

This is missing an autorelease.

> Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:85
> +    return [[NSImage alloc] initWithCGImage:image->bitmap()->makeCGImage().get() size:NSZeroSize];

This is missing an autorelease.
Comment 3 Anders Carlsson 2015-04-03 11:26:11 PDT
(In reply to comment #2)
> Comment on attachment 250004 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=250004&action=review
> 
> > Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.h:46
> > +#if TARGET_OS_IPHONE
> > +- (UIImage *)renderedImage:(WKSnapshotOptions)options;
> > +#else
> > +- (NSImage *)renderedImage:(WKSnapshotOptions)options;
> > +#endif
> 
> I think we need new availability annotation when we add a new method.
> 

Yes. I also think we should call this renderedImageWithOptions:
Comment 4 Said Abou-Hallawa 2015-04-03 11:39:57 PDT
Created attachment 250091 [details]
Patch
Comment 5 Said Abou-Hallawa 2015-04-03 12:18:59 PDT
(In reply to comment #2)
> Comment on attachment 250004 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=250004&action=review
> 
> > Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.h:46
> > +#if TARGET_OS_IPHONE
> > +- (UIImage *)renderedImage:(WKSnapshotOptions)options;
> > +#else
> > +- (NSImage *)renderedImage:(WKSnapshotOptions)options;
> > +#endif
> 
> I think we need new availability annotation when we add a new method.
> 

Done. I was not aware of the Cocoa availability annotation.

> > Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:74
> > +    return [[UIImage alloc] initWithCGImage:image->bitmap()->makeCGImage().get()];
> 
> This is missing an autorelease.
> 

Done.

> > Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.mm:85
> > +    return [[NSImage alloc] initWithCGImage:image->bitmap()->makeCGImage().get() size:NSZeroSize];
> 
> This is missing an autorelease.

Done.
Comment 6 Said Abou-Hallawa 2015-04-03 12:19:14 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > Comment on attachment 250004 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=250004&action=review
> > 
> > > Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInNodeHandle.h:46
> > > +#if TARGET_OS_IPHONE
> > > +- (UIImage *)renderedImage:(WKSnapshotOptions)options;
> > > +#else
> > > +- (NSImage *)renderedImage:(WKSnapshotOptions)options;
> > > +#endif
> > 
> > I think we need new availability annotation when we add a new method.
> > 
> 
> Yes. I also think we should call this renderedImageWithOptions:

Done.
Comment 7 Radar WebKit Bug Importer 2015-04-03 12:20:48 PDT
<rdar://problem/20419231>
Comment 8 WebKit Commit Bot 2015-04-03 13:13:17 PDT
Comment on attachment 250091 [details]
Patch

Clearing flags on attachment: 250091

Committed r182327: <http://trac.webkit.org/changeset/182327>
Comment 9 WebKit Commit Bot 2015-04-03 13:13:21 PDT
All reviewed patches have been landed.  Closing bug.