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