| 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 26 matching lines...) Expand all Loading... |
| 37 #include "core/frame/csp/ContentSecurityPolicy.h" | 37 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 38 #include "core/inspector/InspectorInstrumentation.h" | 38 #include "core/inspector/InspectorInstrumentation.h" |
| 39 #include "core/inspector/WorkerDebuggerAgent.h" | 39 #include "core/inspector/WorkerDebuggerAgent.h" |
| 40 #include "core/inspector/WorkerInspectorController.h" | 40 #include "core/inspector/WorkerInspectorController.h" |
| 41 #include "core/loader/FrameLoadRequest.h" | 41 #include "core/loader/FrameLoadRequest.h" |
| 42 #include "core/workers/WorkerClients.h" | 42 #include "core/workers/WorkerClients.h" |
| 43 #include "core/workers/WorkerGlobalScope.h" | 43 #include "core/workers/WorkerGlobalScope.h" |
| 44 #include "core/workers/WorkerInspectorProxy.h" | 44 #include "core/workers/WorkerInspectorProxy.h" |
| 45 #include "core/workers/WorkerLoaderProxy.h" | 45 #include "core/workers/WorkerLoaderProxy.h" |
| 46 #include "core/workers/WorkerScriptLoader.h" | 46 #include "core/workers/WorkerScriptLoader.h" |
| 47 #include "core/workers/WorkerScriptLoaderClient.h" | |
| 48 #include "core/workers/WorkerThreadStartupData.h" | 47 #include "core/workers/WorkerThreadStartupData.h" |
| 49 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 48 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
| 50 #include "modules/serviceworkers/ServiceWorkerThread.h" | 49 #include "modules/serviceworkers/ServiceWorkerThread.h" |
| 51 #include "platform/SharedBuffer.h" | 50 #include "platform/SharedBuffer.h" |
| 52 #include "platform/heap/Handle.h" | 51 #include "platform/heap/Handle.h" |
| 53 #include "platform/network/ContentSecurityPolicyParsers.h" | 52 #include "platform/network/ContentSecurityPolicyParsers.h" |
| 54 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" | 53 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" |
| 55 #include "public/platform/Platform.h" | 54 #include "public/platform/Platform.h" |
| 56 #include "public/platform/WebServiceWorkerProvider.h" | 55 #include "public/platform/WebServiceWorkerProvider.h" |
| 57 #include "public/platform/WebURLRequest.h" | 56 #include "public/platform/WebURLRequest.h" |
| 58 #include "public/web/WebDevToolsAgent.h" | 57 #include "public/web/WebDevToolsAgent.h" |
| 59 #include "public/web/WebServiceWorkerContextClient.h" | 58 #include "public/web/WebServiceWorkerContextClient.h" |
| 60 #include "public/web/WebServiceWorkerNetworkProvider.h" | 59 #include "public/web/WebServiceWorkerNetworkProvider.h" |
| 61 #include "public/web/WebSettings.h" | 60 #include "public/web/WebSettings.h" |
| 62 #include "public/web/WebView.h" | 61 #include "public/web/WebView.h" |
| 63 #include "public/web/WebWorkerContentSettingsClientProxy.h" | 62 #include "public/web/WebWorkerContentSettingsClientProxy.h" |
| 64 #include "web/ServiceWorkerGlobalScopeClientImpl.h" | 63 #include "web/ServiceWorkerGlobalScopeClientImpl.h" |
| 65 #include "web/ServiceWorkerGlobalScopeProxy.h" | 64 #include "web/ServiceWorkerGlobalScopeProxy.h" |
| 66 #include "web/WebDataSourceImpl.h" | 65 #include "web/WebDataSourceImpl.h" |
| 67 #include "web/WebLocalFrameImpl.h" | 66 #include "web/WebLocalFrameImpl.h" |
| 68 #include "web/WorkerContentSettingsClient.h" | 67 #include "web/WorkerContentSettingsClient.h" |
| 69 #include "wtf/Functional.h" | 68 #include "wtf/Functional.h" |
| 70 | 69 |
| 71 namespace blink { | 70 namespace blink { |
| 72 | 71 |
| 73 // A thin wrapper for one-off script loading. | |
| 74 class WebEmbeddedWorkerImpl::Loader : public WorkerScriptLoaderClient { | |
| 75 public: | |
| 76 static PassOwnPtr<Loader> create() | |
| 77 { | |
| 78 return adoptPtr(new Loader()); | |
| 79 } | |
| 80 | |
| 81 virtual ~Loader() | |
| 82 { | |
| 83 m_scriptLoader->setClient(0); | |
| 84 } | |
| 85 | |
| 86 void load(ExecutionContext* loadingContext, const KURL& scriptURL, PassOwnPt
r<Closure> callback) | |
| 87 { | |
| 88 ASSERT(loadingContext); | |
| 89 m_callback = callback; | |
| 90 m_scriptLoader->setRequestContext(WebURLRequest::RequestContextServiceWo
rker); | |
| 91 m_scriptLoader->loadAsynchronously( | |
| 92 *loadingContext, scriptURL, DenyCrossOriginRequests, this); | |
| 93 } | |
| 94 | |
| 95 virtual void notifyFinished() override | |
| 96 { | |
| 97 (*m_callback)(); | |
| 98 } | |
| 99 | |
| 100 void cancel() | |
| 101 { | |
| 102 m_scriptLoader->cancel(); | |
| 103 } | |
| 104 | |
| 105 bool failed() const { return m_scriptLoader->failed(); } | |
| 106 const KURL& url() const { return m_scriptLoader->responseURL(); } | |
| 107 String script() const { return m_scriptLoader->script(); } | |
| 108 const Vector<char>* cachedMetadata() const { return m_scriptLoader->cachedMe
tadata(); } | |
| 109 PassOwnPtr<Vector<char>> releaseCachedMetadata() const { return m_scriptLoad
er->releaseCachedMetadata(); } | |
| 110 PassRefPtr<ContentSecurityPolicy> releaseContentSecurityPolicy() { return m_
scriptLoader->releaseContentSecurityPolicy(); } | |
| 111 | |
| 112 private: | |
| 113 Loader() : m_scriptLoader(WorkerScriptLoader::create()) | |
| 114 { | |
| 115 } | |
| 116 | |
| 117 RefPtr<WorkerScriptLoader> m_scriptLoader; | |
| 118 OwnPtr<Closure> m_callback; | |
| 119 }; | |
| 120 | |
| 121 WebEmbeddedWorker* WebEmbeddedWorker::create(WebServiceWorkerContextClient* clie
nt, WebWorkerContentSettingsClientProxy* contentSettingsClient) | 72 WebEmbeddedWorker* WebEmbeddedWorker::create(WebServiceWorkerContextClient* clie
nt, WebWorkerContentSettingsClientProxy* contentSettingsClient) |
| 122 { | 73 { |
| 123 return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(contentSettingsC
lient)); | 74 return new WebEmbeddedWorkerImpl(adoptPtr(client), adoptPtr(contentSettingsC
lient)); |
| 124 } | 75 } |
| 125 | 76 |
| 126 static HashSet<WebEmbeddedWorkerImpl*>& runningWorkerInstances() | 77 static HashSet<WebEmbeddedWorkerImpl*>& runningWorkerInstances() |
| 127 { | 78 { |
| 128 DEFINE_STATIC_LOCAL(HashSet<WebEmbeddedWorkerImpl*>, set, ()); | 79 DEFINE_STATIC_LOCAL(HashSet<WebEmbeddedWorkerImpl*>, set, ()); |
| 129 return set; | 80 return set; |
| 130 } | 81 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) | 290 void WebEmbeddedWorkerImpl::didFinishDocumentLoad(WebLocalFrame* frame) |
| 340 { | 291 { |
| 341 ASSERT(!m_mainScriptLoader); | 292 ASSERT(!m_mainScriptLoader); |
| 342 ASSERT(!m_networkProvider); | 293 ASSERT(!m_networkProvider); |
| 343 ASSERT(m_mainFrame); | 294 ASSERT(m_mainFrame); |
| 344 ASSERT(m_workerContextClient); | 295 ASSERT(m_workerContextClient); |
| 345 ASSERT(m_loadingShadowPage); | 296 ASSERT(m_loadingShadowPage); |
| 346 ASSERT(!m_askedToTerminate); | 297 ASSERT(!m_askedToTerminate); |
| 347 m_loadingShadowPage = false; | 298 m_loadingShadowPage = false; |
| 348 m_networkProvider = adoptPtr(m_workerContextClient->createServiceWorkerNetwo
rkProvider(frame->dataSource())); | 299 m_networkProvider = adoptPtr(m_workerContextClient->createServiceWorkerNetwo
rkProvider(frame->dataSource())); |
| 349 m_mainScriptLoader = Loader::create(); | 300 m_mainScriptLoader = adoptPtr(new WorkerScriptLoader()); |
| 350 m_mainScriptLoader->load( | 301 m_mainScriptLoader->setRequestContext(WebURLRequest::RequestContextServiceWo
rker); |
| 351 m_mainFrame->frame()->document(), | 302 m_mainScriptLoader->loadAsynchronously( |
| 303 *m_mainFrame->frame()->document(), |
| 352 m_workerStartData.scriptURL, | 304 m_workerStartData.scriptURL, |
| 305 DenyCrossOriginRequests, |
| 306 nullptr, |
| 353 bind(&WebEmbeddedWorkerImpl::onScriptLoaderFinished, this)); | 307 bind(&WebEmbeddedWorkerImpl::onScriptLoaderFinished, this)); |
| 354 } | 308 } |
| 355 | 309 |
| 356 void WebEmbeddedWorkerImpl::sendProtocolMessage(int callId, const WebString& mes
sage, const WebString& state) | 310 void WebEmbeddedWorkerImpl::sendProtocolMessage(int callId, const WebString& mes
sage, const WebString& state) |
| 357 { | 311 { |
| 358 m_workerContextClient->sendDevToolsMessage(callId, message, state); | 312 m_workerContextClient->sendDevToolsMessage(callId, message, state); |
| 359 } | 313 } |
| 360 | 314 |
| 361 void WebEmbeddedWorkerImpl::resumeStartup() | 315 void WebEmbeddedWorkerImpl::resumeStartup() |
| 362 { | 316 { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 m_mainScriptLoader.clear(); | 385 m_mainScriptLoader.clear(); |
| 432 | 386 |
| 433 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); | 387 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); |
| 434 m_loaderProxy = WorkerLoaderProxy::create(this); | 388 m_loaderProxy = WorkerLoaderProxy::create(this); |
| 435 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy); | 389 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy); |
| 436 m_workerThread->start(startupData.release()); | 390 m_workerThread->start(startupData.release()); |
| 437 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); | 391 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); |
| 438 } | 392 } |
| 439 | 393 |
| 440 } // namespace blink | 394 } // namespace blink |
| OLD | NEW |