From 8b8add04674ca49626d083cfcd845c0a90edddeb Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Wed, 1 Jun 2005 19:09:44 +0000 Subject: [PATCH] Bug 295265 - (re)introduce chrome overrides r=darin a=shaver --- chrome/src/nsChromeRegistry.cpp | 42 ++++++++++++++++++++++++++++++--- chrome/src/nsChromeRegistry.h | 4 ++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/chrome/src/nsChromeRegistry.cpp b/chrome/src/nsChromeRegistry.cpp index 4f82c48028ee..b864fba47616 100644 --- a/chrome/src/nsChromeRegistry.cpp +++ b/chrome/src/nsChromeRegistry.cpp @@ -466,7 +466,8 @@ nsChromeRegistry::Init() return NS_ERROR_FAILURE; if (!mOverlayHash.Init() || - !mStyleHash.Init()) + !mStyleHash.Init() || + !mOverrideTable.Init()) return NS_ERROR_FAILURE; mSelectedLocale = NS_LITERAL_CSTRING("en-US"); @@ -664,6 +665,9 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult) nsresult rv; NS_ASSERTION(aChromeURI, "null url!"); + if (mOverrideTable.Get(aChromeURI, aResult)) + return NS_OK; + nsCOMPtr chromeURL (do_QueryInterface(aChromeURI)); NS_ENSURE_TRUE(chromeURL, NS_NOINTERFACE); @@ -1051,6 +1055,7 @@ nsChromeRegistry::CheckForNewChrome() PL_DHashTableEnumerate(&mPackagesHash, RemoveAll, nsnull); mOverlayHash.Clear(); mStyleHash.Clear(); + mOverrideTable.Clear(); nsCOMPtr manifestURI; rv = NS_NewURI(getter_AddRefs(manifestURI), @@ -1999,8 +2004,11 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length, } char *base = nsCRT::strtok(whitespace, kWhitespace, &whitespace); char *overlay = nsCRT::strtok(whitespace, kWhitespace, &whitespace); - if (!base || !overlay) + if (!base || !overlay) { + LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag, + "Warning: malformed chrome overlay instruction."); continue; + } nsCOMPtr baseuri, overlayuri; rv = io->NewURI(nsDependentCString(base), nsnull, nsnull, @@ -2017,8 +2025,11 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length, else if (!strcmp(token, "style")) { char *base = nsCRT::strtok(whitespace, kWhitespace, &whitespace); char *overlay = nsCRT::strtok(whitespace, kWhitespace, &whitespace); - if (!base || !overlay) + if (!base || !overlay) { + LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag, + "Warning: malformed chrome style instruction."); continue; + } nsCOMPtr baseuri, overlayuri; rv = io->NewURI(nsDependentCString(base), nsnull, nsnull, @@ -2030,6 +2041,31 @@ nsChromeRegistry::ProcessManifestBuffer(char *buf, PRInt32 length, mStyleHash.Add(baseuri, overlayuri); } + else if (!strcmp(token, "override")) { + if (aSkinOnly) { + LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag, + "Warning: Ignoring override registration in skin-only manifest."); + continue; + } + + char *chrome = nsCRT::strtok(whitespace, kWhitespace, &whitespace); + char *resolved = nsCRT::strtok(whitespace, kWhitespace, &whitespace); + if (!chrome || !resolved) { + LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag, + "Warning: malformed chrome override instruction."); + continue; + } + + nsCOMPtr chromeuri, resolveduri; + rv = io->NewURI(nsDependentCString(chrome), nsnull, nsnull, + getter_AddRefs(chromeuri)); + rv |= io->NewURI(nsDependentCString(resolved), nsnull, nsnull, + getter_AddRefs(resolveduri)); + if (NS_FAILED(rv)) + continue; + + mOverrideTable.Put(chromeuri, resolveduri); + } else { LogMessageWithContext(manifestURI, line, nsIScriptError::warningFlag, "Warning: Ignoring unrecognized chrome manifest instruction."); diff --git a/chrome/src/nsChromeRegistry.h b/chrome/src/nsChromeRegistry.h index 54bfafb244ed..749c4f3f4365 100644 --- a/chrome/src/nsChromeRegistry.h +++ b/chrome/src/nsChromeRegistry.h @@ -50,6 +50,7 @@ #include "nsTHashtable.h" #include "nsURIHashKey.h" #include "nsVoidArray.h" +#include "nsInterfaceHashtable.h" struct PRFileDesc; class nsIAtom; @@ -235,6 +236,9 @@ private: OverlayListHash mOverlayHash; OverlayListHash mStyleHash; + // "Override" table (chrome URI string -> real URI) + nsInterfaceHashtable mOverrideTable; + nsCString mSelectedLocale; nsCString mSelectedSkin; };