2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2007-12-20 03:11:02 +00:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-04-02 00:52:35 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
#include "nsChromeRegistry.h"
|
2010-07-01 15:55:57 +00:00
|
|
|
#include "nsChromeRegistryChrome.h"
|
|
|
|
#include "nsChromeRegistryContent.h"
|
2005-02-22 21:49:45 +00:00
|
|
|
|
1999-04-02 00:52:35 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2005-02-22 21:49:45 +00:00
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsString.h"
|
2015-04-15 16:47:03 +00:00
|
|
|
#include "nsQueryObject.h"
|
2005-02-22 21:49:45 +00:00
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
#include "mozilla/dom/URL.h"
|
2005-04-05 15:20:20 +00:00
|
|
|
#include "nsIConsoleService.h"
|
2019-01-02 13:05:23 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
2005-02-22 21:49:45 +00:00
|
|
|
#include "nsIObserverService.h"
|
2005-04-05 15:20:20 +00:00
|
|
|
#include "nsIScriptError.h"
|
2017-03-28 09:05:12 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-03-29 15:12:47 +00:00
|
|
|
#include "mozilla/PresShell.h"
|
2016-12-09 19:58:57 +00:00
|
|
|
#include "mozilla/Printf.h"
|
2016-09-26 12:03:25 +00:00
|
|
|
#include "mozilla/StyleSheet.h"
|
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2017-05-08 13:49:31 +00:00
|
|
|
#include "mozilla/dom/Location.h"
|
1999-12-01 08:44:43 +00:00
|
|
|
|
2005-02-25 21:11:46 +00:00
|
|
|
nsChromeRegistry* nsChromeRegistry::gChromeRegistry;
|
2014-06-20 10:32:49 +00:00
|
|
|
|
|
|
|
// DO NOT use namespace mozilla; it'll break due to a naming conflict between
|
|
|
|
// mozilla::TextRange and a TextRange in OSX headers.
|
2019-03-29 15:12:47 +00:00
|
|
|
using mozilla::PresShell;
|
2016-09-26 12:03:25 +00:00
|
|
|
using mozilla::StyleSheet;
|
2019-01-02 13:05:23 +00:00
|
|
|
using mozilla::dom::Document;
|
2017-05-08 13:49:31 +00:00
|
|
|
using mozilla::dom::Location;
|
2004-10-13 19:05:48 +00:00
|
|
|
|
1999-04-02 00:52:35 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-05-13 23:44:53 +00:00
|
|
|
void nsChromeRegistry::LogMessage(const char* aMsg, ...) {
|
2005-04-05 15:20:20 +00:00
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (!console) return;
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, aMsg);
|
2017-03-03 15:17:27 +00:00
|
|
|
mozilla::SmprintfPointer formatted = mozilla::Vsmprintf(aMsg, args);
|
2005-04-05 15:20:20 +00:00
|
|
|
va_end(args);
|
|
|
|
if (!formatted) return;
|
|
|
|
|
2017-03-03 15:17:27 +00:00
|
|
|
console->LogStringMessage(NS_ConvertUTF8toUTF16(formatted.get()).get());
|
2005-04-05 15:20:20 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void nsChromeRegistry::LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber,
|
2010-05-13 23:44:53 +00:00
|
|
|
uint32_t flags, const char* aMsg,
|
|
|
|
...) {
|
2005-04-05 15:20:20 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
|
|
|
if (!console || !error) return;
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, aMsg);
|
2017-03-03 15:17:27 +00:00
|
|
|
mozilla::SmprintfPointer formatted = mozilla::Vsmprintf(aMsg, args);
|
2005-04-05 15:20:20 +00:00
|
|
|
va_end(args);
|
|
|
|
if (!formatted) return;
|
|
|
|
|
|
|
|
nsCString spec;
|
|
|
|
if (aURL) aURL->GetSpec(spec);
|
|
|
|
|
2020-09-23 15:17:15 +00:00
|
|
|
rv = error->Init(NS_ConvertUTF8toUTF16(formatted.get()),
|
|
|
|
NS_ConvertUTF8toUTF16(spec), u""_ns, aLineNumber, 0, flags,
|
|
|
|
"chrome registration", false /* from private window */,
|
|
|
|
true /* from chrome context */);
|
2005-04-05 15:20:20 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
nsChromeRegistry::~nsChromeRegistry() { gChromeRegistry = nullptr; }
|
1999-04-02 00:52:35 +00:00
|
|
|
|
2006-01-25 20:23:24 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsChromeRegistry)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIChromeRegistry)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXULChromeRegistry)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIToolkitChromeRegistry)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2006-01-26 01:07:37 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChromeRegistry)
|
2006-01-25 20:23:24 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsChromeRegistry)
|
|
|
|
NS_IMPL_RELEASE(nsChromeRegistry)
|
1999-04-02 00:52:35 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIChromeRegistry methods:
|
1999-07-30 00:53:42 +00:00
|
|
|
|
2010-03-11 05:33:00 +00:00
|
|
|
already_AddRefed<nsIChromeRegistry> nsChromeRegistry::GetService() {
|
2010-07-23 18:16:00 +00:00
|
|
|
if (!gChromeRegistry) {
|
2010-03-11 05:33:00 +00:00
|
|
|
// We don't actually want this ref, we just want the service to
|
|
|
|
// initialize if it hasn't already.
|
|
|
|
nsCOMPtr<nsIChromeRegistry> reg(
|
|
|
|
do_GetService(NS_CHROMEREGISTRY_CONTRACTID));
|
|
|
|
if (!gChromeRegistry) return nullptr;
|
|
|
|
}
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<nsIChromeRegistry> registry = gChromeRegistry;
|
|
|
|
return registry.forget();
|
2004-09-21 20:19:48 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 20:22:17 +00:00
|
|
|
nsresult nsChromeRegistry::Init() {
|
2005-02-25 21:11:46 +00:00
|
|
|
// This initialization process is fairly complicated and may cause reentrant
|
|
|
|
// getservice calls to resolve chrome URIs (especially locale files). We
|
|
|
|
// don't want that, so we inform the protocol handler about our existence
|
|
|
|
// before we are actually fully initialized.
|
|
|
|
gChromeRegistry = this;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = true;
|
2005-02-25 21:11:46 +00:00
|
|
|
|
2001-01-10 20:22:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-26 19:43:45 +00:00
|
|
|
nsresult nsChromeRegistry::GetProviderAndPath(nsIURI* aChromeURL,
|
2005-02-22 21:49:45 +00:00
|
|
|
nsACString& aProvider,
|
|
|
|
nsACString& aPath) {
|
2000-03-21 10:42:22 +00:00
|
|
|
nsresult rv;
|
2001-09-06 00:45:16 +00:00
|
|
|
|
2019-08-07 19:49:40 +00:00
|
|
|
NS_ASSERTION(aChromeURL->SchemeIs("chrome"), "Non-chrome URI?");
|
1999-04-02 00:52:35 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString path;
|
2017-07-29 11:50:21 +00:00
|
|
|
rv = aChromeURL->GetPathQueryRef(path);
|
2005-02-22 21:49:45 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-07-30 00:53:42 +00:00
|
|
|
|
2005-04-05 15:20:20 +00:00
|
|
|
if (path.Length() < 3) {
|
2020-05-01 16:34:22 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
LogMessage("Invalid chrome URI (need path): %s",
|
|
|
|
aChromeURL->GetSpecOrDefault().get());
|
|
|
|
#endif
|
2005-02-22 21:49:45 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2005-04-05 15:20:20 +00:00
|
|
|
}
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
path.SetLength(nsUnescapeCount(path.BeginWriting()));
|
|
|
|
NS_ASSERTION(path.First() == '/', "Path should always begin with a slash!");
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t slash = path.FindChar('/', 1);
|
2005-04-05 15:20:20 +00:00
|
|
|
if (slash == 1) {
|
2020-05-01 16:34:22 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
LogMessage("Invalid chrome URI (path cannot start with another slash): %s",
|
|
|
|
aChromeURL->GetSpecOrDefault().get());
|
|
|
|
#endif
|
2005-02-22 21:49:45 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2005-04-05 15:20:20 +00:00
|
|
|
}
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
if (slash == -1) {
|
|
|
|
aPath.Truncate();
|
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
if (slash == (int32_t)path.Length() - 1)
|
2005-02-22 21:49:45 +00:00
|
|
|
aPath.Truncate();
|
|
|
|
else
|
|
|
|
aPath.Assign(path.get() + slash + 1, path.Length() - slash - 1);
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
--slash;
|
2005-02-20 01:47:13 +00:00
|
|
|
}
|
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
aProvider.Assign(path.get() + 1, slash);
|
2005-02-20 01:47:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-26 19:43:45 +00:00
|
|
|
nsresult nsChromeRegistry::Canonify(nsCOMPtr<nsIURI>& aChromeURL) {
|
2005-02-23 00:01:54 +00:00
|
|
|
constexpr auto kSlash = "/"_ns;
|
|
|
|
|
2005-02-20 01:47:13 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString provider, path;
|
2005-02-22 21:49:45 +00:00
|
|
|
rv = GetProviderAndPath(aChromeURL, provider, path);
|
2005-02-20 01:47:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
if (path.IsEmpty()) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString package;
|
2005-02-22 21:49:45 +00:00
|
|
|
rv = aChromeURL->GetHost(package);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
// we re-use the "path" local string to build a new URL path
|
|
|
|
path.Assign(kSlash + provider + kSlash + package);
|
|
|
|
if (provider.EqualsLiteral("content")) {
|
|
|
|
path.AppendLiteral(".xul");
|
|
|
|
} else if (provider.EqualsLiteral("locale")) {
|
|
|
|
path.AppendLiteral(".dtd");
|
|
|
|
} else if (provider.EqualsLiteral("skin")) {
|
|
|
|
path.AppendLiteral(".css");
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2005-02-20 01:47:13 +00:00
|
|
|
}
|
2018-02-26 19:43:45 +00:00
|
|
|
return NS_MutateURI(aChromeURL).SetPathQueryRef(path).Finalize(aChromeURL);
|
2020-10-17 13:47:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// prevent directory traversals ("..")
|
|
|
|
// path is already unescaped once, but uris can get unescaped twice
|
|
|
|
const char* pos = path.BeginReading();
|
|
|
|
const char* end = path.EndReading();
|
|
|
|
// Must start with [a-zA-Z0-9].
|
|
|
|
if (!('a' <= *pos && *pos <= 'z') && !('A' <= *pos && *pos <= 'Z') &&
|
|
|
|
!('0' <= *pos && *pos <= '9')) {
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
while (pos < end) {
|
|
|
|
switch (*pos) {
|
|
|
|
case ':':
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
case '.':
|
|
|
|
if (pos[1] == '.') {
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
// chrome: URIs with double-escapes are trying to trick us.
|
|
|
|
// watch for %2e, and %25 in case someone triple unescapes
|
|
|
|
if (pos[1] == '2' &&
|
|
|
|
(pos[2] == 'e' || pos[2] == 'E' || pos[2] == '5')) {
|
2008-02-01 01:59:12 +00:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2020-10-17 13:47:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
case '#':
|
|
|
|
pos = end;
|
|
|
|
continue;
|
2006-05-19 23:32:49 +00:00
|
|
|
}
|
2020-10-17 13:47:13 +00:00
|
|
|
++pos;
|
2002-08-21 20:58:05 +00:00
|
|
|
}
|
|
|
|
|
2005-02-20 01:47:13 +00:00
|
|
|
return NS_OK;
|
2004-09-25 16:14:52 +00:00
|
|
|
}
|
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURI, nsIURI** aResult) {
|
2005-02-20 01:47:13 +00:00
|
|
|
nsresult rv;
|
2015-09-04 09:39:08 +00:00
|
|
|
if (NS_WARN_IF(!aChromeURI)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2004-09-21 20:19:48 +00:00
|
|
|
|
2005-06-01 19:09:44 +00:00
|
|
|
if (mOverrideTable.Get(aChromeURI, aResult)) return NS_OK;
|
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
nsCOMPtr<nsIURL> chromeURL(do_QueryInterface(aChromeURI));
|
|
|
|
NS_ENSURE_TRUE(chromeURL, NS_NOINTERFACE);
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString package, provider, path;
|
2005-02-22 21:49:45 +00:00
|
|
|
rv = chromeURL->GetHostPort(package);
|
2005-02-20 01:47:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
rv = GetProviderAndPath(chromeURL, provider, path);
|
2005-02-20 01:47:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-13 19:46:05 +00:00
|
|
|
nsIURI* baseURI = GetBaseURIFromPackage(package, provider, path);
|
2005-06-07 19:28:23 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flags;
|
2010-03-11 05:33:00 +00:00
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2005-04-05 15:20:20 +00:00
|
|
|
if (!baseURI) {
|
2007-11-13 08:50:30 +00:00
|
|
|
LogMessage("No chrome package registered for chrome://%s/%s/%s",
|
2005-04-05 15:20:20 +00:00
|
|
|
package.get(), provider.get(), path.get());
|
2014-06-20 23:50:58 +00:00
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
2005-04-05 15:20:20 +00:00
|
|
|
}
|
2004-09-25 16:14:52 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return NS_NewURI(aResult, path, nullptr, baseURI);
|
2000-05-13 21:42:56 +00:00
|
|
|
}
|
|
|
|
|
1999-08-05 04:33:41 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
void nsChromeRegistry::FlushAllCaches() {
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
|
2005-02-22 21:49:45 +00:00
|
|
|
NS_ASSERTION(obsSvc, "Couldn't get observer service.");
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
obsSvc->NotifyObservers((nsIChromeRegistry*)this, NS_CHROME_FLUSH_TOPIC,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr);
|
2005-02-22 21:49:45 +00:00
|
|
|
}
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsChromeRegistry::AllowScriptsForPackage(nsIURI* aChromeURI, bool* aResult) {
|
2004-09-21 20:19:48 +00:00
|
|
|
nsresult rv;
|
2011-10-17 14:59:28 +00:00
|
|
|
*aResult = false;
|
2001-03-08 01:50:36 +00:00
|
|
|
|
2019-08-07 19:49:40 +00:00
|
|
|
NS_ASSERTION(aChromeURI->SchemeIs("chrome"),
|
|
|
|
"Non-chrome URI passed to AllowScriptsForPackage!");
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(aChromeURI));
|
|
|
|
NS_ENSURE_TRUE(url, NS_NOINTERFACE);
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString provider, file;
|
2005-02-22 21:49:45 +00:00
|
|
|
rv = GetProviderAndPath(url, provider, file);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-20 01:47:13 +00:00
|
|
|
|
2005-02-22 21:49:45 +00:00
|
|
|
if (!provider.EqualsLiteral("skin")) *aResult = true;
|
2001-03-08 01:50:36 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-11 13:39:43 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsChromeRegistry::AllowContentToAccess(nsIURI* aURI, bool* aResult) {
|
2008-04-11 13:39:43 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*aResult = false;
|
2008-04-11 13:39:43 +00:00
|
|
|
|
2019-08-07 19:49:40 +00:00
|
|
|
NS_ASSERTION(aURI->SchemeIs("chrome"),
|
|
|
|
"Non-chrome URI passed to AllowContentToAccess!");
|
2008-04-11 13:39:43 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
|
|
|
|
if (!url) {
|
|
|
|
NS_ERROR("Chrome URL doesn't implement nsIURL.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString package;
|
2008-04-11 13:39:43 +00:00
|
|
|
rv = url->GetHostPort(package);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flags;
|
2010-03-11 05:33:00 +00:00
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
2008-04-11 13:39:43 +00:00
|
|
|
|
2010-03-11 05:33:00 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aResult = !!(flags & CONTENT_ACCESSIBLE);
|
2008-04-11 13:39:43 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-05 16:09:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistry::CanLoadURLRemotely(nsIURI* aURI, bool* aResult) {
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
*aResult = false;
|
|
|
|
|
2019-08-07 19:49:40 +00:00
|
|
|
NS_ASSERTION(aURI->SchemeIs("chrome"),
|
|
|
|
"Non-chrome URI passed to CanLoadURLRemotely!");
|
2015-02-05 16:09:15 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
|
|
|
|
if (!url) {
|
|
|
|
NS_ERROR("Chrome URL doesn't implement nsIURL.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString package;
|
|
|
|
rv = url->GetHostPort(package);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
uint32_t flags;
|
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aResult = !!(flags & REMOTE_ALLOWED);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistry::MustLoadURLRemotely(nsIURI* aURI, bool* aResult) {
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
*aResult = false;
|
|
|
|
|
2019-08-07 19:49:40 +00:00
|
|
|
NS_ASSERTION(aURI->SchemeIs("chrome"),
|
|
|
|
"Non-chrome URI passed to MustLoadURLRemotely!");
|
2015-02-05 16:09:15 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
|
|
|
|
if (!url) {
|
|
|
|
NS_ERROR("Chrome URL doesn't implement nsIURL.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString package;
|
|
|
|
rv = url->GetHostPort(package);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
uint32_t flags;
|
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aResult = !!(flags & REMOTE_REQUIRED);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-01 15:55:57 +00:00
|
|
|
already_AddRefed<nsChromeRegistry> nsChromeRegistry::GetSingleton() {
|
|
|
|
if (gChromeRegistry) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsChromeRegistry> registry = gChromeRegistry;
|
2013-04-22 11:15:59 +00:00
|
|
|
return registry.forget();
|
2009-11-02 18:04:45 +00:00
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsChromeRegistry> cr;
|
2010-07-01 15:55:57 +00:00
|
|
|
if (GeckoProcessType_Content == XRE_GetProcessType())
|
|
|
|
cr = new nsChromeRegistryContent();
|
|
|
|
else
|
|
|
|
cr = new nsChromeRegistryChrome();
|
2005-07-14 15:40:25 +00:00
|
|
|
|
2010-07-01 15:55:57 +00:00
|
|
|
if (NS_FAILED(cr->Init())) return nullptr;
|
2005-07-14 15:40:25 +00:00
|
|
|
|
2010-07-01 15:55:57 +00:00
|
|
|
return cr.forget();
|
2001-05-17 02:02:51 +00:00
|
|
|
}
|