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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "modules/EventTargetModules.h" | 43 #include "modules/EventTargetModules.h" |
44 #include "modules/serviceworkers/CacheStorage.h" | 44 #include "modules/serviceworkers/CacheStorage.h" |
45 #include "modules/serviceworkers/FetchManager.h" | 45 #include "modules/serviceworkers/FetchManager.h" |
46 #include "modules/serviceworkers/Request.h" | 46 #include "modules/serviceworkers/Request.h" |
47 #include "modules/serviceworkers/ServiceWorkerClients.h" | 47 #include "modules/serviceworkers/ServiceWorkerClients.h" |
48 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 48 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
49 #include "modules/serviceworkers/ServiceWorkerThread.h" | 49 #include "modules/serviceworkers/ServiceWorkerThread.h" |
50 #include "modules/serviceworkers/WaitUntilObserver.h" | 50 #include "modules/serviceworkers/WaitUntilObserver.h" |
51 #include "platform/network/ResourceRequest.h" | 51 #include "platform/network/ResourceRequest.h" |
52 #include "platform/weborigin/KURL.h" | 52 #include "platform/weborigin/KURL.h" |
| 53 #include "public/platform/WebCallback.h" |
53 #include "public/platform/WebURL.h" | 54 #include "public/platform/WebURL.h" |
54 #include "wtf/CurrentTime.h" | 55 #include "wtf/CurrentTime.h" |
55 | 56 |
56 namespace blink { | 57 namespace blink { |
57 | 58 |
| 59 class ServiceWorkerGlobalScope::SkipWaitingCallback final : public WebCallback { |
| 60 WTF_MAKE_NONCOPYABLE(SkipWaitingCallback); |
| 61 public: |
| 62 explicit SkipWaitingCallback(PassRefPtr<ScriptPromiseResolver> resolver) |
| 63 : m_resolver(resolver) { } |
| 64 ~SkipWaitingCallback() { } |
| 65 |
| 66 void run() override |
| 67 { |
| 68 m_resolver->resolve(); |
| 69 } |
| 70 |
| 71 private: |
| 72 RefPtr<ScriptPromiseResolver> m_resolver; |
| 73 }; |
| 74 |
58 PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::creat
e(ServiceWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> s
tartupData) | 75 PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::creat
e(ServiceWorkerThread* thread, PassOwnPtrWillBeRawPtr<WorkerThreadStartupData> s
tartupData) |
59 { | 76 { |
60 RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeNoop(ne
w ServiceWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, t
hread, monotonicallyIncreasingTime(), startupData->m_starterOrigin, startupData-
>m_workerClients.release())); | 77 RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeNoop(ne
w ServiceWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, t
hread, monotonicallyIncreasingTime(), startupData->m_starterOrigin, startupData-
>m_workerClients.release())); |
61 | 78 |
62 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurity
Policy, startupData->m_contentSecurityPolicyType); | 79 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurity
Policy, startupData->m_contentSecurityPolicyType); |
63 | 80 |
64 return context.release(); | 81 return context.release(); |
65 } | 82 } |
66 | 83 |
67 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String
& userAgent, ServiceWorkerThread* thread, double timeOrigin, const SecurityOrigi
n* starterOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients) | 84 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String
& userAgent, ServiceWorkerThread* thread, double timeOrigin, const SecurityOrigi
n* starterOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 if (!m_clients) | 185 if (!m_clients) |
169 m_clients = ServiceWorkerClients::create(); | 186 m_clients = ServiceWorkerClients::create(); |
170 return m_clients; | 187 return m_clients; |
171 } | 188 } |
172 | 189 |
173 void ServiceWorkerGlobalScope::close(ExceptionState& exceptionState) | 190 void ServiceWorkerGlobalScope::close(ExceptionState& exceptionState) |
174 { | 191 { |
175 exceptionState.throwDOMException(InvalidAccessError, "Not supported."); | 192 exceptionState.throwDOMException(InvalidAccessError, "Not supported."); |
176 } | 193 } |
177 | 194 |
| 195 ScriptPromise ServiceWorkerGlobalScope::skipWaiting(ScriptState* scriptState) |
| 196 { |
| 197 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip
tState); |
| 198 ScriptPromise promise = resolver->promise(); |
| 199 |
| 200 ExecutionContext* executionContext = scriptState->executionContext(); |
| 201 ServiceWorkerGlobalScopeClient::from(executionContext)->skipWaiting(new Skip
WaitingCallback(resolver)); |
| 202 return promise; |
| 203 } |
| 204 |
178 bool ServiceWorkerGlobalScope::addEventListener(const AtomicString& eventType, P
assRefPtr<EventListener> listener, bool useCapture) | 205 bool ServiceWorkerGlobalScope::addEventListener(const AtomicString& eventType, P
assRefPtr<EventListener> listener, bool useCapture) |
179 { | 206 { |
180 if (m_didEvaluateScript) { | 207 if (m_didEvaluateScript) { |
181 if (eventType == EventTypeNames::install) { | 208 if (eventType == EventTypeNames::install) { |
182 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::
create(JSMessageSource, WarningMessageLevel, "Event handler of 'install' event m
ust be added on the initial evaluation of worker script."); | 209 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::
create(JSMessageSource, WarningMessageLevel, "Event handler of 'install' event m
ust be added on the initial evaluation of worker script."); |
183 addMessageToWorkerConsole(consoleMessage.release()); | 210 addMessageToWorkerConsole(consoleMessage.release()); |
184 } else if (eventType == EventTypeNames::activate) { | 211 } else if (eventType == EventTypeNames::activate) { |
185 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::
create(JSMessageSource, WarningMessageLevel, "Event handler of 'activate' event
must be added on the initial evaluation of worker script."); | 212 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::
create(JSMessageSource, WarningMessageLevel, "Event handler of 'activate' event
must be added on the initial evaluation of worker script."); |
186 addMessageToWorkerConsole(consoleMessage.release()); | 213 addMessageToWorkerConsole(consoleMessage.release()); |
187 } | 214 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage,
int scriptId, const String& sourceURL, int lineNumber, int columnNumber, PassRe
fPtrWillBeRawPtr<ScriptCallStack> callStack) | 261 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage,
int scriptId, const String& sourceURL, int lineNumber, int columnNumber, PassRe
fPtrWillBeRawPtr<ScriptCallStack> callStack) |
235 { | 262 { |
236 WorkerGlobalScope::logExceptionToConsole(errorMessage, scriptId, sourceURL,
lineNumber, columnNumber, callStack); | 263 WorkerGlobalScope::logExceptionToConsole(errorMessage, scriptId, sourceURL,
lineNumber, columnNumber, callStack); |
237 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(J
SMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber); | 264 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(J
SMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber); |
238 consoleMessage->setScriptId(scriptId); | 265 consoleMessage->setScriptId(scriptId); |
239 consoleMessage->setCallStack(callStack); | 266 consoleMessage->setCallStack(callStack); |
240 addMessageToWorkerConsole(consoleMessage.release()); | 267 addMessageToWorkerConsole(consoleMessage.release()); |
241 } | 268 } |
242 | 269 |
243 } // namespace blink | 270 } // namespace blink |
OLD | NEW |