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

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

Issue 657213004: ServiceWorker: Issue a warning after initial execution of worker script (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Incorporate reviews and rebase Created 6 years, 2 months 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
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerGlobalScope.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeNoop(ne w ServiceWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, t hread, monotonicallyIncreasingTime(), startupData->m_starterOrigin, startupData- >m_workerClients.release())); 58 RefPtrWillBeRawPtr<ServiceWorkerGlobalScope> context = adoptRefWillBeNoop(ne w ServiceWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, t hread, monotonicallyIncreasingTime(), startupData->m_starterOrigin, startupData- >m_workerClients.release()));
59 59
60 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurity Policy, startupData->m_contentSecurityPolicyType); 60 context->applyContentSecurityPolicyFromString(startupData->m_contentSecurity Policy, startupData->m_contentSecurityPolicyType);
61 61
62 return context.release(); 62 return context.release();
63 } 63 }
64 64
65 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String & userAgent, ServiceWorkerThread* thread, double timeOrigin, const SecurityOrigi n* starterOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients) 65 ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String & userAgent, ServiceWorkerThread* thread, double timeOrigin, const SecurityOrigi n* starterOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
66 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOrigin, worke rClients) 66 : WorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOrigin, worke rClients)
67 , m_fetchManager(adoptPtr(new FetchManager(this))) 67 , m_fetchManager(adoptPtr(new FetchManager(this)))
68 , m_didEvaluateScript(false)
68 { 69 {
69 } 70 }
70 71
71 ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope() 72 ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope()
72 { 73 {
73 } 74 }
74 75
76 void ServiceWorkerGlobalScope::didEvaluateWorkerScript()
77 {
78 m_didEvaluateScript = true;
79 }
80
75 void ServiceWorkerGlobalScope::stopFetch() 81 void ServiceWorkerGlobalScope::stopFetch()
76 { 82 {
77 m_fetchManager.clear(); 83 m_fetchManager.clear();
78 } 84 }
79 85
80 String ServiceWorkerGlobalScope::scope(ExecutionContext* context) 86 String ServiceWorkerGlobalScope::scope(ExecutionContext* context)
81 { 87 {
82 return ServiceWorkerGlobalScopeClient::from(context)->scope().string(); 88 return ServiceWorkerGlobalScopeClient::from(context)->scope().string();
83 } 89 }
84 90
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (!m_clients) 164 if (!m_clients)
159 m_clients = ServiceWorkerClients::create(); 165 m_clients = ServiceWorkerClients::create();
160 return m_clients; 166 return m_clients;
161 } 167 }
162 168
163 void ServiceWorkerGlobalScope::close(ExceptionState& exceptionState) 169 void ServiceWorkerGlobalScope::close(ExceptionState& exceptionState)
164 { 170 {
165 exceptionState.throwDOMException(InvalidAccessError, "Not supported."); 171 exceptionState.throwDOMException(InvalidAccessError, "Not supported.");
166 } 172 }
167 173
174 bool ServiceWorkerGlobalScope::addEventListener(const AtomicString& eventType, P assRefPtr<EventListener> listener, bool useCapture)
175 {
176 if (m_didEvaluateScript) {
177 if (eventType == EventTypeNames::install) {
178 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, WarningMessageLevel, "Event handler of 'install' event m ust be added on the initial evaluation of worker script.");
179 addMessageToWorkerConsole(consoleMessage.release());
180 } else if (eventType == EventTypeNames::activate) {
181 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(JSMessageSource, WarningMessageLevel, "Event handler of 'activate' event must be added on the initial evaluation of worker script.");
182 addMessageToWorkerConsole(consoleMessage.release());
183 }
184 }
185 return WorkerGlobalScope::addEventListener(eventType, listener, useCapture);
186 }
187
168 const AtomicString& ServiceWorkerGlobalScope::interfaceName() const 188 const AtomicString& ServiceWorkerGlobalScope::interfaceName() const
169 { 189 {
170 return EventTargetNames::ServiceWorkerGlobalScope; 190 return EventTargetNames::ServiceWorkerGlobalScope;
171 } 191 }
172 192
173 void ServiceWorkerGlobalScope::trace(Visitor* visitor) 193 void ServiceWorkerGlobalScope::trace(Visitor* visitor)
174 { 194 {
175 visitor->trace(m_clients); 195 visitor->trace(m_clients);
176 visitor->trace(m_caches); 196 visitor->trace(m_caches);
177 WorkerGlobalScope::trace(visitor); 197 WorkerGlobalScope::trace(visitor);
(...skipping 12 matching lines...) Expand all
190 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage, int scriptId, const String& sourceURL, int lineNumber, int columnNumber, PassRe fPtrWillBeRawPtr<ScriptCallStack> callStack) 210 void ServiceWorkerGlobalScope::logExceptionToConsole(const String& errorMessage, int scriptId, const String& sourceURL, int lineNumber, int columnNumber, PassRe fPtrWillBeRawPtr<ScriptCallStack> callStack)
191 { 211 {
192 WorkerGlobalScope::logExceptionToConsole(errorMessage, scriptId, sourceURL, lineNumber, columnNumber, callStack); 212 WorkerGlobalScope::logExceptionToConsole(errorMessage, scriptId, sourceURL, lineNumber, columnNumber, callStack);
193 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(J SMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber); 213 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(J SMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber);
194 consoleMessage->setScriptId(scriptId); 214 consoleMessage->setScriptId(scriptId);
195 consoleMessage->setCallStack(callStack); 215 consoleMessage->setCallStack(callStack);
196 addMessageToWorkerConsole(consoleMessage.release()); 216 addMessageToWorkerConsole(consoleMessage.release());
197 } 217 }
198 218
199 } // namespace blink 219 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerGlobalScope.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698