Commit c735ffcc authored by jkarlin@chromium.org's avatar jkarlin@chromium.org

The blink half of the new ServiceWorker 'sync' event.

The browser side is https://codereview.chromium.org/205033002/

BUG=354112

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

git-svn-id: svn://svn.chromium.org/blink/trunk@170165 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 1303c4b9
...@@ -172,6 +172,7 @@ storage ...@@ -172,6 +172,7 @@ storage
submit submit
success success
suspend suspend
sync
textInput textInput
timeout timeout
timeupdate timeupdate
......
...@@ -54,6 +54,7 @@ public: ...@@ -54,6 +54,7 @@ public:
DEFINE_ATTRIBUTE_EVENT_LISTENER(install); DEFINE_ATTRIBUTE_EVENT_LISTENER(install);
DEFINE_ATTRIBUTE_EVENT_LISTENER(activate); DEFINE_ATTRIBUTE_EVENT_LISTENER(activate);
DEFINE_ATTRIBUTE_EVENT_LISTENER(fetch); DEFINE_ATTRIBUTE_EVENT_LISTENER(fetch);
DEFINE_ATTRIBUTE_EVENT_LISTENER(sync);
virtual void trace(Visitor*) OVERRIDE; virtual void trace(Visitor*) OVERRIDE;
......
...@@ -34,4 +34,5 @@ ...@@ -34,4 +34,5 @@
attribute EventHandler oninstall; attribute EventHandler oninstall;
attribute EventHandler onactivate; attribute EventHandler onactivate;
attribute EventHandler onfetch; attribute EventHandler onfetch;
attribute EventHandler onsync;
}; };
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
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;
virtual void didHandleSyncEvent(int syncEventID) = 0;
static const char* supplementName(); static const char* supplementName();
static ServiceWorkerGlobalScopeClient* from(ExecutionContext*); static ServiceWorkerGlobalScopeClient* from(ExecutionContext*);
......
...@@ -50,14 +50,11 @@ ServiceWorkerGlobalScopeClientImpl::~ServiceWorkerGlobalScopeClientImpl() ...@@ -50,14 +50,11 @@ ServiceWorkerGlobalScopeClientImpl::~ServiceWorkerGlobalScopeClientImpl()
void ServiceWorkerGlobalScopeClientImpl::didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result) void ServiceWorkerGlobalScopeClientImpl::didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result)
{ {
if (m_client) m_client->didHandleInstallEvent(installEventID, result);
m_client->didHandleInstallEvent(installEventID, result);
} }
void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int fetchEventID, PassRefPtr<WebCore::Response> response) void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int fetchEventID, PassRefPtr<WebCore::Response> response)
{ {
if (!m_client)
return;
if (!response) { if (!response) {
m_client->didHandleFetchEvent(fetchEventID); m_client->didHandleFetchEvent(fetchEventID);
return; return;
...@@ -68,6 +65,11 @@ void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int fetchEventID, P ...@@ -68,6 +65,11 @@ void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int fetchEventID, P
m_client->didHandleFetchEvent(fetchEventID, webResponse); m_client->didHandleFetchEvent(fetchEventID, webResponse);
} }
void ServiceWorkerGlobalScopeClientImpl::didHandleSyncEvent(int syncEventID)
{
m_client->didHandleSyncEvent(syncEventID);
}
ServiceWorkerGlobalScopeClientImpl::ServiceWorkerGlobalScopeClientImpl(PassOwnPtr<WebServiceWorkerContextClient> client) ServiceWorkerGlobalScopeClientImpl::ServiceWorkerGlobalScopeClientImpl(PassOwnPtr<WebServiceWorkerContextClient> client)
: m_client(client) : m_client(client)
{ {
......
...@@ -45,6 +45,7 @@ public: ...@@ -45,6 +45,7 @@ public:
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;
private: private:
ServiceWorkerGlobalScopeClientImpl(PassOwnPtr<WebServiceWorkerContextClient>); ServiceWorkerGlobalScopeClientImpl(PassOwnPtr<WebServiceWorkerContextClient>);
......
...@@ -85,6 +85,13 @@ void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& messag ...@@ -85,6 +85,13 @@ void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& messag
m_workerGlobalScope->dispatchEvent(MessageEvent::create(ports.release(), value)); m_workerGlobalScope->dispatchEvent(MessageEvent::create(ports.release(), value));
} }
void ServiceWorkerGlobalScopeProxy::dispatchSyncEvent(int eventID)
{
ASSERT(m_workerGlobalScope);
m_workerGlobalScope->dispatchEvent(Event::create(EventTypeNames::sync));
ServiceWorkerGlobalScopeClient::from(m_workerGlobalScope)->didHandleSyncEvent(eventID);
}
void ServiceWorkerGlobalScopeProxy::reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) void ServiceWorkerGlobalScopeProxy::reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
{ {
m_client.reportException(errorMessage, lineNumber, columnNumber, sourceURL); m_client.reportException(errorMessage, lineNumber, columnNumber, sourceURL);
......
...@@ -69,6 +69,7 @@ public: ...@@ -69,6 +69,7 @@ public:
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;
virtual void dispatchSyncEvent(int) OVERRIDE;
// WorkerReportingProxy overrides: // WorkerReportingProxy overrides:
virtual void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) OVERRIDE; virtual void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) OVERRIDE;
......
...@@ -95,6 +95,11 @@ public: ...@@ -95,6 +95,11 @@ public:
// Ownership of the returned object is transferred to the caller. // Ownership of the returned object is transferred to the caller.
virtual WebServiceWorkerNetworkProvider* createServiceWorkerNetworkProvider(blink::WebDataSource*) { return 0; } virtual WebServiceWorkerNetworkProvider* createServiceWorkerNetworkProvider(blink::WebDataSource*) { return 0; }
// ServiceWorker specific method. Called after SyncEvent (dispatched via
// WebServiceWorkerContextProxy) is handled by the ServiceWorker's script
// context.
virtual void didHandleSyncEvent(int syncEventID) { }
}; };
} // namespace blink } // namespace blink
......
...@@ -50,6 +50,10 @@ public: ...@@ -50,6 +50,10 @@ public:
virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray& channels) = 0; virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray& channels) = 0;
// Once the ServiceWorker has finished handling the sync event
// didHandleSyncEvent is called on the context client.
virtual void dispatchSyncEvent(int syncEventID) = 0;
virtual void resumeWorkerContext() { } virtual void resumeWorkerContext() { }
virtual void attachDevTools() { } virtual void attachDevTools() { }
virtual void reattachDevTools(const WebString& savedState) { } virtual void reattachDevTools(const WebString& savedState) { }
......
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