tor-browser

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

StorageOriginAttributes.h (2010B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_QUOTA_STORAGEORIGINATTRIBUTES_H_
      8 #define DOM_QUOTA_STORAGEORIGINATTRIBUTES_H_
      9 
     10 #include "mozilla/OriginAttributes.h"
     11 
     12 namespace mozilla {
     13 
     14 // A class which can handle origin attributes which are not fully supported
     15 // in OriginAttributes class anymore.
     16 class StorageOriginAttributes {
     17 public:
     18  StorageOriginAttributes() : mInIsolatedMozBrowser(false) {}
     19 
     20  explicit StorageOriginAttributes(bool aInIsolatedMozBrowser)
     21      : mInIsolatedMozBrowser(aInIsolatedMozBrowser) {}
     22 
     23  bool InIsolatedMozBrowser() const { return mInIsolatedMozBrowser; }
     24 
     25  uint32_t UserContextId() const { return mOriginAttributes.mUserContextId; }
     26 
     27  // New getters can be added here incrementally.
     28 
     29  void SetInIsolatedMozBrowser(bool aInIsolatedMozBrowser) {
     30    mInIsolatedMozBrowser = aInIsolatedMozBrowser;
     31  }
     32 
     33  void SetUserContextId(uint32_t aUserContextId) {
     34    mOriginAttributes.mUserContextId = aUserContextId;
     35  }
     36 
     37  // New setters can be added here incrementally.
     38 
     39  // Serializes/Deserializes non-default values into the suffix format, i.e.
     40  // |^key1=value1&key2=value2|. If there are no non-default attributes, this
     41  // returns an empty string
     42  void CreateSuffix(nsACString& aStr) const;
     43 
     44  [[nodiscard]] bool PopulateFromSuffix(const nsACString& aStr);
     45 
     46  // Populates the attributes from a string like
     47  // |uri^key1=value1&key2=value2| and returns the uri without the suffix.
     48  [[nodiscard]] bool PopulateFromOrigin(const nsACString& aOrigin,
     49                                        nsACString& aOriginNoSuffix);
     50 
     51 private:
     52  OriginAttributes mOriginAttributes;
     53 
     54  bool mInIsolatedMozBrowser;
     55 };
     56 
     57 }  // namespace mozilla
     58 
     59 #endif  // DOM_QUOTA_STORAGEORIGINATTRIBUTES_H_