Bug 1113621 - Rename InstallPhaseEvent to ExtendableEvent. r=baku relanding because it wasn't supposed to be backed out on a CLOSED TREE

Change Exposed=ServiceWorker for all ServiceWorker events.
Move Func= exposure check to ServiceWorker.

--HG--
rename : dom/webidl/InstallPhaseEvent.webidl => dom/webidl/ExtendableEvent.webidl
extra : source : 5ed6d1902cc7bafbf9ffeaf35815c56cdd8f8c0d
extra : amend_source : eab06a362baf7545b9b61e28316666c2ec76acac
This commit is contained in:
Nikhil Marathe 2014-11-06 07:57:57 -08:00
parent 3ddd04bd7d
commit 39a14f36e2
11 changed files with 69 additions and 66 deletions

View File

@ -409,6 +409,11 @@ DOMInterfaces = {
},
},
'ExtendableEvent': {
'headerFile': 'mozilla/dom/ServiceWorkerEvents.h',
'nativeType': 'mozilla::dom::workers::ExtendableEvent',
},
'FileList': {
'headerFile': 'mozilla/dom/File.h',
},
@ -605,11 +610,6 @@ DOMInterfaces = {
'workers': True,
}],
'InstallPhaseEvent': {
'headerFile': 'ServiceWorkerEvents.h',
'nativeType': 'mozilla::dom::workers::InstallPhaseEvent',
},
'InstallEvent': {
'headerFile': 'ServiceWorkerEvents.h',
'nativeType': 'mozilla::dom::workers::InstallEvent',

View File

@ -7,12 +7,13 @@
* http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
*/
// While not explicitly restricted to ServiceWorkerGlobalScope, it probably
// should be. https://github.com/slightlyoff/ServiceWorker/issues/254
[Constructor(DOMString type, optional EventInit eventInitDict),
Func="mozilla::dom::workers::ServiceWorkerEventsVisible",
Exposed=(ServiceWorker,Window)]
interface InstallPhaseEvent : Event {
[Constructor(DOMString type, optional ExtendableEventInit eventInitDict),
Exposed=ServiceWorker]
interface ExtendableEvent : Event {
// https://github.com/slightlyoff/ServiceWorker/issues/261
void waitUntil(Promise<any> p);
};
dictionary ExtendableEventInit : EventInit {
// Defined for the forward compatibility across the derived events
};

View File

@ -7,20 +7,9 @@
* http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
*/
// While not explicitly restricted to ServiceWorkerGlobalScope, it probably
// should be. https://github.com/slightlyoff/ServiceWorker/issues/254
[Constructor(DOMString type, optional InstallEventInit eventInitDict),
Func="mozilla::dom::workers::ServiceWorkerEventsVisible",
// XXXbz I have no idea where this should be exposed. The spec makes
// no sense. But since it returns a ServiceWorker and that's only
// exposed in Window, let's say Window.
Exposed=Window]
interface InstallEvent : InstallPhaseEvent {
// The currently active worker for this scope when this worker is asked to
// install itself.
// This may be null when a ServiceWorker is being installed for a previously
// uncontrolled scope.
// https://github.com/slightlyoff/ServiceWorker/issues/260
Exposed=ServiceWorker]
interface InstallEvent : ExtendableEvent {
readonly attribute ServiceWorker? activeWorker;
void replace();
};

View File

@ -10,9 +10,9 @@
// Still unclear what should be subclassed.
// https://github.com/slightlyoff/ServiceWorker/issues/189
[Pref="dom.serviceWorkers.enabled",
// FIXME(nsm): Bug 1113522. Should also be exposed on Workers too.
Exposed=Window]
[Func="mozilla::dom::workers::ServiceWorkerVisible",
// FIXME(nsm): Bug 1113522. This is exposed to satisfy webidl constraints, but it won't actually work.
Exposed=(ServiceWorker,Window)]
interface ServiceWorker : EventTarget {
readonly attribute USVString scriptURL;
readonly attribute ServiceWorkerState state;

View File

@ -130,6 +130,7 @@ WEBIDL_FILES = [
'EventListener.webidl',
'EventSource.webidl',
'EventTarget.webidl',
'ExtendableEvent.webidl',
'Fetch.webidl',
'File.webidl',
'FileList.webidl',
@ -245,7 +246,6 @@ WEBIDL_FILES = [
'InputMethod.webidl',
'InspectorUtils.webidl',
'InstallEvent.webidl',
'InstallPhaseEvent.webidl',
'InterAppConnection.webidl',
'InterAppConnectionRequest.webidl',
'InterAppMessagePort.webidl',

View File

@ -9,10 +9,28 @@
#include "SharedWorker.h"
#include "WorkerPrivate.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
using namespace mozilla::dom;
USING_WORKERS_NAMESPACE
namespace mozilla {
namespace dom {
namespace workers {
bool
ServiceWorkerVisible(JSContext* aCx, JSObject* aObj)
{
if (NS_IsMainThread()) {
return Preferences::GetBool("dom.serviceWorkers.enabled", false);
}
ServiceWorkerGlobalScope* scope = nullptr;
nsresult rv = UnwrapObject<prototypes::id::ServiceWorkerGlobalScope_workers,
mozilla::dom::ServiceWorkerGlobalScopeBinding_workers::NativeType>(aObj, scope);
return NS_SUCCEEDED(rv);
}
ServiceWorker::ServiceWorker(nsPIDOMWindow* aWindow,
SharedWorker* aSharedWorker)
@ -55,3 +73,7 @@ ServiceWorker::GetWorkerPrivate() const
MOZ_ASSERT(mSharedWorker);
return mSharedWorker->GetWorkerPrivate();
}
} // namespace workers
} // namespace dom
} // namespace mozilla

View File

@ -21,6 +21,9 @@ namespace workers {
class SharedWorker;
bool
ServiceWorkerVisible(JSContext* aCx, JSObject* aObj);
class ServiceWorker MOZ_FINAL : public DOMEventTargetHelper
{
friend class RuntimeService;

View File

@ -11,28 +11,18 @@
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/WorkerScope.h"
#include "mozilla/dom/workers/bindings/ServiceWorker.h"
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
using namespace mozilla::dom;
BEGIN_WORKERS_NAMESPACE
bool
ServiceWorkerEventsVisible(JSContext* aCx, JSObject* aObj)
{
ServiceWorkerGlobalScope* scope = nullptr;
nsresult rv = UnwrapObject<prototypes::id::ServiceWorkerGlobalScope_workers,
mozilla::dom::ServiceWorkerGlobalScopeBinding_workers::NativeType>(aObj, scope);
return NS_SUCCEEDED(rv) && scope;
}
InstallPhaseEvent::InstallPhaseEvent(EventTarget* aOwner)
ExtendableEvent::ExtendableEvent(EventTarget* aOwner)
: Event(aOwner, nullptr, nullptr)
{
}
void
InstallPhaseEvent::WaitUntil(Promise& aPromise)
ExtendableEvent::WaitUntil(Promise& aPromise)
{
MOZ_ASSERT(!NS_IsMainThread());
@ -42,26 +32,26 @@ InstallPhaseEvent::WaitUntil(Promise& aPromise)
}
}
NS_IMPL_ADDREF_INHERITED(InstallPhaseEvent, Event)
NS_IMPL_RELEASE_INHERITED(InstallPhaseEvent, Event)
NS_IMPL_ADDREF_INHERITED(ExtendableEvent, Event)
NS_IMPL_RELEASE_INHERITED(ExtendableEvent, Event)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(InstallPhaseEvent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ExtendableEvent)
NS_INTERFACE_MAP_END_INHERITING(Event)
NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallPhaseEvent, Event, mPromise)
NS_IMPL_CYCLE_COLLECTION_INHERITED(ExtendableEvent, Event, mPromise)
InstallEvent::InstallEvent(EventTarget* aOwner)
: InstallPhaseEvent(aOwner)
: ExtendableEvent(aOwner)
, mActivateImmediately(false)
{
}
NS_IMPL_ADDREF_INHERITED(InstallEvent, InstallPhaseEvent)
NS_IMPL_RELEASE_INHERITED(InstallEvent, InstallPhaseEvent)
NS_IMPL_ADDREF_INHERITED(InstallEvent, ExtendableEvent)
NS_IMPL_RELEASE_INHERITED(InstallEvent, ExtendableEvent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(InstallEvent)
NS_INTERFACE_MAP_END_INHERITING(InstallPhaseEvent)
NS_INTERFACE_MAP_END_INHERITING(ExtendableEvent)
NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallEvent, InstallPhaseEvent, mActiveWorker)
NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallEvent, ExtendableEvent, mActiveWorker)
END_WORKERS_NAMESPACE

View File

@ -7,7 +7,7 @@
#define mozilla_dom_workers_serviceworkerevents_h__
#include "mozilla/dom/Event.h"
#include "mozilla/dom/InstallPhaseEventBinding.h"
#include "mozilla/dom/ExtendableEventBinding.h"
#include "mozilla/dom/InstallEventBinding.h"
namespace mozilla {
@ -20,40 +20,37 @@ BEGIN_WORKERS_NAMESPACE
class ServiceWorker;
bool
ServiceWorkerEventsVisible(JSContext* aCx, JSObject* aObj);
class InstallPhaseEvent : public Event
class ExtendableEvent : public Event
{
nsRefPtr<Promise> mPromise;
protected:
explicit InstallPhaseEvent(mozilla::dom::EventTarget* aOwner);
~InstallPhaseEvent() {}
explicit ExtendableEvent(mozilla::dom::EventTarget* aOwner);
~ExtendableEvent() {}
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InstallPhaseEvent, Event)
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ExtendableEvent, Event)
NS_FORWARD_TO_EVENT
virtual JSObject* WrapObjectInternal(JSContext* aCx) MOZ_OVERRIDE
{
return mozilla::dom::InstallPhaseEventBinding::Wrap(aCx, this);
return mozilla::dom::ExtendableEventBinding::Wrap(aCx, this);
}
static already_AddRefed<InstallPhaseEvent>
static already_AddRefed<ExtendableEvent>
Constructor(mozilla::dom::EventTarget* aOwner,
const nsAString& aType,
const EventInit& aOptions)
{
nsRefPtr<InstallPhaseEvent> e = new InstallPhaseEvent(aOwner);
nsRefPtr<ExtendableEvent> e = new ExtendableEvent(aOwner);
bool trusted = e->Init(aOwner);
e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
e->SetTrusted(trusted);
return e.forget();
}
static already_AddRefed<InstallPhaseEvent>
static already_AddRefed<ExtendableEvent>
Constructor(const GlobalObject& aGlobal,
const nsAString& aType,
const EventInit& aOptions,
@ -74,7 +71,7 @@ public:
}
};
class InstallEvent MOZ_FINAL : public InstallPhaseEvent
class InstallEvent MOZ_FINAL : public ExtendableEvent
{
// FIXME(nsm): Bug 982787 will allow actually populating this.
nsRefPtr<ServiceWorker> mActiveWorker;
@ -86,7 +83,7 @@ protected:
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InstallEvent, InstallPhaseEvent)
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InstallEvent, ExtendableEvent)
NS_FORWARD_TO_EVENT
virtual JSObject* WrapObjectInternal(JSContext* aCx) MOZ_OVERRIDE

View File

@ -1043,8 +1043,8 @@ private:
EventInit init;
init.mBubbles = false;
init.mCancelable = true;
nsRefPtr<InstallPhaseEvent> event =
InstallPhaseEvent::Constructor(target, NS_LITERAL_STRING("activate"), init);
nsRefPtr<ExtendableEvent> event =
ExtendableEvent::Constructor(target, NS_LITERAL_STRING("activate"), init);
event->SetTrusted(true);

View File

@ -8,6 +8,7 @@
EXPORTS.mozilla.dom += [
'ServiceWorkerCommon.h',
'ServiceWorkerContainer.h',
'ServiceWorkerEvents.h',
'ServiceWorkerRegistration.h',
'WorkerPrivate.h',
'WorkerRunnable.h',