| 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 16 matching lines...) Expand all Loading... |
| 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 "ServiceWorkerGlobalScopeClientImpl.h" | 34 #include "ServiceWorkerGlobalScopeClientImpl.h" |
| 35 #include "ServiceWorkerGlobalScopeProxy.h" | 35 #include "ServiceWorkerGlobalScopeProxy.h" |
| 36 #include "WebDataSourceImpl.h" | 36 #include "WebDataSourceImpl.h" |
| 37 #include "WebFrameImpl.h" | 37 #include "WebLocalFrameImpl.h" |
| 38 #include "WebServiceWorkerContextClient.h" | 38 #include "WebServiceWorkerContextClient.h" |
| 39 #include "WebServiceWorkerNetworkProvider.h" | 39 #include "WebServiceWorkerNetworkProvider.h" |
| 40 #include "WebView.h" | 40 #include "WebView.h" |
| 41 #include "WebWorkerPermissionClientProxy.h" | 41 #include "WebWorkerPermissionClientProxy.h" |
| 42 #include "WorkerPermissionClient.h" | 42 #include "WorkerPermissionClient.h" |
| 43 #include "core/dom/Document.h" | 43 #include "core/dom/Document.h" |
| 44 #include "core/loader/FrameLoadRequest.h" | 44 #include "core/loader/FrameLoadRequest.h" |
| 45 #include "core/loader/SubstituteData.h" | 45 #include "core/loader/SubstituteData.h" |
| 46 #include "core/workers/WorkerClients.h" | 46 #include "core/workers/WorkerClients.h" |
| 47 #include "core/workers/WorkerLoaderProxy.h" | 47 #include "core/workers/WorkerLoaderProxy.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 106 |
| 107 class WebEmbeddedWorkerImpl::LoaderProxy : public WorkerLoaderProxy { | 107 class WebEmbeddedWorkerImpl::LoaderProxy : public WorkerLoaderProxy { |
| 108 public: | 108 public: |
| 109 static PassOwnPtr<LoaderProxy> create(WebEmbeddedWorkerImpl& embeddedWorker) | 109 static PassOwnPtr<LoaderProxy> create(WebEmbeddedWorkerImpl& embeddedWorker) |
| 110 { | 110 { |
| 111 return adoptPtr(new LoaderProxy(embeddedWorker)); | 111 return adoptPtr(new LoaderProxy(embeddedWorker)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask> task) OVERRID
E | 114 virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask> task) OVERRID
E |
| 115 { | 115 { |
| 116 toWebFrameImpl(m_embeddedWorker.m_mainFrame)->frame()->document()->postT
ask(task); | 116 toWebLocalFrameImpl(m_embeddedWorker.m_mainFrame)->frame()->document()->
postTask(task); |
| 117 } | 117 } |
| 118 | 118 |
| 119 virtual bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask> ta
sk) OVERRIDE | 119 virtual bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask> ta
sk) OVERRIDE |
| 120 { | 120 { |
| 121 if (m_embeddedWorker.m_askedToTerminate || !m_embeddedWorker.m_workerThr
ead) | 121 if (m_embeddedWorker.m_askedToTerminate || !m_embeddedWorker.m_workerThr
ead) |
| 122 return false; | 122 return false; |
| 123 return m_embeddedWorker.m_workerThread->runLoop().postTask(task); | 123 return m_embeddedWorker.m_workerThread->runLoop().postTask(task); |
| 124 } | 124 } |
| 125 | 125 |
| 126 private: | 126 private: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 149 , m_mainFrame(0) | 149 , m_mainFrame(0) |
| 150 , m_askedToTerminate(false) | 150 , m_askedToTerminate(false) |
| 151 { | 151 { |
| 152 } | 152 } |
| 153 | 153 |
| 154 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() | 154 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() |
| 155 { | 155 { |
| 156 ASSERT(m_webView); | 156 ASSERT(m_webView); |
| 157 | 157 |
| 158 // Detach the client before closing the view to avoid getting called back. | 158 // Detach the client before closing the view to avoid getting called back. |
| 159 toWebFrameImpl(m_mainFrame)->setClient(0); | 159 toWebLocalFrameImpl(m_mainFrame)->setClient(0); |
| 160 | 160 |
| 161 m_webView->close(); | 161 m_webView->close(); |
| 162 m_mainFrame->close(); | 162 m_mainFrame->close(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void WebEmbeddedWorkerImpl::startWorkerContext( | 165 void WebEmbeddedWorkerImpl::startWorkerContext( |
| 166 const WebEmbeddedWorkerStartData& data) | 166 const WebEmbeddedWorkerStartData& data) |
| 167 { | 167 { |
| 168 ASSERT(!m_askedToTerminate); | 168 ASSERT(!m_askedToTerminate); |
| 169 ASSERT(!m_mainScriptLoader); | 169 ASSERT(!m_mainScriptLoader); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 189 // provide a context for loading on the main thread. | 189 // provide a context for loading on the main thread. |
| 190 // | 190 // |
| 191 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader. | 191 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader. |
| 192 // This code, and probably most of the code in this class should be shared | 192 // This code, and probably most of the code in this class should be shared |
| 193 // with SharedWorker. | 193 // with SharedWorker. |
| 194 ASSERT(!m_webView); | 194 ASSERT(!m_webView); |
| 195 m_webView = WebView::create(0); | 195 m_webView = WebView::create(0); |
| 196 m_mainFrame = WebLocalFrame::create(this); | 196 m_mainFrame = WebLocalFrame::create(this); |
| 197 m_webView->setMainFrame(m_mainFrame); | 197 m_webView->setMainFrame(m_mainFrame); |
| 198 | 198 |
| 199 WebFrameImpl* webFrame = toWebFrameImpl(m_webView->mainFrame()); | 199 WebLocalFrameImpl* webFrame = toWebLocalFrameImpl(m_webView->mainFrame()); |
| 200 | 200 |
| 201 // Construct substitute data source for the 'shadow page'. We only need it | 201 // Construct substitute data source for the 'shadow page'. We only need it |
| 202 // to have same origin as the worker so the loading checks work correctly. | 202 // to have same origin as the worker so the loading checks work correctly. |
| 203 CString content(""); | 203 CString content(""); |
| 204 int length = static_cast<int>(content.length()); | 204 int length = static_cast<int>(content.length()); |
| 205 RefPtr<SharedBuffer> buffer(SharedBuffer::create(content.data(), length)); | 205 RefPtr<SharedBuffer> buffer(SharedBuffer::create(content.data(), length)); |
| 206 webFrame->frame()->loader().load(FrameLoadRequest(0, ResourceRequest(m_worke
rStartData.scriptURL), SubstituteData(buffer, "text/html", "UTF-8", KURL()))); | 206 webFrame->frame()->loader().load(FrameLoadRequest(0, ResourceRequest(m_worke
rStartData.scriptURL), SubstituteData(buffer, "text/html", "UTF-8", KURL()))); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void WebEmbeddedWorkerImpl::willSendRequest( | 209 void WebEmbeddedWorkerImpl::willSendRequest( |
| 210 WebLocalFrame* frame, unsigned, WebURLRequest& request, | 210 WebLocalFrame* frame, unsigned, WebURLRequest& request, |
| 211 const WebURLResponse& redirectResponse) | 211 const WebURLResponse& redirectResponse) |
| 212 { | 212 { |
| 213 if (m_networkProvider) | 213 if (m_networkProvider) |
| 214 m_networkProvider->willSendRequest(frame->dataSource(), request); | 214 m_networkProvider->willSendRequest(frame->dataSource(), request); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) | 217 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) |
| 218 { | 218 { |
| 219 ASSERT(!m_mainScriptLoader); | 219 ASSERT(!m_mainScriptLoader); |
| 220 ASSERT(!m_networkProvider); | 220 ASSERT(!m_networkProvider); |
| 221 ASSERT(m_mainFrame); | 221 ASSERT(m_mainFrame); |
| 222 ASSERT(m_workerContextClient); | 222 ASSERT(m_workerContextClient); |
| 223 m_networkProvider = adoptPtr(m_workerContextClient->createServiceWorkerNetwo
rkProvider(frame->dataSource())); | 223 m_networkProvider = adoptPtr(m_workerContextClient->createServiceWorkerNetwo
rkProvider(frame->dataSource())); |
| 224 m_mainScriptLoader = Loader::create(); | 224 m_mainScriptLoader = Loader::create(); |
| 225 m_mainScriptLoader->load( | 225 m_mainScriptLoader->load( |
| 226 toWebFrameImpl(m_mainFrame)->frame()->document(), | 226 toWebLocalFrameImpl(m_mainFrame)->frame()->document(), |
| 227 m_workerStartData.scriptURL, | 227 m_workerStartData.scriptURL, |
| 228 bind(&WebEmbeddedWorkerImpl::onScriptLoaderFinished, this)); | 228 bind(&WebEmbeddedWorkerImpl::onScriptLoaderFinished, this)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() | 231 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() |
| 232 { | 232 { |
| 233 ASSERT(m_mainScriptLoader); | 233 ASSERT(m_mainScriptLoader); |
| 234 | 234 |
| 235 if (m_mainScriptLoader->failed() || m_askedToTerminate) { | 235 if (m_mainScriptLoader->failed() || m_askedToTerminate) { |
| 236 m_mainScriptLoader.clear(); | 236 m_mainScriptLoader.clear(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 257 m_workerStartData.userAgent, | 257 m_workerStartData.userAgent, |
| 258 m_mainScriptLoader->script(), | 258 m_mainScriptLoader->script(), |
| 259 startMode, | 259 startMode, |
| 260 // FIXME: fill appropriate CSP info and policy type. | 260 // FIXME: fill appropriate CSP info and policy type. |
| 261 String(), | 261 String(), |
| 262 ContentSecurityPolicyHeaderTypeEnforce, | 262 ContentSecurityPolicyHeaderTypeEnforce, |
| 263 workerClients.release()); | 263 workerClients.release()); |
| 264 | 264 |
| 265 m_mainScriptLoader.clear(); | 265 m_mainScriptLoader.clear(); |
| 266 | 266 |
| 267 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *toW
ebFrameImpl(m_mainFrame)->frame()->document(), *contextClient); | 267 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *toW
ebLocalFrameImpl(m_mainFrame)->frame()->document(), *contextClient); |
| 268 m_loaderProxy = LoaderProxy::create(*this); | 268 m_loaderProxy = LoaderProxy::create(*this); |
| 269 | 269 |
| 270 m_workerThread = ServiceWorkerThread::create(*m_loaderProxy, *m_workerGlobal
ScopeProxy, startupData.release()); | 270 m_workerThread = ServiceWorkerThread::create(*m_loaderProxy, *m_workerGlobal
ScopeProxy, startupData.release()); |
| 271 m_workerThread->start(); | 271 m_workerThread->start(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 } // namespace blink | 274 } // namespace blink |
| OLD | NEW |