Bug 106440 - [EFL][WK2] Add ewk_view_page_contents_get() API
Summary: [EFL][WK2] Add ewk_view_page_contents_get() API
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit EFL (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: KwangYong Choi
URL:
Keywords:
Depends on:
Blocks: 106620 108634
  Show dependency treegraph
 
Reported: 2013-01-09 03:36 PST by KwangYong Choi
Modified: 2013-02-03 23:35 PST (History)
7 users (show)

See Also:


Attachments
Patch (4.61 KB, patch)
2013-01-09 03:56 PST, KwangYong Choi
no flags Details | Formatted Diff | Diff
Patch (5.18 KB, patch)
2013-01-09 20:54 PST, KwangYong Choi
no flags Details | Formatted Diff | Diff
Patch (5.17 KB, patch)
2013-01-09 20:57 PST, KwangYong Choi
no flags Details | Formatted Diff | Diff
Patch (5.00 KB, patch)
2013-01-09 23:02 PST, KwangYong Choi
webkit.review.bot: commit-queue-
Details | Formatted Diff | Diff
Patch (5.00 KB, patch)
2013-01-10 01:31 PST, KwangYong Choi
no flags Details | Formatted Diff | Diff
Patch (5.00 KB, patch)
2013-01-10 18:14 PST, KwangYong Choi
no flags Details | Formatted Diff | Diff
Patch (4.97 KB, patch)
2013-01-10 18:16 PST, KwangYong Choi
no flags Details | Formatted Diff | Diff
Patch (6.58 KB, patch)
2013-01-10 23:30 PST, KwangYong Choi
no flags Details | Formatted Diff | Diff
Patch (6.58 KB, patch)
2013-01-10 23:53 PST, KwangYong Choi
no flags Details | Formatted Diff | Diff
Patch (6.50 KB, patch)
2013-01-11 00:19 PST, KwangYong Choi
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description KwangYong Choi 2013-01-09 03:36:14 PST
Add ewk_view_mhtml_data_get() API for getting mhtml data of current page.
Comment 1 KwangYong Choi 2013-01-09 03:56:58 PST
Created attachment 181892 [details]
Patch
Comment 2 WebKit Review Bot 2013-01-09 03:59:37 PST
Attachment 181892 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebKit2/ChangeLog', u'Source/WebKit..." exit_code: 1
Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:954:  When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Mikhail Pozdnyakov 2013-01-09 04:51:23 PST
Comment on attachment 181892 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:941
> +    Ewk_View_MHTML_Data_Cb MHTMLDataCallback = reinterpret_cast<Ewk_View_MHTML_Data_Cb>(context);

why reinterpret_cast? static_cast should work here as far as I remember.

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:943
> +    MHTMLDataCallback(webData.get()->size(), webData.get()->bytes());

you don't need '.get()' invoking

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:958
> +    return false;

UNUSED_PARAM ?

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:323
> +typedef void (*Ewk_View_MHTML_Data_Cb)(unsigned size, const unsigned char *bytes);

why not 'const char*'?
Comment 4 Chris Dumez 2013-01-09 05:06:18 PST
Comment on attachment 181892 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:938
> +static void ewk_view_mhtml_data_callback(WKDataRef wkData, WKErrorRef, void* context)

I think we should use camel case here since this is coding style for non-exposed functions.

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:943
> +    MHTMLDataCallback(webData.get()->size(), webData.get()->bytes());

webData->size(), webData->bytes() (i.e. .get() is useless)

>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:954
>> +                                                            ewk_view_mhtml_data_callback), false);
> 
> When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]

Please fix style. Also, it would be nice to have an inline comment to indicate what 'false' stands for. e.g. false /* useBinaryEncoding */

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:323
> +typedef void (*Ewk_View_MHTML_Data_Cb)(unsigned size, const unsigned char *bytes);

Shouldn't we reverse the arguments? It feels better to me to get the array first and then its size second.

Also, why "const unsigned char *" instead of "const char *"? Technically, you are returning a string, not binary bytes. "bytes" may be a bit confusing here.

> Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp:926
> +    ASSERT_EQ(size, strlen(reinterpret_cast<const char*>(bytes)));

Question: why do we pass the size to the callback if the array is null terminated? Usually it is one or the other.

> Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp:928
> +    MHTMLDataObtained = true;

No validation of the data besides its length?
Comment 5 KwangYong Choi 2013-01-09 20:09:47 PST
Comment on attachment 181892 [details]
Patch

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

>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:938
>> +static void ewk_view_mhtml_data_callback(WKDataRef wkData, WKErrorRef, void* context)
> 
> I think we should use camel case here since this is coding style for non-exposed functions.

OK. I will use camel case here.

>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:941
>> +    Ewk_View_MHTML_Data_Cb MHTMLDataCallback = reinterpret_cast<Ewk_View_MHTML_Data_Cb>(context);
> 
> why reinterpret_cast? static_cast should work here as far as I remember.

static_cast is not work.

>>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:943
>>> +    MHTMLDataCallback(webData.get()->size(), webData.get()->bytes());
>> 
>> you don't need '.get()' invoking
> 
> webData->size(), webData->bytes() (i.e. .get() is useless)

OK.

>>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:954
>>> +                                                            ewk_view_mhtml_data_callback), false);
>> 
>> When wrapping a line, only indent 4 spaces.  [whitespace/indent] [3]
> 
> Please fix style. Also, it would be nice to have an inline comment to indicate what 'false' stands for. e.g. false /* useBinaryEncoding */

OK I will fix.

>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:958
>> +    return false;
> 
> UNUSED_PARAM ?

OK. I will add UNUSED_PARAM.

>>> Source/WebKit2/UIProcess/API/efl/ewk_view.h:323
>>> +typedef void (*Ewk_View_MHTML_Data_Cb)(unsigned size, const unsigned char *bytes);
>> 
>> why not 'const char*'?
> 
> Shouldn't we reverse the arguments? It feels better to me to get the array first and then its size second.
> 
> Also, why "const unsigned char *" instead of "const char *"? Technically, you are returning a string, not binary bytes. "bytes" may be a bit confusing here.

OK. I will reverse the arguments. It's my work sequence. I just worked size first.
And also change const unsigned char *bytes to const char *data.

>> Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp:926
>> +    ASSERT_EQ(size, strlen(reinterpret_cast<const char*>(bytes)));
> 
> Question: why do we pass the size to the callback if the array is null terminated? Usually it is one or the other.

Actually, the buffer is always null terminated string. Shall I remove the size argument?

>> Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp:928
>> +    MHTMLDataObtained = true;
> 
> No validation of the data besides its length?

OK. I will add the data comparison routine.
Comment 6 KwangYong Choi 2013-01-09 20:54:24 PST
Created attachment 182056 [details]
Patch
Comment 7 KwangYong Choi 2013-01-09 20:57:28 PST
Created attachment 182057 [details]
Patch
Comment 8 Chris Dumez 2013-01-09 21:59:36 PST
Comment on attachment 182057 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:323
> +typedef void (*Ewk_View_MHTML_Data_Cb)(const char *data, unsigned length);

I would remove the length argument since data is a NULL-terminated string.
Comment 9 KwangYong Choi 2013-01-09 23:02:43 PST
Created attachment 182070 [details]
Patch

Removed length argument in callback function.
Comment 10 Benjamin Poulain 2013-01-09 23:06:50 PST
(In reply to comment #8)
> (From update of attachment 182057 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=182057&action=review
> 
> > Source/WebKit2/UIProcess/API/efl/ewk_view.h:323
> > +typedef void (*Ewk_View_MHTML_Data_Cb)(const char *data, unsigned length);
> 
> I would remove the length argument since data is a NULL-terminated string.

This depends a lot on the platform, on some architecture you really don't want to read memory if you can avoid it (some ARMv7 implementations for example).

On Intel, the caches are so huge, that probably does not matter.

(I don't mind either way for this patch)
Comment 11 WebKit Review Bot 2013-01-10 00:13:06 PST
Comment on attachment 182070 [details]
Patch

Attachment 182070 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/15762841

New failing tests:
inspector-protocol/debugger-terminate-dedicated-worker-while-paused.html
Comment 12 KwangYong Choi 2013-01-10 01:31:46 PST
Created attachment 182086 [details]
Patch

Upload same patch again.
Comment 13 Gyuyoung Kim 2013-01-10 18:04:47 PST
Comment on attachment 182086 [details]
Patch

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

=

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:954
> +        ewkViewMHTMLDataCallback), false /* useBinaryEncoding */);

I don't know you should mention /* useBinaryEncoding */ comment. We can know what mean *false* if we see getContentsAsMHTMLData().

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:318
> + * Creates a type name for the callback function used to get the mhtml data.

s/mhtml/MHTML/g

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:320
> + * @param data string buffer of the mhtml data

ditto.

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:859
> + * @param o view object to get mhtml data

ditto.

> Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp:921
> +static bool MHTMLDataObtained = false;

Generally, verb is placed first. For example, obtainedMHTMLData.
Comment 14 KwangYong Choi 2013-01-10 18:12:03 PST
Comment on attachment 182086 [details]
Patch

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

>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:954
>> +        ewkViewMHTMLDataCallback), false /* useBinaryEncoding */);
> 
> I don't know you should mention /* useBinaryEncoding */ comment. We can know what mean *false* if we see getContentsAsMHTMLData().

OK. I will remove.

>> Source/WebKit2/UIProcess/API/efl/ewk_view.h:318
>> + * Creates a type name for the callback function used to get the mhtml data.
> 
> s/mhtml/MHTML/g

OK

>> Source/WebKit2/UIProcess/API/efl/ewk_view.h:320
>> + * @param data string buffer of the mhtml data
> 
> ditto.

OK

>> Source/WebKit2/UIProcess/API/efl/ewk_view.h:859
>> + * @param o view object to get mhtml data
> 
> ditto.

OK

>> Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp:921
>> +static bool MHTMLDataObtained = false;
> 
> Generally, verb is placed first. For example, obtainedMHTMLData.

OK. I will use obtainedMHTMLData.
Comment 15 KwangYong Choi 2013-01-10 18:14:08 PST
Created attachment 182233 [details]
Patch
Comment 16 KwangYong Choi 2013-01-10 18:16:40 PST
Created attachment 182234 [details]
Patch
Comment 17 Gyuyoung Kim 2013-01-10 19:43:33 PST
Comment on attachment 182234 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:864
> +EAPI Eina_Bool ewk_view_mhtml_data_get(const Evas_Object *o, Ewk_View_MHTML_Data_Cb callback);

As you know, GTK port added *WebKitSaveMode* enum to support webpage saving functionality. I also think we need to support various data formats to save a webpage in future. I don't like to add new API to support new format. How about adding saving mode as GTK port ?
Comment 18 KwangYong Choi 2013-01-10 21:04:52 PST
Comment on attachment 182234 [details]
Patch

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

>> Source/WebKit2/UIProcess/API/efl/ewk_view.h:864
>> +EAPI Eina_Bool ewk_view_mhtml_data_get(const Evas_Object *o, Ewk_View_MHTML_Data_Cb callback);
> 
> As you know, GTK port added *WebKitSaveMode* enum to support webpage saving functionality. I also think we need to support various data formats to save a webpage in future. I don't like to add new API to support new format. How about adding saving mode as GTK port ?

OK. I will implement mode feature.
Comment 19 KwangYong Choi 2013-01-10 23:30:55 PST
Created attachment 182271 [details]
Patch

Renamed the API name as ewk_view_page_contents_get().

And it can set the contents type for the callback data. It supports only MHTML for now.
Comment 20 Gyuyoung Kim 2013-01-10 23:46:22 PST
Comment on attachment 182271 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:155
> +struct Ewk_Page_Contents_Context {

Please use _Ewk_Page_Contents_Context
Comment 21 KwangYong Choi 2013-01-10 23:53:25 PST
Created attachment 182274 [details]
Patch

struct Ewk_Page_Contents_Context -> struct _Ewk_Page_Contents_Context
Comment 22 Mikhail Pozdnyakov 2013-01-11 00:03:06 PST
(In reply to comment #20)
> (From update of attachment 182271 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=182271&action=review
> 
> > Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:155
> > +struct Ewk_Page_Contents_Context {
> 
> Please use _Ewk_Page_Contents_Context

I guess we do not use '_' prefixes in other places. Why is it needed? (Sorry if I missed something)
Comment 23 Mikhail Pozdnyakov 2013-01-11 00:05:11 PST
Comment on attachment 182274 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:950
> +    if (!context)

it's invoked internally, how 'context' can be NULL? ASSERTION or EINA check at least is needed.

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:968
> +    Ewk_Page_Contents_Context* context = static_cast<Ewk_Page_Contents_Context*>(calloc(1, sizeof(Ewk_Page_Contents_Context)));

why not 'new/delete' ?
Comment 24 Gyuyoung Kim 2013-01-11 00:07:28 PST
(In reply to comment #22)
> (In reply to comment #20)
> > (From update of attachment 182271 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=182271&action=review
> > 
> > > Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:155
> > > +struct Ewk_Page_Contents_Context {
> > 
> > Please use _Ewk_Page_Contents_Context
> 
> I guess we do not use '_' prefixes in other places. Why is it needed? (Sorry if I missed something)

That is my mistake. I saw old version which is used by my private debugging. Sorry for my noise.
Comment 25 KwangYong Choi 2013-01-11 00:19:31 PST
Created attachment 182277 [details]
Patch

Modified to use EINA_SAFETY_ON_NULL_RETURN(context);

Modified to use new/delete.
Comment 26 Mikhail Pozdnyakov 2013-01-11 00:24:28 PST
Comment on attachment 182277 [details]
Patch

looks OK
Comment 27 WebKit Review Bot 2013-01-11 02:33:06 PST
Comment on attachment 182277 [details]
Patch

Clearing flags on attachment: 182277

Committed r139422: <http://trac.webkit.org/changeset/139422>
Comment 28 WebKit Review Bot 2013-01-11 02:33:13 PST
All reviewed patches have been landed.  Closing bug.