Commit e31aa0c3 authored by ukai@chromium.org's avatar ukai@chromium.org

2010-01-06 Fumitoshi Ukai <ukai@chromium.org>

        Reviewed by David Levin

        Add WebSocket feature in Worker
        https://bugs.webkit.org/show_bug.cgi?id=32214

        * websocket/tests/workers/resources/simple_wsh.py: Copied from LayoutTests/websocket/tests/simple_wsh.py.
        * websocket/tests/workers/resources/worker-simple.js: Added.
        * websocket/tests/workers/worker-simple-expected.txt: Added.
        * websocket/tests/workers/worker-simple.html: Added.
2010-01-06  Fumitoshi Ukai  <ukai@chromium.org>

        Reviewed by David Levin.

        Add WebSocket feature in Worker
        https://bugs.webkit.org/show_bug.cgi?id=32214

        Introduce ThreadableWebSocketChannel interface and add
        WorkerThreadableWebSocketChannel for Worker.
        WorkerThreadableWebSocketChannel uses WebSocketChannel in the
        main thread, which is managed by Peer and communicated via Bridge.

        Test: websocket/tests/workers/worker-simple.html

        * GNUmakefile.am:
        * WebCore.gypi:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * bindings/js/JSWebSocketConstructor.h:
        * bindings/js/JSWorkerContextCustom.cpp:
        (WebCore::JSWorkerContext::webSocket):
        * bindings/v8/WorkerContextExecutionProxy.cpp:
        (WebCore::WorkerContextExecutionProxy::convertEventTargetToV8Object):
        * bindings/v8/custom/V8WebSocketCustom.cpp:
        (WebCore::V8Custom::v8WebSocketConstructorCallback):
        * bindings/v8/custom/V8WorkerContextCustom.cpp:
        * platform/CrossThreadCopier.cpp:
        (WebCore::::copy):
        * platform/CrossThreadCopier.h:
        (WebCore::):
        * websockets/ThreadableWebSocketChannel.cpp: Added.
        * websockets/ThreadableWebSocketChannel.h: Added.
        * websockets/ThreadableWebSocketChannelClientWrapper.h: Added.
        * websockets/WebSocket.cpp:
        (WebCore::WebSocket::connect):
        (WebCore::WebSocket::didReceiveMessage):
        * websockets/WebSocket.h:
        * websockets/WebSocketChannel.h:
        (WebCore::WebSocketChannel::refThreadableWebSocketChannel):
        (WebCore::WebSocketChannel::derefThreadableWebSocketChannel):
        * websockets/WebSocketChannelClient.h:
        * websockets/WebSocketHandshake.h:
        * websockets/WorkerThreadableWebSocketChannel.cpp: Added.
        * websockets/WorkerThreadableWebSocketChannel.h: Added.
        * workers/WorkerContext.idl:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@52892 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 39adec95
2010-01-06 Fumitoshi Ukai <ukai@chromium.org>
Reviewed by David Levin
Add WebSocket feature in Worker
https://bugs.webkit.org/show_bug.cgi?id=32214
* websocket/tests/workers/resources/simple_wsh.py: Copied from LayoutTests/websocket/tests/simple_wsh.py.
* websocket/tests/workers/resources/worker-simple.js: Added.
* websocket/tests/workers/worker-simple-expected.txt: Added.
* websocket/tests/workers/worker-simple.html: Added.
2010-01-06 Adam Bergkvist <adam.bergkvist@ericsson.com>
Reviewed by Darin Adler.
# Copyright (C) 2009 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from mod_pywebsocket import msgutil
def web_socket_do_extra_handshake(request):
pass # Always accept.
def web_socket_transfer_data(request):
msgutil.send_message(request, 'Hello from Simple WSH.')
if (self.postMessage)
runTests();
else
onconnect = handleConnect();
function handleConnect(evevnt)
{
// For shared workers, create a faux postMessage() API to send message back to the parent page.
self.postMessage = function (message) { event.ports[0].postMessage(message); };
runTests();
};
function runTests()
{
try {
postMessage("PASS: worker: init");
if ('WebSocket' in self)
postMessage("PASS: worker: WebSocket exists");
else
postMessage("PASS: worker: no WebSocket");
ws = new WebSocket('ws://localhost:8880/websocket/tests/workers/resources/simple');
ws.onopen = function() {
postMessage("PASS: worker: Connected.");
};
ws.onmessage = function(evt) {
postMessage("PASS: worker: Received: '" + evt.data + "'");
};
ws.onclose = function() {
postMessage("PASS: worker: Closed.");
postMessage("DONE");
};
} catch (e) {
postMessage("FAIL: worker: Unexpected exception: " + e);
} finally {
postMessage("PASS: worker: successfullyParsed:" + ws);
}
};
Test for Web Socket in Worker.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS: worker: init
PASS: worker: WebSocket exists
PASS: worker: successfullyParsed:[object WebSocket]
PASS: worker: Connected.
PASS: worker: Received: 'Hello from Simple WSH.'
PASS: worker: Closed.
DONE
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head></head>
<body>
<p>Test for Web Socket in Worker.</p>
<p></p>
<p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
<pre id=log>
</pre>
<script>
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
function log(message)
{
document.getElementById("log").innerHTML += message + "\n";
}
function endTest()
{
log("TEST COMPLETE");
if (window.layoutTestController)
layoutTestController.notifyDone();
}
var worker = new Worker('resources/worker-simple.js');
worker.onmessage = function (evt) {
log(evt.data);
if (evt.data == "DONE")
endTest();
};
</script>
</body>
</html>
2010-01-06 Fumitoshi Ukai <ukai@chromium.org>
Reviewed by David Levin.
Add WebSocket feature in Worker
https://bugs.webkit.org/show_bug.cgi?id=32214
Introduce ThreadableWebSocketChannel interface and add
WorkerThreadableWebSocketChannel for Worker.
WorkerThreadableWebSocketChannel uses WebSocketChannel in the
main thread, which is managed by Peer and communicated via Bridge.
Test: websocket/tests/workers/worker-simple.html
* GNUmakefile.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSWebSocketConstructor.h:
* bindings/js/JSWorkerContextCustom.cpp:
(WebCore::JSWorkerContext::webSocket):
* bindings/v8/WorkerContextExecutionProxy.cpp:
(WebCore::WorkerContextExecutionProxy::convertEventTargetToV8Object):
* bindings/v8/custom/V8WebSocketCustom.cpp:
(WebCore::V8Custom::v8WebSocketConstructorCallback):
* bindings/v8/custom/V8WorkerContextCustom.cpp:
* platform/CrossThreadCopier.cpp:
(WebCore::::copy):
* platform/CrossThreadCopier.h:
(WebCore::):
* websockets/ThreadableWebSocketChannel.cpp: Added.
* websockets/ThreadableWebSocketChannel.h: Added.
* websockets/ThreadableWebSocketChannelClientWrapper.h: Added.
* websockets/WebSocket.cpp:
(WebCore::WebSocket::connect):
(WebCore::WebSocket::didReceiveMessage):
* websockets/WebSocket.h:
* websockets/WebSocketChannel.h:
(WebCore::WebSocketChannel::refThreadableWebSocketChannel):
(WebCore::WebSocketChannel::derefThreadableWebSocketChannel):
* websockets/WebSocketChannelClient.h:
* websockets/WebSocketHandshake.h:
* websockets/WorkerThreadableWebSocketChannel.cpp: Added.
* websockets/WorkerThreadableWebSocketChannel.h: Added.
* workers/WorkerContext.idl:
2010-01-06 Adam Bergkvist <adam.bergkvist@ericsson.com>
Reviewed by Darin Adler.
......@@ -3386,6 +3386,15 @@ webcore_sources += \
WebCore/websockets/WebSocketHandshake.cpp \
WebCore/websockets/WebSocketHandshake.h
if ENABLE_WORKERS
webcore_sources += \
WebCore/websockets/ThreadableWebSocketChannel.cpp \
WebCore/websockets/ThreadableWebSocketChannel.h \
WebCore/websockets/ThreadableWebSocketChannelClientWrapper.h \
WebCore/websockets/WorkerThreadableWebSocketChannel.cpp \
WebCore/websockets/WorkerThreadableWebSocketChannel.h
endif
webcoregtk_sources += \
WebCore/platform/network/soup/SocketStreamError.h \
WebCore/platform/network/soup/SocketStreamHandle.h \
......
......@@ -3556,6 +3556,9 @@
'svg/SynchronizablePropertyController.cpp',
'svg/SynchronizablePropertyController.h',
'svg/SynchronizableTypeWrapper.h',
'websockets/ThreadableWebSocketChannel.cpp',
'websockets/ThreadableWebSocketChannel.h',
'websockets/ThreadableWebSocketChannelClientWrapper.h',
'websockets/WebSocket.cpp',
'websockets/WebSocket.h',
'websockets/WebSocketChannel.cpp',
......@@ -3563,6 +3566,8 @@
'websockets/WebSocketChannelClient.h',
'websockets/WebSocketHandshake.cpp',
'websockets/WebSocketHandshake.h',
'websockets/WorkerThreadableWebSocketChannel.cpp',
'websockets/WorkerThreadableWebSocketChannel.h',
'workers/AbstractWorker.cpp',
'workers/AbstractWorker.h',
'workers/DedicatedWorkerContext.cpp',
......
......@@ -3222,6 +3222,12 @@ SOURCES += \
platform/network/qt/SocketStreamHandleSoup.cpp \
bindings/js/JSWebSocketCustom.cpp \
bindings/js/JSWebSocketConstructor.cpp
contains(DEFINES, ENABLE_WORKERS=1) {
SOURCES += \
websockets/ThreadableWebSocketChannel.cpp \
websockets/WorkerThreadableWebSocketChannel.cpp
}
}
# GENERATOR 1: IDL compiler
......
......@@ -43376,6 +43376,18 @@
<Filter
Name="websockets"
>
<File
RelativePath="..\websockets\ThreadableWebSocketChannel.cpp"
>
</File>
<File
RelativePath="..\websockets\ThreadableWebSocketChannel.h"
>
</File>
<File
RelativePath="..\websockets\ThreadableWebSocketChannelClientWrapper.h"
>
</File>
<File
RelativePath="..\websockets\WebSocket.cpp"
>
......@@ -43404,6 +43416,14 @@
RelativePath="..\websockets\WebSocketHandshake.h"
>
</File>
<File
RelativePath="..\websockets\WorkerThreadableWebSocketChannel.cpp"
>
</File>
<File
RelativePath="..\websockets\WorkerThreadableWebSocketChannel.h"
>
</File>
</Filter>
<File
RelativePath="..\config.h"
......
......@@ -968,6 +968,11 @@
510D4A4E103177A20049EA54 /* WebSocketChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 510D4A47103177A20049EA54 /* WebSocketChannel.cpp */; };
510D4A4F103177A20049EA54 /* WebSocketChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 510D4A48103177A20049EA54 /* WebSocketChannel.h */; };
510D4A50103177A20049EA54 /* WebSocketChannelClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 510D4A49103177A20049EA54 /* WebSocketChannelClient.h */; };
5112247210CFB8C6008099D7 /* ThreadableWebSocketChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5112247110CFB8C6008099D7 /* ThreadableWebSocketChannel.cpp */; };
5112247410CFB8D8008099D7 /* ThreadableWebSocketChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 5112247310CFB8D8008099D7 /* ThreadableWebSocketChannel.h */; };
5112247610CFB8E8008099D7 /* ThreadableWebSocketChannelClientWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 5112247510CFB8E8008099D7 /* ThreadableWebSocketChannelClientWrapper.h */; };
5112247810CFB8F4008099D7 /* WorkerThreadableWebSocketChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5112247710CFB8F4008099D7 /* WorkerThreadableWebSocketChannel.cpp */; };
5112247A10CFB8FF008099D7 /* WorkerThreadableWebSocketChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 5112247910CFB8FF008099D7 /* WorkerThreadableWebSocketChannel.h */; };
5116D9770CF177BD00C2B84D /* DatabaseDetails.h in Headers */ = {isa = PBXBuildFile; fileRef = 5116D9750CF177BD00C2B84D /* DatabaseDetails.h */; settings = {ATTRIBUTES = (Private, ); }; };
511F23170DC160DA004F0032 /* LocalStorageTask.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 511F23130DC160DA004F0032 /* LocalStorageTask.cpp */; };
511F23180DC160DA004F0032 /* LocalStorageTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 511F23140DC160DA004F0032 /* LocalStorageTask.h */; };
......@@ -6287,6 +6292,11 @@
510D4A47103177A20049EA54 /* WebSocketChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSocketChannel.cpp; sourceTree = "<group>"; };
510D4A48103177A20049EA54 /* WebSocketChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSocketChannel.h; sourceTree = "<group>"; };
510D4A49103177A20049EA54 /* WebSocketChannelClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSocketChannelClient.h; sourceTree = "<group>"; };
5112247110CFB8C6008099D7 /* ThreadableWebSocketChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadableWebSocketChannel.cpp; sourceTree = "<group>"; };
5112247310CFB8D8008099D7 /* ThreadableWebSocketChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadableWebSocketChannel.h; sourceTree = "<group>"; };
5112247510CFB8E8008099D7 /* ThreadableWebSocketChannelClientWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadableWebSocketChannelClientWrapper.h; sourceTree = "<group>"; };
5112247710CFB8F4008099D7 /* WorkerThreadableWebSocketChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkerThreadableWebSocketChannel.cpp; sourceTree = "<group>"; };
5112247910CFB8FF008099D7 /* WorkerThreadableWebSocketChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WorkerThreadableWebSocketChannel.h; sourceTree = "<group>"; };
5116D9750CF177BD00C2B84D /* DatabaseDetails.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DatabaseDetails.h; sourceTree = "<group>"; };
511F23130DC160DA004F0032 /* LocalStorageTask.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LocalStorageTask.cpp; sourceTree = "<group>"; };
511F23140DC160DA004F0032 /* LocalStorageTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalStorageTask.h; sourceTree = "<group>"; };
......@@ -11000,6 +11010,11 @@
518A34BD1026C831001B6896 /* websockets */ = {
isa = PBXGroup;
children = (
5112247910CFB8FF008099D7 /* WorkerThreadableWebSocketChannel.h */,
5112247710CFB8F4008099D7 /* WorkerThreadableWebSocketChannel.cpp */,
5112247510CFB8E8008099D7 /* ThreadableWebSocketChannelClientWrapper.h */,
5112247310CFB8D8008099D7 /* ThreadableWebSocketChannel.h */,
5112247110CFB8C6008099D7 /* ThreadableWebSocketChannel.cpp */,
518A34BE1026C831001B6896 /* WebSocket.cpp */,
518A34BF1026C831001B6896 /* WebSocket.h */,
518A34C01026C831001B6896 /* WebSocket.idl */,
......@@ -18291,6 +18306,9 @@
08735FB910E91232006D6FAD /* SVGMarkerLayoutInfo.h in Headers */,
08385FF610F0186000BFE07B /* SVGMarkerData.h in Headers */,
0AFDAC3D10F5448C00E1F3D2 /* PluginWidget.h in Headers */,
5112247410CFB8D8008099D7 /* ThreadableWebSocketChannel.h in Headers */,
5112247610CFB8E8008099D7 /* ThreadableWebSocketChannelClientWrapper.h in Headers */,
5112247A10CFB8FF008099D7 /* WorkerThreadableWebSocketChannel.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -20449,6 +20467,8 @@
BC56CB2110D5AC8000A77C64 /* GeolocationController.cpp in Sources */,
08735FB810E91232006D6FAD /* SVGMarkerLayoutInfo.cpp in Sources */,
0AFDAC3B10F5448300E1F3D2 /* PluginWidgetMac.mm in Sources */,
5112247210CFB8C6008099D7 /* ThreadableWebSocketChannel.cpp in Sources */,
5112247810CFB8F4008099D7 /* WorkerThreadableWebSocketChannel.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -31,6 +31,8 @@
#ifndef JSWebSocketConstructor_h
#define JSWebSocketConstructor_h
#if ENABLE(WEB_SOCKETS)
#include "JSDOMBinding.h"
namespace WebCore {
......@@ -45,6 +47,8 @@ class JSWebSocketConstructor : public DOMConstructorObject {
virtual const JSC::ClassInfo* classInfo() const { return &s_info; }
};
} // namespace WebCore
} // namespace WebCore
#endif // ENABLE(WEB_SOCKETS)
#endif // JSWebSocketConstructor_h
#endif // JSWebSocketConstructor_h
......@@ -32,8 +32,10 @@
#include "JSDOMBinding.h"
#include "JSDOMGlobalObject.h"
#include "JSEventListener.h"
#include "JSEventSourceConstructor.h"
#include "JSMessageChannelConstructor.h"
#include "JSMessagePort.h"
#include "JSWebSocketConstructor.h"
#include "JSWorkerLocation.h"
#include "JSWorkerNavigator.h"
#include "JSXMLHttpRequestConstructor.h"
......@@ -43,10 +45,6 @@
#include "WorkerNavigator.h"
#include <interpreter/Interpreter.h>
#if ENABLE(EVENTSOURCE)
#include "JSEventSourceConstructor.h"
#endif
using namespace JSC;
namespace WebCore {
......@@ -93,6 +91,13 @@ JSValue JSWorkerContext::xmlHttpRequest(ExecState* exec) const
return getDOMConstructor<JSXMLHttpRequestConstructor>(exec, this);
}
#if ENABLE(WEB_SOCKETS)
JSValue JSWorkerContext::webSocket(ExecState* exec) const
{
return getDOMConstructor<JSWebSocketConstructor>(exec, this);
}
#endif
JSValue JSWorkerContext::importScripts(ExecState* exec, const ArgList& args)
{
if (!args.size())
......
......@@ -319,6 +319,12 @@ v8::Handle<v8::Value> WorkerContextExecutionProxy::convertEventTargetToV8Object(
if (mp)
return convertToV8Object(V8ClassIndex::MESSAGEPORT, mp);
#if ENABLE(WEB_SOCKETS)
WebSocket* webSocket = target->toWebSocket();
if (webSocket)
return convertToV8Object(V8ClassIndex::WEBSOCKET, webSocket);
#endif
ASSERT_NOT_REACHED();
return v8::Handle<v8::Value>();
}
......
......@@ -93,14 +93,9 @@ v8::Handle<v8::Value> V8Custom::v8WebSocketConstructorCallback(const v8::Argumen
return throwError("Empty URL", V8Proxy::SyntaxError);
// Get the script execution context.
ScriptExecutionContext* context = 0;
// TODO: Workers
if (!context) {
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
if (!frame)
return throwError("WebSocket constructor's associated frame is not available", V8Proxy::ReferenceError);
context = frame->document();
}
ScriptExecutionContext* context = getScriptExecutionContext();
if (!context)
return throwError("WebSocket constructor's associated frame is not available", V8Proxy::ReferenceError);
const KURL& url = context->completeURL(toWebCoreString(urlstring));
......
......@@ -42,6 +42,7 @@
#include "V8Proxy.h"
#include "V8Utilities.h"
#include "V8WorkerContextEventListener.h"
#include "WebSocket.h"
#include "WorkerContext.h"
#include "WorkerContextExecutionProxy.h"
......
......@@ -32,6 +32,7 @@
#include "CrossThreadCopier.h"
#include "KURL.h"
#include "PlatformString.h"
#include "ResourceError.h"
#include "ResourceRequest.h"
......@@ -39,6 +40,11 @@
namespace WebCore {
CrossThreadCopierBase<false, KURL>::Type CrossThreadCopierBase<false, KURL>::copy(const KURL& url)
{
return url.copy();
}
CrossThreadCopierBase<false, String>::Type CrossThreadCopierBase<false, String>::copy(const String& str)
{
return str.crossThreadString();
......
......@@ -40,6 +40,7 @@
namespace WebCore {
class KURL;
class ResourceError;
class ResourceRequest;
class ResourceResponse;
......@@ -94,6 +95,11 @@ namespace WebCore {
}
};
template<> struct CrossThreadCopierBase<false, KURL> {
typedef KURL Type;
static Type copy(const KURL&);
};
template<> struct CrossThreadCopierBase<false, String> {
typedef String Type;
static Type copy(const String&);
......
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if ENABLE(WEB_SOCKETS)
#include "ThreadableWebSocketChannel.h"
#include "PlatformString.h"
#include "ScriptExecutionContext.h"
#include "ThreadableWebSocketChannelClientWrapper.h"
#include "WebSocketChannel.h"
#include "WebSocketChannelClient.h"
#include "WorkerContext.h"
#include "WorkerRunLoop.h"
#include "WorkerThread.h"
#include "WorkerThreadableWebSocketChannel.h"
#include <wtf/PassRefPtr.h>
namespace WebCore {
static const char webSocketChannelMode[] = "webSocketChannelMode";
PassRefPtr<ThreadableWebSocketChannel> ThreadableWebSocketChannel::create(ScriptExecutionContext* context, WebSocketChannelClient* client, const KURL& url, const String& protocol)
{
ASSERT(context);
ASSERT(client);
#if ENABLE(WORKERS)
if (context->isWorkerContext()) {
WorkerContext* workerContext = static_cast<WorkerContext*>(context);
WorkerRunLoop& runLoop = workerContext->thread()->runLoop();
String mode = webSocketChannelMode;
mode.append(String::number(runLoop.createUniqueId()));
return WorkerThreadableWebSocketChannel::create(workerContext, client, mode, url, protocol);
}
#endif // ENABLE(WORKERS)
ASSERT(context->isDocument());
return WebSocketChannel::create(context, client, url, protocol);
}
} // namespace WebCore
#endif // ENABLE(WEB_SOCKETS)
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ThreadableWebSocketChannel_h
#define ThreadableWebSocketChannel_h
#if ENABLE(WEB_SOCKETS)
#include <wtf/Noncopyable.h>
#include <wtf/PassRefPtr.h>
namespace WebCore {
class KURL;
class ScriptExecutionContext;
class String;
class WebSocketChannelClient;
class ThreadableWebSocketChannel : public Noncopyable {
public:
static PassRefPtr<ThreadableWebSocketChannel> create(ScriptExecutionContext*, WebSocketChannelClient*, const KURL&, const String& protocol);
virtual void connect() = 0;
virtual bool send(const String& message) = 0;
virtual unsigned long bufferedAmount() const = 0;
virtual void close() = 0;
virtual void disconnect() = 0; // Will suppress didClose().
void ref() { refThreadableWebSocketChannel(); }
void deref() { derefThreadableWebSocketChannel(); }
protected:
virtual ~ThreadableWebSocketChannel() { }
virtual void refThreadableWebSocketChannel() = 0;
virtual void derefThreadableWebSocketChannel() = 0;
};
} // namespace WebCore
#endif // ENABLE(WEB_SOCKETS)
#endif // ThreadableWebSocketChannel_h
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*