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_ServiceWorkerScriptCache_h
8 #define mozilla_dom_ServiceWorkerScriptCache_h
9 
10 #include "nsIRequest.h"
11 #include "nsISupportsImpl.h"
12 #include "nsString.h"
13 
14 class nsILoadGroup;
15 class nsIPrincipal;
16 
17 namespace mozilla {
18 namespace dom {
19 
20 class ServiceWorkerRegistrationInfo;
21 
22 namespace serviceWorkerScriptCache {
23 
24 nsresult PurgeCache(nsIPrincipal* aPrincipal, const nsAString& aCacheName);
25 
26 nsresult GenerateCacheName(nsAString& aName);
27 
28 enum class OnFailure : uint8_t { DoNothing, Uninstall };
29 
30 class CompareCallback {
31  public:
32   /*
33    * If there is an error, ignore aInCacheAndEqual and aNewCacheName.
34    * On success, if the cached result and network result matched,
35    * aInCacheAndEqual will be true and no new cache name is passed, otherwise
36    * use the new cache name to load the ServiceWorker.
37    */
38   virtual void ComparisonResult(nsresult aStatus, bool aInCacheAndEqual,
39                                 OnFailure aOnFailure,
40                                 const nsAString& aNewCacheName,
41                                 const nsACString& aMaxScope,
42                                 nsLoadFlags aLoadFlags) = 0;
43 
44   NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
45 };
46 
47 nsresult Compare(ServiceWorkerRegistrationInfo* aRegistration,
48                  nsIPrincipal* aPrincipal, const nsAString& aCacheName,
49                  const nsAString& aURL, CompareCallback* aCallback);
50 
51 }  // namespace serviceWorkerScriptCache
52 
53 }  // namespace dom
54 }  // namespace mozilla
55 
56 #endif  // mozilla_dom_ServiceWorkerScriptCache_h
57