Source code

Revision control

Other Tools

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