Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/chrome/nsChromeRegistryChrome.h
Line
Count
Source (jump to first uncovered line)
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
  // If aChild is non-null then it is a new child to notify. If aChild is
45
  // null, then we have installed new chrome and we are resetting all of our
46
  // children's registered chrome.
47
  void SendRegisteredChrome(mozilla::dom::PContentParent* aChild);
48
49
 private:
50
  struct PackageEntry;
51
  static void ChromePackageFromPackageEntry(const nsACString& aPackageName,
52
                                            PackageEntry* aPackage,
53
                                            ChromePackage* aChromePackage,
54
                                            const nsCString& aSelectedSkin);
55
56
  nsresult OverrideLocalePackage(const nsACString& aPackage,
57
                                 nsACString& aOverride);
58
  nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
59
                                 const nsCString& aProvider,
60
                                 const nsCString& aPath) override;
61
  nsresult GetFlagsFromPackage(const nsCString& aPackage,
62
                               uint32_t* aFlags) override;
63
64
  struct ProviderEntry
65
  {
66
    ProviderEntry(const nsACString& aProvider, nsIURI* aBase) :
67
    provider(aProvider),
68
45
    baseURI(aBase) { }
69
70
    nsCString        provider;
71
    nsCOMPtr<nsIURI> baseURI;
72
  };
73
74
  class nsProviderArray
75
  {
76
   public:
77
    nsProviderArray() :
78
108
    mArray(1) { }
79
0
    ~nsProviderArray() { }
80
81
    // When looking up locales and skins, the "selected" locale is not always
82
    // available. This enum identifies what kind of match is desired/found.
83
    enum MatchType {
84
      EXACT = 0,
85
      LOCALE = 1, // "en-GB" is selected, we found "en-US"
86
      ANY = 2
87
    };
88
89
    nsIURI* GetBase(const nsACString& aPreferred, MatchType aType);
90
    const nsACString& GetSelected(const nsACString& aPreferred, MatchType aType);
91
    void    SetBase(const nsACString& aProvider, nsIURI* base);
92
    void    EnumerateToArray(nsTArray<nsCString> *a);
93
94
   private:
95
    ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType);
96
97
    nsTArray<ProviderEntry> mArray;
98
  };
99
100
  struct PackageEntry : public PLDHashEntryHdr
101
  {
102
    PackageEntry()
103
54
    : flags(0) { }
104
0
    ~PackageEntry() { }
105
106
    nsCOMPtr<nsIURI> baseURI;
107
    uint32_t         flags;
108
    nsProviderArray  locales;
109
    nsProviderArray  skins;
110
  };
111
112
  bool mProfileLoaded;
113
  bool mDynamicRegistration;
114
115
  nsCString mSelectedSkin;
116
117
  // Hash of package names ("global") to PackageEntry objects
118
  nsClassHashtable<nsCStringHashKey, PackageEntry> mPackagesHash;
119
120
  virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
121
                               char *const * argv, int flags) override;
122
  virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
123
                              char *const * argv, int flags) override;
124
  virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
125
                            char *const * argv, int flags) override;
126
  virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
127
                                char *const * argv, int flags) override;
128
  virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
129
                                char *const * argv, int flags) override;
130
};
131
132
#endif // nsChromeRegistryChrome_h