⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 233782 in webkit


Ignore:
Timestamp:
Jul 12, 2018, 2:34:35 PM (8 years ago)
Author:
youenn@apple.com
Message:

Add a FrameLoaderClient willInjectUserScriptForFrame callback
​https://bugs.webkit.org/show_bug.cgi?id=187565

Reviewed by Alex Christensen.

Source/WebCore:

Test: http/tests/contentextensions/injected-script-callback.html.

  • loader/FrameLoaderClient.h:
  • page/Frame.cpp:

(WebCore::Frame::injectUserScriptImmediately):
Calling the new callback whenever being about to inject a new script.

Source/WebKit:

Introduce a new WKBundlePageLoaderClient callback that is called everytime a user script is injected.
Implement WebFrameLoaderClient::willInjectUserScript by calling this new callback.

  • WebProcess/InjectedBundle/API/APIInjectedBundlePageLoaderClient.h:

(API::InjectedBundle::PageLoaderClient::willInjectUserScriptForFrame):

  • WebProcess/InjectedBundle/API/c/WKBundlePageLoaderClient.h:
  • WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:

(setUpPageLoaderClient):

  • WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:

(WebKit::InjectedBundlePageLoaderClient::globalObjectIsAvailableForFrame):
(WebKit::InjectedBundlePageLoaderClient::willInjectUserScriptForFrame):

  • WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
  • WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:

(WebKit::WebFrameLoaderClient::willInjectUserScript):

  • WebProcess/WebCoreSupport/WebFrameLoaderClient.h:

Tools:

Added new test runner API to check for willInjectUserScriptForFrame callback.

  • WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
  • WebKitTestRunner/InjectedBundle/InjectedBundle.h:

(WTR::InjectedBundle::resetUserScriptInjectedCount):
(WTR::InjectedBundle::increaseUserScriptInjectedCount):
(WTR::InjectedBundle::userScriptInjectedCount const):

  • WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:

(WTR::InjectedBundlePage::InjectedBundlePage):
(WTR::InjectedBundlePage::resetAfterTest):
(WTR::InjectedBundlePage::willInjectUserScriptForFrame):

  • WebKitTestRunner/InjectedBundle/InjectedBundlePage.h:
  • WebKitTestRunner/InjectedBundle/TestRunner.cpp:

(WTR::TestRunner::userScriptInjectedCount const):
(WTR::TestRunner::injectUserScript):

  • WebKitTestRunner/InjectedBundle/TestRunner.h:
  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::injectUserScript):

  • WebKitTestRunner/TestController.h:
  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):

  • WebKitTestRunner/cocoa/TestControllerCocoa.mm:

(WTR::TestController::injectUserScript):

LayoutTests:

  • http/tests/contentextensions/injected-script-callback-expected.txt: Added.
  • http/tests/contentextensions/injected-script-callback.html: Added.
Location:
trunk
Files:
2 added
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r233776 r233782  
     12018-07-12  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a FrameLoaderClient willInjectUserScriptForFrame callback
     4        https://bugs.webkit.org/show_bug.cgi?id=187565
     5
     6        Reviewed by Alex Christensen.
     7
     8        * http/tests/contentextensions/injected-script-callback-expected.txt: Added.
     9        * http/tests/contentextensions/injected-script-callback.html: Added.
     10
    1112018-07-11  Ross Kirsling  <ross.kirsling@sony.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r233778 r233782  
     12018-07-12  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a FrameLoaderClient willInjectUserScriptForFrame callback
     4        https://bugs.webkit.org/show_bug.cgi?id=187565
     5
     6        Reviewed by Alex Christensen.
     7
     8        Test: http/tests/contentextensions/injected-script-callback.html.
     9
     10        * loader/FrameLoaderClient.h:
     11        * page/Frame.cpp:
     12        (WebCore::Frame::injectUserScriptImmediately):
     13        Calling the new callback whenever being about to inject a new script.
     14
    1152018-07-12  Megan Gardner  <megan_gardner@apple.com>
    216
  • trunk/Source/WebCore/loader/FrameLoaderClient.h

    r232814 r233782  
    333333    virtual void dispatchWillDestroyGlobalObjectForDOMWindowExtension(DOMWindowExtension*) { }
    334334
     335    virtual void willInjectUserScript(DOMWrapperWorld&) { }
     336
    335337#if ENABLE(WEB_RTC)
    336338    virtual void dispatchWillStartUsingPeerConnectionHandler(RTCPeerConnectionHandler*) { }
  • trunk/Source/WebCore/page/Frame.cpp

    r233752 r233782  
    752752    if (m_page)
    753753        m_page->setAsRunningUserScripts();
     754    loader().client().willInjectUserScript(world);
    754755    m_script->evaluateInWorld(ScriptSourceCode(script.source(), script.url()), world);
    755756}
  • trunk/Source/WebKit/ChangeLog

    r233781 r233782  
     12018-07-12  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a FrameLoaderClient willInjectUserScriptForFrame callback
     4        https://bugs.webkit.org/show_bug.cgi?id=187565
     5
     6        Reviewed by Alex Christensen.
     7
     8        Introduce a new WKBundlePageLoaderClient callback that is called everytime a user script is injected.
     9        Implement WebFrameLoaderClient::willInjectUserScript by calling this new callback.
     10
     11        * WebProcess/InjectedBundle/API/APIInjectedBundlePageLoaderClient.h:
     12        (API::InjectedBundle::PageLoaderClient::willInjectUserScriptForFrame):
     13        * WebProcess/InjectedBundle/API/c/WKBundlePageLoaderClient.h:
     14        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
     15        (setUpPageLoaderClient):
     16        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
     17        (WebKit::InjectedBundlePageLoaderClient::globalObjectIsAvailableForFrame):
     18        (WebKit::InjectedBundlePageLoaderClient::willInjectUserScriptForFrame):
     19        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
     20        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
     21        (WebKit::WebFrameLoaderClient::willInjectUserScript):
     22        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
     23
    1242018-07-12  Said Abou-Hallawa  <sabouhallawa@apple.com>
    225
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/APIInjectedBundlePageLoaderClient.h

    r228942 r233782  
    9090    virtual void willDestroyGlobalObjectForDOMWindowExtension(WebKit::WebPage&, WebCore::DOMWindowExtension*) { }
    9191
     92    virtual void willInjectUserScriptForFrame(WebKit::WebPage&, WebKit::WebFrame&, WebCore::DOMWrapperWorld&) { }
     93
    9294    virtual bool shouldForceUniversalAccessFromLocalURL(WebKit::WebPage&, const WTF::String&) { return false; }
    9395
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePageLoaderClient.h

    r205487 r233782  
    5454typedef bool (*WKBundlePageShouldGoToBackForwardListItemCallback)(WKBundlePageRef page, WKBundleBackForwardListItemRef item, WKTypeRef* userData, const void *clientInfo);
    5555typedef void (*WKBundlePageGlobalObjectIsAvailableForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef, WKBundleScriptWorldRef, const void* clientInfo);
     56typedef void (*WKBundlePageWillInjectUserScriptForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef, WKBundleScriptWorldRef, const void* clientInfo);
    5657typedef void (*WKBundlePageWillDisconnectDOMWindowExtensionFromGlobalObjectCallback)(WKBundlePageRef page, WKBundleDOMWindowExtensionRef, const void* clientInfo);
    5758typedef void (*WKBundlePageDidReconnectDOMWindowExtensionToGlobalObjectCallback)(WKBundlePageRef page, WKBundleDOMWindowExtensionRef, const void* clientInfo);
    … …  
    465466} WKBundlePageLoaderClientV8;
    466467
     468typedef struct WKBundlePageLoaderClientV9 {
     469    WKBundlePageLoaderClientBase                                            base;
     470
     471    // Version 0.
     472    WKBundlePageDidStartProvisionalLoadForFrameCallback                     didStartProvisionalLoadForFrame;
     473    WKBundlePageDidReceiveServerRedirectForProvisionalLoadForFrameCallback  didReceiveServerRedirectForProvisionalLoadForFrame;
     474    WKBundlePageDidFailProvisionalLoadWithErrorForFrameCallback             didFailProvisionalLoadWithErrorForFrame;
     475    WKBundlePageDidCommitLoadForFrameCallback                               didCommitLoadForFrame;
     476    WKBundlePageDidFinishDocumentLoadForFrameCallback                       didFinishDocumentLoadForFrame;
     477    WKBundlePageDidFinishLoadForFrameCallback                               didFinishLoadForFrame;
     478    WKBundlePageDidFailLoadWithErrorForFrameCallback                        didFailLoadWithErrorForFrame;
     479    WKBundlePageDidSameDocumentNavigationForFrameCallback                   didSameDocumentNavigationForFrame;
     480    WKBundlePageDidReceiveTitleForFrameCallback                             didReceiveTitleForFrame;
     481    WKBundlePageDidFirstLayoutForFrameCallback                              didFirstLayoutForFrame;
     482    WKBundlePageDidFirstVisuallyNonEmptyLayoutForFrameCallback              didFirstVisuallyNonEmptyLayoutForFrame;
     483    WKBundlePageDidRemoveFrameFromHierarchyCallback                         didRemoveFrameFromHierarchy;
     484    WKBundlePageDidDisplayInsecureContentForFrameCallback                   didDisplayInsecureContentForFrame;
     485    WKBundlePageDidRunInsecureContentForFrameCallback                       didRunInsecureContentForFrame;
     486    WKBundlePageDidClearWindowObjectForFrameCallback                        didClearWindowObjectForFrame;
     487    WKBundlePageDidCancelClientRedirectForFrameCallback                     didCancelClientRedirectForFrame;
     488    WKBundlePageWillPerformClientRedirectForFrameCallback                   willPerformClientRedirectForFrame;
     489    WKBundlePageDidHandleOnloadEventsForFrameCallback                       didHandleOnloadEventsForFrame;
     490
     491    // Version 1.
     492    WKBundlePageDidLayoutForFrameCallback                                   didLayoutForFrame;
     493    void *                                                                  didNewFirstVisuallyNonEmptyLayout_unavailable;
     494    WKBundlePageDidDetectXSSForFrameCallback                                didDetectXSSForFrame;
     495    WKBundlePageShouldGoToBackForwardListItemCallback                       shouldGoToBackForwardListItem;
     496    WKBundlePageGlobalObjectIsAvailableForFrameCallback                     globalObjectIsAvailableForFrame;
     497    WKBundlePageWillDisconnectDOMWindowExtensionFromGlobalObjectCallback    willDisconnectDOMWindowExtensionFromGlobalObject;
     498    WKBundlePageDidReconnectDOMWindowExtensionToGlobalObjectCallback        didReconnectDOMWindowExtensionToGlobalObject;
     499    WKBundlePageWillDestroyGlobalObjectForDOMWindowExtensionCallback        willDestroyGlobalObjectForDOMWindowExtension;
     500
     501    // Version 2
     502    WKBundlePageDidFinishProgressCallback                                   didFinishProgress;
     503    WKBundlePageShouldForceUniversalAccessFromLocalURLCallback              shouldForceUniversalAccessFromLocalURL;
     504
     505    // Version 3
     506    void *                                                                  didReceiveIntentForFrame_unavailable;
     507    void *                                                                  registerIntentServiceForFrame_unavailable;
     508
     509    // Version 4
     510    WKBundlePageDidLayoutCallback                                           didLayout;
     511
     512    // Version 5
     513    WKBundlePageFeaturesUsedInPageCallback                                  featuresUsedInPage;
     514
     515    // Version 6
     516    WKBundlePageWillLoadURLRequestCallback                                  willLoadURLRequest;
     517    WKBundlePageWillLoadDataRequestCallback                                 willLoadDataRequest;
     518
     519    // Version 7
     520    void *                                                                  willDestroyFrame_unavailable;
     521
     522    // Version 8
     523    WKBundlePageUserAgentForURLCallback                                     userAgentForURL;
     524
     525    // Version 9
     526    WKBundlePageWillInjectUserScriptForFrameCallback                        willInjectUserScriptForFrame;
     527} WKBundlePageLoaderClientV9;
     528
    467529#endif // WKBundlePageLoaderClient_h
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm

    r233713 r233782  
    233233static void setUpPageLoaderClient(WKWebProcessPlugInBrowserContextController *contextController, WebPage& page)
    234234{
    235     WKBundlePageLoaderClientV8 client;
     235    WKBundlePageLoaderClientV9 client;
    236236    memset(&client, 0, sizeof(client));
    237237
  • trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp

    r228942 r233782  
    304304    if (!m_client.globalObjectIsAvailableForFrame)
    305305        return;
    306    
     306
    307307    RefPtr<InjectedBundleScriptWorld> injectedWorld = InjectedBundleScriptWorld::getOrCreate(world);
    308308    m_client.globalObjectIsAvailableForFrame(toAPI(&page), toAPI(&frame), toAPI(injectedWorld.get()), m_client.base.clientInfo);
     309}
     310
     311void InjectedBundlePageLoaderClient::willInjectUserScriptForFrame(WebPage& page, WebFrame& frame, DOMWrapperWorld& world)
     312{
     313    if (!m_client.willInjectUserScriptForFrame)
     314        return;
     315
     316    RefPtr<InjectedBundleScriptWorld> injectedWorld = InjectedBundleScriptWorld::getOrCreate(world);
     317    m_client.willInjectUserScriptForFrame(toAPI(&page), toAPI(&frame), toAPI(injectedWorld.get()), m_client.base.clientInfo);
    309318}
    310319
  • trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h

    r228942 r233782  
    3838
    3939template<> struct ClientTraits<WKBundlePageLoaderClientBase> {
    40     typedef std::tuple<WKBundlePageLoaderClientV0, WKBundlePageLoaderClientV1, WKBundlePageLoaderClientV2, WKBundlePageLoaderClientV3, WKBundlePageLoaderClientV4, WKBundlePageLoaderClientV5, WKBundlePageLoaderClientV6, WKBundlePageLoaderClientV7, WKBundlePageLoaderClientV8> Versions;
     40    typedef std::tuple<WKBundlePageLoaderClientV0, WKBundlePageLoaderClientV1, WKBundlePageLoaderClientV2, WKBundlePageLoaderClientV3, WKBundlePageLoaderClientV4, WKBundlePageLoaderClientV5, WKBundlePageLoaderClientV6, WKBundlePageLoaderClientV7, WKBundlePageLoaderClientV8, WKBundlePageLoaderClientV9> Versions;
    4141};
    4242}
    … …  
    8282    void willDestroyGlobalObjectForDOMWindowExtension(WebPage&, WebCore::DOMWindowExtension*) override;
    8383
     84    void willInjectUserScriptForFrame(WebKit::WebPage&, WebKit::WebFrame&, WebCore::DOMWrapperWorld&) final;
     85
    8486    bool shouldForceUniversalAccessFromLocalURL(WebPage&, const WTF::String&) override;
    8587
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp

    r232814 r233782  
    16921692}
    16931693
    1694 
    16951694void WebFrameLoaderClient::dispatchGlobalObjectAvailable(DOMWrapperWorld& world)
    16961695{
    … …  
    17001699   
    17011700    webPage->injectedBundleLoaderClient().globalObjectIsAvailableForFrame(*webPage, *m_frame, world);
     1701}
     1702
     1703void WebFrameLoaderClient::willInjectUserScript(DOMWrapperWorld& world)
     1704{
     1705    WebPage* webPage = m_frame->page();
     1706    if (!webPage)
     1707        return;
     1708
     1709    webPage->injectedBundleLoaderClient().willInjectUserScriptForFrame(*webPage, *m_frame, world);
    17021710}
    17031711
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h

    r232814 r233782  
    233233    void dispatchDidReconnectDOMWindowExtensionToGlobalObject(WebCore::DOMWindowExtension*) final;
    234234    void dispatchWillDestroyGlobalObjectForDOMWindowExtension(WebCore::DOMWindowExtension*) final;
    235    
     235
     236    void willInjectUserScript(WebCore::DOMWrapperWorld&) final;
     237
    236238#if PLATFORM(COCOA)
    237239    RemoteAXObjectRef accessibilityRemoteObject() final;
  • trunk/Tools/ChangeLog

    r233777 r233782  
     12018-07-12  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a FrameLoaderClient willInjectUserScriptForFrame callback
     4        https://bugs.webkit.org/show_bug.cgi?id=187565
     5
     6        Reviewed by Alex Christensen.
     7
     8        Added new test runner API to check for willInjectUserScriptForFrame callback.
     9
     10        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
     11        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
     12        (WTR::InjectedBundle::resetUserScriptInjectedCount):
     13        (WTR::InjectedBundle::increaseUserScriptInjectedCount):
     14        (WTR::InjectedBundle::userScriptInjectedCount const):
     15        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
     16        (WTR::InjectedBundlePage::InjectedBundlePage):
     17        (WTR::InjectedBundlePage::resetAfterTest):
     18        (WTR::InjectedBundlePage::willInjectUserScriptForFrame):
     19        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.h:
     20        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     21        (WTR::TestRunner::userScriptInjectedCount const):
     22        (WTR::TestRunner::injectUserScript):
     23        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     24        * WebKitTestRunner/TestController.cpp:
     25        (WTR::TestController::injectUserScript):
     26        * WebKitTestRunner/TestController.h:
     27        * WebKitTestRunner/TestInvocation.cpp:
     28        (WTR::TestInvocation::didReceiveSynchronousMessageFromInjectedBundle):
     29        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
     30        (WTR::TestController::injectUserScript):
     31
    1322018-07-12  Sihui Liu  <sihui_liu@apple.com>
    233
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r233688 r233782  
    344344    void removeMockMediaDevice(DOMString persistentId);
    345345    void resetMockMediaDevices();
     346
     347    void injectUserScript(DOMString string);
     348    readonly attribute unsigned long userScriptInjectedCount;
    346349};
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h

    r231222 r233782  
    141141    void textFieldDidEndEditing();
    142142
     143    void resetUserScriptInjectedCount() { m_userScriptInjectedCount = 0; }
     144    void increaseUserScriptInjectedCount() { ++m_userScriptInjectedCount; }
     145    size_t userScriptInjectedCount() const { return m_userScriptInjectedCount; }
     146
    143147private:
    144148    InjectedBundle();
    … …  
    200204
    201205    Vector<String> m_allowedHosts;
     206
     207    size_t m_userScriptInjectedCount { 0 };
    202208};
    203209
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp

    r233239 r233782  
    275275    , m_world(AdoptWK, WKBundleScriptWorldCreateWorld())
    276276{
    277     WKBundlePageLoaderClientV8 loaderClient = {
    278         { 8, this },
     277    WKBundlePageLoaderClientV9 loaderClient = {
     278        { 9, this },
    279279        didStartProvisionalLoadForFrame,
    280280        didReceiveServerRedirectForProvisionalLoadForFrame,
    … …  
    313313        0, // willDestroyFrame_unavailable
    314314        0, // userAgentForURL
     315        willInjectUserScriptForFrame
    315316    };
    316317    WKBundlePageSetPageLoaderClient(m_page, &loaderClient.base);
    … …  
    444445
    445446    uninstallFakeHelvetica();
     447
     448    InjectedBundle::singleton().resetUserScriptInjectedCount();
    446449}
    447450
    … …  
    591594{
    592595    static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didFinishProgress();
     596}
     597
     598void InjectedBundlePage::willInjectUserScriptForFrame(WKBundlePageRef, WKBundleFrameRef, WKBundleScriptWorldRef, const void* clientInfo)
     599{
     600    static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->willInjectUserScriptForFrame();
    593601}
    594602
    … …  
    758766
    759767    injectedBundle.outputText("postProgressFinishedNotification\n");
     768}
     769
     770void InjectedBundlePage::willInjectUserScriptForFrame()
     771{
     772    InjectedBundle::singleton().increaseUserScriptInjectedCount();
    760773}
    761774
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.h

    r230224 r233782  
    7878    static void didFailLoadForResource(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, WKErrorRef, const void*);
    7979    static bool shouldCacheResponse(WKBundlePageRef, WKBundleFrameRef, uint64_t identifier, const void*);
     80    static void willInjectUserScriptForFrame(WKBundlePageRef, WKBundleFrameRef, WKBundleScriptWorldRef, const void*);
    8081
    8182    void didStartProvisionalLoadForFrame(WKBundleFrameRef);
    … …  
    9697    void didRunInsecureContentForFrame(WKBundleFrameRef);
    9798    void didDetectXSSForFrame(WKBundleFrameRef);
     99    void willInjectUserScriptForFrame();
    98100
    99101    // Resource Load Client
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r233688 r233782  
    22682268}
    22692269
     2270size_t TestRunner::userScriptInjectedCount() const
     2271{
     2272    return InjectedBundle::singleton().userScriptInjectedCount();
     2273}
     2274
     2275void TestRunner::injectUserScript(JSStringRef script)
     2276{
     2277    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("InjectUserScript"));
     2278    WKRetainPtr<WKStringRef> messageBody(AdoptWK, WKStringCreateWithJSString(script));
     2279    WKTypeRef returnData = 0;
     2280    WKBundlePagePostSynchronousMessageForTesting(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get(), &returnData);
     2281}
     2282
    22702283} // namespace WTR
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r233688 r233782  
    455455    void resetMockMediaDevices();
    456456
     457    size_t userScriptInjectedCount() const;
     458    void injectUserScript(JSStringRef);
     459
    457460private:
    458461    TestRunner();
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r233688 r233782  
    29132913{
    29142914}
     2915
     2916void TestController::injectUserScript(WKStringRef)
     2917{
     2918}
     2919
    29152920#endif
    29162921
  • trunk/Tools/WebKitTestRunner/TestController.h

    r233563 r233782  
    219219    void resetMockMediaDevices();
    220220
     221    void injectUserScript(WKStringRef);
     222
    221223private:
    222224    WKRetainPtr<WKPageConfigurationRef> generatePageConfiguration(WKContextConfigurationRef);
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r233688 r233782  
    14151415    }
    14161416
     1417    if (WKStringIsEqualToUTF8CString(messageName, "InjectUserScript")) {
     1418        ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID());
     1419        WKStringRef script = static_cast<WKStringRef>(messageBody);
     1420
     1421        TestController::singleton().injectUserScript(script);
     1422    }
     1423
    14171424    if (WKStringIsEqualToUTF8CString(messageName, "GetApplicationManifest")) {
    14181425#ifdef __BLOCKS__
  • trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm

    r233468 r233782  
    281281}
    282282
     283void TestController::injectUserScript(WKStringRef script)
     284{
     285#if WK_API_ENABLED
     286    auto userScript = adoptNS([[WKUserScript alloc] initWithSource: toWTFString(script) injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:NO]);
     287
     288    [[globalWebViewConfiguration userContentController] addUserScript: userScript.get()];
     289#endif
     290}
     291
    283292} // namespace WTR
Note: See TracChangeset for help on using the changeset viewer.