X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2FWebKit%2FSource%2Fweb%2FSharedWorkerRepositoryClientImpl.cpp;h=404288c028f60a3951480fed94e530128890c1b2;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=6010196d0714280d06eed57cc2ba703a84cefe6b;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/WebKit/Source/web/SharedWorkerRepositoryClientImpl.cpp b/src/third_party/WebKit/Source/web/SharedWorkerRepositoryClientImpl.cpp index 6010196..404288c 100644 --- a/src/third_party/WebKit/Source/web/SharedWorkerRepositoryClientImpl.cpp +++ b/src/third_party/WebKit/Source/web/SharedWorkerRepositoryClientImpl.cpp @@ -57,92 +57,51 @@ using namespace WebCore; namespace blink { -// 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 WebSharedWorkerConnector::ConnectListener { +// Callback class that keeps the SharedWorker and WebSharedWorker objects alive while connecting. +class SharedWorkerConnector : private WebSharedWorkerConnector::ConnectListener { public: - SharedWorkerScriptLoader(PassRefPtr worker, const KURL& url, const String& name, PassOwnPtr channel, PassOwnPtr webWorkerConnector) + SharedWorkerConnector(PassRefPtr worker, const KURL& url, const String& name, PassOwnPtr channel, PassOwnPtr webWorkerConnector) : m_worker(worker) , m_url(url) , m_name(name) , m_webWorkerConnector(webWorkerConnector) - , m_channel(channel) - , m_scriptLoader(WorkerScriptLoader::create()) - , m_loading(false) - , m_responseAppCacheID(0) - { - m_scriptLoader->setTargetType(ResourceRequest::TargetIsSharedWorker); - } + , m_channel(channel) { } - ~SharedWorkerScriptLoader(); - void load(); + virtual ~SharedWorkerConnector(); + void connect(); private: - // WorkerScriptLoaderClient callbacks - virtual void didReceiveResponse(unsigned long identifier, const ResourceResponse&); - virtual void notifyFinished(); - virtual void connected(); - - void sendConnect(); + // WebSharedWorkerConnector::ConnectListener overrides. + virtual void connected() OVERRIDE; + virtual void scriptLoadFailed() OVERRIDE; RefPtr m_worker; KURL m_url; String m_name; OwnPtr m_webWorkerConnector; OwnPtr m_channel; - RefPtr m_scriptLoader; - bool m_loading; - long long m_responseAppCacheID; }; -SharedWorkerScriptLoader::~SharedWorkerScriptLoader() -{ - if (m_loading) - m_worker->unsetPreventGC(); -} - -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_webWorkerConnector->isStarted()) { - sendConnect(); - } else { - // Keep the worker + JS wrapper alive until the resource load is complete in case we need to dispatch an error event. - m_worker->setPreventGC(); - m_loading = true; - - m_scriptLoader->loadAsynchronously(m_worker->executionContext(), m_url, DenyCrossOriginRequests, this); - } -} - -void SharedWorkerScriptLoader::didReceiveResponse(unsigned long identifier, const ResourceResponse& response) +SharedWorkerConnector::~SharedWorkerConnector() { - m_responseAppCacheID = response.appCacheID(); - InspectorInstrumentation::didReceiveScriptResponse(m_worker->executionContext(), identifier); + m_worker->unsetPreventGC(); } - -void SharedWorkerScriptLoader::notifyFinished() +void SharedWorkerConnector::connect() { - if (m_scriptLoader->failed()) { - m_worker->dispatchEvent(Event::createCancelable(EventTypeNames::error)); - delete this; - } else { - InspectorInstrumentation::scriptImported(m_worker->executionContext(), m_scriptLoader->identifier(), m_scriptLoader->script()); - // Pass the script off to the worker, then send a connect event. - m_webWorkerConnector->startWorkerContext(m_url, m_name, m_worker->executionContext()->userAgent(m_url), m_scriptLoader->script(), m_worker->executionContext()->contentSecurityPolicy()->deprecatedHeader(), static_cast(m_worker->executionContext()->contentSecurityPolicy()->deprecatedHeaderType()), m_responseAppCacheID); - sendConnect(); - } + m_worker->setPreventGC(); + m_webWorkerConnector->connect(m_channel.leakPtr(), this); } -void SharedWorkerScriptLoader::sendConnect() +void SharedWorkerConnector::connected() { - // Send the connect event off, and linger until it is done sending. - m_webWorkerConnector->connect(m_channel.leakPtr(), this); + // Free ourselves (this releases the SharedWorker so it can be freed as well if unreferenced). + delete this; } -void SharedWorkerScriptLoader::connected() +void SharedWorkerConnector::scriptLoadFailed() { - // Connect event has been sent, so free ourselves (this releases the SharedWorker so it can be freed as well if unreferenced). + m_worker->dispatchEvent(Event::createCancelable(EventTypeNames::error)); + // Free ourselves (this releases the SharedWorker so it can be freed as well if unreferenced). delete this; } @@ -166,10 +125,10 @@ void SharedWorkerRepositoryClientImpl::connect(PassRefPtr worker, return; } - // The loader object manages its own lifecycle (and the lifecycles of the two worker objects). - // It will free itself once loading is completed. - SharedWorkerScriptLoader* loader = new SharedWorkerScriptLoader(worker, url, name, port, webWorkerConnector.release()); - loader->load(); + // The connector object manages its own lifecycle (and the lifecycles of the two worker objects). + // It will free itself once connecting is completed. + SharedWorkerConnector* connector = new SharedWorkerConnector(worker, url, name, port, webWorkerConnector.release()); + connector->connect(); } void SharedWorkerRepositoryClientImpl::documentDetached(Document* document)