| Differences between
and this patch
- a/Source/WebCore/ChangeLog +20 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2013-07-17  Tullio Lucena  <tullio.lucena@openbossa.org>
2
3
        [WK2] Proof of concept to inject custom JavaScript objects on WebWorker context.
4
        https://bugs.webkit.org/show_bug.cgi?id=117523
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Callbacks were added for initialize and terminate WebWorkers using WK2 API.
9
        These callbacks handle bindings between functions of JavaScript Workers and functions defined at a previously loaded bundle.
10
        An API test was added to check the these callbacks. It verifies the two types of workers, dedicated and shared.
11
12
        * bindings/js/WorkerScriptController.cpp:
13
        (WebCore::WorkerScriptController::~WorkerScriptController):
14
        (WebCore::WorkerScriptController::initScript):
15
        (WebCore::WorkerScriptController::setInitScriptCallback):
16
        (WebCore::WorkerScriptController::initScriptCallback):
17
        (WebCore::WorkerScriptController::setTerminateScriptCallback):
18
        (WebCore::WorkerScriptController::terminateScriptCallback):
19
        * bindings/js/WorkerScriptController.h:
20
1
2013-07-17  Commit Queue  <commit-queue@webkit.org>
21
2013-07-17  Commit Queue  <commit-queue@webkit.org>
2
22
3
        Unreviewed, rolling out r152701, r152703, r152739, r152754,
23
        Unreviewed, rolling out r152701, r152703, r152739, r152754,
- a/Source/WebKit2/ChangeLog +18 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2013-07-17  Tullio Lucena  <tullio.lucena@openbossa.org>
2
3
        [WK2] Proof of concept to inject custom JavaScript objects on WebWorker context.
4
        https://bugs.webkit.org/show_bug.cgi?id=117523
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Callbacks were added for initialize and terminate WebWorkers using WK2 API.
9
        These callbacks handle bindings between functions of JavaScript Workers and functions defined at a previously loaded bundle.
10
        An API test was added to check the these callbacks. It verifies the two types of workers, dedicated and shared.
11
12
        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
13
        (localWorkerScriptInitCallback):
14
        (WKBundleFrameSetWorkerInitializeCallback):
15
        (localWorkerScriptTerminateCallback):
16
        (WKBundleFrameSetWorkerTerminateCallback):
17
        * WebProcess/InjectedBundle/API/c/WKBundleFrame.h:
18
1
2013-07-17  Commit Queue  <commit-queue@webkit.org>
19
2013-07-17  Commit Queue  <commit-queue@webkit.org>
2
20
3
        Unreviewed, rolling out r152701, r152703, r152739, r152754,
21
        Unreviewed, rolling out r152701, r152703, r152739, r152754,
- a/Source/WebCore/bindings/js/WorkerScriptController.cpp +29 lines
Lines 66-71 WorkerScriptController::WorkerScriptController(WorkerGlobalScope* workerGlobalSc a/Source/WebCore/bindings/js/WorkerScriptController.cpp_sec1
66
66
67
WorkerScriptController::~WorkerScriptController()
67
WorkerScriptController::~WorkerScriptController()
68
{
68
{
69
    if (terminateScriptCallback())
70
        terminateScriptCallback()(m_workerGlobalScopeWrapper->globalExec(), m_workerGlobalScope->isDedicatedWorkerGlobalScope());
71
69
    JSLockHolder lock(vm());
72
    JSLockHolder lock(vm());
70
    m_workerGlobalScopeWrapper.clear();
73
    m_workerGlobalScopeWrapper.clear();
71
    m_vm.clear();
74
    m_vm.clear();
Lines 109-114 void WorkerScriptController::initScript() a/Source/WebCore/bindings/js/WorkerScriptController.cpp_sec2
109
    }
112
    }
110
    ASSERT(m_workerGlobalScopeWrapper->globalObject() == m_workerGlobalScopeWrapper);
113
    ASSERT(m_workerGlobalScopeWrapper->globalObject() == m_workerGlobalScopeWrapper);
111
    ASSERT(asObject(m_workerGlobalScopeWrapper->prototype())->globalObject() == m_workerGlobalScopeWrapper);
114
    ASSERT(asObject(m_workerGlobalScopeWrapper->prototype())->globalObject() == m_workerGlobalScopeWrapper);
115
116
    if (initScriptCallback())
117
        initScriptCallback()(m_workerGlobalScopeWrapper->globalExec(), m_workerGlobalScope->isDedicatedWorkerGlobalScope());
112
}
118
}
113
119
114
void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode)
120
void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode)
Lines 205-210 void WorkerScriptController::detachDebugger(JSC::Debugger* debugger) a/Source/WebCore/bindings/js/WorkerScriptController.cpp_sec3
205
    debugger->detach(m_workerGlobalScopeWrapper->globalObject());
211
    debugger->detach(m_workerGlobalScopeWrapper->globalObject());
206
}
212
}
207
213
214
WorkerScriptCallback WorkerScriptController::m_initScriptCallback = 0;
215
WorkerScriptCallback WorkerScriptController::m_terminateScriptCallback = 0;
216
217
void WorkerScriptController::setInitScriptCallback(WorkerScriptCallback callback)
218
{
219
    m_initScriptCallback = callback;
220
}
221
222
WorkerScriptCallback WorkerScriptController::initScriptCallback()
223
{
224
    return m_initScriptCallback;
225
}
226
227
void WorkerScriptController::setTerminateScriptCallback(WorkerScriptCallback callback)
228
{
229
    m_terminateScriptCallback = callback;
230
}
231
232
WorkerScriptCallback WorkerScriptController::terminateScriptCallback()
233
{
234
    return m_terminateScriptCallback;
235
}
236
208
} // namespace WebCore
237
} // namespace WebCore
209
238
210
#endif // ENABLE(WORKERS)
239
#endif // ENABLE(WORKERS)
- a/Source/WebCore/bindings/js/WorkerScriptController.h +9 lines
Lines 40-45 namespace JSC { a/Source/WebCore/bindings/js/WorkerScriptController.h_sec1
40
40
41
namespace WebCore {
41
namespace WebCore {
42
42
43
    typedef void (*WorkerScriptCallback)(JSC::ExecState*, bool);
44
43
    class JSWorkerGlobalScope;
45
    class JSWorkerGlobalScope;
44
    class ScriptSourceCode;
46
    class ScriptSourceCode;
45
    class ScriptValue;
47
    class ScriptValue;
Lines 82-87 namespace WebCore { a/Source/WebCore/bindings/js/WorkerScriptController.h_sec2
82
        void attachDebugger(JSC::Debugger*);
84
        void attachDebugger(JSC::Debugger*);
83
        void detachDebugger(JSC::Debugger*);
85
        void detachDebugger(JSC::Debugger*);
84
86
87
        static void setInitScriptCallback(WorkerScriptCallback);
88
        static WorkerScriptCallback initScriptCallback();
89
        static void setTerminateScriptCallback(WorkerScriptCallback);
90
        static WorkerScriptCallback terminateScriptCallback();
85
    private:
91
    private:
86
        void initScriptIfNeeded()
92
        void initScriptIfNeeded()
87
        {
93
        {
Lines 95-100 namespace WebCore { a/Source/WebCore/bindings/js/WorkerScriptController.h_sec3
95
        JSC::Strong<JSWorkerGlobalScope> m_workerGlobalScopeWrapper;
101
        JSC::Strong<JSWorkerGlobalScope> m_workerGlobalScopeWrapper;
96
        bool m_executionForbidden;
102
        bool m_executionForbidden;
97
        mutable Mutex m_scheduledTerminationMutex;
103
        mutable Mutex m_scheduledTerminationMutex;
104
105
        static WorkerScriptCallback m_initScriptCallback;
106
        static WorkerScriptCallback m_terminateScriptCallback;
98
    };
107
    };
99
108
100
} // namespace WebCore
109
} // namespace WebCore
- a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp +43 lines
Lines 28-33 a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp_sec1
28
#include "WKBundleFramePrivate.h"
28
#include "WKBundleFramePrivate.h"
29
29
30
#include "InjectedBundleHitTestResult.h"
30
#include "InjectedBundleHitTestResult.h"
31
#include "JavaScriptCore/APICast.h"
31
#include "WKAPICast.h"
32
#include "WKAPICast.h"
32
#include "WKBundleAPICast.h"
33
#include "WKBundleAPICast.h"
33
#include "WKData.h"
34
#include "WKData.h"
Lines 37-42 a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp_sec2
37
#include <WebCore/Frame.h>
38
#include <WebCore/Frame.h>
38
#include <WebCore/FrameLoader.h>
39
#include <WebCore/FrameLoader.h>
39
#include <WebCore/FrameView.h>
40
#include <WebCore/FrameView.h>
41
#include <WebCore/WorkerScriptController.h>
42
40
43
41
using namespace WebCore;
44
using namespace WebCore;
42
using namespace WebKit;
45
using namespace WebKit;
Lines 109-114 JSGlobalContextRef WKBundleFrameGetJavaScriptContextForWorld(WKBundleFrameRef fr a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp_sec3
109
    return toImpl(frameRef)->jsContextForWorld(toImpl(worldRef));
112
    return toImpl(frameRef)->jsContextForWorld(toImpl(worldRef));
110
}
113
}
111
114
115
static WKBundleFrameWorkerScriptCallback s_localWorkerScriptInitCallback;
116
117
static void localWorkerScriptInitCallback(JSC::ExecState* execState, bool isDedicated)
118
{
119
    s_localWorkerScriptInitCallback(toRef(execState), isDedicated);
120
}
121
122
void WKBundleFrameSetWorkerInitializeCallback(WKBundleFrameWorkerScriptCallback callback)
123
{
124
#if ENABLE(WORKERS)
125
    if (callback) {
126
        s_localWorkerScriptInitCallback = callback;
127
        WorkerScriptController::setInitScriptCallback(localWorkerScriptInitCallback);
128
    } else
129
        WorkerScriptController::setInitScriptCallback(0);
130
#else
131
    UNUSED_PARAM(callback);
132
#endif
133
}
134
135
static WKBundleFrameWorkerScriptCallback s_localWorkerScriptTerminateCallback;
136
137
static void localWorkerScriptTerminateCallback(JSC::ExecState* execState, bool isDedicated)
138
{
139
    s_localWorkerScriptTerminateCallback(toRef(execState), isDedicated);
140
}
141
142
void WKBundleFrameSetWorkerTerminateCallback(WKBundleFrameWorkerScriptCallback callback)
143
{
144
#if ENABLE(WORKERS)
145
    if (callback) {
146
        s_localWorkerScriptTerminateCallback = callback;
147
        WorkerScriptController::setTerminateScriptCallback(localWorkerScriptTerminateCallback);
148
    } else
149
        WorkerScriptController::setTerminateScriptCallback(0);
150
#else
151
    UNUSED_PARAM(callback);
152
#endif
153
}
154
112
JSValueRef WKBundleFrameGetJavaScriptWrapperForNodeForWorld(WKBundleFrameRef frameRef, WKBundleNodeHandleRef nodeHandleRef, WKBundleScriptWorldRef worldRef)
155
JSValueRef WKBundleFrameGetJavaScriptWrapperForNodeForWorld(WKBundleFrameRef frameRef, WKBundleNodeHandleRef nodeHandleRef, WKBundleScriptWorldRef worldRef)
113
{
156
{
114
    return toImpl(frameRef)->jsWrapperForWorld(toImpl(nodeHandleRef), toImpl(worldRef));
157
    return toImpl(frameRef)->jsWrapperForWorld(toImpl(nodeHandleRef), toImpl(worldRef));
- a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h +4 lines
Lines 51-56 WK_EXPORT WKFrameLoadState WKBundleFrameGetFrameLoadState(WKBundleFrameRef frame a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h_sec1
51
WK_EXPORT JSGlobalContextRef WKBundleFrameGetJavaScriptContext(WKBundleFrameRef frame);
51
WK_EXPORT JSGlobalContextRef WKBundleFrameGetJavaScriptContext(WKBundleFrameRef frame);
52
WK_EXPORT JSGlobalContextRef WKBundleFrameGetJavaScriptContextForWorld(WKBundleFrameRef frame, WKBundleScriptWorldRef world);
52
WK_EXPORT JSGlobalContextRef WKBundleFrameGetJavaScriptContextForWorld(WKBundleFrameRef frame, WKBundleScriptWorldRef world);
53
53
54
typedef void (*WKBundleFrameWorkerScriptCallback)(JSContextRef context, int isDedicated);
55
WK_EXPORT void WKBundleFrameSetWorkerInitializeCallback(WKBundleFrameWorkerScriptCallback callback);
56
WK_EXPORT void WKBundleFrameSetWorkerTerminateCallback(WKBundleFrameWorkerScriptCallback callback);
57
54
WK_EXPORT WKBundleFrameRef WKBundleFrameForJavaScriptContext(JSContextRef context);
58
WK_EXPORT WKBundleFrameRef WKBundleFrameForJavaScriptContext(JSContextRef context);
55
59
56
WK_EXPORT JSValueRef WKBundleFrameGetJavaScriptWrapperForNodeForWorld(WKBundleFrameRef frame, WKBundleNodeHandleRef nodeHandle, WKBundleScriptWorldRef world);
60
WK_EXPORT JSValueRef WKBundleFrameGetJavaScriptWrapperForNodeForWorld(WKBundleFrameRef frame, WKBundleNodeHandleRef nodeHandle, WKBundleScriptWorldRef world);
- a/Tools/ChangeLog +32 lines
Lines 1-3 a/Tools/ChangeLog_sec1
1
2013-07-17  Tullio Lucena  <tullio.lucena@openbossa.org>
2
3
        [WK2] Proof of concept to inject custom JavaScript objects on WebWorker context.
4
        https://bugs.webkit.org/show_bug.cgi?id=117523
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        Callbacks were added for initialize and terminate WebWorkers using WK2 API.
9
        These callbacks handle bindings between functions of JavaScript Workers and functions defined at a previously loaded bundle.
10
        An API test was added to check the these callbacks. It verifies the two types of workers, dedicated and shared.
11
12
        * TestWebKitAPI/GNUmakefile.am:
13
        * TestWebKitAPI/PlatformEfl.cmake:
14
        * TestWebKitAPI/Tests/WebKit2/WebWorker.cpp: Added.
15
        (TestWebKitAPI::didReceiveMessageFromInjectedBundle):
16
        (TestWebKitAPI::didReceiveTitleForFrame):
17
        (TestWebKitAPI::TEST):
18
        * TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.html: Added.
19
        * TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.js: Added.
20
        (onconnect):
21
        (listenForMessage):
22
        * TestWebKitAPI/Tests/WebKit2/WebWorkerTest.html: Added.
23
        * TestWebKitAPI/Tests/WebKit2/WebWorkerTest.js: Added.
24
        (self.onmessage):
25
        * TestWebKitAPI/Tests/WebKit2/WebWorker_Bundle.cpp: Added.
26
        (TestWebKitAPI::foo):
27
        (TestWebKitAPI::bar):
28
        (TestWebKitAPI::webWorkerInitialize):
29
        (TestWebKitAPI::webWorkerTerminate):
30
        (TestWebKitAPI::WebWorkerTest::WebWorkerTest):
31
        (TestWebKitAPI::WebWorkerTest::initialize):
32
1
2013-07-17  Commit Queue  <commit-queue@webkit.org>
33
2013-07-17  Commit Queue  <commit-queue@webkit.org>
2
34
3
        Unreviewed, rolling out r152701, r152703, r152739, r152754,
35
        Unreviewed, rolling out r152701, r152703, r152739, r152754,
- a/Tools/TestWebKitAPI/GNUmakefile.am +2 lines
Lines 282-287 Programs_TestWebKitAPI_TestWebKit2_SOURCES = \ a/Tools/TestWebKitAPI/GNUmakefile.am_sec1
282
	Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp \
282
	Tools/TestWebKitAPI/Tests/WebKit2/SpacebarScrolling.cpp \
283
	Tools/TestWebKitAPI/Tests/WebKit2/TerminateTwice.cpp \
283
	Tools/TestWebKitAPI/Tests/WebKit2/TerminateTwice.cpp \
284
	Tools/TestWebKitAPI/Tests/WebKit2/UserMessage.cpp \
284
	Tools/TestWebKitAPI/Tests/WebKit2/UserMessage.cpp \
285
	Tools/TestWebKitAPI/Tests/WebKit2/WebWorker.cpp \
285
	Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent.cpp \
286
	Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent.cpp \
286
	Tools/TestWebKitAPI/Tests/WebKit2/WKConnection.cpp \
287
	Tools/TestWebKitAPI/Tests/WebKit2/WKConnection.cpp \
287
	Tools/TestWebKitAPI/Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp \
288
	Tools/TestWebKitAPI/Tests/WebKit2/WKPageGetScaleFactorNotZero.cpp \
Lines 319-324 Libraries_libTestWebKitAPIInjectedBundle_la_SOURCES = \ a/Tools/TestWebKitAPI/GNUmakefile.am_sec2
319
	Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp \
320
	Tools/TestWebKitAPI/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp \
320
	Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp \
321
	Tools/TestWebKitAPI/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp \
321
	Tools/TestWebKitAPI/Tests/WebKit2/UserMessage_Bundle.cpp \
322
	Tools/TestWebKitAPI/Tests/WebKit2/UserMessage_Bundle.cpp \
323
	Tools/TestWebKitAPI/Tests/WebKit2/WebWorker_Bundle.cpp \
322
	Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp \
324
	Tools/TestWebKitAPI/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp \
323
	Tools/TestWebKitAPI/Tests/WebKit2/WKConnection_Bundle.cpp \
325
	Tools/TestWebKitAPI/Tests/WebKit2/WKConnection_Bundle.cpp \
324
	Tools/TestWebKitAPI/gtk/InjectedBundleControllerGtk.cpp \
326
	Tools/TestWebKitAPI/gtk/InjectedBundleControllerGtk.cpp \
- a/Tools/TestWebKitAPI/PlatformEfl.cmake +2 lines
Lines 54-59 set(test_webcore_BINARIES a/Tools/TestWebKitAPI/PlatformEfl.cmake_sec1
54
54
55
# In here we list the bundles that are used by our specific WK2 API Tests
55
# In here we list the bundles that are used by our specific WK2 API Tests
56
list(APPEND bundle_harness_SOURCES
56
list(APPEND bundle_harness_SOURCES
57
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/WebWorker_Bundle.cpp
57
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/efl/WKViewClientWebProcessCallbacks_Bundle.cpp
58
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/efl/WKViewClientWebProcessCallbacks_Bundle.cpp
58
)
59
)
59
60
Lines 93-98 set(test_webkit2_api_BINARIES a/Tools/TestWebKitAPI/PlatformEfl.cmake_sec2
93
    ResponsivenessTimerDoesntFireEarly
94
    ResponsivenessTimerDoesntFireEarly
94
    TerminateTwice
95
    TerminateTwice
95
    UserMessage
96
    UserMessage
97
    WebWorker
96
    WKConnection
98
    WKConnection
97
    WKPreferences
99
    WKPreferences
98
    WKString
100
    WKString
- a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorker.cpp +106 lines
Line 0 a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorker.cpp_sec1
1
/*
2
 * Copyright (C) 2013 INdT - Instituto Nokia de Tecnologia
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions are
6
 * met:
7
 *
8
 *     * Redistributions of source code must retain the above copyright
9
 * notice, this list of conditions and the following disclaimer.
10
 *     * Redistributions in binary form must reproduce the above
11
 * copyright notice, this list of conditions and the following disclaimer
12
 * in the documentation and/or other materials provided with the
13
 * distribution.
14
 *     * Neither the name of Google Inc. nor the names of its
15
 * contributors may be used to endorse or promote products derived from
16
 * this software without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
31
#include "config.h"
32
33
#include "PlatformUtilities.h"
34
#include "PlatformWebView.h"
35
#include <WebKit2/WKContext.h>
36
#include <WebKit2/WKPage.h>
37
#include <WebKit2/WKPreferencesPrivate.h>
38
39
namespace TestWebKitAPI {
40
41
static bool initialized = false;
42
static bool terminated = false;
43
static bool changedTitle = false;
44
static bool initializedShared = false;
45
static bool terminatedShared = false;
46
static bool changedTitleShared = false;
47
48
static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef, const void*)
49
{
50
    if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerInitMessage"))
51
        initialized = true;
52
    else if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerTerminateMessage"))
53
        terminated = true;
54
    else if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerSharedInitMessage"))
55
        initializedShared = true;
56
    else if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerSharedTerminateMessage"))
57
        terminatedShared = true;
58
}
59
60
static void didReceiveTitleForFrame(WKPageRef, WKStringRef title, WKFrameRef, WKTypeRef, const void *)
61
{
62
    if (WKStringIsEqualToUTF8CString(title, "WebWorkerTitle"))
63
        changedTitle = true;
64
    else if (WKStringIsEqualToUTF8CString(title, "WebWorkerSharedTitle"))
65
        changedTitleShared = true;
66
}
67
68
TEST(WebKit2, WebWorker)
69
{
70
    // This test cover the binding between functions of JavaScript Workers and
71
    // functions defined at a previously loaded bundle. It verifies the two
72
    // types of Workers, dedicated and shared.
73
    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("WebWorkerTest"));
74
75
    WKContextInjectedBundleClient injectedBundleClient;
76
    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
77
    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
78
    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient);
79
80
    PlatformWebView webView(context.get());
81
82
    WKPageLoaderClient pageLoaderClient;
83
    memset(&pageLoaderClient, 0, sizeof(WKPageLoaderClient));
84
    pageLoaderClient.version = kWKPageLoaderClientCurrentVersion;
85
    pageLoaderClient.didReceiveTitleForFrame = didReceiveTitleForFrame;
86
    WKPageSetPageLoaderClient(webView.page(), &pageLoaderClient);
87
88
    WKPageGroupRef pageGroup = WKPageGetPageGroup(webView.page());
89
    WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup);
90
    WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true);
91
92
    WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("WebWorkerTest", "html"));
93
    WKPageLoadURL(webView.page(), url.get());
94
    
95
    Util::run(&initialized);
96
    Util::run(&terminated);
97
    Util::run(&changedTitle);
98
99
    url = adoptWK(Util::createURLForResource("WebWorkerSharedTest", "html"));
100
    WKPageLoadURL(webView.page(), url.get());
101
    Util::run(&initializedShared);
102
    Util::run(&terminatedShared);
103
    Util::run(&changedTitleShared);
104
}
105
106
} // TestWebKitAPI
- a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.html +12 lines
Line 0 a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.html_sec1
1
<html>
2
    <body>
3
        <script>
4
            var worker = new SharedWorker("WebWorkerSharedTest.js");
5
            worker.port.addEventListener("message", function(event) {
6
                document.title = event.data;
7
            }, false);
8
            worker.port.start();
9
            worker.port.postMessage("WebWorkerSharedMessage");
10
        </script>
11
    </body>
12
</html>
- a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.js +13 lines
Line 0 a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.js_sec1
1
var ports = [];
2
3
onconnect = function(event) {
4
    var port = event.ports[0];
5
    ports.push(port);
6
    port.start();
7
    port.addEventListener("message", function(event) { listenForMessage(event, port); } );
8
}
9
10
listenForMessage = function (event, port) {
11
    port.postMessage(self.bar());
12
    self.close();
13
}
- a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorkerTest.html +11 lines
Line 0 a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorkerTest.html_sec1
1
<html>
2
    <body>
3
        <script>
4
            var worker = new Worker("WebWorkerTest.js");
5
            worker.postMessage("WebWorkerMessage");
6
            worker.onmessage = function(event) {
7
                document.title = event.data;
8
            };
9
        </script>
10
    </body>
11
</html>
- a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorkerTest.js +5 lines
Line 0 a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorkerTest.js_sec1
1
self.onmessage = function(event) {
2
    self.postMessage(self.foo());
3
    self.close();
4
    return;
5
};
- a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorker_Bundle.cpp +90 lines
Line 0 a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorker_Bundle.cpp_sec1
1
/*
2
 * Copyright (C) 2013 INdT - Instituto Nokia de Tecnologia
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions are
6
 * met:
7
 *
8
 *     * Redistributions of source code must retain the above copyright
9
 * notice, this list of conditions and the following disclaimer.
10
 *     * Redistributions in binary form must reproduce the above
11
 * copyright notice, this list of conditions and the following disclaimer
12
 * in the documentation and/or other materials provided with the
13
 * distribution.
14
 *     * Neither the name of Google Inc. nor the names of its
15
 * contributors may be used to endorse or promote products derived from
16
 * this software without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
31
#include "config.h"
32
#include "PlatformUtilities.h"
33
#include "InjectedBundleTest.h"
34
#include <WebKit2/WKBundleFrame.h>
35
#include <cstdio>
36
using namespace std;
37
namespace TestWebKitAPI {
38
39
JSValueRef foo(JSContextRef ctx, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef*)
40
{
41
    WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WebWorkerInitMessage").get(), 0);
42
    return JSValueMakeString(ctx, JSStringCreateWithUTF8CString("WebWorkerTitle"));
43
}
44
45
JSValueRef bar(JSContextRef ctx, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef*)
46
{
47
    WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WebWorkerSharedInitMessage").get(), 0);
48
    return JSValueMakeString(ctx, JSStringCreateWithUTF8CString("WebWorkerSharedTitle"));
49
}
50
51
void webWorkerInitialize(JSContextRef context, int isDedicated)
52
{
53
    if (isDedicated) {
54
        JSStringRef funcName = JSStringCreateWithUTF8CString("foo");
55
        JSObjectRef jsFunc = JSObjectMakeFunctionWithCallback(context, funcName, &foo);
56
        JSObjectSetProperty(context, JSContextGetGlobalObject(context), funcName, jsFunc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, 0);
57
        JSStringRelease(funcName);
58
    } else {
59
        JSStringRef funcName = JSStringCreateWithUTF8CString("bar");
60
        JSObjectRef jsFunc = JSObjectMakeFunctionWithCallback(context, funcName, &bar);
61
        JSObjectSetProperty(context, JSContextGetGlobalObject(context), funcName, jsFunc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, 0);
62
        JSStringRelease(funcName);
63
    }
64
}
65
66
void webWorkerTerminate(JSContextRef context, int isDedicated)
67
{
68
    if (isDedicated)
69
        WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WebWorkerTerminateMessage").get(), 0);
70
    else
71
        WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WebWorkerSharedTerminateMessage").get(), 0);
72
}
73
74
class WebWorkerTest : public InjectedBundleTest {
75
public:
76
    WebWorkerTest(const std::string& identifier)
77
        : InjectedBundleTest(identifier)
78
    {
79
    }
80
81
    virtual void initialize(WKBundleRef, WKTypeRef)
82
    {
83
        WKBundleFrameSetWorkerInitializeCallback(webWorkerInitialize);
84
        WKBundleFrameSetWorkerTerminateCallback(webWorkerTerminate);
85
    }
86
};
87
88
static InjectedBundleTest::Register<WebWorkerTest> registrar("WebWorkerTest");
89
90
} // namespace TestWebKitAPI

Return to Bug 117523