tor-browser

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

nsChromeRegistryChrome.h (4391B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef nsChromeRegistryChrome_h
      7 #define nsChromeRegistryChrome_h
      8 
      9 #include "nsCOMArray.h"
     10 #include "nsChromeRegistry.h"
     11 #include "nsClassHashtable.h"
     12 #include "nsTArray.h"
     13 
     14 namespace mozilla {
     15 namespace dom {
     16 class PContentParent;
     17 }  // namespace dom
     18 }  // namespace mozilla
     19 
     20 class nsIPrefBranch;
     21 struct ChromePackage;
     22 
     23 class nsChromeRegistryChrome : public nsChromeRegistry {
     24 public:
     25  nsChromeRegistryChrome();
     26  ~nsChromeRegistryChrome();
     27 
     28  nsresult Init() override;
     29 
     30  NS_IMETHOD CheckForNewChrome() override;
     31  NS_IMETHOD GetLocalesForPackage(const nsACString& aPackage,
     32                                  nsIUTF8StringEnumerator** aResult) override;
     33  NS_IMETHOD IsLocaleRTL(const nsACString& package, bool* aResult) override;
     34  nsresult GetSelectedLocale(const nsACString& aPackage, nsACString& aLocale);
     35  NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic,
     36                     const char16_t* someData) override;
     37 
     38  // If aChild is non-null then it is a new child to notify. If aChild is
     39  // null, then we have installed new chrome and we are resetting all of our
     40  // children's registered chrome.
     41  void SendRegisteredChrome(mozilla::dom::PContentParent* aChild);
     42 
     43 private:
     44  struct PackageEntry;
     45  static void ChromePackageFromPackageEntry(const nsACString& aPackageName,
     46                                            PackageEntry* aPackage,
     47                                            ChromePackage* aChromePackage,
     48                                            const nsCString& aSelectedSkin);
     49 
     50  nsresult OverrideLocalePackage(const nsACString& aPackage,
     51                                 nsACString& aOverride);
     52  nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
     53                                const nsCString& aProvider,
     54                                const nsCString& aPath) override;
     55  nsresult GetFlagsFromPackage(const nsCString& aPackage,
     56                               uint32_t* aFlags) override;
     57 
     58  struct ProviderEntry {
     59    ProviderEntry(const nsACString& aProvider, nsIURI* aBase)
     60        : provider(aProvider), baseURI(aBase) {}
     61 
     62    nsCString provider;
     63    nsCOMPtr<nsIURI> baseURI;
     64  };
     65 
     66  class nsProviderArray {
     67   public:
     68    nsProviderArray() : mArray(1) {}
     69    ~nsProviderArray() {}
     70 
     71    // When looking up locales and skins, the "selected" locale is not always
     72    // available. This enum identifies what kind of match is desired/found.
     73    enum MatchType {
     74      EXACT = 0,
     75      LOCALE = 1,  // "en-GB" is selected, we found "en-US"
     76      ANY = 2
     77    };
     78 
     79    nsIURI* GetBase(const nsACString& aPreferred, MatchType aType);
     80    const nsACString& GetSelected(const nsACString& aPreferred,
     81                                  MatchType aType);
     82    void SetBase(const nsACString& aProvider, nsIURI* base);
     83    void EnumerateToArray(nsTArray<nsCString>* a);
     84 
     85   private:
     86    ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType);
     87 
     88    nsTArray<ProviderEntry> mArray;
     89  };
     90 
     91  struct PackageEntry : public PLDHashEntryHdr {
     92    PackageEntry() : flags(0) {}
     93    ~PackageEntry() {}
     94 
     95    nsCOMPtr<nsIURI> baseURI;
     96    uint32_t flags;
     97    nsProviderArray locales;
     98    nsProviderArray skins;
     99  };
    100 
    101  bool mProfileLoaded;
    102  bool mDynamicRegistration;
    103 
    104  // Hash of package names ("global") to PackageEntry objects
    105  nsClassHashtable<nsCStringHashKey, PackageEntry> mPackagesHash;
    106 
    107  virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
    108                               char* const* argv, int flags) override;
    109  virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
    110                              char* const* argv, int flags) override;
    111  virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
    112                            char* const* argv, int flags) override;
    113  virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
    114                                char* const* argv, int flags) override;
    115  virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
    116                                char* const* argv, int flags) override;
    117 };
    118 
    119 #endif  // nsChromeRegistryChrome_h