зеркало из https://github.com/mozilla/gecko-dev.git
Bug 967264 - Patch 2: InstallPhaseEvent and InstallEvent. r=ehsan r=jst
--HG-- extra : amend_source : 06855fd6ba0c0b06f087f98f51fe9b3a314ed7ca
This commit is contained in:
Родитель
d16ae2c822
Коммит
d2595e6a75
|
@ -707,6 +707,18 @@ DOMInterfaces = {
|
|||
'workers': True,
|
||||
}],
|
||||
|
||||
'InstallPhaseEvent': {
|
||||
'headerFile': 'ServiceWorkerEvents.h',
|
||||
'nativeType': 'mozilla::dom::workers::InstallPhaseEvent',
|
||||
'workers': True
|
||||
},
|
||||
|
||||
'InstallEvent': {
|
||||
'headerFile': 'ServiceWorkerEvents.h',
|
||||
'nativeType': 'mozilla::dom::workers::InstallEvent',
|
||||
'workers': True
|
||||
},
|
||||
|
||||
'KeyEvent': {
|
||||
'concrete': False
|
||||
},
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* For more information on this interface, please see
|
||||
* 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"]
|
||||
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
|
||||
readonly attribute ServiceWorker? activeWorker;
|
||||
void replace();
|
||||
};
|
||||
|
||||
// Should be in the spec soon to satisfy conventions about events.
|
||||
// https://github.com/slightlyoff/ServiceWorker/issues/216.
|
||||
dictionary InstallEventInit : EventInit {
|
||||
ServiceWorker? activeWorker = null;
|
||||
};
|
|
@ -0,0 +1,17 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* For more information on this interface, please see
|
||||
* 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"]
|
||||
interface InstallPhaseEvent : Event {
|
||||
// https://github.com/slightlyoff/ServiceWorker/issues/261
|
||||
void waitUntil(Promise p);
|
||||
};
|
|
@ -214,6 +214,8 @@ WEBIDL_FILES = [
|
|||
'InputEvent.webidl',
|
||||
'InputMethod.webidl',
|
||||
'InspectorUtils.webidl',
|
||||
'InstallEvent.webidl',
|
||||
'InstallPhaseEvent.webidl',
|
||||
'InterAppConnection.webidl',
|
||||
'InterAppConnectionRequest.webidl',
|
||||
'InterAppMessagePort.webidl',
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ServiceWorkerEvents.h"
|
||||
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
#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)
|
||||
: Event(aOwner, nullptr, nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
InstallPhaseEvent::WaitUntil(Promise& aPromise)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
// Only first caller counts.
|
||||
if (EventPhase() == AT_TARGET && !mPromise) {
|
||||
mPromise = &aPromise;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(InstallPhaseEvent, Event)
|
||||
NS_IMPL_RELEASE_INHERITED(InstallPhaseEvent, Event)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(InstallPhaseEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(Event)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallPhaseEvent, Event, mPromise)
|
||||
|
||||
InstallEvent::InstallEvent(EventTarget* aOwner)
|
||||
: InstallPhaseEvent(aOwner)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(InstallEvent, InstallPhaseEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(InstallEvent, InstallPhaseEvent)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(InstallEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(InstallPhaseEvent)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallEvent, InstallPhaseEvent, mActiveWorker)
|
||||
|
||||
END_WORKERS_NAMESPACE
|
|
@ -0,0 +1,133 @@
|
|||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_workers_serviceworkerevents_h__
|
||||
#define mozilla_dom_workers_serviceworkerevents_h__
|
||||
|
||||
#include "mozilla/dom/Event.h"
|
||||
#include "mozilla/dom/InstallPhaseEventBinding.h"
|
||||
#include "mozilla/dom/InstallEventBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class Promise;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
BEGIN_WORKERS_NAMESPACE
|
||||
|
||||
class ServiceWorker;
|
||||
|
||||
bool
|
||||
ServiceWorkerEventsVisible(JSContext* aCx, JSObject* aObj);
|
||||
|
||||
class InstallPhaseEvent : public Event
|
||||
{
|
||||
nsRefPtr<Promise> mPromise;
|
||||
|
||||
protected:
|
||||
InstallPhaseEvent(mozilla::dom::EventTarget* aOwner);
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InstallPhaseEvent, Event)
|
||||
NS_FORWARD_TO_EVENT
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
|
||||
{
|
||||
return mozilla::dom::InstallPhaseEventBinding_workers::Wrap(aCx, this);
|
||||
}
|
||||
|
||||
static already_AddRefed<InstallPhaseEvent>
|
||||
Constructor(mozilla::dom::EventTarget* aOwner,
|
||||
const nsAString& aType,
|
||||
const EventInit& aOptions)
|
||||
{
|
||||
nsRefPtr<InstallPhaseEvent> e = new InstallPhaseEvent(aOwner);
|
||||
bool trusted = e->Init(aOwner);
|
||||
e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
|
||||
e->SetTrusted(trusted);
|
||||
return e.forget();
|
||||
}
|
||||
|
||||
static already_AddRefed<InstallPhaseEvent>
|
||||
Constructor(const GlobalObject& aGlobal,
|
||||
const nsAString& aType,
|
||||
const EventInit& aOptions,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<EventTarget> target = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
return Constructor(target, aType, aOptions);
|
||||
}
|
||||
|
||||
void
|
||||
WaitUntil(Promise& aPromise);
|
||||
|
||||
already_AddRefed<Promise>
|
||||
GetPromise() const
|
||||
{
|
||||
nsRefPtr<Promise> p = mPromise;
|
||||
return p.forget();
|
||||
}
|
||||
};
|
||||
|
||||
class InstallEvent MOZ_FINAL : public InstallPhaseEvent
|
||||
{
|
||||
// FIXME(nsm): Bug 982787 will allow actually populating this.
|
||||
nsRefPtr<ServiceWorker> mActiveWorker;
|
||||
|
||||
protected:
|
||||
InstallEvent(mozilla::dom::EventTarget* aOwner);
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InstallEvent, InstallPhaseEvent)
|
||||
NS_FORWARD_TO_EVENT
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE
|
||||
{
|
||||
return mozilla::dom::InstallEventBinding_workers::Wrap(aCx, this);
|
||||
}
|
||||
|
||||
static already_AddRefed<InstallEvent>
|
||||
Constructor(mozilla::dom::EventTarget* aOwner,
|
||||
const nsAString& aType,
|
||||
const InstallEventInit& aOptions)
|
||||
{
|
||||
nsRefPtr<InstallEvent> e = new InstallEvent(aOwner);
|
||||
bool trusted = e->Init(aOwner);
|
||||
e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
|
||||
e->SetTrusted(trusted);
|
||||
e->mActiveWorker = aOptions.mActiveWorker;
|
||||
return e.forget();
|
||||
}
|
||||
|
||||
static already_AddRefed<InstallEvent>
|
||||
Constructor(const GlobalObject& aGlobal,
|
||||
const nsAString& aType,
|
||||
const InstallEventInit& aOptions,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
return Constructor(owner, aType, aOptions);
|
||||
}
|
||||
|
||||
already_AddRefed<ServiceWorker>
|
||||
GetActiveWorker() const
|
||||
{
|
||||
nsRefPtr<ServiceWorker> sw = mActiveWorker;
|
||||
return sw.forget();
|
||||
}
|
||||
|
||||
void
|
||||
Replace()
|
||||
{
|
||||
// FIXME(nsm): Unspecced. Bug 982711
|
||||
NS_WARNING("Not Implemented");
|
||||
};
|
||||
};
|
||||
|
||||
END_WORKERS_NAMESPACE
|
||||
#endif /* mozilla_dom_workers_serviceworkerevents_h__ */
|
|
@ -49,6 +49,7 @@ SOURCES += [
|
|||
'ScriptLoader.cpp',
|
||||
'ServiceWorker.cpp',
|
||||
'ServiceWorkerContainer.cpp',
|
||||
'ServiceWorkerEvents.cpp',
|
||||
'SharedWorker.cpp',
|
||||
'URL.cpp',
|
||||
'WorkerPrivate.cpp',
|
||||
|
|
Загрузка…
Ссылка в новой задаче