Push API: define push event on Service Worker.

Should be safe to reland after this build fix:
https://codereview.chromium.org/325483002/

BUG=350394
TBR=peter@chromium.org,dominicc@chromium.org,jochen@chromium.org,michaeln@chromium.org,kinuko@chromium.org

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

git-svn-id: svn://svn.chromium.org/blink/trunk@175804 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4607f604
......@@ -259,6 +259,7 @@ PopStateEvent
ProcessingInstruction
ProgressEvent
Promise
PushEvent
RGBColor
RTCIceCandidate
RTCSessionDescription
......
......@@ -145,6 +145,7 @@ pointerlockchange
pointerlockerror
popstate
progress
push
ratechange
ready
readystatechange
......
......@@ -110,6 +110,7 @@
'notifications/Notification.idl',
'notifications/NotificationPermissionCallback.idl',
'performance/WorkerPerformance.idl',
'push_messaging/PushEvent.idl',
'push_messaging/PushManager.idl',
'push_messaging/PushRegistration.idl',
'quota/DeprecatedStorageInfo.idl',
......@@ -228,6 +229,7 @@
'performance/SharedWorkerPerformance.idl',
'performance/WorkerGlobalScopePerformance.idl',
'push_messaging/NavigatorPushManager.idl',
'push_messaging/ServiceWorkerGlobalScopePush.idl',
'quota/NavigatorStorageQuota.idl',
'quota/WindowQuota.idl',
'quota/WorkerNavigatorStorageQuota.idl',
......@@ -255,6 +257,7 @@
'mediastream/RTCDTMFToneChangeEvent.idl',
'mediastream/RTCDataChannelEvent.idl',
'mediastream/RTCIceCandidateEvent.idl',
'push_messaging/PushEvent.idl',
'serviceworkers/FetchEvent.idl',
'serviceworkers/InstallEvent.idl',
'serviceworkers/InstallPhaseEvent.idl',
......@@ -609,10 +612,13 @@
'push_messaging/PushController.h',
'push_messaging/PushError.cpp',
'push_messaging/PushError.h',
'push_messaging/PushEvent.cpp',
'push_messaging/PushEvent.h',
'push_messaging/PushManager.cpp',
'push_messaging/PushManager.h',
'push_messaging/PushRegistration.cpp',
'push_messaging/PushRegistration.h',
'push_messaging/ServiceWorkerGlobalScopePush.h',
'quota/DOMWindowQuota.cpp',
'quota/DOMWindowQuota.h',
'quota/DeprecatedStorageInfo.cpp',
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "modules/push_messaging/PushEvent.h"
namespace WebCore {
PushEventInit::PushEventInit()
{
}
PushEvent::PushEvent()
{
ScriptWrappable::init(this);
}
PushEvent::PushEvent(const AtomicString& type, const String& data)
: Event(type, /*canBubble=*/false, /*cancelable=*/false)
, m_data(data)
{
ScriptWrappable::init(this);
}
PushEvent::PushEvent(const AtomicString& type, const PushEventInit& initializer)
: Event(type, initializer)
, m_data(initializer.data)
{
ScriptWrappable::init(this);
}
PushEvent::~PushEvent()
{
}
const AtomicString& PushEvent::interfaceName() const
{
return EventNames::PushEvent;
}
} // namespace WebCore
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PushEvent_h
#define PushEvent_h
#include "modules/EventModules.h"
#include "platform/heap/Handle.h"
#include "wtf/text/AtomicString.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
struct PushEventInit : public EventInit {
PushEventInit();
String data;
};
class PushEvent FINAL : public Event {
public:
static PassRefPtrWillBeRawPtr<PushEvent> create()
{
return adoptRefWillBeNoop(new PushEvent);
}
static PassRefPtrWillBeRawPtr<PushEvent> create(const AtomicString& type, const String& data)
{
return adoptRefWillBeNoop(new PushEvent(type, data));
}
static PassRefPtrWillBeRawPtr<PushEvent> create(const AtomicString& type, const PushEventInit& initializer)
{
return adoptRefWillBeNoop(new PushEvent(type, initializer));
}
virtual ~PushEvent();
virtual const AtomicString& interfaceName() const OVERRIDE;
String data() const { return m_data; }
private:
PushEvent();
PushEvent(const AtomicString& type, const String& data);
PushEvent(const AtomicString& type, const PushEventInit&);
String m_data;
};
} // namespace WebCore
#endif // PushEvent_h
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
EventConstructor,
RuntimeEnabled=PushMessaging,
] interface PushEvent : Event {
[InitializedByEventConstructor] readonly attribute DOMString data;
};
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ServiceWorkerGlobalScopePush_h
#define ServiceWorkerGlobalScopePush_h
#include "core/events/EventTarget.h"
namespace WebCore {
class ServiceWorkerGlobalScopePush {
public:
DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(push);
};
} // namespace WebCore
#endif // ServiceWorkerGlobalScopePush_h
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
RuntimeEnabled=PushMessaging,
] partial interface ServiceWorkerGlobalScope {
attribute EventHandler onpush;
};
......@@ -36,6 +36,7 @@
#include "core/dom/MessagePort.h"
#include "core/events/MessageEvent.h"
#include "core/workers/WorkerGlobalScope.h"
#include "modules/push_messaging/PushEvent.h"
#include "modules/serviceworkers/FetchEvent.h"
#include "modules/serviceworkers/InstallEvent.h"
#include "modules/serviceworkers/InstallPhaseEvent.h"
......@@ -96,6 +97,12 @@ void ServiceWorkerGlobalScopeProxy::dispatchMessageEvent(const WebString& messag
m_workerGlobalScope->dispatchEvent(MessageEvent::create(ports.release(), value));
}
void ServiceWorkerGlobalScopeProxy::dispatchPushEvent(int eventID, const WebString& data)
{
ASSERT(m_workerGlobalScope);
m_workerGlobalScope->dispatchEvent(PushEvent::create(EventTypeNames::push, data));
}
void ServiceWorkerGlobalScopeProxy::dispatchSyncEvent(int eventID)
{
ASSERT(m_workerGlobalScope);
......
......@@ -32,6 +32,7 @@
#define ServiceWorkerGlobalScopeProxy_h
#include "core/workers/WorkerReportingProxy.h"
#include "public/platform/WebString.h"
#include "public/web/WebServiceWorkerContextProxy.h"
#include "wtf/Forward.h"
#include "wtf/OwnPtr.h"
......@@ -71,6 +72,7 @@ public:
virtual void dispatchInstallEvent(int) OVERRIDE;
virtual void dispatchFetchEvent(int, const WebServiceWorkerRequest&) OVERRIDE;
virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray&) OVERRIDE;
virtual void dispatchPushEvent(int, const WebString& data) OVERRIDE;
virtual void dispatchSyncEvent(int) OVERRIDE;
// WorkerReportingProxy overrides:
......
......@@ -51,6 +51,8 @@ public:
virtual void dispatchMessageEvent(const WebString& message, const WebMessagePortChannelArray& channels) = 0;
virtual void dispatchPushEvent(int eventID, const WebString& data) = 0;
// Once the ServiceWorker has finished handling the sync event
// didHandleSyncEvent is called on the context client.
virtual void dispatchSyncEvent(int syncEventID) = 0;
......
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