Commit 90b52e84 authored by ap@webkit.org's avatar ap@webkit.org

Reviewed by Darin Adler.

        https://bugs.webkit.org/show_bug.cgi?id=22066
        Implement Worker global object

        * DerivedSources.make: Added WorkerLocation IDL and JSWorkerContext lookup table.

        * WebCore.xcodeproj/project.pbxproj: Only adding files to Mac project for now, as Worker
        support is still disabled by default.

        * bindings/js/JSDOMGlobalObject.cpp: (WebCore::toJSDOMGlobalObject): Implemented Worker case.

        * bindings/js/JSMessageChannelConstructor.cpp:
        (WebCore::JSMessageChannelConstructor::JSMessageChannelConstructor): Ditto.

        * bindings/js/JSWorkerContext.cpp: Added.
        * bindings/js/JSWorkerContext.h: Added.
        * bindings/js/WorkerScriptController.cpp: Added.
        * bindings/js/WorkerScriptController.h: Added.
        * dom/WorkerContext.cpp: Added.
        * dom/WorkerContext.h: Added.
        Added an implementation of worker contexts.

        * dom/DedicatedWorker.cpp:
        (WebCore::DedicatedWorker::startLoad): Fixed a lifetime bug I saw on my tests.
        (WebCore::DedicatedWorker::notifyFinished): Create a thread. Currently, object ownership
        and lifetime is not clear at all.

        * dom/WorkerLocation.cpp: Added.
        * dom/WorkerLocation.h: Added.
        * dom/WorkerLocation.idl: Added.
        Added WorkerLocation, which is one of the objects available to workers.

        * dom/WorkerThread.cpp: Added.
        (WebCore::WorkerThread::WorkerThread):
        (WebCore::WorkerThread::start):
        (WebCore::WorkerThread::workerThreadStart):
        (WebCore::WorkerThread::workerThread):
        * dom/WorkerThread.h: Added.
        (WebCore::WorkerThread::create):
        Run some code in a worker thread (no message loop yet).



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@38150 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d4ff35ba
2008-11-05 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=22066
Implement Worker global object
* DerivedSources.make: Added WorkerLocation IDL and JSWorkerContext lookup table.
* WebCore.xcodeproj/project.pbxproj: Only adding files to Mac project for now, as Worker
support is still disabled by default.
* bindings/js/JSDOMGlobalObject.cpp: (WebCore::toJSDOMGlobalObject): Implemented Worker case.
* bindings/js/JSMessageChannelConstructor.cpp:
(WebCore::JSMessageChannelConstructor::JSMessageChannelConstructor): Ditto.
* bindings/js/JSWorkerContext.cpp: Added.
* bindings/js/JSWorkerContext.h: Added.
* bindings/js/WorkerScriptController.cpp: Added.
* bindings/js/WorkerScriptController.h: Added.
* dom/WorkerContext.cpp: Added.
* dom/WorkerContext.h: Added.
Added an implementation of worker contexts.
* dom/DedicatedWorker.cpp:
(WebCore::DedicatedWorker::startLoad): Fixed a lifetime bug I saw on my tests.
(WebCore::DedicatedWorker::notifyFinished): Create a thread. Currently, object ownership
and lifetime is not clear at all.
* dom/WorkerLocation.cpp: Added.
* dom/WorkerLocation.h: Added.
* dom/WorkerLocation.idl: Added.
Added WorkerLocation, which is one of the objects available to workers.
* dom/WorkerThread.cpp: Added.
(WebCore::WorkerThread::WorkerThread):
(WebCore::WorkerThread::start):
(WebCore::WorkerThread::workerThreadStart):
(WebCore::WorkerThread::workerThread):
* dom/WorkerThread.h: Added.
(WebCore::WorkerThread::create):
Run some code in a worker thread (no message loop yet).
2008-11-05 Antti Koivisto <antti@apple.com>
Reviewed by Dan Bernstein.
......@@ -359,6 +359,7 @@ DOM_CLASSES = \
WebKitCSSTransformValue \
WebKitTransitionEvent \
WheelEvent \
WorkerLocation \
XMLHttpRequest \
XMLHttpRequestException \
XMLHttpRequestProgressEvent \
......@@ -379,6 +380,7 @@ all : \
\
JSDOMWindowBase.lut.h \
JSRGBColor.lut.h \
JSWorkerContext.lut.h \
\
JSJavaScriptCallFrame.h \
\
......
This diff is collapsed.
......@@ -30,6 +30,8 @@
#include "Document.h"
#include "JSDOMWindow.h"
#include "JSEventListener.h"
#include "JSWorkerContext.h"
#include "WorkerContext.h"
using namespace JSC;
......@@ -161,7 +163,12 @@ JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionCo
if (scriptExecutionContext->isDocument())
return toJSDOMWindow(static_cast<Document*>(scriptExecutionContext)->frame());
// Not implemented yet.
#if ENABLE(WORKERS)
if (scriptExecutionContext->isWorkerContext())
return static_cast<WorkerContext*>(scriptExecutionContext)->script()->workerContextWrapper();
#endif
ASSERT_NOT_REACHED();
return 0;
}
......
......@@ -29,6 +29,7 @@
#include "Document.h"
#include "JSDocument.h"
#include "JSMessageChannel.h"
#include "JSWorkerContext.h"
#include "MessageChannel.h"
using namespace JSC;
......@@ -43,8 +44,10 @@ JSMessageChannelConstructor::JSMessageChannelConstructor(ExecState* exec, Script
{
if (m_scriptExecutionContext->isDocument())
m_contextWrapper = toJS(exec, static_cast<Document*>(scriptExecutionContext));
#if ENABLE(WORKERS)
else if (m_scriptExecutionContext->isWorkerContext())
; // Not yet implemented.
m_contextWrapper = toJSDOMGlobalObject(scriptExecutionContext);
#endif
else
ASSERT_NOT_REACHED();
......
/*
* Copyright (C) 2008 Apple 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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(WORKERS)
#include "JSWorkerContext.h"
#include "JSDOMBinding.h"
#include "JSMessageChannelConstructor.h"
#include "JSMessagePort.h"
#include "JSWorkerLocation.h"
#include "WorkerContext.h"
#include "WorkerLocation.h"
using namespace JSC;
namespace WebCore {
JSValue* jsWorkerContextLocation(ExecState*, const Identifier&, const PropertySlot&);
JSValue* jsWorkerContextMessageChannel(ExecState*, const Identifier&, const PropertySlot&);
void setJSWorkerContextMessageChannel(ExecState*, JSObject*, JSValue*);
JSValue* jsWorkerContextMessagePort(ExecState*, const Identifier&, const PropertySlot&);
void setJSWorkerContextMessagePort(ExecState*, JSObject*, JSValue*);
JSValue* jsWorkerContextWorkerLocation(ExecState*, const Identifier&, const PropertySlot&);
void setJSWorkerContextWorkerLocation(ExecState*, JSObject*, JSValue*);
}
/*
@begin JSWorkerContextPrototypeTable
# close jsWorkerContextPrototypeFunctionClose DontDelete|Function 0
# MessagePort methods?
@end
*/
/*
@begin JSWorkerContextTable
location jsWorkerContextLocation DontDelete|ReadOnly
# onclose jsWorkerContextOnclose DontDelete
# onconnect jsWorkerContextOnconnect DontDelete
# onmessage and other MessagePort attributes?
MessageChannel jsWorkerContextMessageChannel DontDelete
MessagePort jsWorkerContextMessagePort DontDelete
WorkerLocation jsWorkerContextWorkerLocation DontDelete
# XMLHttpRequest jsWorkerContextXMLHttpRequest DontDelete
# Database
@end
*/
#include "JSWorkerContext.lut.h"
namespace WebCore {
ASSERT_CLASS_FITS_IN_CELL(JSWorkerContext)
static inline PassRefPtr<StructureID> createJSWorkerContextStructureID(JSGlobalData* globalData)
{
return JSWorkerContext::createStructureID(new (globalData) JSWorkerContextPrototype(JSWorkerContextPrototype::createStructureID(jsNull())));
}
JSWorkerContext::JSWorkerContext(PassRefPtr<WorkerContext> impl)
: JSDOMGlobalObject(createJSWorkerContextStructureID(Heap::heap(this)->globalData()), new JSDOMGlobalObjectData, this)
, m_impl(impl)
{
GlobalPropertyInfo staticGlobals[] = {
GlobalPropertyInfo(Identifier(globalExec(), "self"), this, DontDelete | ReadOnly),
};
addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo));
}
JSWorkerContext::~JSWorkerContext()
{
}
ScriptExecutionContext* JSWorkerContext::scriptExecutionContext() const
{
return m_impl.get();
}
void JSWorkerContext::mark()
{
Base::mark();
markActiveObjectsForContext(*globalData(), scriptExecutionContext());
}
static const HashTable* getJSWorkerContextTable(ExecState* exec)
{
return getHashTableForGlobalData(exec->globalData(), &JSWorkerContextTable);
}
const ClassInfo JSWorkerContext::s_info = { "WorkerContext", 0, 0, getJSWorkerContextTable };
JSObject* JSWorkerContext::createPrototype(ExecState* exec)
{
return new (exec) JSWorkerContextPrototype(JSWorkerLocationPrototype::createStructureID(exec->lexicalGlobalObject()->objectPrototype()));
}
bool JSWorkerContext::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
return getStaticValueSlot<JSWorkerContext, Base>(exec, getJSWorkerContextTable(exec), this, propertyName, slot);
}
JSValue* jsWorkerContextLocation(JSC::ExecState* exec, const Identifier&, const PropertySlot& slot)
{
WorkerContext* imp = static_cast<WorkerContext*>(static_cast<JSWorkerContext*>(asObject(slot.slotBase()))->impl());
return toJS(exec, imp->location());
}
JSValue* jsWorkerContextMessageChannel(ExecState* exec, const Identifier&, const PropertySlot& slot)
{
return getDOMConstructor<JSMessageChannelConstructor>(exec, static_cast<JSWorkerContext*>(asObject(slot.slotBase())));
}
JSValue* jsWorkerContextMessagePort(ExecState* exec, const Identifier&, const PropertySlot&)
{
return JSMessagePort::getConstructor(exec);
}
JSValue* jsWorkerContextWorkerLocation(ExecState* exec, const Identifier&, const PropertySlot&)
{
return JSWorkerLocation::getConstructor(exec);
}
static const HashTable* getJSWorkerContextPrototypeTable(ExecState* exec)
{
return getHashTableForGlobalData(exec->globalData(), &JSWorkerContextPrototypeTable);
}
const ClassInfo JSWorkerContextPrototype::s_info = { "WorkerContextPrototype", 0, 0, getJSWorkerContextPrototypeTable };
JSObject* JSWorkerContextPrototype::self(ExecState* exec)
{
return getDOMPrototype<JSWorkerContext>(exec);
}
bool JSWorkerContextPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
return getStaticFunctionSlot<JSObject>(exec, getJSWorkerContextPrototypeTable(exec), this, propertyName, slot);
}
void setJSWorkerContextMessageChannel(ExecState*, JSObject*, JSValue*)
{
// FIXME: Do we need to override put for global constructors, like JSDOMWindowBase does?
ASSERT_NOT_REACHED();
}
void setJSWorkerContextMessagePort(ExecState*, JSObject*, JSValue*)
{
ASSERT_NOT_REACHED();
}
void setJSWorkerContextWorkerLocation(ExecState*, JSObject*, JSValue*)
{
ASSERT_NOT_REACHED();
}
} // namespace WebCore
#endif // ENABLE(WORKERS)
/*
* Copyright (C) 2008 Apple 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 JSWorkerContext_h
#define JSWorkerContext_h
#if ENABLE(WORKERS)
#include "JSDOMGlobalObject.h"
namespace WebCore {
class WorkerContext;
class JSWorkerContext : public JSDOMGlobalObject {
typedef JSDOMGlobalObject Base;
public:
JSWorkerContext(PassRefPtr<WorkerContext>);
virtual ~JSWorkerContext();
static JSC::JSObject* createPrototype(JSC::ExecState*);
virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot&);
virtual const JSC::ClassInfo* classInfo() const { return &s_info; }
static const JSC::ClassInfo s_info;
static PassRefPtr<JSC::StructureID> createStructureID(JSC::JSValue* prototype)
{
return JSC::StructureID::create(prototype, JSC::TypeInfo(JSC::ObjectType));
}
WorkerContext* impl() const { return m_impl.get(); }
virtual ScriptExecutionContext* scriptExecutionContext() const;
virtual void mark();
private:
RefPtr<WorkerContext> m_impl;
};
class JSWorkerContextPrototype : public JSC::JSObject {
public:
static JSC::JSObject* self(JSC::ExecState*);
JSWorkerContextPrototype(PassRefPtr<JSC::StructureID> structure) : JSC::JSObject(structure) { }
virtual const JSC::ClassInfo* classInfo() const { return &s_info; }
static const JSC::ClassInfo s_info;
virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);
static PassRefPtr<JSC::StructureID> createStructureID(JSC::JSValue* prototype)
{
return JSC::StructureID::create(prototype, JSC::TypeInfo(JSC::ObjectType));
}
};
} // namespace WebCore
#endif // ENABLE(WORKERS)
#endif // JSWorkerContext_h
/*
* Copyright (C) 2008 Apple 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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(WORKERS)
#include "WorkerScriptController.h"
#include "JSWorkerContext.h"
#include "WorkerContext.h"
#include <kjs/SourceCode.h>
#include <runtime/Completion.h>
#include <runtime/Interpreter.h>
#include <runtime/JSLock.h>
using namespace JSC;
namespace WebCore {
WorkerScriptController::WorkerScriptController(WorkerContext* workerContext)
: m_globalData(JSGlobalData::create())
, m_workerContext(workerContext)
{
}
WorkerScriptController::~WorkerScriptController()
{
m_workerContextWrapper = 0; // Unprotect the global object.
ASSERT(!m_globalData->heap.protectedObjectCount());
ASSERT(!m_globalData->heap.isBusy());
m_globalData->heap.destroy();
}
void WorkerScriptController::initScript()
{
ASSERT(!m_workerContextWrapper);
JSLock lock(false);
m_workerContextWrapper = new (m_globalData.get()) JSWorkerContext(m_workerContext);
}
JSValue* WorkerScriptController::evaluate(const String& sourceURL, int baseLine, const String& code)
{
ExecState* exec = m_workerContextWrapper->globalExec();
m_workerContextWrapper->startTimeoutCheck();
Completion comp = Interpreter::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), makeSource(code, sourceURL, baseLine), m_workerContextWrapper);
m_workerContextWrapper->stopTimeoutCheck();
if (comp.complType() == Normal || comp.complType() == ReturnValue)
return comp.value();
// FIXME: send exceptions to console.
if (comp.complType() == Throw)
fprintf(stderr, "%s\n", comp.value()->toString(exec).UTF8String().c_str());
return noValue();
}
} // namespace WebCore
#endif // ENABLE(WORKERS)
/*
* Copyright (C) 2008 Apple 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 WorkerScriptController_h
#define WorkerScriptController_h
#if ENABLE(WORKERS)
#include <runtime/Protect.h>
#include <wtf/Noncopyable.h>
namespace JSC {
class JSGlobalData;
class JSValue;
}
namespace WebCore {
class JSWorkerContext;
class String;
class WorkerContext;
class WorkerScriptController : Noncopyable {
public:
WorkerScriptController(WorkerContext*);
~WorkerScriptController();
JSWorkerContext* workerContextWrapper()
{
initScriptIfNeeded();
return m_workerContextWrapper;
}
JSC::JSValue* evaluate(const String& sourceURL, int baseLine, const String& code);
private:
void initScriptIfNeeded()
{
if (!m_workerContext)
initScript();
}
void initScript();
RefPtr<JSC::JSGlobalData> m_globalData;
WorkerContext* m_workerContext;
JSC::ProtectedPtr<JSWorkerContext> m_workerContextWrapper;
};
} // namespace WebCore
#endif // ENABLE(WORKERS)
#endif // WorkerScriptController_h
......@@ -44,6 +44,7 @@
#include "SecurityOrigin.h"
#include "ScriptExecutionContext.h"
#include "Timer.h"
#include "WorkerThread.h"
#include <wtf/MainThread.h>
namespace WebCore {
......@@ -113,6 +114,11 @@ void DedicatedWorker::postMessage(const String& /*message*/, MessagePort* /*port
void DedicatedWorker::startLoad()
{
// The document may have been destroyed already.
// FIXME: Should we explicitly check whether the document has been detached, and cancel loading in that case?
if (!document())
return;
m_cachedScript = document()->docLoader()->requestScript(m_scriptURL, document()->charset());
if (m_cachedScript) {
......@@ -131,7 +137,7 @@ void DedicatedWorker::notifyFinished(CachedResource* resource)
dispatchErrorEvent();
unsetPendingActivity(this);
} else {
// Start the worker thread.
WorkerThread::create(m_scriptURL, m_cachedScript->script(), this)->start();
}
m_cachedScript->removeClient(this);
......
/*
* Copyright (C) 2008 Apple 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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(WORKERS)
#include "SecurityOrigin.h"
#include "WorkerContext.h"
#include "WorkerLocation.h"
namespace WebCore {
WorkerContext::WorkerContext(const KURL& url)
: m_url(url)
, m_location(WorkerLocation::create(url))
, m_securityOrigin(SecurityOrigin::create(url))
, m_script(this)
{
}
WorkerContext::~WorkerContext()
{
}
const KURL& WorkerContext::virtualURL() const
{
return m_url;
}
KURL WorkerContext::completeURL(const String& url) const
{
// Always return a null URL when passed a null string.
// FIXME: Should we change the KURL constructor to have this behavior?
if (url.isNull())
return KURL();
// FIXME: does this need to provide a charset, like Document::completeURL does?
return KURL(m_location->url(), url);
}
} // namespace WebCore
#endif // ENABLE(WORKERS)
/*
* Copyright (C) 2008 Apple 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:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. 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 WorkerContext_h
#define WorkerContext_h
#if ENABLE(WORKERS)
#include "KURL.h"
#include "ScriptExecutionContext.h"
#include "WorkerScriptController.h"
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class WorkerLocation;