Changeset 186010 in webkit


Ignore:
Timestamp:
Jun 26, 2015 3:14:44 PM (9 years ago)
Author:
mark.lam@apple.com
Message:

ScriptMessageHandlerDelegate::didPostMessage() should reuse its JSContext instance.
https://bugs.webkit.org/show_bug.cgi?id=146358

Reviewed by Anders Carlsson.

Currently, ScriptMessageHandlerDelegate::didPostMessage() creates a new JSContext each
time it is called. This JSContext is used only once to deserialized a JSON object
and then destroyed. We will change ScriptMessageHandlerDelegate to cache the JSContext
and reuse it in all subsequent calls to didPostMessage().

Also added a @autoreleasepool scope in didPostMessage() so that transient ObjC objects
will be release sooner.

  • UIProcess/API/Cocoa/WKUserContentController.mm:
Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r186008 r186010  
     12015-06-26  Mark Lam  <mark.lam@apple.com>
     2
     3        ScriptMessageHandlerDelegate::didPostMessage() should reuse its JSContext instance.
     4        https://bugs.webkit.org/show_bug.cgi?id=146358
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Currently, ScriptMessageHandlerDelegate::didPostMessage() creates a new JSContext each
     9        time it is called.  This JSContext is used only once to deserialized a JSON object
     10        and then destroyed.  We will change ScriptMessageHandlerDelegate to cache the JSContext
     11        and reuse it in all subsequent calls to didPostMessage().
     12
     13        Also added a @autoreleasepool scope in didPostMessage() so that transient ObjC objects
     14        will be release sooner.
     15
     16        * UIProcess/API/Cocoa/WKUserContentController.mm:
     17
    1182015-06-26  Beth Dakin  <bdakin@apple.com>
    219
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm

    r185877 r186010  
    4141#import <JavaScriptCore/JSContext.h>
    4242#import <JavaScriptCore/JSValue.h>
     43#import <WTF/MainThread.h>
    4344#import <WebCore/SerializedScriptValue.h>
    4445
     
    8889    virtual void didPostMessage(WebKit::WebPageProxy& page, WebKit::WebFrameProxy& frame, const WebKit::SecurityOriginData& securityOriginData, WebCore::SerializedScriptValue& serializedScriptValue)
    8990    {
    90         RetainPtr<WKFrameInfo> frameInfo = wrapper(API::FrameInfo::create(frame, securityOriginData.securityOrigin()));
     91        @autoreleasepool {
     92            RetainPtr<WKFrameInfo> frameInfo = wrapper(API::FrameInfo::create(frame, securityOriginData.securityOrigin()));
    9193
    92         RetainPtr<JSContext> context = adoptNS([[JSContext alloc] init]);
    93         JSValueRef valueRef = serializedScriptValue.deserialize([context JSGlobalContextRef], 0);
    94         JSValue *value = [JSValue valueWithJSValueRef:valueRef inContext:context.get()];
    95         id body = [value toObject];
     94            ASSERT(isUIThread());
     95            static JSContext* context = [[JSContext alloc] init];
    9696
    97         RetainPtr<WKScriptMessage> message = adoptNS([[WKScriptMessage alloc] _initWithBody:body webView:fromWebPageProxy(page) frameInfo:frameInfo.get() name:m_name.get()]);
    98    
    99         [m_handler userContentController:m_controller.get() didReceiveScriptMessage:message.get()];
     97            JSValueRef valueRef = serializedScriptValue.deserialize([context JSGlobalContextRef], 0);
     98            JSValue *value = [JSValue valueWithJSValueRef:valueRef inContext:context];
     99            id body = value.toObject;
     100
     101            auto message = adoptNS([[WKScriptMessage alloc] _initWithBody:body webView:fromWebPageProxy(page) frameInfo:frameInfo.get() name:m_name.get()]);
     102       
     103            [m_handler userContentController:m_controller.get() didReceiveScriptMessage:message.get()];
     104        }
    100105    }
    101106
Note: See TracChangeset for help on using the changeset viewer.