tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CookieStoreSubscriptionService.h (2973B)


      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_CookieStoreSubscriptionService_h
      8 #define mozilla_dom_CookieStoreSubscriptionService_h
      9 
     10 #include "mozilla/dom/ServiceWorkerRegistrarTypes.h"
     11 #include "nsIObserver.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 class CookieSubscription;
     16 
     17 class CookieStoreSubscriptionService final : public nsIObserver {
     18 public:
     19  NS_DECL_THREADSAFE_ISUPPORTS
     20  NS_DECL_NSIOBSERVER
     21 
     22  static CookieStoreSubscriptionService* Instance();
     23 
     24  // ServiceWorkerRegistrar expandos callbacks:
     25  // This callback is executed when something is retrieved from the disk. The
     26  // `aValue` is a JSON string containing the cookie subscriptions for the
     27  // `aData` ServiceWorker.
     28  static void ServiceWorkerLoaded(const ServiceWorkerRegistrationData& aData,
     29                                  const nsACString& aValue);
     30  // When a ServiceWorker registration is updated, this callback is triggered.
     31  // For the CookieStore implementation, this is noop.
     32  static void ServiceWorkerUpdated(const ServiceWorkerRegistrationData& aData);
     33  // When a ServiceWorker is unregistered, this callback is executed.
     34  static void ServiceWorkerUnregistered(
     35      const ServiceWorkerRegistrationData& aData);
     36  // Similar to the previous callback but with different arguments.
     37  static void ServiceWorkerUnregistered(nsIPrincipal* aPrincipal,
     38                                        const nsACString& aScopeURL);
     39 
     40  void GetSubscriptions(const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
     41                        const nsACString& aScope,
     42                        nsTArray<CookieSubscription>& aSubscriptions);
     43 
     44  void Subscribe(const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
     45                 const nsACString& aScope,
     46                 const nsTArray<CookieSubscription>& aSubscriptions);
     47 
     48  void Unsubscribe(const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
     49                   const nsACString& aScope,
     50                   const nsTArray<CookieSubscription>& aSubscriptions);
     51 
     52  void Load(const ServiceWorkerRegistrationData& aData,
     53            const nsACString& aValue);
     54 
     55  void Unregister(const ServiceWorkerRegistrationData& aData);
     56 
     57 private:
     58  CookieStoreSubscriptionService();
     59  ~CookieStoreSubscriptionService() = default;
     60 
     61  void Initialize();
     62 
     63  struct RegistrationData {
     64    ServiceWorkerRegistrationData mRegistration;
     65    nsTArray<CookieSubscription> mSubscriptions;
     66  };
     67 
     68  void ParseAndAddSubscription(RegistrationData& aData,
     69                               const nsACString& aValue);
     70 
     71  void SerializeAndSave(const RegistrationData& aData);
     72 
     73  nsTArray<RegistrationData> mData;
     74 };
     75 
     76 }  // namespace mozilla::dom
     77 
     78 #endif /* mozilla_dom_CookieStoreSubscriptionService_h */