1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ServiceWorkerRegistration_h
8 #define mozilla_dom_ServiceWorkerRegistration_h
10 #include "mozilla/DOMEventTargetHelper.h"
11 #include "mozilla/dom/ServiceWorkerCommon.h"
24 class ServiceWorkerRegistration MOZ_FINAL
: public DOMEventTargetHelper
27 NS_DECL_ISUPPORTS_INHERITED
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerRegistration
,
31 IMPL_EVENT_HANDLER(updatefound
)
33 ServiceWorkerRegistration(nsPIDOMWindow
* aWindow
,
34 const nsAString
& aScope
);
37 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
39 already_AddRefed
<workers::ServiceWorker
>
42 already_AddRefed
<workers::ServiceWorker
>
45 already_AddRefed
<workers::ServiceWorker
>
49 GetScope(nsAString
& aScope
) const
54 already_AddRefed
<Promise
>
55 Unregister(ErrorResult
& aRv
);
57 // Useful methods for ServiceWorkerManager:
60 GetDocumentURI() const;
63 InvalidateWorkerReference(WhichServiceWorker aWhichOnes
);
65 // DOMEventTargethelper
66 virtual void DisconnectFromOwner() MOZ_OVERRIDE
;
69 ~ServiceWorkerRegistration();
71 already_AddRefed
<workers::ServiceWorker
>
72 GetWorkerReference(WhichServiceWorker aWhichOne
);
75 StartListeningForEvents();
78 StopListeningForEvents();
80 // The following properties are cached here to ensure JS equality is satisfied
81 // instead of acquiring a new worker instance from the ServiceWorkerManager
82 // for every access. A null value is considered a cache miss.
83 // These three may change to a new worker at any time.
84 nsRefPtr
<workers::ServiceWorker
> mInstallingWorker
;
85 nsRefPtr
<workers::ServiceWorker
> mWaitingWorker
;
86 nsRefPtr
<workers::ServiceWorker
> mActiveWorker
;
88 const nsString mScope
;
89 bool mListeningForEvents
;
93 } // namespace mozilla
95 #endif /* mozilla_dom_ServiceWorkerRegistration_h */