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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 #include "modules/serviceworkers/ServiceWorkerRegistration.h" | 55 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
56 #include "modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.h" | 56 #include "modules/serviceworkers/ServiceWorkerScriptCachedMetadataHandler.h" |
57 #include "modules/serviceworkers/ServiceWorkerThread.h" | 57 #include "modules/serviceworkers/ServiceWorkerThread.h" |
58 #include "modules/serviceworkers/WaitUntilObserver.h" | 58 #include "modules/serviceworkers/WaitUntilObserver.h" |
59 #include "platform/Histogram.h" | 59 #include "platform/Histogram.h" |
60 #include "platform/network/ResourceRequest.h" | 60 #include "platform/network/ResourceRequest.h" |
61 #include "platform/weborigin/KURL.h" | 61 #include "platform/weborigin/KURL.h" |
62 #include "public/platform/Platform.h" | 62 #include "public/platform/Platform.h" |
63 #include "public/platform/WebURL.h" | 63 #include "public/platform/WebURL.h" |
64 #include "wtf/CurrentTime.h" | 64 #include "wtf/CurrentTime.h" |
| 65 #include "wtf/PtrUtil.h" |
| 66 #include <memory> |
65 | 67 |
66 namespace blink { | 68 namespace blink { |
67 | 69 |
68 ServiceWorkerGlobalScope* ServiceWorkerGlobalScope::create(ServiceWorkerThread*
thread, PassOwnPtr<WorkerThreadStartupData> startupData) | 70 ServiceWorkerGlobalScope* ServiceWorkerGlobalScope::create(ServiceWorkerThread*
thread, std::unique_ptr<WorkerThreadStartupData> startupData) |
69 { | 71 { |
70 // Note: startupData is finalized on return. After the relevant parts has be
en | 72 // Note: startupData is finalized on return. After the relevant parts has be
en |
71 // passed along to the created 'context'. | 73 // passed along to the created 'context'. |
72 ServiceWorkerGlobalScope* context = new ServiceWorkerGlobalScope(startupData
->m_scriptURL, startupData->m_userAgent, thread, monotonicallyIncreasingTime(),
std::move(startupData->m_starterOriginPrivilegeData), startupData->m_workerClien
ts.release()); | 74 ServiceWorkerGlobalScope* context = new ServiceWorkerGlobalScope(startupData
->m_scriptURL, startupData->m_userAgent, thread, monotonicallyIncreasingTime(),
std::move(startupData->m_starterOriginPrivilegeData), startupData->m_workerClien
ts.release()); |
73 | 75 |
74 context->setV8CacheOptions(startupData->m_v8CacheOptions); | 76 context->setV8CacheOptions(startupData->m_v8CacheOptions); |
75 context->applyContentSecurityPolicyFromVector(*startupData->m_contentSecurit
yPolicyHeaders); | 77 context->applyContentSecurityPolicyFromVector(*startupData->m_contentSecurit
yPolicyHeaders); |
76 context->setAddressSpace(startupData->m_addressSpace); | 78 context->setAddressSpace(startupData->m_addressSpace); |
77 OriginTrialContext::addTokens(context, startupData->m_originTrialTokens.get(
)); | 79 OriginTrialContext::addTokens(context, startupData->m_originTrialTokens.get(
)); |
78 | 80 |
79 return context; | 81 return context; |
80 } | 82 } |
81 | 83 |
82 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String
& userAgent, ServiceWorkerThread* thread, double timeOrigin, PassOwnPtr<Security
Origin::PrivilegeData> starterOriginPrivilegeData, WorkerClients* workerClients) | 84 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String
& userAgent, ServiceWorkerThread* thread, double timeOrigin, std::unique_ptr<Sec
urityOrigin::PrivilegeData> starterOriginPrivilegeData, WorkerClients* workerCli
ents) |
83 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, std::move(starterOri
ginPrivilegeData), workerClients) | 85 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, std::move(starterOri
ginPrivilegeData), workerClients) |
84 , m_didEvaluateScript(false) | 86 , m_didEvaluateScript(false) |
85 , m_hadErrorInTopLevelEventHandler(false) | 87 , m_hadErrorInTopLevelEventHandler(false) |
86 , m_eventNestingLevel(0) | 88 , m_eventNestingLevel(0) |
87 , m_scriptCount(0) | 89 , m_scriptCount(0) |
88 , m_scriptTotalSize(0) | 90 , m_scriptTotalSize(0) |
89 , m_scriptCachedMetadataTotalSize(0) | 91 , m_scriptCachedMetadataTotalSize(0) |
90 { | 92 { |
91 } | 93 } |
92 | 94 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 ScriptPromise promise = resolver->promise(); | 137 ScriptPromise promise = resolver->promise(); |
136 | 138 |
137 ServiceWorkerGlobalScopeClient::from(executionContext)->skipWaiting(new Call
backPromiseAdapter<void, void>(resolver)); | 139 ServiceWorkerGlobalScopeClient::from(executionContext)->skipWaiting(new Call
backPromiseAdapter<void, void>(resolver)); |
138 return promise; | 140 return promise; |
139 } | 141 } |
140 | 142 |
141 void ServiceWorkerGlobalScope::setRegistration(std::unique_ptr<WebServiceWorkerR
egistration::Handle> handle) | 143 void ServiceWorkerGlobalScope::setRegistration(std::unique_ptr<WebServiceWorkerR
egistration::Handle> handle) |
142 { | 144 { |
143 if (!getExecutionContext()) | 145 if (!getExecutionContext()) |
144 return; | 146 return; |
145 m_registration = ServiceWorkerRegistration::getOrCreate(getExecutionContext(
), adoptPtr(handle.release())); | 147 m_registration = ServiceWorkerRegistration::getOrCreate(getExecutionContext(
), wrapUnique(handle.release())); |
146 } | 148 } |
147 | 149 |
148 bool ServiceWorkerGlobalScope::addEventListenerInternal(const AtomicString& even
tType, EventListener* listener, const AddEventListenerOptions& options) | 150 bool ServiceWorkerGlobalScope::addEventListenerInternal(const AtomicString& even
tType, EventListener* listener, const AddEventListenerOptions& options) |
149 { | 151 { |
150 if (m_didEvaluateScript) { | 152 if (m_didEvaluateScript) { |
151 if (eventType == EventTypeNames::install) { | 153 if (eventType == EventTypeNames::install) { |
152 ConsoleMessage* consoleMessage = ConsoleMessage::create(JSMessageSou
rce, WarningMessageLevel, "Event handler of 'install' event must be added on the
initial evaluation of worker script."); | 154 ConsoleMessage* consoleMessage = ConsoleMessage::create(JSMessageSou
rce, WarningMessageLevel, "Event handler of 'install' event must be added on the
initial evaluation of worker script."); |
153 addMessageToWorkerConsole(consoleMessage); | 155 addMessageToWorkerConsole(consoleMessage); |
154 } else if (eventType == EventTypeNames::activate) { | 156 } else if (eventType == EventTypeNames::activate) { |
155 ConsoleMessage* consoleMessage = ConsoleMessage::create(JSMessageSou
rce, WarningMessageLevel, "Event handler of 'activate' event must be added on th
e initial evaluation of worker script."); | 157 ConsoleMessage* consoleMessage = ConsoleMessage::create(JSMessageSou
rce, WarningMessageLevel, "Event handler of 'activate' event must be added on th
e initial evaluation of worker script."); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 for (Vector<String>::const_iterator it = urls.begin(); it != urls.end(); ++i
t) | 203 for (Vector<String>::const_iterator it = urls.begin(); it != urls.end(); ++i
t) |
202 getExecutionContext()->removeURLFromMemoryCache(completeURL(*it)); | 204 getExecutionContext()->removeURLFromMemoryCache(completeURL(*it)); |
203 WorkerGlobalScope::importScripts(urls, exceptionState); | 205 WorkerGlobalScope::importScripts(urls, exceptionState); |
204 } | 206 } |
205 | 207 |
206 CachedMetadataHandler* ServiceWorkerGlobalScope::createWorkerScriptCachedMetadat
aHandler(const KURL& scriptURL, const Vector<char>* metaData) | 208 CachedMetadataHandler* ServiceWorkerGlobalScope::createWorkerScriptCachedMetadat
aHandler(const KURL& scriptURL, const Vector<char>* metaData) |
207 { | 209 { |
208 return ServiceWorkerScriptCachedMetadataHandler::create(this, scriptURL, met
aData); | 210 return ServiceWorkerScriptCachedMetadataHandler::create(this, scriptURL, met
aData); |
209 } | 211 } |
210 | 212 |
211 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage,
PassOwnPtr<SourceLocation> location) | 213 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage,
std::unique_ptr<SourceLocation> location) |
212 { | 214 { |
213 WorkerGlobalScope::logExceptionToConsole(errorMessage, location->clone()); | 215 WorkerGlobalScope::logExceptionToConsole(errorMessage, location->clone()); |
214 ConsoleMessage* consoleMessage = ConsoleMessage::create(JSMessageSource, Err
orMessageLevel, errorMessage, std::move(location)); | 216 ConsoleMessage* consoleMessage = ConsoleMessage::create(JSMessageSource, Err
orMessageLevel, errorMessage, std::move(location)); |
215 addMessageToWorkerConsole(consoleMessage); | 217 addMessageToWorkerConsole(consoleMessage); |
216 } | 218 } |
217 | 219 |
218 void ServiceWorkerGlobalScope::scriptLoaded(size_t scriptSize, size_t cachedMeta
dataSize) | 220 void ServiceWorkerGlobalScope::scriptLoaded(size_t scriptSize, size_t cachedMeta
dataSize) |
219 { | 221 { |
220 ++m_scriptCount; | 222 ++m_scriptCount; |
221 m_scriptTotalSize += scriptSize; | 223 m_scriptTotalSize += scriptSize; |
222 m_scriptCachedMetadataTotalSize += cachedMetadataSize; | 224 m_scriptCachedMetadataTotalSize += cachedMetadataSize; |
223 } | 225 } |
224 | 226 |
225 } // namespace blink | 227 } // namespace blink |
OLD | NEW |