Bug 101904 - [EFL][WK2] Add API to execute js script
Summary: [EFL][WK2] Add API to execute js script
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit EFL (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other Linux
: P2 Normal
Assignee: Ryuan Choi
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-11 23:30 PST by Jongseok Yang
Modified: 2014-01-08 17:03 PST (History)
9 users (show)

See Also:


Attachments
Patch (9.86 KB, patch)
2012-11-11 23:32 PST, Jongseok Yang
no flags Details | Formatted Diff | Diff
Patch (9.77 KB, patch)
2012-11-12 01:40 PST, Jongseok Yang
no flags Details | Formatted Diff | Diff
Patch (10.81 KB, patch)
2014-01-05 19:59 PST, Ryuan Choi
no flags Details | Formatted Diff | Diff
improve testcase (11.24 KB, patch)
2014-01-07 18:26 PST, Ryuan Choi
no flags Details | Formatted Diff | Diff
Patch (11.14 KB, patch)
2014-01-08 16:46 PST, Ryuan 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 Jongseok Yang 2012-11-11 23:30:45 PST
Add the API to execute the specific javascript
Comment 1 Jongseok Yang 2012-11-11 23:32:48 PST
Created attachment 173571 [details]
Patch
Comment 2 Jongseok Yang 2012-11-12 01:40:36 PST
Created attachment 173587 [details]
Patch
Comment 3 Gyuyoung Kim 2012-12-13 22:10:45 PST
Comment on attachment 173587 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:926
> +struct _Ewk_View_Script_Execute_Callback_Context {

I think ewk_view_private.h or EwkViewImpl.h is more better place for this struct.

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:939
> +    if (!ewkView || error)

What is error role here ? It looks QT and GTK ports don't take care of error.

Beside don't you need to delete callbackContext here ?

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:943
> +    JSGlobalContextRef jsGlobalContext = impl->ewkContext()->jsGlobalContext();

Don't you need to free jsGlobalContext using JSGlobalContextRelease() after finishing to use it ?

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:945
> +    if (!callbackContext->scriptExecuteCallback)

I think this line should be placed before above two lines.

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:975
> +

Unneeded line.
Comment 4 Chris Dumez 2012-12-13 23:13:11 PST
Comment on attachment 173587 [details]
Patch

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

>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:926
>> +struct _Ewk_View_Script_Execute_Callback_Context {
> 
> I think ewk_view_private.h or EwkViewImpl.h is more better place for this struct.

Why? if this struct is used only in ewk_view.cpp, then I think this is the right place for it. However, we don't use _ prefix for such structures anymore.

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:936
> +    Ewk_View_Script_Execute_Callback_Context* callbackContext = static_cast<Ewk_View_Script_Execute_Callback_Context*>(context);

It is a good idea to use OwnPtr here and adopt to avoid having to call delete manually.

>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:943
>> +    JSGlobalContextRef jsGlobalContext = impl->ewkContext()->jsGlobalContext();
> 
> Don't you need to free jsGlobalContext using JSGlobalContextRelease() after finishing to use it ?

Looks like the global context object is owned by Ewk_Context so I don't think we should free it here.

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:950
> +        JSRetainPtr<JSStringRef> jsStringValue(JSValueToStringCopy(jsGlobalContext, value, 0));

Looks like you may be leaking here. Don't you need to adopt the value returned by JSValueToStringCopy() ?

> Source/WebKit2/UIProcess/API/efl/ewk_view.h:822
> + * The result value for the executeion can be got from the asynchronous callback.

"execution"
"got" -> "retrieved"
Comment 5 Gyuyoung Kim 2012-12-13 23:56:53 PST
Comment on attachment 173587 [details]
Patch

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

>>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:926
>>> +struct _Ewk_View_Script_Execute_Callback_Context {
>> 
>> I think ewk_view_private.h or EwkViewImpl.h is more better place for this struct.
> 
> Why? if this struct is used only in ewk_view.cpp, then I think this is the right place for it. However, we don't use _ prefix for such structures anymore.

If so, what do you think ewk_view_private.h role ? Do you think it isn't for internal data type or struct ?

>>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:943
>>> +    JSGlobalContextRef jsGlobalContext = impl->ewkContext()->jsGlobalContext();
>> 
>> Don't you need to free jsGlobalContext using JSGlobalContextRelease() after finishing to use it ?
> 
> Looks like the global context object is owned by Ewk_Context so I don't think we should free it here.

Ok
Comment 6 Chris Dumez 2012-12-14 00:34:45 PST
Comment on attachment 173587 [details]
Patch

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

>>>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:926
>>>> +struct _Ewk_View_Script_Execute_Callback_Context {
>>> 
>>> I think ewk_view_private.h or EwkViewImpl.h is more better place for this struct.
>> 
>> Why? if this struct is used only in ewk_view.cpp, then I think this is the right place for it. However, we don't use _ prefix for such structures anymore.
> 
> If so, what do you think ewk_view_private.h role ? Do you think it isn't for internal data type or struct ?

ewk_view_private.h should be used for structures / macros that need to be shared between several files.
In this case, Ewk_View_Script_Execute_Callback_Context is only used internally by ewk_view.cpp. There is no point in sharing it with other implementation files since none of them will use it. It would only make compile time longer.
Comment 7 Mikhail Pozdnyakov 2012-12-14 01:54:44 PST
Comment on attachment 173587 [details]
Patch

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

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:931
> +typedef struct _Ewk_View_Script_Execute_Callback_Context Ewk_View_Script_Execute_Callback_Context;

could be just 'struct EwkViewScriptExecuteCallbackContext'

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:935
> +    EINA_SAFETY_ON_NULL_RETURN(context);

maybe assert is better since 'runJavaScriptCallback' is always invoked internally? How context can be '0'?

>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:936
>> +    Ewk_View_Script_Execute_Callback_Context* callbackContext = static_cast<Ewk_View_Script_Execute_Callback_Context*>(context);
> 
> It is a good idea to use OwnPtr here and adopt to avoid having to call delete manually.

indeed.

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:961
> +Eina_Bool ewk_view_script_execute(Evas_Object* ewkView, const char* script, Ewk_View_Script_Execute_Cb callback, void* userData)

isn't it worth mentioning where the script will be executed?  like "runJavaScriptInMainFrame"

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:967
> +    context->scriptExecuteCallback = callback;

maybe this could be done inside structure constructor?
Comment 8 Gyuyoung Kim 2012-12-14 01:59:01 PST
Comment on attachment 173587 [details]
Patch

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

>>>>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:926
>>>>> +struct _Ewk_View_Script_Execute_Callback_Context {
>>>> 
>>>> I think ewk_view_private.h or EwkViewImpl.h is more better place for this struct.
>>> 
>>> Why? if this struct is used only in ewk_view.cpp, then I think this is the right place for it. However, we don't use _ prefix for such structures anymore.
>> 
>> If so, what do you think ewk_view_private.h role ? Do you think it isn't for internal data type or struct ?
> 
> ewk_view_private.h should be used for structures / macros that need to be shared between several files.
> In this case, Ewk_View_Script_Execute_Callback_Context is only used internally by ewk_view.cpp. There is no point in sharing it with other implementation files since none of them will use it. It would only make compile time longer.

I agree. Thanks.

>>>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:943
>>>> +    JSGlobalContextRef jsGlobalContext = impl->ewkContext()->jsGlobalContext();
>>> 
>>> Don't you need to free jsGlobalContext using JSGlobalContextRelease() after finishing to use it ?
>> 
>> Looks like the global context object is owned by Ewk_Context so I don't think we should free it here.
> 
> Ok

BTW, could you explain why jsGlobalContext should be maintained by ewkContext ? Because, it seems jsGlobalContext() is just used by this callback now.
If there is no reason, is below code enough ?

JSGlobalContextRef jsGlobalContext = JSGlobalContextCreate(0);
...
...
JSGlobalContextRelease(jsGlobalContext);
Comment 9 Gyuyoung Kim 2013-04-08 19:09:51 PDT
Comment on attachment 173587 [details]
Patch

Cleared review? from attachment 173587 [details] so that this bug does not appear in http://webkit.org/pending-review. If you would like this patch reviewed, please attach it to a new bug or this bug again.
Comment 10 Ryuan Choi 2014-01-05 19:59:02 PST
Created attachment 220411 [details]
Patch
Comment 11 Ryuan Choi 2014-01-05 20:05:36 PST
(In reply to comment #10)
> Created an attachment (id=220411) [details]
> Patch

I tried to follow almost comments except below comment.

(In reply to comment #7)
> > Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:961
> > +Eina_Bool ewk_view_script_execute(Evas_Object* ewkView, const char* script, Ewk_View_Script_Execute_Cb callback, void* userData)
> 
> isn't it worth mentioning where the script will be executed?  like "runJavaScriptInMainFrame"

I think that we can assume MainFrame from the *ewk_view* becaus ewk_view implicitly represents Page or MainFrame.

And we don't have plan to support this API for each frame.
Comment 12 Ryuan Choi 2014-01-07 18:26:43 PST
Created attachment 220578 [details]
improve testcase
Comment 13 Gyuyoung Kim 2014-01-08 15:56:05 PST
Comment on attachment 220578 [details]
improve testcase

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

> Source/WebKit2/UIProcess/API/efl/ewk_context.cpp:76
> +    , m_jsGlobalContext(0)

Please use *nullptr* instead of 0. As you know, we are talking about using *nullptr* instead of 0 or NULL in webkit-dev.

> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:648
> +    if (error)

Isn't it better to add a log here ?
Comment 14 Ryuan Choi 2014-01-08 16:46:38 PST
Created attachment 220675 [details]
Patch
Comment 15 Ryuan Choi 2014-01-08 16:47:27 PST
Comment on attachment 220578 [details]
improve testcase

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

>> Source/WebKit2/UIProcess/API/efl/ewk_context.cpp:76
>> +    , m_jsGlobalContext(0)
> 
> Please use *nullptr* instead of 0. As you know, we are talking about using *nullptr* instead of 0 or NULL in webkit-dev.

Done

>> Source/WebKit2/UIProcess/API/efl/ewk_view.cpp:648
>> +    if (error)
> 
> Isn't it better to add a log here ?

I realized that this callback does not need error.
I removed.
Comment 16 Ryuan Choi 2014-01-08 17:03:12 PST
Comment on attachment 220675 [details]
Patch

Clearing flags on attachment: 220675

Committed r161527: <http://trac.webkit.org/changeset/161527>
Comment 17 Ryuan Choi 2014-01-08 17:03:21 PST
All reviewed patches have been landed.  Closing bug.