2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2007-12-19 19:11:02 -08:00
|
|
|
/* vim: set ts=2 sw=2 et tw=78: */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsChromeRegistry.h"
|
2010-07-01 08:55:57 -07:00
|
|
|
#include "nsChromeRegistryChrome.h"
|
|
|
|
#include "nsChromeRegistryContent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "prprf.h"
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsEscape.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2014-06-20 03:32:49 -07:00
|
|
|
#include "mozilla/CSSStyleSheet.h"
|
|
|
|
#include "mozilla/dom/URL.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMLocation.h"
|
|
|
|
#include "nsIDOMWindowCollection.h"
|
2011-07-15 03:31:34 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIWindowMediator.h"
|
|
|
|
|
|
|
|
nsChromeRegistry* nsChromeRegistry::gChromeRegistry;
|
2014-06-20 03:32:49 -07:00
|
|
|
|
|
|
|
// DO NOT use namespace mozilla; it'll break due to a naming conflict between
|
|
|
|
// mozilla::TextRange and a TextRange in OSX headers.
|
|
|
|
using mozilla::CSSStyleSheet;
|
2013-11-20 08:29:03 -08:00
|
|
|
using mozilla::dom::IsChromeURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-05-13 16:44:53 -07:00
|
|
|
void
|
|
|
|
nsChromeRegistry::LogMessage(const char* aMsg, ...)
|
2007-03-22 10:30:00 -07: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-13 16:44:53 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsChromeRegistry::LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber, uint32_t flags,
|
2010-05-13 16:44:53 -07:00
|
|
|
const char* aMsg, ...)
|
2007-03-22 10:30:00 -07: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-09 16:29:12 -07:00
|
|
|
rv = error->Init(NS_ConvertUTF8toUTF16(formatted),
|
|
|
|
NS_ConvertUTF8toUTF16(spec),
|
|
|
|
EmptyString(),
|
2007-03-22 10:30:00 -07:00
|
|
|
aLineNumber, 0, flags, "chrome registration");
|
|
|
|
PR_smprintf_free(formatted);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsChromeRegistry::~nsChromeRegistry()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
gChromeRegistry = nullptr;
|
2007-03-22 10:30:00 -07: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)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChromeRegistry)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsChromeRegistry)
|
|
|
|
NS_IMPL_RELEASE(nsChromeRegistry)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIChromeRegistry methods:
|
|
|
|
|
2010-03-10 21:33:00 -08:00
|
|
|
already_AddRefed<nsIChromeRegistry>
|
|
|
|
nsChromeRegistry::GetService()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-23 11:16:00 -07:00
|
|
|
if (!gChromeRegistry)
|
2010-03-10 21:33:00 -08: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-02 17:15:07 -07:00
|
|
|
return nullptr;
|
2010-03-10 21:33:00 -08:00
|
|
|
}
|
2013-04-22 04:15:59 -07:00
|
|
|
nsCOMPtr<nsIChromeRegistry> registry = gChromeRegistry;
|
|
|
|
return registry.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsChromeRegistry::Init()
|
|
|
|
{
|
|
|
|
// 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 07:59:28 -07:00
|
|
|
mInitialized = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsChromeRegistry::GetProviderAndPath(nsIURL* aChromeURL,
|
|
|
|
nsACString& aProvider, nsACString& aPath)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isChrome;
|
2007-03-22 10:30:00 -07:00
|
|
|
aChromeURL->SchemeIs("chrome", &isChrome);
|
|
|
|
NS_ASSERTION(isChrome, "Non-chrome URI?");
|
|
|
|
#endif
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString path;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = aChromeURL->GetPath(path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (path.Length() < 3) {
|
|
|
|
LogMessage("Invalid chrome URI: %s", path.get());
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
path.SetLength(nsUnescapeCount(path.BeginWriting()));
|
|
|
|
NS_ASSERTION(path.First() == '/', "Path should always begin with a slash!");
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t slash = path.FindChar('/', 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (slash == 1) {
|
|
|
|
LogMessage("Invalid chrome URI: %s", path.get());
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (slash == -1) {
|
|
|
|
aPath.Truncate();
|
|
|
|
}
|
|
|
|
else {
|
2012-08-22 08:56:38 -07:00
|
|
|
if (slash == (int32_t) path.Length() - 1)
|
2007-03-22 10:30:00 -07:00
|
|
|
aPath.Truncate();
|
|
|
|
else
|
|
|
|
aPath.Assign(path.get() + slash + 1, path.Length() - slash - 1);
|
|
|
|
|
|
|
|
--slash;
|
|
|
|
}
|
|
|
|
|
|
|
|
aProvider.Assign(path.get() + 1, slash);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsChromeRegistry::Canonify(nsIURL* aChromeURL)
|
|
|
|
{
|
|
|
|
NS_NAMED_LITERAL_CSTRING(kSlash, "/");
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString provider, path;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = GetProviderAndPath(aChromeURL, provider, path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (path.IsEmpty()) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString package;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = aChromeURL->GetHost(package);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
aChromeURL->SetPath(path);
|
|
|
|
}
|
|
|
|
else {
|
2008-01-31 17:59:12 -08:00
|
|
|
// prevent directory traversals ("..")
|
|
|
|
// path is already unescaped once, but uris can get unescaped twice
|
2008-02-02 11:50:09 -08:00
|
|
|
const char* pos = path.BeginReading();
|
2008-01-31 17:59:12 -08:00
|
|
|
const char* end = path.EndReading();
|
2008-02-02 11:50:09 -08:00
|
|
|
while (pos < end) {
|
|
|
|
switch (*pos) {
|
2008-01-31 17:59:12 -08:00
|
|
|
case ':':
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
|
|
case '.':
|
2008-02-02 11:50:09 -08:00
|
|
|
if (pos[1] == '.')
|
2008-01-31 17:59:12 -08:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2008-02-02 11:50:09 -08:00
|
|
|
break;
|
2008-01-31 17:59:12 -08: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 11:50:09 -08:00
|
|
|
if (pos[1] == '2' &&
|
|
|
|
( pos[2] == 'e' || pos[2] == 'E' ||
|
|
|
|
pos[2] == '5' ))
|
2008-01-31 17:59:12 -08:00
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
2008-02-02 11:50:09 -08:00
|
|
|
break;
|
|
|
|
case '?':
|
2008-03-06 17:20:44 -08:00
|
|
|
case '#':
|
2008-02-02 11:50:09 -08:00
|
|
|
pos = end;
|
|
|
|
continue;
|
2008-01-31 17:59:12 -08:00
|
|
|
}
|
2008-02-02 11:50:09 -08:00
|
|
|
++pos;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
NS_ASSERTION(aChromeURI, "null url!");
|
|
|
|
|
|
|
|
if (mOverrideTable.Get(aChromeURI, aResult))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> chromeURL (do_QueryInterface(aChromeURI));
|
|
|
|
NS_ENSURE_TRUE(chromeURL, NS_NOINTERFACE);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString package, provider, path;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = chromeURL->GetHostPort(package);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = GetProviderAndPath(chromeURL, provider, path);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-13 12:46:05 -07:00
|
|
|
nsIURI* baseURI = GetBaseURIFromPackage(package, provider, path);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags;
|
2010-03-10 21:33:00 -08:00
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-10 21:33:00 -08:00
|
|
|
if (flags & PLATFORM_PACKAGE) {
|
2014-02-10 14:57:01 -08:00
|
|
|
#if defined(XP_WIN)
|
2007-03-22 10:30:00 -07:00
|
|
|
path.Insert("win/", 0);
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
path.Insert("mac/", 0);
|
|
|
|
#else
|
|
|
|
path.Insert("unix/", 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!baseURI) {
|
2007-11-13 00:50:30 -08:00
|
|
|
LogMessage("No chrome package registered for chrome://%s/%s/%s",
|
2007-03-22 10:30:00 -07:00
|
|
|
package.get(), provider.get(), path.get());
|
2014-06-20 16:50:58 -07:00
|
|
|
return NS_ERROR_FILE_NOT_FOUND;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return NS_NewURI(aResult, path, nullptr, baseURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// theme stuff
|
|
|
|
|
|
|
|
|
2011-07-15 03:31:34 -07:00
|
|
|
static void FlushSkinBindingsForWindow(nsIDOMWindow* aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Get the DOM document.
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDocument;
|
|
|
|
aWindow->GetDocument(getter_AddRefs(domDocument));
|
|
|
|
if (!domDocument)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
|
|
|
|
if (!document)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Annihilate all XBL bindings.
|
|
|
|
document->FlushSkinBindings();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXXbsmedberg: move this to nsIWindowMediator
|
|
|
|
NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator
|
|
|
|
(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
|
|
|
if (!windowMediator)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
2012-07-30 07:20:58 -07:00
|
|
|
windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
|
2011-09-28 23:19:26 -07:00
|
|
|
bool more;
|
2007-03-22 10:30:00 -07:00
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
while (more) {
|
|
|
|
nsCOMPtr<nsISupports> protoWindow;
|
|
|
|
windowEnumerator->GetNext(getter_AddRefs(protoWindow));
|
|
|
|
if (protoWindow) {
|
2011-07-15 03:31:34 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (domWindow)
|
|
|
|
FlushSkinBindingsForWindow(domWindow);
|
|
|
|
}
|
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
}
|
|
|
|
|
|
|
|
FlushSkinCaches();
|
2010-03-02 13:00:39 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
|
2007-03-22 10:30:00 -07:00
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
while (more) {
|
|
|
|
nsCOMPtr<nsISupports> protoWindow;
|
|
|
|
windowEnumerator->GetNext(getter_AddRefs(protoWindow));
|
|
|
|
if (protoWindow) {
|
2011-07-15 03:31:34 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (domWindow)
|
2010-03-02 13:00:39 -08:00
|
|
|
RefreshWindow(domWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
windowEnumerator->HasMoreElements(&more);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsChromeRegistry::FlushSkinCaches()
|
|
|
|
{
|
|
|
|
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 09:59:13 -07:00
|
|
|
mozilla::services::GetObserverService();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(obsSvc, "Couldn't get observer service.");
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
obsSvc->NotifyObservers(static_cast<nsIChromeRegistry*>(this),
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_CHROME_FLUSH_SKINS_TOPIC, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXXbsmedberg: move this to windowmediator
|
2011-07-15 03:31:34 -07:00
|
|
|
nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindow* aWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Deal with our subframes first.
|
|
|
|
nsCOMPtr<nsIDOMWindowCollection> frames;
|
|
|
|
aWindow->GetFrames(getter_AddRefs(frames));
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length;
|
2007-03-22 10:30:00 -07:00
|
|
|
frames->GetLength(&length);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t j;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (j = 0; j < length; j++) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> childWin;
|
|
|
|
frames->Item(j, getter_AddRefs(childWin));
|
2011-07-15 03:31:34 -07:00
|
|
|
RefreshWindow(childWin);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
// Get the DOM document.
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDocument;
|
|
|
|
aWindow->GetDocument(getter_AddRefs(domDocument));
|
|
|
|
if (!domDocument)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> document = do_QueryInterface(domDocument);
|
|
|
|
if (!document)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Deal with the agent sheets first. Have to do all the style sets by hand.
|
2010-06-25 06:59:57 -07:00
|
|
|
nsCOMPtr<nsIPresShell> shell = document->GetShell();
|
2010-01-07 02:36:11 -08:00
|
|
|
if (shell) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Reload only the chrome URL agent style sheets.
|
|
|
|
nsCOMArray<nsIStyleSheet> agentSheets;
|
|
|
|
rv = shell->GetAgentStyleSheets(agentSheets);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMArray<nsIStyleSheet> newAgentSheets;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t l = 0; l < agentSheets.Count(); ++l) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIStyleSheet *sheet = agentSheets[l];
|
|
|
|
|
2010-05-17 21:00:40 -07:00
|
|
|
nsIURI* uri = sheet->GetSheetURI();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (IsChromeURI(uri)) {
|
|
|
|
// Reload the sheet.
|
2014-06-20 03:32:49 -07:00
|
|
|
nsRefPtr<CSSStyleSheet> newSheet;
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = document->LoadChromeSheetSync(uri, true,
|
2010-03-02 13:00:39 -08:00
|
|
|
getter_AddRefs(newSheet));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (newSheet) {
|
|
|
|
rv = newAgentSheets.AppendObject(newSheet) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // Just use the same sheet.
|
|
|
|
rv = newAgentSheets.AppendObject(sheet) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = shell->SetAgentStyleSheets(newAgentSheets);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build an array of nsIURIs of style sheets we need to load.
|
|
|
|
nsCOMArray<nsIStyleSheet> oldSheets;
|
|
|
|
nsCOMArray<nsIStyleSheet> newSheets;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = document->GetNumberOfStyleSheets();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Iterate over the style sheets.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
// Get the style sheet
|
|
|
|
nsIStyleSheet *styleSheet = document->GetStyleSheetAt(i);
|
2010-03-02 13:00:39 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!oldSheets.AppendObject(styleSheet)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-02 13:00:39 -08:00
|
|
|
// Iterate over our old sheets and kick off a sync load of the new
|
2007-03-22 10:30:00 -07:00
|
|
|
// sheet if and only if it's a chrome URL.
|
|
|
|
for (i = 0; i < count; i++) {
|
2014-06-20 03:32:49 -07:00
|
|
|
nsRefPtr<CSSStyleSheet> sheet = do_QueryObject(oldSheets[i]);
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-10 06:52:23 -07:00
|
|
|
if (uri && IsChromeURI(uri)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Reload the sheet.
|
2014-06-20 03:32:49 -07:00
|
|
|
nsRefPtr<CSSStyleSheet> newSheet;
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX what about chrome sheets that have a title or are disabled? This
|
|
|
|
// only works by sheer dumb luck.
|
2011-10-17 07:59:28 -07:00
|
|
|
document->LoadChromeSheetSync(uri, false, getter_AddRefs(newSheet));
|
2007-03-22 10:30:00 -07:00
|
|
|
// Even if it's null, we put in in there.
|
|
|
|
newSheets.AppendObject(newSheet);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Just use the same sheet.
|
|
|
|
newSheets.AppendObject(sheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now notify the document that multiple sheets have been added and removed.
|
|
|
|
document->UpdateStyleSheets(oldSheets, newSheets);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsChromeRegistry::FlushAllCaches()
|
|
|
|
{
|
|
|
|
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 09:59:13 -07:00
|
|
|
mozilla::services::GetObserverService();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(obsSvc, "Couldn't get observer service.");
|
|
|
|
|
|
|
|
obsSvc->NotifyObservers((nsIChromeRegistry*) this,
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_CHROME_FLUSH_TOPIC, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// xxxbsmedberg Move me to nsIWindowMediator
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsChromeRegistry::ReloadChrome()
|
|
|
|
{
|
2010-11-30 06:02:23 -08:00
|
|
|
UpdateSelectedLocale();
|
2007-03-22 10:30:00 -07:00
|
|
|
FlushAllCaches();
|
|
|
|
// Do a reload of all top level windows.
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// Get the window mediator
|
|
|
|
nsCOMPtr<nsIWindowMediator> windowMediator
|
|
|
|
(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
|
|
|
|
if (windowMediator) {
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = windowMediator->GetEnumerator(nullptr, getter_AddRefs(windowEnumerator));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Get each dom window
|
2011-09-28 23:19:26 -07:00
|
|
|
bool more;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = windowEnumerator->HasMoreElements(&more);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
while (more) {
|
|
|
|
nsCOMPtr<nsISupports> protoWindow;
|
|
|
|
rv = windowEnumerator->GetNext(getter_AddRefs(protoWindow));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-07-15 03:31:34 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(protoWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (domWindow) {
|
|
|
|
nsCOMPtr<nsIDOMLocation> location;
|
|
|
|
domWindow->GetLocation(getter_AddRefs(location));
|
|
|
|
if (location) {
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = location->Reload(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rv = windowEnumerator->HasMoreElements(&more);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsChromeRegistry::AllowScriptsForPackage(nsIURI* aChromeURI, bool *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2011-10-17 07:59:28 -07:00
|
|
|
*aResult = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isChrome;
|
2007-03-22 10:30:00 -07:00
|
|
|
aChromeURI->SchemeIs("chrome", &isChrome);
|
|
|
|
NS_ASSERTION(isChrome, "Non-chrome URI passed to AllowScriptsForPackage!");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url (do_QueryInterface(aChromeURI));
|
|
|
|
NS_ENSURE_TRUE(url, NS_NOINTERFACE);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString provider, file;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = GetProviderAndPath(url, provider, file);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!provider.EqualsLiteral("skin"))
|
2011-10-17 07:59:28 -07:00
|
|
|
*aResult = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-11 06:39:43 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsChromeRegistry::AllowContentToAccess(nsIURI *aURI, bool *aResult)
|
2008-04-11 06:39:43 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aResult = false;
|
2008-04-11 06:39:43 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isChrome;
|
2008-04-11 06:39:43 -07: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-01 19:35:17 -07:00
|
|
|
nsAutoCString package;
|
2008-04-11 06:39:43 -07:00
|
|
|
rv = url->GetHostPort(package);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags;
|
2010-03-10 21:33:00 -08:00
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
2008-04-11 06:39:43 -07:00
|
|
|
|
2010-03-10 21:33:00 -08:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aResult = !!(flags & CONTENT_ACCESSIBLE);
|
2008-04-11 06:39:43 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-05 08:09:15 -08: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;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2008-11-13 16:00:11 -08:00
|
|
|
nsChromeRegistry::WrappersEnabled(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURL> chromeURL (do_QueryInterface(aURI));
|
|
|
|
if (!chromeURL)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-11-13 16:00:11 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isChrome = false;
|
2008-11-13 16:00:11 -08:00
|
|
|
nsresult rv = chromeURL->SchemeIs("chrome", &isChrome);
|
|
|
|
if (NS_FAILED(rv) || !isChrome)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-11-13 16:00:11 -08:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString package;
|
2008-11-13 16:00:11 -08:00
|
|
|
rv = chromeURL->GetHostPort(package);
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-11-13 16:00:11 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags;
|
2010-06-07 15:49:12 -07:00
|
|
|
rv = GetFlagsFromPackage(package, &flags);
|
|
|
|
return NS_SUCCEEDED(rv) && (flags & XPCNATIVEWRAPPERS);
|
2008-11-13 16:00:11 -08:00
|
|
|
}
|
|
|
|
|
2010-07-01 08:55:57 -07:00
|
|
|
already_AddRefed<nsChromeRegistry>
|
|
|
|
nsChromeRegistry::GetSingleton()
|
2009-11-02 10:04:45 -08:00
|
|
|
{
|
2010-07-01 08:55:57 -07:00
|
|
|
if (gChromeRegistry) {
|
2013-04-22 04:15:59 -07:00
|
|
|
nsRefPtr<nsChromeRegistry> registry = gChromeRegistry;
|
|
|
|
return registry.forget();
|
2009-11-02 10:04:45 -08:00
|
|
|
}
|
|
|
|
|
2010-07-01 08:55:57 -07:00
|
|
|
nsRefPtr<nsChromeRegistry> cr;
|
|
|
|
if (GeckoProcessType_Content == XRE_GetProcessType())
|
|
|
|
cr = new nsChromeRegistryContent();
|
|
|
|
else
|
|
|
|
cr = new nsChromeRegistryChrome();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-01 08:55:57 -07:00
|
|
|
if (NS_FAILED(cr->Init()))
|
2013-04-02 17:15:07 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-01 08:55:57 -07:00
|
|
|
return cr.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|