2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2007-12-20 06:11:02 +03:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 15:12:37 +04: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 04:52:35 +04:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
#include "nsChromeRegistry.h"
|
2010-07-01 19:55:57 +04:00
|
|
|
#include "nsChromeRegistryChrome.h"
|
|
|
|
#include "nsChromeRegistryContent.h"
|
2005-02-23 00:49:45 +03:00
|
|
|
|
1999-04-02 04:52:35 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2005-02-23 00:49:45 +03:00
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsString.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2005-02-23 00:49:45 +03:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
#include "mozilla/dom/URL.h"
|
2005-04-05 19:20:20 +04:00
|
|
|
#include "nsIConsoleService.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2005-02-23 00:49:45 +03:00
|
|
|
#include "nsIObserverService.h"
|
2005-04-05 19:20:20 +04:00
|
|
|
#include "nsIScriptError.h"
|
2017-03-28 12:05:12 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-03-29 18:12:47 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2016-12-09 22:58:57 +03:00
|
|
|
#include "mozilla/Printf.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheet.h"
|
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2017-05-08 16:49:31 +03:00
|
|
|
#include "mozilla/dom/Location.h"
|
1999-12-01 11:44:43 +03:00
|
|
|
|
2005-02-26 00:11:46 +03:00
|
|
|
nsChromeRegistry* nsChromeRegistry::gChromeRegistry;
|
2014-06-20 14:32:49 +04: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 18:12:47 +03:00
|
|
|
using mozilla::PresShell;
|
2016-09-26 15:03:25 +03:00
|
|
|
using mozilla::StyleSheet;
|
2019-01-02 16:05:23 +03:00
|
|
|
using mozilla::dom::Document;
|
2017-05-08 16:49:31 +03:00
|
|
|
using mozilla::dom::Location;
|
2004-10-13 23:05:48 +04:00
|
|
|
|
1999-04-02 04:52:35 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-05-14 03:44:53 +04:00
|
|
|
void nsChromeRegistry::LogMessage(const char* aMsg, ...) {
|
2005-04-05 19:20:20 +04:00
|
|
|
nsCOMPtr<nsIConsoleService> console(
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (!console) return;
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
va_start(args, aMsg);
|
2017-03-03 18:17:27 +03:00
|
|
|
mozilla::SmprintfPointer formatted = mozilla::Vsmprintf(aMsg, args);
|
2005-04-05 19:20:20 +04:00
|
|
|
va_end(args);
|
|
|
|
if (!formatted) return;
|
|
|
|
|
2017-03-03 18:17:27 +03:00
|
|
|
console->LogStringMessage(NS_ConvertUTF8toUTF16(formatted.get()).get());
|
2005-04-05 19:20:20 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsChromeRegistry::LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber,
|
2010-05-14 03:44:53 +04:00
|
|
|
uint32_t flags, const char* aMsg,
|
|
|
|
...) {
|
2005-04-05 19:20:20 +04: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 18:17:27 +03:00
|
|
|
mozilla::SmprintfPointer formatted = mozilla::Vsmprintf(aMsg, args);
|
2005-04-05 19:20:20 +04:00
|
|
|
va_end(args);
|
|
|
|
if (!formatted) return;
|
|
|
|
|
|
|
|
nsCString spec;
|
|
|
|
if (aURL) aURL->GetSpec(spec);
|
|
|
|
|
2020-09-23 18:17:15 +03:00
|
|
|
rv = error->Init(NS_ConvertUTF8toUTF16(formatted.get()),
|
|
|
|
NS_ConvertUTF8toUTF16(spec), u""_ns, aLineNumber, 0, flags,
|
2022-07-25 23:19:48 +03:00
|
|
|
"chrome registration"_ns, false /* from private window */,
|
2020-09-23 18:17:15 +03:00
|
|
|
true /* from chrome context */);
|
2005-04-05 19:20:20 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return;
|
|
|
|
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
nsChromeRegistry::~nsChromeRegistry() { gChromeRegistry = nullptr; }
|
1999-04-02 04:52:35 +04:00
|
|
|
|
2006-01-25 23:23:24 +03: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 04:07:37 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChromeRegistry)
|
2006-01-25 23:23:24 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsChromeRegistry)
|
|
|
|
NS_IMPL_RELEASE(nsChromeRegistry)
|
1999-04-02 04:52:35 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIChromeRegistry methods:
|
1999-07-30 04:53:42 +04:00
|
|
|
|
2010-03-11 08:33:00 +03:00
|
|
|
already_AddRefed<nsIChromeRegistry> nsChromeRegistry::GetService() {
|
2010-07-23 22:16:00 +04:00
|
|
|
if (!gChromeRegistry) {
|
2010-03-11 08:33:00 +03: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 15:15:59 +04:00
|
|
|
nsCOMPtr<nsIChromeRegistry> registry = gChromeRegistry;
|
|
|
|
return registry.forget();
|
2004-09-22 00:19:48 +04:00
|
|
|
}
|
|
|
|
|
2001-01-10 23:22:17 +03:00
|
|
|
nsresult nsChromeRegistry::Init() {
|
2005-02-26 00:11:46 +03: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 18:59:28 +04:00
|
|
|
mInitialized = true;
|
2005-02-26 00:11:46 +03:00
|
|
|
|
2001-01-10 23:22:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-26 22:43:45 +03:00
|
|
|
nsresult nsChromeRegistry::GetProviderAndPath(nsIURI* aChromeURL,
|
2005-02-23 00:49:45 +03:00
|
|
|
nsACString& aProvider,
|
|
|
|
nsACString& aPath) {
|
2000-03-21 13:42:22 +03:00
|
|
|
nsresult rv;
|
2001-09-06 04:45:16 +04:00
|
|
|
|
2019-08-07 22:49:40 +03:00
|
|
|
NS_ASSERTION(aChromeURL->SchemeIs("chrome"), "Non-chrome URI?");
|
1999-04-02 04:52:35 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2017-07-29 14:50:21 +03:00
|
|
|
rv = aChromeURL->GetPathQueryRef(path);
|
2005-02-23 00:49:45 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-07-30 04:53:42 +04:00
|
|
|
|
2005-04-05 19:20:20 +04:00
|
|
|
if (path.Length() < 3) {
|
2020-05-01 19:34:22 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
LogMessage("Invalid chrome URI (need path): %s",
|
|
|
|
aChromeURL->GetSpecOrDefault().get());
|
|
|
|
#endif
|
2005-02-23 00:49:45 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2005-04-05 19:20:20 +04:00
|
|
|
}
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
path.SetLength(nsUnescapeCount(path.BeginWriting()));
|
|
|
|
NS_ASSERTION(path.First() == '/', "Path should always begin with a slash!");
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t slash = path.FindChar('/', 1);
|
2005-04-05 19:20:20 +04:00
|
|
|
if (slash == 1) {
|
2020-05-01 19:34:22 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
LogMessage("Invalid chrome URI (path cannot start with another slash): %s",
|
|
|
|
aChromeURL->GetSpecOrDefault().get());
|
|
|
|
#endif
|
2005-02-23 00:49:45 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2005-04-05 19:20:20 +04:00
|
|
|
}
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
if (slash == -1) {
|
|
|
|
aPath.Truncate();
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
if (slash == (int32_t)path.Length() - 1)
|
2005-02-23 00:49:45 +03:00
|
|
|
aPath.Truncate();
|
|
|
|
else
|
|
|
|
aPath.Assign(path.get() + slash + 1, path.Length() - slash - 1);
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
--slash;
|
2005-02-20 04:47:13 +03:00
|
|
|
}
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
aProvider.Assign(path.get() + 1, slash);
|
2005-02-20 04:47:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-26 22:43:45 +03:00
|
|
|
nsresult nsChromeRegistry::Canonify(nsCOMPtr<nsIURI>& aChromeURL) {
|
2005-02-23 03:01:54 +03:00
|
|
|
constexpr auto kSlash = "/"_ns;
|
|
|
|
|
2005-02-20 04:47:13 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString provider, path;
|
2005-02-23 00:49:45 +03:00
|
|
|
rv = GetProviderAndPath(aChromeURL, provider, path);
|
2005-02-20 04:47:13 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
if (path.IsEmpty()) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString package;
|
2005-02-23 00:49:45 +03:00
|
|
|
rv = aChromeURL->GetHost(package);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-02-23 00:49:45 +03: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 04:47:13 +03:00
|
|
|
}
|
2018-02-26 22:43:45 +03:00
|
|
|
return NS_MutateURI(aChromeURL).SetPathQueryRef(path).Finalize(aChromeURL);
|
2020-10-17 16:47:13 +03: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 04:59:12 +03:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2020-10-17 16:47:13 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
case '#':
|
|
|
|
pos = end;
|
|
|
|
continue;
|
2006-05-20 03:32:49 +04:00
|
|
|
}
|
2020-10-17 16:47:13 +03:00
|
|
|
++pos;
|
2002-08-22 00:58:05 +04:00
|
|
|
}
|
|
|
|
|
2005-02-20 04:47:13 +03:00
|
|
|
return NS_OK;
|
2004-09-25 20:14:52 +04:00
|
|
|
}
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURI, nsIURI** aResult) {
|
2005-02-20 04:47:13 +03:00
|
|
|
nsresult rv;
|
2015-09-04 12:39:08 +03:00
|
|
|
if (NS_WARN_IF(!aChromeURI)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2004-09-22 00:19:48 +04:00
|
|
|
|
2005-06-01 23:09:44 +04:00
|
|
|
if (mOverrideTable.Get(aChromeURI, aResult)) return NS_OK;
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
nsCOMPtr<nsIURL> chromeURL(do_QueryInterface(aChromeURI));
|
|
|
|
NS_ENSURE_TRUE(chromeURL, NS_NOINTERFACE);
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString package, provider, path;
|
2005-02-23 00:49:45 +03:00
|
|
|
rv = chromeURL->GetHostPort(package);
|
2005-02-20 04:47:13 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
rv = GetProviderAndPath(chromeURL, provider, path);
|
2005-02-20 04:47:13 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-13 23:46:05 +04:00
|
|
|
nsIURI* baseURI = GetBaseURIFromPackage(package, provider, path);
|
2005-06-07 23:28:23 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags;
|
2010-03-11 08:33:00 +03:00
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-04-05 19:20:20 +04:00
|
|
|
if (!baseURI) {
|
2007-11-13 11:50:30 +03:00
|
|
|
LogMessage("No chrome package registered for chrome://%s/%s/%s",
|
2005-04-05 19:20:20 +04:00
|
|
|
package.get(), provider.get(), path.get());
|
2014-06-21 03:50:58 +04:00
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
2005-04-05 19:20:20 +04:00
|
|
|
}
|
2004-09-25 20:14:52 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return NS_NewURI(aResult, path, nullptr, baseURI);
|
2000-05-14 01:42:56 +04:00
|
|
|
}
|
|
|
|
|
1999-08-05 08:33:41 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2005-02-23 00:49:45 +03: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 20:59:13 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
|
2005-02-23 00:49:45 +03:00
|
|
|
NS_ASSERTION(obsSvc, "Couldn't get observer service.");
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
obsSvc->NotifyObservers((nsIChromeRegistry*)this, NS_CHROME_FLUSH_TOPIC,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr);
|
2005-02-23 00:49:45 +03:00
|
|
|
}
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsChromeRegistry::AllowScriptsForPackage(nsIURI* aChromeURI, bool* aResult) {
|
2004-09-22 00:19:48 +04:00
|
|
|
nsresult rv;
|
2011-10-17 18:59:28 +04:00
|
|
|
*aResult = false;
|
2001-03-08 04:50:36 +03:00
|
|
|
|
2019-08-07 22:49:40 +03:00
|
|
|
NS_ASSERTION(aChromeURI->SchemeIs("chrome"),
|
|
|
|
"Non-chrome URI passed to AllowScriptsForPackage!");
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(aChromeURI));
|
|
|
|
NS_ENSURE_TRUE(url, NS_NOINTERFACE);
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString provider, file;
|
2005-02-23 00:49:45 +03:00
|
|
|
rv = GetProviderAndPath(url, provider, file);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
if (!provider.EqualsLiteral("skin")) *aResult = true;
|
2001-03-08 04:50:36 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-11 17:39:43 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsChromeRegistry::AllowContentToAccess(nsIURI* aURI, bool* aResult) {
|
2008-04-11 17:39:43 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aResult = false;
|
2008-04-11 17:39:43 +04:00
|
|
|
|
2019-08-07 22:49:40 +03:00
|
|
|
NS_ASSERTION(aURI->SchemeIs("chrome"),
|
|
|
|
"Non-chrome URI passed to AllowContentToAccess!");
|
2008-04-11 17:39:43 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
|
|
|
|
if (!url) {
|
|
|
|
NS_ERROR("Chrome URL doesn't implement nsIURL.");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString package;
|
2008-04-11 17:39:43 +04:00
|
|
|
rv = url->GetHostPort(package);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags;
|
2010-03-11 08:33:00 +03:00
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
2008-04-11 17:39:43 +04:00
|
|
|
|
2010-03-11 08:33:00 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aResult = !!(flags & CONTENT_ACCESSIBLE);
|
2008-04-11 17:39:43 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-05 19:09:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistry::CanLoadURLRemotely(nsIURI* aURI, bool* aResult) {
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
*aResult = false;
|
|
|
|
|
2019-08-07 22:49:40 +03:00
|
|
|
NS_ASSERTION(aURI->SchemeIs("chrome"),
|
|
|
|
"Non-chrome URI passed to CanLoadURLRemotely!");
|
2015-02-05 19:09:15 +03: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 22:49:40 +03:00
|
|
|
NS_ASSERTION(aURI->SchemeIs("chrome"),
|
|
|
|
"Non-chrome URI passed to MustLoadURLRemotely!");
|
2015-02-05 19:09:15 +03: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 19:55:57 +04:00
|
|
|
already_AddRefed<nsChromeRegistry> nsChromeRegistry::GetSingleton() {
|
|
|
|
if (gChromeRegistry) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsChromeRegistry> registry = gChromeRegistry;
|
2013-04-22 15:15:59 +04:00
|
|
|
return registry.forget();
|
2009-11-02 21:04:45 +03:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsChromeRegistry> cr;
|
2010-07-01 19:55:57 +04:00
|
|
|
if (GeckoProcessType_Content == XRE_GetProcessType())
|
|
|
|
cr = new nsChromeRegistryContent();
|
|
|
|
else
|
|
|
|
cr = new nsChromeRegistryChrome();
|
2005-07-14 19:40:25 +04:00
|
|
|
|
2010-07-01 19:55:57 +04:00
|
|
|
if (NS_FAILED(cr->Init())) return nullptr;
|
2005-07-14 19:40:25 +04:00
|
|
|
|
2010-07-01 19:55:57 +04:00
|
|
|
return cr.forget();
|
2001-05-17 06:02:51 +04:00
|
|
|
}
|