Index: Source/web/SharedWorkerRepositoryClientImpl.cpp |
diff --git a/Source/web/SharedWorkerRepository.cpp b/Source/web/SharedWorkerRepositoryClientImpl.cpp |
similarity index 76% |
rename from Source/web/SharedWorkerRepository.cpp |
rename to Source/web/SharedWorkerRepositoryClientImpl.cpp |
index 5e8e5543beb2cd486b112f33ca23ec789b8f1f68..bcf279eda5240fd3cf11b11152ab36b74ed2a495 100644 |
--- a/Source/web/SharedWorkerRepository.cpp |
+++ b/Source/web/SharedWorkerRepositoryClientImpl.cpp |
@@ -29,7 +29,7 @@ |
*/ |
#include "config.h" |
-#include "core/workers/SharedWorkerRepository.h" |
+#include "SharedWorkerRepositoryClientImpl.h" |
#include "WebContentSecurityPolicy.h" |
#include "WebFrameClient.h" |
@@ -37,6 +37,7 @@ |
#include "WebKit.h" |
#include "WebSharedWorker.h" |
#include "WebSharedWorkerRepository.h" |
+#include "WebSharedWorkerRepositoryClient.h" |
#include "bindings/v8/ExceptionMessages.h" |
#include "bindings/v8/ExceptionState.h" |
#include "core/dom/ExceptionCode.h" |
@@ -50,13 +51,15 @@ |
#include "core/workers/WorkerScriptLoader.h" |
#include "core/workers/WorkerScriptLoaderClient.h" |
#include "platform/network/ResourceResponse.h" |
-#include "public/platform/Platform.h" |
#include "public/platform/WebMessagePortChannel.h" |
#include "public/platform/WebString.h" |
#include "public/platform/WebURL.h" |
+using namespace WebCore; |
+ |
namespace WebKit { |
+// FIXME: Deprecate these static methods. |
WebSharedWorkerRepository* s_sharedWorkerRepository = 0; |
void setSharedWorkerRepository(WebSharedWorkerRepository* repository) |
@@ -70,16 +73,6 @@ static WebSharedWorkerRepository* sharedWorkerRepository() |
return s_sharedWorkerRepository; |
} |
-} |
- |
-namespace WebCore { |
- |
-class Document; |
-using WebKit::WebFrameImpl; |
-using WebKit::WebMessagePortChannel; |
-using WebKit::WebSharedWorker; |
-using WebKit::WebSharedWorkerRepository; |
- |
// Callback class that keeps the SharedWorker and WebSharedWorker objects alive while loads are potentially happening, and also translates load errors into error events on the worker. |
class SharedWorkerScriptLoader : private WorkerScriptLoaderClient, private WebSharedWorker::ConnectListener { |
public: |
@@ -98,17 +91,13 @@ public: |
~SharedWorkerScriptLoader(); |
void load(); |
- static void stopAllLoadersForContext(ExecutionContext*); |
private: |
// WorkerScriptLoaderClient callbacks |
virtual void didReceiveResponse(unsigned long identifier, const ResourceResponse&); |
virtual void notifyFinished(); |
- |
virtual void connected(); |
- const ExecutionContext* loadingContext() { return m_worker->executionContext(); } |
- |
void sendConnect(); |
RefPtr<SharedWorker> m_worker; |
@@ -121,26 +110,6 @@ private: |
long long m_responseAppCacheID; |
}; |
-static Vector<SharedWorkerScriptLoader*>& pendingLoaders() |
-{ |
- AtomicallyInitializedStatic(Vector<SharedWorkerScriptLoader*>&, loaders = *new Vector<SharedWorkerScriptLoader*>); |
- return loaders; |
-} |
- |
-void SharedWorkerScriptLoader::stopAllLoadersForContext(ExecutionContext* context) |
-{ |
- // Walk our list of pending loaders and shutdown any that belong to this context. |
- Vector<SharedWorkerScriptLoader*>& loaders = pendingLoaders(); |
- for (unsigned i = 0; i < loaders.size(); ) { |
- SharedWorkerScriptLoader* loader = loaders[i]; |
- if (context == loader->loadingContext()) { |
- loaders.remove(i); |
- delete loader; |
- } else |
- i++; |
- } |
-} |
- |
SharedWorkerScriptLoader::~SharedWorkerScriptLoader() |
{ |
if (m_loading) |
@@ -151,9 +120,9 @@ void SharedWorkerScriptLoader::load() |
{ |
ASSERT(!m_loading); |
// If the shared worker is not yet running, load the script resource for it, otherwise just send it a connect event. |
- if (m_webWorker->isStarted()) |
+ if (m_webWorker->isStarted()) { |
sendConnect(); |
- else { |
+ } else { |
// Keep the worker + JS wrapper alive until the resource load is complete in case we need to dispatch an error event. |
m_worker->setPendingActivity(m_worker.get()); |
m_loading = true; |
@@ -195,31 +164,25 @@ void SharedWorkerScriptLoader::connected() |
delete this; |
} |
-bool SharedWorkerRepository::isAvailable() |
-{ |
- return WebKit::sharedWorkerRepository(); |
-} |
- |
static WebSharedWorkerRepository::DocumentID getId(void* document) |
{ |
ASSERT(document); |
return reinterpret_cast<WebSharedWorkerRepository::DocumentID>(document); |
} |
-void SharedWorkerRepository::connect(PassRefPtr<SharedWorker> worker, PassRefPtr<MessagePortChannel> port, const KURL& url, const String& name, ExceptionState& es) |
+void SharedWorkerRepositoryClientImpl::connect(PassRefPtr<SharedWorker> worker, PassRefPtr<MessagePortChannel> port, const KURL& url, const String& name, ExceptionState& es) |
{ |
- WebKit::WebSharedWorkerRepository* repository = WebKit::sharedWorkerRepository(); |
- |
- // This should not be callable unless there's a SharedWorkerRepository for |
- // this context (since isAvailable() should have returned null). |
- ASSERT(repository); |
- |
// No nested workers (for now) - connect() should only be called from document context. |
ASSERT(worker->executionContext()->isDocument()); |
Document* document = toDocument(worker->executionContext()); |
WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame()); |
OwnPtr<WebSharedWorker> webWorker; |
- webWorker = adoptPtr(webFrame->client()->createSharedWorker(webFrame, url, name, getId(document))); |
+ if (m_client) { |
+ webWorker = adoptPtr(m_client->createSharedWorker(url, name, getId(document))); |
+ } else { |
+ // FIXME: Deprecate this once client is implemented. |
+ webWorker = adoptPtr(webFrame->client()->createSharedWorker(webFrame, url, name, getId(document))); |
+ } |
if (!webWorker) { |
// Existing worker does not match this url, so return an error back to the caller. |
@@ -227,7 +190,9 @@ void SharedWorkerRepository::connect(PassRefPtr<SharedWorker> worker, PassRefPtr |
return; |
} |
- repository->addSharedWorker(webWorker.get(), getId(document)); |
+ WebKit::WebSharedWorkerRepository* repository = WebKit::sharedWorkerRepository(); |
+ if (repository) |
+ repository->addSharedWorker(webWorker.get(), getId(document)); |
// The loader object manages its own lifecycle (and the lifecycles of the two worker objects). |
// It will free itself once loading is completed. |
@@ -235,23 +200,22 @@ void SharedWorkerRepository::connect(PassRefPtr<SharedWorker> worker, PassRefPtr |
loader->load(); |
} |
-void SharedWorkerRepository::documentDetached(Document* document) |
+void SharedWorkerRepositoryClientImpl::documentDetached(Document* document) |
{ |
- WebKit::WebSharedWorkerRepository* repository = WebKit::sharedWorkerRepository(); |
+ if (m_client) { |
+ m_client->documentDetached(getId(document)); |
+ return; |
+ } |
+ // FIXME: Deprecate this once client is implemented. |
+ WebSharedWorkerRepository* repository = sharedWorkerRepository(); |
if (repository) |
repository->documentDetached(getId(document)); |
- |
- // Stop the creation of any pending SharedWorkers for this context. |
- // FIXME: Need a way to invoke this for WorkerGlobalScopes as well when we support for nested workers. |
- SharedWorkerScriptLoader::stopAllLoadersForContext(document); |
} |
-bool SharedWorkerRepository::hasSharedWorkers(Document* document) |
+SharedWorkerRepositoryClientImpl::SharedWorkerRepositoryClientImpl(WebSharedWorkerRepositoryClient* client) |
+ : m_client(client) |
{ |
- WebKit::WebSharedWorkerRepository* repository = WebKit::sharedWorkerRepository(); |
- |
- return repository && repository->hasSharedWorkers(getId(document)); |
} |
-} // namespace WebCore |
+} // namespace WebKit |