| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 2013 Google Inc. All rights reserved. | 2  * Copyright (C) 2013 Google Inc. All rights reserved. | 
| 3  * | 3  * | 
| 4  * Redistribution and use in source and binary forms, with or without | 4  * Redistribution and use in source and binary forms, with or without | 
| 5  * modification, are permitted provided that the following conditions are | 5  * modification, are permitted provided that the following conditions are | 
| 6  * met: | 6  * met: | 
| 7  * | 7  * | 
| 8  *     * Redistributions of source code must retain the above copyright | 8  *     * Redistributions of source code must retain the above copyright | 
| 9  * notice, this list of conditions and the following disclaimer. | 9  * notice, this list of conditions and the following disclaimer. | 
| 10  *     * Redistributions in binary form must reproduce the above | 10  *     * Redistributions in binary form must reproduce the above | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
| 25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
| 26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| 28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 29  */ | 29  */ | 
| 30 | 30 | 
| 31 #include "config.h" | 31 #include "config.h" | 
| 32 #include "WebEmbeddedWorkerImpl.h" | 32 #include "WebEmbeddedWorkerImpl.h" | 
| 33 | 33 | 
|  | 34 #include "ServiceWorkerGlobalScopeProxy.h" | 
| 34 #include "WebDataSourceImpl.h" | 35 #include "WebDataSourceImpl.h" | 
| 35 #include "WebFrameImpl.h" | 36 #include "WebFrameImpl.h" | 
| 36 #include "WebServiceWorkerContextClient.h" | 37 #include "WebServiceWorkerContextClient.h" | 
| 37 #include "WebView.h" | 38 #include "WebView.h" | 
| 38 #include "WebWorkerPermissionClientProxy.h" | 39 #include "WebWorkerPermissionClientProxy.h" | 
| 39 #include "WorkerPermissionClient.h" | 40 #include "WorkerPermissionClient.h" | 
| 40 #include "core/dom/Document.h" | 41 #include "core/dom/Document.h" | 
| 41 #include "core/loader/FrameLoadRequest.h" | 42 #include "core/loader/FrameLoadRequest.h" | 
| 42 #include "core/loader/SubstituteData.h" | 43 #include "core/loader/SubstituteData.h" | 
| 43 #include "core/workers/WorkerClients.h" | 44 #include "core/workers/WorkerClients.h" | 
|  | 45 #include "core/workers/WorkerLoaderProxy.h" | 
| 44 #include "core/workers/WorkerScriptLoader.h" | 46 #include "core/workers/WorkerScriptLoader.h" | 
| 45 #include "core/workers/WorkerScriptLoaderClient.h" | 47 #include "core/workers/WorkerScriptLoaderClient.h" | 
| 46 #include "core/workers/WorkerThreadStartupData.h" | 48 #include "core/workers/WorkerThreadStartupData.h" | 
|  | 49 #include "modules/serviceworkers/ServiceWorkerThread.h" | 
| 47 #include "platform/NotImplemented.h" | 50 #include "platform/NotImplemented.h" | 
| 48 #include "platform/SharedBuffer.h" | 51 #include "platform/SharedBuffer.h" | 
| 49 #include "wtf/Functional.h" | 52 #include "wtf/Functional.h" | 
| 50 | 53 | 
| 51 using namespace WebCore; | 54 using namespace WebCore; | 
| 52 | 55 | 
| 53 namespace blink { | 56 namespace blink { | 
| 54 | 57 | 
| 55 // A thin wrapper for one-off script loading. | 58 // A thin wrapper for one-off script loading. | 
| 56 class WebEmbeddedWorkerImpl::Loader : public WorkerScriptLoaderClient { | 59 class WebEmbeddedWorkerImpl::Loader : public WorkerScriptLoaderClient { | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 69     { | 72     { | 
| 70         m_callback(); | 73         m_callback(); | 
| 71     } | 74     } | 
| 72 | 75 | 
| 73     void cancel() | 76     void cancel() | 
| 74     { | 77     { | 
| 75         m_scriptLoader->cancel(); | 78         m_scriptLoader->cancel(); | 
| 76     } | 79     } | 
| 77 | 80 | 
| 78     bool failed() const { return m_scriptLoader->failed(); } | 81     bool failed() const { return m_scriptLoader->failed(); } | 
|  | 82     const KURL& url() const { return m_scriptLoader->responseURL(); } | 
| 79     String script() const { return m_scriptLoader->script(); } | 83     String script() const { return m_scriptLoader->script(); } | 
| 80 | 84 | 
| 81 private: | 85 private: | 
| 82     Loader(ExecutionContext* loadingContext, const KURL& scriptURL, const Closur
     e& callback) | 86     Loader(ExecutionContext* loadingContext, const KURL& scriptURL, const Closur
     e& callback) | 
| 83         : m_scriptLoader(WorkerScriptLoader::create()) | 87         : m_scriptLoader(WorkerScriptLoader::create()) | 
| 84         , m_callback(callback) | 88         , m_callback(callback) | 
| 85     { | 89     { | 
| 86         m_scriptLoader->setTargetType(ResourceRequest::TargetIsServiceWorker); | 90         m_scriptLoader->setTargetType(ResourceRequest::TargetIsServiceWorker); | 
| 87         m_scriptLoader->loadAsynchronously( | 91         m_scriptLoader->loadAsynchronously( | 
| 88             loadingContext, scriptURL, DenyCrossOriginRequests, this); | 92             loadingContext, scriptURL, DenyCrossOriginRequests, this); | 
| 89     } | 93     } | 
| 90 | 94 | 
| 91     RefPtr<WorkerScriptLoader> m_scriptLoader; | 95     RefPtr<WorkerScriptLoader> m_scriptLoader; | 
| 92     Closure m_callback; | 96     Closure m_callback; | 
| 93 }; | 97 }; | 
| 94 | 98 | 
|  | 99 class WebEmbeddedWorkerImpl::LoaderProxy : public WorkerLoaderProxy { | 
|  | 100 public: | 
|  | 101     static PassOwnPtr<LoaderProxy> create(WebEmbeddedWorkerImpl& embeddedWorker) | 
|  | 102     { | 
|  | 103         return adoptPtr(new LoaderProxy(embeddedWorker)); | 
|  | 104     } | 
|  | 105 | 
|  | 106     virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask> task) OVERRID
     E | 
|  | 107     { | 
|  | 108         m_embeddedWorker.m_loadingContext->postTask(task); | 
|  | 109     } | 
|  | 110 | 
|  | 111     virtual bool postTaskForModeToWorkerGlobalScope(PassOwnPtr<ExecutionContextT
     ask> task, const String& mode) OVERRIDE | 
|  | 112     { | 
|  | 113         if (m_embeddedWorker.m_askedToTerminate || !m_embeddedWorker.m_workerThr
     ead) | 
|  | 114             return false; | 
|  | 115         return m_embeddedWorker.m_workerThread->runLoop().postTaskForMode(task, 
     mode); | 
|  | 116     } | 
|  | 117 | 
|  | 118 private: | 
|  | 119     explicit LoaderProxy(WebEmbeddedWorkerImpl& embeddedWorker) | 
|  | 120         : m_embeddedWorker(embeddedWorker) | 
|  | 121     { | 
|  | 122     } | 
|  | 123 | 
|  | 124     // Not owned, embedded worker owns this. | 
|  | 125     WebEmbeddedWorkerImpl& m_embeddedWorker; | 
|  | 126 }; | 
|  | 127 | 
| 95 WebEmbeddedWorker* WebEmbeddedWorker::create( | 128 WebEmbeddedWorker* WebEmbeddedWorker::create( | 
| 96     WebServiceWorkerContextClient* client, | 129     WebServiceWorkerContextClient* client, | 
| 97     WebWorkerPermissionClientProxy* permissionClient) | 130     WebWorkerPermissionClientProxy* permissionClient) | 
| 98 { | 131 { | 
| 99     return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(permissionClient
     )); | 132     return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(permissionClient
     )); | 
| 100 } | 133 } | 
| 101 | 134 | 
| 102 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl( | 135 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl( | 
| 103     PassOwnPtr<WebServiceWorkerContextClient> client, | 136     PassOwnPtr<WebServiceWorkerContextClient> client, | 
| 104     PassOwnPtr<WebWorkerPermissionClientProxy> permissionClient) | 137     PassOwnPtr<WebWorkerPermissionClientProxy> permissionClient) | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 181 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() | 214 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() | 
| 182 { | 215 { | 
| 183     ASSERT(m_mainScriptLoader); | 216     ASSERT(m_mainScriptLoader); | 
| 184 | 217 | 
| 185     if (m_mainScriptLoader->failed() || m_askedToTerminate) { | 218     if (m_mainScriptLoader->failed() || m_askedToTerminate) { | 
| 186         m_workerContextClient->workerContextFailedToStart(); | 219         m_workerContextClient->workerContextFailedToStart(); | 
| 187         m_mainScriptLoader.clear(); | 220         m_mainScriptLoader.clear(); | 
| 188         return; | 221         return; | 
| 189     } | 222     } | 
| 190 | 223 | 
| 191     // FIXME: Create WorkerReportingProxy, set up WorkerThreadStartupData, | 224     WorkerThreadStartMode startMode = | 
| 192     // create ServiceWorkerThread and start it with m_scripLoader->script(). | 225         (m_workerStartData.startMode == WebEmbeddedWorkerStartModePauseOnStart) | 
|  | 226         ? PauseWorkerGlobalScopeOnStart : DontPauseWorkerGlobalScopeOnStart; | 
|  | 227 | 
|  | 228     OwnPtr<WorkerClients> workerClients = WorkerClients::create(); | 
|  | 229     providePermissionClientToWorker(workerClients.get(), m_permissionClient.rele
     ase()); | 
|  | 230 | 
|  | 231     OwnPtr<WorkerThreadStartupData> startupData = | 
|  | 232         WorkerThreadStartupData::create( | 
|  | 233             m_mainScriptLoader->url(), | 
|  | 234             m_workerStartData.userAgent, | 
|  | 235             m_mainScriptLoader->script(), | 
|  | 236             startMode, | 
|  | 237             // FIXME: fill appropriate CSP info and policy type. | 
|  | 238             String(), | 
|  | 239             ContentSecurityPolicy::Enforce, | 
|  | 240             workerClients.release()); | 
| 193 | 241 | 
| 194     m_mainScriptLoader.clear(); | 242     m_mainScriptLoader.clear(); | 
| 195 | 243 | 
| 196     notImplemented(); | 244     m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *m_l
     oadingContext, m_workerContextClient.release()); | 
|  | 245     m_loaderProxy = LoaderProxy::create(*this); | 
|  | 246 | 
|  | 247     m_workerThread = ServiceWorkerThread::create(*m_loaderProxy, *m_workerGlobal
     ScopeProxy, startupData.release()); | 
|  | 248     m_workerThread->start(); | 
| 197 } | 249 } | 
| 198 | 250 | 
| 199 } // namespace blink | 251 } // namespace blink | 
| OLD | NEW | 
|---|