Bug 233160 - separate style overlays out of nsIXULChomeRegistry r+sr=hyatt with additional lookovers from dbaron+bz

This commit is contained in:
bsmedberg%covad.net 2004-03-09 19:59:09 +00:00
Родитель 82e01f4cf4
Коммит b107850633
25 изменённых файлов: 956 добавлений и 769 удалений

Просмотреть файл

@ -45,14 +45,12 @@ REQUIRES = xpcom \
content \ content \
necko \ necko \
dom \ dom \
intl \
widget \ widget \
js \ js \
appshell \ appshell \
caps \ caps \
pref \ pref \
docshell \ docshell \
imglib2 \
xpconnect \ xpconnect \
jar \ jar \
$(NULL) $(NULL)

Просмотреть файл

@ -22,6 +22,7 @@
* Contributor(s): * Contributor(s):
* Original Author: David W. Hyatt (hyatt@netscape.com) * Original Author: David W. Hyatt (hyatt@netscape.com)
* Gagan Saksena <gagan@netscape.com> * Gagan Saksena <gagan@netscape.com>
* Benjamin Smedberg <bsmedberg@covad.net>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -37,11 +38,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/* build on macs with low memory */
#if defined(XP_MAC) && defined(MOZ_MAC_LOWMEM)
#pragma optimization_level 1
#endif
#include <string.h> #include <string.h>
#include "nsArrayEnumerator.h" #include "nsArrayEnumerator.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -52,7 +48,6 @@
#include "nsIRDFObserver.h" #include "nsIRDFObserver.h"
#include "nsIRDFRemoteDataSource.h" #include "nsIRDFRemoteDataSource.h"
#include "nsIRDFXMLSink.h" #include "nsIRDFXMLSink.h"
#include "nsCRT.h"
#include "rdf.h" #include "rdf.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsIRDFService.h" #include "nsIRDFService.h"
@ -65,7 +60,6 @@
#include "nsString.h" #include "nsString.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsIStringBundle.h"
#include "nsISimpleEnumerator.h" #include "nsISimpleEnumerator.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsIFileChannel.h" #include "nsIFileChannel.h"
@ -78,19 +72,14 @@
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsIDOMDocument.h" #include "nsIDOMDocument.h"
#include "nsIStyleSheet.h" #include "nsIStyleSheet.h"
#include "nsIHTMLCSSStyleSheet.h" #include "nsICSSLoader.h"
#include "nsIHTMLStyleSheet.h" #include "nsICSSStyleSheet.h"
#include "nsIPresShell.h" #include "nsIPresShell.h"
#include "nsIDocShell.h" #include "nsIDocShell.h"
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "nsIDocumentObserver.h" #include "nsIDocumentObserver.h"
#ifdef MOZ_XUL
#include "nsIXULDocument.h"
#include "nsIXULPrototypeCache.h"
#endif
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsLayoutCID.h" #include "nsLayoutCID.h"
#include "nsGfxCIID.h"
#include "nsIBindingManager.h" #include "nsIBindingManager.h"
#include "prio.h" #include "prio.h"
#include "nsInt64.h" #include "nsInt64.h"
@ -101,10 +90,7 @@
#include "nsIPrefService.h" #include "nsIPrefService.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIDOMElement.h" #include "nsIDOMElement.h"
#include "nsIChromeEventHandler.h"
#include "nsIContent.h"
#include "nsIDOMWindowCollection.h" #include "nsIDOMWindowCollection.h"
#include "imgICache.h"
#include "nsIAtom.h" #include "nsIAtom.h"
#include "nsStaticAtom.h" #include "nsStaticAtom.h"
#include "nsNetCID.h" #include "nsNetCID.h"
@ -112,7 +98,6 @@
#include "nsIFileURL.h" #include "nsIFileURL.h"
static char kChromePrefix[] = "chrome://"; static char kChromePrefix[] = "chrome://";
static char kUseXBLFormsPref[] = "nglayout.debug.enable_xbl_forms";
nsIAtom* nsChromeRegistry::sCPrefix; // atom for "c" nsIAtom* nsChromeRegistry::sCPrefix; // atom for "c"
#define kChromeFileName NS_LITERAL_CSTRING("chrome.rdf") #define kChromeFileName NS_LITERAL_CSTRING("chrome.rdf")
@ -123,7 +108,6 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID); static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID); static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
class nsChromeRegistry; class nsChromeRegistry;
@ -151,17 +135,12 @@ DEFINE_RDF_VOCAB(CHROME_URI, CHROME, disabled);
nsChromeRegistry::nsChromeRegistry() : mRDFService(nsnull), nsChromeRegistry::nsChromeRegistry() : mRDFService(nsnull),
mRDFContainerUtils(nsnull), mRDFContainerUtils(nsnull),
mUseXBLForms(PR_FALSE),
mInstallInitialized(PR_FALSE), mInstallInitialized(PR_FALSE),
mProfileInitialized(PR_FALSE), mProfileInitialized(PR_FALSE),
mRuntimeProvider(PR_FALSE), mRuntimeProvider(PR_FALSE),
mBatchInstallFlushes(PR_FALSE), mBatchInstallFlushes(PR_FALSE),
mSearchedForOverride(PR_FALSE) mSearchedForOverride(PR_FALSE)
{ {
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefBranch)
prefBranch->GetBoolPref(kUseXBLFormsPref, &mUseXBLForms);
mDataSourceTable = nsnull; mDataSourceTable = nsnull;
} }
@ -1046,44 +1025,15 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL,
return LoadDataSource(overlayFile, aResult, aUseProfile, nsnull); return LoadDataSource(overlayFile, aResult, aUseProfile, nsnull);
} }
nsresult NS_IMETHODIMP
nsChromeRegistry::GetStyleSheets(nsIURI *aChromeURL, nsChromeRegistry::GetStyleOverlays(nsIURI *aChromeURL,
nsISupportsArray **aResult) nsISimpleEnumerator **aResult)
{ {
*aResult = nsnull; return GetDynamicInfo(aChromeURL, PR_FALSE, aResult);
nsCOMPtr<nsISimpleEnumerator> sheets;
nsresult rv = GetDynamicInfo(aChromeURL, PR_FALSE, getter_AddRefs(sheets));
if (NS_FAILED(rv) || !sheets) return rv;
PRBool hasMore;
rv = sheets->HasMoreElements(&hasMore);
if (NS_FAILED(rv)) return rv;
while (hasMore) {
if (!*aResult) {
rv = NS_NewISupportsArray(aResult);
if (NS_FAILED(rv)) return rv;
}
nsCOMPtr<nsISupports> supp;
rv = sheets->GetNext(getter_AddRefs(supp));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURL> url(do_QueryInterface(supp));
if (url) {
nsCOMPtr<nsICSSStyleSheet> sheet;
nsCAutoString str;
rv = url->GetSpec(str);
if (NS_FAILED(rv)) return rv;
rv = LoadStyleSheet(getter_AddRefs(sheet), str);
if (NS_FAILED(rv)) return rv;
rv = (*aResult)->AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
}
sheets->HasMoreElements(&hasMore);
}
return NS_OK;
} }
NS_IMETHODIMP nsChromeRegistry::GetOverlaysForURI(nsIURI *aChromeURL, nsISimpleEnumerator **aResult) NS_IMETHODIMP
nsChromeRegistry::GetXULOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **aResult)
{ {
return GetDynamicInfo(aChromeURL, PR_TRUE, aResult); return GetDynamicInfo(aChromeURL, PR_TRUE, aResult);
} }
@ -1371,6 +1321,7 @@ static void FlushSkinBindingsForWindow(nsIDOMWindowInternal* aWindow)
document->GetBindingManager()->FlushSkinBindings(); document->GetBindingManager()->FlushSkinBindings();
} }
// XXXbsmedberg: move this to nsIWindowMediator
NS_IMETHODIMP nsChromeRegistry::RefreshSkins() NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
{ {
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID)); nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
@ -1392,7 +1343,7 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
windowEnumerator->HasMoreElements(&more); windowEnumerator->HasMoreElements(&more);
} }
FlushCaches(); FlushSkinCaches();
windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator));
windowEnumerator->HasMoreElements(&more); windowEnumerator->HasMoreElements(&more);
@ -1411,25 +1362,15 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
} }
nsresult nsChromeRegistry::FlushCaches() void
nsChromeRegistry::FlushSkinCaches()
{ {
nsresult rv; nsCOMPtr<nsIObserverService> obsSvc =
do_GetService("@mozilla.org/observer-service;1");
NS_ASSERTION(obsSvc, "Couldn't get observer service.");
#ifdef MOZ_XUL obsSvc->NotifyObservers((nsIChromeRegistry*) this,
// Flush the style sheet cache completely. NS_CHROME_FLUSH_SKINS_TOPIC, nsnull);
nsCOMPtr<nsIXULPrototypeCache> xulCache =
do_GetService("@mozilla.org/xul/xul-prototype-cache;1", &rv);
if (NS_SUCCEEDED(rv) && xulCache)
xulCache->FlushSkinFiles();
#endif
// Flush the new imagelib image chrome cache.
nsCOMPtr<imgICache> imageCache(do_GetService("@mozilla.org/image/cache;1", &rv));
if (NS_SUCCEEDED(rv) && imageCache) {
imageCache->ClearCache(PR_TRUE);
}
return rv;
} }
static PRBool IsChromeURI(nsIURI* aURI) static PRBool IsChromeURI(nsIURI* aURI)
@ -1440,6 +1381,7 @@ static PRBool IsChromeURI(nsIURI* aURI)
return PR_FALSE; return PR_FALSE;
} }
// XXXbsmedberg: move this to windowmediator
nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow)
{ {
// Deal with our subframes first. // Deal with our subframes first.
@ -1771,7 +1713,9 @@ nsChromeRegistry::UpdateDynamicDataSources(nsIRDFDataSource *aDataSource,
NS_IMETHODIMP nsChromeRegistry::SelectSkin(const nsACString& aSkin, NS_IMETHODIMP nsChromeRegistry::SelectSkin(const nsACString& aSkin,
PRBool aUseProfile) PRBool aUseProfile)
{ {
return SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_TRUE); nsresult rv = SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_TRUE);
FlushSkinCaches();
return rv;
} }
NS_IMETHODIMP nsChromeRegistry::SelectLocale(const nsACString& aLocale, NS_IMETHODIMP nsChromeRegistry::SelectLocale(const nsACString& aLocale,
@ -1886,7 +1830,9 @@ nsChromeRegistry::GetSelectedProvider(const nsACString& aPackageName,
NS_IMETHODIMP nsChromeRegistry::DeselectSkin(const nsACString& aSkin, NS_IMETHODIMP nsChromeRegistry::DeselectSkin(const nsACString& aSkin,
PRBool aUseProfile) PRBool aUseProfile)
{ {
return SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_FALSE); nsresult rv = SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_FALSE);
FlushSkinCaches();
return rv;
} }
NS_IMETHODIMP nsChromeRegistry::DeselectLocale(const nsACString& aLocale, NS_IMETHODIMP nsChromeRegistry::DeselectLocale(const nsACString& aLocale,
@ -1979,9 +1925,6 @@ nsChromeRegistry::SetProvider(const nsACString& aProvider,
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
if (aProvider.Equals("skin") && mScrollbarSheet)
LoadStyleSheet(getter_AddRefs(mScrollbarSheet), NS_LITERAL_CSTRING("chrome://global/skin/scrollbars.css"));
return NS_OK; return NS_OK;
} }
@ -2864,30 +2807,26 @@ nsChromeRegistry::GetInstallRoot(nsIFile** aFileURL)
return NS_GetSpecialDirectory(NS_APP_CHROME_DIR, aFileURL); return NS_GetSpecialDirectory(NS_APP_CHROME_DIR, aFileURL);
} }
void
nsChromeRegistry::FlushAllCaches()
{
nsCOMPtr<nsIObserverService> obsSvc =
do_GetService("@mozilla.org/observer-service;1");
NS_ASSERTION(obsSvc, "Couldn't get observer service.");
obsSvc->NotifyObservers((nsIChromeRegistry*) this,
NS_CHROME_FLUSH_TOPIC, nsnull);
}
// xxxbsmedberg Move me to nsIWindowMediator
NS_IMETHODIMP NS_IMETHODIMP
nsChromeRegistry::ReloadChrome() nsChromeRegistry::ReloadChrome()
{ {
FlushAllCaches();
// Do a reload of all top level windows. // Do a reload of all top level windows.
nsresult rv = NS_OK; nsresult rv = NS_OK;
#ifdef MOZ_XUL
// Flush the cache completely.
nsCOMPtr<nsIXULPrototypeCache> xulCache =
do_GetService("@mozilla.org/xul/xul-prototype-cache;1", &rv);
if (NS_SUCCEEDED(rv) && xulCache) {
rv = xulCache->Flush();
if (NS_FAILED(rv)) return rv;
}
#endif
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(kStringBundleServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = bundleService->FlushBundles();
if (NS_FAILED(rv)) return rv;
}
// Get the window mediator // Get the window mediator
nsCOMPtr<nsIWindowMediator> windowMediator = do_GetService(kWindowMediatorCID, &rv); nsCOMPtr<nsIWindowMediator> windowMediator = do_GetService(kWindowMediatorCID, &rv);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
@ -2988,135 +2927,14 @@ nsChromeRegistry::AddToCompositeDataSource(PRBool aUseProfile)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsChromeRegistry::GetAgentSheets(nsIDocShell* aDocShell, nsISupportsArray **aResult)
{
nsresult rv = NS_NewISupportsArray(aResult);
// Determine the agent sheets that should be loaded.
if (!mScrollbarSheet)
LoadStyleSheet(getter_AddRefs(mScrollbarSheet), NS_LITERAL_CSTRING("chrome://global/skin/scrollbars.css"));
if (!mFormSheet) {
nsCAutoString sheetURL;
GetFormSheetURL(sheetURL);
LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL);
}
PRBool shouldOverride = PR_FALSE;
nsCOMPtr<nsIChromeEventHandler> chromeHandler;
aDocShell->GetChromeEventHandler(getter_AddRefs(chromeHandler));
if (chromeHandler) {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(chromeHandler));
if (elt) {
nsAutoString sheets;
elt->GetAttribute(NS_LITERAL_STRING("usechromesheets"), sheets);
if (!sheets.IsEmpty()) {
// Construct the URIs and try to load each sheet.
char* str = ToNewCString(sheets);
char* newStr;
char* token = nsCRT::strtok( str, ", ", &newStr );
while (token) {
nsCOMPtr<nsIContent> content(do_QueryInterface(elt));
nsCOMPtr<nsIDocument> doc = content->GetDocument();
nsCOMPtr<nsIURI> url;
rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token),
nsnull, doc->GetDocumentURI());
nsCOMPtr<nsICSSStyleSheet> sheet;
// The CSSLoader handles all the prototype cache stuff for
// us as needed.
LoadStyleSheetWithURL(url, getter_AddRefs(sheet));
if (sheet) {
// A sheet was loaded successfully. We will *not* use the default
// set of agent sheets (which consists solely of the scrollbar sheet).
shouldOverride = PR_TRUE;
(*aResult)->AppendElement(sheet);
}
// Advance to the next sheet URL.
token = nsCRT::strtok( newStr, ", ", &newStr );
}
nsMemory::Free(str);
}
}
}
if (mScrollbarSheet && !shouldOverride)
(*aResult)->AppendElement(mScrollbarSheet);
if (mFormSheet)
(*aResult)->AppendElement(mFormSheet);
return NS_OK;
}
NS_IMETHODIMP
nsChromeRegistry::GetUserSheets(PRBool aIsChrome, nsISupportsArray **aResult)
{
nsresult rv;
if ((aIsChrome && mUserChromeSheet) || (!aIsChrome && mUserContentSheet)) {
rv = NS_NewISupportsArray(aResult);
if (NS_FAILED(rv)) return rv;
if (aIsChrome && mUserChromeSheet) {
rv = (*aResult)->AppendElement(mUserChromeSheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
}
if (!aIsChrome && mUserContentSheet) {
rv = (*aResult)->AppendElement(mUserContentSheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
}
}
return NS_OK;
}
nsresult nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsACString& aURL)
{
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
if (NS_FAILED(rv)) return rv;
rv = LoadStyleSheetWithURL(uri, aSheet);
return rv;
}
nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet) nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet)
{ {
*aSheet = nsnull; *aSheet = nsnull;
nsresult rv;
if (!mCSSLoader) { nsCOMPtr<nsICSSLoader> cssLoader = do_GetService(kCSSLoaderCID);
mCSSLoader = do_CreateInstance(kCSSLoaderCID, &rv); if (!cssLoader) return NS_ERROR_FAILURE;
NS_ENSURE_SUCCESS(rv, rv);
}
if (mCSSLoader) { return cssLoader->LoadAgentSheet(aURL, aSheet);
rv = mCSSLoader->LoadAgentSheet(aURL, aSheet);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
nsresult nsChromeRegistry::GetUserSheetURL(PRBool aIsChrome, nsACString & aURL)
{
aURL = mProfileRoot;
if (aIsChrome)
aURL.Append("userChrome.css");
else aURL.Append("userContent.css");
return NS_OK;
}
nsresult nsChromeRegistry::GetFormSheetURL(nsACString& aURL)
{
aURL = mUseXBLForms ? "chrome://forms/skin/forms.css" : "resource://gre/res/platform-forms.css";
return NS_OK;
} }
nsresult nsChromeRegistry::LoadInstallDataSource() nsresult nsChromeRegistry::LoadInstallDataSource()
@ -3158,30 +2976,8 @@ nsresult nsChromeRegistry::LoadProfileDataSource()
} }
} }
// We have to flush the chrome cache! // We have to flush the chrome skin cache...
rv = FlushCaches(); FlushAllCaches();
if (NS_FAILED(rv)) return rv;
rv = LoadStyleSheet(getter_AddRefs(mScrollbarSheet), NS_LITERAL_CSTRING("chrome://global/skin/scrollbars.css"));
// This must always be the last line of profile initialization!
nsCAutoString sheetURL;
rv = GetUserSheetURL(PR_TRUE, sheetURL);
if (NS_FAILED(rv)) return rv;
if (!sheetURL.IsEmpty()) {
(void)LoadStyleSheet(getter_AddRefs(mUserChromeSheet), sheetURL);
// it's ok to not have a user.css file
}
rv = GetUserSheetURL(PR_FALSE, sheetURL);
if (NS_FAILED(rv)) return rv;
if (!sheetURL.IsEmpty()) {
(void)LoadStyleSheet(getter_AddRefs(mUserContentSheet), sheetURL);
// it's ok not to have a userContent.css or userChrome.css file
}
rv = GetFormSheetURL(sheetURL);
if (NS_FAILED(rv)) return rv;
if (!sheetURL.IsEmpty())
(void)LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL);
} }
return NS_OK; return NS_OK;
} }
@ -3485,25 +3281,20 @@ NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const char *aTopi
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (!nsCRT::strcmp("profile-before-change", aTopic)) { if (!strcmp("profile-before-change", aTopic)) {
mChromeDataSource = nsnull; mChromeDataSource = nsnull;
mScrollbarSheet = mFormSheet = nsnull;
mInstallInitialized = mProfileInitialized = PR_FALSE; mInstallInitialized = mProfileInitialized = PR_FALSE;
if (!nsCRT::strcmp("shutdown-cleanse", NS_ConvertUCS2toUTF8(someData).get())) { if (!strcmp("shutdown-cleanse", NS_ConvertUCS2toUTF8(someData).get())) {
nsCOMPtr<nsIFile> userChromeDir; nsCOMPtr<nsIFile> userChromeDir;
rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir)); rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir));
if (NS_SUCCEEDED(rv) && userChromeDir) if (NS_SUCCEEDED(rv) && userChromeDir)
rv = userChromeDir->Remove(PR_TRUE); rv = userChromeDir->Remove(PR_TRUE);
} }
} }
else if (!nsCRT::strcmp("profile-after-change", aTopic)) { else if (!strcmp("profile-after-change", aTopic)) {
if (!mProfileInitialized) { if (!mProfileInitialized) {
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefBranch)
prefBranch->GetBoolPref(kUseXBLFormsPref, &mUseXBLForms);
rv = LoadProfileDataSource(); rv = LoadProfileDataSource();
} }
} }

Просмотреть файл

@ -36,11 +36,12 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
class nsIAtom;
class nsICSSStyleSheet;
class nsIRDFService; class nsIRDFService;
class nsIRDFDataSource; class nsIRDFDataSource;
class nsIRDFResource; class nsIRDFResource;
class nsIRDFNode; class nsIRDFNode;
class nsICSSLoader;
class nsISimpleEnumerator; class nsISimpleEnumerator;
class nsSupportsHashtable; class nsSupportsHashtable;
class nsIRDFContainer; class nsIRDFContainer;
@ -51,12 +52,10 @@ class nsIDocument;
#include "nsIChromeRegistry.h" #include "nsIChromeRegistry.h"
#include "nsIXULOverlayProvider.h" #include "nsIXULOverlayProvider.h"
#include "nsIRDFCompositeDataSource.h" #include "nsIRDFCompositeDataSource.h"
#include "nsICSSStyleSheet.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "nsString.h" #include "nsString.h"
#include "nsIZipReader.h" #include "nsIZipReader.h"
#include "nsICSSLoader.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
// for component registration // for component registration
@ -116,16 +115,13 @@ protected:
PRBool aIsOverlay, PRBool PRBool aIsOverlay, PRBool
aUseProfile, PRBool aRemove); aUseProfile, PRBool aRemove);
nsresult LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsACString & aURL);
nsresult LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet); nsresult LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet);
nsresult GetUserSheetURL(PRBool aIsChrome, nsACString & aURL);
nsresult GetFormSheetURL(nsACString& aURL);
nsresult LoadInstallDataSource(); nsresult LoadInstallDataSource();
nsresult LoadProfileDataSource(); nsresult LoadProfileDataSource();
nsresult FlushCaches(); void FlushSkinCaches();
void FlushAllCaches();
private: private:
nsresult LoadDataSource(const nsACString &aFileName, nsresult LoadDataSource(const nsACString &aFileName,
@ -255,22 +251,12 @@ protected:
nsCOMPtr<nsIRDFResource> mPackageVersion; nsCOMPtr<nsIRDFResource> mPackageVersion;
nsCOMPtr<nsIRDFResource> mDisabled; nsCOMPtr<nsIRDFResource> mDisabled;
// Style Sheets
nsCOMPtr<nsICSSStyleSheet> mScrollbarSheet;
nsCOMPtr<nsICSSStyleSheet> mUserChromeSheet;
nsCOMPtr<nsICSSStyleSheet> mUserContentSheet;
nsCOMPtr<nsICSSStyleSheet> mFormSheet;
nsCOMPtr<nsICSSLoader> mCSSLoader;
nsCOMPtr<nsIZipReader> mOverrideJAR; nsCOMPtr<nsIZipReader> mOverrideJAR;
nsCString mOverrideJARURL; nsCString mOverrideJARURL;
// useful atoms - these are static atoms, so don't use nsCOMPtr // useful atoms - these are static atoms, so don't use nsCOMPtr
static nsIAtom* sCPrefix; // "c" static nsIAtom* sCPrefix; // "c"
PRBool mUseXBLForms;
PRPackedBool mInstallInitialized; PRPackedBool mInstallInitialized;
PRPackedBool mProfileInitialized; PRPackedBool mProfileInitialized;
@ -283,4 +269,3 @@ protected:
// make sure we only look once for the JAR override // make sure we only look once for the JAR override
PRPackedBool mSearchedForOverride; PRPackedBool mSearchedForOverride;
}; };

Просмотреть файл

@ -60,6 +60,7 @@ nsIXPathEvaluatorInternal.h \
mozISanitizingSerializer.h \ mozISanitizingSerializer.h \
nsIContentList.h \ nsIContentList.h \
nsIFrameLoader.h \ nsIFrameLoader.h \
nsLayoutStylesheetCache.h \
nsContentCID.h \ nsContentCID.h \
$(NULL) $(NULL)

Просмотреть файл

@ -29,7 +29,7 @@
#include "nsISupportsArray.idl" #include "nsISupportsArray.idl"
interface nsIDocShell; interface nsIDocShell;
[scriptable, uuid(D8C7D8A1-E84C-11d2-BF87-00105A1B0627)] [scriptable, uuid(68389281-f6d0-4533-841d-344a2018140c)]
interface nsIChromeRegistry : nsISupports interface nsIChromeRegistry : nsISupports
{ {
const PRInt32 NONE = 0; const PRInt32 NONE = 0;
@ -64,21 +64,6 @@ interface nsIChromeRegistry : nsISupports
*/ */
AUTF8String convertChromeURL(in nsIURI aChromeURL); AUTF8String convertChromeURL(in nsIURI aChromeURL);
/**
* get the style sheets for a specific chrome URL
*/
nsISupportsArray getStyleSheets(in nsIURI aChromeURL);
/**
* get the user-specified style sheets
*/
nsISupportsArray getUserSheets(in boolean useChromeSheets);
/**
* get the style sheets required for a specific running docshell
*/
nsISupportsArray getAgentSheets(in nsIDocShell docShell);
/** /**
* refresh the chrome list at runtime, looking for new packages/etc * refresh the chrome list at runtime, looking for new packages/etc
*/ */
@ -164,4 +149,19 @@ interface nsIXULChromeRegistry : nsIChromeRegistry {
#define NS_CHROMEREGISTRY_CONTRACTID \ #define NS_CHROMEREGISTRY_CONTRACTID \
"@mozilla.org/chrome/chrome-registry;1" "@mozilla.org/chrome/chrome-registry;1"
/**
* Chrome registry will notify various caches that all chrome files need
* flushing.
*/
#define NS_CHROME_FLUSH_TOPIC \
"chrome-flush-caches"
/**
* Chrome registry will notify various caches that skin files need flushing.
* If "chrome-flush-caches" is notified, this topic will *not* be notified.
*/
#define NS_CHROME_FLUSH_SKINS_TOPIC \
"chrome-flush-skin-caches"
%} %}

Просмотреть файл

@ -0,0 +1,78 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Gecko Layout
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <bsmedberg@covad.net>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsLayoutStylesheetCache_h__
#define nsLayoutStylesheetCache_h__
#include "nsICSSStyleSheet.h"
#include "nsCOMPtr.h"
#include "nsIObserver.h"
class nsIFile;
class nsLayoutStylesheetCache
: public nsIObserver
{
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
static nsICSSStyleSheet* ScrollbarsSheet();
static nsICSSStyleSheet* FormsSheet();
static nsICSSStyleSheet* UserContentSheet();
static nsICSSStyleSheet* UserChromeSheet();
static void Shutdown();
private:
nsLayoutStylesheetCache();
~nsLayoutStylesheetCache();
static void EnsureGlobal();
void InitFromSkin();
void InitFromProfile();
static void LoadSheetFile(nsIFile* aFile, nsCOMPtr<nsICSSStyleSheet> &aSheet);
static void LoadSheet(nsIURI* aURI, nsCOMPtr<nsICSSStyleSheet> &aSheet);
static nsLayoutStylesheetCache* gStyleCache;
nsCOMPtr<nsICSSStyleSheet> mScrollbarsSheet;
nsCOMPtr<nsICSSStyleSheet> mFormsSheet;
nsCOMPtr<nsICSSStyleSheet> mUserContentSheet;
nsCOMPtr<nsICSSStyleSheet> mUserChromeSheet;
};
#endif

Просмотреть файл

@ -46,6 +46,7 @@ REQUIRES = xpcom \
chrome \ chrome \
docshell \ docshell \
pref \ pref \
profile \
xpconnect \ xpconnect \
util \ util \
unicharutil \ unicharutil \
@ -91,6 +92,7 @@ CPPSRCS = \
nsGenericDOMNodeList.cpp \ nsGenericDOMNodeList.cpp \
nsGenericElement.cpp \ nsGenericElement.cpp \
nsContentUtils.cpp \ nsContentUtils.cpp \
nsLayoutStylesheetCache.cpp \
nsMappedAttributes.cpp \ nsMappedAttributes.cpp \
nsNameSpaceManager.cpp \ nsNameSpaceManager.cpp \
nsNodeInfo.cpp \ nsNodeInfo.cpp \

Просмотреть файл

@ -72,6 +72,7 @@
#include "nsContentCID.h" #include "nsContentCID.h"
#include "nsLayoutCID.h" #include "nsLayoutCID.h"
#include "nsGenericHTMLElement.h" #include "nsGenericHTMLElement.h"
#include "nsLayoutStylesheetCache.h"
#include "nsViewsCID.h" #include "nsViewsCID.h"
#include "nsWidgetsCID.h" #include "nsWidgetsCID.h"
@ -86,8 +87,11 @@
#include "nsIPrefLocalizedString.h" #include "nsIPrefLocalizedString.h"
#include "nsIPageSequenceFrame.h" #include "nsIPageSequenceFrame.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsIChromeEventHandler.h"
#include "nsIContentViewerEdit.h" #include "nsIContentViewerEdit.h"
#include "nsIContentViewerFile.h" #include "nsIContentViewerFile.h"
#include "nsICSSLoader.h"
#include "nsIMarkupDocumentViewer.h" #include "nsIMarkupDocumentViewer.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h" #include "nsIInterfaceRequestorUtils.h"
@ -112,7 +116,6 @@
#include "nsIXULDocument.h" // Temporary code for Bug 136185 #include "nsIXULDocument.h" // Temporary code for Bug 136185
#endif #endif
#include "nsIChromeRegistry.h"
#include "nsIClipboardHelper.h" #include "nsIClipboardHelper.h"
#include "nsIEventQueueService.h" #include "nsIEventQueueService.h"
@ -1719,6 +1722,8 @@ DocumentViewerImpl::ForceRefresh()
mWindow->Invalidate(PR_TRUE); mWindow->Invalidate(PR_TRUE);
} }
NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
nsresult nsresult
DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
nsStyleSet** aStyleSet) nsStyleSet** aStyleSet)
@ -1754,44 +1759,70 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
} }
} }
nsCOMPtr<nsIChromeRegistry> chromeRegistry = // Now handle the user sheets.
do_GetService("@mozilla.org/chrome/chrome-registry;1"); nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(mContainer));
PRInt32 shellType;
docShell->GetItemType(&shellType);
nsICSSStyleSheet* sheet = nsnull;
if (shellType == nsIDocShellTreeItem::typeChrome) {
sheet = nsLayoutStylesheetCache::UserChromeSheet();
}
else {
sheet = nsLayoutStylesheetCache::UserContentSheet();
}
if (chromeRegistry) { if (sheet)
nsCOMPtr<nsISupportsArray> sheets; styleSet->PrependStyleSheet(nsStyleSet::eUserSheet, sheet);
// Now handle the user sheets. // Append chrome sheets (scrollbars + forms).
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(mContainer)); PRBool shouldOverride = PR_FALSE;
PRInt32 shellType; nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer));
docShell->GetItemType(&shellType); nsCOMPtr<nsIChromeEventHandler> chromeHandler;
PRBool isChrome = (shellType == nsIDocShellTreeItem::typeChrome); nsCOMPtr<nsICSSLoader> cssLoader( do_GetService(kCSSLoaderCID) );
chromeRegistry->GetUserSheets(isChrome, getter_AddRefs(sheets)); nsCOMPtr<nsIURI> uri;
if (sheets) { nsCOMPtr<nsICSSStyleSheet> csssheet;
nsCOMPtr<nsICSSStyleSheet> sheet;
PRUint32 count; ds->GetChromeEventHandler(getter_AddRefs(chromeHandler));
sheets->Count(&count); if (chromeHandler) {
// Insert the user sheets at the front of the user sheet list nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(chromeHandler));
// so that they are most significant user sheets. nsCOMPtr<nsIContent> content(do_QueryInterface(elt));
for (PRUint32 i=0; i<count; i++) { if (elt && content) {
sheets->GetElementAt(i, getter_AddRefs(sheet)); nsCOMPtr<nsIURI> baseURI = content->GetBaseURI();
styleSet->PrependStyleSheet(nsStyleSet::eUserSheet, sheet);
nsAutoString sheets;
elt->GetAttribute(NS_LITERAL_STRING("usechromesheets"), sheets);
if (!sheets.IsEmpty() && baseURI) {
char *str = ToNewCString(sheets);
char *newStr;
char *token = str;
while ( (token = nsCRT::strtok(token, ", ", &newStr)) ) {
NS_NewURI(getter_AddRefs(uri), nsDependentCString(token), nsnull,
baseURI);
if (!uri) continue;
cssLoader->LoadAgentSheet(uri, getter_AddRefs(csssheet));
if (!sheet) continue;
styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, csssheet);
shouldOverride = PR_TRUE;
}
nsMemory::Free(str);
} }
} }
}
// Append chrome sheets (scrollbars + forms). if (!shouldOverride) {
nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer)); sheet = nsLayoutStylesheetCache::ScrollbarsSheet();
chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets)); if (sheet) {
if (sheets) { styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
nsCOMPtr<nsICSSStyleSheet> sheet;
PRUint32 count;
sheets->Count(&count);
for (PRUint32 i=0; i<count; i++) {
sheets->GetElementAt(i, getter_AddRefs(sheet));
styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
}
} }
} }
sheet = nsLayoutStylesheetCache::FormsSheet();
if (sheet) {
styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
}
if (mUAStyleSheet) { if (mUAStyleSheet) {
styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, mUAStyleSheet); styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, mUAStyleSheet);
} }
@ -3620,8 +3651,6 @@ DocumentViewerImpl::ReturnToGalleyPresentation()
} }
// Get the current size of what is being viewed // Get the current size of what is being viewed
nsRect area = mPresContext->GetVisibleArea();
nsRect bounds; nsRect bounds;
mWindow->GetBounds(bounds); mWindow->GetBounds(bounds);
@ -3725,8 +3754,6 @@ DocumentViewerImpl::InstallNewPresentation()
{ {
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW) #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
// Get the current size of what is being viewed // Get the current size of what is being viewed
nsRect area = mPresContext->GetVisibleArea();
nsRect bounds; nsRect bounds;
mWindow->GetBounds(bounds); mWindow->GetBounds(bounds);

Просмотреть файл

@ -0,0 +1,227 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Gecko Layout
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <bsmedberg@covad.net>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsLayoutStylesheetCache.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsICSSLoader.h"
#include "nsIFile.h"
#include "nsLayoutCID.h"
#include "nsNetUtil.h"
#include "nsIObserverService.h"
#include "nsIServiceManagerUtils.h"
#include "nsIProfileChangeStatus.h"
NS_IMPL_ISUPPORTS1(nsLayoutStylesheetCache, nsIObserver)
nsresult
nsLayoutStylesheetCache::Observe(nsISupports* aSubject,
const char* aTopic,
const PRUnichar* aData)
{
if (!strcmp(aTopic, "profile-before-change")) {
mScrollbarsSheet = nsnull;
mUserContentSheet = nsnull;
mUserChromeSheet = nsnull;
}
else if (!strcmp(aTopic, "profile-do-change")) {
InitFromProfile();
}
else if (strcmp(aTopic, "chrome-flush-skin-caches") == 0 ||
strcmp(aTopic, "chrome-flush-caches") == 0) {
InitFromSkin();
}
else {
NS_NOTREACHED("Unexpected observer topic.");
}
return NS_OK;
}
nsICSSStyleSheet*
nsLayoutStylesheetCache::ScrollbarsSheet()
{
EnsureGlobal();
if (!gStyleCache)
return nsnull;
return gStyleCache->mScrollbarsSheet;
}
nsICSSStyleSheet*
nsLayoutStylesheetCache::FormsSheet()
{
EnsureGlobal();
if (!gStyleCache)
return nsnull;
return gStyleCache->mFormsSheet;
}
nsICSSStyleSheet*
nsLayoutStylesheetCache::UserContentSheet()
{
EnsureGlobal();
if (!gStyleCache)
return nsnull;
return gStyleCache->mUserContentSheet;
}
nsICSSStyleSheet*
nsLayoutStylesheetCache::UserChromeSheet()
{
EnsureGlobal();
if (!gStyleCache)
return nsnull;
return gStyleCache->mUserChromeSheet;
}
void
nsLayoutStylesheetCache::Shutdown()
{
NS_IF_RELEASE(gStyleCache);
}
nsLayoutStylesheetCache::nsLayoutStylesheetCache()
{
nsCOMPtr<nsIObserverService> obsSvc =
do_GetService("@mozilla.org/observer-service;1");
NS_ASSERTION(obsSvc, "No global observer service?");
if (obsSvc) {
obsSvc->AddObserver(this, "profile-before-change", PR_FALSE);
obsSvc->AddObserver(this, "profile-do-change", PR_FALSE);
obsSvc->AddObserver(this, "chrome-flush-skin-caches", PR_FALSE);
obsSvc->AddObserver(this, "chrome-flush-caches", PR_FALSE);
}
nsCOMPtr<nsIURI> formsSheetURI;
NS_NewURI(getter_AddRefs(formsSheetURI),
NS_LITERAL_CSTRING("resource://gre/res/platform-forms.css"));
LoadSheet(formsSheetURI, mFormsSheet);
NS_ASSERTION(mFormsSheet, "Could not load platform-forms.css stylesheet.");
InitFromProfile();
InitFromSkin();
}
nsLayoutStylesheetCache::~nsLayoutStylesheetCache()
{
gStyleCache = nsnull;
}
void
nsLayoutStylesheetCache::EnsureGlobal()
{
if (gStyleCache) return;
gStyleCache = new nsLayoutStylesheetCache();
if (!gStyleCache) return;
NS_ADDREF(gStyleCache);
}
void
nsLayoutStylesheetCache::InitFromProfile()
{
nsCOMPtr<nsIFile> contentFile;
nsCOMPtr<nsIFile> chromeFile;
NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR,
getter_AddRefs(contentFile));
if (!contentFile) {
// if we don't have a profile yet, that's OK!
return;
}
contentFile->Clone(getter_AddRefs(chromeFile));
if (!chromeFile) return;
contentFile->Append(NS_LITERAL_STRING("userContent.css"));
chromeFile->Append(NS_LITERAL_STRING("userChrome.css"));
LoadSheetFile(contentFile, mUserContentSheet);
LoadSheetFile(chromeFile, mUserChromeSheet);
}
void
nsLayoutStylesheetCache::InitFromSkin()
{
nsCOMPtr<nsIURI> scrollbarsSheetURI;
NS_NewURI(getter_AddRefs(scrollbarsSheetURI),
NS_LITERAL_CSTRING("chrome://global/skin/scrollbars.css"));
if (scrollbarsSheetURI) {
LoadSheet(scrollbarsSheetURI, mScrollbarsSheet);
}
NS_ASSERTION(mScrollbarsSheet, "Could not loade scrollbars.css stylesheet.");
}
void
nsLayoutStylesheetCache::LoadSheetFile(nsIFile* aFile, nsCOMPtr<nsICSSStyleSheet> &aSheet)
{
PRBool exists = PR_FALSE;
aFile->Exists(&exists);
if (!exists) return;
nsCOMPtr<nsIURI> uri;
NS_NewFileURI(getter_AddRefs(uri), aFile);
LoadSheet(uri, aSheet);
}
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
void
nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, nsCOMPtr<nsICSSStyleSheet> &aSheet)
{
if (!aURI) {
NS_ERROR("Null URI. Out of memory?");
return;
}
// note: CSS Loader is treated as a service here... slightly unusual,
// but within the rules.
nsCOMPtr<nsICSSLoader> cssLoader = do_GetService(kCSSLoaderCID);
if (!cssLoader) return;
cssLoader->LoadAgentSheet(aURI, getter_AddRefs(aSheet));
}
nsLayoutStylesheetCache*
nsLayoutStylesheetCache::gStyleCache = nsnull;

Просмотреть файл

@ -43,19 +43,24 @@ interface nsIURI;
/** /**
* The chrome registry implements this interface to give overlays * The chrome registry implements this interface to give overlays
* to the gecko XUL engine. * to the gecko XUL engine.
*
* @status UNDER_REVIEW
*/ */
[scriptable, uuid(3b1b0a68-261c-44e1-abfe-fc7637b6977a)] [scriptable, uuid(1d5b5b94-dc47-4050-93b7-ac092e383cad)]
interface nsIXULOverlayProvider : nsISupports interface nsIXULOverlayProvider : nsISupports
{ {
/** /**
* Method will be called by the gecko XUL engine when loading a chrome * Get the XUL overlays for a particular chrome URI.
* XUL page.
* *
* @param aURI The URI being loaded * @param aURI The URI being loaded
* @return An enumerator of nsIURI for the overlays of this URI * @return An enumerator of nsIURI for the overlays of this URI
*/ */
nsISimpleEnumerator /*nsIURI*/ getOverlaysForURI(in nsIURI aURI); nsISimpleEnumerator /*nsIURI*/ getXULOverlays(in nsIURI aURI);
/**
* Get the style overlays for a particular chrome URI.
*
* @param aURI The URI being loaded
* @return An enumerator of nsIURI for the overlays of this URI
*/
nsISimpleEnumerator /*nsIURI*/ getStyleOverlays(in nsIURI aURI);
}; };

Просмотреть файл

@ -60,9 +60,9 @@ class nsIFastLoadService;
#define NS_XULPROTOTYPECACHE_CID \ #define NS_XULPROTOTYPECACHE_CID \
{ 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } { 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
// {3A0A0FC0-8349-11d3-BE47-00104BDE6048} // {CD196299-18E9-4642-AD43-666315C4D241}
#define NS_IXULPROTOTYPECACHE_IID \ #define NS_IXULPROTOTYPECACHE_IID \
{ 0x3a0a0fc0, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } { 0xcd196299, 0x18e9, 0x4642, { 0xad, 0x43, 0x66, 0x63, 0x15, 0xc4, 0xd2, 0x41 } };
class nsIXULPrototypeCache : public nsISupports class nsIXULPrototypeCache : public nsISupports
@ -87,12 +87,6 @@ public:
NS_IMETHOD FlushXBLInformation() = 0; NS_IMETHOD FlushXBLInformation() = 0;
/*
* Flush only the skin files from the cache while retaining all other
* files.
*/
NS_IMETHOD FlushSkinFiles() = 0;
/** /**
* Flush the cache; remove all XUL prototype documents, style * Flush the cache; remove all XUL prototype documents, style
* sheets, and scripts. * sheets, and scripts.

Просмотреть файл

@ -652,6 +652,7 @@ nsXULDocument::SetPrincipal(nsIPrincipal *aPrincipal)
NS_NOTREACHED("SetPrincipal"); NS_NOTREACHED("SetPrincipal");
} }
void void
nsXULDocument::EndLoad() nsXULDocument::EndLoad()
{ {
@ -679,30 +680,40 @@ nsXULDocument::EndLoad()
gXULCache->WritePrototype(mCurrentPrototype); gXULCache->WritePrototype(mCurrentPrototype);
if (isChrome) { if (isChrome) {
nsCOMPtr<nsIXULChromeRegistry> reg = nsCOMPtr<nsIXULOverlayProvider> reg =
do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); do_GetService(NS_CHROMEREGISTRY_CONTRACTID);
if (NS_FAILED(rv)) return; nsCOMPtr<nsICSSLoader> cssLoader = GetCSSLoader();
if (reg && cssLoader) {
nsCOMPtr<nsISimpleEnumerator> overlays;
reg->GetStyleOverlays(uri, getter_AddRefs(overlays));
nsCOMPtr<nsISupportsArray> sheets; PRBool moreSheets;
reg->GetStyleSheets(uri, getter_AddRefs(sheets)); nsCOMPtr<nsISupports> next;
nsCOMPtr<nsIURI> sheetURI;
// Walk the sheets and add them to the prototype. Also put them
// into the document.
if (sheets) {
nsCOMPtr<nsICSSStyleSheet> sheet; nsCOMPtr<nsICSSStyleSheet> sheet;
PRUint32 count;
sheets->Count(&count);
for (PRUint32 i = 0; i < count; ++i) {
sheet = do_QueryElementAt(sheets, i);
if (sheet) {
nsCOMPtr<nsIURI> sheetURL;
sheet->GetURL(*getter_AddRefs(sheetURL));
if (useXULCache && IsChromeURI(sheetURL)) { while (NS_SUCCEEDED(rv = overlays->HasMoreElements(&moreSheets)) &&
mCurrentPrototype->AddStyleSheetReference(sheetURL); moreSheets) {
} overlays->GetNext(getter_AddRefs(next));
AddStyleSheet(sheet, 0);
sheetURI = do_QueryInterface(next);
if (!uri) {
NS_ERROR("Chrome registry handed me a non-nsIURI object!");
continue;
} }
if (useXULCache && IsChromeURI(sheetURI)) {
mCurrentPrototype->AddStyleSheetReference(sheetURI);
}
cssLoader->LoadAgentSheet(sheetURI, getter_AddRefs(sheet));
if (!sheet) {
NS_WARNING("Couldn't load chrome style overlay.");
continue;
}
AddStyleSheet(sheet, 0);
} }
} }
@ -2684,7 +2695,7 @@ nsXULDocument::AddChromeOverlays()
NS_ENSURE_TRUE(chromeReg, NS_OK); NS_ENSURE_TRUE(chromeReg, NS_OK);
nsCOMPtr<nsISimpleEnumerator> overlays; nsCOMPtr<nsISimpleEnumerator> overlays;
rv = chromeReg->GetOverlaysForURI(docUri, getter_AddRefs(overlays)); rv = chromeReg->GetXULOverlays(docUri, getter_AddRefs(overlays));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
PRBool moreOverlays; PRBool moreOverlays;

Просмотреть файл

@ -64,6 +64,8 @@
#include "nsIFile.h" #include "nsIFile.h"
#include "nsIObjectInputStream.h" #include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h" #include "nsIObjectOutputStream.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsURIHashKey.h" #include "nsURIHashKey.h"
@ -71,11 +73,13 @@
#include "nsDataHashtable.h" #include "nsDataHashtable.h"
#include "nsAppDirectoryServiceDefs.h" #include "nsAppDirectoryServiceDefs.h"
class nsXULPrototypeCache : public nsIXULPrototypeCache class nsXULPrototypeCache : public nsIXULPrototypeCache,
nsIObserver
{ {
public: public:
// nsISupports // nsISupports
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_IMETHOD GetPrototype(nsIURI* aURI, nsIXULPrototypeDocument** _result); NS_IMETHOD GetPrototype(nsIURI* aURI, nsIXULPrototypeDocument** _result);
NS_IMETHOD PutPrototype(nsIXULPrototypeDocument* aDocument); NS_IMETHOD PutPrototype(nsIXULPrototypeDocument* aDocument);
@ -92,7 +96,6 @@ public:
NS_IMETHOD GetXBLDocumentInfo(nsIURI* aURL, nsIXBLDocumentInfo** _result); NS_IMETHOD GetXBLDocumentInfo(nsIURI* aURL, nsIXBLDocumentInfo** _result);
NS_IMETHOD PutXBLDocumentInfo(nsIXBLDocumentInfo* aDocumentInfo); NS_IMETHOD PutXBLDocumentInfo(nsIXBLDocumentInfo* aDocumentInfo);
NS_IMETHOD FlushXBLInformation(); NS_IMETHOD FlushXBLInformation();
NS_IMETHOD FlushSkinFiles();
NS_IMETHOD Flush(); NS_IMETHOD Flush();
@ -110,6 +113,8 @@ protected:
nsXULPrototypeCache(); nsXULPrototypeCache();
virtual ~nsXULPrototypeCache(); virtual ~nsXULPrototypeCache();
void FlushSkinFiles();
JSRuntime* GetJSRuntime(); JSRuntime* GetJSRuntime();
nsInterfaceHashtable<nsURIHashKey,nsIXULPrototypeDocument> mPrototypeTable; nsInterfaceHashtable<nsURIHashKey,nsIXULPrototypeDocument> mPrototypeTable;
@ -209,6 +214,13 @@ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult)
NS_ADDREF(result); NS_ADDREF(result);
rv = result->QueryInterface(aIID, aResult); rv = result->QueryInterface(aIID, aResult);
nsCOMPtr<nsIObserverService> obsSvc(do_GetService("@mozilla.org/observer-service;1"));
if (obsSvc && NS_SUCCEEDED(rv)) {
obsSvc->AddObserver(result, "chrome-flush-skin-caches", PR_FALSE);
obsSvc->AddObserver(result, "chrome-flush-caches", PR_FALSE);
}
NS_RELEASE(result); NS_RELEASE(result);
return rv; return rv;
@ -217,6 +229,23 @@ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
NS_IMETHODIMP
nsXULPrototypeCache::Observe(nsISupports* aSubject,
const char *aTopic,
const PRUnichar *aData)
{
if (!strcmp(aTopic, "chrome-flush-skin-caches")) {
FlushSkinFiles();
}
else if (!strcmp(aTopic, "chrome-flush-caches")) {
Flush();
}
else {
NS_WARNING("Unexpected observer topic.");
}
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
nsXULPrototypeCache::GetPrototype(nsIURI* aURI, nsIXULPrototypeDocument** _result) nsXULPrototypeCache::GetPrototype(nsIURI* aURI, nsIXULPrototypeDocument** _result)
@ -431,7 +460,7 @@ FlushScopedSkinStylesheets(nsIURI* aKey, nsCOMPtr<nsIXBLDocumentInfo> &aDocInfo,
return PL_DHASH_NEXT; return PL_DHASH_NEXT;
} }
NS_IMETHODIMP void
nsXULPrototypeCache::FlushSkinFiles() nsXULPrototypeCache::FlushSkinFiles()
{ {
// Flush out skin XBL files from the cache. // Flush out skin XBL files from the cache.
@ -444,7 +473,6 @@ nsXULPrototypeCache::FlushSkinFiles()
// scoped skin stylesheets are flushed and refetched by the // scoped skin stylesheets are flushed and refetched by the
// prototype bindings. // prototype bindings.
mXBLDocTable.Enumerate(FlushScopedSkinStylesheets, nsnull); mXBLDocTable.Enumerate(FlushScopedSkinStylesheets, nsnull);
return NS_OK;
} }

Просмотреть файл

@ -45,8 +45,6 @@ NS_IMPL_ISUPPORTS1(nsSimpleChromeRegistry, nsIChromeRegistry)
nsSimpleChromeRegistry::nsSimpleChromeRegistry() nsSimpleChromeRegistry::nsSimpleChromeRegistry()
{ {
nsCOMPtr<nsISupportsArray> foo;
GetAgentSheets(nsnull, getter_AddRefs(foo));
} }
nsSimpleChromeRegistry::~nsSimpleChromeRegistry() nsSimpleChromeRegistry::~nsSimpleChromeRegistry()
@ -65,74 +63,6 @@ nsSimpleChromeRegistry::ConvertChromeURL(nsIURI *aChromeURL, nsACString & _retva
return aChromeURL->GetSpec(_retval); return aChromeURL->GetSpec(_retval);
} }
NS_IMETHODIMP
nsSimpleChromeRegistry::GetStyleSheets(nsIURI *aChromeURL, nsISupportsArray **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsSimpleChromeRegistry::GetUserSheets(PRBool useChromeSheets, nsISupportsArray **_retval)
{
*_retval = nsnull;
return NS_OK;
}
nsresult
nsSimpleChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsACString& aURL)
{
*aSheet = nsnull;
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
if (NS_FAILED(rv)) return rv;
if (!mCSSLoader) {
mCSSLoader = do_CreateInstance(kCSSLoaderCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
if (mCSSLoader)
rv = mCSSLoader->LoadAgentSheet(uri, aSheet);
#ifdef DEBUG
if (NS_FAILED(rv)) {
nsXPIDLCString spec;
uri->GetSpec(spec);
printf("chrome: failed to load: %s\n", spec.get());
}
#endif
return rv;
}
NS_IMETHODIMP
nsSimpleChromeRegistry::GetAgentSheets(nsIDocShell *docShell, nsISupportsArray **_retval)
{
nsresult rv = NS_NewISupportsArray(_retval);
if (NS_FAILED(rv))
return rv;
// Determine the agent sheets that should be loaded.
if (!mScrollbarSheet)
LoadStyleSheet(getter_AddRefs(mScrollbarSheet), NS_LITERAL_CSTRING("chrome://global/skin/scrollbars.css"));
if (!mFormSheet)
LoadStyleSheet(getter_AddRefs(mFormSheet), NS_LITERAL_CSTRING("resource:/res/platform-forms.css"));
if (mScrollbarSheet) {
(*_retval)->AppendElement(mScrollbarSheet);
}
if (mFormSheet) {
(*_retval)->AppendElement(mFormSheet);
}
return NS_OK;
}
NS_IMETHODIMP nsSimpleChromeRegistry::CheckForNewChrome() NS_IMETHODIMP nsSimpleChromeRegistry::CheckForNewChrome()
{ {
return NS_OK; return NS_OK;

Просмотреть файл

@ -49,13 +49,6 @@ public:
nsSimpleChromeRegistry(); nsSimpleChromeRegistry();
virtual ~nsSimpleChromeRegistry(); virtual ~nsSimpleChromeRegistry();
private:
nsCOMPtr<nsICSSStyleSheet> mScrollbarSheet;
nsCOMPtr<nsICSSStyleSheet> mFormSheet;
nsCOMPtr<nsICSSLoader> mCSSLoader;
nsresult LoadStyleSheet( nsICSSStyleSheet** aSheet, const nsACString& aURL);
}; };
#endif #endif

Просмотреть файл

@ -48,9 +48,9 @@ ac_add_options --enable-necko-protocols=http,file,res,jar
ac_add_options --enable-image-decoders=png,gif,jpeg ac_add_options --enable-image-decoders=png,gif,jpeg
# code generation options (optimize for size) # code generation options (optimize for size)
ac_add_options --enable-optimize=-Os # ac_add_options --enable-optimize=-Os
ac_add_options --enable-strip # ac_add_options --enable-strip
ac_add_options --disable-debug # ac_add_options --disable-debug
ac_add_options --enable-reorder ac_add_options --enable-reorder
ac_add_options --enable-elf-dynstr-gc ac_add_options --enable-elf-dynstr-gc

Просмотреть файл

@ -547,6 +547,7 @@ nsStringBundleService::Init()
if (os) { if (os) {
os->AddObserver(this, "memory-pressure", PR_TRUE); os->AddObserver(this, "memory-pressure", PR_TRUE);
os->AddObserver(this, "profile-do-change", PR_TRUE); os->AddObserver(this, "profile-do-change", PR_TRUE);
os->AddObserver(this, "chrome-flush-caches", PR_TRUE);
} }
// instantiate the override service, if there is any. // instantiate the override service, if there is any.
@ -562,8 +563,9 @@ nsStringBundleService::Observe(nsISupports* aSubject,
const char* aTopic, const char* aTopic,
const PRUnichar* aSomeData) const PRUnichar* aSomeData)
{ {
if (nsCRT::strcmp("memory-pressure", aTopic) == 0 || if (strcmp("memory-pressure", aTopic) == 0 ||
nsCRT::strcmp("profile-do-change", aTopic) == 0) strcmp("profile-do-change", aTopic) == 0 ||
strcmp("chrome-flush-caches", aTopic) == 0)
flushBundleCache(); flushBundleCache();
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -72,6 +72,7 @@
#include "nsContentCID.h" #include "nsContentCID.h"
#include "nsLayoutCID.h" #include "nsLayoutCID.h"
#include "nsGenericHTMLElement.h" #include "nsGenericHTMLElement.h"
#include "nsLayoutStylesheetCache.h"
#include "nsViewsCID.h" #include "nsViewsCID.h"
#include "nsWidgetsCID.h" #include "nsWidgetsCID.h"
@ -86,8 +87,11 @@
#include "nsIPrefLocalizedString.h" #include "nsIPrefLocalizedString.h"
#include "nsIPageSequenceFrame.h" #include "nsIPageSequenceFrame.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsIChromeEventHandler.h"
#include "nsIContentViewerEdit.h" #include "nsIContentViewerEdit.h"
#include "nsIContentViewerFile.h" #include "nsIContentViewerFile.h"
#include "nsICSSLoader.h"
#include "nsIMarkupDocumentViewer.h" #include "nsIMarkupDocumentViewer.h"
#include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h" #include "nsIInterfaceRequestorUtils.h"
@ -112,7 +116,6 @@
#include "nsIXULDocument.h" // Temporary code for Bug 136185 #include "nsIXULDocument.h" // Temporary code for Bug 136185
#endif #endif
#include "nsIChromeRegistry.h"
#include "nsIClipboardHelper.h" #include "nsIClipboardHelper.h"
#include "nsIEventQueueService.h" #include "nsIEventQueueService.h"
@ -1719,6 +1722,8 @@ DocumentViewerImpl::ForceRefresh()
mWindow->Invalidate(PR_TRUE); mWindow->Invalidate(PR_TRUE);
} }
NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
nsresult nsresult
DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
nsStyleSet** aStyleSet) nsStyleSet** aStyleSet)
@ -1754,44 +1759,70 @@ DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument,
} }
} }
nsCOMPtr<nsIChromeRegistry> chromeRegistry = // Now handle the user sheets.
do_GetService("@mozilla.org/chrome/chrome-registry;1"); nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(mContainer));
PRInt32 shellType;
docShell->GetItemType(&shellType);
nsICSSStyleSheet* sheet = nsnull;
if (shellType == nsIDocShellTreeItem::typeChrome) {
sheet = nsLayoutStylesheetCache::UserChromeSheet();
}
else {
sheet = nsLayoutStylesheetCache::UserContentSheet();
}
if (chromeRegistry) { if (sheet)
nsCOMPtr<nsISupportsArray> sheets; styleSet->PrependStyleSheet(nsStyleSet::eUserSheet, sheet);
// Now handle the user sheets. // Append chrome sheets (scrollbars + forms).
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(mContainer)); PRBool shouldOverride = PR_FALSE;
PRInt32 shellType; nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer));
docShell->GetItemType(&shellType); nsCOMPtr<nsIChromeEventHandler> chromeHandler;
PRBool isChrome = (shellType == nsIDocShellTreeItem::typeChrome); nsCOMPtr<nsICSSLoader> cssLoader( do_GetService(kCSSLoaderCID) );
chromeRegistry->GetUserSheets(isChrome, getter_AddRefs(sheets)); nsCOMPtr<nsIURI> uri;
if (sheets) { nsCOMPtr<nsICSSStyleSheet> csssheet;
nsCOMPtr<nsICSSStyleSheet> sheet;
PRUint32 count; ds->GetChromeEventHandler(getter_AddRefs(chromeHandler));
sheets->Count(&count); if (chromeHandler) {
// Insert the user sheets at the front of the user sheet list nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(chromeHandler));
// so that they are most significant user sheets. nsCOMPtr<nsIContent> content(do_QueryInterface(elt));
for (PRUint32 i=0; i<count; i++) { if (elt && content) {
sheets->GetElementAt(i, getter_AddRefs(sheet)); nsCOMPtr<nsIURI> baseURI = content->GetBaseURI();
styleSet->PrependStyleSheet(nsStyleSet::eUserSheet, sheet);
nsAutoString sheets;
elt->GetAttribute(NS_LITERAL_STRING("usechromesheets"), sheets);
if (!sheets.IsEmpty() && baseURI) {
char *str = ToNewCString(sheets);
char *newStr;
char *token = str;
while ( (token = nsCRT::strtok(token, ", ", &newStr)) ) {
NS_NewURI(getter_AddRefs(uri), nsDependentCString(token), nsnull,
baseURI);
if (!uri) continue;
cssLoader->LoadAgentSheet(uri, getter_AddRefs(csssheet));
if (!sheet) continue;
styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, csssheet);
shouldOverride = PR_TRUE;
}
nsMemory::Free(str);
} }
} }
}
// Append chrome sheets (scrollbars + forms). if (!shouldOverride) {
nsCOMPtr<nsIDocShell> ds(do_QueryInterface(mContainer)); sheet = nsLayoutStylesheetCache::ScrollbarsSheet();
chromeRegistry->GetAgentSheets(ds, getter_AddRefs(sheets)); if (sheet) {
if (sheets) { styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
nsCOMPtr<nsICSSStyleSheet> sheet;
PRUint32 count;
sheets->Count(&count);
for (PRUint32 i=0; i<count; i++) {
sheets->GetElementAt(i, getter_AddRefs(sheet));
styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
}
} }
} }
sheet = nsLayoutStylesheetCache::FormsSheet();
if (sheet) {
styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, sheet);
}
if (mUAStyleSheet) { if (mUAStyleSheet) {
styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, mUAStyleSheet); styleSet->AppendStyleSheet(nsStyleSet::eAgentSheet, mUAStyleSheet);
} }
@ -3620,8 +3651,6 @@ DocumentViewerImpl::ReturnToGalleyPresentation()
} }
// Get the current size of what is being viewed // Get the current size of what is being viewed
nsRect area = mPresContext->GetVisibleArea();
nsRect bounds; nsRect bounds;
mWindow->GetBounds(bounds); mWindow->GetBounds(bounds);
@ -3725,8 +3754,6 @@ DocumentViewerImpl::InstallNewPresentation()
{ {
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW) #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
// Get the current size of what is being viewed // Get the current size of what is being viewed
nsRect area = mPresContext->GetVisibleArea();
nsRect bounds; nsRect bounds;
mWindow->GetBounds(bounds); mWindow->GetBounds(bounds);

Просмотреть файл

@ -48,6 +48,7 @@
#include "nsContentDLF.h" #include "nsContentDLF.h"
#include "nsContentPolicyUtils.h" #include "nsContentPolicyUtils.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsLayoutStylesheetCache.h"
#include "nsDOMCID.h" #include "nsDOMCID.h"
#include "nsCSSOMFactory.h" #include "nsCSSOMFactory.h"
#include "nsInspectorCSSUtils.h" #include "nsInspectorCSSUtils.h"
@ -406,6 +407,7 @@ Shutdown(nsIModule* aSelf)
nsGenericHTMLElement::Shutdown(); nsGenericHTMLElement::Shutdown();
nsContentUtils::Shutdown(); nsContentUtils::Shutdown();
nsLayoutStylesheetCache::Shutdown();
NS_NameSpaceManagerShutdown(); NS_NameSpaceManagerShutdown();
nsImageLoadingContent::Shutdown(); nsImageLoadingContent::Shutdown();
nsStyleSet::FreeGlobals(); nsStyleSet::FreeGlobals();

Просмотреть файл

@ -0,0 +1,227 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Gecko Layout
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <bsmedberg@covad.net>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsLayoutStylesheetCache.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsICSSLoader.h"
#include "nsIFile.h"
#include "nsLayoutCID.h"
#include "nsNetUtil.h"
#include "nsIObserverService.h"
#include "nsIServiceManagerUtils.h"
#include "nsIProfileChangeStatus.h"
NS_IMPL_ISUPPORTS1(nsLayoutStylesheetCache, nsIObserver)
nsresult
nsLayoutStylesheetCache::Observe(nsISupports* aSubject,
const char* aTopic,
const PRUnichar* aData)
{
if (!strcmp(aTopic, "profile-before-change")) {
mScrollbarsSheet = nsnull;
mUserContentSheet = nsnull;
mUserChromeSheet = nsnull;
}
else if (!strcmp(aTopic, "profile-do-change")) {
InitFromProfile();
}
else if (strcmp(aTopic, "chrome-flush-skin-caches") == 0 ||
strcmp(aTopic, "chrome-flush-caches") == 0) {
InitFromSkin();
}
else {
NS_NOTREACHED("Unexpected observer topic.");
}
return NS_OK;
}
nsICSSStyleSheet*
nsLayoutStylesheetCache::ScrollbarsSheet()
{
EnsureGlobal();
if (!gStyleCache)
return nsnull;
return gStyleCache->mScrollbarsSheet;
}
nsICSSStyleSheet*
nsLayoutStylesheetCache::FormsSheet()
{
EnsureGlobal();
if (!gStyleCache)
return nsnull;
return gStyleCache->mFormsSheet;
}
nsICSSStyleSheet*
nsLayoutStylesheetCache::UserContentSheet()
{
EnsureGlobal();
if (!gStyleCache)
return nsnull;
return gStyleCache->mUserContentSheet;
}
nsICSSStyleSheet*
nsLayoutStylesheetCache::UserChromeSheet()
{
EnsureGlobal();
if (!gStyleCache)
return nsnull;
return gStyleCache->mUserChromeSheet;
}
void
nsLayoutStylesheetCache::Shutdown()
{
NS_IF_RELEASE(gStyleCache);
}
nsLayoutStylesheetCache::nsLayoutStylesheetCache()
{
nsCOMPtr<nsIObserverService> obsSvc =
do_GetService("@mozilla.org/observer-service;1");
NS_ASSERTION(obsSvc, "No global observer service?");
if (obsSvc) {
obsSvc->AddObserver(this, "profile-before-change", PR_FALSE);
obsSvc->AddObserver(this, "profile-do-change", PR_FALSE);
obsSvc->AddObserver(this, "chrome-flush-skin-caches", PR_FALSE);
obsSvc->AddObserver(this, "chrome-flush-caches", PR_FALSE);
}
nsCOMPtr<nsIURI> formsSheetURI;
NS_NewURI(getter_AddRefs(formsSheetURI),
NS_LITERAL_CSTRING("resource://gre/res/platform-forms.css"));
LoadSheet(formsSheetURI, mFormsSheet);
NS_ASSERTION(mFormsSheet, "Could not load platform-forms.css stylesheet.");
InitFromProfile();
InitFromSkin();
}
nsLayoutStylesheetCache::~nsLayoutStylesheetCache()
{
gStyleCache = nsnull;
}
void
nsLayoutStylesheetCache::EnsureGlobal()
{
if (gStyleCache) return;
gStyleCache = new nsLayoutStylesheetCache();
if (!gStyleCache) return;
NS_ADDREF(gStyleCache);
}
void
nsLayoutStylesheetCache::InitFromProfile()
{
nsCOMPtr<nsIFile> contentFile;
nsCOMPtr<nsIFile> chromeFile;
NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR,
getter_AddRefs(contentFile));
if (!contentFile) {
// if we don't have a profile yet, that's OK!
return;
}
contentFile->Clone(getter_AddRefs(chromeFile));
if (!chromeFile) return;
contentFile->Append(NS_LITERAL_STRING("userContent.css"));
chromeFile->Append(NS_LITERAL_STRING("userChrome.css"));
LoadSheetFile(contentFile, mUserContentSheet);
LoadSheetFile(chromeFile, mUserChromeSheet);
}
void
nsLayoutStylesheetCache::InitFromSkin()
{
nsCOMPtr<nsIURI> scrollbarsSheetURI;
NS_NewURI(getter_AddRefs(scrollbarsSheetURI),
NS_LITERAL_CSTRING("chrome://global/skin/scrollbars.css"));
if (scrollbarsSheetURI) {
LoadSheet(scrollbarsSheetURI, mScrollbarsSheet);
}
NS_ASSERTION(mScrollbarsSheet, "Could not loade scrollbars.css stylesheet.");
}
void
nsLayoutStylesheetCache::LoadSheetFile(nsIFile* aFile, nsCOMPtr<nsICSSStyleSheet> &aSheet)
{
PRBool exists = PR_FALSE;
aFile->Exists(&exists);
if (!exists) return;
nsCOMPtr<nsIURI> uri;
NS_NewFileURI(getter_AddRefs(uri), aFile);
LoadSheet(uri, aSheet);
}
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
void
nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, nsCOMPtr<nsICSSStyleSheet> &aSheet)
{
if (!aURI) {
NS_ERROR("Null URI. Out of memory?");
return;
}
// note: CSS Loader is treated as a service here... slightly unusual,
// but within the rules.
nsCOMPtr<nsICSSLoader> cssLoader = do_GetService(kCSSLoaderCID);
if (!cssLoader) return;
cssLoader->LoadAgentSheet(aURI, getter_AddRefs(aSheet));
}
nsLayoutStylesheetCache*
nsLayoutStylesheetCache::gStyleCache = nsnull;

Просмотреть файл

@ -0,0 +1,78 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Gecko Layout
*
* The Initial Developer of the Original Code is
* Benjamin Smedberg <bsmedberg@covad.net>
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsLayoutStylesheetCache_h__
#define nsLayoutStylesheetCache_h__
#include "nsICSSStyleSheet.h"
#include "nsCOMPtr.h"
#include "nsIObserver.h"
class nsIFile;
class nsLayoutStylesheetCache
: public nsIObserver
{
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
static nsICSSStyleSheet* ScrollbarsSheet();
static nsICSSStyleSheet* FormsSheet();
static nsICSSStyleSheet* UserContentSheet();
static nsICSSStyleSheet* UserChromeSheet();
static void Shutdown();
private:
nsLayoutStylesheetCache();
~nsLayoutStylesheetCache();
static void EnsureGlobal();
void InitFromSkin();
void InitFromProfile();
static void LoadSheetFile(nsIFile* aFile, nsCOMPtr<nsICSSStyleSheet> &aSheet);
static void LoadSheet(nsIURI* aURI, nsCOMPtr<nsICSSStyleSheet> &aSheet);
static nsLayoutStylesheetCache* gStyleCache;
nsCOMPtr<nsICSSStyleSheet> mScrollbarsSheet;
nsCOMPtr<nsICSSStyleSheet> mFormsSheet;
nsCOMPtr<nsICSSStyleSheet> mUserContentSheet;
nsCOMPtr<nsICSSStyleSheet> mUserChromeSheet;
};
#endif

Просмотреть файл

@ -58,11 +58,14 @@ nsresult imgCache::Init()
imgCache* cache = new imgCache(); imgCache* cache = new imgCache();
if(!cache) return NS_ERROR_OUT_OF_MEMORY; if(!cache) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv; nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1", &rv); if (os) {
if (NS_SUCCEEDED(rv) && os) os->AddObserver(cache, "memory-pressure", PR_FALSE);
rv = os->AddObserver(cache, "memory-pressure", PR_TRUE); os->AddObserver(cache, "chrome-flush-skin-caches", PR_FALSE);
return rv; os->AddObserver(cache, "chrome-flush-caches", PR_FALSE);
}
return NS_OK;
} }
/* void clearCache (in boolean chrome); */ /* void clearCache (in boolean chrome); */
@ -301,7 +304,9 @@ PRBool imgCache::Remove(nsIURI *aKey)
NS_IMETHODIMP NS_IMETHODIMP
imgCache::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aSomeData) imgCache::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aSomeData)
{ {
if (strcmp(aTopic, "memory-pressure") == 0) if (strcmp(aTopic, "memory-pressure") == 0 ||
strcmp(aTopic, "chrome-flush-skin-caches") == 0 ||
strcmp(aTopic, "chrome-flush-caches") == 0)
ClearCache(PR_TRUE); ClearCache(PR_TRUE);
return NS_OK; return NS_OK;

Просмотреть файл

@ -38,14 +38,12 @@ REQUIRES = xpcom \
content \ content \
necko \ necko \
dom \ dom \
intl \
widget \ widget \
js \ js \
appshell \ appshell \
caps \ caps \
pref \ pref \
docshell \ docshell \
imglib2 \
xpconnect \ xpconnect \
jar \ jar \
$(NULL) $(NULL)

Просмотреть файл

@ -22,6 +22,7 @@
* Contributor(s): * Contributor(s):
* Original Author: David W. Hyatt (hyatt@netscape.com) * Original Author: David W. Hyatt (hyatt@netscape.com)
* Gagan Saksena <gagan@netscape.com> * Gagan Saksena <gagan@netscape.com>
* Benjamin Smedberg <bsmedberg@covad.net>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -37,11 +38,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/* build on macs with low memory */
#if defined(XP_MAC) && defined(MOZ_MAC_LOWMEM)
#pragma optimization_level 1
#endif
#include <string.h> #include <string.h>
#include "nsArrayEnumerator.h" #include "nsArrayEnumerator.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -52,7 +48,6 @@
#include "nsIRDFObserver.h" #include "nsIRDFObserver.h"
#include "nsIRDFRemoteDataSource.h" #include "nsIRDFRemoteDataSource.h"
#include "nsIRDFXMLSink.h" #include "nsIRDFXMLSink.h"
#include "nsCRT.h"
#include "rdf.h" #include "rdf.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsIRDFService.h" #include "nsIRDFService.h"
@ -65,7 +60,6 @@
#include "nsString.h" #include "nsString.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsIStringBundle.h"
#include "nsISimpleEnumerator.h" #include "nsISimpleEnumerator.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsIFileChannel.h" #include "nsIFileChannel.h"
@ -78,19 +72,14 @@
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsIDOMDocument.h" #include "nsIDOMDocument.h"
#include "nsIStyleSheet.h" #include "nsIStyleSheet.h"
#include "nsIHTMLCSSStyleSheet.h" #include "nsICSSLoader.h"
#include "nsIHTMLStyleSheet.h" #include "nsICSSStyleSheet.h"
#include "nsIPresShell.h" #include "nsIPresShell.h"
#include "nsIDocShell.h" #include "nsIDocShell.h"
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "nsIDocumentObserver.h" #include "nsIDocumentObserver.h"
#ifdef MOZ_XUL
#include "nsIXULDocument.h"
#include "nsIXULPrototypeCache.h"
#endif
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsLayoutCID.h" #include "nsLayoutCID.h"
#include "nsGfxCIID.h"
#include "nsIBindingManager.h" #include "nsIBindingManager.h"
#include "prio.h" #include "prio.h"
#include "nsInt64.h" #include "nsInt64.h"
@ -101,10 +90,7 @@
#include "nsIPrefService.h" #include "nsIPrefService.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIDOMElement.h" #include "nsIDOMElement.h"
#include "nsIChromeEventHandler.h"
#include "nsIContent.h"
#include "nsIDOMWindowCollection.h" #include "nsIDOMWindowCollection.h"
#include "imgICache.h"
#include "nsIAtom.h" #include "nsIAtom.h"
#include "nsStaticAtom.h" #include "nsStaticAtom.h"
#include "nsNetCID.h" #include "nsNetCID.h"
@ -112,7 +98,6 @@
#include "nsIFileURL.h" #include "nsIFileURL.h"
static char kChromePrefix[] = "chrome://"; static char kChromePrefix[] = "chrome://";
static char kUseXBLFormsPref[] = "nglayout.debug.enable_xbl_forms";
nsIAtom* nsChromeRegistry::sCPrefix; // atom for "c" nsIAtom* nsChromeRegistry::sCPrefix; // atom for "c"
#define kChromeFileName NS_LITERAL_CSTRING("chrome.rdf") #define kChromeFileName NS_LITERAL_CSTRING("chrome.rdf")
@ -123,7 +108,6 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID); static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID); static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
class nsChromeRegistry; class nsChromeRegistry;
@ -151,17 +135,12 @@ DEFINE_RDF_VOCAB(CHROME_URI, CHROME, disabled);
nsChromeRegistry::nsChromeRegistry() : mRDFService(nsnull), nsChromeRegistry::nsChromeRegistry() : mRDFService(nsnull),
mRDFContainerUtils(nsnull), mRDFContainerUtils(nsnull),
mUseXBLForms(PR_FALSE),
mInstallInitialized(PR_FALSE), mInstallInitialized(PR_FALSE),
mProfileInitialized(PR_FALSE), mProfileInitialized(PR_FALSE),
mRuntimeProvider(PR_FALSE), mRuntimeProvider(PR_FALSE),
mBatchInstallFlushes(PR_FALSE), mBatchInstallFlushes(PR_FALSE),
mSearchedForOverride(PR_FALSE) mSearchedForOverride(PR_FALSE)
{ {
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefBranch)
prefBranch->GetBoolPref(kUseXBLFormsPref, &mUseXBLForms);
mDataSourceTable = nsnull; mDataSourceTable = nsnull;
} }
@ -1046,44 +1025,15 @@ nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL,
return LoadDataSource(overlayFile, aResult, aUseProfile, nsnull); return LoadDataSource(overlayFile, aResult, aUseProfile, nsnull);
} }
nsresult NS_IMETHODIMP
nsChromeRegistry::GetStyleSheets(nsIURI *aChromeURL, nsChromeRegistry::GetStyleOverlays(nsIURI *aChromeURL,
nsISupportsArray **aResult) nsISimpleEnumerator **aResult)
{ {
*aResult = nsnull; return GetDynamicInfo(aChromeURL, PR_FALSE, aResult);
nsCOMPtr<nsISimpleEnumerator> sheets;
nsresult rv = GetDynamicInfo(aChromeURL, PR_FALSE, getter_AddRefs(sheets));
if (NS_FAILED(rv) || !sheets) return rv;
PRBool hasMore;
rv = sheets->HasMoreElements(&hasMore);
if (NS_FAILED(rv)) return rv;
while (hasMore) {
if (!*aResult) {
rv = NS_NewISupportsArray(aResult);
if (NS_FAILED(rv)) return rv;
}
nsCOMPtr<nsISupports> supp;
rv = sheets->GetNext(getter_AddRefs(supp));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIURL> url(do_QueryInterface(supp));
if (url) {
nsCOMPtr<nsICSSStyleSheet> sheet;
nsCAutoString str;
rv = url->GetSpec(str);
if (NS_FAILED(rv)) return rv;
rv = LoadStyleSheet(getter_AddRefs(sheet), str);
if (NS_FAILED(rv)) return rv;
rv = (*aResult)->AppendElement(sheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
}
sheets->HasMoreElements(&hasMore);
}
return NS_OK;
} }
NS_IMETHODIMP nsChromeRegistry::GetOverlaysForURI(nsIURI *aChromeURL, nsISimpleEnumerator **aResult) NS_IMETHODIMP
nsChromeRegistry::GetXULOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **aResult)
{ {
return GetDynamicInfo(aChromeURL, PR_TRUE, aResult); return GetDynamicInfo(aChromeURL, PR_TRUE, aResult);
} }
@ -1371,6 +1321,7 @@ static void FlushSkinBindingsForWindow(nsIDOMWindowInternal* aWindow)
document->GetBindingManager()->FlushSkinBindings(); document->GetBindingManager()->FlushSkinBindings();
} }
// XXXbsmedberg: move this to nsIWindowMediator
NS_IMETHODIMP nsChromeRegistry::RefreshSkins() NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
{ {
nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID)); nsCOMPtr<nsIWindowMediator> windowMediator(do_GetService(kWindowMediatorCID));
@ -1392,7 +1343,7 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
windowEnumerator->HasMoreElements(&more); windowEnumerator->HasMoreElements(&more);
} }
FlushCaches(); FlushSkinCaches();
windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator));
windowEnumerator->HasMoreElements(&more); windowEnumerator->HasMoreElements(&more);
@ -1411,25 +1362,15 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
} }
nsresult nsChromeRegistry::FlushCaches() void
nsChromeRegistry::FlushSkinCaches()
{ {
nsresult rv; nsCOMPtr<nsIObserverService> obsSvc =
do_GetService("@mozilla.org/observer-service;1");
NS_ASSERTION(obsSvc, "Couldn't get observer service.");
#ifdef MOZ_XUL obsSvc->NotifyObservers((nsIChromeRegistry*) this,
// Flush the style sheet cache completely. NS_CHROME_FLUSH_SKINS_TOPIC, nsnull);
nsCOMPtr<nsIXULPrototypeCache> xulCache =
do_GetService("@mozilla.org/xul/xul-prototype-cache;1", &rv);
if (NS_SUCCEEDED(rv) && xulCache)
xulCache->FlushSkinFiles();
#endif
// Flush the new imagelib image chrome cache.
nsCOMPtr<imgICache> imageCache(do_GetService("@mozilla.org/image/cache;1", &rv));
if (NS_SUCCEEDED(rv) && imageCache) {
imageCache->ClearCache(PR_TRUE);
}
return rv;
} }
static PRBool IsChromeURI(nsIURI* aURI) static PRBool IsChromeURI(nsIURI* aURI)
@ -1440,6 +1381,7 @@ static PRBool IsChromeURI(nsIURI* aURI)
return PR_FALSE; return PR_FALSE;
} }
// XXXbsmedberg: move this to windowmediator
nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow)
{ {
// Deal with our subframes first. // Deal with our subframes first.
@ -1771,7 +1713,9 @@ nsChromeRegistry::UpdateDynamicDataSources(nsIRDFDataSource *aDataSource,
NS_IMETHODIMP nsChromeRegistry::SelectSkin(const nsACString& aSkin, NS_IMETHODIMP nsChromeRegistry::SelectSkin(const nsACString& aSkin,
PRBool aUseProfile) PRBool aUseProfile)
{ {
return SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_TRUE); nsresult rv = SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_TRUE);
FlushSkinCaches();
return rv;
} }
NS_IMETHODIMP nsChromeRegistry::SelectLocale(const nsACString& aLocale, NS_IMETHODIMP nsChromeRegistry::SelectLocale(const nsACString& aLocale,
@ -1886,7 +1830,9 @@ nsChromeRegistry::GetSelectedProvider(const nsACString& aPackageName,
NS_IMETHODIMP nsChromeRegistry::DeselectSkin(const nsACString& aSkin, NS_IMETHODIMP nsChromeRegistry::DeselectSkin(const nsACString& aSkin,
PRBool aUseProfile) PRBool aUseProfile)
{ {
return SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_FALSE); nsresult rv = SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_FALSE);
FlushSkinCaches();
return rv;
} }
NS_IMETHODIMP nsChromeRegistry::DeselectLocale(const nsACString& aLocale, NS_IMETHODIMP nsChromeRegistry::DeselectLocale(const nsACString& aLocale,
@ -1979,9 +1925,6 @@ nsChromeRegistry::SetProvider(const nsACString& aProvider,
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
if (aProvider.Equals("skin") && mScrollbarSheet)
LoadStyleSheet(getter_AddRefs(mScrollbarSheet), NS_LITERAL_CSTRING("chrome://global/skin/scrollbars.css"));
return NS_OK; return NS_OK;
} }
@ -2866,30 +2809,26 @@ nsChromeRegistry::GetInstallRoot(nsIFile** aFileURL)
return NS_GetSpecialDirectory(NS_APP_CHROME_DIR, aFileURL); return NS_GetSpecialDirectory(NS_APP_CHROME_DIR, aFileURL);
} }
void
nsChromeRegistry::FlushAllCaches()
{
nsCOMPtr<nsIObserverService> obsSvc =
do_GetService("@mozilla.org/observer-service;1");
NS_ASSERTION(obsSvc, "Couldn't get observer service.");
obsSvc->NotifyObservers((nsIChromeRegistry*) this,
NS_CHROME_FLUSH_TOPIC, nsnull);
}
// xxxbsmedberg Move me to nsIWindowMediator
NS_IMETHODIMP NS_IMETHODIMP
nsChromeRegistry::ReloadChrome() nsChromeRegistry::ReloadChrome()
{ {
FlushAllCaches();
// Do a reload of all top level windows. // Do a reload of all top level windows.
nsresult rv = NS_OK; nsresult rv = NS_OK;
#ifdef MOZ_XUL
// Flush the cache completely.
nsCOMPtr<nsIXULPrototypeCache> xulCache =
do_GetService("@mozilla.org/xul/xul-prototype-cache;1", &rv);
if (NS_SUCCEEDED(rv) && xulCache) {
rv = xulCache->Flush();
if (NS_FAILED(rv)) return rv;
}
#endif
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(kStringBundleServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = bundleService->FlushBundles();
if (NS_FAILED(rv)) return rv;
}
// Get the window mediator // Get the window mediator
nsCOMPtr<nsIWindowMediator> windowMediator = do_GetService(kWindowMediatorCID, &rv); nsCOMPtr<nsIWindowMediator> windowMediator = do_GetService(kWindowMediatorCID, &rv);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
@ -2990,133 +2929,14 @@ nsChromeRegistry::AddToCompositeDataSource(PRBool aUseProfile)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsChromeRegistry::GetAgentSheets(nsIDocShell* aDocShell, nsISupportsArray **aResult)
{
nsresult rv = NS_NewISupportsArray(aResult);
// Determine the agent sheets that should be loaded.
if (!mScrollbarSheet)
LoadStyleSheet(getter_AddRefs(mScrollbarSheet), NS_LITERAL_CSTRING("chrome://global/skin/scrollbars.css"));
if (!mFormSheet) {
nsCAutoString sheetURL;
GetFormSheetURL(sheetURL);
LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL);
}
PRBool shouldOverride = PR_FALSE;
nsCOMPtr<nsIChromeEventHandler> chromeHandler;
aDocShell->GetChromeEventHandler(getter_AddRefs(chromeHandler));
if (chromeHandler) {
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(chromeHandler));
if (elt) {
nsAutoString sheets;
elt->GetAttribute(NS_LITERAL_STRING("usechromesheets"), sheets);
if (!sheets.IsEmpty()) {
// Construct the URIs and try to load each sheet.
char* str = ToNewCString(sheets);
char* newStr;
char* token = nsCRT::strtok( str, ", ", &newStr );
while (token) {
nsCOMPtr<nsIContent> content(do_QueryInterface(elt));
nsCOMPtr<nsIDocument> doc = content->GetDocument();
nsCOMPtr<nsIURI> url;
rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(token),
nsnull, doc->GetDocumentURI());
nsCOMPtr<nsICSSStyleSheet> sheet;
// The CSSLoader handles all the prototype cache stuff for
// us as needed.
LoadStyleSheetWithURL(url, getter_AddRefs(sheet));
if (sheet) {
// A sheet was loaded successfully. We will *not* use the default
// set of agent sheets (which consists solely of the scrollbar sheet).
shouldOverride = PR_TRUE;
(*aResult)->AppendElement(sheet);
}
// Advance to the next sheet URL.
token = nsCRT::strtok( newStr, ", ", &newStr );
}
nsMemory::Free(str);
}
}
}
if (mScrollbarSheet && !shouldOverride)
(*aResult)->AppendElement(mScrollbarSheet);
if (mFormSheet)
(*aResult)->AppendElement(mFormSheet);
return NS_OK;
}
NS_IMETHODIMP
nsChromeRegistry::GetUserSheets(PRBool aIsChrome, nsISupportsArray **aResult)
{
nsresult rv;
if ((aIsChrome && mUserChromeSheet) || (!aIsChrome && mUserContentSheet)) {
rv = NS_NewISupportsArray(aResult);
if (NS_FAILED(rv)) return rv;
if (aIsChrome && mUserChromeSheet) {
rv = (*aResult)->AppendElement(mUserChromeSheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
}
if (!aIsChrome && mUserContentSheet) {
rv = (*aResult)->AppendElement(mUserContentSheet) ? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
}
}
return NS_OK;
}
nsresult nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsACString& aURL)
{
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
if (NS_FAILED(rv)) return rv;
rv = LoadStyleSheetWithURL(uri, aSheet);
return rv;
}
nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet) nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet)
{ {
*aSheet = nsnull; *aSheet = nsnull;
nsresult rv = NS_OK;
if (!mCSSLoader) {
mCSSLoader = do_CreateInstance(kCSSLoaderCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
if (mCSSLoader)
rv = mCSSLoader->LoadAgentSheet(aURL, aSheet);
return rv;
}
nsresult nsChromeRegistry::GetUserSheetURL(PRBool aIsChrome, nsACString & aURL) nsCOMPtr<nsICSSLoader> cssLoader = do_GetService(kCSSLoaderCID);
{ if (!cssLoader) return NS_ERROR_FAILURE;
aURL = mProfileRoot;
if (aIsChrome)
aURL.Append("userChrome.css");
else aURL.Append("userContent.css");
return NS_OK; return cssLoader->LoadAgentSheet(aURL, aSheet);
}
nsresult nsChromeRegistry::GetFormSheetURL(nsACString& aURL)
{
aURL = mUseXBLForms ? "chrome://forms/skin/forms.css" : "resource://gre/res/platform-forms.css";
return NS_OK;
} }
nsresult nsChromeRegistry::LoadInstallDataSource() nsresult nsChromeRegistry::LoadInstallDataSource()
@ -3158,30 +2978,8 @@ nsresult nsChromeRegistry::LoadProfileDataSource()
} }
} }
// We have to flush the chrome cache! // We have to flush the chrome skin cache...
rv = FlushCaches(); FlushAllCaches();
if (NS_FAILED(rv)) return rv;
rv = LoadStyleSheet(getter_AddRefs(mScrollbarSheet), NS_LITERAL_CSTRING("chrome://global/skin/scrollbars.css"));
// This must always be the last line of profile initialization!
nsCAutoString sheetURL;
rv = GetUserSheetURL(PR_TRUE, sheetURL);
if (NS_FAILED(rv)) return rv;
if (!sheetURL.IsEmpty()) {
(void)LoadStyleSheet(getter_AddRefs(mUserChromeSheet), sheetURL);
// it's ok to not have a user.css file
}
rv = GetUserSheetURL(PR_FALSE, sheetURL);
if (NS_FAILED(rv)) return rv;
if (!sheetURL.IsEmpty()) {
(void)LoadStyleSheet(getter_AddRefs(mUserContentSheet), sheetURL);
// it's ok not to have a userContent.css or userChrome.css file
}
rv = GetFormSheetURL(sheetURL);
if (NS_FAILED(rv)) return rv;
if (!sheetURL.IsEmpty())
(void)LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL);
} }
return NS_OK; return NS_OK;
} }
@ -3485,25 +3283,20 @@ NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const char *aTopi
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (!nsCRT::strcmp("profile-before-change", aTopic)) { if (!strcmp("profile-before-change", aTopic)) {
mChromeDataSource = nsnull; mChromeDataSource = nsnull;
mScrollbarSheet = mFormSheet = nsnull;
mInstallInitialized = mProfileInitialized = PR_FALSE; mInstallInitialized = mProfileInitialized = PR_FALSE;
if (!nsCRT::strcmp("shutdown-cleanse", NS_ConvertUCS2toUTF8(someData).get())) { if (!strcmp("shutdown-cleanse", NS_ConvertUCS2toUTF8(someData).get())) {
nsCOMPtr<nsIFile> userChromeDir; nsCOMPtr<nsIFile> userChromeDir;
rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir)); rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir));
if (NS_SUCCEEDED(rv) && userChromeDir) if (NS_SUCCEEDED(rv) && userChromeDir)
rv = userChromeDir->Remove(PR_TRUE); rv = userChromeDir->Remove(PR_TRUE);
} }
} }
else if (!nsCRT::strcmp("profile-after-change", aTopic)) { else if (!strcmp("profile-after-change", aTopic)) {
if (!mProfileInitialized) { if (!mProfileInitialized) {
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefBranch)
prefBranch->GetBoolPref(kUseXBLFormsPref, &mUseXBLForms);
rv = LoadProfileDataSource(); rv = LoadProfileDataSource();
} }
} }

Просмотреть файл

@ -36,11 +36,12 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
class nsIAtom;
class nsICSSStyleSheet;
class nsIRDFService; class nsIRDFService;
class nsIRDFDataSource; class nsIRDFDataSource;
class nsIRDFResource; class nsIRDFResource;
class nsIRDFNode; class nsIRDFNode;
class nsICSSLoader;
class nsISimpleEnumerator; class nsISimpleEnumerator;
class nsSupportsHashtable; class nsSupportsHashtable;
class nsIRDFContainer; class nsIRDFContainer;
@ -51,12 +52,10 @@ class nsIDocument;
#include "nsIChromeRegistry.h" #include "nsIChromeRegistry.h"
#include "nsIXULOverlayProvider.h" #include "nsIXULOverlayProvider.h"
#include "nsIRDFCompositeDataSource.h" #include "nsIRDFCompositeDataSource.h"
#include "nsICSSStyleSheet.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "nsString.h" #include "nsString.h"
#include "nsIZipReader.h" #include "nsIZipReader.h"
#include "nsICSSLoader.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
// for component registration // for component registration
@ -116,16 +115,13 @@ protected:
PRBool aIsOverlay, PRBool PRBool aIsOverlay, PRBool
aUseProfile, PRBool aRemove); aUseProfile, PRBool aRemove);
nsresult LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsACString & aURL);
nsresult LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet); nsresult LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet** aSheet);
nsresult GetUserSheetURL(PRBool aIsChrome, nsACString & aURL);
nsresult GetFormSheetURL(nsACString& aURL);
nsresult LoadInstallDataSource(); nsresult LoadInstallDataSource();
nsresult LoadProfileDataSource(); nsresult LoadProfileDataSource();
nsresult FlushCaches(); void FlushSkinCaches();
void FlushAllCaches();
private: private:
nsresult LoadDataSource(const nsACString &aFileName, nsresult LoadDataSource(const nsACString &aFileName,
@ -255,22 +251,12 @@ protected:
nsCOMPtr<nsIRDFResource> mPackageVersion; nsCOMPtr<nsIRDFResource> mPackageVersion;
nsCOMPtr<nsIRDFResource> mDisabled; nsCOMPtr<nsIRDFResource> mDisabled;
// Style Sheets
nsCOMPtr<nsICSSStyleSheet> mScrollbarSheet;
nsCOMPtr<nsICSSStyleSheet> mUserChromeSheet;
nsCOMPtr<nsICSSStyleSheet> mUserContentSheet;
nsCOMPtr<nsICSSStyleSheet> mFormSheet;
nsCOMPtr<nsICSSLoader> mCSSLoader;
nsCOMPtr<nsIZipReader> mOverrideJAR; nsCOMPtr<nsIZipReader> mOverrideJAR;
nsCString mOverrideJARURL; nsCString mOverrideJARURL;
// useful atoms - these are static atoms, so don't use nsCOMPtr // useful atoms - these are static atoms, so don't use nsCOMPtr
static nsIAtom* sCPrefix; // "c" static nsIAtom* sCPrefix; // "c"
PRBool mUseXBLForms;
PRPackedBool mInstallInitialized; PRPackedBool mInstallInitialized;
PRPackedBool mProfileInitialized; PRPackedBool mProfileInitialized;
@ -283,4 +269,3 @@ protected:
// make sure we only look once for the JAR override // make sure we only look once for the JAR override
PRPackedBool mSearchedForOverride; PRPackedBool mSearchedForOverride;
}; };