chrome/src/nsChromeRegistryChrome.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     6 #ifndef nsChromeRegistryChrome_h
     7 #define nsChromeRegistryChrome_h
     9 #include "nsCOMArray.h"
    10 #include "nsChromeRegistry.h"
    11 #include "nsVoidArray.h"
    12 #include "mozilla/Move.h"
    14 namespace mozilla {
    15 namespace dom {
    16 class PContentParent;
    17 }
    18 }
    20 class nsIPrefBranch;
    22 class nsChromeRegistryChrome : public nsChromeRegistry
    23 {
    24  public:
    25   nsChromeRegistryChrome();
    26   ~nsChromeRegistryChrome();
    28   nsresult Init() MOZ_OVERRIDE;
    30   NS_IMETHOD CheckForNewChrome() MOZ_OVERRIDE;
    31   NS_IMETHOD CheckForOSAccessibility() MOZ_OVERRIDE;
    32   NS_IMETHOD GetLocalesForPackage(const nsACString& aPackage,
    33                                   nsIUTF8StringEnumerator* *aResult) MOZ_OVERRIDE;
    34   NS_IMETHOD IsLocaleRTL(const nsACString& package,
    35                          bool *aResult) MOZ_OVERRIDE;
    36   NS_IMETHOD GetSelectedLocale(const nsACString& aPackage,
    37                                nsACString& aLocale) MOZ_OVERRIDE;
    38   NS_IMETHOD Observe(nsISupports *aSubject, const char *aTopic,
    39                      const char16_t *someData) MOZ_OVERRIDE;
    41 #ifdef MOZ_XUL
    42   NS_IMETHOD GetXULOverlays(nsIURI *aURI,
    43                             nsISimpleEnumerator **_retval) MOZ_OVERRIDE;
    44   NS_IMETHOD GetStyleOverlays(nsIURI *aURI,
    45                               nsISimpleEnumerator **_retval) MOZ_OVERRIDE;
    46 #endif
    48   void SendRegisteredChrome(mozilla::dom::PContentParent* aChild);
    50  private:
    51   static PLDHashOperator CollectPackages(PLDHashTable *table,
    52                                          PLDHashEntryHdr *entry,
    53                                          uint32_t number, void *arg);
    55   nsresult OverrideLocalePackage(const nsACString& aPackage,
    56                                  nsACString& aOverride);
    57   nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
    58   nsresult UpdateSelectedLocale() MOZ_OVERRIDE;
    59   nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
    60                                  const nsCString& aProvider,
    61                                  const nsCString& aPath) MOZ_OVERRIDE;
    62   nsresult GetFlagsFromPackage(const nsCString& aPackage,
    63                                uint32_t* aFlags) MOZ_OVERRIDE;
    65   static const PLDHashTableOps kTableOps;
    66   static PLDHashNumber HashKey(PLDHashTable *table, const void *key);
    67   static bool          MatchKey(PLDHashTable *table, const PLDHashEntryHdr *entry,
    68                                 const void *key);
    69   static void          ClearEntry(PLDHashTable *table, PLDHashEntryHdr *entry);
    70   static bool          InitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
    71                                  const void *key);
    73   struct ProviderEntry
    74   {
    75     ProviderEntry(const nsACString& aProvider, nsIURI* aBase) :
    76     provider(aProvider),
    77     baseURI(aBase) { }
    79     nsCString        provider;
    80     nsCOMPtr<nsIURI> baseURI;
    81   };
    83   class nsProviderArray
    84   {
    85    public:
    86     nsProviderArray() :
    87     mArray(1) { }
    88     ~nsProviderArray()
    89     { Clear(); }
    91     // When looking up locales and skins, the "selected" locale is not always
    92     // available. This enum identifies what kind of match is desired/found.
    93     enum MatchType {
    94       EXACT = 0,
    95       LOCALE = 1, // "en-GB" is selected, we found "en-US"
    96       ANY = 2
    97     };
    99     nsIURI* GetBase(const nsACString& aPreferred, MatchType aType);
   100     const nsACString& GetSelected(const nsACString& aPreferred, MatchType aType);
   101     void    SetBase(const nsACString& aProvider, nsIURI* base);
   102     void    EnumerateToArray(nsTArray<nsCString> *a);
   103     void    Clear();
   105    private:
   106     ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType);
   108     nsVoidArray mArray;
   109   };
   111   struct PackageEntry : public PLDHashEntryHdr
   112   {
   113     PackageEntry(const nsACString& package)
   114     : package(package), flags(0) { }
   115     ~PackageEntry() { }
   117     nsCString        package;
   118     nsCOMPtr<nsIURI> baseURI;
   119     uint32_t         flags;
   120     nsProviderArray  locales;
   121     nsProviderArray  skins;
   122   };
   124   class OverlayListEntry : public nsURIHashKey
   125   {
   126    public:
   127     typedef nsURIHashKey::KeyType        KeyType;
   128     typedef nsURIHashKey::KeyTypePointer KeyTypePointer;
   130     OverlayListEntry(KeyTypePointer aKey) : nsURIHashKey(aKey) { }
   131     OverlayListEntry(OverlayListEntry&& toMove) : nsURIHashKey(mozilla::Move(toMove)),
   132                                                   mArray(mozilla::Move(toMove.mArray)) { }
   133     ~OverlayListEntry() { }
   135     void AddURI(nsIURI* aURI);
   137     nsCOMArray<nsIURI> mArray;
   138   };
   140   class OverlayListHash
   141   {
   142    public:
   143     OverlayListHash() { }
   144     ~OverlayListHash() { }
   146     void Add(nsIURI* aBase, nsIURI* aOverlay);
   147     void Clear() { mTable.Clear(); }
   148     const nsCOMArray<nsIURI>* GetArray(nsIURI* aBase);
   150    private:
   151     nsTHashtable<OverlayListEntry> mTable;
   152   };
   154   // Hashes on the file to be overlaid (chrome://browser/content/browser.xul)
   155   // to a list of overlays/stylesheets
   156   OverlayListHash mOverlayHash;
   157   OverlayListHash mStyleHash;
   159   bool mProfileLoaded;
   161   nsCString mSelectedLocale;
   162   nsCString mSelectedSkin;
   164   // Hash of package names ("global") to PackageEntry objects
   165   PLDHashTable mPackagesHash;
   167   virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
   168                                char *const * argv, bool platform,
   169                                bool contentaccessible);
   170   virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
   171                               char *const * argv, bool platform,
   172                               bool contentaccessible);
   173   virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
   174                             char *const * argv, bool platform,
   175                             bool contentaccessible);
   176   virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno,
   177                                char *const * argv, bool platform,
   178                                bool contentaccessible);
   179   virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno,
   180                              char *const * argv, bool platform,
   181                              bool contentaccessible);
   182   virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
   183                                 char *const * argv, bool platform,
   184                                 bool contentaccessible);
   185   virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
   186                                 char *const * argv, bool platform,
   187                                 bool contentaccessible);
   188 };
   190 #endif // nsChromeRegistryChrome_h

mercurial