Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / serviceworkers / NavigationPreloadManager.h
blob7b4d0ac50b7b20c9e76f87e7274b045b4a936eaf
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
10 #include "nsCOMPtr.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 {
21 class Promise;
23 class NavigationPreloadManager final : public nsISupports,
24 public nsWrapperCache {
25 public:
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);
36 // Webidl binding
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,
50 ErrorResult& aError);
52 already_AddRefed<Promise> GetState(ErrorResult& aError);
54 private:
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