Bumping gaia.json for 4 gaia revision(s) a=gaia-bump
[gecko.git] / dom / workers / ServiceWorker.h
blob0883ad525b81c33ff94a74c69df1ff7f052c5514
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_dom_workers_serviceworker_h__
7 #define mozilla_dom_workers_serviceworker_h__
9 #include "mozilla/DOMEventTargetHelper.h"
10 #include "mozilla/dom/BindingDeclarations.h"
11 #include "mozilla/dom/ServiceWorkerBinding.h" // For ServiceWorkerState.
13 class nsPIDOMWindow;
15 namespace mozilla {
16 namespace dom {
18 class Promise;
20 namespace workers {
22 class SharedWorker;
24 class ServiceWorker MOZ_FINAL : public DOMEventTargetHelper
26 friend class RuntimeService;
27 public:
28 NS_DECL_ISUPPORTS_INHERITED
29 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorker, DOMEventTargetHelper)
31 IMPL_EVENT_HANDLER(statechange)
32 IMPL_EVENT_HANDLER(error)
34 virtual JSObject*
35 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
37 ServiceWorkerState
38 State() const
40 return mState;
43 void
44 GetScope(nsString& aScope) const
46 aScope = mScope;
49 void
50 GetUrl(nsString& aURL) const
52 aURL = mURL;
55 WorkerPrivate*
56 GetWorkerPrivate() const;
58 private:
59 // This class can only be created from the RuntimeService.
60 ServiceWorker(nsPIDOMWindow* aWindow, SharedWorker* aSharedWorker);
62 // This class is reference-counted and will be destroyed from Release().
63 ~ServiceWorker();
65 ServiceWorkerState mState;
66 nsString mScope;
67 nsString mURL;
69 // To allow ServiceWorkers to potentially drop the backing DOMEventTargetHelper and
70 // re-instantiate it later, they simply own a SharedWorker member that
71 // can be released and recreated as required rather than re-implement some of
72 // the SharedWorker logic.
73 nsRefPtr<SharedWorker> mSharedWorker;
76 } // namespace workers
77 } // namespace dom
78 } // namespace mozilla
80 #endif // mozilla_dom_workers_serviceworker_h__