| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/workers/InProcessWorkerBase.h" | 6 #include "core/workers/InProcessWorkerBase.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "core/events/MessageEvent.h" | 9 #include "core/events/MessageEvent.h" |
| 10 #include "core/fetch/ResourceFetcher.h" | 10 #include "core/fetch/ResourceFetcher.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool InProcessWorkerBase::initialize(ExecutionContext* context, const String& ur
l, ExceptionState& exceptionState) | 46 bool InProcessWorkerBase::initialize(ExecutionContext* context, const String& ur
l, ExceptionState& exceptionState) |
| 47 { | 47 { |
| 48 suspendIfNeeded(); | 48 suspendIfNeeded(); |
| 49 | 49 |
| 50 KURL scriptURL = resolveURL(url, exceptionState); | 50 KURL scriptURL = resolveURL(url, exceptionState); |
| 51 if (scriptURL.isEmpty()) | 51 if (scriptURL.isEmpty()) |
| 52 return false; | 52 return false; |
| 53 | 53 |
| 54 m_scriptLoader = WorkerScriptLoader::create(); | 54 m_scriptLoader = adoptPtr(new WorkerScriptLoader()); |
| 55 m_scriptLoader->loadAsynchronously(*context, scriptURL, DenyCrossOriginReque
sts, this); | 55 m_scriptLoader->loadAsynchronously( |
| 56 *context, |
| 57 scriptURL, |
| 58 DenyCrossOriginRequests, |
| 59 bind(&InProcessWorkerBase::onResponse, this), |
| 60 bind(&InProcessWorkerBase::onFinished, this)); |
| 56 | 61 |
| 57 m_contextProxy = createWorkerGlobalScopeProxy(context); | 62 m_contextProxy = createWorkerGlobalScopeProxy(context); |
| 58 | 63 |
| 59 return true; | 64 return true; |
| 60 } | 65 } |
| 61 | 66 |
| 62 void InProcessWorkerBase::terminate() | 67 void InProcessWorkerBase::terminate() |
| 63 { | 68 { |
| 64 if (m_contextProxy) | 69 if (m_contextProxy) |
| 65 m_contextProxy->terminateWorkerGlobalScope(); | 70 m_contextProxy->terminateWorkerGlobalScope(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 return (m_contextProxy && m_contextProxy->hasPendingActivity()) || m_scriptL
oader; | 81 return (m_contextProxy && m_contextProxy->hasPendingActivity()) || m_scriptL
oader; |
| 77 } | 82 } |
| 78 | 83 |
| 79 PassRefPtr<ContentSecurityPolicy> InProcessWorkerBase::contentSecurityPolicy() | 84 PassRefPtr<ContentSecurityPolicy> InProcessWorkerBase::contentSecurityPolicy() |
| 80 { | 85 { |
| 81 if (m_scriptLoader) | 86 if (m_scriptLoader) |
| 82 return m_scriptLoader->contentSecurityPolicy(); | 87 return m_scriptLoader->contentSecurityPolicy(); |
| 83 return m_contentSecurityPolicy; | 88 return m_contentSecurityPolicy; |
| 84 } | 89 } |
| 85 | 90 |
| 86 void InProcessWorkerBase::didReceiveResponse(unsigned long identifier, const Res
ourceResponse& response) | 91 void InProcessWorkerBase::onResponse() |
| 87 { | 92 { |
| 88 InspectorInstrumentation::didReceiveScriptResponse(executionContext(), ident
ifier); | 93 InspectorInstrumentation::didReceiveScriptResponse(executionContext(), m_scr
iptLoader->identifier()); |
| 89 } | 94 } |
| 90 | 95 |
| 91 void InProcessWorkerBase::notifyFinished() | 96 void InProcessWorkerBase::onFinished() |
| 92 { | 97 { |
| 93 if (m_scriptLoader->failed()) { | 98 if (m_scriptLoader->failed()) { |
| 94 dispatchEvent(Event::createCancelable(EventTypeNames::error)); | 99 dispatchEvent(Event::createCancelable(EventTypeNames::error)); |
| 95 } else { | 100 } else { |
| 96 ASSERT(m_contextProxy); | 101 ASSERT(m_contextProxy); |
| 97 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart; | 102 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart; |
| 98 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio
nContext())) | 103 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(executio
nContext())) |
| 99 startMode = PauseWorkerGlobalScopeOnStart; | 104 startMode = PauseWorkerGlobalScopeOnStart; |
| 100 m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionC
ontext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode)
; | 105 m_contextProxy->startWorkerGlobalScope(m_scriptLoader->url(), executionC
ontext()->userAgent(m_scriptLoader->url()), m_scriptLoader->script(), startMode)
; |
| 101 InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoa
der->identifier(), m_scriptLoader->script()); | 106 InspectorInstrumentation::scriptImported(executionContext(), m_scriptLoa
der->identifier(), m_scriptLoader->script()); |
| 102 } | 107 } |
| 103 m_contentSecurityPolicy = m_scriptLoader->releaseContentSecurityPolicy(); | 108 m_contentSecurityPolicy = m_scriptLoader->releaseContentSecurityPolicy(); |
| 104 m_scriptLoader = nullptr; | 109 m_scriptLoader = nullptr; |
| 105 } | 110 } |
| 106 | 111 |
| 107 DEFINE_TRACE(InProcessWorkerBase) | 112 DEFINE_TRACE(InProcessWorkerBase) |
| 108 { | 113 { |
| 109 AbstractWorker::trace(visitor); | 114 AbstractWorker::trace(visitor); |
| 110 } | 115 } |
| 111 | 116 |
| 112 } // namespace blink | 117 } // namespace blink |
| OLD | NEW |