[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.16-1409-g5afdf4d

dimich at chromium.org dimich at chromium.org
Thu Dec 3 13:44:19 UTC 2009


The following commit has been merged in the webkit-1.1 branch:
commit f54bd851a5ec9c1f8781ca21a91cb4a2ab321389
Author: dimich at chromium.org <dimich at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Nov 25 06:01:46 2009 +0000

    Initial implementation of WebKitSharedScript and SharedScriptContext
    https://bugs.webkit.org/show_bug.cgi?id=31569
    
    Reviewed by David Levin.
    
    No new tests since there are no bindings yet (soon to come).
    
    * DerivedSources.make: Add WebKitSharedScript and SharedScriptContext to a list of idl files.
    * WebCore.xcodeproj/project.pbxproj:
    * dom/Document.cpp:
    (WebCore::Document::detach): Notify WebKitSharedScriptRepository that document is detaching.
    * dom/EventTarget.cpp: Add new casting methods, since the new types are EventTargets.
    (WebCore::EventTarget::toWebKitSharedScript):
    (WebCore::EventTarget::toSharedScriptContext):
    * dom/EventTarget.h: Ditto
    * dom/ScriptExecutionContext.h:
    (WebCore::ScriptExecutionContext::isSharedScriptContext): New virtual method, since there is a new type of context.
    
    * SharedScript/SharedScriptContext.cpp: Added. Similar to WorkerContext, but w/o threading.
    (WebCore::SharedScriptContext::SharedScriptContext):
    (WebCore::SharedScriptContext::~SharedScriptContext):
    (WebCore::SharedScriptContext::clearScript):
    (WebCore::SharedScriptContext::virtualURL):
    (WebCore::SharedScriptContext::virtualCompleteURL):
    (WebCore::SharedScriptContext::reportException):
    (WebCore::SharedScriptContext::addMessage):
    (WebCore::SharedScriptContext::resourceRetrievedByXMLHttpRequest):
    (WebCore::SharedScriptContext::scriptImported):
    (WebCore::SharedScriptContext::matches):
    (WebCore::SharedScriptContext::addToDocumentsList):
    (WebCore::SharedScriptContext::destructionTimerFired):
    (WebCore::SharedScriptContext::removeFromDocumentList):
    (WebCore::SharedScriptContext::load):
    (WebCore::SharedScriptContext::postTask):
    (WebCore::SharedScriptContext::eventTargetData):
    (WebCore::SharedScriptContext::ensureEventTargetData):
    (WebCore::SharedScriptContext::scriptExecutionContext):
    * SharedScript/SharedScriptContext.h: Added.
    (WebCore::SharedScriptContext::create):
    (WebCore::SharedScriptContext::isSharedScriptContext):
    (WebCore::SharedScriptContext::userAgent):
    (WebCore::SharedScriptContext::toSharedScriptContext):
    (WebCore::SharedScriptContext::self):
    (WebCore::SharedScriptContext::script):
    (WebCore::SharedScriptContext::loaded):
    (WebCore::SharedScriptContext::name):
    (WebCore::SharedScriptContext::refEventTarget):
    (WebCore::SharedScriptContext::derefEventTarget):
    (WebCore::SharedScriptContext::refScriptExecutionContext):
    (WebCore::SharedScriptContext::derefScriptExecutionContext):
    * SharedScript/SharedScriptContext.idl: Added.
    
    * SharedScript/SharedScriptController.h:
    Added. Empty implementation of a ScriptController, will come later as part of bindings. Needed to compile.
    
    * SharedScript/WebKitSharedScript.cpp: Added. EventTarget-based DOM object.
    (WebCore::WebKitSharedScript::WebKitSharedScript):
    (WebCore::WebKitSharedScript::~WebKitSharedScript):
    (WebCore::WebKitSharedScript::setContext):
    (WebCore::LoadEventTask::create): Fires asynchronous 'load' event when underlying SharedScriptContext is initialized.
    (WebCore::LoadEventTask::performTask):
    (WebCore::LoadEventTask::LoadEventTask):
    (WebCore::WebKitSharedScript::scheduleLoadEvent):
    * SharedScript/WebKitSharedScript.h: Added.
    (WebCore::WebKitSharedScript::create):
    (WebCore::WebKitSharedScript::scriptExecutionContext):
    (WebCore::WebKitSharedScript::toWebKitSharedScript):
    (WebCore::WebKitSharedScript::context):
    (WebCore::WebKitSharedScript::refEventTarget):
    (WebCore::WebKitSharedScript::derefEventTarget):
    (WebCore::WebKitSharedScript::eventTargetData):
    (WebCore::WebKitSharedScript::ensureEventTargetData):
    * SharedScript/WebKitSharedScript.idl: Added.
    
    * SharedScript/WebKitSharedScriptRepository.cpp: Added. Implements a list of running SharedScriptContexts.
    (WebCore::ScriptLoader::ScriptLoader): The helper class to load an initial script of SharedScriptContext.
    (WebCore::ScriptLoader::load):
    (WebCore::ScriptLoader::notifyFinished):
    (WebCore::WebKitSharedScriptRepository::instance): Repository has a static global instance.
    (WebCore::WebKitSharedScriptRepository::connect):
    (WebCore::WebKitSharedScriptRepository::documentDetached): Called from Document::detach().
    (WebCore::WebKitSharedScriptRepository::removeSharedScriptContext): Called from ~SharedScriptContext().
    (WebCore::WebKitSharedScriptRepository::connectToSharedScript):
    (WebCore::WebKitSharedScriptRepository::getSharedScriptContext):
    * SharedScript/WebKitSharedScriptRepository.h: Added.
    (WebCore::WebKitSharedScriptRepository::WebKitSharedScriptRepository):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@51374 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 6475eee..feecb4a 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,5 +1,94 @@
 2009-11-24  Dmitry Titov  <dimich at chromium.org>
 
+        Reviewed by David Levin.
+
+        Initial implementation of WebKitSharedScript and SharedScriptContext
+        https://bugs.webkit.org/show_bug.cgi?id=31569
+
+        No new tests since there are no bindings yet (soon to come).
+
+        * DerivedSources.make: Add WebKitSharedScript and SharedScriptContext to a list of idl files.
+        * WebCore.xcodeproj/project.pbxproj:
+        * dom/Document.cpp:
+        (WebCore::Document::detach): Notify WebKitSharedScriptRepository that document is detaching.
+        * dom/EventTarget.cpp: Add new casting methods, since the new types are EventTargets.
+        (WebCore::EventTarget::toWebKitSharedScript):
+        (WebCore::EventTarget::toSharedScriptContext):
+        * dom/EventTarget.h: Ditto
+        * dom/ScriptExecutionContext.h:
+        (WebCore::ScriptExecutionContext::isSharedScriptContext): New virtual method, since there is a new type of context.
+
+        * SharedScript/SharedScriptContext.cpp: Added. Similar to WorkerContext, but w/o threading.
+        (WebCore::SharedScriptContext::SharedScriptContext):
+        (WebCore::SharedScriptContext::~SharedScriptContext):
+        (WebCore::SharedScriptContext::clearScript):
+        (WebCore::SharedScriptContext::virtualURL):
+        (WebCore::SharedScriptContext::virtualCompleteURL):
+        (WebCore::SharedScriptContext::reportException):
+        (WebCore::SharedScriptContext::addMessage):
+        (WebCore::SharedScriptContext::resourceRetrievedByXMLHttpRequest):
+        (WebCore::SharedScriptContext::scriptImported):
+        (WebCore::SharedScriptContext::matches):
+        (WebCore::SharedScriptContext::addToDocumentsList):
+        (WebCore::SharedScriptContext::destructionTimerFired):
+        (WebCore::SharedScriptContext::removeFromDocumentList):
+        (WebCore::SharedScriptContext::load):
+        (WebCore::SharedScriptContext::postTask):
+        (WebCore::SharedScriptContext::eventTargetData):
+        (WebCore::SharedScriptContext::ensureEventTargetData):
+        (WebCore::SharedScriptContext::scriptExecutionContext):
+        * SharedScript/SharedScriptContext.h: Added.
+        (WebCore::SharedScriptContext::create):
+        (WebCore::SharedScriptContext::isSharedScriptContext):
+        (WebCore::SharedScriptContext::userAgent):
+        (WebCore::SharedScriptContext::toSharedScriptContext):
+        (WebCore::SharedScriptContext::self):
+        (WebCore::SharedScriptContext::script):
+        (WebCore::SharedScriptContext::loaded):
+        (WebCore::SharedScriptContext::name):
+        (WebCore::SharedScriptContext::refEventTarget):
+        (WebCore::SharedScriptContext::derefEventTarget):
+        (WebCore::SharedScriptContext::refScriptExecutionContext):
+        (WebCore::SharedScriptContext::derefScriptExecutionContext):
+        * SharedScript/SharedScriptContext.idl: Added.
+
+        * SharedScript/SharedScriptController.h: 
+        Added. Empty implementation of a ScriptController, will come later as part of bindings. Needed to compile.
+
+        * SharedScript/WebKitSharedScript.cpp: Added. EventTarget-based DOM object.
+        (WebCore::WebKitSharedScript::WebKitSharedScript):
+        (WebCore::WebKitSharedScript::~WebKitSharedScript):
+        (WebCore::WebKitSharedScript::setContext):
+        (WebCore::LoadEventTask::create): Fires asynchronous 'load' event when underlying SharedScriptContext is initialized.
+        (WebCore::LoadEventTask::performTask):
+        (WebCore::LoadEventTask::LoadEventTask):
+        (WebCore::WebKitSharedScript::scheduleLoadEvent):
+        * SharedScript/WebKitSharedScript.h: Added.
+        (WebCore::WebKitSharedScript::create):
+        (WebCore::WebKitSharedScript::scriptExecutionContext):
+        (WebCore::WebKitSharedScript::toWebKitSharedScript):
+        (WebCore::WebKitSharedScript::context):
+        (WebCore::WebKitSharedScript::refEventTarget):
+        (WebCore::WebKitSharedScript::derefEventTarget):
+        (WebCore::WebKitSharedScript::eventTargetData):
+        (WebCore::WebKitSharedScript::ensureEventTargetData):
+        * SharedScript/WebKitSharedScript.idl: Added.
+
+        * SharedScript/WebKitSharedScriptRepository.cpp: Added. Implements a list of running SharedScriptContexts.
+        (WebCore::ScriptLoader::ScriptLoader): The helper class to load an initial script of SharedScriptContext.
+        (WebCore::ScriptLoader::load):
+        (WebCore::ScriptLoader::notifyFinished):
+        (WebCore::WebKitSharedScriptRepository::instance): Repository has a static global instance.
+        (WebCore::WebKitSharedScriptRepository::connect):
+        (WebCore::WebKitSharedScriptRepository::documentDetached): Called from Document::detach().
+        (WebCore::WebKitSharedScriptRepository::removeSharedScriptContext): Called from ~SharedScriptContext().
+        (WebCore::WebKitSharedScriptRepository::connectToSharedScript):
+        (WebCore::WebKitSharedScriptRepository::getSharedScriptContext):
+        * SharedScript/WebKitSharedScriptRepository.h: Added.
+        (WebCore::WebKitSharedScriptRepository::WebKitSharedScriptRepository):
+
+2009-11-24  Dmitry Titov  <dimich at chromium.org>
+
         Reviewed by Eric Seidel.
 
         Add ENABLE_SHARED_SCRIPT feature define and flag for build-webkit
diff --git a/WebCore/DerivedSources.make b/WebCore/DerivedSources.make
index 5844609..3d7636f 100644
--- a/WebCore/DerivedSources.make
+++ b/WebCore/DerivedSources.make
@@ -39,6 +39,7 @@ VPATH = \
     $(WebCore)/notifications \
     $(WebCore)/page \
     $(WebCore)/plugins \
+    $(WebCore)/SharedScript \
     $(WebCore)/storage \
     $(WebCore)/xml \
     $(WebCore)/wml \
@@ -232,6 +233,7 @@ DOM_CLASSES = \
     Range \
     RangeException \
     Rect \
+    SharedScriptContext \
     SharedWorker \
     SharedWorkerContext \
     SQLError \
@@ -400,6 +402,7 @@ DOM_CLASSES = \
     WebKitCSSKeyframesRule \
     WebKitCSSMatrix \
     WebKitCSSTransformValue \
+    WebKitSharedScript \
     WebKitPoint \
     WebKitTransitionEvent \
     WebSocket \
diff --git a/WebCore/SharedScript/SharedScriptContext.cpp b/WebCore/SharedScript/SharedScriptContext.cpp
new file mode 100644
index 0000000..2ef9be4
--- /dev/null
+++ b/WebCore/SharedScript/SharedScriptContext.cpp
@@ -0,0 +1,188 @@
+/*
+ * 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(SHARED_SCRIPT)
+
+#include "SharedScriptContext.h"
+#include "Event.h"
+#include "EventException.h"
+#include "NotImplemented.h"
+#include "ScriptSourceCode.h"
+#include "ScriptValue.h"
+#include "SecurityOrigin.h"
+#include "SharedScriptController.h"
+#include "WebKitSharedScriptRepository.h"
+
+namespace WebCore {
+
+SharedScriptContext::SharedScriptContext(const String& name, const KURL& url, PassRefPtr<SecurityOrigin> origin)
+    : m_name(name)
+    , m_url(url)
+    , m_script(new SharedScriptController(this))
+    , m_destructionTimer(this, &SharedScriptContext::destructionTimerFired)
+    , m_loaded(false)
+{
+    setSecurityOrigin(origin);
+    ref(); // Matching deref is in destructionTimerFired callback.
+}
+
+void SharedScriptContext::clearScript()
+{
+    m_script.clear(); 
+}
+
+const KURL& SharedScriptContext::virtualURL() const
+{
+    return m_url;
+}
+
+KURL SharedScriptContext::virtualCompleteURL(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();
+    // Always use UTF-8 in Workers.
+    return KURL(m_url, url);
+}
+
+void SharedScriptContext::reportException(const String& errorMessage, int lineNumber, const String& sourceURL)
+{
+    bool errorHandled = false;
+    if (onerror())
+        errorHandled = onerror()->reportError(this, errorMessage, sourceURL, lineNumber);
+}
+
+void SharedScriptContext::addMessage(MessageDestination destination, MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL)
+{
+    // FIXME: figure out console/inspector story for SharedScript. Maybe similar to SharedWorkers.
+    UNUSED_PARAM(destination);
+    UNUSED_PARAM(source);
+    UNUSED_PARAM(type);
+    UNUSED_PARAM(level);
+    UNUSED_PARAM(message);
+    UNUSED_PARAM(lineNumber);
+    UNUSED_PARAM(sourceURL);
+    notImplemented();
+}
+
+void SharedScriptContext::resourceRetrievedByXMLHttpRequest(unsigned long, const ScriptString&)
+{
+    // FIXME: figure out console/inspector story for SharedScript. Maybe similar to SharedWorkers.
+    notImplemented();
+}
+
+void SharedScriptContext::scriptImported(unsigned long, const String&)
+{
+    // FIXME: figure out console/inspector story for SharedScript. Maybe similar to SharedWorkers.
+    notImplemented();
+}
+
+bool SharedScriptContext::matches(const String& name, const SecurityOrigin& origin, const KURL& urlToMatch) const
+{
+    // If the origins don't match, or the names don't match, then this is not the context we are looking for.
+    if (!origin.equal(securityOrigin()))
+        return false;
+
+    // If the names are both empty, compares the URLs instead.
+    if (name.isEmpty() && m_name.isEmpty())
+        return urlToMatch == m_url;
+
+    return name == m_name;
+}
+
+void SharedScriptContext::addToDocumentsList(Document* document)
+{
+    m_documentList.add(document);
+
+    if (m_destructionTimer.isActive())
+        m_destructionTimer.stop();
+}
+
+void SharedScriptContext::destructionTimerFired(Timer<SharedScriptContext>*)
+{
+    if (!m_documentList.size()) {
+        WebKitSharedScriptRepository::removeSharedScriptContext(this);
+        stopActiveDOMObjects();
+        clearScript();
+        deref();
+    }
+}
+
+void SharedScriptContext::removeFromDocumentList(Document* document)
+{
+    HashSet<Document*>::iterator it = m_documentList.find(document);
+    if (it == m_documentList.end())
+        return;
+
+    m_documentList.remove(it);
+
+    // The use of a timer makes destruction of the context happen later to
+    // avoid deallocating it right now while it is notified.
+    // The context can gain a new owner by the time the timer is fired.
+    if (!m_documentList.size())
+        m_destructionTimer.startOneShot(0);
+}
+
+void SharedScriptContext::load(const String& userAgent, const String& initialScript)
+{
+    m_userAgent = userAgent;
+    script()->evaluate(ScriptSourceCode(initialScript, m_url));
+    m_loaded = true;
+}
+
+void SharedScriptContext::postTask(PassOwnPtr<Task> task)
+{
+    // FIXME: Need to implement ScriptExecutionContext::postTaskToMainThread to share between Document and SharedScriptContext.
+    UNUSED_PARAM(task);
+    notImplemented();
+}
+
+EventTargetData* SharedScriptContext::eventTargetData()
+{
+    return &m_eventTargetData;
+}
+
+EventTargetData* SharedScriptContext::ensureEventTargetData()
+{
+    return &m_eventTargetData;
+}
+
+ScriptExecutionContext* SharedScriptContext::scriptExecutionContext() const
+{
+    return const_cast<SharedScriptContext*>(this);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SHARED_SCRIPT)
+
diff --git a/WebCore/SharedScript/SharedScriptContext.h b/WebCore/SharedScript/SharedScriptContext.h
new file mode 100644
index 0000000..6103c5d
--- /dev/null
+++ b/WebCore/SharedScript/SharedScriptContext.h
@@ -0,0 +1,126 @@
+/*
+ * 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 SharedScriptContext_h
+#define SharedScriptContext_h
+
+#if ENABLE(SHARED_SCRIPT)
+
+#include "EventTarget.h"
+#include "SecurityOrigin.h"
+#include "SharedScriptController.h"
+#include "Timer.h"
+#include "WorkerContext.h"
+#include <wtf/HashSet.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class Document;
+class KURL;
+class String;
+
+class SharedScriptContext : public RefCounted<SharedScriptContext>, public ScriptExecutionContext, public EventTarget {
+public:
+    static PassRefPtr<SharedScriptContext> create(const String& name, const KURL& url, PassRefPtr<SecurityOrigin> origin)
+    {
+        return adoptRef(new SharedScriptContext(name, url, origin));
+    }
+
+    // ScriptExecutionContext
+    virtual bool isSharedScriptContext() const { return true; }
+    virtual String userAgent(const KURL&) const { return m_userAgent; }
+
+    virtual void reportException(const String& errorMessage, int lineNumber, const String& sourceURL);
+    virtual void addMessage(MessageDestination, MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL);
+    virtual void resourceRetrievedByXMLHttpRequest(unsigned long identifier, const ScriptString& sourceString);
+    virtual void scriptImported(unsigned long, const String&);
+    virtual void postTask(PassOwnPtr<Task>); // Executes the task on context's thread asynchronously.
+
+    // JS wrapper and EventTarget support.
+    virtual ScriptExecutionContext* scriptExecutionContext() const;
+    virtual SharedScriptContext* toSharedScriptContext() { return this; }
+    DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
+
+    // SharedScriptGlobalScope
+    SharedScriptContext* self() { return this; }
+
+    // Lifetime - keep the list of documents that are connected, deref when the last disconnects.
+    void addToDocumentsList(Document*);
+    void removeFromDocumentList(Document*);
+
+    SharedScriptController* script() { return m_script.get(); }
+    void clearScript();
+
+    bool loaded() { return m_loaded; }
+    void load(const String& userAgent, const String& initialScript);
+
+    bool matches(const String& name, const SecurityOrigin&, const KURL&) const;
+    String name() const { return m_name; }
+
+    using RefCounted<SharedScriptContext>::ref;
+    using RefCounted<SharedScriptContext>::deref;
+
+protected:
+    SharedScriptContext(const String& name, const KURL&, PassRefPtr<SecurityOrigin>);
+
+private:
+    // EventTarget
+    virtual EventTargetData* eventTargetData();
+    virtual EventTargetData* ensureEventTargetData();
+    virtual void refEventTarget() { ref(); }
+    virtual void derefEventTarget() { deref(); }
+    
+    // ScriptExecutionContext
+    virtual const KURL& virtualURL() const;
+    virtual KURL virtualCompleteURL(const String&) const;
+    virtual void refScriptExecutionContext() { ref(); }
+    virtual void derefScriptExecutionContext() { deref(); }
+            
+    void destructionTimerFired(Timer<SharedScriptContext>*);
+            
+    String m_name;
+    String m_userAgent;
+    KURL m_url;
+    OwnPtr<SharedScriptController> m_script;
+    HashSet<Document*> m_documentList;
+    Timer<SharedScriptContext> m_destructionTimer;
+    EventTargetData m_eventTargetData;
+
+    bool m_loaded;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SHARED_SCRIPT)
+
+#endif // SharedScriptContext_h
+
diff --git a/WebCore/SharedScript/SharedScriptContext.idl b/WebCore/SharedScript/SharedScriptContext.idl
new file mode 100644
index 0000000..811ffca
--- /dev/null
+++ b/WebCore/SharedScript/SharedScriptContext.idl
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+module window {
+
+    interface [
+        Conditional=SHARED_SCRIPT,
+        CustomMarkFunction,
+        EventTarget,
+        ExtendsDOMGlobalObject,
+        IsWorkerContext,
+        GenerateNativeConverter,
+        LegacyParent=JSSharedScriptContextBase,
+        NoStaticTables
+    ] SharedScriptContext {
+
+#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
+        attribute [Replaceable] SharedScriptContext self;
+#endif
+
+        readonly attribute DOMString name;
+        attribute EventListener onerror;
+
+        // EventTarget interface
+        [Custom] void addEventListener(in DOMString type, 
+                                       in EventListener listener, 
+                                       in boolean useCapture);
+        [Custom] void removeEventListener(in DOMString type, 
+                                          in EventListener listener, 
+                                          in boolean useCapture);
+        boolean dispatchEvent(in Event evt)
+            raises(EventException);
+
+    };
+
+}
diff --git a/WebCore/SharedScript/SharedScriptController.h b/WebCore/SharedScript/SharedScriptController.h
new file mode 100644
index 0000000..cc3e445
--- /dev/null
+++ b/WebCore/SharedScript/SharedScriptController.h
@@ -0,0 +1,57 @@
+/*
+ * 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 SharedScriptController_h
+#define SharedScriptController_h
+
+#if ENABLE(SHARED_SCRIPT)
+
+// Non-functioning ScriptController. Will be implemented with corresponding bindings (since it's JSC- and V8-dependant).
+
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+    class SharedScriptContext;
+    class ScriptSourceCode;
+
+    class SharedScriptController : public Noncopyable {
+    public:
+        SharedScriptController(SharedScriptContext*) { }
+        ~SharedScriptController() { }
+
+        void evaluate(const ScriptSourceCode&) { }
+    };
+
+} // namespace WebCore
+
+#endif // ENABLE(SHARED_SCRIPT)
+
+#endif // SharedScriptController_h
diff --git a/WebCore/SharedScript/WebKitSharedScript.cpp b/WebCore/SharedScript/WebKitSharedScript.cpp
new file mode 100644
index 0000000..3cdac91
--- /dev/null
+++ b/WebCore/SharedScript/WebKitSharedScript.cpp
@@ -0,0 +1,117 @@
+/*
+ * 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(SHARED_SCRIPT)
+
+#include "WebKitSharedScript.h"
+
+#include "Event.h"
+#include "EventException.h"
+#include "ScriptExecutionContext.h"
+#include "SecurityOrigin.h"
+#include "SharedScriptContext.h"
+#include "WebKitSharedScriptRepository.h"
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+WebKitSharedScript::WebKitSharedScript(const String& url, const String& name, ScriptExecutionContext* context, ExceptionCode& ec)
+    : ActiveDOMObject(context, this)
+{
+    if (url.isEmpty()) {
+        ec = SYNTAX_ERR;
+        return;
+    }
+
+    // FIXME: This should use the dynamic global scope (bug #27887).
+    KURL scriptURL = context->completeURL(url);
+    if (!scriptURL.isValid()) {
+        ec = SYNTAX_ERR;
+        return;
+    }
+
+    if (!context->securityOrigin()->canAccess(SecurityOrigin::create(scriptURL).get())) {
+        ec = SECURITY_ERR;
+        return;
+    }
+
+    WebKitSharedScriptRepository::connect(this, scriptURL, name, ec);
+}
+
+WebKitSharedScript::~WebKitSharedScript()
+{
+}
+
+void WebKitSharedScript::setContext(PassRefPtr<SharedScriptContext> context)
+{ 
+    m_innerContext = context;
+}
+
+class LoadEventTask : public ScriptExecutionContext::Task {
+public:
+    static PassOwnPtr<LoadEventTask> create(PassRefPtr<WebKitSharedScript> sharedScript, PassRefPtr<SharedScriptContext> innerContext)
+    {
+        return new LoadEventTask(sharedScript, innerContext);
+    }
+
+    virtual void performTask(ScriptExecutionContext* context)
+    {
+        ASSERT_UNUSED(context, context->isDocument());
+        m_sharedScript->setContext(m_innerContext);
+        m_sharedScript->dispatchEvent(Event::create(EventNames().loadEvent, false, false));
+
+        m_sharedScript->unsetPendingActivity(m_sharedScript.get());
+    }
+
+private:
+    LoadEventTask(PassRefPtr<WebKitSharedScript> sharedScript, PassRefPtr<SharedScriptContext> innerContext)
+        : m_sharedScript(sharedScript)
+        , m_innerContext(innerContext)
+    {
+        // Keep event listeners alive.
+        m_sharedScript->setPendingActivity(m_sharedScript.get());
+    }
+
+    RefPtr<WebKitSharedScript> m_sharedScript;
+    RefPtr<SharedScriptContext> m_innerContext;
+};
+
+void WebKitSharedScript::scheduleLoadEvent(PassRefPtr<SharedScriptContext> innerContext)
+{
+    ASSERT(!m_innerContext);
+    scriptExecutionContext()->postTask(LoadEventTask::create(this, innerContext));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SHARED_SCRIPT)
+
diff --git a/WebCore/SharedScript/WebKitSharedScript.h b/WebCore/SharedScript/WebKitSharedScript.h
new file mode 100644
index 0000000..4d9d476
--- /dev/null
+++ b/WebCore/SharedScript/WebKitSharedScript.h
@@ -0,0 +1,91 @@
+/*
+ * 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 WebKitSharedScript_h
+#define WebKitSharedScript_h
+
+#if ENABLE(SHARED_SCRIPT)
+
+#include "ActiveDOMObject.h"
+#include "AtomicStringHash.h"
+#include "EventListener.h"
+#include "EventTarget.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+    class KURL;
+    class SharedScriptContext;
+    class ScriptExecutionContext;
+
+    class WebKitSharedScript : public RefCounted<WebKitSharedScript>, public ActiveDOMObject, public EventTarget {
+    public:
+        static PassRefPtr<WebKitSharedScript> create(const String& url, const String& name, ScriptExecutionContext* context, ExceptionCode& ec)
+        {
+            return adoptRef(new WebKitSharedScript(url, name, context, ec));
+        }
+        virtual ~WebKitSharedScript();
+
+        // EventTarget APIs
+        virtual ScriptExecutionContext* scriptExecutionContext() const { return ActiveDOMObject::scriptExecutionContext(); }
+        virtual WebKitSharedScript* toWebKitSharedScript() { return this; }
+
+        DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
+        DEFINE_ATTRIBUTE_EVENT_LISTENER(load);
+
+        using RefCounted<WebKitSharedScript>::ref;
+        using RefCounted<WebKitSharedScript>::deref;
+
+        SharedScriptContext* context() const { return m_innerContext.get(); }
+        void setContext(PassRefPtr<SharedScriptContext> context);
+
+        // When fired, this will set the innerContext into this WebKitSharedScript and dispatch 'load' event.
+        void scheduleLoadEvent(PassRefPtr<SharedScriptContext> innerContext);
+
+    private:
+        WebKitSharedScript(const String& url, const String& name, ScriptExecutionContext*, ExceptionCode&);
+
+        virtual void refEventTarget() { ref(); }
+        virtual void derefEventTarget() { deref(); }
+        virtual EventTargetData* eventTargetData() { return &m_eventTargetData; }
+        virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData; }
+
+        EventTargetData m_eventTargetData;
+        RefPtr<SharedScriptContext> m_innerContext;
+    };
+
+} // namespace WebCore
+
+#endif // ENABLE(SHARED_SCRIPT)
+
+#endif // WebKitSharedScript_h
+
diff --git a/WebCore/SharedScript/WebKitSharedScript.idl b/WebCore/SharedScript/WebKitSharedScript.idl
new file mode 100644
index 0000000..7934508
--- /dev/null
+++ b/WebCore/SharedScript/WebKitSharedScript.idl
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+module window {
+
+    interface [
+        Conditional=SHARED_SCRIPT,
+        EventTarget,
+        GenerateToJS
+    ] WebKitSharedScript {
+
+        attribute EventListener onerror;
+        attribute EventListener onload;
+
+        // EventTarget interface
+        [Custom] void addEventListener(in DOMString type,
+                                       in EventListener listener,
+                                       in boolean useCapture);
+        [Custom] void removeEventListener(in DOMString type,
+                                          in EventListener listener,
+                                          in boolean useCapture);
+        boolean dispatchEvent(in Event evt)
+            raises(EventException);
+
+        readonly attribute SharedScriptContext context;
+    };
+}
diff --git a/WebCore/SharedScript/WebKitSharedScriptRepository.cpp b/WebCore/SharedScript/WebKitSharedScriptRepository.cpp
new file mode 100644
index 0000000..e233218
--- /dev/null
+++ b/WebCore/SharedScript/WebKitSharedScriptRepository.cpp
@@ -0,0 +1,176 @@
+/*
+ * 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(SHARED_SCRIPT)
+
+#include "WebKitSharedScriptRepository.h"
+
+#include "ActiveDOMObject.h"
+#include "Document.h"
+#include "Event.h"
+#include "EventNames.h"
+#include "ExceptionCode.h"
+#include "SecurityOrigin.h"
+#include "SharedScriptContext.h"
+#include "WebKitSharedScript.h"
+#include "WorkerScriptLoader.h"
+#include "WorkerScriptLoaderClient.h"
+#include <wtf/HashSet.h>
+#include <wtf/StdLibExtras.h>
+
+namespace WebCore {
+
+// Helper class to load the initial script on behalf of a SharedScript.
+class SharedScriptLoader : public RefCounted<SharedScriptLoader>, public ActiveDOMObject, private WorkerScriptLoaderClient {
+public:
+    static PassRefPtr<SharedScriptLoader> create(PassRefPtr<WebKitSharedScript> sharedScript, PassRefPtr<SharedScriptContext> innerContext)
+    {
+        return adoptRef(new SharedScriptLoader(sharedScript, innerContext));
+    }
+
+    void load(const KURL&);
+
+private:
+    SharedScriptLoader(PassRefPtr<WebKitSharedScript>, PassRefPtr<SharedScriptContext>);
+    // WorkerScriptLoaderClient callback
+    virtual void notifyFinished();
+
+    RefPtr<WebKitSharedScript> m_sharedScript;
+    RefPtr<SharedScriptContext> m_innerContext;
+    OwnPtr<WorkerScriptLoader> m_scriptLoader;
+};
+
+SharedScriptLoader::SharedScriptLoader(PassRefPtr<WebKitSharedScript> sharedScript, PassRefPtr<SharedScriptContext> innerContext)
+    : ActiveDOMObject(sharedScript->scriptExecutionContext(), this)
+    , m_sharedScript(sharedScript)
+    , m_innerContext(innerContext)
+{
+}
+
+void SharedScriptLoader::load(const KURL& url)
+{
+    // Mark this object as active for the duration of the load.
+    ASSERT(!hasPendingActivity());
+    m_scriptLoader = new WorkerScriptLoader();
+    m_scriptLoader->loadAsynchronously(scriptExecutionContext(), url, DenyCrossOriginRequests, this);
+
+    // Stay alive until the load finishes.
+    setPendingActivity(this);
+    m_sharedScript->setPendingActivity(m_sharedScript.get());
+}
+
+void SharedScriptLoader::notifyFinished()
+{
+    if (m_scriptLoader->failed())
+        m_sharedScript->dispatchEvent(Event::create(eventNames().errorEvent, false, true));
+    else {
+        // If another loader has not yet initialized the SharedScriptContext, do so.
+        if (!m_innerContext->loaded())
+            m_innerContext->load(scriptExecutionContext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script());
+    
+        m_sharedScript->scheduleLoadEvent(m_innerContext);
+    }
+
+    m_sharedScript->unsetPendingActivity(m_sharedScript.get());
+    unsetPendingActivity(this); // This frees this object so it must be the last action in this function.
+}
+
+WebKitSharedScriptRepository& WebKitSharedScriptRepository::instance()
+{
+    DEFINE_STATIC_LOCAL(WebKitSharedScriptRepository, instance, ());
+    return instance;
+}
+
+void WebKitSharedScriptRepository::connect(PassRefPtr<WebKitSharedScript> sharedScript, const KURL& url, const String& name, ExceptionCode& ec)
+{
+    instance().connectToSharedScript(sharedScript, url, name, ec);
+}
+
+void WebKitSharedScriptRepository::documentDetached(Document* document)
+{
+    WebKitSharedScriptRepository& repository = instance();
+    for (unsigned i = 0; i < repository.m_sharedScriptContexts.size(); i++)
+        repository.m_sharedScriptContexts[i]->removeFromDocumentList(document);
+}
+
+void WebKitSharedScriptRepository::removeSharedScriptContext(SharedScriptContext* context)
+{
+    WebKitSharedScriptRepository& repository = instance();
+    for (unsigned i = 0; i < repository.m_sharedScriptContexts.size(); i++) {
+        if (context == repository.m_sharedScriptContexts[i]) {
+            repository.m_sharedScriptContexts.remove(i);
+            return;
+        }
+    }
+}
+
+void WebKitSharedScriptRepository::connectToSharedScript(PassRefPtr<WebKitSharedScript> sharedScript, const KURL& url, const String& name, ExceptionCode& ec)
+{
+    ASSERT(sharedScript->scriptExecutionContext()->securityOrigin()->canAccess(SecurityOrigin::create(url).get()));
+    RefPtr<SharedScriptContext> innerContext = getSharedScriptContext(name, url);
+
+    if (innerContext->url() != url) {
+        // SharedScript with same name but different URL already exists - return an error.
+        ec = URL_MISMATCH_ERR;
+        return;
+    }
+
+    ASSERT(sharedScript->scriptExecutionContext()->isDocument());
+    innerContext->addToDocumentsList(static_cast<Document*>(sharedScript->scriptExecutionContext()));
+
+    // If SharedScriptContext is already running, just schedule a load event - otherwise, kick off a loader to load the script.
+    if (innerContext->loaded())
+        sharedScript->scheduleLoadEvent(innerContext);
+    else {
+        RefPtr<SharedScriptLoader> loader = SharedScriptLoader::create(sharedScript, innerContext.release());
+        loader->load(url); // Pending activity will keep the loader alive.
+    }
+}
+
+// Creates a new SharedScriptContext or returns an existing one from the repository.
+PassRefPtr<SharedScriptContext> WebKitSharedScriptRepository::getSharedScriptContext(const String& name, const KURL& url)
+{
+    RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url);
+    for (unsigned i = 0; i < m_sharedScriptContexts.size(); i++) {
+        if (m_sharedScriptContexts[i]->matches(name, *origin, url))
+            return m_sharedScriptContexts[i];
+    }
+
+    RefPtr<SharedScriptContext> sharedScriptContext = SharedScriptContext::create(name, url, origin.release());
+    m_sharedScriptContexts.append(sharedScriptContext.get());
+    return sharedScriptContext.release();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SHARED_SCRIPT)
+
diff --git a/WebCore/SharedScript/WebKitSharedScriptRepository.h b/WebCore/SharedScript/WebKitSharedScriptRepository.h
new file mode 100644
index 0000000..17c60d0
--- /dev/null
+++ b/WebCore/SharedScript/WebKitSharedScriptRepository.h
@@ -0,0 +1,76 @@
+/*
+ * 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 WebKitSharedScriptRepository_h
+#define WebKitSharedScriptRepository_h
+
+#if ENABLE(SHARED_SCRIPT)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+typedef int ExceptionCode;
+
+class Document;
+class KURL;
+class SharedScriptContext;
+class String;
+class WebKitSharedScript;
+
+// Interface to a repository which manages references to the set of active SharedScriptContexts.
+class WebKitSharedScriptRepository {
+public:
+    // Connects the passed WebKitSharedScript object with a SharedScriptContext, creating a new one if necessary.
+    static void connect(PassRefPtr<WebKitSharedScript>, const KURL&, const String& name, ExceptionCode&);
+
+    static void removeSharedScriptContext(SharedScriptContext*);
+    static void documentDetached(Document*);
+
+private:
+    WebKitSharedScriptRepository() { }
+    static WebKitSharedScriptRepository& instance();
+    void connectToSharedScript(PassRefPtr<WebKitSharedScript>, const KURL&, const String& name, ExceptionCode&);
+    PassRefPtr<SharedScriptContext> getSharedScriptContext(const String& name, const KURL&);
+
+    // List of SharedScriptContexts.
+    // Expectation is that there will be a limited number of SharedScriptContexts, and so tracking them in a Vector is more efficient than nested HashMaps.
+    typedef Vector<SharedScriptContext*> SharedScriptContextList;
+    SharedScriptContextList m_sharedScriptContexts;
+
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SHARED_SCRIPT)
+
+#endif // WebKitSharedScriptRepository_h
+
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index 63144d0..be65836 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -41924,6 +41924,38 @@
 			</Filter>
 		</Filter>
 		<Filter
+			Name="SharedScript"
+			>
+			<File
+				RelativePath="..\SharedScript\SharedScriptContext.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\SharedScript\SharedScriptContext.h"
+				>
+			</File>
+			<File
+				RelativePath="..\SharedScript\SharedScriptController.h"
+				>
+			</File>
+			<File
+				RelativePath="..\SharedScript\WebKitSharedScript.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\SharedScript\WebKitSharedScript.h"
+				>
+			</File>
+			<File
+				RelativePath="..\SharedScript\WebKitSharedScriptRepository.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\SharedScript\WebKitSharedScriptRepository.h"
+				>
+			</File>
+		</Filter>
+		<Filter
 			Name="storage"
 			>
 			<File
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 549ddf6..981b35b 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -242,6 +242,14 @@
 		185BCF290F3279CE000EA262 /* ThreadTimers.h in Headers */ = {isa = PBXBuildFile; fileRef = 185BCF270F3279CE000EA262 /* ThreadTimers.h */; };
 		188604B30F2E654A000B6443 /* DOMTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 188604B10F2E654A000B6443 /* DOMTimer.cpp */; };
 		188604B40F2E654A000B6443 /* DOMTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 188604B20F2E654A000B6443 /* DOMTimer.h */; };
+		18C5FCA510A3991F0048438D /* WebKitSharedScript.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18C5FCA010A3991F0048438D /* WebKitSharedScript.cpp */; };
+		18C5FCA610A3991F0048438D /* WebKitSharedScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 18C5FCA110A3991F0048438D /* WebKitSharedScript.h */; };
+		18C5FCA710A3991F0048438D /* WebKitSharedScript.idl in Resources */ = {isa = PBXBuildFile; fileRef = 18C5FCA210A3991F0048438D /* WebKitSharedScript.idl */; };
+		18C5FCA810A3991F0048438D /* WebKitSharedScriptRepository.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18C5FCA310A3991F0048438D /* WebKitSharedScriptRepository.cpp */; };
+		18C5FCA910A3991F0048438D /* WebKitSharedScriptRepository.h in Headers */ = {isa = PBXBuildFile; fileRef = 18C5FCA410A3991F0048438D /* WebKitSharedScriptRepository.h */; };
+		18C5FCB710A3C6F20048438D /* SharedScriptContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18C5FCB410A3C6F20048438D /* SharedScriptContext.cpp */; };
+		18C5FCB810A3C6F20048438D /* SharedScriptContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 18C5FCB510A3C6F20048438D /* SharedScriptContext.h */; };
+		18C5FCB910A3C6F20048438D /* SharedScriptContext.idl in Resources */ = {isa = PBXBuildFile; fileRef = 18C5FCB610A3C6F20048438D /* SharedScriptContext.idl */; };
 		18F831B80FD48C7800D8C56B /* WorkerLoaderProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 18F831B70FD48C7800D8C56B /* WorkerLoaderProxy.h */; };
 		1A0D57360A5C77FE007EDD4C /* OverflowEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A0D57340A5C77FE007EDD4C /* OverflowEvent.cpp */; };
 		1A0D57370A5C77FE007EDD4C /* OverflowEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A0D57350A5C77FE007EDD4C /* OverflowEvent.h */; };
@@ -5432,6 +5440,14 @@
 		185BCF270F3279CE000EA262 /* ThreadTimers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadTimers.h; sourceTree = "<group>"; };
 		188604B10F2E654A000B6443 /* DOMTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMTimer.cpp; sourceTree = "<group>"; };
 		188604B20F2E654A000B6443 /* DOMTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMTimer.h; sourceTree = "<group>"; };
+		18C5FCA010A3991F0048438D /* WebKitSharedScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitSharedScript.cpp; sourceTree = "<group>"; };
+		18C5FCA110A3991F0048438D /* WebKitSharedScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitSharedScript.h; sourceTree = "<group>"; };
+		18C5FCA210A3991F0048438D /* WebKitSharedScript.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebKitSharedScript.idl; sourceTree = "<group>"; };
+		18C5FCA310A3991F0048438D /* WebKitSharedScriptRepository.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitSharedScriptRepository.cpp; sourceTree = "<group>"; };
+		18C5FCA410A3991F0048438D /* WebKitSharedScriptRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitSharedScriptRepository.h; sourceTree = "<group>"; };
+		18C5FCB410A3C6F20048438D /* SharedScriptContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedScriptContext.cpp; sourceTree = "<group>"; };
+		18C5FCB510A3C6F20048438D /* SharedScriptContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedScriptContext.h; sourceTree = "<group>"; };
+		18C5FCB610A3C6F20048438D /* SharedScriptContext.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SharedScriptContext.idl; sourceTree = "<group>"; };
 		18F831B70FD48C7800D8C56B /* WorkerLoaderProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WorkerLoaderProxy.h; path = workers/WorkerLoaderProxy.h; sourceTree = "<group>"; };
 		1A0D57340A5C77FE007EDD4C /* OverflowEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = OverflowEvent.cpp; sourceTree = "<group>"; };
 		1A0D57350A5C77FE007EDD4C /* OverflowEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = OverflowEvent.h; sourceTree = "<group>"; };
@@ -10062,6 +10078,7 @@
 				BCF1A5BA097832090061A123 /* platform */,
 				5DCF83690D59157800953BC6 /* plugins */,
 				F523D2F302DE443B018635CA /* rendering */,
+				18C5FC9F10A3991F0048438D /* SharedScript */,
 				1AE82EC90CAAE177002237AE /* storage */,
 				B22277CA0D00BF1E0071B782 /* svg */,
 				518A34BD1026C831001B6896 /* websockets */,
@@ -10163,6 +10180,21 @@
 			path = DerivedSources/WebCore;
 			sourceTree = BUILT_PRODUCTS_DIR;
 		};
+		18C5FC9F10A3991F0048438D /* SharedScript */ = {
+			isa = PBXGroup;
+			children = (
+				18C5FCB410A3C6F20048438D /* SharedScriptContext.cpp */,
+				18C5FCB510A3C6F20048438D /* SharedScriptContext.h */,
+				18C5FCB610A3C6F20048438D /* SharedScriptContext.idl */,
+				18C5FCA010A3991F0048438D /* WebKitSharedScript.cpp */,
+				18C5FCA110A3991F0048438D /* WebKitSharedScript.h */,
+				18C5FCA210A3991F0048438D /* WebKitSharedScript.idl */,
+				18C5FCA310A3991F0048438D /* WebKitSharedScriptRepository.cpp */,
+				18C5FCA410A3991F0048438D /* WebKitSharedScriptRepository.h */,
+			);
+			path = "SharedScript";
+			sourceTree = "<group>";
+		};
 		1A2E6E560CC551E0004A2062 /* sql */ = {
 			isa = PBXGroup;
 			children = (
@@ -18140,6 +18172,9 @@
 				1479FAF0109AE37500DED655 /* RenderRubyBase.h in Headers */,
 				1479FAF2109AE37500DED655 /* RenderRubyRun.h in Headers */,
 				1479FAF4109AE37500DED655 /* RenderRubyText.h in Headers */,
+				18C5FCA610A3991F0048438D /* WebKitSharedScript.h in Headers */,
+				18C5FCA910A3991F0048438D /* WebKitSharedScriptRepository.h in Headers */,
+				18C5FCB810A3C6F20048438D /* SharedScriptContext.h in Headers */,
 				E124748410AA161D00B79493 /* AuthenticationClient.h in Headers */,
 				9382DF5810A8D5C900925652 /* ColorSpace.h in Headers */,
 				AB31C91E10AE1B8E000C7B92 /* LineClampValue.h in Headers */,
@@ -18245,6 +18280,8 @@
 				85136CA80AED665900F90A3D /* westResizeCursor.png in Resources */,
 				1AB1AE7A0C051FDE00139F4F /* zoomInCursor.png in Resources */,
 				1AB1AE7B0C051FDE00139F4F /* zoomOutCursor.png in Resources */,
+				18C5FCA710A3991F0048438D /* WebKitSharedScript.idl in Resources */,
+				18C5FCB910A3C6F20048438D /* SharedScriptContext.idl in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -20287,6 +20324,9 @@
 				1479FAEF109AE37500DED655 /* RenderRubyBase.cpp in Sources */,
 				1479FAF1109AE37500DED655 /* RenderRubyRun.cpp in Sources */,
 				1479FAF3109AE37500DED655 /* RenderRubyText.cpp in Sources */,
+				18C5FCA510A3991F0048438D /* WebKitSharedScript.cpp in Sources */,
+				18C5FCA810A3991F0048438D /* WebKitSharedScriptRepository.cpp in Sources */,
+				18C5FCB710A3C6F20048438D /* SharedScriptContext.cpp in Sources */,
 				E1B4CD2510B322E200BFFD7E /* CredentialStorageMac.mm in Sources */,
 				6E47E66010B7944B00B186C8 /* WebGLGetInfo.cpp in Sources */,
 			);
diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp
index da60887..edf50c1 100644
--- a/WebCore/dom/Document.cpp
+++ b/WebCore/dom/Document.cpp
@@ -143,6 +143,10 @@
 #include "SharedWorkerRepository.h"
 #endif
 
+#if ENABLE(SHARED_SCRIPT)
+#include "WebKitSharedScriptRepository.h"
+#endif
+
 #if ENABLE(DOM_STORAGE)
 #include "StorageEvent.h"
 #endif
@@ -1442,6 +1446,10 @@ void Document::detach()
     SharedWorkerRepository::documentDetached(this);
 #endif
 
+#if ENABLE(SHARED_SCRIPT)
+    WebKitSharedScriptRepository::documentDetached(this);
+#endif
+
     if (m_frame) {
         FrameView* view = m_frame->view();
         if (view)
diff --git a/WebCore/dom/EventTarget.cpp b/WebCore/dom/EventTarget.cpp
index 65d751a..8ee1f52 100644
--- a/WebCore/dom/EventTarget.cpp
+++ b/WebCore/dom/EventTarget.cpp
@@ -156,6 +156,18 @@ Notification* EventTarget::toNotification()
 }
 #endif
 
+#if ENABLE(SHARED_SCRIPT)
+WebKitSharedScript* EventTarget::toWebKitSharedScript()
+{
+    return 0;
+}
+
+SharedScriptContext* EventTarget::toSharedScriptContext()
+{
+    return 0;
+}
+#endif
+
 bool EventTarget::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
 {
     EventTargetData* d = ensureEventTargetData();
diff --git a/WebCore/dom/EventTarget.h b/WebCore/dom/EventTarget.h
index 2d77c87..d0c1b67 100644
--- a/WebCore/dom/EventTarget.h
+++ b/WebCore/dom/EventTarget.h
@@ -59,6 +59,11 @@ namespace WebCore {
     class XMLHttpRequest;
     class XMLHttpRequestUpload;
 
+#if ENABLE(SHARED_SCRIPT)
+    class SharedScriptContext;
+    class WebKitSharedScript;
+#endif
+
     typedef int ExceptionCode;
 
     struct FiringEventIterator {
@@ -118,6 +123,11 @@ namespace WebCore {
         virtual Notification* toNotification();
 #endif
 
+#if ENABLE(SHARED_SCRIPT)
+        virtual WebKitSharedScript* toWebKitSharedScript();
+        virtual SharedScriptContext* toSharedScriptContext();
+#endif
+
         virtual ScriptExecutionContext* scriptExecutionContext() const = 0;
 
         virtual bool addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
diff --git a/WebCore/dom/ScriptExecutionContext.h b/WebCore/dom/ScriptExecutionContext.h
index 1414125..3ef48eb 100644
--- a/WebCore/dom/ScriptExecutionContext.h
+++ b/WebCore/dom/ScriptExecutionContext.h
@@ -57,6 +57,9 @@ namespace WebCore {
 
         virtual bool isDocument() const { return false; }
         virtual bool isWorkerContext() const { return false; }
+#if ENABLE(SHARED_SCRIPT)
+        virtual bool isSharedScriptContext() const { return false; }
+#endif
 
         const KURL& url() const { return virtualURL(); }
         KURL completeURL(const String& url) const { return virtualCompleteURL(url); }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list