Bug 91345 - [EFL][WK2] Add download client for Ewk_Context
Summary: [EFL][WK2] Add download client for Ewk_Context
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on: 91401 91602 91639 92073 92077
Blocks: 61838
  Show dependency treegraph
 
Reported: 2012-07-15 07:31 PDT by Chris Dumez
Modified: 2012-07-27 10:25 PDT (History)
8 users (show)

See Also:


Attachments
Patch (55.13 KB, patch)
2012-07-24 03:13 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (63.66 KB, patch)
2012-07-24 03:16 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (63.68 KB, patch)
2012-07-25 14:10 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (63.92 KB, patch)
2012-07-25 22:13 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (63.97 KB, patch)
2012-07-26 22:51 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (65.42 KB, patch)
2012-07-27 06:41 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2012-07-15 07:31:31 PDT
We should define a download client and attach it to the Ewk_Context so that we can report information about downloads.

We should also add an API function to Ewk_Context so that the browser can trigger a download.
Comment 1 Chris Dumez 2012-07-24 03:13:31 PDT
Created attachment 154005 [details]
Patch
Comment 2 Chris Dumez 2012-07-24 03:16:39 PDT
Created attachment 154006 [details]
Patch

Regenerate patch with --binary for test PDF.
Comment 3 Raphael Kubo da Costa (:rakuco) 2012-07-25 13:44:56 PDT
Comment on attachment 154006 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_context.cpp:150
> +    if (!download)
> +        return;
> +    ewk_download_unref(download);

Nit: how about
  if (download)
      ewk_download_unref(download);

> Source/WebKit2/UIProcess/API/efl/ewk_context_download_client.cpp:62
> +    String destination = makeString("file://", String::fromUTF8(ewk_download_destination_get(download)));

IIRC, makeString() is normally frowned upon: <https://bugs.webkit.org/show_bug.cgi?id=62527#c15>. Is some other code responsible for checking if the destination is valid?

> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:72
> +        ASSERT(!__ref);

What if you build in Release mode? Is it OK for the de-ref not to happen?

> Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_download.cpp:45
> +static const char* serverSuggestedFilename = "webkit-downloaded-file";

Couldn't this be made as const as testFilePath?
Comment 4 Chris Dumez 2012-07-25 13:54:02 PDT
Comment on attachment 154006 [details]
Patch

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

>> Source/WebKit2/UIProcess/API/efl/ewk_context.cpp:150
>> +    ewk_download_unref(download);
> 
> Nit: how about
>   if (download)
>       ewk_download_unref(download);

Sure.

>> Source/WebKit2/UIProcess/API/efl/ewk_context_download_client.cpp:62
>> +    String destination = makeString("file://", String::fromUTF8(ewk_download_destination_get(download)));
> 
> IIRC, makeString() is normally frowned upon: <https://bugs.webkit.org/show_bug.cgi?id=62527#c15>. Is some other code responsible for checking if the destination is valid?

Good to know. Gyuyoung has been pushing me to use makeString() so I followed his advice. I'll fix it.

>> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:72
>> +        ASSERT(!__ref);
> 
> What if you build in Release mode? Is it OK for the de-ref not to happen?

I'm not sure what you mean. This assertion simply makes sure we are not calling delete on an object that's still referenced. This would indicate a programming error on our part so I think an assertion is correct here.

>> Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_download.cpp:45
>> +static const char* serverSuggestedFilename = "webkit-downloaded-file";
> 
> Couldn't this be made as const as testFilePath?

Could you clarify? if you mean that I should define it as an array instead of a pointer (similarly to testFilePath), then I agree and I'll fix this.
I don't really understand the "const" comment since it is already const.
Comment 5 Chris Dumez 2012-07-25 14:10:53 PDT
Created attachment 154440 [details]
Patch

Take rakuco's feedback into consideration.
Comment 6 Raphael Kubo da Costa (:rakuco) 2012-07-25 16:21:06 PDT
Comment on attachment 154440 [details]
Patch

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

A few style nits I noticed now. I see that the file names and the URIs are handled as UTF-8. Do you know how that plays out with languages such as Japanese or Korean (I know, if it's broken here it's broken in the rest of the API as well)?

> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:157
> +Eina_Bool ewk_download_destination_set(Ewk_Download *download, const char* destination)

Style nit: '*download' should be '* download'.

> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:162
> +    eina_stringshare_replace(&download->destination, destination);

I still wonder whether if some part of this code should check if the destination is a valid path or not.

> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:167
> +const char *ewk_download_suggested_filename_get(const Ewk_Download *download)

Ditto here.

> Source/WebKit2/UIProcess/API/efl/ewk_download.h:134
> +EAPI Eina_Bool ewk_download_destination_set(Ewk_Download *download, const char* destination);

s/* destination/*destination/.
Comment 7 Gyuyoung Kim 2012-07-25 19:04:20 PDT
Comment on attachment 154440 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:198
> +    return static_cast<double>(download->downloaded) / static_cast<double>(contentLength);

Is it enough to use static_cast for one operand ?

> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:203
> +    EINA_SAFETY_ON_NULL_RETURN_VAL(download, 0);

0 -> 0.0 ?

> Source/WebKit2/UIProcess/API/efl/ewk_download.h:25
> +

Missing file description.

> Source/WebKit2/UIProcess/API/efl/ewk_download.h:185
> + * @return seconds since the download was started or 0 in case of failure.

ditto.

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:30
> + * - "download,new", Ewk_Download*: reports that a new download has been requested. The client should set the

Wrong alphabetical order.
Comment 8 Chris Dumez 2012-07-25 22:11:41 PDT
Comment on attachment 154440 [details]
Patch

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

>> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:162
>> +    eina_stringshare_replace(&download->destination, destination);
> 
> I still wonder whether if some part of this code should check if the destination is a valid path or not.

I'm not sure what kind of check I can do here really. What will happen is that if the destination path is invalid, we won't be able to create the file later and the download will fail. Any kind of check I would do here would only be partial because you don't really know if it's valid until you try writing to the hard disk (e.g. in case of permission problem).

>> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:198
>> +    return static_cast<double>(download->downloaded) / static_cast<double>(contentLength);
> 
> Is it enough to use static_cast for one operand ?

True.

>> Source/WebKit2/UIProcess/API/efl/ewk_download.cpp:203
>> +    EINA_SAFETY_ON_NULL_RETURN_VAL(download, 0);
> 
> 0 -> 0.0 ?

This would be against WebKit coding style Gyuyoung :)
Comment 9 Chris Dumez 2012-07-25 22:13:02 PDT
Created attachment 154538 [details]
Patch

Take Rakuco and Gyuyoung's feedback into consideration.
Comment 10 Chris Dumez 2012-07-26 11:49:43 PDT
Kenneth, I know it's big but can you please find the courage to review this patch? :)
Comment 11 Gyuyoung Kim 2012-07-26 20:41:33 PDT
Comment on attachment 154538 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view_private.h:50
> +void ewk_view_download_new(Evas_Object* ewkView, Ewk_Download*);

Nit : Wrong alphabetical order.
Comment 12 Chris Dumez 2012-07-26 22:51:35 PDT
Created attachment 154846 [details]
Patch

Fix nit spotted by Gyuyoung and rebase on master.
Comment 13 Kenneth Rohde Christiansen 2012-07-27 05:13:51 PDT
Comment on attachment 154846 [details]
Patch

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

> Source/WebKit2/ChangeLog:17
> +        The client application needs to listen for
> +        "download,new" signal on the view and set
> +        the download path for the download in the
> +        callback in order to accept it. If the signal
> +        is ignored or if the download path is not set
> +        the download will fail.

That makes it more of a request then. "download,request" ?

> Source/WebKit2/UIProcess/API/efl/PageClientImpl.cpp:285
> +    Ewk_Download* ewkDownload = ewk_download_new(download, m_viewWidget);

ewk_download_request_new ? ewk_download_job_new

> Source/WebKit2/UIProcess/API/efl/ewk_context.cpp:68
> +    HashMap<uint64_t, Ewk_Download*> downloads;

downloadJobs?

> Source/WebKit2/UIProcess/API/efl/ewk_context.cpp:158
> +    if (download)
> +        ewk_download_unref(download);

why not make these methods accept null pointers?
Comment 14 Chris Dumez 2012-07-27 05:58:00 PDT
Comment on attachment 154846 [details]
Patch

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

>> Source/WebKit2/UIProcess/API/efl/PageClientImpl.cpp:285
>> +    Ewk_Download* ewkDownload = ewk_download_new(download, m_viewWidget);
> 
> ewk_download_request_new ? ewk_download_job_new

It is not really a request, except in it initial state, then it's an ongoing download.
If you prefer Download_Job instead of Download, I don't mind.

>> Source/WebKit2/UIProcess/API/efl/ewk_context.cpp:158
>> +        ewk_download_unref(download);
> 
> why not make these methods accept null pointers?

I think this is would be wrong API usage to call an unref method on NULL pointer. If I'm not mistaken, g_object_unref(NULL) will also cause warnings.

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:32
> + * - "download,new", Ewk_Download*: reports that a new download has been requested. The client should set the

"download,request" is a good idea, yes.
Comment 15 Chris Dumez 2012-07-27 06:41:58 PDT
Created attachment 154932 [details]
Patch

Take Kenneth's feedback into consideration:
- Rename Ewk_Download to Ewk_Download_Job (and all corresponding functions: ewk_download_job_*())
- Rename "download,new" signal to "download,request"
Comment 16 WebKit Review Bot 2012-07-27 10:25:06 PDT
Comment on attachment 154932 [details]
Patch

Clearing flags on attachment: 154932

Committed r123882: <http://trac.webkit.org/changeset/123882>
Comment 17 WebKit Review Bot 2012-07-27 10:25:14 PDT
All reviewed patches have been landed.  Closing bug.