| 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 private: | 115 private: |
| 116 Loader() : m_scriptLoader(WorkerScriptLoader::create()) | 116 Loader() : m_scriptLoader(WorkerScriptLoader::create()) |
| 117 { | 117 { |
| 118 } | 118 } |
| 119 | 119 |
| 120 RefPtr<WorkerScriptLoader> m_scriptLoader; | 120 RefPtr<WorkerScriptLoader> m_scriptLoader; |
| 121 OwnPtr<Closure> m_callback; | 121 OwnPtr<Closure> m_callback; |
| 122 RefPtr<ContentSecurityPolicy> m_contentSecurityPolicy; | 122 RefPtr<ContentSecurityPolicy> m_contentSecurityPolicy; |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 class WebEmbeddedWorkerImpl::LoaderProxy : public WorkerLoaderProxy { | 125 WebEmbeddedWorker* WebEmbeddedWorker::create(WebServiceWorkerContextClient* clie
nt, WebWorkerPermissionClientProxy* permissionClient) |
| 126 public: | |
| 127 static PassOwnPtr<LoaderProxy> create(WebEmbeddedWorkerImpl& embeddedWorker) | |
| 128 { | |
| 129 return adoptPtr(new LoaderProxy(embeddedWorker)); | |
| 130 } | |
| 131 | |
| 132 virtual void postTaskToLoader(PassOwnPtr<ExecutionContextTask> task) overrid
e | |
| 133 { | |
| 134 toWebLocalFrameImpl(m_embeddedWorker.m_mainFrame)->frame()->document()->
postTask(task); | |
| 135 } | |
| 136 | |
| 137 virtual bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask> ta
sk) override | |
| 138 { | |
| 139 if (m_embeddedWorker.m_askedToTerminate || !m_embeddedWorker.m_workerThr
ead) | |
| 140 return false; | |
| 141 m_embeddedWorker.m_workerThread->postTask(task); | |
| 142 return !m_embeddedWorker.m_workerThread->terminated(); | |
| 143 } | |
| 144 | |
| 145 private: | |
| 146 explicit LoaderProxy(WebEmbeddedWorkerImpl& embeddedWorker) | |
| 147 : m_embeddedWorker(embeddedWorker) | |
| 148 { | |
| 149 } | |
| 150 | |
| 151 // Not owned, embedded worker owns this. | |
| 152 WebEmbeddedWorkerImpl& m_embeddedWorker; | |
| 153 }; | |
| 154 | |
| 155 WebEmbeddedWorker* WebEmbeddedWorker::create( | |
| 156 WebServiceWorkerContextClient* client, | |
| 157 WebWorkerPermissionClientProxy* permissionClient) | |
| 158 { | 126 { |
| 159 return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(permissionClient
)); | 127 return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(permissionClient
)); |
| 160 } | 128 } |
| 161 | 129 |
| 162 static HashSet<WebEmbeddedWorkerImpl*>& runningWorkerInstances() | 130 static HashSet<WebEmbeddedWorkerImpl*>& runningWorkerInstances() |
| 163 { | 131 { |
| 164 DEFINE_STATIC_LOCAL(HashSet<WebEmbeddedWorkerImpl*>, set, ()); | 132 DEFINE_STATIC_LOCAL(HashSet<WebEmbeddedWorkerImpl*>, set, ()); |
| 165 return set; | 133 return set; |
| 166 } | 134 } |
| 167 | 135 |
| 168 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl( | 136 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl(PassOwnPtr<WebServiceWorkerContextC
lient> client, PassOwnPtr<WebWorkerPermissionClientProxy> permissionClient) |
| 169 PassOwnPtr<WebServiceWorkerContextClient> client, | |
| 170 PassOwnPtr<WebWorkerPermissionClientProxy> permissionClient) | |
| 171 : m_workerContextClient(client) | 137 : m_workerContextClient(client) |
| 172 , m_permissionClient(permissionClient) | 138 , m_permissionClient(permissionClient) |
| 173 , m_workerInspectorProxy(WorkerInspectorProxy::create()) | 139 , m_workerInspectorProxy(WorkerInspectorProxy::create()) |
| 174 , m_webView(0) | 140 , m_webView(0) |
| 175 , m_mainFrame(0) | 141 , m_mainFrame(0) |
| 176 , m_askedToTerminate(false) | 142 , m_askedToTerminate(false) |
| 177 , m_pauseAfterDownloadState(DontPauseAfterDownload) | 143 , m_pauseAfterDownloadState(DontPauseAfterDownload) |
| 178 , m_waitingForDebuggerState(NotWaitingForDebugger) | 144 , m_waitingForDebuggerState(NotWaitingForDebugger) |
| 179 { | 145 { |
| 180 runningWorkerInstances().add(this); | 146 runningWorkerInstances().add(this); |
| 181 } | 147 } |
| 182 | 148 |
| 183 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() | 149 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() |
| 184 { | 150 { |
| 185 // Prevent onScriptLoaderFinished from deleting 'this'. | 151 // Prevent onScriptLoaderFinished from deleting 'this'. |
| 186 m_askedToTerminate = true; | 152 m_askedToTerminate = true; |
| 187 | 153 |
| 188 if (m_workerThread) | 154 if (m_workerThread) |
| 189 m_workerThread->terminateAndWait(); | 155 m_workerThread->terminateAndWait(); |
| 190 | 156 |
| 191 ASSERT(runningWorkerInstances().contains(this)); | 157 ASSERT(runningWorkerInstances().contains(this)); |
| 192 runningWorkerInstances().remove(this); | 158 runningWorkerInstances().remove(this); |
| 193 ASSERT(m_webView); | 159 ASSERT(m_webView); |
| 194 | 160 |
| 195 // Detach the client before closing the view to avoid getting called back. | 161 // Detach the client before closing the view to avoid getting called back. |
| 196 toWebLocalFrameImpl(m_mainFrame)->setClient(0); | 162 toWebLocalFrameImpl(m_mainFrame)->setClient(0); |
| 197 | 163 |
| 198 m_webView->close(); | 164 m_webView->close(); |
| 199 m_mainFrame->close(); | 165 m_mainFrame->close(); |
| 166 if (m_loaderProxy) |
| 167 m_loaderProxy->detachProvider(this); |
| 200 } | 168 } |
| 201 | 169 |
| 202 void WebEmbeddedWorkerImpl::terminateAll() | 170 void WebEmbeddedWorkerImpl::terminateAll() |
| 203 { | 171 { |
| 204 HashSet<WebEmbeddedWorkerImpl*> instances = runningWorkerInstances(); | 172 HashSet<WebEmbeddedWorkerImpl*> instances = runningWorkerInstances(); |
| 205 for (HashSet<WebEmbeddedWorkerImpl*>::iterator it = instances.begin(), itEnd
= instances.end(); it != itEnd; ++it) { | 173 for (HashSet<WebEmbeddedWorkerImpl*>::iterator it = instances.begin(), itEnd
= instances.end(); it != itEnd; ++it) { |
| 206 (*it)->terminateWorkerContext(); | 174 (*it)->terminateWorkerContext(); |
| 207 } | 175 } |
| 208 } | 176 } |
| 209 | 177 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 255 } |
| 288 | 256 |
| 289 void WebEmbeddedWorkerImpl::postMessageToPageInspector(const String& message) | 257 void WebEmbeddedWorkerImpl::postMessageToPageInspector(const String& message) |
| 290 { | 258 { |
| 291 WorkerInspectorProxy::PageInspector* pageInspector = m_workerInspectorProxy-
>pageInspector(); | 259 WorkerInspectorProxy::PageInspector* pageInspector = m_workerInspectorProxy-
>pageInspector(); |
| 292 if (!pageInspector) | 260 if (!pageInspector) |
| 293 return; | 261 return; |
| 294 pageInspector->dispatchMessageFromWorker(message); | 262 pageInspector->dispatchMessageFromWorker(message); |
| 295 } | 263 } |
| 296 | 264 |
| 265 void WebEmbeddedWorkerImpl::postTaskToLoader(PassOwnPtr<ExecutionContextTask> ta
sk) |
| 266 { |
| 267 toWebLocalFrameImpl(m_mainFrame)->frame()->document()->postTask(task); |
| 268 } |
| 269 |
| 270 bool WebEmbeddedWorkerImpl::postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionCont
extTask> task) |
| 271 { |
| 272 if (m_askedToTerminate || !m_workerThread) |
| 273 return false; |
| 274 |
| 275 m_workerThread->postTask(task); |
| 276 return !m_workerThread->terminated(); |
| 277 } |
| 278 |
| 297 void WebEmbeddedWorkerImpl::prepareShadowPageForLoader() | 279 void WebEmbeddedWorkerImpl::prepareShadowPageForLoader() |
| 298 { | 280 { |
| 299 // Create 'shadow page', which is never displayed and is used mainly to | 281 // Create 'shadow page', which is never displayed and is used mainly to |
| 300 // provide a context for loading on the main thread. | 282 // provide a context for loading on the main thread. |
| 301 // | 283 // |
| 302 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader. | 284 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader. |
| 303 // This code, and probably most of the code in this class should be shared | 285 // This code, and probably most of the code in this class should be shared |
| 304 // with SharedWorker. | 286 // with SharedWorker. |
| 305 ASSERT(!m_webView); | 287 ASSERT(!m_webView); |
| 306 m_webView = WebView::create(0); | 288 m_webView = WebView::create(0); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 m_mainScriptLoader->script(), | 416 m_mainScriptLoader->script(), |
| 435 startMode, | 417 startMode, |
| 436 document->contentSecurityPolicy()->deprecatedHeader(), | 418 document->contentSecurityPolicy()->deprecatedHeader(), |
| 437 document->contentSecurityPolicy()->deprecatedHeaderType(), | 419 document->contentSecurityPolicy()->deprecatedHeaderType(), |
| 438 starterOrigin, | 420 starterOrigin, |
| 439 workerClients.release()); | 421 workerClients.release()); |
| 440 | 422 |
| 441 m_mainScriptLoader.clear(); | 423 m_mainScriptLoader.clear(); |
| 442 | 424 |
| 443 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); | 425 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); |
| 444 m_loaderProxy = LoaderProxy::create(*this); | 426 m_loaderProxy = WorkerLoaderProxy::create(this); |
| 445 m_workerThread = ServiceWorkerThread::create(*m_loaderProxy, *m_workerGlobal
ScopeProxy, startupData.release()); | 427 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy, startupData.release()); |
| 446 m_workerThread->start(); | 428 m_workerThread->start(); |
| 447 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); | 429 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); |
| 448 } | 430 } |
| 449 | 431 |
| 450 } // namespace blink | 432 } // namespace blink |
| OLD | NEW |