[webkit-help] How to call JavaScript function from WebKit

achellies achellies at 163.com
Mon Jun 20 06:36:20 PDT 2011


you can call as the following:
bool returnFlag = false;
WebCore::Frame* pMainFrame = GetFrame();//Note 10/19/10 - abaldeva - We need to investigate if we should get the focus Or MainFrame here.
if(pMainFrame)
{
WebCore::ScriptController* pProxy = pMainFrame->script();
if(pProxy)
{
const WebCore::String sFileName;
const int             baseLine = 1;
const WebCore::String sScriptSource(pScriptSource, length);


KJS::JSValue* pValue = pProxy->evaluate(sFileName, baseLine, sScriptSource);


if(pValue)
{
if(pReturnValue)
                {
                    // we need the exec only because JSArray::get requires the exec state. This could potentially be removed.
                    ExecState* exec = pProxy->windowShell()->window()->globalExec();
                    TranslateJavaScriptValue(pValue, pReturnValue, exec);
                }


                // 7/27/10 CSidhall So this is a small API change, we now return true if a non zero pValue was found versus previously where 
                // we only returned true if  pValue was non zero and a pReturnValue was set by the user.  This was suggested by Chin Yee Cheng.
                // So any return with a non NULL pValue is a success.  (It is unclear if there could be some special
                // exceptions to this in case of with "Break" or "Continue" internal JS completion codes but we consider those as fails for now).
                
                returnFlag = true;  
            }
            else
            {
                // No valid return so leave the returnValue to undefined
            }
            // 5/12/10 CSidhall - Changed this to just flag the update instead of doing a full layout update as EvaluateJavascript might be called x times in a same frame. 
       // We could consider only updating the layout in case only of a pValue return
            WebCore::FrameView* const pMainFrameView  = GetFrameView();
       if(pMainFrameView)
       pMainFrameView->setNeedsLayout();
        }
}

At 2011-06-20,"Vicky Tux" <ssseintr2 at gmail.com> wrote:
Hi,

anyone help me, how to call JavaScript function from webkit and give the example code..


Thanks & Regards,
Vicky.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-help/attachments/20110620/bc8dad23/attachment.html>


More information about the webkit-help mailing list