nsChromeRegistryChrome.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. #ifndef nsChromeRegistryChrome_h
  6. #define nsChromeRegistryChrome_h
  7. #include "nsCOMArray.h"
  8. #include "nsChromeRegistry.h"
  9. #include "nsTArray.h"
  10. #include "mozilla/Move.h"
  11. #include "nsClassHashtable.h"
  12. namespace mozilla {
  13. namespace dom {
  14. class PContentParent;
  15. } // namespace dom
  16. } // namespace mozilla
  17. class nsIPrefBranch;
  18. struct ChromePackage;
  19. class nsChromeRegistryChrome : public nsChromeRegistry
  20. {
  21. public:
  22. nsChromeRegistryChrome();
  23. ~nsChromeRegistryChrome();
  24. nsresult Init() override;
  25. NS_IMETHOD CheckForNewChrome() override;
  26. NS_IMETHOD CheckForOSAccessibility() override;
  27. NS_IMETHOD GetLocalesForPackage(const nsACString& aPackage,
  28. nsIUTF8StringEnumerator* *aResult) override;
  29. NS_IMETHOD IsLocaleRTL(const nsACString& package,
  30. bool *aResult) override;
  31. NS_IMETHOD GetSelectedLocale(const nsACString& aPackage,
  32. bool aAsBCP47,
  33. nsACString& aLocale) override;
  34. NS_IMETHOD Observe(nsISupports *aSubject, const char *aTopic,
  35. const char16_t *someData) override;
  36. #ifdef MOZ_XUL
  37. NS_IMETHOD GetXULOverlays(nsIURI *aURI,
  38. nsISimpleEnumerator **_retval) override;
  39. NS_IMETHOD GetStyleOverlays(nsIURI *aURI,
  40. nsISimpleEnumerator **_retval) override;
  41. #endif
  42. // If aChild is non-null then it is a new child to notify. If aChild is
  43. // null, then we have installed new chrome and we are resetting all of our
  44. // children's registered chrome.
  45. void SendRegisteredChrome(mozilla::dom::PContentParent* aChild);
  46. private:
  47. struct PackageEntry;
  48. static void ChromePackageFromPackageEntry(const nsACString& aPackageName,
  49. PackageEntry* aPackage,
  50. ChromePackage* aChromePackage,
  51. const nsCString& aSelectedLocale,
  52. const nsCString& aSelectedSkin);
  53. nsresult OverrideLocalePackage(const nsACString& aPackage,
  54. nsACString& aOverride);
  55. nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
  56. nsresult UpdateSelectedLocale() override;
  57. nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
  58. const nsCString& aProvider,
  59. const nsCString& aPath) override;
  60. nsresult GetFlagsFromPackage(const nsCString& aPackage,
  61. uint32_t* aFlags) override;
  62. struct ProviderEntry
  63. {
  64. ProviderEntry(const nsACString& aProvider, nsIURI* aBase) :
  65. provider(aProvider),
  66. baseURI(aBase) { }
  67. nsCString provider;
  68. nsCOMPtr<nsIURI> baseURI;
  69. };
  70. class nsProviderArray
  71. {
  72. public:
  73. nsProviderArray() :
  74. mArray(1) { }
  75. ~nsProviderArray() { }
  76. // When looking up locales and skins, the "selected" locale is not always
  77. // available. This enum identifies what kind of match is desired/found.
  78. enum MatchType {
  79. EXACT = 0,
  80. LOCALE = 1, // "en-GB" is selected, we found "en-US"
  81. ANY = 2
  82. };
  83. nsIURI* GetBase(const nsACString& aPreferred, MatchType aType);
  84. const nsACString& GetSelected(const nsACString& aPreferred, MatchType aType);
  85. void SetBase(const nsACString& aProvider, nsIURI* base);
  86. void EnumerateToArray(nsTArray<nsCString> *a);
  87. private:
  88. ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType);
  89. nsTArray<ProviderEntry> mArray;
  90. };
  91. struct PackageEntry : public PLDHashEntryHdr
  92. {
  93. PackageEntry()
  94. : flags(0) { }
  95. ~PackageEntry() { }
  96. nsCOMPtr<nsIURI> baseURI;
  97. uint32_t flags;
  98. nsProviderArray locales;
  99. nsProviderArray skins;
  100. };
  101. class OverlayListEntry : public nsURIHashKey
  102. {
  103. public:
  104. typedef nsURIHashKey::KeyType KeyType;
  105. typedef nsURIHashKey::KeyTypePointer KeyTypePointer;
  106. explicit OverlayListEntry(KeyTypePointer aKey) : nsURIHashKey(aKey) { }
  107. OverlayListEntry(OverlayListEntry&& toMove) : nsURIHashKey(mozilla::Move(toMove)),
  108. mArray(mozilla::Move(toMove.mArray)) { }
  109. ~OverlayListEntry() { }
  110. void AddURI(nsIURI* aURI);
  111. nsCOMArray<nsIURI> mArray;
  112. };
  113. class OverlayListHash
  114. {
  115. public:
  116. OverlayListHash() { }
  117. ~OverlayListHash() { }
  118. void Add(nsIURI* aBase, nsIURI* aOverlay);
  119. void Clear() { mTable.Clear(); }
  120. const nsCOMArray<nsIURI>* GetArray(nsIURI* aBase);
  121. private:
  122. nsTHashtable<OverlayListEntry> mTable;
  123. };
  124. // Hashes on the file to be overlaid (chrome://browser/content/browser.xul)
  125. // to a list of overlays/stylesheets
  126. OverlayListHash mOverlayHash;
  127. OverlayListHash mStyleHash;
  128. bool mProfileLoaded;
  129. bool mDynamicRegistration;
  130. nsCString mSelectedLocale;
  131. nsCString mSelectedSkin;
  132. // Hash of package names ("global") to PackageEntry objects
  133. nsClassHashtable<nsCStringHashKey, PackageEntry> mPackagesHash;
  134. virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
  135. char *const * argv, int flags) override;
  136. virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
  137. char *const * argv, int flags) override;
  138. virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
  139. char *const * argv, int flags) override;
  140. virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno,
  141. char *const * argv, int flags) override;
  142. virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno,
  143. char *const * argv, int flags) override;
  144. virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
  145. char *const * argv, int flags) override;
  146. virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
  147. char *const * argv, int flags) override;
  148. };
  149. #endif // nsChromeRegistryChrome_h