Commit 1d1a836a authored by jianli@chromium.org's avatar jianli@chromium.org

WebCore:

2009-06-16  Jian Li  <jianli@chromium.org>

        Reviewed by Adam Barth and David Levin.

        Bug 26146: Change to use ThreadableLoader to load the worker script
        in order to check URL origin for redirection.
        https://bugs.webkit.org/show_bug.cgi?id=26146

        Test: http/tests/workers/worker-redirect.html

        * GNUmakefile.am:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * workers/Worker.cpp:
        (WebCore::Worker::Worker):
        (WebCore::Worker::notifyFinished):
        * workers/Worker.h:
        * workers/WorkerContext.cpp:
        (WebCore::WorkerContext::importScripts):
        * workers/WorkerImportScriptsClient.cpp: Removed.
        * workers/WorkerImportScriptsClient.h: Removed.
        * workers/WorkerScriptLoader.cpp: Renamed from workers/WorkerImportScriptsClient.cpp.
          This to make it more generic so worker script loading could use it.
        (WebCore::WorkerScriptLoader::loadSynchronously):
        (WebCore::WorkerScriptLoader::loadAsynchronously):
        (WebCore::WorkerScriptLoader::didFinishLoading):
        (WebCore::WorkerScriptLoader::didFail):
        (WebCore::WorkerScriptLoader::didFailRedirectCheck):
        (WebCore::WorkerScriptLoader::didReceiveAuthenticationCancellation):
        (WebCore::WorkerScriptLoader::notifyFinished):
        * workers/WorkerScriptLoader.h: Renamed from workers/WorkerImportScriptsClient.h.
          This to make it more generic so worker script loading could use it.
        * workers/WorkerScriptLoaderClient.h: Added.

LayoutTests:

2009-06-16  Jian Li  <jianli@chromium.org>

        Reviewed by Adam Barth and David Levin.

        Bug 26146: Change to use ThreadableLoader to load the worker script
        in order to check URL origin for redirection.
        https://bugs.webkit.org/show_bug.cgi?id=26146

        Add a layout test to cover the scenario that the worker script is
        loaded from different redirect origin.

        * http/tests/workers/resources/worker-redirect-target.js: Added.
        * http/tests/workers/worker-redirect-expected.txt: Added.
        * http/tests/workers/worker-redirect.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44726 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2627f253
2009-06-16 Jian Li <jianli@chromium.org>
Reviewed by Adam Barth and David Levin.
Bug 26146: Change to use ThreadableLoader to load the worker script
in order to check URL origin for redirection.
https://bugs.webkit.org/show_bug.cgi?id=26146
Add a layout test to cover the scenario that the worker script is
loaded from different redirect origin.
* http/tests/workers/resources/worker-redirect-target.js: Added.
* http/tests/workers/worker-redirect-expected.txt: Added.
* http/tests/workers/worker-redirect.html: Added.
2009-06-16 Xan Lopez <xlopez@igalia.com>
Fix typo in test name.
......
Test that loading the worker's script does not allow a cross origin redirect (bug 26146)
SUCCESS: threw error when attempting to redirected cross origin while loading the worker script.
<body>
<p>Test that loading the worker's script does not allow a cross origin redirect (<a href="https://bugs.webkit.org/show_bug.cgi?id=26146">bug 26146</a>)</p>
<div id=result></div>
<script>
function log(message)
{
document.getElementById("result").innerHTML += message + "<br>";
}
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.waitUntilDone();
}
var worker = new Worker('/resources/redirect.php?url=http://localhost:8000/workers/resources/worker-redirect-target.js');
worker.onerror = function(evt) {
log("SUCCESS: threw error when attempting to redirected cross origin while loading the worker script.");
if (window.layoutTestController)
layoutTestController.notifyDone();
}
worker.onmessage = function(evt) {
log("FAIL: executed script when redirect cross origin.");
if (window.layoutTestController)
layoutTestController.notifyDone();
}
</script>
</body>
</html>
2009-06-16 Jian Li <jianli@chromium.org>
Reviewed by Adam Barth and David Levin.
Bug 26146: Change to use ThreadableLoader to load the worker script
in order to check URL origin for redirection.
https://bugs.webkit.org/show_bug.cgi?id=26146
Test: http/tests/workers/worker-redirect.html
* GNUmakefile.am:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* workers/Worker.cpp:
(WebCore::Worker::Worker):
(WebCore::Worker::notifyFinished):
* workers/Worker.h:
* workers/WorkerContext.cpp:
(WebCore::WorkerContext::importScripts):
* workers/WorkerImportScriptsClient.cpp: Removed.
* workers/WorkerImportScriptsClient.h: Removed.
* workers/WorkerScriptLoader.cpp: Renamed from workers/WorkerImportScriptsClient.cpp.
This to make it more generic so worker script loading could use it.
(WebCore::WorkerScriptLoader::loadSynchronously):
(WebCore::WorkerScriptLoader::loadAsynchronously):
(WebCore::WorkerScriptLoader::didFinishLoading):
(WebCore::WorkerScriptLoader::didFail):
(WebCore::WorkerScriptLoader::didFailRedirectCheck):
(WebCore::WorkerScriptLoader::didReceiveAuthenticationCancellation):
(WebCore::WorkerScriptLoader::notifyFinished):
* workers/WorkerScriptLoader.h: Renamed from workers/WorkerImportScriptsClient.h.
This to make it more generic so worker script loading could use it.
* workers/WorkerScriptLoaderClient.h: Added.
2009-06-16 Brent Fulgham <bfulgham@gmail.com>
Reviewed by Darin Adler.
......
......@@ -2282,10 +2282,11 @@ webcore_sources += \
WebCore/workers/WorkerObjectProxy.h \
WebCore/workers/WorkerRunLoop.cpp \
WebCore/workers/WorkerRunLoop.h \
WebCore/workers/WorkerScriptLoader.cpp \
WebCore/workers/WorkerScriptLoader.h \
WebCore/workers/WorkerScriptLoaderClient.h \
WebCore/workers/WorkerThread.cpp \
WebCore/workers/WorkerThread.h \
WebCore/workers/WorkerImportScriptsClient.cpp \
WebCore/workers/WorkerImportScriptsClient.h
WebCore/workers/WorkerThread.h
endif
# ----
......
......@@ -1404,7 +1404,7 @@ contains(DEFINES, ENABLE_WORKERS=1) {
workers/WorkerMessagingProxy.cpp \
workers/WorkerRunLoop.cpp \
workers/WorkerThread.cpp \
workers/WorkerImportScriptsClient.cpp
workers/WorkerScriptLoader.cpp
}
contains(DEFINES, ENABLE_VIDEO=1) {
......
......@@ -9538,14 +9538,6 @@
RelativePath="..\workers\WorkerContextProxy.h"
>
</File>
<File
RelativePath="..\workers\WorkerImportScriptsClient.cpp"
>
</File>
<File
RelativePath="..\workers\WorkerImportScriptsClient.h"
>
</File>
<File
RelativePath="..\workers\WorkerLoaderProxy.h"
>
......@@ -9578,6 +9570,18 @@
RelativePath="..\workers\WorkerRunLoop.h"
>
</File>
<File
RelativePath="..\workers\WorkerScriptLoader.cpp"
>
</File>
<File
RelativePath="..\workers\WorkerScriptLoader.h"
>
</File>
<File
RelativePath="..\workers\WorkerScriptLoaderClient.h"
>
</File>
<File
RelativePath="..\workers\WorkerThread.cpp"
>
......
......@@ -570,6 +570,7 @@
2E4346550F546A8200B0F1BA /* WorkerThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4346430F546A8200B0F1BA /* WorkerThread.h */; };
2E4346580F546A9900B0F1BA /* CrossThreadCopier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E4346560F546A9900B0F1BA /* CrossThreadCopier.cpp */; };
2E4346590F546A9900B0F1BA /* CrossThreadCopier.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4346570F546A9900B0F1BA /* CrossThreadCopier.h */; };
2EA768040FE7126400AB9C8A /* WorkerScriptLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EA768030FE7126400AB9C8A /* WorkerScriptLoaderClient.h */; };
31288E720E3005D6003619AE /* WebKitCSSKeyframeRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31288E6E0E3005D6003619AE /* WebKitCSSKeyframeRule.cpp */; };
31288E730E3005D6003619AE /* WebKitCSSKeyframeRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 31288E6F0E3005D6003619AE /* WebKitCSSKeyframeRule.h */; };
31288E740E3005D6003619AE /* WebKitCSSKeyframesRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31288E700E3005D6003619AE /* WebKitCSSKeyframesRule.cpp */; };
......@@ -2172,8 +2173,8 @@
A7D0318E0E93540300E24ACD /* JSImageDataCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D0318D0E93540300E24ACD /* JSImageDataCustom.cpp */; };
A7D27FC40E0A599F0079AD2B /* SVGFETile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D27FC30E0A599F0079AD2B /* SVGFETile.cpp */; };
A7D3C5240B576B4B002CA450 /* PasteboardHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */; settings = {ATTRIBUTES = (Private, ); }; };
A7D6B3490F61104500B79FD1 /* WorkerImportScriptsClient.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D6B3470F61104500B79FD1 /* WorkerImportScriptsClient.h */; };
A7D6B34A0F61104500B79FD1 /* WorkerImportScriptsClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D6B3480F61104500B79FD1 /* WorkerImportScriptsClient.cpp */; };
A7D6B3490F61104500B79FD1 /* WorkerScriptLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = A7D6B3470F61104500B79FD1 /* WorkerScriptLoader.h */; };
A7D6B34A0F61104500B79FD1 /* WorkerScriptLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7D6B3480F61104500B79FD1 /* WorkerScriptLoader.cpp */; };
A809F1470B73793A002E4D7F /* RenderSVGGradientStop.h in Headers */ = {isa = PBXBuildFile; fileRef = A809F1450B73793A002E4D7F /* RenderSVGGradientStop.h */; };
A809F1480B73793B002E4D7F /* RenderSVGGradientStop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A809F1460B73793A002E4D7F /* RenderSVGGradientStop.cpp */; };
A809F1AA0B737FB6002E4D7F /* RenderSVGHiddenContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = A809F1A80B737FB6002E4D7F /* RenderSVGHiddenContainer.h */; };
......@@ -5455,6 +5456,7 @@
2E4346430F546A8200B0F1BA /* WorkerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WorkerThread.h; path = workers/WorkerThread.h; sourceTree = "<group>"; };
2E4346560F546A9900B0F1BA /* CrossThreadCopier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossThreadCopier.cpp; sourceTree = "<group>"; };
2E4346570F546A9900B0F1BA /* CrossThreadCopier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossThreadCopier.h; sourceTree = "<group>"; };
2EA768030FE7126400AB9C8A /* WorkerScriptLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WorkerScriptLoaderClient.h; path = workers/WorkerScriptLoaderClient.h; sourceTree = "<group>"; };
31288E6E0E3005D6003619AE /* WebKitCSSKeyframeRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitCSSKeyframeRule.cpp; sourceTree = "<group>"; };
31288E6F0E3005D6003619AE /* WebKitCSSKeyframeRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKitCSSKeyframeRule.h; sourceTree = "<group>"; };
31288E700E3005D6003619AE /* WebKitCSSKeyframesRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebKitCSSKeyframesRule.cpp; sourceTree = "<group>"; };
......@@ -7048,8 +7050,8 @@
A7D0318D0E93540300E24ACD /* JSImageDataCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSImageDataCustom.cpp; sourceTree = "<group>"; };
A7D27FC30E0A599F0079AD2B /* SVGFETile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGFETile.cpp; sourceTree = "<group>"; };
A7D3C5230B576B4B002CA450 /* PasteboardHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PasteboardHelper.h; sourceTree = "<group>"; };
A7D6B3470F61104500B79FD1 /* WorkerImportScriptsClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WorkerImportScriptsClient.h; path = workers/WorkerImportScriptsClient.h; sourceTree = "<group>"; };
A7D6B3480F61104500B79FD1 /* WorkerImportScriptsClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WorkerImportScriptsClient.cpp; path = workers/WorkerImportScriptsClient.cpp; sourceTree = "<group>"; };
A7D6B3470F61104500B79FD1 /* WorkerScriptLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WorkerScriptLoader.h; path = workers/WorkerScriptLoader.h; sourceTree = "<group>"; };
A7D6B3480F61104500B79FD1 /* WorkerScriptLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WorkerScriptLoader.cpp; path = workers/WorkerScriptLoader.cpp; sourceTree = "<group>"; };
A809F1450B73793A002E4D7F /* RenderSVGGradientStop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGGradientStop.h; sourceTree = "<group>"; };
A809F1460B73793A002E4D7F /* RenderSVGGradientStop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGGradientStop.cpp; sourceTree = "<group>"; };
A809F1A80B737FB6002E4D7F /* RenderSVGHiddenContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGHiddenContainer.h; sourceTree = "<group>"; };
......@@ -9774,8 +9776,6 @@
2E4346370F546A8200B0F1BA /* WorkerContext.h */,
2E4346380F546A8200B0F1BA /* WorkerContext.idl */,
2E4346390F546A8200B0F1BA /* WorkerContextProxy.h */,
A7D6B3480F61104500B79FD1 /* WorkerImportScriptsClient.cpp */,
A7D6B3470F61104500B79FD1 /* WorkerImportScriptsClient.h */,
2E43463A0F546A8200B0F1BA /* WorkerLocation.cpp */,
2E43463B0F546A8200B0F1BA /* WorkerLocation.h */,
2E43463C0F546A8200B0F1BA /* WorkerLocation.idl */,
......@@ -9784,6 +9784,9 @@
2E43463F0F546A8200B0F1BA /* WorkerObjectProxy.h */,
2E4346400F546A8200B0F1BA /* WorkerRunLoop.cpp */,
2E4346410F546A8200B0F1BA /* WorkerRunLoop.h */,
A7D6B3480F61104500B79FD1 /* WorkerScriptLoader.cpp */,
A7D6B3470F61104500B79FD1 /* WorkerScriptLoader.h */,
2EA768030FE7126400AB9C8A /* WorkerScriptLoaderClient.h */,
2E4346420F546A8200B0F1BA /* WorkerThread.cpp */,
2E4346430F546A8200B0F1BA /* WorkerThread.h */,
);
......@@ -16692,13 +16695,13 @@
2E4346460F546A8200B0F1BA /* Worker.h in Headers */,
2E4346490F546A8200B0F1BA /* WorkerContext.h in Headers */,
2E43464B0F546A8200B0F1BA /* WorkerContextProxy.h in Headers */,
A7D6B3490F61104500B79FD1 /* WorkerImportScriptsClient.h in Headers */,
2E43464D0F546A8200B0F1BA /* WorkerLocation.h in Headers */,
2E4346500F546A8200B0F1BA /* WorkerMessagingProxy.h in Headers */,
E1271A0B0EEEC77A00F61213 /* WorkerNavigator.h in Headers */,
2E4346510F546A8200B0F1BA /* WorkerObjectProxy.h in Headers */,
2E4346530F546A8200B0F1BA /* WorkerRunLoop.h in Headers */,
E1A643F20EC0972500779668 /* WorkerScriptController.h in Headers */,
A7D6B3490F61104500B79FD1 /* WorkerScriptLoader.h in Headers */,
2E4346550F546A8200B0F1BA /* WorkerThread.h in Headers */,
0B9056F90F2685F30095FF6A /* WorkerThreadableLoader.h in Headers */,
93309E24099E64920056E581 /* WrapContentsInDummySpanCommand.h in Headers */,
......@@ -16792,6 +16795,7 @@
081EBF3B0FD34F4100DA7559 /* SVGFilterBuilder.h in Headers */,
18F831B80FD48C7800D8C56B /* WorkerLoaderProxy.h in Headers */,
A89CCC530F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.h in Headers */,
2EA768040FE7126400AB9C8A /* WorkerScriptLoaderClient.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -18694,12 +18698,12 @@
BC8243E80D0CFD7500460C8F /* WindowFeatures.cpp in Sources */,
2E4346450F546A8200B0F1BA /* Worker.cpp in Sources */,
2E4346480F546A8200B0F1BA /* WorkerContext.cpp in Sources */,
A7D6B34A0F61104500B79FD1 /* WorkerImportScriptsClient.cpp in Sources */,
2E43464C0F546A8200B0F1BA /* WorkerLocation.cpp in Sources */,
2E43464F0F546A8200B0F1BA /* WorkerMessagingProxy.cpp in Sources */,
E1271A140EEEC80400F61213 /* WorkerNavigator.cpp in Sources */,
2E4346520F546A8200B0F1BA /* WorkerRunLoop.cpp in Sources */,
E1A643FD0EC097A000779668 /* WorkerScriptController.cpp in Sources */,
A7D6B34A0F61104500B79FD1 /* WorkerScriptLoader.cpp in Sources */,
2E4346540F546A8200B0F1BA /* WorkerThread.cpp in Sources */,
0B9056F80F2685F30095FF6A /* WorkerThreadableLoader.cpp in Sources */,
93309E23099E64920056E581 /* WrapContentsInDummySpanCommand.cpp in Sources */,
......@@ -31,7 +31,6 @@
#include "Worker.h"
#include "CachedScript.h"
#include "DOMWindow.h"
#include "DocLoader.h"
#include "Document.h"
......@@ -45,6 +44,7 @@
#include "SecurityOrigin.h"
#include "TextEncoding.h"
#include "WorkerContextProxy.h"
#include "WorkerScriptLoader.h"
#include "WorkerThread.h"
#include <wtf/MainThread.h>
......@@ -65,18 +65,9 @@ Worker::Worker(const String& url, ScriptExecutionContext* context, ExceptionCode
return;
}
// FIXME: Nested workers need loading support. Consider adopting ThreadableLoader here.
ASSERT(scriptExecutionContext()->isDocument());
Document* document = static_cast<Document*>(scriptExecutionContext());
m_cachedScript = document->docLoader()->requestScript(m_scriptURL, "UTF-8");
if (!m_cachedScript) {
dispatchErrorEvent();
return;
}
m_scriptLoader = new WorkerScriptLoader();
m_scriptLoader->loadAsynchronously(scriptExecutionContext(), m_scriptURL, RequireSameRedirectOrigin, this);
setPendingActivity(this); // The worker context does not exist while loading, so we must ensure that the worker object is not collected, as well as its event listeners.
m_cachedScript->addClient(this);
}
Worker::~Worker()
......@@ -112,17 +103,14 @@ bool Worker::hasPendingActivity() const
return m_contextProxy->hasPendingActivity() || ActiveDOMObject::hasPendingActivity();
}
void Worker::notifyFinished(CachedResource* unusedResource)
void Worker::notifyFinished()
{
ASSERT_UNUSED(unusedResource, unusedResource == m_cachedScript);
if (m_cachedScript->errorOccurred())
if (m_scriptLoader->failed())
dispatchErrorEvent();
else
m_contextProxy->startWorkerContext(m_scriptURL, scriptExecutionContext()->userAgent(m_scriptURL), m_cachedScript->script());
m_contextProxy->startWorkerContext(m_scriptURL, scriptExecutionContext()->userAgent(m_scriptURL), m_scriptLoader->script());
m_cachedScript->removeClient(this);
m_cachedScript = 0;
m_scriptLoader = 0;
unsetPendingActivity(this);
}
......
......@@ -31,25 +31,25 @@
#include "AtomicStringHash.h"
#include "ActiveDOMObject.h"
#include "CachedResourceClient.h"
#include "CachedResourceHandle.h"
#include "EventListener.h"
#include "EventTarget.h"
#include "KURL.h"
#include "WorkerScriptLoaderClient.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class CachedResource;
class CachedScript;
class ScriptExecutionContext;
class String;
class WorkerContextProxy;
class WorkerScriptLoader;
typedef int ExceptionCode;
class Worker : public RefCounted<Worker>, public ActiveDOMObject, private CachedResourceClient, public EventTarget {
class Worker : public RefCounted<Worker>, public ActiveDOMObject, private WorkerScriptLoaderClient, public EventTarget {
public:
static PassRefPtr<Worker> create(const String& url, ScriptExecutionContext* context, ExceptionCode& ec) { return adoptRef(new Worker(url, context, ec)); }
~Worker();
......@@ -89,13 +89,13 @@ namespace WebCore {
private:
Worker(const String&, ScriptExecutionContext*, ExceptionCode&);
virtual void notifyFinished(CachedResource*);
virtual void notifyFinished();
virtual void refEventTarget() { ref(); }
virtual void derefEventTarget() { deref(); }
KURL m_scriptURL;
CachedResourceHandle<CachedScript> m_cachedScript;
OwnPtr<WorkerScriptLoader> m_scriptLoader;
WorkerContextProxy* m_contextProxy; // The proxy outlives the worker to perform thread shutdown.
......
......@@ -38,14 +38,13 @@
#include "EventException.h"
#include "MessageEvent.h"
#include "NotImplemented.h"
#include "ResourceRequest.h"
#include "ScriptSourceCode.h"
#include "ScriptValue.h"
#include "SecurityOrigin.h"
#include "WorkerImportScriptsClient.h"
#include "WorkerLocation.h"
#include "WorkerNavigator.h"
#include "WorkerObjectProxy.h"
#include "WorkerScriptLoader.h"
#include "WorkerThread.h"
#include "WorkerThreadableLoader.h"
#include "XMLHttpRequestException.h"
......@@ -274,20 +273,20 @@ void WorkerContext::importScripts(const Vector<String>& urls, const String& call
Vector<KURL>::const_iterator end = completedURLs.end();
for (Vector<KURL>::const_iterator it = completedURLs.begin(); it != end; ++it) {
ResourceRequest request(*it);
request.setHTTPMethod("GET");
request.setHTTPOrigin(securityOrigin);
WorkerImportScriptsClient client(scriptExecutionContext(), *it, callerURL, callerLine);
WorkerThreadableLoader::loadResourceSynchronously(this, request, client, AllowStoredCredentials, AllowDifferentRedirectOrigin);
WorkerScriptLoader scriptLoader;
scriptLoader.loadSynchronously(scriptExecutionContext(), *it, AllowDifferentRedirectOrigin);
// If the fetching attempt failed, throw a NETWORK_ERR exception and abort all these steps.
if (client.failed()) {
if (scriptLoader.failed()) {
ec = XMLHttpRequestException::NETWORK_ERR;
return;
}
scriptExecutionContext()->scriptImported(scriptLoader.identifier(), scriptLoader.script());
scriptExecutionContext()->addMessage(InspectorControllerDestination, JSMessageSource, LogMessageLevel, "Worker script imported: \"" + *it + "\".", callerLine, callerURL);
ScriptValue exception;
m_script->evaluate(ScriptSourceCode(client.script(), *it), &exception);
m_script->evaluate(ScriptSourceCode(scriptLoader.script(), *it), &exception);
if (!exception.hasNoValue()) {
m_script->setException(exception);
return;
......
/*
* Copyright (C) 2009 Apple Inc. All Rights Reserved.
* 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
......@@ -28,22 +29,54 @@
#if ENABLE(WORKERS)
#include "WorkerImportScriptsClient.h"
#include "WorkerScriptLoader.h"
#include "ResourceRequest.h"
#include "ScriptExecutionContext.h"
#include "SecurityOrigin.h"
#include "WorkerContext.h"
#include "WorkerScriptLoaderClient.h"
#include "WorkerThreadableLoader.h"
namespace WebCore {
void WorkerImportScriptsClient::didReceiveResponse(const ResourceResponse& response)
WorkerScriptLoader::WorkerScriptLoader()
: m_client(0)
, m_failed(false)
, m_identifier(0)
{
if (response.httpStatusCode() / 100 != 2 && response.httpStatusCode() != 0) {
}
void WorkerScriptLoader::loadSynchronously(ScriptExecutionContext* scriptExecutionContext, const String& url, RedirectOriginCheck redirectOriginCheck)
{
ResourceRequest request(url);
request.setHTTPMethod("GET");
ASSERT(scriptExecutionContext->isWorkerContext());
WorkerThreadableLoader::loadResourceSynchronously(static_cast<WorkerContext*>(scriptExecutionContext), request, *this, AllowStoredCredentials, redirectOriginCheck);
}
void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecutionContext, const String& url, RedirectOriginCheck redirectOriginCheck, WorkerScriptLoaderClient* client)
{
ASSERT(client);
m_client = client;
ResourceRequest request(url);
request.setHTTPMethod("GET");
m_threadableLoader = ThreadableLoader::create(scriptExecutionContext, this, request, DoNotSendLoadCallbacks, DoNotSniffContent, AllowStoredCredentials, redirectOriginCheck);
}
void WorkerScriptLoader::didReceiveResponse(const ResourceResponse& response)
{
if (response.httpStatusCode() / 100 != 2 && response.httpStatusCode()) {
m_failed = true;
return;
}
m_responseEncoding = response.textEncodingName();
}
void WorkerImportScriptsClient::didReceiveData(const char* data, int len)
void WorkerScriptLoader::didReceiveData(const char* data, int len)
{
if (m_failed)
return;
......@@ -64,33 +97,42 @@ void WorkerImportScriptsClient::didReceiveData(const char* data, int len)
m_script += m_decoder->decode(data, len);
}
void WorkerImportScriptsClient::didFinishLoading(unsigned long identifier)
void WorkerScriptLoader::didFinishLoading(unsigned long identifier)
{
if (m_failed)
return;
if (m_decoder)
m_script += m_decoder->flush();
m_scriptExecutionContext->scriptImported(identifier, m_script);
m_scriptExecutionContext->addMessage(InspectorControllerDestination, JSMessageSource, LogMessageLevel, "Worker script imported: \"" + m_url + "\".", m_callerLineNumber, m_callerURL);
m_identifier = identifier;
notifyFinished();
}
void WorkerImportScriptsClient::didFail(const ResourceError&)
void WorkerScriptLoader::didFail(const ResourceError&)
{
m_failed = true;
notifyFinished();
}
void WorkerImportScriptsClient::didFailRedirectCheck()
void WorkerScriptLoader::didFailRedirectCheck()
{
m_failed = true;
notifyFinished();
}
void WorkerImportScriptsClient::didReceiveAuthenticationCancellation(const ResourceResponse&)
void WorkerScriptLoader::didReceiveAuthenticationCancellation(const ResourceResponse&)
{
m_failed = true;
notifyFinished();
}
void WorkerScriptLoader::notifyFinished()
{
if (m_client)
m_client->notifyFinished();
}
} // namespace WebCore
#endif // ENABLE(WORKERS)
/*
* Copyright (C) 2009 Apple Inc. All Rights Reserved.
* 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
......@@ -24,35 +25,34 @@
*
*/
#ifndef WorkerImportScriptsClient_h
#define WorkerImportScriptsClient_h
#ifndef WorkerScriptLoader_h
#define WorkerScriptLoader_h
#if ENABLE(WORKERS)
#include "ResourceResponse.h"
#include "ScriptString.h"
#include "TextResourceDecoder.h"
#include "ThreadableLoader.h"
#include "ThreadableLoaderClient.h"
namespace WebCore {
class ScriptExecutionContext;
class WorkerImportScriptsClient : public ThreadableLoaderClient {
class WorkerScriptLoaderClient;
class WorkerScriptLoader : public ThreadableLoaderClient {
public:
WorkerImportScriptsClient(ScriptExecutionContext* scriptExecutionContext, const String& url, const String& callerURL, int callerLineNumber)
: m_scriptExecutionContext(scriptExecutionContext)
, m_url(url)
, m_callerURL(callerURL)
, m_callerLineNumber(callerLineNumber)
, m_failed(false)
{
}
WorkerScriptLoader();
void loadSynchronously(ScriptExecutionContext*, const String& url, RedirectOriginCheck);
void loadAsynchronously(ScriptExecutionContext*, const String& url, RedirectOriginCheck, WorkerScriptLoaderClient*);
const String& script() const { return m_script; }
bool failed() const { return m_failed; }
unsigned long identifier() const { return m_identifier; }
virtual void didReceiveResponse(const ResourceResponse& response);
virtual void didReceiveResponse(const ResourceResponse&);
virtual void didReceiveData(const char* data, int lengthReceived);
virtual void didFinishLoading(unsigned long identifier);
virtual void didFail(const ResourceError&);
......@@ -60,18 +60,19 @@ namespace WebCore {
virtual void didReceiveAuthenticationCancellation(const ResourceResponse&);
private:
ScriptExecutionContext* m_scriptExecutionContext;
String m_url;
String m_callerURL;
int m_callerLineNumber;
void notifyFinished();
WorkerScriptLoaderClient* m_client;
RefPtr<ThreadableLoader> m_threadableLoader;
String m_responseEncoding;
RefPtr<TextResourceDecoder> m_decoder;
String m_script;
bool m_failed;
unsigned long m_identifier;
};
}
} // namespace WebCore
#endif // ENABLE(WORKERS)
#endif
#endif // WorkerScriptLoader_h
/*
* Copyright (C) 2009 Apple Inc. All Rights Reserved.
* 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:
* 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 WorkerScriptLoaderClient_h
#define WorkerScriptLoaderClient_h
#if ENABLE(WORKERS)
namespace WebCore {
class WorkerScriptLoaderClient {
public:
virtual void notifyFinished() { }
protected:
virtual ~WorkerScriptLoaderClient() { }
};
} // namespace WebCore
#endif // ENABLE(WORKERS)
#endif // WorkerScriptLoaderClient_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment