| Differences between
and this patch
- a/Source/WebCore/ChangeLog +16 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2013-06-11  Tullio Lucena  <tullio.lucena@openbossa.org>
2
3
        [WK2][EFL] 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
        * bindings/js/WorkerScriptController.cpp:
9
        (WebCore::WorkerScriptController::~WorkerScriptController):
10
        (WebCore::WorkerScriptController::initScript):
11
        (WebCore::WorkerScriptController::setInitScriptCallback):
12
        (WebCore::WorkerScriptController::initScriptCallback):
13
        (WebCore::WorkerScriptController::setTerminateScriptCallback):
14
        (WebCore::WorkerScriptController::terminateScriptCallback):
15
        * bindings/js/WorkerScriptController.h:
16
1
2013-06-11  Eric Carlson  <eric.carlson@apple.com>
17
2013-06-11  Eric Carlson  <eric.carlson@apple.com>
2
18
3
        [Mac] Update text track menu
19
        [Mac] Update text track menu
- a/Source/WebKit2/ChangeLog +14 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2013-06-11  Tullio Lucena  <tullio.lucena@openbossa.org>
2
3
        [WK2][EFL] 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
        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
9
        (localWorkerScriptInitCallback):
10
        (WKBundleFrameSetWorkerInitializeCallback):
11
        (localWorkerScriptTerminateCallback):
12
        (WKBundleFrameSetWorkerTerminateCallback):
13
        * WebProcess/InjectedBundle/API/c/WKBundleFrame.h:
14
1
2013-06-06  Timothy Hatcher  <timothy@apple.com>
15
2013-06-06  Timothy Hatcher  <timothy@apple.com>
2
16
3
        Update the framework bundle identifier for the Web Inspector.
17
        Update the framework bundle identifier for the Web Inspector.
- a/Source/WebCore/bindings/js/WorkerScriptController.cpp +29 lines
Lines 66-71 WorkerScriptController::WorkerScriptController(WorkerContext* workerContext) a/Source/WebCore/bindings/js/WorkerScriptController.cpp_sec1
66
66
67
WorkerScriptController::~WorkerScriptController()
67
WorkerScriptController::~WorkerScriptController()
68
{
68
{
69
    if (terminateScriptCallback())
70
        terminateScriptCallback()(m_workerContextWrapper->globalExec(), m_workerContext->isDedicatedWorkerContext());
71
69
    JSLockHolder lock(vm());
72
    JSLockHolder lock(vm());
70
    m_workerContextWrapper.clear();
73
    m_workerContextWrapper.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_workerContextWrapper->globalObject() == m_workerContextWrapper);
113
    ASSERT(m_workerContextWrapper->globalObject() == m_workerContextWrapper);
111
    ASSERT(asObject(m_workerContextWrapper->prototype())->globalObject() == m_workerContextWrapper);
114
    ASSERT(asObject(m_workerContextWrapper->prototype())->globalObject() == m_workerContextWrapper);
115
116
    if (initScriptCallback())
117
        initScriptCallback()(m_workerContextWrapper->globalExec(), m_workerContext->isDedicatedWorkerContext());
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_workerContextWrapper->globalObject());
211
    debugger->detach(m_workerContextWrapper->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 JSWorkerContext;
45
    class JSWorkerContext;
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<JSWorkerContext> m_workerContextWrapper;
101
        JSC::Strong<JSWorkerContext> m_workerContextWrapper;
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 +38 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>
40
42
41
using namespace WebCore;
43
using namespace WebCore;
42
using namespace WebKit;
44
using namespace WebKit;
Lines 114-119 JSValueRef WKBundleFrameGetJavaScriptWrapperForNodeForWorld(WKBundleFrameRef fra a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp_sec3
114
    return toImpl(frameRef)->jsWrapperForWorld(toImpl(nodeHandleRef), toImpl(worldRef));
116
    return toImpl(frameRef)->jsWrapperForWorld(toImpl(nodeHandleRef), toImpl(worldRef));
115
}
117
}
116
118
119
static WKBundleFrameWorkerScriptCallback s_localWorkerScriptInitCallback;
120
121
static void localWorkerScriptInitCallback(JSC::ExecState* execState, bool isDedicated)
122
{
123
    s_localWorkerScriptInitCallback(toRef(execState), isDedicated);
124
}
125
126
void WKBundleFrameSetWorkerInitializeCallback(WKBundleFrameWorkerScriptCallback callback)
127
{
128
#if ENABLE(WORKERS)
129
    if (callback) {
130
        s_localWorkerScriptInitCallback = callback;
131
        WorkerScriptController::setInitScriptCallback(localWorkerScriptInitCallback);
132
    } else
133
        WorkerScriptController::setInitScriptCallback(0);
134
#endif
135
}
136
137
static WKBundleFrameWorkerScriptCallback s_localWorkerScriptTerminateCallback;
138
139
static void localWorkerScriptTerminateCallback(JSC::ExecState* execState, bool isDedicated)
140
{
141
    s_localWorkerScriptTerminateCallback(toRef(execState), isDedicated);
142
}
143
144
void WKBundleFrameSetWorkerTerminateCallback(WKBundleFrameWorkerScriptCallback callback)
145
{
146
#if ENABLE(WORKERS)
147
    if (callback) {
148
        s_localWorkerScriptTerminateCallback = callback;
149
        WorkerScriptController::setTerminateScriptCallback(localWorkerScriptTerminateCallback);
150
    } else
151
        WorkerScriptController::setTerminateScriptCallback(0);
152
#endif
153
}
154
117
JSValueRef WKBundleFrameGetJavaScriptWrapperForRangeForWorld(WKBundleFrameRef frameRef, WKBundleRangeHandleRef rangeHandleRef, WKBundleScriptWorldRef worldRef)
155
JSValueRef WKBundleFrameGetJavaScriptWrapperForRangeForWorld(WKBundleFrameRef frameRef, WKBundleRangeHandleRef rangeHandleRef, WKBundleScriptWorldRef worldRef)
118
{
156
{
119
    return toImpl(frameRef)->jsWrapperForWorld(toImpl(rangeHandleRef), toImpl(worldRef));
157
    return toImpl(frameRef)->jsWrapperForWorld(toImpl(rangeHandleRef), 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 +27 lines
Lines 1-3 a/Tools/ChangeLog_sec1
1
2013-06-11  Tullio Lucena  <tullio.lucena@openbossa.org>
2
3
        [WK2][EFL] 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
        * TestWebKitAPI/PlatformEfl.cmake:
9
        * TestWebKitAPI/Tests/WebKit2/WebWorker.cpp: Added.
10
        (TestWebKitAPI::didReceiveMessageFromInjectedBundle):
11
        (TestWebKitAPI::didReceiveTitleForFrame):
12
        (TestWebKitAPI::TEST):
13
        * TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.html: Added.
14
        * TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.js: Added.
15
        (onconnect):
16
        (listenForMessage):
17
        * TestWebKitAPI/Tests/WebKit2/WebWorkerTest.html: Added.
18
        * TestWebKitAPI/Tests/WebKit2/WebWorkerTest.js: Added.
19
        (self.onmessage):
20
        * TestWebKitAPI/Tests/WebKit2/WebWorker_Bundle.cpp: Added.
21
        (TestWebKitAPI::foo):
22
        (TestWebKitAPI::bar):
23
        (TestWebKitAPI::webWorkerInitialize):
24
        (TestWebKitAPI::webWorkerTerminate):
25
        (TestWebKitAPI::WebWorkerTest::WebWorkerTest):
26
        (TestWebKitAPI::WebWorkerTest::initialize):
27
1
2013-06-11  Timothy Hatcher  <timothy@apple.com>
28
2013-06-11  Timothy Hatcher  <timothy@apple.com>
2
29
3
        Have build-webkit build the WebInspectorUI project.
30
        Have build-webkit build the WebInspectorUI project.
- a/Tools/TestWebKitAPI/PlatformEfl.cmake +2 lines
Lines 55-60 set(test_webcore_BINARIES a/Tools/TestWebKitAPI/PlatformEfl.cmake_sec1
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/efl/WKViewClientWebProcessCallbacks_Bundle.cpp
57
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/efl/WKViewClientWebProcessCallbacks_Bundle.cpp
58
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/WebWorker_Bundle.cpp
58
)
59
)
59
60
60
set(test_webkit2_api_BINARIES
61
set(test_webkit2_api_BINARIES
Lines 88-93 set(test_webkit2_api_BINARIES a/Tools/TestWebKitAPI/PlatformEfl.cmake_sec2
88
    PreventEmptyUserAgent
89
    PreventEmptyUserAgent
89
    PrivateBrowsingPushStateNoHistoryCallback
90
    PrivateBrowsingPushStateNoHistoryCallback
90
    UserMessage
91
    UserMessage
92
    WebWorker
91
    WKConnection
93
    WKConnection
92
    WKPreferences
94
    WKPreferences
93
    WKString
95
    WKString
- a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorker.cpp +109 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
#include <WebKit2/WKView.h>
39
40
namespace TestWebKitAPI {
41
42
static bool initialized = false;
43
static bool terminated = false;
44
static bool changedTitle = false;
45
static bool initializedShared = false;
46
static bool terminatedShared = false;
47
static bool changedTitleShared = false;
48
49
static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef, const void*)
50
{
51
    if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerInitMessage"))
52
        initialized = true;
53
    else if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerTerminateMessage"))
54
        terminated = true;
55
    else if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerSharedInitMessage"))
56
        initializedShared = true;
57
    else if (WKStringIsEqualToUTF8CString(messageName, "WebWorkerSharedTerminateMessage"))
58
        terminatedShared = true;
59
}
60
61
static void didReceiveTitleForFrame(WKPageRef, WKStringRef title, WKFrameRef, WKTypeRef, const void *)
62
{
63
    if (WKStringIsEqualToUTF8CString(title, "WebWorkerTitle"))
64
        changedTitle = true;
65
    else if (WKStringIsEqualToUTF8CString(title, "WebWorkerSharedTitle"))
66
        changedTitleShared = true;
67
}
68
69
TEST(WebKit2, WebWorker)
70
{
71
    // This test cover the binding between functions of JavaScript Workers and
72
    // functions defined at a previously loaded bundle. It verifies the two
73
    // types of Workers, dedicated and shared.
74
75
    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("WebWorkerTest"));
76
    WKRetainPtr<WKViewRef> view(AdoptWK, WKViewCreate(context.get(), 0));
77
78
    WKViewInitialize(view.get());
79
80
81
    WKPageLoaderClient pageLoaderClient;
82
    memset(&pageLoaderClient, 0, sizeof(WKPageLoaderClient));
83
    pageLoaderClient.version = kWKPageLoaderClientCurrentVersion;
84
    pageLoaderClient.didReceiveTitleForFrame = didReceiveTitleForFrame;
85
    WKPageSetPageLoaderClient(WKViewGetPage(view.get()), &pageLoaderClient);
86
87
    WKContextInjectedBundleClient injectedBundleClient;
88
    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
89
    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
90
    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient);
91
92
    WKPageGroupRef pageGroup = WKPageGetPageGroup(WKViewGetPage(view.get()));
93
    WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup);
94
    WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true);
95
96
    WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("../WebKit2/WebWorkerTest", "html"));
97
    WKPageLoadURL(WKViewGetPage(view.get()), url.get());
98
    Util::run(&initialized);
99
    Util::run(&terminated);
100
    Util::run(&changedTitle);
101
102
    url = adoptWK(Util::createURLForResource("../WebKit2/WebWorkerSharedTest", "html"));
103
    WKPageLoadURL(WKViewGetPage(view.get()), url.get());
104
    Util::run(&initializedShared);
105
    Util::run(&terminatedShared);
106
    Util::run(&changedTitleShared);
107
}
108
109
} // 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 +89 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
36
namespace TestWebKitAPI {
37
38
JSValueRef foo(JSContextRef ctx, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef*)
39
{
40
    WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WebWorkerInitMessage").get(), 0);
41
    return JSValueMakeString(ctx, JSStringCreateWithUTF8CString("WebWorkerTitle"));
42
}
43
44
JSValueRef bar(JSContextRef ctx, JSObjectRef, JSObjectRef, size_t, const JSValueRef[], JSValueRef*)
45
{
46
    WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WebWorkerSharedInitMessage").get(), 0);
47
    return JSValueMakeString(ctx, JSStringCreateWithUTF8CString("WebWorkerSharedTitle"));
48
}
49
50
void webWorkerInitialize(JSContextRef context, int isDedicated)
51
{
52
    if (isDedicated) {
53
        JSStringRef funcName = JSStringCreateWithUTF8CString("foo");
54
        JSObjectRef jsFunc = JSObjectMakeFunctionWithCallback(context, funcName, &foo);
55
        JSObjectSetProperty(context, JSContextGetGlobalObject(context), funcName, jsFunc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, 0);
56
        JSStringRelease(funcName);
57
    } else {
58
        JSStringRef funcName = JSStringCreateWithUTF8CString("bar");
59
        JSObjectRef jsFunc = JSObjectMakeFunctionWithCallback(context, funcName, &bar);
60
        JSObjectSetProperty(context, JSContextGetGlobalObject(context), funcName, jsFunc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, 0);
61
        JSStringRelease(funcName);
62
    }
63
}
64
65
void webWorkerTerminate(JSContextRef context, int isDedicated)
66
{
67
    if (isDedicated)
68
        WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WebWorkerTerminateMessage").get(), 0);
69
    else
70
        WKBundlePostMessage(InjectedBundleController::shared().bundle(), Util::toWK("WebWorkerSharedTerminateMessage").get(), 0);
71
}
72
73
class WebWorkerTest : public InjectedBundleTest {
74
public:
75
    WebWorkerTest(const std::string& identifier)
76
        : InjectedBundleTest(identifier)
77
    {
78
    }
79
80
    virtual void initialize(WKBundleRef, WKTypeRef)
81
    {
82
        WKBundleFrameSetWorkerInitializeCallback(webWorkerInitialize);
83
        WKBundleFrameSetWorkerTerminateCallback(webWorkerTerminate);
84
    }
85
};
86
87
static InjectedBundleTest::Register<WebWorkerTest> registrar("WebWorkerTest");
88
89
} // namespace TestWebKitAPI

Return to Bug 117523