1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/chrome/src/nsChromeRegistry.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,631 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sw=2 et tw=78: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "nsChromeRegistry.h" 1.11 +#include "nsChromeRegistryChrome.h" 1.12 +#include "nsChromeRegistryContent.h" 1.13 + 1.14 +#include "prprf.h" 1.15 + 1.16 +#include "nsCOMPtr.h" 1.17 +#include "nsError.h" 1.18 +#include "nsEscape.h" 1.19 +#include "nsNetUtil.h" 1.20 +#include "nsString.h" 1.21 + 1.22 +#include "nsCSSStyleSheet.h" 1.23 +#include "nsIConsoleService.h" 1.24 +#include "nsIDocument.h" 1.25 +#include "nsIDOMDocument.h" 1.26 +#include "nsIDOMLocation.h" 1.27 +#include "nsIDOMWindowCollection.h" 1.28 +#include "nsIDOMWindow.h" 1.29 +#include "nsIObserverService.h" 1.30 +#include "nsIPresShell.h" 1.31 +#include "nsIScriptError.h" 1.32 +#include "nsIWindowMediator.h" 1.33 +#include "mozilla/dom/URL.h" 1.34 + 1.35 +nsChromeRegistry* nsChromeRegistry::gChromeRegistry; 1.36 +using mozilla::dom::IsChromeURI; 1.37 + 1.38 +//////////////////////////////////////////////////////////////////////////////// 1.39 + 1.40 +void 1.41 +nsChromeRegistry::LogMessage(const char* aMsg, ...) 1.42 +{ 1.43 + nsCOMPtr<nsIConsoleService> console 1.44 + (do_GetService(NS_CONSOLESERVICE_CONTRACTID)); 1.45 + if (!console) 1.46 + return; 1.47 + 1.48 + va_list args; 1.49 + va_start(args, aMsg); 1.50 + char* formatted = PR_vsmprintf(aMsg, args); 1.51 + va_end(args); 1.52 + if (!formatted) 1.53 + return; 1.54 + 1.55 + console->LogStringMessage(NS_ConvertUTF8toUTF16(formatted).get()); 1.56 + PR_smprintf_free(formatted); 1.57 +} 1.58 + 1.59 +void 1.60 +nsChromeRegistry::LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber, uint32_t flags, 1.61 + const char* aMsg, ...) 1.62 +{ 1.63 + nsresult rv; 1.64 + 1.65 + nsCOMPtr<nsIConsoleService> console 1.66 + (do_GetService(NS_CONSOLESERVICE_CONTRACTID)); 1.67 + 1.68 + nsCOMPtr<nsIScriptError> error 1.69 + (do_CreateInstance(NS_SCRIPTERROR_CONTRACTID)); 1.70 + if (!console || !error) 1.71 + return; 1.72 + 1.73 + va_list args; 1.74 + va_start(args, aMsg); 1.75 + char* formatted = PR_vsmprintf(aMsg, args); 1.76 + va_end(args); 1.77 + if (!formatted) 1.78 + return; 1.79 + 1.80 + nsCString spec; 1.81 + if (aURL) 1.82 + aURL->GetSpec(spec); 1.83 + 1.84 + rv = error->Init(NS_ConvertUTF8toUTF16(formatted), 1.85 + NS_ConvertUTF8toUTF16(spec), 1.86 + EmptyString(), 1.87 + aLineNumber, 0, flags, "chrome registration"); 1.88 + PR_smprintf_free(formatted); 1.89 + 1.90 + if (NS_FAILED(rv)) 1.91 + return; 1.92 + 1.93 + console->LogMessage(error); 1.94 +} 1.95 + 1.96 +nsChromeRegistry::~nsChromeRegistry() 1.97 +{ 1.98 + gChromeRegistry = nullptr; 1.99 +} 1.100 + 1.101 +NS_INTERFACE_MAP_BEGIN(nsChromeRegistry) 1.102 + NS_INTERFACE_MAP_ENTRY(nsIChromeRegistry) 1.103 + NS_INTERFACE_MAP_ENTRY(nsIXULChromeRegistry) 1.104 + NS_INTERFACE_MAP_ENTRY(nsIToolkitChromeRegistry) 1.105 +#ifdef MOZ_XUL 1.106 + NS_INTERFACE_MAP_ENTRY(nsIXULOverlayProvider) 1.107 +#endif 1.108 + NS_INTERFACE_MAP_ENTRY(nsIObserver) 1.109 + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) 1.110 + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChromeRegistry) 1.111 +NS_INTERFACE_MAP_END 1.112 + 1.113 +NS_IMPL_ADDREF(nsChromeRegistry) 1.114 +NS_IMPL_RELEASE(nsChromeRegistry) 1.115 + 1.116 +//////////////////////////////////////////////////////////////////////////////// 1.117 +// nsIChromeRegistry methods: 1.118 + 1.119 +already_AddRefed<nsIChromeRegistry> 1.120 +nsChromeRegistry::GetService() 1.121 +{ 1.122 + if (!gChromeRegistry) 1.123 + { 1.124 + // We don't actually want this ref, we just want the service to 1.125 + // initialize if it hasn't already. 1.126 + nsCOMPtr<nsIChromeRegistry> reg( 1.127 + do_GetService(NS_CHROMEREGISTRY_CONTRACTID)); 1.128 + if (!gChromeRegistry) 1.129 + return nullptr; 1.130 + } 1.131 + nsCOMPtr<nsIChromeRegistry> registry = gChromeRegistry; 1.132 + return registry.forget(); 1.133 +} 1.134 + 1.135 +nsresult 1.136 +nsChromeRegistry::Init() 1.137 +{ 1.138 + // This initialization process is fairly complicated and may cause reentrant 1.139 + // getservice calls to resolve chrome URIs (especially locale files). We 1.140 + // don't want that, so we inform the protocol handler about our existence 1.141 + // before we are actually fully initialized. 1.142 + gChromeRegistry = this; 1.143 + 1.144 + mInitialized = true; 1.145 + 1.146 + return NS_OK; 1.147 +} 1.148 + 1.149 +nsresult 1.150 +nsChromeRegistry::GetProviderAndPath(nsIURL* aChromeURL, 1.151 + nsACString& aProvider, nsACString& aPath) 1.152 +{ 1.153 + nsresult rv; 1.154 + 1.155 +#ifdef DEBUG 1.156 + bool isChrome; 1.157 + aChromeURL->SchemeIs("chrome", &isChrome); 1.158 + NS_ASSERTION(isChrome, "Non-chrome URI?"); 1.159 +#endif 1.160 + 1.161 + nsAutoCString path; 1.162 + rv = aChromeURL->GetPath(path); 1.163 + NS_ENSURE_SUCCESS(rv, rv); 1.164 + 1.165 + if (path.Length() < 3) { 1.166 + LogMessage("Invalid chrome URI: %s", path.get()); 1.167 + return NS_ERROR_FAILURE; 1.168 + } 1.169 + 1.170 + path.SetLength(nsUnescapeCount(path.BeginWriting())); 1.171 + NS_ASSERTION(path.First() == '/', "Path should always begin with a slash!"); 1.172 + 1.173 + int32_t slash = path.FindChar('/', 1); 1.174 + if (slash == 1) { 1.175 + LogMessage("Invalid chrome URI: %s", path.get()); 1.176 + return NS_ERROR_FAILURE; 1.177 + } 1.178 + 1.179 + if (slash == -1) { 1.180 + aPath.Truncate(); 1.181 + } 1.182 + else { 1.183 + if (slash == (int32_t) path.Length() - 1) 1.184 + aPath.Truncate(); 1.185 + else 1.186 + aPath.Assign(path.get() + slash + 1, path.Length() - slash - 1); 1.187 + 1.188 + --slash; 1.189 + } 1.190 + 1.191 + aProvider.Assign(path.get() + 1, slash); 1.192 + return NS_OK; 1.193 +} 1.194 + 1.195 + 1.196 +nsresult 1.197 +nsChromeRegistry::Canonify(nsIURL* aChromeURL) 1.198 +{ 1.199 + NS_NAMED_LITERAL_CSTRING(kSlash, "/"); 1.200 + 1.201 + nsresult rv; 1.202 + 1.203 + nsAutoCString provider, path; 1.204 + rv = GetProviderAndPath(aChromeURL, provider, path); 1.205 + NS_ENSURE_SUCCESS(rv, rv); 1.206 + 1.207 + if (path.IsEmpty()) { 1.208 + nsAutoCString package; 1.209 + rv = aChromeURL->GetHost(package); 1.210 + NS_ENSURE_SUCCESS(rv, rv); 1.211 + 1.212 + // we re-use the "path" local string to build a new URL path 1.213 + path.Assign(kSlash + provider + kSlash + package); 1.214 + if (provider.EqualsLiteral("content")) { 1.215 + path.AppendLiteral(".xul"); 1.216 + } 1.217 + else if (provider.EqualsLiteral("locale")) { 1.218 + path.AppendLiteral(".dtd"); 1.219 + } 1.220 + else if (provider.EqualsLiteral("skin")) { 1.221 + path.AppendLiteral(".css"); 1.222 + } 1.223 + else { 1.224 + return NS_ERROR_INVALID_ARG; 1.225 + } 1.226 + aChromeURL->SetPath(path); 1.227 + } 1.228 + else { 1.229 + // prevent directory traversals ("..") 1.230 + // path is already unescaped once, but uris can get unescaped twice 1.231 + const char* pos = path.BeginReading(); 1.232 + const char* end = path.EndReading(); 1.233 + while (pos < end) { 1.234 + switch (*pos) { 1.235 + case ':': 1.236 + return NS_ERROR_DOM_BAD_URI; 1.237 + case '.': 1.238 + if (pos[1] == '.') 1.239 + return NS_ERROR_DOM_BAD_URI; 1.240 + break; 1.241 + case '%': 1.242 + // chrome: URIs with double-escapes are trying to trick us. 1.243 + // watch for %2e, and %25 in case someone triple unescapes 1.244 + if (pos[1] == '2' && 1.245 + ( pos[2] == 'e' || pos[2] == 'E' || 1.246 + pos[2] == '5' )) 1.247 + return NS_ERROR_DOM_BAD_URI; 1.248 + break; 1.249 + case '?': 1.250 + case '#': 1.251 + pos = end; 1.252 + continue; 1.253 + } 1.254 + ++pos; 1.255 + } 1.256 + } 1.257 + 1.258 + return NS_OK; 1.259 +} 1.260 + 1.261 +NS_IMETHODIMP 1.262 +nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult) 1.263 +{ 1.264 + nsresult rv; 1.265 + NS_ASSERTION(aChromeURI, "null url!"); 1.266 + 1.267 + if (mOverrideTable.Get(aChromeURI, aResult)) 1.268 + return NS_OK; 1.269 + 1.270 + nsCOMPtr<nsIURL> chromeURL (do_QueryInterface(aChromeURI)); 1.271 + NS_ENSURE_TRUE(chromeURL, NS_NOINTERFACE); 1.272 + 1.273 + nsAutoCString package, provider, path; 1.274 + rv = chromeURL->GetHostPort(package); 1.275 + NS_ENSURE_SUCCESS(rv, rv); 1.276 + 1.277 + rv = GetProviderAndPath(chromeURL, provider, path); 1.278 + NS_ENSURE_SUCCESS(rv, rv); 1.279 + 1.280 + nsIURI* baseURI = GetBaseURIFromPackage(package, provider, path); 1.281 + 1.282 + uint32_t flags; 1.283 + rv = GetFlagsFromPackage(package, &flags); 1.284 + if (NS_FAILED(rv)) 1.285 + return rv; 1.286 + 1.287 + if (flags & PLATFORM_PACKAGE) { 1.288 +#if defined(XP_WIN) 1.289 + path.Insert("win/", 0); 1.290 +#elif defined(XP_MACOSX) 1.291 + path.Insert("mac/", 0); 1.292 +#else 1.293 + path.Insert("unix/", 0); 1.294 +#endif 1.295 + } 1.296 + 1.297 + if (!baseURI) { 1.298 + LogMessage("No chrome package registered for chrome://%s/%s/%s", 1.299 + package.get(), provider.get(), path.get()); 1.300 + return NS_ERROR_FAILURE; 1.301 + } 1.302 + 1.303 + return NS_NewURI(aResult, path, nullptr, baseURI); 1.304 +} 1.305 + 1.306 +//////////////////////////////////////////////////////////////////////// 1.307 + 1.308 +// theme stuff 1.309 + 1.310 + 1.311 +static void FlushSkinBindingsForWindow(nsIDOMWindow* aWindow) 1.312 +{ 1.313 + // Get the DOM document. 1.314 + nsCOMPtr<nsIDOMDocument> domDocument; 1.315 + aWindow->GetDocument(getter_AddRefs(domDocument)); 1.316 + if (!domDocument) 1.317 + return; 1.318 + 1.319 + nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument); 1.320 + if (!document) 1.321 + return; 1.322 + 1.323 + // Annihilate all XBL bindings. 1.324 + document->FlushSkinBindings(); 1.325 +} 1.326 + 1.327 +// XXXbsmedberg: move this to nsIWindowMediator 1.328 +NS_IMETHODIMP nsChromeRegistry::RefreshSkins() 1.329 +{ 1.330 + nsCOMPtr<nsIWindowMediator> windowMediator 1.331 + (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID)); 1.332 + if (!windowMediator) 1.333 + return NS_OK; 1.334 + 1.335 + nsCOMPtr<nsISimpleEnumerator> windowEnumerator; 1.336 + windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator)); 1.337 + bool more; 1.338 + windowEnumerator->HasMoreElements(&more); 1.339 + while (more) { 1.340 + nsCOMPtr<nsISupports> protoWindow; 1.341 + windowEnumerator->GetNext(getter_AddRefs(protoWindow)); 1.342 + if (protoWindow) { 1.343 + nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow); 1.344 + if (domWindow) 1.345 + FlushSkinBindingsForWindow(domWindow); 1.346 + } 1.347 + windowEnumerator->HasMoreElements(&more); 1.348 + } 1.349 + 1.350 + FlushSkinCaches(); 1.351 + 1.352 + windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator)); 1.353 + windowEnumerator->HasMoreElements(&more); 1.354 + while (more) { 1.355 + nsCOMPtr<nsISupports> protoWindow; 1.356 + windowEnumerator->GetNext(getter_AddRefs(protoWindow)); 1.357 + if (protoWindow) { 1.358 + nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow); 1.359 + if (domWindow) 1.360 + RefreshWindow(domWindow); 1.361 + } 1.362 + windowEnumerator->HasMoreElements(&more); 1.363 + } 1.364 + 1.365 + return NS_OK; 1.366 +} 1.367 + 1.368 +void 1.369 +nsChromeRegistry::FlushSkinCaches() 1.370 +{ 1.371 + nsCOMPtr<nsIObserverService> obsSvc = 1.372 + mozilla::services::GetObserverService(); 1.373 + NS_ASSERTION(obsSvc, "Couldn't get observer service."); 1.374 + 1.375 + obsSvc->NotifyObservers(static_cast<nsIChromeRegistry*>(this), 1.376 + NS_CHROME_FLUSH_SKINS_TOPIC, nullptr); 1.377 +} 1.378 + 1.379 +// XXXbsmedberg: move this to windowmediator 1.380 +nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow) 1.381 +{ 1.382 + // Deal with our subframes first. 1.383 + nsCOMPtr<nsIDOMWindowCollection> frames; 1.384 + aWindow->GetFrames(getter_AddRefs(frames)); 1.385 + uint32_t length; 1.386 + frames->GetLength(&length); 1.387 + uint32_t j; 1.388 + for (j = 0; j < length; j++) { 1.389 + nsCOMPtr<nsIDOMWindow> childWin; 1.390 + frames->Item(j, getter_AddRefs(childWin)); 1.391 + RefreshWindow(childWin); 1.392 + } 1.393 + 1.394 + nsresult rv; 1.395 + // Get the DOM document. 1.396 + nsCOMPtr<nsIDOMDocument> domDocument; 1.397 + aWindow->GetDocument(getter_AddRefs(domDocument)); 1.398 + if (!domDocument) 1.399 + return NS_OK; 1.400 + 1.401 + nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument); 1.402 + if (!document) 1.403 + return NS_OK; 1.404 + 1.405 + // Deal with the agent sheets first. Have to do all the style sets by hand. 1.406 + nsCOMPtr<nsIPresShell> shell = document->GetShell(); 1.407 + if (shell) { 1.408 + // Reload only the chrome URL agent style sheets. 1.409 + nsCOMArray<nsIStyleSheet> agentSheets; 1.410 + rv = shell->GetAgentStyleSheets(agentSheets); 1.411 + NS_ENSURE_SUCCESS(rv, rv); 1.412 + 1.413 + nsCOMArray<nsIStyleSheet> newAgentSheets; 1.414 + for (int32_t l = 0; l < agentSheets.Count(); ++l) { 1.415 + nsIStyleSheet *sheet = agentSheets[l]; 1.416 + 1.417 + nsIURI* uri = sheet->GetSheetURI(); 1.418 + 1.419 + if (IsChromeURI(uri)) { 1.420 + // Reload the sheet. 1.421 + nsRefPtr<nsCSSStyleSheet> newSheet; 1.422 + rv = document->LoadChromeSheetSync(uri, true, 1.423 + getter_AddRefs(newSheet)); 1.424 + if (NS_FAILED(rv)) return rv; 1.425 + if (newSheet) { 1.426 + rv = newAgentSheets.AppendObject(newSheet) ? NS_OK : NS_ERROR_FAILURE; 1.427 + if (NS_FAILED(rv)) return rv; 1.428 + } 1.429 + } 1.430 + else { // Just use the same sheet. 1.431 + rv = newAgentSheets.AppendObject(sheet) ? NS_OK : NS_ERROR_FAILURE; 1.432 + if (NS_FAILED(rv)) return rv; 1.433 + } 1.434 + } 1.435 + 1.436 + rv = shell->SetAgentStyleSheets(newAgentSheets); 1.437 + NS_ENSURE_SUCCESS(rv, rv); 1.438 + } 1.439 + 1.440 + // Build an array of nsIURIs of style sheets we need to load. 1.441 + nsCOMArray<nsIStyleSheet> oldSheets; 1.442 + nsCOMArray<nsIStyleSheet> newSheets; 1.443 + 1.444 + int32_t count = document->GetNumberOfStyleSheets(); 1.445 + 1.446 + // Iterate over the style sheets. 1.447 + int32_t i; 1.448 + for (i = 0; i < count; i++) { 1.449 + // Get the style sheet 1.450 + nsIStyleSheet *styleSheet = document->GetStyleSheetAt(i); 1.451 + 1.452 + if (!oldSheets.AppendObject(styleSheet)) { 1.453 + return NS_ERROR_OUT_OF_MEMORY; 1.454 + } 1.455 + } 1.456 + 1.457 + // Iterate over our old sheets and kick off a sync load of the new 1.458 + // sheet if and only if it's a chrome URL. 1.459 + for (i = 0; i < count; i++) { 1.460 + nsRefPtr<nsCSSStyleSheet> sheet = do_QueryObject(oldSheets[i]); 1.461 + nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr; 1.462 + 1.463 + if (uri && IsChromeURI(uri)) { 1.464 + // Reload the sheet. 1.465 + nsRefPtr<nsCSSStyleSheet> newSheet; 1.466 + // XXX what about chrome sheets that have a title or are disabled? This 1.467 + // only works by sheer dumb luck. 1.468 + document->LoadChromeSheetSync(uri, false, getter_AddRefs(newSheet)); 1.469 + // Even if it's null, we put in in there. 1.470 + newSheets.AppendObject(newSheet); 1.471 + } 1.472 + else { 1.473 + // Just use the same sheet. 1.474 + newSheets.AppendObject(sheet); 1.475 + } 1.476 + } 1.477 + 1.478 + // Now notify the document that multiple sheets have been added and removed. 1.479 + document->UpdateStyleSheets(oldSheets, newSheets); 1.480 + return NS_OK; 1.481 +} 1.482 + 1.483 +void 1.484 +nsChromeRegistry::FlushAllCaches() 1.485 +{ 1.486 + nsCOMPtr<nsIObserverService> obsSvc = 1.487 + mozilla::services::GetObserverService(); 1.488 + NS_ASSERTION(obsSvc, "Couldn't get observer service."); 1.489 + 1.490 + obsSvc->NotifyObservers((nsIChromeRegistry*) this, 1.491 + NS_CHROME_FLUSH_TOPIC, nullptr); 1.492 +} 1.493 + 1.494 +// xxxbsmedberg Move me to nsIWindowMediator 1.495 +NS_IMETHODIMP 1.496 +nsChromeRegistry::ReloadChrome() 1.497 +{ 1.498 + UpdateSelectedLocale(); 1.499 + FlushAllCaches(); 1.500 + // Do a reload of all top level windows. 1.501 + nsresult rv = NS_OK; 1.502 + 1.503 + // Get the window mediator 1.504 + nsCOMPtr<nsIWindowMediator> windowMediator 1.505 + (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID)); 1.506 + if (windowMediator) { 1.507 + nsCOMPtr<nsISimpleEnumerator> windowEnumerator; 1.508 + 1.509 + rv = windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator)); 1.510 + if (NS_SUCCEEDED(rv)) { 1.511 + // Get each dom window 1.512 + bool more; 1.513 + rv = windowEnumerator->HasMoreElements(&more); 1.514 + if (NS_FAILED(rv)) return rv; 1.515 + while (more) { 1.516 + nsCOMPtr<nsISupports> protoWindow; 1.517 + rv = windowEnumerator->GetNext(getter_AddRefs(protoWindow)); 1.518 + if (NS_SUCCEEDED(rv)) { 1.519 + nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow); 1.520 + if (domWindow) { 1.521 + nsCOMPtr<nsIDOMLocation> location; 1.522 + domWindow->GetLocation(getter_AddRefs(location)); 1.523 + if (location) { 1.524 + rv = location->Reload(false); 1.525 + if (NS_FAILED(rv)) return rv; 1.526 + } 1.527 + } 1.528 + } 1.529 + rv = windowEnumerator->HasMoreElements(&more); 1.530 + if (NS_FAILED(rv)) return rv; 1.531 + } 1.532 + } 1.533 + } 1.534 + return rv; 1.535 +} 1.536 + 1.537 +NS_IMETHODIMP 1.538 +nsChromeRegistry::AllowScriptsForPackage(nsIURI* aChromeURI, bool *aResult) 1.539 +{ 1.540 + nsresult rv; 1.541 + *aResult = false; 1.542 + 1.543 +#ifdef DEBUG 1.544 + bool isChrome; 1.545 + aChromeURI->SchemeIs("chrome", &isChrome); 1.546 + NS_ASSERTION(isChrome, "Non-chrome URI passed to AllowScriptsForPackage!"); 1.547 +#endif 1.548 + 1.549 + nsCOMPtr<nsIURL> url (do_QueryInterface(aChromeURI)); 1.550 + NS_ENSURE_TRUE(url, NS_NOINTERFACE); 1.551 + 1.552 + nsAutoCString provider, file; 1.553 + rv = GetProviderAndPath(url, provider, file); 1.554 + NS_ENSURE_SUCCESS(rv, rv); 1.555 + 1.556 + if (!provider.EqualsLiteral("skin")) 1.557 + *aResult = true; 1.558 + 1.559 + return NS_OK; 1.560 +} 1.561 + 1.562 +NS_IMETHODIMP 1.563 +nsChromeRegistry::AllowContentToAccess(nsIURI *aURI, bool *aResult) 1.564 +{ 1.565 + nsresult rv; 1.566 + 1.567 + *aResult = false; 1.568 + 1.569 +#ifdef DEBUG 1.570 + bool isChrome; 1.571 + aURI->SchemeIs("chrome", &isChrome); 1.572 + NS_ASSERTION(isChrome, "Non-chrome URI passed to AllowContentToAccess!"); 1.573 +#endif 1.574 + 1.575 + nsCOMPtr<nsIURL> url = do_QueryInterface(aURI); 1.576 + if (!url) { 1.577 + NS_ERROR("Chrome URL doesn't implement nsIURL."); 1.578 + return NS_ERROR_UNEXPECTED; 1.579 + } 1.580 + 1.581 + nsAutoCString package; 1.582 + rv = url->GetHostPort(package); 1.583 + NS_ENSURE_SUCCESS(rv, rv); 1.584 + 1.585 + uint32_t flags; 1.586 + rv = GetFlagsFromPackage(package, &flags); 1.587 + 1.588 + if (NS_SUCCEEDED(rv)) { 1.589 + *aResult = !!(flags & CONTENT_ACCESSIBLE); 1.590 + } 1.591 + return NS_OK; 1.592 +} 1.593 + 1.594 +NS_IMETHODIMP_(bool) 1.595 +nsChromeRegistry::WrappersEnabled(nsIURI *aURI) 1.596 +{ 1.597 + nsCOMPtr<nsIURL> chromeURL (do_QueryInterface(aURI)); 1.598 + if (!chromeURL) 1.599 + return false; 1.600 + 1.601 + bool isChrome = false; 1.602 + nsresult rv = chromeURL->SchemeIs("chrome", &isChrome); 1.603 + if (NS_FAILED(rv) || !isChrome) 1.604 + return false; 1.605 + 1.606 + nsAutoCString package; 1.607 + rv = chromeURL->GetHostPort(package); 1.608 + if (NS_FAILED(rv)) 1.609 + return false; 1.610 + 1.611 + uint32_t flags; 1.612 + rv = GetFlagsFromPackage(package, &flags); 1.613 + return NS_SUCCEEDED(rv) && (flags & XPCNATIVEWRAPPERS); 1.614 +} 1.615 + 1.616 +already_AddRefed<nsChromeRegistry> 1.617 +nsChromeRegistry::GetSingleton() 1.618 +{ 1.619 + if (gChromeRegistry) { 1.620 + nsRefPtr<nsChromeRegistry> registry = gChromeRegistry; 1.621 + return registry.forget(); 1.622 + } 1.623 + 1.624 + nsRefPtr<nsChromeRegistry> cr; 1.625 + if (GeckoProcessType_Content == XRE_GetProcessType()) 1.626 + cr = new nsChromeRegistryContent(); 1.627 + else 1.628 + cr = new nsChromeRegistryChrome(); 1.629 + 1.630 + if (NS_FAILED(cr->Init())) 1.631 + return nullptr; 1.632 + 1.633 + return cr.forget(); 1.634 +}