Tue, 06 Jan 2015 21:39:09 +0100
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 | #include "RegistryMessageUtils.h" |
michael@0 | 7 | #include "nsChromeRegistryContent.h" |
michael@0 | 8 | #include "nsString.h" |
michael@0 | 9 | #include "nsNetUtil.h" |
michael@0 | 10 | #include "nsIResProtocolHandler.h" |
michael@0 | 11 | |
michael@0 | 12 | nsChromeRegistryContent::nsChromeRegistryContent() |
michael@0 | 13 | { |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | void |
michael@0 | 17 | nsChromeRegistryContent::RegisterRemoteChrome( |
michael@0 | 18 | const InfallibleTArray<ChromePackage>& aPackages, |
michael@0 | 19 | const InfallibleTArray<ResourceMapping>& aResources, |
michael@0 | 20 | const InfallibleTArray<OverrideMapping>& aOverrides, |
michael@0 | 21 | const nsACString& aLocale) |
michael@0 | 22 | { |
michael@0 | 23 | NS_ABORT_IF_FALSE(mLocale == nsDependentCString(""), |
michael@0 | 24 | "RegisterChrome twice?"); |
michael@0 | 25 | |
michael@0 | 26 | for (uint32_t i = aPackages.Length(); i > 0; ) { |
michael@0 | 27 | --i; |
michael@0 | 28 | RegisterPackage(aPackages[i]); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | for (uint32_t i = aResources.Length(); i > 0; ) { |
michael@0 | 32 | --i; |
michael@0 | 33 | RegisterResource(aResources[i]); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | for (uint32_t i = aOverrides.Length(); i > 0; ) { |
michael@0 | 37 | --i; |
michael@0 | 38 | RegisterOverride(aOverrides[i]); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | mLocale = aLocale; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | void |
michael@0 | 45 | nsChromeRegistryContent::RegisterPackage(const ChromePackage& aPackage) |
michael@0 | 46 | { |
michael@0 | 47 | nsCOMPtr<nsIIOService> io (do_GetIOService()); |
michael@0 | 48 | if (!io) |
michael@0 | 49 | return; |
michael@0 | 50 | |
michael@0 | 51 | nsCOMPtr<nsIURI> content, locale, skin; |
michael@0 | 52 | |
michael@0 | 53 | if (aPackage.contentBaseURI.spec.Length()) { |
michael@0 | 54 | nsresult rv = NS_NewURI(getter_AddRefs(content), |
michael@0 | 55 | aPackage.contentBaseURI.spec, |
michael@0 | 56 | aPackage.contentBaseURI.charset.get(), |
michael@0 | 57 | nullptr, io); |
michael@0 | 58 | if (NS_FAILED(rv)) |
michael@0 | 59 | return; |
michael@0 | 60 | } |
michael@0 | 61 | if (aPackage.localeBaseURI.spec.Length()) { |
michael@0 | 62 | nsresult rv = NS_NewURI(getter_AddRefs(locale), |
michael@0 | 63 | aPackage.localeBaseURI.spec, |
michael@0 | 64 | aPackage.localeBaseURI.charset.get(), |
michael@0 | 65 | nullptr, io); |
michael@0 | 66 | if (NS_FAILED(rv)) |
michael@0 | 67 | return; |
michael@0 | 68 | } |
michael@0 | 69 | if (aPackage.skinBaseURI.spec.Length()) { |
michael@0 | 70 | nsCOMPtr<nsIURI> skinBaseURI; |
michael@0 | 71 | nsresult rv = NS_NewURI(getter_AddRefs(skin), |
michael@0 | 72 | aPackage.skinBaseURI.spec, |
michael@0 | 73 | aPackage.skinBaseURI.charset.get(), |
michael@0 | 74 | nullptr, io); |
michael@0 | 75 | if (NS_FAILED(rv)) |
michael@0 | 76 | return; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | PackageEntry* entry = new PackageEntry; |
michael@0 | 80 | entry->flags = aPackage.flags; |
michael@0 | 81 | entry->contentBaseURI = content; |
michael@0 | 82 | entry->localeBaseURI = locale; |
michael@0 | 83 | entry->skinBaseURI = skin; |
michael@0 | 84 | |
michael@0 | 85 | mPackagesHash.Put(aPackage.package, entry); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | void |
michael@0 | 89 | nsChromeRegistryContent::RegisterResource(const ResourceMapping& aResource) |
michael@0 | 90 | { |
michael@0 | 91 | nsCOMPtr<nsIIOService> io (do_GetIOService()); |
michael@0 | 92 | if (!io) |
michael@0 | 93 | return; |
michael@0 | 94 | |
michael@0 | 95 | nsCOMPtr<nsIProtocolHandler> ph; |
michael@0 | 96 | nsresult rv = io->GetProtocolHandler("resource", getter_AddRefs(ph)); |
michael@0 | 97 | if (NS_FAILED(rv)) |
michael@0 | 98 | return; |
michael@0 | 99 | |
michael@0 | 100 | nsCOMPtr<nsIResProtocolHandler> rph (do_QueryInterface(ph)); |
michael@0 | 101 | if (!rph) |
michael@0 | 102 | return; |
michael@0 | 103 | |
michael@0 | 104 | nsCOMPtr<nsIURI> resolvedURI; |
michael@0 | 105 | if (aResource.resolvedURI.spec.Length()) { |
michael@0 | 106 | nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI), |
michael@0 | 107 | aResource.resolvedURI.spec, |
michael@0 | 108 | aResource.resolvedURI.charset.get(), |
michael@0 | 109 | nullptr, io); |
michael@0 | 110 | if (NS_FAILED(rv)) |
michael@0 | 111 | return; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | rv = rph->SetSubstitution(aResource.resource, resolvedURI); |
michael@0 | 115 | if (NS_FAILED(rv)) |
michael@0 | 116 | return; |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | void |
michael@0 | 120 | nsChromeRegistryContent::RegisterOverride(const OverrideMapping& aOverride) |
michael@0 | 121 | { |
michael@0 | 122 | nsCOMPtr<nsIIOService> io (do_GetIOService()); |
michael@0 | 123 | if (!io) |
michael@0 | 124 | return; |
michael@0 | 125 | |
michael@0 | 126 | nsCOMPtr<nsIURI> chromeURI, overrideURI; |
michael@0 | 127 | nsresult rv = NS_NewURI(getter_AddRefs(chromeURI), |
michael@0 | 128 | aOverride.originalURI.spec, |
michael@0 | 129 | aOverride.originalURI.charset.get(), |
michael@0 | 130 | nullptr, io); |
michael@0 | 131 | if (NS_FAILED(rv)) |
michael@0 | 132 | return; |
michael@0 | 133 | |
michael@0 | 134 | rv = NS_NewURI(getter_AddRefs(overrideURI), aOverride.overrideURI.spec, |
michael@0 | 135 | aOverride.overrideURI.charset.get(), nullptr, io); |
michael@0 | 136 | if (NS_FAILED(rv)) |
michael@0 | 137 | return; |
michael@0 | 138 | |
michael@0 | 139 | mOverrideTable.Put(chromeURI, overrideURI); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | nsIURI* |
michael@0 | 143 | nsChromeRegistryContent::GetBaseURIFromPackage(const nsCString& aPackage, |
michael@0 | 144 | const nsCString& aProvider, |
michael@0 | 145 | const nsCString& aPath) |
michael@0 | 146 | { |
michael@0 | 147 | PackageEntry* entry; |
michael@0 | 148 | if (!mPackagesHash.Get(aPackage, &entry)) { |
michael@0 | 149 | return nullptr; |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | if (aProvider.EqualsLiteral("locale")) { |
michael@0 | 153 | return entry->localeBaseURI; |
michael@0 | 154 | } |
michael@0 | 155 | else if (aProvider.EqualsLiteral("skin")) { |
michael@0 | 156 | return entry->skinBaseURI; |
michael@0 | 157 | } |
michael@0 | 158 | else if (aProvider.EqualsLiteral("content")) { |
michael@0 | 159 | return entry->contentBaseURI; |
michael@0 | 160 | } |
michael@0 | 161 | return nullptr; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | nsresult |
michael@0 | 165 | nsChromeRegistryContent::GetFlagsFromPackage(const nsCString& aPackage, |
michael@0 | 166 | uint32_t* aFlags) |
michael@0 | 167 | { |
michael@0 | 168 | PackageEntry* entry; |
michael@0 | 169 | if (!mPackagesHash.Get(aPackage, &entry)) { |
michael@0 | 170 | return NS_ERROR_FAILURE; |
michael@0 | 171 | } |
michael@0 | 172 | *aFlags = entry->flags; |
michael@0 | 173 | return NS_OK; |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | // All functions following only make sense in chrome, and therefore assert |
michael@0 | 177 | |
michael@0 | 178 | #define CONTENT_NOTREACHED() \ |
michael@0 | 179 | NS_NOTREACHED("Content should not be calling this") |
michael@0 | 180 | |
michael@0 | 181 | #define CONTENT_NOT_IMPLEMENTED() \ |
michael@0 | 182 | CONTENT_NOTREACHED(); \ |
michael@0 | 183 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 184 | |
michael@0 | 185 | NS_IMETHODIMP |
michael@0 | 186 | nsChromeRegistryContent::GetLocalesForPackage(const nsACString& aPackage, |
michael@0 | 187 | nsIUTF8StringEnumerator* *aResult) |
michael@0 | 188 | { |
michael@0 | 189 | CONTENT_NOT_IMPLEMENTED(); |
michael@0 | 190 | } |
michael@0 | 191 | |
michael@0 | 192 | NS_IMETHODIMP |
michael@0 | 193 | nsChromeRegistryContent::CheckForOSAccessibility() |
michael@0 | 194 | { |
michael@0 | 195 | CONTENT_NOT_IMPLEMENTED(); |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | NS_IMETHODIMP |
michael@0 | 199 | nsChromeRegistryContent::CheckForNewChrome() |
michael@0 | 200 | { |
michael@0 | 201 | CONTENT_NOT_IMPLEMENTED(); |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | NS_IMETHODIMP |
michael@0 | 205 | nsChromeRegistryContent::IsLocaleRTL(const nsACString& package, |
michael@0 | 206 | bool *aResult) |
michael@0 | 207 | { |
michael@0 | 208 | CONTENT_NOT_IMPLEMENTED(); |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | NS_IMETHODIMP |
michael@0 | 212 | nsChromeRegistryContent::GetSelectedLocale(const nsACString& aPackage, |
michael@0 | 213 | nsACString& aLocale) |
michael@0 | 214 | { |
michael@0 | 215 | if (aPackage != nsDependentCString("global")) { |
michael@0 | 216 | NS_ERROR("Uh-oh, caller wanted something other than 'some local'"); |
michael@0 | 217 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 218 | } |
michael@0 | 219 | aLocale = mLocale; |
michael@0 | 220 | return NS_OK; |
michael@0 | 221 | } |
michael@0 | 222 | |
michael@0 | 223 | NS_IMETHODIMP |
michael@0 | 224 | nsChromeRegistryContent::Observe(nsISupports* aSubject, const char* aTopic, |
michael@0 | 225 | const char16_t* aData) |
michael@0 | 226 | { |
michael@0 | 227 | CONTENT_NOT_IMPLEMENTED(); |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | NS_IMETHODIMP |
michael@0 | 231 | nsChromeRegistryContent::GetStyleOverlays(nsIURI *aChromeURL, |
michael@0 | 232 | nsISimpleEnumerator **aResult) |
michael@0 | 233 | { |
michael@0 | 234 | CONTENT_NOT_IMPLEMENTED(); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | NS_IMETHODIMP |
michael@0 | 238 | nsChromeRegistryContent::GetXULOverlays(nsIURI *aChromeURL, |
michael@0 | 239 | nsISimpleEnumerator **aResult) |
michael@0 | 240 | { |
michael@0 | 241 | CONTENT_NOT_IMPLEMENTED(); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | nsresult nsChromeRegistryContent::UpdateSelectedLocale() |
michael@0 | 245 | { |
michael@0 | 246 | CONTENT_NOT_IMPLEMENTED(); |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | void |
michael@0 | 250 | nsChromeRegistryContent::ManifestContent(ManifestProcessingContext& cx, |
michael@0 | 251 | int lineno, char *const * argv, |
michael@0 | 252 | bool platform, bool contentaccessible) |
michael@0 | 253 | { |
michael@0 | 254 | CONTENT_NOTREACHED(); |
michael@0 | 255 | } |
michael@0 | 256 | |
michael@0 | 257 | void |
michael@0 | 258 | nsChromeRegistryContent::ManifestLocale(ManifestProcessingContext& cx, |
michael@0 | 259 | int lineno, |
michael@0 | 260 | char *const * argv, bool platform, |
michael@0 | 261 | bool contentaccessible) |
michael@0 | 262 | { |
michael@0 | 263 | CONTENT_NOTREACHED(); |
michael@0 | 264 | } |
michael@0 | 265 | |
michael@0 | 266 | void |
michael@0 | 267 | nsChromeRegistryContent::ManifestSkin(ManifestProcessingContext& cx, |
michael@0 | 268 | int lineno, |
michael@0 | 269 | char *const * argv, bool platform, |
michael@0 | 270 | bool contentaccessible) |
michael@0 | 271 | { |
michael@0 | 272 | CONTENT_NOTREACHED(); |
michael@0 | 273 | } |
michael@0 | 274 | |
michael@0 | 275 | void |
michael@0 | 276 | nsChromeRegistryContent::ManifestOverlay(ManifestProcessingContext& cx, int lineno, |
michael@0 | 277 | char *const * argv, bool platform, |
michael@0 | 278 | bool contentaccessible) |
michael@0 | 279 | { |
michael@0 | 280 | CONTENT_NOTREACHED(); |
michael@0 | 281 | } |
michael@0 | 282 | |
michael@0 | 283 | void |
michael@0 | 284 | nsChromeRegistryContent::ManifestStyle(ManifestProcessingContext& cx, |
michael@0 | 285 | int lineno, |
michael@0 | 286 | char *const * argv, bool platform, |
michael@0 | 287 | bool contentaccessible) |
michael@0 | 288 | { |
michael@0 | 289 | CONTENT_NOTREACHED(); |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | void |
michael@0 | 293 | nsChromeRegistryContent::ManifestOverride(ManifestProcessingContext& cx, |
michael@0 | 294 | int lineno, |
michael@0 | 295 | char *const * argv, bool platform, |
michael@0 | 296 | bool contentaccessible) |
michael@0 | 297 | { |
michael@0 | 298 | CONTENT_NOTREACHED(); |
michael@0 | 299 | } |
michael@0 | 300 | |
michael@0 | 301 | void |
michael@0 | 302 | nsChromeRegistryContent::ManifestResource(ManifestProcessingContext& cx, |
michael@0 | 303 | int lineno, |
michael@0 | 304 | char *const * argv, bool platform, |
michael@0 | 305 | bool contentaccessible) |
michael@0 | 306 | { |
michael@0 | 307 | CONTENT_NOTREACHED(); |
michael@0 | 308 | } |