NavigationPreloadManager.h (2048B)
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/. */ 6 7 #ifndef mozilla_dom_NavigationPreloadManager_h 8 #define mozilla_dom_NavigationPreloadManager_h 9 10 #include "mozilla/RefPtr.h" 11 #include "mozilla/dom/ServiceWorkerRegistration.h" 12 #include "nsCOMPtr.h" 13 #include "nsCycleCollectionParticipant.h" 14 #include "nsISupports.h" 15 #include "nsWrapperCache.h" 16 17 class nsIGlobalObject; 18 19 namespace mozilla::dom { 20 21 class Promise; 22 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) 28 29 static bool IsValidHeader(const nsACString& aHeader); 30 31 static bool IsEnabled(JSContext* aCx, JSObject* aGlobal); 32 33 explicit NavigationPreloadManager( 34 RefPtr<ServiceWorkerRegistration>& aServiceWorkerRegistration); 35 36 // Webidl binding 37 nsIGlobalObject* GetParentObject() const { 38 return mServiceWorkerRegistration->GetParentObject(); 39 } 40 41 JSObject* WrapObject(JSContext* aCx, 42 JS::Handle<JSObject*> aGivenProto) override; 43 44 // WebIdl implementation 45 already_AddRefed<Promise> Enable(ErrorResult& aError); 46 47 already_AddRefed<Promise> Disable(ErrorResult& aError); 48 49 already_AddRefed<Promise> SetHeaderValue(const nsACString& aHeader, 50 ErrorResult& aError); 51 52 already_AddRefed<Promise> GetState(ErrorResult& aError); 53 54 private: 55 ~NavigationPreloadManager() = default; 56 57 // General method for Enable()/Disable() 58 already_AddRefed<Promise> SetEnabled(bool aEnabled, ErrorResult& aError); 59 60 RefPtr<ServiceWorkerRegistration> mServiceWorkerRegistration; 61 }; 62 63 } // namespace mozilla::dom 64 65 #endif // mozilla_dom_NavigationPreloadManager_h