Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp

Issue 723923002: ServiceWorker: Add support for .skipWaiting and controllerchange event(1/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/WebServiceWorkerSkipWaitingCallbacks.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 WebServiceWor kerSkipWaitingCallbacks {
60 WTF_MAKE_NONCOPYABLE(SkipWaitingCallback);
61 public:
62 explicit SkipWaitingCallback(PassRefPtr<ScriptPromiseResolver> resolver)
63 : m_resolver(resolver) { }
64 ~SkipWaitingCallback() { }
65
66 void onSuccess() 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 if (!m_clients) 137 if (!m_clients)
121 m_clients = ServiceWorkerClients::create(); 138 m_clients = ServiceWorkerClients::create();
122 return m_clients; 139 return m_clients;
123 } 140 }
124 141
125 void ServiceWorkerGlobalScope::close(ExceptionState& exceptionState) 142 void ServiceWorkerGlobalScope::close(ExceptionState& exceptionState)
126 { 143 {
127 exceptionState.throwDOMException(InvalidAccessError, "Not supported."); 144 exceptionState.throwDOMException(InvalidAccessError, "Not supported.");
128 } 145 }
129 146
147 ScriptPromise ServiceWorkerGlobalScope::skipWaiting(ScriptState* scriptState)
148 {
149 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
150 ScriptPromise promise = resolver->promise();
151
152 ExecutionContext* executionContext = scriptState->executionContext();
153 ServiceWorkerGlobalScopeClient::from(executionContext)->skipWaiting(new Skip WaitingCallback(resolver));
154 return promise;
155 }
156
130 bool ServiceWorkerGlobalScope::addEventListener(const AtomicString& eventType, P assRefPtr<EventListener> listener, bool useCapture) 157 bool ServiceWorkerGlobalScope::addEventListener(const AtomicString& eventType, P assRefPtr<EventListener> listener, bool useCapture)
131 { 158 {
132 if (m_didEvaluateScript) { 159 if (m_didEvaluateScript) {
133 if (eventType == EventTypeNames::install) { 160 if (eventType == EventTypeNames::install) {
134 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, WarningMessageLevel, "Event handler of 'install' event m ust be added on the initial evaluation of worker script."); 161 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, WarningMessageLevel, "Event handler of 'install' event m ust be added on the initial evaluation of worker script.");
135 addMessageToWorkerConsole(consoleMessage.release()); 162 addMessageToWorkerConsole(consoleMessage.release());
136 } else if (eventType == EventTypeNames::activate) { 163 } else if (eventType == EventTypeNames::activate) {
137 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, WarningMessageLevel, "Event handler of 'activate' event must be added on the initial evaluation of worker script."); 164 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, WarningMessageLevel, "Event handler of 'activate' event must be added on the initial evaluation of worker script.");
138 addMessageToWorkerConsole(consoleMessage.release()); 165 addMessageToWorkerConsole(consoleMessage.release());
139 } 166 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage, int scriptId, const String& sourceURL, int lineNumber, int columnNumber, PassRe fPtrWillBeRawPtr<ScriptCallStack> callStack) 213 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage, int scriptId, const String& sourceURL, int lineNumber, int columnNumber, PassRe fPtrWillBeRawPtr<ScriptCallStack> callStack)
187 { 214 {
188 WorkerGlobalScope::logExceptionToConsole(errorMessage, scriptId, sourceURL, lineNumber, columnNumber, callStack); 215 WorkerGlobalScope::logExceptionToConsole(errorMessage, scriptId, sourceURL, lineNumber, columnNumber, callStack);
189 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(J SMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber); 216 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(J SMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber);
190 consoleMessage->setScriptId(scriptId); 217 consoleMessage->setScriptId(scriptId);
191 consoleMessage->setCallStack(callStack); 218 consoleMessage->setCallStack(callStack);
192 addMessageToWorkerConsole(consoleMessage.release()); 219 addMessageToWorkerConsole(consoleMessage.release());
193 } 220 }
194 221
195 } // namespace blink 222 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698