| Differences between
and this patch
- a/Source/WebCore/ChangeLog +20 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2013-06-13  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
        Were added callbacks of initialize and terminate for WebWorkers on WK2 API.
9
        These callbacks can 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-06-13  Mihai Tica  <mitica@adobe.com>
21
2013-06-13  Mihai Tica  <mitica@adobe.com>
2
22
3
        [CSS Background Blending] Enable CSS Background blending for layers with SVGs.
23
        [CSS Background Blending] Enable CSS Background blending for layers with SVGs.
- a/Source/WebKit2/ChangeLog +18 lines
Lines 1-3 a/Source/WebKit2/ChangeLog_sec1
1
2013-06-13  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
        Were added callbacks of initialize and terminate for WebWorkers on WK2 API.
9
        These callbacks can 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-06-13  Michał Pakuła vel Rutka  <m.pakula@samsung.com>
19
2013-06-13  Michał Pakuła vel Rutka  <m.pakula@samsung.com>
2
20
3
        [EFL][WK2] Wrong context menu and popup menu positions when scroll is applied
21
        [EFL][WK2] Wrong context menu and popup menu positions when scroll is applied
- 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 +42 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
#else
135
    UNUSED_PARAM(callback);
136
#endif
137
}
138
139
static WKBundleFrameWorkerScriptCallback s_localWorkerScriptTerminateCallback;
140
141
static void localWorkerScriptTerminateCallback(JSC::ExecState* execState, bool isDedicated)
142
{
143
    s_localWorkerScriptTerminateCallback(toRef(execState), isDedicated);
144
}
145
146
void WKBundleFrameSetWorkerTerminateCallback(WKBundleFrameWorkerScriptCallback callback)
147
{
148
#if ENABLE(WORKERS)
149
    if (callback) {
150
        s_localWorkerScriptTerminateCallback = callback;
151
        WorkerScriptController::setTerminateScriptCallback(localWorkerScriptTerminateCallback);
152
    } else
153
        WorkerScriptController::setTerminateScriptCallback(0);
154
#else
155
    UNUSED_PARAM(callback);
156
#endif
157
}
158
117
JSValueRef WKBundleFrameGetJavaScriptWrapperForRangeForWorld(WKBundleFrameRef frameRef, WKBundleRangeHandleRef rangeHandleRef, WKBundleScriptWorldRef worldRef)
159
JSValueRef WKBundleFrameGetJavaScriptWrapperForRangeForWorld(WKBundleFrameRef frameRef, WKBundleRangeHandleRef rangeHandleRef, WKBundleScriptWorldRef worldRef)
118
{
160
{
119
    return toImpl(frameRef)->jsWrapperForWorld(toImpl(rangeHandleRef), toImpl(worldRef));
161
    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 +34 lines
Lines 1-3 a/Tools/ChangeLog_sec1
1
2013-06-13  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
        Were added callbacks of initialize and terminate for WebWorkers on WK2 API.
9
        These callbacks can 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/CMakeLists.txt:
13
        * TestWebKitAPI/GNUmakefile.am:
14
        * TestWebKitAPI/InjectedBundle.pri:
15
        * TestWebKitAPI/PlatformEfl.cmake:
16
        * TestWebKitAPI/Tests/WebKit2/WebWorker.cpp: Added.
17
        (TestWebKitAPI::didReceiveMessageFromInjectedBundle):
18
        (TestWebKitAPI::didReceiveTitleForFrame):
19
        (TestWebKitAPI::TEST):
20
        * TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.html: Added.
21
        * TestWebKitAPI/Tests/WebKit2/WebWorkerSharedTest.js: Added.
22
        (onconnect):
23
        (listenForMessage):
24
        * TestWebKitAPI/Tests/WebKit2/WebWorkerTest.html: Added.
25
        * TestWebKitAPI/Tests/WebKit2/WebWorkerTest.js: Added.
26
        (self.onmessage):
27
        * TestWebKitAPI/Tests/WebKit2/WebWorker_Bundle.cpp: Added.
28
        (TestWebKitAPI::foo):
29
        (TestWebKitAPI::bar):
30
        (TestWebKitAPI::webWorkerInitialize):
31
        (TestWebKitAPI::webWorkerTerminate):
32
        (TestWebKitAPI::WebWorkerTest::WebWorkerTest):
33
        (TestWebKitAPI::WebWorkerTest::initialize):
34
1
2013-06-13  Michael Brüning  <michael.bruning@digia.com>
35
2013-06-13  Michael Brüning  <michael.bruning@digia.com>
2
36
3
        [Qt][Mac] Disable QTKit video on OS X.
37
        [Qt][Mac] Disable QTKit video on OS X.
- a/Tools/TestWebKitAPI/CMakeLists.txt +1 lines
Lines 47-52 add_library(TestWebKitAPIInjectedBundle SHARED a/Tools/TestWebKitAPI/CMakeLists.txt_sec1
47
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp
47
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp
48
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp
48
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp
49
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/UserMessage_Bundle.cpp
49
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/UserMessage_Bundle.cpp
50
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/WebWorker_Bundle.cpp
50
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/WKConnection_Bundle.cpp
51
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/WKConnection_Bundle.cpp
51
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp
52
    ${TESTWEBKITAPI_DIR}/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp
52
)
53
)
- 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/InjectedBundle.pri +1 lines
Lines 38-43 SOURCES += \ a/Tools/TestWebKitAPI/InjectedBundle.pri_sec1
38
    $$PWD/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp \
38
    $$PWD/Tests/WebKit2/ResponsivenessTimerDoesntFireEarly_Bundle.cpp \
39
    $$PWD/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp \
39
    $$PWD/Tests/WebKit2/ShouldGoToBackForwardListItem_Bundle.cpp \
40
    $$PWD/Tests/WebKit2/UserMessage_Bundle.cpp \
40
    $$PWD/Tests/WebKit2/UserMessage_Bundle.cpp \
41
    $$PWD/Tests/WebKit2/WebWorker_Bundle.cpp \
41
    $$PWD/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp \
42
    $$PWD/Tests/WebKit2/WillSendSubmitEvent_Bundle.cpp \
42
    $$PWD/Tests/WebKit2/WKConnection_Bundle.cpp
43
    $$PWD/Tests/WebKit2/WKConnection_Bundle.cpp
43
44
- a/Tools/TestWebKitAPI/PlatformEfl.cmake +1 lines
Lines 88-93 set(test_webkit2_api_BINARIES a/Tools/TestWebKitAPI/PlatformEfl.cmake_sec1
88
    PreventEmptyUserAgent
88
    PreventEmptyUserAgent
89
    PrivateBrowsingPushStateNoHistoryCallback
89
    PrivateBrowsingPushStateNoHistoryCallback
90
    UserMessage
90
    UserMessage
91
    WebWorker
91
    WKConnection
92
    WKConnection
92
    WKPreferences
93
    WKPreferences
93
    WKString
94
    WKString
- a/Tools/TestWebKitAPI/Tests/WebKit2/WebWorker.cpp +108 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
    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("WebWorkerTest"));
75
    WKRetainPtr<WKViewRef> view(AdoptWK, WKViewCreate(context.get(), 0));
76
77
    WKViewInitialize(view.get());
78
79
80
    WKPageLoaderClient pageLoaderClient;
81
    memset(&pageLoaderClient, 0, sizeof(WKPageLoaderClient));
82
    pageLoaderClient.version = kWKPageLoaderClientCurrentVersion;
83
    pageLoaderClient.didReceiveTitleForFrame = didReceiveTitleForFrame;
84
    WKPageSetPageLoaderClient(WKViewGetPage(view.get()), &pageLoaderClient);
85
86
    WKContextInjectedBundleClient injectedBundleClient;
87
    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
88
    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
89
    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient);
90
91
    WKPageGroupRef pageGroup = WKPageGetPageGroup(WKViewGetPage(view.get()));
92
    WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup);
93
    WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true);
94
95
    WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("../WebKit2/WebWorkerTest", "html"));
96
    WKPageLoadURL(WKViewGetPage(view.get()), url.get());
97
    Util::run(&initialized);
98
    Util::run(&terminated);
99
    Util::run(&changedTitle);
100
101
    url = adoptWK(Util::createURLForResource("../WebKit2/WebWorkerSharedTest", "html"));
102
    WKPageLoadURL(WKViewGetPage(view.get()), url.get());
103
    Util::run(&initializedShared);
104
    Util::run(&terminatedShared);
105
    Util::run(&changedTitleShared);
106
}
107
108
} // 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