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