Commit 62a4ff88 authored by dominicc@chromium.org's avatar dominicc@chromium.org

Dispatch the ServiceWorker "activate" event during activation

This will be tested by a Chromium browsertest. Service Worker plumbing that would make this possible to test in Blink isn't fitted yet.

BUG=356021

Review URL: https://codereview.chromium.org/214413004

git-svn-id: svn://svn.chromium.org/blink/trunk@170310 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f72c0df3
...@@ -41,6 +41,11 @@ PassRefPtrWillBeRawPtr<InstallPhaseEvent> InstallPhaseEvent::create() ...@@ -41,6 +41,11 @@ PassRefPtrWillBeRawPtr<InstallPhaseEvent> InstallPhaseEvent::create()
return adoptRefWillBeRefCountedGarbageCollected(new InstallPhaseEvent()); return adoptRefWillBeRefCountedGarbageCollected(new InstallPhaseEvent());
} }
PassRefPtrWillBeRawPtr<InstallPhaseEvent> InstallPhaseEvent::create(const AtomicString& type, const EventInit& eventInit, PassRefPtr<WaitUntilObserver> observer)
{
return adoptRefWillBeRefCountedGarbageCollected(new InstallPhaseEvent(type, eventInit, observer));
}
InstallPhaseEvent::~InstallPhaseEvent() InstallPhaseEvent::~InstallPhaseEvent()
{ {
} }
......
...@@ -41,6 +41,7 @@ class WaitUntilObserver; ...@@ -41,6 +41,7 @@ class WaitUntilObserver;
class InstallPhaseEvent : public Event { class InstallPhaseEvent : public Event {
public: public:
static PassRefPtrWillBeRawPtr<InstallPhaseEvent> create(); static PassRefPtrWillBeRawPtr<InstallPhaseEvent> create();
static PassRefPtrWillBeRawPtr<InstallPhaseEvent> create(const AtomicString& type, const EventInit&, PassRefPtr<WaitUntilObserver>);
virtual ~InstallPhaseEvent(); virtual ~InstallPhaseEvent();
......
...@@ -47,6 +47,7 @@ class ServiceWorkerGlobalScopeClient : public Supplement<WorkerClients> { ...@@ -47,6 +47,7 @@ class ServiceWorkerGlobalScopeClient : public Supplement<WorkerClients> {
public: public:
virtual ~ServiceWorkerGlobalScopeClient() { } virtual ~ServiceWorkerGlobalScopeClient() { }
virtual void didHandleActivateEvent(int eventID, blink::WebServiceWorkerEventResult) = 0;
virtual void didHandleInstallEvent(int installEventID, blink::WebServiceWorkerEventResult) = 0; virtual void didHandleInstallEvent(int installEventID, blink::WebServiceWorkerEventResult) = 0;
// A null response means no valid response was provided by the service worker, so fallback to native. // A null response means no valid response was provided by the service worker, so fallback to native.
virtual void didHandleFetchEvent(int fetchEventID, PassRefPtr<Response> = nullptr) = 0; virtual void didHandleFetchEvent(int fetchEventID, PassRefPtr<Response> = nullptr) = 0;
......
...@@ -53,9 +53,9 @@ private: ...@@ -53,9 +53,9 @@ private:
ResolveType m_resolveType; ResolveType m_resolveType;
}; };
PassRefPtr<WaitUntilObserver> WaitUntilObserver::create(ExecutionContext* context, int eventID) PassRefPtr<WaitUntilObserver> WaitUntilObserver::create(ExecutionContext* context, EventType type, int eventID)
{ {
return adoptRef(new WaitUntilObserver(context, eventID)); return adoptRef(new WaitUntilObserver(context, type, eventID));
} }
WaitUntilObserver::~WaitUntilObserver() WaitUntilObserver::~WaitUntilObserver()
...@@ -81,8 +81,9 @@ void WaitUntilObserver::waitUntil(const ScriptValue& value) ...@@ -81,8 +81,9 @@ void WaitUntilObserver::waitUntil(const ScriptValue& value)
ThenFunction::create(this, ThenFunction::Rejected)); ThenFunction::create(this, ThenFunction::Rejected));
} }
WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, int eventID) WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type, int eventID)
: ContextLifecycleObserver(context) : ContextLifecycleObserver(context)
, m_type(type)
, m_eventID(eventID) , m_eventID(eventID)
, m_pendingActivity(0) , m_pendingActivity(0)
, m_hasError(false) , m_hasError(false)
...@@ -108,8 +109,16 @@ void WaitUntilObserver::decrementPendingActivity() ...@@ -108,8 +109,16 @@ void WaitUntilObserver::decrementPendingActivity()
if (--m_pendingActivity || !executionContext()) if (--m_pendingActivity || !executionContext())
return; return;
ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::from(executionContext());
blink::WebServiceWorkerEventResult result = m_hasError ? blink::WebServiceWorkerEventResultRejected : blink::WebServiceWorkerEventResultCompleted; blink::WebServiceWorkerEventResult result = m_hasError ? blink::WebServiceWorkerEventResultRejected : blink::WebServiceWorkerEventResultCompleted;
ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleInstallEvent(m_eventID, result); switch (m_type) {
case Activate:
client->didHandleActivateEvent(m_eventID, result);
break;
case Install:
client->didHandleInstallEvent(m_eventID, result);
break;
}
observeContext(0); observeContext(0);
} }
......
...@@ -20,7 +20,12 @@ class WaitUntilObserver FINAL : ...@@ -20,7 +20,12 @@ class WaitUntilObserver FINAL :
public ContextLifecycleObserver, public ContextLifecycleObserver,
public RefCounted<WaitUntilObserver> { public RefCounted<WaitUntilObserver> {
public: public:
static PassRefPtr<WaitUntilObserver> create(ExecutionContext*, int eventID); enum EventType {
Activate,
Install
};
static PassRefPtr<WaitUntilObserver> create(ExecutionContext*, EventType, int eventID);
~WaitUntilObserver(); ~WaitUntilObserver();
...@@ -28,20 +33,21 @@ public: ...@@ -28,20 +33,21 @@ public:
void willDispatchEvent(); void willDispatchEvent();
void didDispatchEvent(); void didDispatchEvent();
// Observes the promise and delays calling didHandleInstallEvent() until // Observes the promise and delays calling the continuation until
// the given promise is resolved or rejected. // the given promise is resolved or rejected.
void waitUntil(const ScriptValue&); void waitUntil(const ScriptValue&);
private: private:
class ThenFunction; class ThenFunction;
WaitUntilObserver(ExecutionContext*, int eventID); WaitUntilObserver(ExecutionContext*, EventType, int eventID);
void reportError(const ScriptValue&); void reportError(const ScriptValue&);
void incrementPendingActivity(); void incrementPendingActivity();
void decrementPendingActivity(); void decrementPendingActivity();
EventType m_type;
int m_eventID; int m_eventID;
int m_pendingActivity; int m_pendingActivity;
bool m_hasError; bool m_hasError;
......
...@@ -48,6 +48,11 @@ ServiceWorkerGlobalScopeClientImpl::~ServiceWorkerGlobalScopeClientImpl() ...@@ -48,6 +48,11 @@ ServiceWorkerGlobalScopeClientImpl::~ServiceWorkerGlobalScopeClientImpl()
{ {
} }
void ServiceWorkerGlobalScopeClientImpl::didHandleActivateEvent(int eventID, WebServiceWorkerEventResult result)
{
m_client->didHandleActivateEvent(eventID, result);
}
void ServiceWorkerGlobalScopeClientImpl::didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result) void ServiceWorkerGlobalScopeClientImpl::didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result)
{ {
m_client->didHandleInstallEvent(installEventID, result); m_client->didHandleInstallEvent(installEventID, result);
...@@ -73,6 +78,7 @@ void ServiceWorkerGlobalScopeClientImpl::didHandleSyncEvent(int syncEventID) ...@@ -73,6 +78,7 @@ void ServiceWorkerGlobalScopeClientImpl::didHandleSyncEvent(int syncEventID)
ServiceWorkerGlobalScopeClientImpl::ServiceWorkerGlobalScopeClientImpl(PassOwnPtr<WebServiceWorkerContextClient> client) ServiceWorkerGlobalScopeClientImpl::ServiceWorkerGlobalScopeClientImpl(PassOwnPtr<WebServiceWorkerContextClient> client)
: m_client(client) : m_client(client)
{ {
ASSERT(m_client);
} }
} // namespace blink } // namespace blink
...@@ -43,6 +43,7 @@ public: ...@@ -43,6 +43,7 @@ public:
static PassOwnPtr<WebCore::ServiceWorkerGlobalScopeClient> create(PassOwnPtr<WebServiceWorkerContextClient>); static PassOwnPtr<WebCore::ServiceWorkerGlobalScopeClient> create(PassOwnPtr<WebServiceWorkerContextClient>);
virtual ~ServiceWorkerGlobalScopeClientImpl(); virtual ~ServiceWorkerGlobalScopeClientImpl();
virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult) OVERRIDE;
virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult) OVERRIDE; virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult) OVERRIDE;
virtual void didHandleFetchEvent(int fetchEventID, PassRefPtr<WebCore::Response>) OVERRIDE; virtual void didHandleFetchEvent(int fetchEventID, PassRefPtr<WebCore::Response>) OVERRIDE;
virtual void didHandleSyncEvent(int syncEventID) OVERRIDE; virtual void didHandleSyncEvent(int syncEventID) OVERRIDE;
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "core/workers/WorkerGlobalScope.h" #include "core/workers/WorkerGlobalScope.h"
#include "modules/serviceworkers/FetchEvent.h" #include "modules/serviceworkers/FetchEvent.h"
#include "modules/serviceworkers/InstallEvent.h" #include "modules/serviceworkers/InstallEvent.h"
#include "modules/serviceworkers/InstallPhaseEvent.h"
#include "modules/serviceworkers/WaitUntilObserver.h" #include "modules/serviceworkers/WaitUntilObserver.h"
#include "platform/NotImplemented.h" #include "platform/NotImplemented.h"
#include "wtf/Functional.h" #include "wtf/Functional.h"
...@@ -62,12 +63,21 @@ ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy() ...@@ -62,12 +63,21 @@ ServiceWorkerGlobalScopeProxy::~ServiceWorkerGlobalScopeProxy()
void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID) void ServiceWorkerGlobalScopeProxy::dispatchInstallEvent(int eventID)
{ {
ASSERT(m_workerGlobalScope); ASSERT(m_workerGlobalScope);
RefPtr<WaitUntilObserver> observer = WaitUntilObserver::create(m_workerGlobalScope, eventID); RefPtr<WaitUntilObserver> observer = WaitUntilObserver::create(m_workerGlobalScope, WaitUntilObserver::Install, eventID);
observer->willDispatchEvent(); observer->willDispatchEvent();
m_workerGlobalScope->dispatchEvent(InstallEvent::create(EventTypeNames::install, EventInit(), observer)); m_workerGlobalScope->dispatchEvent(InstallEvent::create(EventTypeNames::install, EventInit(), observer));
observer->didDispatchEvent(); observer->didDispatchEvent();
} }
void ServiceWorkerGlobalScopeProxy::dispatchActivateEvent(int eventID)
{
ASSERT(m_workerGlobalScope);
RefPtr<WaitUntilObserver> observer = WaitUntilObserver::create(m_workerGlobalScope, WaitUntilObserver::Activate, eventID);
observer->willDispatchEvent();
m_workerGlobalScope->dispatchEvent(InstallPhaseEvent::create(EventTypeNames::activate, EventInit(), observer));
observer->didDispatchEvent();
}
void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID) void ServiceWorkerGlobalScopeProxy::dispatchFetchEvent(int eventID)
{ {
ASSERT(m_workerGlobalScope); ASSERT(m_workerGlobalScope);
......
...@@ -66,6 +66,7 @@ public: ...@@ -66,6 +66,7 @@ public:
virtual ~ServiceWorkerGlobalScopeProxy(); virtual ~ServiceWorkerGlobalScopeProxy();
// WebServiceWorkerContextProxy overrides: // WebServiceWorkerContextProxy overrides:
virtual void dispatchActivateEvent(int) OVERRIDE;
virtual void dispatchInstallEvent(int) OVERRIDE; virtual void dispatchInstallEvent(int) OVERRIDE;
virtual void dispatchFetchEvent(int) OVERRIDE; virtual void dispatchFetchEvent(int) OVERRIDE;
virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray&) OVERRIDE; virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray&) OVERRIDE;
......
...@@ -78,6 +78,9 @@ public: ...@@ -78,6 +78,9 @@ public:
virtual void dispatchDevToolsMessage(const WebString&) { } virtual void dispatchDevToolsMessage(const WebString&) { }
virtual void saveDevToolsAgentState(const WebString&) { } virtual void saveDevToolsAgentState(const WebString&) { }
// ServiceWorker specific method.
virtual void didHandleActivateEvent(int eventID, blink::WebServiceWorkerEventResult result) { }
// ServiceWorker specific method. Called after InstallEvent (dispatched // ServiceWorker specific method. Called after InstallEvent (dispatched
// via WebServiceWorkerContextProxy) is handled by the ServiceWorker's // via WebServiceWorkerContextProxy) is handled by the ServiceWorker's
// script context. // script context.
......
...@@ -43,6 +43,7 @@ class WebServiceWorkerContextProxy { ...@@ -43,6 +43,7 @@ class WebServiceWorkerContextProxy {
public: public:
virtual ~WebServiceWorkerContextProxy() { } virtual ~WebServiceWorkerContextProxy() { }
virtual void dispatchActivateEvent(int eventID) = 0;
// FIXME: This needs to pass the active service worker info. // FIXME: This needs to pass the active service worker info.
virtual void dispatchInstallEvent(int installEventID) = 0; virtual void dispatchInstallEvent(int installEventID) = 0;
// FIXME: This needs to pass the fetch request info. // FIXME: This needs to pass the fetch request info.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment