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
|
|
|
|
2005-04-05 19:20:20 +04:00
|
|
|
#include "prprf.h"
|
2005-02-23 00:49:45 +03:00
|
|
|
|
1999-04-02 04:52:35 +04:00
|
|
|
#include "nsCOMPtr.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"
|
2005-02-23 00:49:45 +03:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMLocation.h"
|
2005-02-20 04:47:13 +03:00
|
|
|
#include "nsIDOMWindowCollection.h"
|
2011-07-15 14:31:34 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2005-02-23 00:49:45 +03:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIPresShell.h"
|
2005-04-05 19:20:20 +04:00
|
|
|
#include "nsIScriptError.h"
|
2005-02-23 00:49:45 +03:00
|
|
|
#include "nsIWindowMediator.h"
|
2015-08-28 10:13:06 +03:00
|
|
|
#include "nsIPrefService.h"
|
2016-02-24 10:01:12 +03:00
|
|
|
#include "mozilla/StyleSheetHandle.h"
|
|
|
|
#include "mozilla/StyleSheetHandleInlines.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.
|
2016-02-24 10:01:12 +03:00
|
|
|
using mozilla::StyleSheetHandle;
|
2013-11-20 20:29:03 +04:00
|
|
|
using mozilla::dom::IsChromeURI;
|
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);
|
|
|
|
char* formatted = PR_vsmprintf(aMsg, args);
|
|
|
|
va_end(args);
|
|
|
|
if (!formatted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
console->LogStringMessage(NS_ConvertUTF8toUTF16(formatted).get());
|
|
|
|
PR_smprintf_free(formatted);
|
|
|
|
}
|
|
|
|
|
2010-05-14 03:44:53 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsChromeRegistry::LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber, uint32_t flags,
|
2010-05-14 03:44:53 +04:00
|
|
|
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);
|
|
|
|
char* formatted = PR_vsmprintf(aMsg, args);
|
|
|
|
va_end(args);
|
|
|
|
if (!formatted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCString spec;
|
|
|
|
if (aURL)
|
|
|
|
aURL->GetSpec(spec);
|
|
|
|
|
2012-09-10 03:29:12 +04:00
|
|
|
rv = error->Init(NS_ConvertUTF8toUTF16(formatted),
|
|
|
|
NS_ConvertUTF8toUTF16(spec),
|
|
|
|
EmptyString(),
|
2005-05-20 16:58:57 +04:00
|
|
|
aLineNumber, 0, flags, "chrome registration");
|
2005-04-05 19:20:20 +04:00
|
|
|
PR_smprintf_free(formatted);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
nsChromeRegistry::~nsChromeRegistry()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
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)
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIXULOverlayProvider)
|
|
|
|
#endif
|
|
|
|
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()
|
2004-09-22 00:19:48 +04:00
|
|
|
{
|
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)
|
2013-04-03 04:15:07 +04:00
|
|
|
return nullptr;
|
2010-03-11 08:33:00 +03:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
nsresult
|
|
|
|
nsChromeRegistry::GetProviderAndPath(nsIURL* aChromeURL,
|
|
|
|
nsACString& aProvider, nsACString& aPath)
|
2000-01-06 03:31:06 +03:00
|
|
|
{
|
2000-03-21 13:42:22 +03:00
|
|
|
nsresult rv;
|
2001-09-06 04:45:16 +04:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome;
|
2005-02-23 00:49:45 +03:00
|
|
|
aChromeURL->SchemeIs("chrome", &isChrome);
|
|
|
|
NS_ASSERTION(isChrome, "Non-chrome URI?");
|
|
|
|
#endif
|
1999-04-02 04:52:35 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2005-02-23 00:49:45 +03:00
|
|
|
rv = aChromeURL->GetPath(path);
|
|
|
|
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) {
|
|
|
|
LogMessage("Invalid chrome URI: %s", path.get());
|
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) {
|
|
|
|
LogMessage("Invalid chrome URI: %s", path.get());
|
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();
|
2005-02-20 04:47:13 +03:00
|
|
|
}
|
2005-02-23 00:49:45 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2005-02-23 00:49:45 +03:00
|
|
|
nsChromeRegistry::Canonify(nsIURL* aChromeURL)
|
2005-02-20 04:47:13 +03:00
|
|
|
{
|
2005-02-23 03:01:54 +03:00
|
|
|
NS_NAMED_LITERAL_CSTRING(kSlash, "/");
|
|
|
|
|
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");
|
2005-02-20 04:47:13 +03:00
|
|
|
}
|
2005-02-23 00:49:45 +03:00
|
|
|
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
|
|
|
}
|
2005-02-23 00:49:45 +03:00
|
|
|
aChromeURL->SetPath(path);
|
2004-09-22 00:19:48 +04:00
|
|
|
}
|
2006-05-20 03:32:49 +04:00
|
|
|
else {
|
2008-02-01 04:59:12 +03:00
|
|
|
// prevent directory traversals ("..")
|
|
|
|
// path is already unescaped once, but uris can get unescaped twice
|
2008-02-02 22:50:09 +03:00
|
|
|
const char* pos = path.BeginReading();
|
2008-02-01 04:59:12 +03:00
|
|
|
const char* end = path.EndReading();
|
2008-02-02 22:50:09 +03:00
|
|
|
while (pos < end) {
|
|
|
|
switch (*pos) {
|
2008-02-01 04:59:12 +03:00
|
|
|
case ':':
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
case '.':
|
2008-02-02 22:50:09 +03:00
|
|
|
if (pos[1] == '.')
|
2008-02-01 04:59:12 +03:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2008-02-02 22:50:09 +03:00
|
|
|
break;
|
2008-02-01 04:59:12 +03:00
|
|
|
case '%':
|
|
|
|
// chrome: URIs with double-escapes are trying to trick us.
|
|
|
|
// watch for %2e, and %25 in case someone triple unescapes
|
2008-02-02 22:50:09 +03:00
|
|
|
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;
|
2008-02-02 22:50:09 +03:00
|
|
|
break;
|
|
|
|
case '?':
|
2008-03-07 04:20:44 +03:00
|
|
|
case '#':
|
2008-02-02 22:50:09 +03:00
|
|
|
pos = end;
|
|
|
|
continue;
|
2008-02-01 04:59:12 +03:00
|
|
|
}
|
2008-02-02 22:50:09 +03:00
|
|
|
++pos;
|
2006-05-20 03:32:49 +04:00
|
|
|
}
|
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)
|
2000-05-14 01:42:56 +04:00
|
|
|
{
|
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
|
|
|
|
2010-03-11 08:33:00 +03:00
|
|
|
if (flags & PLATFORM_PACKAGE) {
|
2014-02-11 02:57:01 +04:00
|
|
|
#if defined(XP_WIN)
|
2005-02-23 00:49:45 +03:00
|
|
|
path.Insert("win/", 0);
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
path.Insert("mac/", 0);
|
|
|
|
#else
|
|
|
|
path.Insert("unix/", 0);
|
|
|
|
#endif
|
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
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-10-27 13:24:23 +04:00
|
|
|
// theme stuff
|
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
static void FlushSkinBindingsForWindow(nsPIDOMWindowOuter* aWindow)
|
1999-11-24 04:12:35 +03:00
|
|
|
{
|
2015-10-27 00:37:32 +03:00
|
|
|
// Get the document.
|
|
|
|
nsCOMPtr<nsIDocument> document = aWindow->GetDoc();
|
2001-12-18 01:51:39 +03:00
|
|
|
if (!document)
|
|
|
|
return;
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-22 00:51:34 +04:00
|
|
|
|
2001-12-18 01:51:39 +03:00
|
|
|
// Annihilate all XBL bindings.
|
2007-02-17 01:59:06 +03:00
|
|
|
document->FlushSkinBindings();
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
1999-11-24 04:12:35 +03:00
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
// XXXbsmedberg: move this to nsIWindowMediator
|
2001-12-18 01:51:39 +03:00
|
|
|
NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
|
|
|
|
{
|
2005-02-23 00:49:45 +03:00
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator
|
|
|
|
(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
2001-12-18 01:51:39 +03:00
|
|
|
if (!windowMediator)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
2012-07-30 18:20:58 +04:00
|
|
|
windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
|
2011-09-29 10:19:26 +04:00
|
|
|
bool more;
|
2001-12-18 01:51:39 +03:00
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
while (more) {
|
|
|
|
nsCOMPtr<nsISupports> protoWindow;
|
|
|
|
windowEnumerator->GetNext(getter_AddRefs(protoWindow));
|
|
|
|
if (protoWindow) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> domWindow = do_QueryInterface(protoWindow);
|
2001-12-18 01:51:39 +03:00
|
|
|
if (domWindow)
|
|
|
|
FlushSkinBindingsForWindow(domWindow);
|
1999-11-24 04:12:35 +03:00
|
|
|
}
|
2001-12-18 01:51:39 +03:00
|
|
|
windowEnumerator->HasMoreElements(&more);
|
1999-11-24 04:12:35 +03:00
|
|
|
}
|
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
FlushSkinCaches();
|
2010-03-03 00:00:39 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
|
2001-12-18 01:51:39 +03:00
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
while (more) {
|
|
|
|
nsCOMPtr<nsISupports> protoWindow;
|
|
|
|
windowEnumerator->GetNext(getter_AddRefs(protoWindow));
|
|
|
|
if (protoWindow) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> domWindow = do_QueryInterface(protoWindow);
|
2001-12-18 01:51:39 +03:00
|
|
|
if (domWindow)
|
2010-03-03 00:00:39 +03:00
|
|
|
RefreshWindow(domWindow);
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-05-11 03:18:49 +04:00
|
|
|
}
|
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
void
|
|
|
|
nsChromeRegistry::FlushSkinCaches()
|
2001-05-11 03:18:49 +04:00
|
|
|
{
|
2004-03-09 22:59:09 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
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
|
|
|
mozilla::services::GetObserverService();
|
2004-03-09 22:59:09 +03:00
|
|
|
NS_ASSERTION(obsSvc, "Couldn't get observer service.");
|
2000-05-28 00:03:14 +04:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
obsSvc->NotifyObservers(static_cast<nsIChromeRegistry*>(this),
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_CHROME_FLUSH_SKINS_TOPIC, nullptr);
|
1999-11-24 04:12:35 +03:00
|
|
|
}
|
|
|
|
|
2004-03-09 22:59:09 +03:00
|
|
|
// XXXbsmedberg: move this to windowmediator
|
2016-01-30 20:05:36 +03:00
|
|
|
nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
|
1999-10-27 13:24:23 +04:00
|
|
|
{
|
2001-12-18 01:51:39 +03:00
|
|
|
// Deal with our subframes first.
|
2015-10-27 00:37:32 +03:00
|
|
|
nsCOMPtr<nsIDOMWindowCollection> frames = aWindow->GetFrames();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length;
|
2001-12-18 01:51:39 +03:00
|
|
|
frames->GetLength(&length);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t j;
|
2002-12-03 09:39:59 +03:00
|
|
|
for (j = 0; j < length; j++) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> childWin;
|
2002-12-03 09:39:59 +03:00
|
|
|
frames->Item(j, getter_AddRefs(childWin));
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> piWindow = nsPIDOMWindowOuter::From(childWin);
|
2015-10-27 00:37:32 +03:00
|
|
|
RefreshWindow(piWindow);
|
2001-12-18 01:51:39 +03:00
|
|
|
}
|
|
|
|
|
2000-08-21 11:50:39 +04:00
|
|
|
nsresult rv;
|
2015-10-27 00:37:32 +03:00
|
|
|
// Get the document.
|
|
|
|
nsCOMPtr<nsIDocument> document = aWindow->GetDoc();
|
2000-08-21 11:50:39 +04:00
|
|
|
if (!document)
|
|
|
|
return NS_OK;
|
1999-11-24 04:12:35 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// Deal with the agent sheets first. Have to do all the style sets by hand.
|
2010-06-25 17:59:57 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell = document->GetShell();
|
2010-01-07 13:36:11 +03:00
|
|
|
if (shell) {
|
2004-01-08 01:30:53 +03:00
|
|
|
// Reload only the chrome URL agent style sheets.
|
2016-02-24 10:01:12 +03:00
|
|
|
nsTArray<StyleSheetHandle::RefPtr> agentSheets;
|
2004-01-08 01:30:53 +03:00
|
|
|
rv = shell->GetAgentStyleSheets(agentSheets);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2016-02-24 10:01:12 +03:00
|
|
|
nsTArray<StyleSheetHandle::RefPtr> newAgentSheets;
|
|
|
|
for (StyleSheetHandle sheet : agentSheets) {
|
2010-05-18 08:00:40 +04:00
|
|
|
nsIURI* uri = sheet->GetSheetURI();
|
2002-12-11 03:09:28 +03:00
|
|
|
|
2004-12-02 05:13:20 +03:00
|
|
|
if (IsChromeURI(uri)) {
|
|
|
|
// Reload the sheet.
|
2016-02-24 10:01:12 +03:00
|
|
|
StyleSheetHandle::RefPtr newSheet;
|
|
|
|
rv = document->LoadChromeSheetSync(uri, true, &newSheet);
|
2002-12-11 03:09:28 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2004-01-08 01:30:53 +03:00
|
|
|
if (newSheet) {
|
2015-11-17 09:04:09 +03:00
|
|
|
rv = newAgentSheets.AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE;
|
2003-09-27 22:49:39 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2000-05-28 00:03:14 +04:00
|
|
|
}
|
2004-01-08 01:30:53 +03:00
|
|
|
else { // Just use the same sheet.
|
2015-11-17 09:04:09 +03:00
|
|
|
rv = newAgentSheets.AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE;
|
2004-01-08 01:30:53 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2000-05-28 00:03:14 +04:00
|
|
|
}
|
2004-01-08 01:30:53 +03:00
|
|
|
|
|
|
|
rv = shell->SetAgentStyleSheets(newAgentSheets);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
2000-05-28 00:03:14 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = document->GetNumberOfStyleSheets();
|
2000-05-28 00:03:14 +04:00
|
|
|
|
2015-11-17 09:04:09 +03:00
|
|
|
// Build an array of style sheets we need to reload.
|
2016-02-24 10:01:12 +03:00
|
|
|
nsTArray<StyleSheetHandle::RefPtr> oldSheets(count);
|
|
|
|
nsTArray<StyleSheetHandle::RefPtr> newSheets(count);
|
2015-11-17 09:04:09 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// Iterate over the style sheets.
|
2015-11-17 09:04:09 +03:00
|
|
|
for (int32_t i = 0; i < count; i++) {
|
2002-12-03 08:48:14 +03:00
|
|
|
// Get the style sheet
|
2016-02-24 10:01:12 +03:00
|
|
|
StyleSheetHandle styleSheet = document->GetStyleSheetAt(i);
|
2015-11-17 09:04:09 +03:00
|
|
|
oldSheets.AppendElement(styleSheet);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-22 00:51:34 +04:00
|
|
|
|
2010-03-03 00:00:39 +03:00
|
|
|
// Iterate over our old sheets and kick off a sync load of the new
|
2016-03-26 09:02:30 +03:00
|
|
|
// sheet if and only if it's a non-inline sheet with a chrome URL.
|
2016-02-24 10:01:12 +03:00
|
|
|
for (StyleSheetHandle sheet : oldSheets) {
|
2016-03-26 09:02:30 +03:00
|
|
|
MOZ_ASSERT(sheet, "GetStyleSheetAt shouldn't return nullptr for "
|
|
|
|
"in-range sheet indexes");
|
|
|
|
nsIURI* uri = sheet->GetSheetURI();
|
2001-12-18 01:51:39 +03:00
|
|
|
|
2016-03-26 09:02:30 +03:00
|
|
|
if (!sheet->IsInline() && IsChromeURI(uri)) {
|
2002-12-03 08:48:14 +03:00
|
|
|
// Reload the sheet.
|
2016-02-24 10:01:12 +03:00
|
|
|
StyleSheetHandle::RefPtr newSheet;
|
2002-12-03 08:48:14 +03:00
|
|
|
// XXX what about chrome sheets that have a title or are disabled? This
|
|
|
|
// only works by sheer dumb luck.
|
2016-02-24 10:01:12 +03:00
|
|
|
document->LoadChromeSheetSync(uri, false, &newSheet);
|
2002-12-03 08:48:14 +03:00
|
|
|
// Even if it's null, we put in in there.
|
2015-11-17 09:04:09 +03:00
|
|
|
newSheets.AppendElement(newSheet);
|
|
|
|
} else {
|
2002-12-03 08:48:14 +03:00
|
|
|
// Just use the same sheet.
|
2015-11-17 09:04:09 +03:00
|
|
|
newSheets.AppendElement(sheet);
|
2000-08-21 11:50:39 +04:00
|
|
|
}
|
|
|
|
}
|
1999-11-24 10:37:38 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
// Now notify the document that multiple sheets have been added and removed.
|
|
|
|
document->UpdateStyleSheets(oldSheets, newSheets);
|
1999-10-27 13:24:23 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
void
|
|
|
|
nsChromeRegistry::FlushAllCaches()
|
1999-10-27 13:24:23 +04:00
|
|
|
{
|
2005-02-23 00:49:45 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
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
|
|
|
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,
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_CHROME_FLUSH_TOPIC, 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
|
|
|
// xxxbsmedberg Move me to nsIWindowMediator
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistry::ReloadChrome()
|
|
|
|
{
|
2010-11-30 17:02:23 +03:00
|
|
|
UpdateSelectedLocale();
|
2005-02-23 00:49:45 +03:00
|
|
|
FlushAllCaches();
|
|
|
|
// Do a reload of all top level windows.
|
|
|
|
nsresult rv = NS_OK;
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
// Get the window mediator
|
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator
|
|
|
|
(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
|
|
|
if (windowMediator) {
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
2005-02-20 04:47:13 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
|
2005-02-23 00:49:45 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Get each dom window
|
2011-09-29 10:19:26 +04:00
|
|
|
bool more;
|
2005-02-23 00:49:45 +03:00
|
|
|
rv = windowEnumerator->HasMoreElements(&more);
|
2004-09-22 00:19:48 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2005-02-23 00:49:45 +03:00
|
|
|
while (more) {
|
|
|
|
nsCOMPtr<nsISupports> protoWindow;
|
|
|
|
rv = windowEnumerator->GetNext(getter_AddRefs(protoWindow));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> domWindow = do_QueryInterface(protoWindow);
|
2005-02-23 00:49:45 +03:00
|
|
|
if (domWindow) {
|
2015-10-27 00:37:32 +03:00
|
|
|
nsIDOMLocation* location = domWindow->GetLocation();
|
2005-02-23 00:49:45 +03:00
|
|
|
if (location) {
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = location->Reload(false);
|
2005-02-23 00:49:45 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rv = windowEnumerator->HasMoreElements(&more);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2004-09-22 00:19:48 +04:00
|
|
|
}
|
|
|
|
}
|
2000-08-21 11:50:39 +04:00
|
|
|
return rv;
|
1999-11-24 04:12:35 +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)
|
2001-03-08 04:50:36 +03:00
|
|
|
{
|
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
|
|
|
|
2005-02-23 00:49:45 +03:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome;
|
2005-02-23 00:49:45 +03:00
|
|
|
aChromeURI->SchemeIs("chrome", &isChrome);
|
|
|
|
NS_ASSERTION(isChrome, "Non-chrome URI passed to AllowScriptsForPackage!");
|
|
|
|
#endif
|
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"))
|
2011-10-17 18:59:28 +04:00
|
|
|
*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
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome;
|
2008-04-11 17:39:43 +04:00
|
|
|
aURI->SchemeIs("chrome", &isChrome);
|
|
|
|
NS_ASSERTION(isChrome, "Non-chrome URI passed to AllowContentToAccess!");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool isChrome;
|
|
|
|
aURI->SchemeIs("chrome", &isChrome);
|
|
|
|
NS_ASSERTION(isChrome, "Non-chrome URI passed to CanLoadURLRemotely!");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool isChrome;
|
|
|
|
aURI->SchemeIs("chrome", &isChrome);
|
|
|
|
NS_ASSERTION(isChrome, "Non-chrome URI passed to MustLoadURLRemotely!");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-08-28 10:13:06 +03:00
|
|
|
bool
|
|
|
|
nsChromeRegistry::GetDirectionForLocale(const nsACString& aLocale)
|
|
|
|
{
|
|
|
|
// first check the intl.uidirection.<locale> preference, and if that is not
|
|
|
|
// set, check the same preference but with just the first two characters of
|
|
|
|
// the locale. If that isn't set, default to left-to-right.
|
|
|
|
nsAutoCString prefString = NS_LITERAL_CSTRING("intl.uidirection.") + aLocale;
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch (do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
|
|
if (!prefBranch) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXPIDLCString dir;
|
|
|
|
prefBranch->GetCharPref(prefString.get(), getter_Copies(dir));
|
|
|
|
if (dir.IsEmpty()) {
|
|
|
|
int32_t hyphen = prefString.FindChar('-');
|
|
|
|
if (hyphen >= 1) {
|
|
|
|
nsAutoCString shortPref(Substring(prefString, 0, hyphen));
|
|
|
|
prefBranch->GetCharPref(shortPref.get(), getter_Copies(dir));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dir.EqualsLiteral("rtl");
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2008-11-14 03:00:11 +03:00
|
|
|
nsChromeRegistry::WrappersEnabled(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURL> chromeURL (do_QueryInterface(aURI));
|
|
|
|
if (!chromeURL)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-11-14 03:00:11 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isChrome = false;
|
2008-11-14 03:00:11 +03:00
|
|
|
nsresult rv = chromeURL->SchemeIs("chrome", &isChrome);
|
|
|
|
if (NS_FAILED(rv) || !isChrome)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-11-14 03:00:11 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString package;
|
2008-11-14 03:00:11 +03:00
|
|
|
rv = chromeURL->GetHostPort(package);
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-11-14 03:00:11 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags;
|
2010-06-08 02:49:12 +04:00
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
|
|
|
return NS_SUCCEEDED(rv) && (flags & XPCNATIVEWRAPPERS);
|
2008-11-14 03:00:11 +03:00
|
|
|
}
|
|
|
|
|
2010-07-01 19:55:57 +04:00
|
|
|
already_AddRefed<nsChromeRegistry>
|
|
|
|
nsChromeRegistry::GetSingleton()
|
2009-11-02 21:04:45 +03:00
|
|
|
{
|
2010-07-01 19:55:57 +04:00
|
|
|
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()))
|
2013-04-03 04:15:07 +04:00
|
|
|
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
|
|
|
}
|