Changeset 80188 in webkit


Ignore:
Timestamp:
Mar 2, 2011 5:17:45 PM (13 years ago)
Author:
timothy@apple.com
Message:

Make the runJavaScriptInMainFrame callback send a WKSerializedScriptValueRef.

Source/WebCore: Export SerializedScriptValue::create(JSC::ExecState* exec, JSC::JSValue value).

Reviewed by Darin Adler.

  • WebCore.exp.in: Added ZN7WebCore21SerializedScriptValue6createEPN3JSC9ExecStateENS1_7JSValueE.

Source/WebKit2: Make the runJavaScriptInMainFrame callback send a WKSerializedScriptValueRef.

https://webkit.org/b/55623

Reviewed by Darin Adler.

  • UIProcess/API/C/WKPage.cpp:

(WKPageRunJavaScriptInMainFrame): Use ScriptValueCallback.
(callRunJavaScriptBlockAndRelease): Use WKSerializedScriptValueRef.

  • UIProcess/API/C/WKPage.h: Use WKSerializedScriptValueRef.
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::close): Call invalidateCallbackMap for m_scriptValueCallbacks.
(WebKit::WebPageProxy::runJavaScriptInMainFrame): Take a ScriptValueCallback.
(WebKit::WebPageProxy::scriptValueCallback): Added. Create a WebSerializedScriptValue
from the DataReference before calling the callback.
(WebKit::WebPageProxy::processDidCrash): Call invalidateCallbackMap for m_scriptValueCallbacks.

  • UIProcess/WebPageProxy.h: Added ScriptValueCallback and m_scriptValueCallbacks.
  • UIProcess/WebPageProxy.messages.in: Added ScriptValueCallback.
  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::runJavaScriptInMainFrame): Create a DataReference from a WebCore::SerializedScriptValue.
And use ScriptValueCallback to send the message back.

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r80185 r80188  
     12011-03-02  Timothy Hatcher  <timothy@apple.com>
     2
     3        Export SerializedScriptValue::create(JSC::ExecState* exec, JSC::JSValue value).
     4
     5        Reviewed by Darin Adler.
     6
     7        * WebCore.exp.in: Added __ZN7WebCore21SerializedScriptValue6createEPN3JSC9ExecStateENS1_7JSValueE.
     8
    192011-03-02  Daniel Cheng  <dcheng@chromium.org>
    210
  • trunk/Source/WebCore/WebCore.exp.in

    r80180 r80188  
    529529__ZN7WebCore21SerializedScriptValue11deserializeEPK15OpaqueJSContextPPK13OpaqueJSValue
    530530__ZN7WebCore21SerializedScriptValue6createEPK15OpaqueJSContextPK13OpaqueJSValuePS6_
     531__ZN7WebCore21SerializedScriptValue6createEPN3JSC9ExecStateENS1_7JSValueE
    531532__ZN7WebCore21SerializedScriptValueC1ERN3WTF6VectorIhLm0EEE
    532533__ZN7WebCore21SerializedScriptValueD1Ev
  • trunk/Source/WebKit2/ChangeLog

    r80180 r80188  
     12011-03-02  Timothy Hatcher  <timothy@apple.com>
     2
     3        Make the runJavaScriptInMainFrame callback send a WKSerializedScriptValueRef.
     4
     5        https://webkit.org/b/55623
     6
     7        Reviewed by Darin Adler.
     8
     9        * UIProcess/API/C/WKPage.cpp:
     10        (WKPageRunJavaScriptInMainFrame): Use ScriptValueCallback.
     11        (callRunJavaScriptBlockAndRelease): Use WKSerializedScriptValueRef.
     12        * UIProcess/API/C/WKPage.h: Use WKSerializedScriptValueRef.
     13        * UIProcess/WebPageProxy.cpp:
     14        (WebKit::WebPageProxy::close): Call invalidateCallbackMap for m_scriptValueCallbacks.
     15        (WebKit::WebPageProxy::runJavaScriptInMainFrame): Take a ScriptValueCallback.
     16        (WebKit::WebPageProxy::scriptValueCallback): Added. Create a WebSerializedScriptValue
     17        from the DataReference before calling the callback.
     18        (WebKit::WebPageProxy::processDidCrash): Call invalidateCallbackMap for m_scriptValueCallbacks.
     19        * UIProcess/WebPageProxy.h: Added ScriptValueCallback and m_scriptValueCallbacks.
     20        * UIProcess/WebPageProxy.messages.in: Added ScriptValueCallback.
     21        * WebProcess/WebPage/WebPage.cpp:
     22        (WebKit::WebPage::runJavaScriptInMainFrame): Create a DataReference from a WebCore::SerializedScriptValue.
     23        And use ScriptValueCallback to send the message back.
     24
    1252011-03-02  Jessie Berlin  <jberlin@apple.com>
    226
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.cpp

    r80125 r80188  
    398398void WKPageRunJavaScriptInMainFrame(WKPageRef pageRef, WKStringRef scriptRef, void* context, WKPageRunJavaScriptFunction callback)
    399399{
    400     toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), StringCallback::create(context, callback));
     400    toImpl(pageRef)->runJavaScriptInMainFrame(toImpl(scriptRef)->string(), ScriptValueCallback::create(context, callback));
    401401}
    402402
    403403#ifdef __BLOCKS__
    404 static void callRunJavaScriptBlockAndRelease(WKStringRef resultValue, WKErrorRef error, void* context)
     404static void callRunJavaScriptBlockAndRelease(WKSerializedScriptValueRef resultValue, WKErrorRef error, void* context)
    405405{
    406406    WKPageRunJavaScriptBlock block = (WKPageRunJavaScriptBlock)context;
  • trunk/Source/WebKit2/UIProcess/API/C/WKPage.h

    r80125 r80188  
    340340WK_EXPORT void WKPageSetPageUIClient(WKPageRef page, const WKPageUIClient* client);
    341341
    342 typedef void (*WKPageRunJavaScriptFunction)(WKStringRef, WKErrorRef, void*);
     342typedef void (*WKPageRunJavaScriptFunction)(WKSerializedScriptValueRef, WKErrorRef, void*);
    343343WK_EXPORT void WKPageRunJavaScriptInMainFrame(WKPageRef page, WKStringRef script, void* context, WKPageRunJavaScriptFunction function);
    344344#ifdef __BLOCKS__
    345 typedef void (^WKPageRunJavaScriptBlock)(WKStringRef, WKErrorRef);
     345typedef void (^WKPageRunJavaScriptBlock)(WKSerializedScriptValueRef, WKErrorRef);
    346346WK_EXPORT void WKPageRunJavaScriptInMainFrame_b(WKPageRef page, WKStringRef script, WKPageRunJavaScriptBlock block);
    347347#endif
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r79886 r80188  
    312312    invalidateCallbackMap(m_dataCallbacks);
    313313    invalidateCallbackMap(m_stringCallbacks);
     314    invalidateCallbackMap(m_scriptValueCallbacks);
    314315    invalidateCallbackMap(m_computedPagesCallbacks);
    315316
     
    11131114    process()->send(Messages::WebPage::CountStringMatches(string, options, maxMatchCount), m_pageID);
    11141115}
    1115    
    1116 void WebPageProxy::runJavaScriptInMainFrame(const String& script, PassRefPtr<StringCallback> prpCallback)
    1117 {
    1118     RefPtr<StringCallback> callback = prpCallback;
     1116
     1117void WebPageProxy::runJavaScriptInMainFrame(const String& script, PassRefPtr<ScriptValueCallback> prpCallback)
     1118{
     1119    RefPtr<ScriptValueCallback> callback = prpCallback;
    11191120    uint64_t callbackID = callback->callbackID();
    1120     m_stringCallbacks.set(callbackID, callback.get());
     1121    m_scriptValueCallbacks.set(callbackID, callback.get());
    11211122    process()->send(Messages::WebPage::RunJavaScriptInMainFrame(script, callbackID), m_pageID);
    11221123}
     
    24432444}
    24442445
     2446void WebPageProxy::scriptValueCallback(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
     2447{
     2448    RefPtr<ScriptValueCallback> callback = m_scriptValueCallbacks.take(callbackID);
     2449    if (!callback) {
     2450        // FIXME: Log error or assert.
     2451        return;
     2452    }
     2453
     2454    Vector<uint8_t> data;
     2455    data.reserveInitialCapacity(dataReference.size());
     2456    data.append(dataReference.data(), dataReference.size());
     2457
     2458    callback->performCallbackWithReturnValue(WebSerializedScriptValue::adopt(data).get());
     2459}
     2460
    24452461void WebPageProxy::computedPagesCallback(const Vector<WebCore::IntRect>& pageRects, double totalScaleFactorForPrinting, uint64_t callbackID)
    24462462{
     
    25482564    invalidateCallbackMap(m_dataCallbacks);
    25492565    invalidateCallbackMap(m_stringCallbacks);
     2566    invalidateCallbackMap(m_scriptValueCallbacks);
    25502567    invalidateCallbackMap(m_computedPagesCallbacks);
    25512568
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r80125 r80188  
    114114
    115115typedef GenericCallback<WKStringRef, StringImpl*> StringCallback;
     116typedef GenericCallback<WKSerializedScriptValueRef, WebSerializedScriptValue*> ScriptValueCallback;
    116117
    117118class WebPageProxy : public APIObject, public WebPopupMenuProxy::Client {
     
    304305    void getSourceForFrame(WebFrameProxy*, PassRefPtr<StringCallback>);
    305306    void getWebArchiveOfFrame(WebFrameProxy*, PassRefPtr<DataCallback>);
    306     void runJavaScriptInMainFrame(const String&, PassRefPtr<StringCallback>);
     307    void runJavaScriptInMainFrame(const String&, PassRefPtr<ScriptValueCallback>);
    307308    void forceRepaint(PassRefPtr<VoidCallback>);
    308309
     
    575576    void dataCallback(const CoreIPC::DataReference&, uint64_t);
    576577    void stringCallback(const String&, uint64_t);
     578    void scriptValueCallback(const CoreIPC::DataReference&, uint64_t);
    577579    void computedPagesCallback(const Vector<WebCore::IntRect>&, double totalScaleFactorForPrinting, uint64_t);
    578580
     
    624626    HashMap<uint64_t, RefPtr<DataCallback> > m_dataCallbacks;
    625627    HashMap<uint64_t, RefPtr<StringCallback> > m_stringCallbacks;
     628    HashMap<uint64_t, RefPtr<ScriptValueCallback> > m_scriptValueCallbacks;
    626629    HashMap<uint64_t, RefPtr<ComputedPagesCallback> > m_computedPagesCallbacks;
    627630
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in

    r79886 r80188  
    120120    DataCallback(CoreIPC::DataReference resultData, uint64_t callbackID)
    121121    StringCallback(WTF::String resultString, uint64_t callbackID)
     122    ScriptValueCallback(CoreIPC::DataReference resultData, uint64_t callbackID)
    122123    ComputedPagesCallback(Vector<WebCore::IntRect> pageRects, double totalScaleFactorForPrinting, uint64_t callbackID)
    123124
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r79965 r80188  
    9292#include <WebCore/ReplaceSelectionCommand.h>
    9393#include <WebCore/ResourceRequest.h>
     94#include <WebCore/SerializedScriptValue.h>
    9495#include <WebCore/Settings.h>
    9596#include <WebCore/SharedBuffer.h>
     
    11951196    // disappear during script execution.
    11961197
     1198    CoreIPC::DataReference dataReference;
     1199
    11971200    JSLock lock(SilenceAssertionsOnly);
    1198     JSValue resultValue = m_mainFrame->coreFrame()->script()->executeScript(script, true).jsValue();
    1199     String resultString;
    1200     if (resultValue)
    1201         resultString = ustringToString(resultValue.toString(m_mainFrame->coreFrame()->script()->globalObject(mainThreadNormalWorld())->globalExec()));
    1202 
    1203     send(Messages::WebPageProxy::StringCallback(resultString, callbackID));
     1201    if (JSValue resultValue = m_mainFrame->coreFrame()->script()->executeScript(script, true).jsValue()) {
     1202        if (RefPtr<SerializedScriptValue> serializedResultValue = SerializedScriptValue::create(m_mainFrame->coreFrame()->script()->globalObject(mainThreadNormalWorld())->globalExec(), resultValue))
     1203           dataReference = CoreIPC::DataReference(serializedResultValue->data().data(), serializedResultValue->data().size());
     1204    }
     1205
     1206    send(Messages::WebPageProxy::ScriptValueCallback(dataReference, callbackID));
    12041207}
    12051208
Note: See TracChangeset for help on using the changeset viewer.