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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerGlobalScope.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp b/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp
index d0b455dfd9bb1dc9b772c2cf460ee669cd71647e..0ebb688687089cf41970d41edfb3110fadcf1dfb 100644
--- a/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp
+++ b/Source/modules/serviceworkers/ServiceWorkerGlobalScope.cpp
@@ -65,6 +65,7 @@ PassRefPtrWillBeRawPtr<ServiceWorkerGlobalScope> ServiceWorkerGlobalScope::creat
ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(const KURL& url, const String& userAgent, ServiceWorkerThread* thread, double timeOrigin, const SecurityOrigin* starterOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
: WorkerGlobalScope(url, userAgent, thread, timeOrigin, starterOrigin, workerClients)
, m_fetchManager(adoptPtr(new FetchManager(this)))
+ , m_didEvaluateScript(false)
{
}
@@ -72,6 +73,11 @@ ServiceWorkerGlobalScope::~ServiceWorkerGlobalScope()
{
}
+void ServiceWorkerGlobalScope::didEvaluateWorkerScript()
+{
+ m_didEvaluateScript = true;
+}
+
void ServiceWorkerGlobalScope::stopFetch()
{
m_fetchManager.clear();
@@ -165,6 +171,20 @@ void ServiceWorkerGlobalScope::close(ExceptionState& exceptionState)
exceptionState.throwDOMException(InvalidAccessError, "Not supported.");
}
+bool ServiceWorkerGlobalScope::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
+{
+ if (m_didEvaluateScript) {
+ if (eventType == EventTypeNames::install) {
+ RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "Event handler of 'install' event must be added on the initial evaluation of worker script.");
+ addMessageToWorkerConsole(consoleMessage.release());
+ } else if (eventType == EventTypeNames::activate) {
+ RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "Event handler of 'activate' event must be added on the initial evaluation of worker script.");
+ addMessageToWorkerConsole(consoleMessage.release());
+ }
+ }
+ return WorkerGlobalScope::addEventListener(eventType, listener, useCapture);
+}
+
const AtomicString& ServiceWorkerGlobalScope::interfaceName() const
{
return EventTargetNames::ServiceWorkerGlobalScope;
« 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