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_NavigationPreloadManager_h
8 #define mozilla_dom_NavigationPreloadManager_h
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsISupports.h"
13 #include "nsWrapperCache.h"
14 #include "mozilla/dom/ServiceWorkerRegistration.h"
15 #include "mozilla/RefPtr.h"
17 class nsIGlobalObject
;
19 namespace mozilla::dom
{
23 class NavigationPreloadManager final
: public nsISupports
,
24 public nsWrapperCache
{
26 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(NavigationPreloadManager
)
29 static bool IsValidHeader(const nsACString
& aHeader
);
31 static bool IsEnabled(JSContext
* aCx
, JSObject
* aGlobal
);
33 explicit NavigationPreloadManager(
34 RefPtr
<ServiceWorkerRegistration
>& aServiceWorkerRegistration
);
37 nsIGlobalObject
* GetParentObject() const {
38 return mServiceWorkerRegistration
->GetParentObject();
41 JSObject
* WrapObject(JSContext
* aCx
,
42 JS::Handle
<JSObject
*> aGivenProto
) override
;
44 // WebIdl implementation
45 already_AddRefed
<Promise
> Enable(ErrorResult
& aError
);
47 already_AddRefed
<Promise
> Disable(ErrorResult
& aError
);
49 already_AddRefed
<Promise
> SetHeaderValue(const nsACString
& aHeader
,
52 already_AddRefed
<Promise
> GetState(ErrorResult
& aError
);
55 ~NavigationPreloadManager() = default;
57 // General method for Enable()/Disable()
58 already_AddRefed
<Promise
> SetEnabled(bool aEnabled
, ErrorResult
& aError
);
60 RefPtr
<ServiceWorkerRegistration
> mServiceWorkerRegistration
;
63 } // namespace mozilla::dom
65 #endif // mozilla_dom_NavigationPreloadManager_h