chrome/src/nsChromeRegistryChrome.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial