 Chromium Code Reviews
 Chromium Code Reviews Issue 91173002:
  Actually start ServiceWorkerThread in EmbeddedWorker  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 91173002:
  Actually start ServiceWorkerThread in EmbeddedWorker  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk| 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/frame/ContentSecurityPolicyResponseHeaders.h" | 42 #include "core/frame/ContentSecurityPolicyResponseHeaders.h" | 
| 42 #include "core/loader/FrameLoadRequest.h" | 43 #include "core/loader/FrameLoadRequest.h" | 
| 43 #include "core/loader/SubstituteData.h" | 44 #include "core/loader/SubstituteData.h" | 
| 44 #include "core/workers/WorkerClients.h" | 45 #include "core/workers/WorkerClients.h" | 
| 46 #include "core/workers/WorkerLoaderProxy.h" | |
| 45 #include "core/workers/WorkerScriptLoader.h" | 47 #include "core/workers/WorkerScriptLoader.h" | 
| 46 #include "core/workers/WorkerScriptLoaderClient.h" | 48 #include "core/workers/WorkerScriptLoaderClient.h" | 
| 47 #include "core/workers/WorkerThreadStartupData.h" | 49 #include "core/workers/WorkerThreadStartupData.h" | 
| 50 #include "modules/serviceworkers/ServiceWorkerThread.h" | |
| 48 #include "platform/NotImplemented.h" | 51 #include "platform/NotImplemented.h" | 
| 49 #include "platform/SharedBuffer.h" | 52 #include "platform/SharedBuffer.h" | 
| 50 #include "wtf/Functional.h" | 53 #include "wtf/Functional.h" | 
| 51 | 54 | 
| 52 using namespace WebCore; | 55 using namespace WebCore; | 
| 53 | 56 | 
| 54 namespace blink { | 57 namespace blink { | 
| 55 | 58 | 
| 56 // A thin wrapper for one-off script loading. | 59 // A thin wrapper for one-off script loading. | 
| 57 class WebEmbeddedWorkerImpl::Loader : public WorkerScriptLoaderClient { | 60 class WebEmbeddedWorkerImpl::Loader : public WorkerScriptLoaderClient { | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 70 { | 73 { | 
| 71 m_callback(); | 74 m_callback(); | 
| 72 } | 75 } | 
| 73 | 76 | 
| 74 void cancel() | 77 void cancel() | 
| 75 { | 78 { | 
| 76 m_scriptLoader->cancel(); | 79 m_scriptLoader->cancel(); | 
| 77 } | 80 } | 
| 78 | 81 | 
| 79 bool failed() const { return m_scriptLoader->failed(); } | 82 bool failed() const { return m_scriptLoader->failed(); } | 
| 83 const KURL& url() const { return m_scriptLoader->responseURL(); } | |
| 80 String script() const { return m_scriptLoader->script(); } | 84 String script() const { return m_scriptLoader->script(); } | 
| 81 | 85 | 
| 82 private: | 86 private: | 
| 83 Loader(ExecutionContext* loadingContext, const KURL& scriptURL, const Closur e& callback) | 87 Loader(ExecutionContext* loadingContext, const KURL& scriptURL, const Closur e& callback) | 
| 84 : m_scriptLoader(WorkerScriptLoader::create()) | 88 : m_scriptLoader(WorkerScriptLoader::create()) | 
| 85 , m_callback(callback) | 89 , m_callback(callback) | 
| 86 { | 90 { | 
| 87 m_scriptLoader->setTargetType(ResourceRequest::TargetIsServiceWorker); | 91 m_scriptLoader->setTargetType(ResourceRequest::TargetIsServiceWorker); | 
| 88 m_scriptLoader->loadAsynchronously( | 92 m_scriptLoader->loadAsynchronously( | 
| 89 loadingContext, scriptURL, DenyCrossOriginRequests, this); | 93 loadingContext, scriptURL, DenyCrossOriginRequests, this); | 
| 90 } | 94 } | 
| 91 | 95 | 
| 92 RefPtr<WorkerScriptLoader> m_scriptLoader; | 96 RefPtr<WorkerScriptLoader> m_scriptLoader; | 
| 93 Closure m_callback; | 97 Closure m_callback; | 
| 94 }; | 98 }; | 
| 95 | 99 | 
| 100 class WebEmbeddedWorkerImpl::LoaderProxy : public WorkerLoaderProxy { | |
| 101 public: | |
| 102 static PassOwnPtr<LoaderProxy> create(WebEmbeddedWorkerImpl* embeddedWorker) | |
| 103 { | |
| 104 return adoptPtr(new LoaderProxy(embeddedWorker)); | |
| 105 } | |
| 106 | |
| 107 virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask> task) OVERRID E | |
| 108 { | |
| 109 m_embeddedWorker->m_loadingContext->postTask(task); | |
| 110 } | |
| 111 | |
| 112 virtual bool postTaskForModeToWorkerGlobalScope(PassOwnPtr<ExecutionContextT ask> task, const String& mode) OVERRIDE | |
| 113 { | |
| 114 if (m_embeddedWorker->m_askedToTerminate | |
| 115 || !m_embeddedWorker->m_workerThread) | |
| 
adamk
2013/12/05 22:50:12
Nit: This linebreak looks funny in Blink
 
kinuko
2013/12/09 12:24:20
Concatenated the lines.
 | |
| 116 return false; | |
| 117 return m_embeddedWorker->m_workerThread->runLoop().postTaskForMode(task, mode); | |
| 118 } | |
| 119 | |
| 120 private: | |
| 121 explicit LoaderProxy(WebEmbeddedWorkerImpl* embeddedWorker) | |
| 122 : m_embeddedWorker(embeddedWorker) | |
| 123 { | |
| 124 } | |
| 125 | |
| 126 // Not owned, embedded worker owns this. | |
| 
adamk
2013/12/05 22:50:12
Maybe should be a reference too?
I guess you're f
 
kinuko
2013/12/09 12:24:20
Done.
 | |
| 127 WebEmbeddedWorkerImpl* m_embeddedWorker; | |
| 128 }; | |
| 129 | |
| 96 WebEmbeddedWorker* WebEmbeddedWorker::create( | 130 WebEmbeddedWorker* WebEmbeddedWorker::create( | 
| 97 WebServiceWorkerContextClient* client, | 131 WebServiceWorkerContextClient* client, | 
| 98 WebWorkerPermissionClientProxy* permissionClient) | 132 WebWorkerPermissionClientProxy* permissionClient) | 
| 99 { | 133 { | 
| 100 return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(permissionClient )); | 134 return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(permissionClient )); | 
| 101 } | 135 } | 
| 102 | 136 | 
| 103 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl( | 137 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl( | 
| 104 PassOwnPtr<WebServiceWorkerContextClient> client, | 138 PassOwnPtr<WebServiceWorkerContextClient> client, | 
| 105 PassOwnPtr<WebWorkerPermissionClientProxy> permissionClient) | 139 PassOwnPtr<WebWorkerPermissionClientProxy> permissionClient) | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() | 216 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() | 
| 183 { | 217 { | 
| 184 ASSERT(m_mainScriptLoader); | 218 ASSERT(m_mainScriptLoader); | 
| 185 | 219 | 
| 186 if (m_mainScriptLoader->failed() || m_askedToTerminate) { | 220 if (m_mainScriptLoader->failed() || m_askedToTerminate) { | 
| 187 m_workerContextClient->workerContextFailedToStart(); | 221 m_workerContextClient->workerContextFailedToStart(); | 
| 188 m_mainScriptLoader.clear(); | 222 m_mainScriptLoader.clear(); | 
| 189 return; | 223 return; | 
| 190 } | 224 } | 
| 191 | 225 | 
| 192 // FIXME: Create WorkerReportingProxy, set up WorkerThreadStartupData, | 226 WorkerThreadStartMode startMode = | 
| 193 // create ServiceWorkerThread and start it with m_scripLoader->script(). | 227 (m_workerStartData.startMode == WebEmbeddedWorkerStartModePauseOnStart) | 
| 228 ? PauseWorkerGlobalScopeOnStart : DontPauseWorkerGlobalScopeOnStart; | |
| 229 | |
| 230 OwnPtr<WorkerClients> workerClients = WorkerClients::create(); | |
| 231 providePermissionClientToWorker(workerClients.get(), m_permissionClient.rele ase()); | |
| 232 | |
| 233 OwnPtr<WorkerThreadStartupData> startupData = | |
| 234 WorkerThreadStartupData::create( | |
| 235 m_mainScriptLoader->url(), | |
| 236 m_workerStartData.userAgent, | |
| 237 m_mainScriptLoader->script(), | |
| 238 startMode, | |
| 239 // FIXME: fill appropriate CSP info and policy type. | |
| 240 String(), | |
| 241 ContentSecurityPolicy::Enforce, | |
| 242 workerClients.release()); | |
| 194 | 243 | 
| 195 m_mainScriptLoader.clear(); | 244 m_mainScriptLoader.clear(); | 
| 196 | 245 | 
| 197 notImplemented(); | 246 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(this, m_loa dingContext.get(), m_workerContextClient.release()); | 
| 247 m_loaderProxy = LoaderProxy::create(this); | |
| 248 | |
| 249 m_workerThread = ServiceWorkerThread::create( | |
| 250 *m_loaderProxy.get(), | |
| 
adamk
2013/12/05 22:50:12
No need for .get() if you're using operator*.
 
kinuko
2013/12/09 12:24:20
Done.
 | |
| 251 *m_workerGlobalScopeProxy.get(), | |
| 
adamk
2013/12/05 22:50:12
Same here.
 
kinuko
2013/12/09 12:24:20
Done.
 | |
| 252 startupData.release()); | |
| 
adamk
2013/12/05 22:50:12
More linebreaks...
 
kinuko
2013/12/09 12:24:20
Too chrome'y? I packed these in one line.
 | |
| 253 m_workerThread->start(); | |
| 198 } | 254 } | 
| 199 | 255 | 
| 200 } // namespace blink | 256 } // namespace blink | 
| OLD | NEW |