Bug 89872 - [WK2] Add new C API to generate MHTML data from the UI process
Summary: [WK2] Add new C API to generate MHTML data from the UI process
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 89873
  Show dependency treegraph
 
Reported: 2012-06-25 05:51 PDT by Mario Sanchez Prada
Modified: 2012-08-08 00:12 PDT (History)
4 users (show)

See Also:


Attachments
Patch proposal (9.72 KB, patch)
2012-06-25 06:59 PDT, Mario Sanchez Prada
buildbot: commit-queue-
Details | Formatted Diff | Diff
Patch proposal (9.73 KB, patch)
2012-06-25 07:33 PDT, Mario Sanchez Prada
cgarcia: review-
buildbot: commit-queue-
Details | Formatted Diff | Diff
Patch proposal (9.81 KB, patch)
2012-06-26 00:36 PDT, Mario Sanchez Prada
andersca: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mario Sanchez Prada 2012-06-25 05:51:44 PDT
It would be good to have a way in WK2 to generate MHTML date for a page from the UIProcess, by providing a new C API wrapping the following functions from WebCore::MHTMLArchive:

    class MHTMLArchive : public Archive {
    public:
        [...]
        static PassRefPtr<SharedBuffer> generateMHTMLData(Page*);
        // Binary encoding results in smaller MHTML files but they might not work in other browsers.
        static PassRefPtr<SharedBuffer> generateMHTMLDataUsingBinaryEncoding(Page*);
        [...]
    };

This bug is for that.
Comment 1 Mario Sanchez Prada 2012-06-25 06:58:10 PDT
Adding people that might be interested in this bug to CC
Comment 2 Mario Sanchez Prada 2012-06-25 06:59:38 PDT
Created attachment 149283 [details]
Patch proposal

Patch implemented this wrapping with just one function and a 'bool useBinaryEncoding' parameter.
Comment 3 Build Bot 2012-06-25 07:18:26 PDT
Comment on attachment 149283 [details]
Patch proposal

Attachment 149283 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/13087169
Comment 4 Mario Sanchez Prada 2012-06-25 07:33:13 PDT
Created attachment 149289 [details]
Patch proposal

Fixing issue in the mac EWS bot
Comment 5 Build Bot 2012-06-25 08:17:23 PDT
Comment on attachment 149289 [details]
Patch proposal

Attachment 149289 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/13089165
Comment 6 Carlos Garcia Campos 2012-06-25 23:34:50 PDT
Comment on attachment 149289 [details]
Patch proposal

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

> Source/WebKit2/UIProcess/API/C/WKPage.cpp:602
> +    WKPageGetContentsAsMHTMLData(pageRef, callGetContentsAsMHTMLDataBlockAndDispose, Block_copy(block));

You are missing the bool useBinaryEncoding parameter here. And the order is context, callback, you are passing the callback before the context.
Comment 7 Mario Sanchez Prada 2012-06-26 00:36:39 PDT
Created attachment 149472 [details]
Patch proposal

(In reply to comment #6)
> (From update of attachment 149289 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=149289&action=review
> 
> > Source/WebKit2/UIProcess/API/C/WKPage.cpp:602
> > +    WKPageGetContentsAsMHTMLData(pageRef, callGetContentsAsMHTMLDataBlockAndDispose, Block_copy(block));
> 
> You are missing the bool useBinaryEncoding parameter here. And the order is context, callback, you are passing the callback before the context.

Ah! That explains things. Attaching a new patch
Comment 8 Mario Sanchez Prada 2012-07-18 03:36:44 PDT
Ping reviewers?
Comment 9 Carlos Garcia Campos 2012-07-18 03:50:20 PDT
Comment on attachment 149472 [details]
Patch proposal

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

Patch looks good to me in general, but since it adds new C API it would be great if Anders or Sam could take a look at it too.

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:1845
> +    if (buffer)
> +        dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());

I don't think buffer can be null
Comment 10 Mario Sanchez Prada 2012-07-19 04:09:01 PDT
(In reply to comment #9)
> (From update of attachment 149472 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=149472&action=review
> 
> Patch looks good to me in general, but since it adds new C API it would be 
> great if Anders or Sam could take a look at it too.

I already pinged Anders in IRC, who already confirmed before me being on holidays that he would take a look to this.
Comment 11 Anders Carlsson 2012-08-07 17:09:17 PDT
Comment on attachment 149472 [details]
Patch proposal

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

> Source/WebKit2/UIProcess/API/C/WKPage.cpp:604
> +#ifdef __BLOCKS__
> +static void callGetContentsAsMHTMLDataBlockAndDispose(WKDataRef mhtmlData, WKErrorRef error, void* context)
> +{
> +    WKPageGetContentsAsMHTMLDataBlock block = (WKPageGetContentsAsMHTMLDataBlock)context;
> +    block(mhtmlData, error);
> +    Block_release(block);
> +}
> +
> +void WKPageGetContentsAsMHTMLData_b(WKPageRef pageRef, bool useBinaryEncoding, WKPageGetContentsAsMHTMLDataBlock block)
> +{
> +    WKPageGetContentsAsMHTMLData(pageRef, useBinaryEncoding, Block_copy(block), callGetContentsAsMHTMLDataBlockAndDispose);
> +}
> +#endif

We don't need this API, blocks don't work well with the C API since none of the WK objects are captured by value.
Comment 12 Mario Sanchez Prada 2012-08-08 00:09:06 PDT
(In reply to comment #11)
> [...] 
> We don't need this API, blocks don't work well with the C API since none of
> the WK objects are captured by value.

Thanks for pointing out this issue (which I was not aware of).

I'll remove that API when landing. Thanks for the review.
Comment 13 Mario Sanchez Prada 2012-08-08 00:12:45 PDT
Committed r125002: <http://trac.webkit.org/changeset/125002>