From 7561fa5d5b1936f654014ea1833fe0704438387a Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Tue, 21 Sep 2004 20:19:48 +0000 Subject: [PATCH] Merge bug 246014 from the aviary branch, splitting nsIXULChromeRegistry into a separate piece for seamonkey-only methods. Original Firefox patch r=bryner sr=ben seamonkey merge r+sr=jst --- Makefile.in | 33 +- allmakefiles.sh | 1 + browser/app/Makefile.in | 2 + browser/app/profile/firefox.js | 4 +- chrome/src/Makefile.in | 1 + chrome/src/nsChromeProtocolHandler.cpp | 43 +- chrome/src/nsChromeRegistry.cpp | 1569 ++++------------- chrome/src/nsChromeRegistry.h | 93 +- content/base/public/nsIChromeRegistry.idl | 56 +- mail/app/profile/all-thunderbird.js | 3 +- profile/src/Makefile.in | 1 + profile/src/nsProfile.cpp | 10 +- rdf/chrome/Makefile.in | 3 +- rdf/chrome/public/Makefile.in | 48 + rdf/chrome/public/nsIChromeRegistrySea.idl | 92 + rdf/chrome/src/nsChromeRegistry.cpp | 3 +- rdf/chrome/src/nsChromeRegistry.h | 4 +- .../mozapps/extensions/content/extensions.js | 20 +- toolkit/xre/nsAppRunner.cpp | 136 -- xpfe/bootstrap/Makefile.in | 1 + xpfe/bootstrap/nsAppRunner.cpp | 12 +- xpfe/browser/resources/content/navigator.js | 4 +- .../resources/content/nsPrefWindow.js | 2 +- .../resources/content/pref-themes.js | 10 +- xpinstall/packager/packages-os2 | 1 + xpinstall/packager/packages-unix | 1 + xpinstall/packager/packages-win | 1 + xpinstall/src/Makefile.in | 1 + xpinstall/src/nsSoftwareUpdateRun.cpp | 27 +- 29 files changed, 656 insertions(+), 1526 deletions(-) create mode 100644 rdf/chrome/public/Makefile.in create mode 100644 rdf/chrome/public/nsIChromeRegistrySea.idl diff --git a/Makefile.in b/Makefile.in index e62638c80c79..a4d15c114f5d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -59,9 +59,6 @@ default: $(SUBMAKEFILES) $(MAKE) tier_1 $(MAKE) tier_2 $(MAKE) tier_9 -ifdef MOZ_PSM - $(MAKE) tier_40 -endif $(MAKE) tier_50 ifdef MOZ_JSDEBUGGER $(MAKE) tier_93 @@ -83,7 +80,6 @@ DIRS = \ $(tier_1_dirs) \ $(tier_2_dirs) \ $(tier_9_dirs) \ - $(tier_40_dirs) \ $(tier_50_dirs) \ $(NULL) @@ -206,7 +202,6 @@ tier_9_dirs += \ xpfe/components/shistory \ docshell \ webshell \ - profile \ embedding \ editor \ $(NULL) @@ -227,12 +222,8 @@ tier_9_dirs += other-licenses/branding/firefox endif endif -tier_9_dirs += \ - xpfe/appshell \ - xpfe/browser/public \ - xpfe/components/sidebar/public \ - xpfe/components/xremote/public \ - $(NULL) +# profile and chrome should be in tier 50, but are required by xpfe/appshell +# This is a temporary hack until the app-startup patch lands. ifdef MOZ_XUL ifdef MOZ_XUL_APP @@ -242,6 +233,15 @@ tier_9_dirs += rdf/chrome endif endif +tier_9_dirs += profile + +tier_9_dirs += \ + xpfe/appshell \ + xpfe/browser/public \ + xpfe/components/sidebar/public \ + xpfe/components/xremote/public \ + $(NULL) + ifdef ACCESSIBILITY tier_9_dirs += accessible endif @@ -260,17 +260,14 @@ tier_9_dirs += toolkit/components/gnome endif endif -# -# tier 40 - security -# -ifdef MOZ_PSM -tier_40_dirs += security/manager -endif - # # tier 50 - xpfe & toolkit # +ifdef MOZ_PSM +tier_50_dirs += security/manager +endif + # This must preceed xpfe ifdef MOZ_JPROF tier_50_dirs += tools/jprof diff --git a/allmakefiles.sh b/allmakefiles.sh index 58f55c99e44c..44fc69aee7e0 100755 --- a/allmakefiles.sh +++ b/allmakefiles.sh @@ -479,6 +479,7 @@ rdf/base/idl/Makefile rdf/base/public/Makefile rdf/base/src/Makefile rdf/chrome/Makefile +rdf/chrome/public/Makefile rdf/chrome/build/Makefile rdf/chrome/src/Makefile rdf/chrome/tools/Makefile diff --git a/browser/app/Makefile.in b/browser/app/Makefile.in index 8a506c1165e5..437381a33490 100644 --- a/browser/app/Makefile.in +++ b/browser/app/Makefile.in @@ -63,6 +63,8 @@ REQUIRES = \ CPPSRCS = nsBrowserApp.cpp +LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre + ifdef BUILD_STATIC_LIBS STATIC_COMPONENTS_LINKER_PATH = -L$(DIST)/lib/components endif diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 5f24537c68f0..306112f8e574 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -104,8 +104,8 @@ pref("update.extensions.count", 0); pref("keyword.enabled", true); pref("keyword.URL", "http://www.google.com/search?btnI=I%27m+Feeling+Lucky&ie=UTF-8&oe=UTF-8&q="); -pref("general.useragent.locale", "chrome://global/locale/intl.properties"); -pref("general.useragent.contentlocale", "chrome://browser-region/locale/region.properties"); +#expand pref("general.useragent.locale", "@AB_CD@"); +pref("general.skins.selectedSkin", "classic/1.0"); pref("general.useragent.vendor", "Firefox"); pref("general.useragent.vendorSub", #expand __APP_VERSION__ diff --git a/chrome/src/Makefile.in b/chrome/src/Makefile.in index 96503f5dc919..30333c75aa22 100644 --- a/chrome/src/Makefile.in +++ b/chrome/src/Makefile.in @@ -43,6 +43,7 @@ REQUIRES = xpcom \ gfx \ layout \ content \ + locale \ necko \ dom \ widget \ diff --git a/chrome/src/nsChromeProtocolHandler.cpp b/chrome/src/nsChromeProtocolHandler.cpp index 23aca0b8f6e0..0ed910d7086f 100644 --- a/chrome/src/nsChromeProtocolHandler.cpp +++ b/chrome/src/nsChromeProtocolHandler.cpp @@ -591,8 +591,14 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, } nsCAutoString spec; - reg->ConvertChromeURL(aURI, spec); - if (NS_FAILED(rv)) return rv; + rv = reg->ConvertChromeURL(aURI, spec); + if (NS_FAILED(rv)) { +#ifdef DEBUG + aURI->GetSpec(spec); + printf("Couldn't convert chrome URL: %s\n", spec.get()); +#endif + return rv; + } nsCOMPtr ioServ(do_GetIOService(&rv)); if (NS_FAILED(rv)) return rv; @@ -605,15 +611,30 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, if (NS_FAILED(rv)) return rv; // XXX Will be removed someday when we handle remote chrome. - nsCOMPtr fileChan; - nsCOMPtr jarChan; - fileChan = do_QueryInterface(result); - if (!fileChan) - jarChan = do_QueryInterface(result); - if (!fileChan && !jarChan) { - NS_WARNING("Remote chrome not allowed! Only file:, resource:, and jar: are valid.\n"); - result = nsnull; - return NS_ERROR_FAILURE; + nsCOMPtr fileChan + (do_QueryInterface(result)); + if (fileChan) { +#ifdef DEBUG + nsCOMPtr file; + fileChan->GetFile(getter_AddRefs(file)); + + PRBool exists = PR_FALSE; + file->Exists(&exists); + if (!exists) { + nsCAutoString path; + file->GetNativePath(path); + printf("Chrome file doesn't exist: %s\n", path.get()); + } +#endif + } + else { + nsCOMPtr jarChan + (do_QueryInterface(result)); + if (!jarChan) { + NS_WARNING("Remote chrome not allowed! Only file:, resource:, and jar: are valid.\n"); + result = nsnull; + return NS_ERROR_FAILURE; + } } // Make sure that the channel remembers where it was diff --git a/chrome/src/nsChromeRegistry.cpp b/chrome/src/nsChromeRegistry.cpp index fb415090a220..54bf4952ab45 100644 --- a/chrome/src/nsChromeRegistry.cpp +++ b/chrome/src/nsChromeRegistry.cpp @@ -85,8 +85,9 @@ #include "nsIDirectoryService.h" #include "nsILocalFile.h" #include "nsAppDirectoryServiceDefs.h" -#include "nsIPrefBranch.h" #include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsIPrefBranchInternal.h" #include "nsIObserverService.h" #include "nsIDOMElement.h" #include "nsIDOMWindowCollection.h" @@ -95,6 +96,18 @@ #include "nsNetCID.h" #include "nsIJARURI.h" #include "nsIFileURL.h" +#include "nsILocaleService.h" +#include "nsICmdLineService.h" +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" + +#define UILOCALE_CMD_LINE_ARG "-UILocale" + +#define MATCH_OS_LOCALE_PREF "intl.locale.matchOS" +#define SELECTED_LOCALE_PREF "general.useragent.locale" +#define SELECTED_SKIN_PREF "general.skins.selectedSkin" +#define DSS_SKIN_TO_SELECT "extensions.lastSelectedSkin" +#define DSS_SWITCH_PENDING "extensions.dss.switchPending" static char kChromePrefix[] = "chrome://"; nsIAtom* nsChromeRegistry::sCPrefix; // atom for "c" @@ -107,15 +120,12 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID); static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID); - -class nsChromeRegistry; +static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); nsIChromeRegistry* gChromeRegistry = nsnull; #define CHROME_URI "http://www.mozilla.org/rdf/chrome#" -DEFINE_RDF_VOCAB(CHROME_URI, CHROME, selectedSkin); -DEFINE_RDF_VOCAB(CHROME_URI, CHROME, selectedLocale); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, baseURL); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, packages); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, package); @@ -125,10 +135,8 @@ DEFINE_RDF_VOCAB(CHROME_URI, CHROME, locType); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, allowScripts); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, hasOverlays); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, hasStylesheets); -DEFINE_RDF_VOCAB(CHROME_URI, CHROME, skinVersion); -DEFINE_RDF_VOCAB(CHROME_URI, CHROME, localeVersion); -DEFINE_RDF_VOCAB(CHROME_URI, CHROME, packageVersion); DEFINE_RDF_VOCAB(CHROME_URI, CHROME, disabled); +DEFINE_RDF_VOCAB(CHROME_URI, CHROME, platformPackage); //////////////////////////////////////////////////////////////////////////////// @@ -136,9 +144,7 @@ nsChromeRegistry::nsChromeRegistry() : mRDFService(nsnull), mRDFContainerUtils(nsnull), mInstallInitialized(PR_FALSE), mProfileInitialized(PR_FALSE), - mRuntimeProvider(PR_FALSE), - mBatchInstallFlushes(PR_FALSE), - mSearchedForOverride(PR_FALSE) + mBatchInstallFlushes(PR_FALSE) { mDataSourceTable = nsnull; } @@ -198,6 +204,22 @@ NS_IMPL_THREADSAFE_ISUPPORTS5(nsChromeRegistry, //////////////////////////////////////////////////////////////////////////////// // nsIChromeRegistry methods: +static nsresult +getUILangCountry(nsACString& aUILang) +{ + nsresult rv; + + nsCOMPtr localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString uiLang; + rv = localeService->GetLocaleComponentForUserAgent(uiLang); + NS_ENSURE_SUCCESS(rv, rv); + + CopyUTF16toUTF8(uiLang, aUILang); + return NS_OK; +} + nsresult nsChromeRegistry::Init() { @@ -211,22 +233,21 @@ nsChromeRegistry::Init() { "NC", nsnull }, { "baseURL", nsnull}, { "allowScripts", nsnull }, - { "skinVersion", nsnull }, { "package", nsnull }, { "packages", nsnull }, { "locType", nsnull }, { "displayName", nsnull }, { "author", nsnull }, - { "localeVersion", nsnull }, { "localeType", nsnull }, - { "selectedLocale", nsnull }, - { "selectedSkin", nsnull }, { "hasOverlays", nsnull }, { "previewURL", nsnull }, }; NS_RegisterStaticAtoms(atoms, NS_ARRAY_LENGTH(atoms)); + if (!mSelectedLocales.Init()) return NS_ERROR_FAILURE; + if (!mSelectedSkins.Init()) return NS_ERROR_FAILURE; + gChromeRegistry = this; nsresult rv; @@ -240,73 +261,109 @@ nsChromeRegistry::Init() (nsISupports**)&mRDFContainerUtils); NS_ENSURE_SUCCESS(rv, rv); - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_selectedSkin), - getter_AddRefs(mSelectedSkin)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_selectedLocale), - getter_AddRefs(mSelectedLocale)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_baseURL), - getter_AddRefs(mBaseURL)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_packages), - getter_AddRefs(mPackages)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_package), - getter_AddRefs(mPackage)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_name), - getter_AddRefs(mName)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_image), - getter_AddRefs(mImage)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_locType), - getter_AddRefs(mLocType)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_allowScripts), - getter_AddRefs(mAllowScripts)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_hasOverlays), - getter_AddRefs(mHasOverlays)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_hasStylesheets), - getter_AddRefs(mHasStylesheets)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_skinVersion), - getter_AddRefs(mSkinVersion)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_localeVersion), - getter_AddRefs(mLocaleVersion)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_packageVersion), - getter_AddRefs(mPackageVersion)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - - rv = mRDFService->GetResource(nsDependentCString(kURICHROME_disabled), - getter_AddRefs(mDisabled)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); + rv = mRDFService->GetResource(nsDependentCString(kURICHROME_baseURL), + getter_AddRefs(mBaseURL)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_packages), + getter_AddRefs(mPackages)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_package), + getter_AddRefs(mPackage)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_name), + getter_AddRefs(mName)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_image), + getter_AddRefs(mImage)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_locType), + getter_AddRefs(mLocType)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_allowScripts), + getter_AddRefs(mAllowScripts)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_hasOverlays), + getter_AddRefs(mHasOverlays)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_hasStylesheets), + getter_AddRefs(mHasStylesheets)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_disabled), + getter_AddRefs(mDisabled)); + rv |= mRDFService->GetResource(nsDependentCString(kURICHROME_platformPackage), + getter_AddRefs(mPlatformPackage)); + NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); + do_GetService("@mozilla.org/observer-service;1"); if (observerService) { observerService->AddObserver(this, "profile-before-change", PR_TRUE); observerService->AddObserver(this, "profile-after-change", PR_TRUE); } + mSelectedLocale = NS_LITERAL_CSTRING("en-US"); + mSelectedSkin = NS_LITERAL_CSTRING("classic/1.0"); + + nsCOMPtr prefs (do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (!prefs) { + NS_WARNING("Could not get pref service!"); + } + + nsXPIDLCString uiLocale; + PRBool useLocalePref = PR_TRUE; + + nsCOMPtr cmdLineArgs + (do_GetService("@mozilla.org/appshell/commandLineService;1")); + + if (cmdLineArgs) + cmdLineArgs->GetCmdLineValue(UILOCALE_CMD_LINE_ARG, getter_Copies(uiLocale)); + + if (uiLocale) { + useLocalePref = PR_FALSE; + mSelectedLocale = uiLocale; + } + else if (prefs) { + // check the pref first + PRBool matchOS = PR_FALSE; + rv = prefs->GetBoolPref(MATCH_OS_LOCALE_PREF, &matchOS); + + // match os locale + if (NS_SUCCEEDED(rv) && matchOS) { + // compute lang and region code only when needed! + rv = getUILangCountry(uiLocale); + if (NS_SUCCEEDED(rv)) { + useLocalePref = PR_FALSE; + mSelectedLocale = uiLocale; + } + } + } + + PRBool useSkinPref = PR_TRUE; + + nsCOMPtr lookAndFeel (do_GetService(kLookAndFeelCID)); + if (lookAndFeel) { + PRInt32 useAccessibilityTheme = 0; + + lookAndFeel->GetMetric(nsILookAndFeel::eMetric_UseAccessibilityTheme, + useAccessibilityTheme); + + if (useAccessibilityTheme) { + useSkinPref = PR_FALSE; + } + } + + if (prefs) { + nsXPIDLCString provider; + + if (useSkinPref) { + rv = prefs->GetCharPref(SELECTED_SKIN_PREF, getter_Copies(provider)); + if (NS_SUCCEEDED(rv)) + mSelectedSkin = provider; + + rv = prefs->AddObserver(SELECTED_SKIN_PREF, this, PR_TRUE); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't add skin-switching observer!"); + } + + if (useLocalePref) { + rv = prefs->GetCharPref(SELECTED_LOCALE_PREF, getter_Copies(provider)); + if (NS_SUCCEEDED(rv)) + mSelectedLocale = provider; + + prefs->AddObserver(SELECTED_LOCALE_PREF, this, PR_TRUE); + } + } + CheckForNewChrome(); return NS_OK; @@ -415,41 +472,6 @@ SplitURL(nsIURI *aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCStrin return NS_OK; } -static nsresult -GetBaseURLFile(const nsACString& aBaseURL, nsIFile** aFile) -{ - NS_ENSURE_ARG_POINTER(aFile); - *aFile = nsnull; - - nsresult rv; - nsCOMPtr ioServ(do_GetService(NS_IOSERVICE_CONTRACTID, &rv)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr uri; - rv = ioServ->NewURI(aBaseURL, nsnull, nsnull, getter_AddRefs(uri)); - if (NS_FAILED(rv)) return rv; - - // Loop, jar: URIs can nest (e.g. jar:jar:A.jar!B.jar!C.xml). - // Often, however, we have jar:resource:/chrome/A.jar!C.xml. - nsCOMPtr jarURI; - while ((jarURI = do_QueryInterface(uri)) != nsnull) - jarURI->GetJARFile(getter_AddRefs(uri)); - - // Here we must have a URL of the form resource:/chrome/A.jar - // or file:/some/path/to/A.jar. - nsCOMPtr fileURL(do_QueryInterface(uri)); - if (fileURL) { - nsCOMPtr file; - fileURL->GetFile(getter_AddRefs(file)); - if (file) { - NS_ADDREF(*aFile = file); - return NS_OK; - } - } - NS_ERROR("GetBaseURLFile() failed. Remote chrome?"); - return NS_ERROR_FAILURE; -} - NS_IMETHODIMP nsChromeRegistry::Canonify(nsIURI* aChromeURI) { @@ -511,11 +533,8 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, nsACString& aResult) nsCAutoString finalURL; - rv = GetOverrideURL(package, provider, remaining, finalURL); - if (NS_SUCCEEDED(rv)) - return NS_OK; - rv = GetBaseURL(package, provider, finalURL); + if (NS_FAILED(rv)) { #ifdef DEBUG nsCAutoString msg("chrome: failed to get base url"); @@ -535,408 +554,252 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, nsACString& aResult) return NS_OK; } +nsresult +nsChromeRegistry::GetSelectedLocale(const nsACString& aPackage, nsACString& aLocale) +{ + nsresult rv; + + // Try for the profile data source first because it + // will load the install data source as well. + if (!mProfileInitialized) { + rv = LoadProfileDataSource(); + if (NS_FAILED(rv)) return rv; + } + if (!mInstallInitialized) { + rv = LoadInstallDataSource(); + if (NS_FAILED(rv)) return rv; + } + + nsCOMPtr resource; + nsCOMPtr packageResource; + + rv = FindProvider(aPackage, NS_LITERAL_CSTRING("locale"), resource, packageResource); + if (NS_FAILED(rv)) return rv; + + // selectedProvider.mURI now looks like "urn:mozilla:locale:ja-JP:navigator" + const char *uri; + resource->GetValueConst(&uri); + + // trim down to "urn:mozilla:locale:ja-JP" + nsCAutoString packageStr(":"); + packageStr += aPackage; + + nsCAutoString ustr(uri); + PRInt32 pos = ustr.RFind(packageStr); + nsCAutoString urn; + ustr.Left(urn, pos); + + rv = GetResource(urn, getter_AddRefs(resource)); + NS_ENSURE_SUCCESS(rv, rv); + + // From this resource, follow the "name" arc. + return FollowArc(mChromeDataSource, aLocale, resource, mName); +} + nsresult nsChromeRegistry::GetBaseURL(const nsACString& aPackage, const nsACString& aProvider, nsACString& aBaseURL) { + nsresult rv; nsCOMPtr resource; + nsCOMPtr packageResource; + + rv = FindProvider(aPackage, aProvider, resource, packageResource); + if (NS_FAILED(rv)) return rv; + + // From this resource, follow the "baseURL" arc. + rv = FollowArc(mChromeDataSource, aBaseURL, resource, mBaseURL); + NS_ENSURE_SUCCESS(rv, rv); + + nsCAutoString isPlatformPackage; + rv = FollowArc(mChromeDataSource, isPlatformPackage, packageResource, mPlatformPackage); + if (NS_FAILED(rv) || !isPlatformPackage.Equals("true")) return NS_OK; + +#if defined(XP_WIN) || defined(XP_OS2) + aBaseURL.Append("win/"); +#elif defined(XP_MACOSX) + aBaseURL.Append("mac/"); +#else + aBaseURL.Append("unix/"); +#endif + + return NS_OK; +} + +nsresult +nsChromeRegistry::FindProvider(const nsACString& aPackage, const nsACString& aProvider, + nsCOMPtr &aProviderResource, + nsCOMPtr &aPackageResource) +{ + nsresult rv; nsCAutoString resourceStr("urn:mozilla:package:"); resourceStr += aPackage; // Obtain the resource. - nsresult rv = NS_OK; - nsCOMPtr packageResource; - rv = GetResource(resourceStr, getter_AddRefs(packageResource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } + rv = GetResource(resourceStr, getter_AddRefs(aPackageResource)); + NS_ENSURE_SUCCESS(rv, rv); - // Follow the "selectedSkin" or "selectedLocale" arc. - nsCOMPtr arc; - if (aProvider.EqualsLiteral("skin")) { - arc = mSelectedSkin; - } - else if (aProvider.EqualsLiteral("locale")) { - arc = mSelectedLocale; - } - else - // We're a package. - resource = packageResource; - - if (arc) { - - nsCOMPtr selectedProvider; - if (NS_FAILED(rv = mChromeDataSource->GetTarget(packageResource, arc, PR_TRUE, getter_AddRefs(selectedProvider)))) { - NS_ERROR("Unable to obtain the provider."); - return rv; - } - - resource = do_QueryInterface(selectedProvider); - - if (resource) { - PRBool providerOK; - rv = VerifyCompatibleProvider(packageResource, resource, arc, &providerOK); + if (aProvider.Equals(NS_LITERAL_CSTRING("skin"))) { + mSelectedSkins.Get(aPackage, getter_AddRefs(aProviderResource)); + if (!aProviderResource) { + rv = FindSubProvider(aPackage, aProvider, aProviderResource); if (NS_FAILED(rv)) return rv; - if (!providerOK) { - // We had a selection but it was incompatible or not present. - // That selection may have come from the profile, so check only - // the part of the datasource in the install. (If this succeeds, - // we won't remember the choice, either, in case the user - // switches back to a build where this theme does work.) - if (NS_FAILED(rv = mInstallDirChromeDataSource->GetTarget(packageResource, arc, PR_TRUE, getter_AddRefs(selectedProvider)))) { - NS_ERROR("Unable to obtain the provider."); - return rv; - } - resource = do_QueryInterface(selectedProvider); - if (resource) { - rv = VerifyCompatibleProvider(packageResource, resource, arc, &providerOK); - if (NS_FAILED(rv)) return rv; - if (!providerOK) - selectedProvider = nsnull; - } - } - } - - if (!selectedProvider) { - // FindProvider will attempt to auto-select a version-compatible provider (skin). If none - // exist it will return nsnull in the selectedProvider variable. - FindProvider(aPackage, aProvider, arc, getter_AddRefs(selectedProvider)); - resource = do_QueryInterface(selectedProvider); - } - - if (!selectedProvider) - return rv; - - if (!resource) - return NS_ERROR_FAILURE; - } - - // From this resource, follow the "baseURL" arc. - return FollowArc(mChromeDataSource, aBaseURL, resource, mBaseURL); -} - -nsresult -nsChromeRegistry::GetOverrideURL(const nsACString& aPackage, - const nsACString& aProvider, - const nsACString& aPath, - nsACString& aResult) -{ - nsresult rv = InitOverrideJAR(); - if (NS_FAILED(rv)) return rv; - - // ok, if we get here, we have an override JAR - - aResult.SetCapacity(mOverrideJARURL.Length() + - aPackage.Length() + - aProvider.Length() + - aPath.Length() + 2); - - aResult = mOverrideJARURL; - aResult += aPackage; - aResult += '/'; - aResult += aProvider; - aResult += '/'; - - // skins and locales get their name tacked on, like - // skin/modern/foo.css or - // locale/en-US/navigator.properties - if (aProvider.EqualsLiteral("skin") || - aProvider.EqualsLiteral("locale")) { - - // little hack here to get the right arc - nsIRDFResource* providerArc; - if (aProvider.Equals("skin")) - providerArc = mSelectedSkin; - else - providerArc = mSelectedLocale; - - nsCAutoString selectedProvider; - rv = GetSelectedProvider(aPackage, aProvider, providerArc, selectedProvider); - - if (NS_SUCCEEDED(rv)) { - aResult += selectedProvider; - aResult += '/'; } } - - aResult += aPath; - - nsCOMPtr zipEntry; - rv = mOverrideJAR->GetEntry(PromiseFlatCString(aResult).get(), - getter_AddRefs(zipEntry)); - if (NS_FAILED(rv)) { - aResult.Truncate(); - return rv; + else if (aProvider.Equals(NS_LITERAL_CSTRING("locale"))) { + mSelectedLocales.Get(aPackage, getter_AddRefs(aProviderResource)); + if (!aProviderResource) { + rv = FindSubProvider(aPackage, aProvider, aProviderResource); + if (NS_FAILED(rv)) return rv; + } } + else { + NS_ASSERTION(aProvider.Equals(NS_LITERAL_CSTRING("content")), "Bad provider!"); + aProviderResource = aPackageResource; + } + + if (!aProviderResource) + return NS_ERROR_FAILURE; return NS_OK; } nsresult -nsChromeRegistry::InitOverrideJAR() +nsChromeRegistry::TrySubProvider(const nsACString& aPackage, PRBool aIsLocale, + nsIRDFResource* aProviderResource, + nsCOMPtr &aSelectedProvider) { - // generic failure if we know there's no override - if (mSearchedForOverride && !mOverrideJAR) - return NS_ERROR_FAILURE; - - mSearchedForOverride = PR_TRUE; - nsresult rv; - // - // look for custom.jar - // - nsCOMPtr overrideFile; - rv = GetInstallRoot(getter_AddRefs(overrideFile)); + + // We've got a resource like in aProviderResource + // get its package list + nsCOMPtr packageNode; + rv = mChromeDataSource->GetTarget(aProviderResource, mPackages, + PR_TRUE, getter_AddRefs(packageNode)); if (NS_FAILED(rv)) return rv; - rv = overrideFile->AppendNative(NS_LITERAL_CSTRING("custom.jar")); - if (NS_FAILED(rv)) return rv; + nsCOMPtr packageList (do_QueryInterface(packageNode)); + if (!packageList) return NS_ERROR_FAILURE; - PRBool exists; - rv = overrideFile->Exists(&exists); - if (NS_FAILED(rv)) return rv; + nsCOMPtr container + (do_CreateInstance("@mozilla.org/rdf/container;1", &rv)); + NS_ENSURE_SUCCESS(rv, rv); - // ok, if the file doesn't exist, its just a generic failure - if (!exists) - return NS_ERROR_FAILURE; - - // - // cache the url so we can later append - // - mOverrideJARURL.Assign("jar:"); - nsCAutoString jarURL; - rv = NS_GetURLSpecFromFile(overrideFile, jarURL); - if (NS_FAILED(rv)) return rv; - - mOverrideJARURL.Append(jarURL); - mOverrideJARURL.Append("!/"); - if (NS_FAILED(rv)) return rv; - - // - // also cache the zip file itself - // - nsCOMPtr readerCache = - do_CreateInstance("@mozilla.org/libjar/zip-reader-cache;1", &rv); - if (NS_FAILED(rv)) return rv; - - rv = readerCache->Init(32); - - rv = readerCache->GetZip(overrideFile, getter_AddRefs(mOverrideJAR)); - if (NS_FAILED(rv)) { - mOverrideJARURL.Truncate(); - return rv; - } - - return NS_OK; -} - -nsresult -nsChromeRegistry::VerifyCompatibleProvider(nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderResource, - nsIRDFResource* aArc, - PRBool *aAcceptable) -{ - // We found a selected provider, but now we need to verify that the version - // specified by the package and the version specified by the provider are - // one and the same. If they aren't, then we cannot use this provider. - nsCOMPtr versionArc; - if (aArc == mSelectedSkin) - versionArc = mSkinVersion; - else // Locale arc - versionArc = mLocaleVersion; - - nsCAutoString packageVersion; - nsChromeRegistry::FollowArc(mChromeDataSource, packageVersion, - aPackageResource, versionArc); - if (!packageVersion.IsEmpty()) { - // The package only wants providers (skins) that say they can work - // with it. Let's find out if our provider (skin) can work with it. - nsCAutoString providerVersion; - nsChromeRegistry::FollowArc(mChromeDataSource, providerVersion, - aProviderResource, versionArc); - if (!providerVersion.Equals(packageVersion)) { - *aAcceptable = PR_FALSE; - return NS_OK; - } - } - - // Ensure that the provider actually exists. - // XXX This will have to change if we handle remote chrome. - nsCAutoString providerBaseURL; - nsresult rv = FollowArc(mChromeDataSource, providerBaseURL, - aProviderResource, mBaseURL); - if (NS_FAILED(rv)) - return rv; - nsCOMPtr baseURLFile; - rv = GetBaseURLFile(providerBaseURL, getter_AddRefs(baseURLFile)); - if (NS_FAILED(rv)) - return rv; - rv = baseURLFile->Exists(aAcceptable); -#if DEBUG - if (NS_FAILED(rv) || !*aAcceptable) - printf("BaseURL %s cannot be found.\n", - PromiseFlatCString(providerBaseURL).get()); -#endif - return rv; -} - -// locate -nsresult -nsChromeRegistry::FindProvider(const nsACString& aPackage, - const nsACString& aProvider, - nsIRDFResource *aArc, - nsIRDFNode **aSelectedProvider) -{ - *aSelectedProvider = nsnull; - - nsCAutoString rootStr("urn:mozilla:"); - nsresult rv = NS_OK; - - rootStr += aProvider; - rootStr += ":root"; - - // obtain the provider root resource - nsCOMPtr resource; - rv = GetResource(rootStr, getter_AddRefs(resource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the provider root resource."); - return rv; - } - - // wrap it in a container - nsCOMPtr container; - rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_FAILED(rv)) return rv; - - rv = container->Init(mChromeDataSource, resource); - if (NS_FAILED(rv)) return rv; + rv = container->Init(mChromeDataSource, packageList); + NS_ENSURE_SUCCESS(rv, rv); // step through its (seq) arcs nsCOMPtr arcs; rv = container->GetElements(getter_AddRefs(arcs)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); - // XXX This needs to be something other than random. See bug 191957. - PRBool moreElements; - rv = arcs->HasMoreElements(&moreElements); - if (NS_FAILED(rv)) return rv; - for ( ; moreElements; arcs->HasMoreElements(&moreElements)) { + PRBool hasMore; + nsCOMPtr supports; + nsCOMPtr kid; + nsCOMPtr package; + while (NS_SUCCEEDED(arcs->HasMoreElements(&hasMore)) && hasMore) { // get next arc resource - nsCOMPtr supports; rv = arcs->GetNext(getter_AddRefs(supports)); - if (NS_FAILED(rv)) return rv; - nsCOMPtr kid = do_QueryInterface(supports); + NS_ENSURE_SUCCESS(rv, rv); - if (kid) { - // get its name - nsCAutoString providerName; - rv = FollowArc(mChromeDataSource, providerName, kid, mName); - if (NS_FAILED(rv)) return rv; + kid = do_QueryInterface(supports); + if (!kid) continue; - // get its package list - nsCOMPtr packageNode; - nsCOMPtr packageList; - rv = mChromeDataSource->GetTarget(kid, mPackages, PR_TRUE, getter_AddRefs(packageNode)); - if (NS_SUCCEEDED(rv)) - packageList = do_QueryInterface(packageNode); - if (!packageList) - continue; + // get its package resource + rv = mChromeDataSource->GetTarget(kid, mPackage, PR_TRUE, + getter_AddRefs(packageNode)); + if (NS_FAILED(rv)) continue; + + package = do_QueryInterface(packageNode); + if (!package) continue; - // if aPackage is named in kid's package list, select it and we're done - rv = SelectPackageInProvider(packageList, aPackage, aProvider, providerName, - aArc, aSelectedProvider); - if (NS_FAILED(rv)) - continue; // Don't let this be disastrous. We may find another acceptable match. + // get its name + nsCAutoString packageName; + rv = FollowArc(mChromeDataSource, packageName, package, mName); + if (NS_FAILED(rv)) continue; // don't fail if package has not yet been installed - if (*aSelectedProvider) - return NS_OK; + if (packageName.Equals(aPackage)) { + // we found the locale, cache it in memory + if (aIsLocale) { + mSelectedLocales.Put(aPackage, kid); + } + else { + mSelectedSkins.Put(aPackage, kid); + } + + aSelectedProvider = kid; + return NS_OK; } } + return NS_ERROR_FAILURE; } nsresult -nsChromeRegistry::SelectPackageInProvider(nsIRDFResource *aPackageList, - const nsACString& aPackage, - const nsACString& aProvider, - const nsACString& aProviderName, - nsIRDFResource *aArc, - nsIRDFNode **aSelectedProvider) +nsChromeRegistry::FindSubProvider(const nsACString& aPackage, + const nsACString& aProvider, + nsCOMPtr &aSelectedProvider) { - *aSelectedProvider = nsnull; + nsresult rv; - nsresult rv = NS_OK; + PRBool isLocale = aProvider.Equals(NS_LITERAL_CSTRING("locale")); - // wrap aPackageList in a container - nsCOMPtr container; - rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_SUCCEEDED(rv)) - rv = container->Init(mChromeDataSource, aPackageList); - if (NS_FAILED(rv)) - return rv; + nsCAutoString rootStr(NS_LITERAL_CSTRING("urn:mozilla:")); + rootStr += aProvider; + rootStr += ":"; + rootStr += isLocale ? mSelectedLocale : mSelectedSkin; + + // obtain the provider root resource + nsCOMPtr resource; + rv = GetResource(rootStr, getter_AddRefs(resource)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = TrySubProvider(aPackage, isLocale, resource, aSelectedProvider); + if (NS_SUCCEEDED(rv)) return rv; + + // If the default locale doesn't have a matching package, try any locale. + // This means that we will probably end up with mixed locales/skins. Mixed + // is better than none. + + rootStr = NS_LITERAL_CSTRING("urn:mozilla:"); + rootStr += aProvider; + rootStr += ":root"; + + rv = GetResource(rootStr, getter_AddRefs(resource)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr container = + do_CreateInstance("@mozilla.org/rdf/container;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); + + rv = container->Init(mChromeDataSource, resource); + NS_ENSURE_SUCCESS(rv, rv); // step through its (seq) arcs nsCOMPtr arcs; rv = container->GetElements(getter_AddRefs(arcs)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); PRBool moreElements; - rv = arcs->HasMoreElements(&moreElements); - if (NS_FAILED(rv)) return rv; - for ( ; moreElements; arcs->HasMoreElements(&moreElements)) { + nsCOMPtr supports; + nsCOMPtr kid; + while (NS_SUCCEEDED(arcs->HasMoreElements(&moreElements)) && moreElements) { // get next arc resource - nsCOMPtr supports; rv = arcs->GetNext(getter_AddRefs(supports)); - if (NS_FAILED(rv)) return rv; - nsCOMPtr kid = do_QueryInterface(supports); + NS_ENSURE_SUCCESS(rv, rv); - if (kid) { - // get its package resource - nsCOMPtr packageNode; - nsCOMPtr package; - rv = mChromeDataSource->GetTarget(kid, mPackage, PR_TRUE, getter_AddRefs(packageNode)); - if (NS_SUCCEEDED(rv)) - package = do_QueryInterface(packageNode); - if (!package) - continue; + kid = do_QueryInterface(supports); + if (!kid) continue; - // get its name - nsCAutoString packageName; - rv = FollowArc(mChromeDataSource, packageName, package, mName); - if (NS_FAILED(rv)) - continue; // don't fail if package has not yet been installed - - if (packageName.Equals(aPackage)) { - PRBool useProfile = !mProfileRoot.IsEmpty(); - // XXXldb Do we really want to do this? We risk crossing skins. - if (packageName.Equals("global") || packageName.Equals("communicator")) - useProfile = PR_FALSE; // Always force the auto-selection to be in the - // install dir for the packages required to bring up the profile UI. - rv = SelectProviderForPackage(aProvider, - aProviderName, - NS_ConvertASCIItoUCS2(packageName).get(), - aArc, useProfile, PR_TRUE); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; - - *aSelectedProvider = kid; - NS_ADDREF(*aSelectedProvider); - return NS_OK; - } - } + rv = TrySubProvider(aPackage, isLocale, kid, aSelectedProvider); + if (NS_SUCCEEDED(rv)) return rv; } - return NS_OK; + + return NS_ERROR_FAILURE; } nsresult @@ -1339,8 +1202,10 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins() return NS_OK; } - void + + + nsChromeRegistry::FlushSkinCaches() { nsCOMPtr obsSvc = @@ -1688,532 +1553,6 @@ nsChromeRegistry::UpdateDynamicDataSources(nsIRDFDataSource *aDataSource, return NS_OK; } -NS_IMETHODIMP nsChromeRegistry::SelectSkin(const nsACString& aSkin, - PRBool aUseProfile) -{ - nsresult rv = SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_TRUE); - FlushSkinCaches(); - return rv; -} - -NS_IMETHODIMP nsChromeRegistry::SelectLocale(const nsACString& aLocale, - PRBool aUseProfile) -{ - return SetProvider(NS_LITERAL_CSTRING("locale"), mSelectedLocale, aLocale, aUseProfile, nsnull, PR_TRUE); -} - -NS_IMETHODIMP nsChromeRegistry::SelectLocaleForProfile(const nsACString& aLocale, - const PRUnichar *aProfilePath) -{ - // to be changed to use given path - return SetProvider(NS_LITERAL_CSTRING("locale"), mSelectedLocale, aLocale, PR_TRUE, NS_ConvertUCS2toUTF8(aProfilePath).get(), PR_TRUE); -} - -NS_IMETHODIMP nsChromeRegistry::SelectSkinForProfile(const nsACString& aSkin, - const PRUnichar *aProfilePath) -{ - return SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, PR_TRUE, NS_ConvertUCS2toUTF8(aProfilePath).get(), PR_TRUE); -} - -/* void setRuntimeProvider (in boolean runtimeProvider); */ -// should we inline this one? -NS_IMETHODIMP nsChromeRegistry::SetRuntimeProvider(PRBool runtimeProvider) -{ - mRuntimeProvider = runtimeProvider; - return NS_OK; -} - - -/* ACString getSelectedLocale (ACString packageName); */ -NS_IMETHODIMP -nsChromeRegistry::GetSelectedLocale(const nsACString& aPackageName, - nsACString& aResult) -{ - return GetSelectedProvider(aPackageName, - NS_LITERAL_CSTRING("locale"), mSelectedLocale, - aResult); -} - -NS_IMETHODIMP -nsChromeRegistry::GetSelectedSkin(const nsACString& aPackageName, - nsACString& aResult) -{ - return GetSelectedProvider(aPackageName, - NS_LITERAL_CSTRING("skin"), mSelectedSkin, - aResult); -} - -nsresult -nsChromeRegistry::GetSelectedProvider(const nsACString& aPackageName, - const nsACString& aProvider, - nsIRDFResource* aSelectionArc, - nsACString& _retval) -{ - // check if mChromeDataSource is null; do we need to apply this to every instance? - // is there a better way to test if the data source is ready? - if (!mChromeDataSource) { - return NS_ERROR_FAILURE; - } - - nsCAutoString resourceStr("urn:mozilla:package:"); - resourceStr += aPackageName; - - // Obtain the resource. - nsresult rv = NS_OK; - nsCOMPtr resource; - rv = GetResource(resourceStr, getter_AddRefs(resource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } - - if (mChromeDataSource == nsnull) - return NS_ERROR_NULL_POINTER; - - // Follow the "selectedLocale" arc. - nsCOMPtr selectedProvider; - if (NS_FAILED(rv = mChromeDataSource->GetTarget(resource, aSelectionArc, PR_TRUE, getter_AddRefs(selectedProvider)))) { - NS_ERROR("Unable to obtain the provider."); - return rv; - } - - if (!selectedProvider) { - rv = FindProvider(aPackageName, aProvider, aSelectionArc, getter_AddRefs(selectedProvider)); - if (!selectedProvider) - return rv; - } - - resource = do_QueryInterface(selectedProvider); - if (!resource) - return NS_ERROR_FAILURE; - - // selectedProvider.mURI now looks like "urn:mozilla:locale:ja-JP:navigator" - const char *uri; - if (NS_FAILED(rv = resource->GetValueConst(&uri))) - return rv; - - // trim down to "urn:mozilla:locale:ja-JP" - nsCAutoString packageStr(":"); - packageStr += aPackageName; - - nsCAutoString ustr(uri); - PRInt32 pos = ustr.RFind(packageStr); - nsCAutoString urn; - ustr.Left(urn, pos); - - rv = GetResource(urn, getter_AddRefs(resource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the provider resource."); - return rv; - } - - // From this resource, follow the "name" arc. - return FollowArc(mChromeDataSource, _retval, resource, mName); -} - -NS_IMETHODIMP nsChromeRegistry::DeselectSkin(const nsACString& aSkin, - PRBool aUseProfile) -{ - nsresult rv = SetProvider(NS_LITERAL_CSTRING("skin"), mSelectedSkin, aSkin, aUseProfile, nsnull, PR_FALSE); - FlushSkinCaches(); - return rv; -} - -NS_IMETHODIMP nsChromeRegistry::DeselectLocale(const nsACString& aLocale, - PRBool aUseProfile) -{ - return SetProvider(NS_LITERAL_CSTRING("locale"), mSelectedLocale, aLocale, aUseProfile, nsnull, PR_FALSE); -} - -nsresult -nsChromeRegistry::SetProvider(const nsACString& aProvider, - nsIRDFResource* aSelectionArc, - const nsACString& aProviderName, - PRBool aUseProfile, const char *aProfilePath, - PRBool aIsAdding) -{ - // Build the provider resource str. - // e.g., urn:mozilla:skin:aqua/1.0 - nsCAutoString resourceStr( "urn:mozilla:" ); - resourceStr += aProvider; - resourceStr += ":"; - resourceStr += aProviderName; - - // Obtain the provider resource. - nsresult rv = NS_OK; - nsCOMPtr resource; - rv = GetResource(resourceStr, getter_AddRefs(resource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } - NS_ASSERTION(resource, "failed to GetResource"); - - // Follow the packages arc to the package resources. - nsCOMPtr packageList; - rv = mChromeDataSource->GetTarget(resource, mPackages, PR_TRUE, getter_AddRefs(packageList)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the SEQ for the package list."); - return rv; - } - // ok for packageList to be null here -- it just means that we haven't encountered that package yet - - nsCOMPtr packageSeq(do_QueryInterface(packageList, &rv)); - if (NS_FAILED(rv)) return rv; - - // Build an RDF container to wrap the SEQ - nsCOMPtr container; - rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_FAILED(rv)) - return NS_OK; - - if (NS_FAILED(container->Init(mChromeDataSource, packageSeq))) - return NS_OK; - - nsCOMPtr arcs; - if (NS_FAILED(container->GetElements(getter_AddRefs(arcs)))) - return NS_OK; - - // For each skin/package entry, follow the arcs to the real package - // resource. - PRBool more; - rv = arcs->HasMoreElements(&more); - if (NS_FAILED(rv)) return rv; - while (more) { - nsCOMPtr packageSkinEntry; - rv = arcs->GetNext(getter_AddRefs(packageSkinEntry)); - if (NS_SUCCEEDED(rv) && packageSkinEntry) { - nsCOMPtr entry = do_QueryInterface(packageSkinEntry); - if (entry) { - // Obtain the real package resource. - nsCOMPtr packageNode; - rv = mChromeDataSource->GetTarget(entry, mPackage, PR_TRUE, getter_AddRefs(packageNode)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } - - // Select the skin for this package resource. - nsCOMPtr packageResource(do_QueryInterface(packageNode)); - if (packageResource) { - rv = SetProviderForPackage(aProvider, packageResource, entry, aSelectionArc, aUseProfile, aProfilePath, aIsAdding); - if (NS_FAILED(rv)) - continue; // Well, let's set as many sub-packages as we can... - } - } - } - rv = arcs->HasMoreElements(&more); - if (NS_FAILED(rv)) return rv; - } - - // always reset the flag - mRuntimeProvider = PR_FALSE; - - return NS_OK; -} - -nsresult -nsChromeRegistry::SetProviderForPackage(const nsACString& aProvider, - nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderPackageResource, - nsIRDFResource* aSelectionArc, - PRBool aUseProfile, const char *aProfilePath, - PRBool aIsAdding) -{ - nsresult rv; - - if (aUseProfile && !mProfileInitialized) { - rv = LoadProfileDataSource(); - if (NS_FAILED(rv)) return rv; - } - - // Figure out which file we're needing to modify, e.g., is it the install - // dir or the profile dir, and get the right datasource. - nsCOMPtr dataSource; - rv = LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), aUseProfile, aProfilePath); - if (NS_FAILED(rv)) return rv; - - rv = nsChromeRegistry::UpdateArc(dataSource, aPackageResource, aSelectionArc, aProviderPackageResource, !aIsAdding); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr remote = do_QueryInterface(dataSource, &rv); - if (NS_FAILED(rv)) return rv; - - // add one more check: - // assert the data source only when we are not setting runtime-only provider - if (!mBatchInstallFlushes && !mRuntimeProvider) - rv = remote->Flush(); - - return rv; -} - -NS_IMETHODIMP nsChromeRegistry::SelectSkinForPackage(const nsACString& aSkin, - const PRUnichar *aPackageName, - PRBool aUseProfile) -{ - return SelectProviderForPackage(NS_LITERAL_CSTRING("skin"), aSkin, aPackageName, mSelectedSkin, aUseProfile, PR_TRUE); -} - -NS_IMETHODIMP nsChromeRegistry::SelectLocaleForPackage(const nsACString& aLocale, - const PRUnichar *aPackageName, - PRBool aUseProfile) -{ - return SelectProviderForPackage(NS_LITERAL_CSTRING("locale"), aLocale, aPackageName, mSelectedLocale, aUseProfile, PR_TRUE); -} - -NS_IMETHODIMP nsChromeRegistry::DeselectSkinForPackage(const nsACString& aSkin, - const PRUnichar *aPackageName, - PRBool aUseProfile) -{ - return SelectProviderForPackage(NS_LITERAL_CSTRING("skin"), aSkin, aPackageName, mSelectedSkin, aUseProfile, PR_FALSE); -} - -NS_IMETHODIMP nsChromeRegistry::DeselectLocaleForPackage(const nsACString& aLocale, - const PRUnichar *aPackageName, - PRBool aUseProfile) -{ - return SelectProviderForPackage(NS_LITERAL_CSTRING("locale"), aLocale, aPackageName, mSelectedLocale, aUseProfile, PR_FALSE); -} - -NS_IMETHODIMP nsChromeRegistry::IsSkinSelectedForPackage(const nsACString& aSkin, - const PRUnichar *aPackageName, - PRBool aUseProfile, PRBool* aResult) -{ - return IsProviderSelectedForPackage(NS_LITERAL_CSTRING("skin"), aSkin, aPackageName, mSelectedSkin, aUseProfile, aResult); -} - -NS_IMETHODIMP nsChromeRegistry::IsLocaleSelectedForPackage(const nsACString& aLocale, - const PRUnichar *aPackageName, - PRBool aUseProfile, PRBool* aResult) -{ - return IsProviderSelectedForPackage(NS_LITERAL_CSTRING("locale"), aLocale, aPackageName, mSelectedLocale, aUseProfile, aResult); -} - -nsresult -nsChromeRegistry::SelectProviderForPackage(const nsACString& aProviderType, - const nsACString& aProviderName, - const PRUnichar *aPackageName, - nsIRDFResource* aSelectionArc, - PRBool aUseProfile, PRBool aIsAdding) -{ - nsCAutoString package( "urn:mozilla:package:" ); - AppendUTF16toUTF8(aPackageName, package); - - nsCAutoString provider( "urn:mozilla:" ); - provider += aProviderType; - provider += ":"; - provider += aProviderName; - provider += ":"; - AppendUTF16toUTF8(aPackageName, provider); - - // Obtain the package resource. - nsresult rv = NS_OK; - nsCOMPtr packageResource; - rv = GetResource(package, getter_AddRefs(packageResource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } - NS_ASSERTION(packageResource, "failed to get packageResource"); - - // Obtain the provider resource. - nsCOMPtr providerResource; - rv = GetResource(provider, getter_AddRefs(providerResource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the provider resource."); - return rv; - } - NS_ASSERTION(providerResource, "failed to get providerResource"); - - // Version-check before selecting. If this skin isn't a compatible version, then - // don't allow the selection. - PRBool acceptable; - rv = VerifyCompatibleProvider(packageResource, providerResource, - aSelectionArc, &acceptable); - if (NS_FAILED(rv)) - return rv; - if (!acceptable) - return NS_ERROR_FAILURE; - - rv = SetProviderForPackage(aProviderType, packageResource, providerResource, aSelectionArc, - aUseProfile, nsnull, aIsAdding); - // always reset the flag - mRuntimeProvider = PR_FALSE; - - return rv; -} - -NS_IMETHODIMP nsChromeRegistry::IsSkinSelected(const nsACString& aSkin, - PRBool aUseProfile, PRInt32* aResult) -{ - return IsProviderSelected(NS_LITERAL_CSTRING("skin"), aSkin, mSelectedSkin, aUseProfile, aResult); -} - -NS_IMETHODIMP nsChromeRegistry::IsLocaleSelected(const nsACString& aLocale, - PRBool aUseProfile, PRInt32* aResult) -{ - return IsProviderSelected(NS_LITERAL_CSTRING("locale"), aLocale, mSelectedLocale, aUseProfile, aResult); -} - -nsresult -nsChromeRegistry::IsProviderSelected(const nsACString& aProvider, - const nsACString& aProviderName, - nsIRDFResource* aSelectionArc, - PRBool aUseProfile, PRInt32* aResult) -{ - // Build the provider resource str. - // e.g., urn:mozilla:skin:aqua/1.0 - *aResult = NONE; - nsCAutoString resourceStr( "urn:mozilla:" ); - resourceStr += aProvider; - resourceStr += ":"; - resourceStr += aProviderName; - // Obtain the provider resource. - nsresult rv = NS_OK; - nsCOMPtr resource; - rv = GetResource(resourceStr, getter_AddRefs(resource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } - NS_ASSERTION(resource, "failed to GetResource"); - - // Follow the packages arc to the package resources. - nsCOMPtr packageList; - rv = mChromeDataSource->GetTarget(resource, mPackages, PR_TRUE, getter_AddRefs(packageList)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the SEQ for the package list."); - return rv; - } - // ok for packageList to be null here -- it just means that we haven't encountered that package yet - - nsCOMPtr packageSeq(do_QueryInterface(packageList, &rv)); - if (NS_FAILED(rv)) return rv; - - // Build an RDF container to wrap the SEQ - nsCOMPtr container(do_CreateInstance("@mozilla.org/rdf/container;1")); - if (NS_FAILED(container->Init(mChromeDataSource, packageSeq))) - return NS_OK; - - nsCOMPtr arcs; - container->GetElements(getter_AddRefs(arcs)); - - // For each skin/package entry, follow the arcs to the real package - // resource. - PRBool more; - PRInt32 numSet = 0; - PRInt32 numPackages = 0; - rv = arcs->HasMoreElements(&more); - if (NS_FAILED(rv)) return rv; - while (more) { - nsCOMPtr packageSkinEntry; - rv = arcs->GetNext(getter_AddRefs(packageSkinEntry)); - if (NS_SUCCEEDED(rv) && packageSkinEntry) { - nsCOMPtr entry = do_QueryInterface(packageSkinEntry); - if (entry) { - // Obtain the real package resource. - nsCOMPtr packageNode; - rv = mChromeDataSource->GetTarget(entry, mPackage, PR_TRUE, getter_AddRefs(packageNode)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } - - // Select the skin for this package resource. - nsCOMPtr packageResource(do_QueryInterface(packageNode)); - if (packageResource) { - PRBool isSet = PR_FALSE; - rv = IsProviderSetForPackage(aProvider, packageResource, entry, aSelectionArc, aUseProfile, &isSet); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to set provider for package resource."); - return rv; - } - ++numPackages; - if (isSet) - ++numSet; - } - } - } - rv = arcs->HasMoreElements(&more); - if (NS_FAILED(rv)) return rv; - } - if (numPackages == numSet) - *aResult = FULL; - else if (numSet) - *aResult = PARTIAL; - return NS_OK; -} - -nsresult -nsChromeRegistry::IsProviderSelectedForPackage(const nsACString& aProviderType, - const nsACString& aProviderName, - const PRUnichar *aPackageName, - nsIRDFResource* aSelectionArc, - PRBool aUseProfile, PRBool* aResult) -{ - *aResult = PR_FALSE; - nsCAutoString package( "urn:mozilla:package:" ); - AppendUTF16toUTF8(aPackageName, package); - - nsCAutoString provider( "urn:mozilla:" ); - provider += aProviderType; - provider += ":"; - provider += aProviderName; - provider += ":"; - AppendUTF16toUTF8(aPackageName, provider); - - // Obtain the package resource. - nsresult rv = NS_OK; - nsCOMPtr packageResource; - rv = GetResource(package, getter_AddRefs(packageResource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } - NS_ASSERTION(packageResource, "failed to get packageResource"); - - // Obtain the provider resource. - nsCOMPtr providerResource; - rv = GetResource(provider, getter_AddRefs(providerResource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the provider resource."); - return rv; - } - NS_ASSERTION(providerResource, "failed to get providerResource"); - - return IsProviderSetForPackage(aProviderType, packageResource, providerResource, aSelectionArc, - aUseProfile, aResult); -} - -nsresult -nsChromeRegistry::IsProviderSetForPackage(const nsACString& aProvider, - nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderPackageResource, - nsIRDFResource* aSelectionArc, - PRBool aUseProfile, PRBool* aResult) -{ - nsresult rv; - // Figure out which file we're needing to modify, e.g., is it the install - // dir or the profile dir, and get the right datasource. - - nsCOMPtr dataSource; - rv = LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), aUseProfile, nsnull); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr retVal; - dataSource->GetTarget(aPackageResource, aSelectionArc, PR_TRUE, getter_AddRefs(retVal)); - if (retVal) { - nsCOMPtr node(do_QueryInterface(aProviderPackageResource)); - if (node == retVal) - *aResult = PR_TRUE; - } - - return NS_OK; -} - nsresult nsChromeRegistry::InstallProvider(const nsACString& aProviderType, const nsACString& aBaseURL, @@ -2259,7 +1598,7 @@ nsChromeRegistry::InstallProvider(const nsACString& aProviderType, if (NS_FAILED(rv)) return rv; appendPackage = PR_TRUE; appendProvider = PR_TRUE; - NS_WARNING("Trying old-style manifest.rdf. Please update to contents.rdf."); + NS_ERROR("Trying old-style manifest.rdf. Please update to contents.rdf."); } else { if ((skinCount > 1 && aProviderType.Equals("skin")) || @@ -2661,8 +2000,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallPackage(const char* aBaseURL, PRBool aUse NS_IMETHODIMP nsChromeRegistry::UninstallSkin(const nsACString& aSkinName, PRBool aUseProfile) { - // The skin must first be deselected. - DeselectSkin(aSkinName, aUseProfile); + mSelectedSkins.Clear(); // Now uninstall it. return UninstallProvider(NS_LITERAL_CSTRING("skin"), aSkinName, aUseProfile); @@ -2670,8 +2008,7 @@ NS_IMETHODIMP nsChromeRegistry::UninstallSkin(const nsACString& aSkinName, PRBoo NS_IMETHODIMP nsChromeRegistry::UninstallLocale(const nsACString& aLocaleName, PRBool aUseProfile) { - // The locale must first be deselected. - DeselectLocale(aLocaleName, aUseProfile); + mSelectedLocales.Clear(); return UninstallProvider(NS_LITERAL_CSTRING("locale"), aLocaleName, aUseProfile); } @@ -3067,13 +2404,15 @@ nsChromeRegistry::GetInstallRoot(nsIFile** aFileURL) void nsChromeRegistry::FlushAllCaches() { + mSelectedSkins.Clear(); + mSelectedLocales.Clear(); + nsCOMPtr 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 @@ -3218,24 +2557,23 @@ nsresult nsChromeRegistry::LoadProfileDataSource() mChromeDataSource = nsnull; rv = AddToCompositeDataSource(PR_TRUE); if (NS_FAILED(rv)) return rv; + } - // XXX this sucks ASS. This is a temporary hack until we get - // around to fixing the skin switching bugs. - // Select and Remove skins based on a pref set in a previous session. - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - nsXPIDLCString skinToSelect; - rv = prefBranch->GetCharPref("general.skins.selectedSkin", getter_Copies(skinToSelect)); + nsCOMPtr pref (do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (pref) { + PRBool pending; + rv = pref->GetBoolPref(DSS_SWITCH_PENDING, &pending); + if (NS_SUCCEEDED(rv) && pending) { + nsXPIDLCString skin; + rv = pref->GetCharPref(DSS_SKIN_TO_SELECT, getter_Copies(skin)); if (NS_SUCCEEDED(rv)) { - rv = SelectSkin(skinToSelect, PR_TRUE); - if (NS_SUCCEEDED(rv)) - prefBranch->DeleteBranch("general.skins.selectedSkin"); + pref->SetCharPref(SELECTED_SKIN_PREF, skin); + pref->ClearUserPref(DSS_SKIN_TO_SELECT); + pref->ClearUserPref(DSS_SWITCH_PENDING); } } - - // We have to flush the chrome skin cache... - FlushSkinCaches(); } + return NS_OK; } @@ -3253,44 +2591,23 @@ NS_IMETHODIMP nsChromeRegistry::AllowScriptsForSkin(nsIURI* aChromeURI, PRBool * if (!provider.Equals("skin")) return NS_OK; - // XXX could factor this with selectproviderforpackage - // get the selected skin resource for the package - nsCOMPtr selectedProvider; + nsCOMPtr selectedProvider; + nsCOMPtr packageResource; - nsCAutoString resourceStr("urn:mozilla:package:"); - resourceStr += package; + rv = FindProvider(package, provider, selectedProvider, packageResource); + if (NS_FAILED(rv)) return rv; - // Obtain the resource. - nsCOMPtr resource; - rv = GetResource(resourceStr, getter_AddRefs(resource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } + // get its script access + nsCAutoString scriptAccess; + rv = nsChromeRegistry::FollowArc(mChromeDataSource, + scriptAccess, + selectedProvider, + mAllowScripts); + if (NS_FAILED(rv)) return rv; // NS_RDF_NO_VALUE is a success code, funny? - if (NS_FAILED(rv = mChromeDataSource->GetTarget(resource, mSelectedSkin, PR_TRUE, getter_AddRefs(selectedProvider)))) - return NS_OK; + if (!scriptAccess.IsEmpty()) + *aResult = PR_FALSE; - if (!selectedProvider) { - rv = FindProvider(package, provider, mSelectedSkin, getter_AddRefs(selectedProvider)); - if (NS_FAILED(rv)) return rv; - } - if (!selectedProvider) - return NS_OK; - - resource = do_QueryInterface(selectedProvider, &rv); - if (NS_SUCCEEDED(rv)) { - // get its script access - nsCAutoString scriptAccess; - rv = nsChromeRegistry::FollowArc(mChromeDataSource, - scriptAccess, - resource, - mAllowScripts); - if (NS_FAILED(rv)) return rv; - - if (!scriptAccess.IsEmpty()) - *aResult = PR_FALSE; - } return NS_OK; } @@ -3517,27 +2834,15 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) // process the line if (skin.Equals(chromeType)) { - if (isSelection) { - - rv = SelectSkin(nsDependentCString(chromeLocation), isProfile); -#ifdef DEBUG2 - printf("***** Chrome Registration: Selecting skin %s as default\n", (const char*)chromeLocation); -#endif - } - else + /* We don't do selection from installed-chrome.txt any more; + just ignore "select" lines */ + if (!isSelection) rv = InstallSkin(chromeURL.get(), isProfile, PR_FALSE); } else if (content.Equals(chromeType)) rv = InstallPackage(chromeURL.get(), isProfile); else if (locale.Equals(chromeType)) { - if (isSelection) { - - rv = SelectLocale(nsDependentCString(chromeLocation), isProfile); -#ifdef DEBUG2 - printf("***** Chrome Registration: Selecting locale %s as default\n", (const char*)chromeLocation); -#endif - } - else + if (!isSelection) rv = InstallLocale(chromeURL.get(), isProfile); } @@ -3606,138 +2911,34 @@ NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const char *aTopi rv = LoadProfileDataSource(); } } + else if (!strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic)) { + nsCOMPtr prefs (do_QueryInterface(aSubject)); + NS_ASSERTION(prefs, "Bad observer call!"); + + NS_ConvertUTF16toUTF8 pref(someData); + + nsXPIDLCString provider; + rv = prefs->GetCharPref(pref.get(), getter_Copies(provider)); + if (NS_FAILED(rv)) { + NS_ERROR("Couldn't get new locale or skin pref!"); + return rv; + } + + if (pref.Equals(NS_LITERAL_CSTRING(SELECTED_SKIN_PREF))) { + mSelectedSkin = provider; + mSelectedSkins.Clear(); + RefreshSkins(); + } + else if (pref.Equals(NS_LITERAL_CSTRING(SELECTED_LOCALE_PREF))) { + mSelectedLocale = provider; + FlushAllCaches(); + } else { + NS_ERROR("Unexpected pref!"); + } + } + else { + NS_ERROR("Unexpected observer topic!"); + } return rv; } - -NS_IMETHODIMP nsChromeRegistry::CheckThemeVersion(const nsACString& aSkin, - PRBool* aResult) -{ - return CheckProviderVersion(NS_LITERAL_CSTRING("skin"), aSkin, mSkinVersion, aResult); -} - - -NS_IMETHODIMP nsChromeRegistry::CheckLocaleVersion(const nsACString& aLocale, - PRBool* aResult) -{ - nsCAutoString provider("locale"); - return CheckProviderVersion(NS_LITERAL_CSTRING("skin"), aLocale, mLocaleVersion, aResult); -} - - -nsresult -nsChromeRegistry::CheckProviderVersion (const nsACString& aProviderType, - const nsACString& aProviderName, - nsIRDFResource* aSelectionArc, - PRBool *aCompatible) -{ - *aCompatible = PR_TRUE; - - // Build the provider resource str. - // e.g., urn:mozilla:skin:aqua/1.0 - nsCAutoString resourceStr( "urn:mozilla:" ); - resourceStr += aProviderType; - resourceStr += ":"; - resourceStr += aProviderName; - - // Obtain the provider resource. - nsresult rv = NS_OK; - nsCOMPtr resource; - rv = GetResource(resourceStr, getter_AddRefs(resource)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } - - // Follow the packages arc to the package resources. - nsCOMPtr packageList; - rv = mChromeDataSource->GetTarget(resource, mPackages, PR_TRUE, getter_AddRefs(packageList)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the SEQ for the package list."); - return rv; - } - // ok for packageList to be null here -- it just means that we haven't encountered that package yet - - nsCOMPtr packageSeq(do_QueryInterface(packageList, &rv)); - if (NS_FAILED(rv)) return rv; - - // Build an RDF container to wrap the SEQ - nsCOMPtr container; - rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", - nsnull, - NS_GET_IID(nsIRDFContainer), - getter_AddRefs(container)); - if (NS_FAILED(rv)) - return rv; - - rv = container->Init(mChromeDataSource, packageSeq); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr arcs; - - rv = container->GetElements(getter_AddRefs(arcs)); - if (NS_FAILED(rv)) - return NS_OK; - - // For each skin-package entry, follow the arcs to the real package - // resource. - PRBool more; - rv = arcs->HasMoreElements(&more); - if (NS_FAILED(rv)) return rv; - while (more) { - nsCOMPtr packageSkinEntry; - rv = arcs->GetNext(getter_AddRefs(packageSkinEntry)); - if (NS_SUCCEEDED(rv) && packageSkinEntry) { - nsCOMPtr entry = do_QueryInterface(packageSkinEntry); - if (entry) { - - nsCAutoString themePackageVersion; - nsChromeRegistry::FollowArc(mChromeDataSource, themePackageVersion, entry, aSelectionArc); - - // Obtain the real package resource. - nsCOMPtr packageNode; - rv = mChromeDataSource->GetTarget(entry, mPackage, PR_TRUE, getter_AddRefs(packageNode)); - if (NS_FAILED(rv)) { - NS_ERROR("Unable to obtain the package resource."); - return rv; - } - - nsCOMPtr packageResource(do_QueryInterface(packageNode)); - if (packageResource) { - - nsCAutoString packageVersion; - nsChromeRegistry::FollowArc(mChromeDataSource, packageVersion, packageResource, aSelectionArc); - - nsCAutoString packageName; - nsChromeRegistry::FollowArc(mChromeDataSource, packageName, packageResource, mName); - - if (packageName.IsEmpty()) - // the package is not represented for current version, so ignore it - *aCompatible = PR_TRUE; - else { - if (packageVersion.IsEmpty() && themePackageVersion.IsEmpty()) - *aCompatible = PR_TRUE; - else { - if (!packageVersion.IsEmpty() && !themePackageVersion.IsEmpty()) - *aCompatible = ( themePackageVersion.Equals(packageVersion)); - else - *aCompatible = PR_FALSE; - } - } - - // if just one theme package is NOT compatible, the theme will be disabled - if (!(*aCompatible)) - return NS_OK; - - } - } - } - rv = arcs->HasMoreElements(&more); - if (NS_FAILED(rv)) - return rv; - } - - return NS_OK; -} - diff --git a/chrome/src/nsChromeRegistry.h b/chrome/src/nsChromeRegistry.h index ed20716a6bf3..4871a1bb9b10 100644 --- a/chrome/src/nsChromeRegistry.h +++ b/chrome/src/nsChromeRegistry.h @@ -59,6 +59,7 @@ class nsIProperties; #include "nsString.h" #include "nsIZipReader.h" #include "nsCOMArray.h" +#include "nsInterfaceHashtable.h" // for component registration // {47049e42-1d87-482a-984d-56ae185e367a} @@ -146,74 +147,18 @@ private: const nsACString& aProvider, nsACString& aBaseURL); - nsresult InitOverrideJAR(); - nsresult GetOverrideURL(const nsACString& aPackage, - const nsACString& aProvider, - const nsACString& aPath, - nsACString& aResult); - - nsresult VerifyCompatibleProvider(nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderResource, - nsIRDFResource* aArc, - PRBool *aAcceptable); - nsresult FindProvider(const nsACString& aPackage, const nsACString& aProvider, - nsIRDFResource *aArc, - nsIRDFNode **aSelectedProvider); + nsCOMPtr &aProviderResource, + nsCOMPtr &aPackageResource); - nsresult SelectPackageInProvider(nsIRDFResource *aPackageList, - const nsACString& aPackage, - const nsACString& aProvider, - const nsACString& aProviderName, - nsIRDFResource *aArc, - nsIRDFNode **aSelectedProvider); + nsresult TrySubProvider(const nsACString& aPackage, PRBool aIsLocale, + nsIRDFResource* aProviderResource, + nsCOMPtr &aSelectedProvider); - nsresult SetProvider(const nsACString& aProvider, - nsIRDFResource* aSelectionArc, - const nsACString& aProviderName, - PRBool aAllUsers, - const char *aProfilePath, - PRBool aIsAdding); - - nsresult SetProviderForPackage(const nsACString& aProvider, - nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderPackageResource, - nsIRDFResource* aSelectionArc, - PRBool aAllUsers, const char *aProfilePath, - PRBool aIsAdding); - - nsresult SelectProviderForPackage(const nsACString& aProviderType, - const nsACString& aProviderName, - const PRUnichar *aPackageName, - nsIRDFResource* aSelectionArc, - PRBool aUseProfile, PRBool aIsAdding); - - nsresult GetSelectedProvider(const nsACString& aPackage, - const nsACString& aProviderName, - nsIRDFResource* aSelectionArc, - nsACString& aResult); - - nsresult CheckProviderVersion (const nsACString& aProviderType, - const nsACString& aProviderName, - nsIRDFResource* aSelectionArc, - PRBool *aCompatible); - - nsresult IsProviderSelected(const nsACString& aProvider, - const nsACString& aProviderName, - nsIRDFResource* aSelectionArc, - PRBool aUseProfile, PRInt32* aResult); - - nsresult IsProviderSelectedForPackage(const nsACString& aProviderType, - const nsACString& aProviderName, - const PRUnichar *aPackageName, - nsIRDFResource* aSelectionArc, - PRBool aUseProfile, PRBool* aResult); - nsresult IsProviderSetForPackage(const nsACString& aProvider, - nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderPackageResource, - nsIRDFResource* aSelectionArc, - PRBool aUseProfile, PRBool* aResult); + nsresult FindSubProvider(const nsACString& aPackage, + const nsACString& aProvider, + nsCOMPtr &aSelectedProvider); nsresult InstallProvider(const nsACString& aProviderType, const nsACString& aBaseURL, @@ -239,9 +184,13 @@ protected: nsIRDFService* mRDFService; nsIRDFContainerUtils* mRDFContainerUtils; + nsCString mSelectedLocale; + nsCString mSelectedSkin; + + nsInterfaceHashtable mSelectedLocales; + nsInterfaceHashtable mSelectedSkins; + // Resources - nsCOMPtr mSelectedSkin; - nsCOMPtr mSelectedLocale; nsCOMPtr mBaseURL; nsCOMPtr mPackages; nsCOMPtr mPackage; @@ -251,26 +200,16 @@ protected: nsCOMPtr mAllowScripts; nsCOMPtr mHasOverlays; nsCOMPtr mHasStylesheets; - nsCOMPtr mSkinVersion; - nsCOMPtr mLocaleVersion; - nsCOMPtr mPackageVersion; nsCOMPtr mDisabled; + nsCOMPtr mPlatformPackage; - nsCOMPtr mOverrideJAR; - nsCString mOverrideJARURL; - // useful atoms - these are static atoms, so don't use nsCOMPtr static nsIAtom* sCPrefix; // "c" PRPackedBool mInstallInitialized; PRPackedBool mProfileInitialized; - PRPackedBool mRuntimeProvider; - // Boolean that indicates we should batch flushes of the main // chrome.rdf file. PRPackedBool mBatchInstallFlushes; - - // make sure we only look once for the JAR override - PRPackedBool mSearchedForOverride; }; diff --git a/content/base/public/nsIChromeRegistry.idl b/content/base/public/nsIChromeRegistry.idl index 12561e74c3df..4febe29142d4 100755 --- a/content/base/public/nsIChromeRegistry.idl +++ b/content/base/public/nsIChromeRegistry.idl @@ -23,6 +23,7 @@ * Contributor(s): * pav * Blake Ross (blaker@netscape.com) + * Benjamin Smedberg * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -39,10 +40,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsISupports.idl" -#include "nsIURL.idl" -#include "nsISimpleEnumerator.idl" -#include "nsISupportsArray.idl" -interface nsIDocShell; +interface nsIURI; [scriptable, uuid(68389281-f6d0-4533-841d-344a2018140c)] interface nsIChromeRegistry : nsISupports @@ -85,57 +83,13 @@ interface nsIChromeRegistry : nsISupports void checkForNewChrome(); }; -[scriptable, uuid(fd1ee2f8-0238-40b0-9b54-27cf810d9c86)] -interface nsIXULChromeRegistry : nsIChromeRegistry { - - /* Applies a skin or locale to all possible packages */ - void selectSkin(in ACString skinName, in boolean useProfile); - void selectLocale(in ACString localeName, in boolean useProfile); - void deselectSkin(in ACString skinName, in boolean useProfile); - void deselectLocale(in ACString localeName, in boolean useProfile); - PRInt32 isSkinSelected(in ACString skinName, in boolean useProfile); - PRInt32 isLocaleSelected(in ACString localeName, in boolean useProfile); - - //Special additional APIs for locales and skin. - void selectLocaleForProfile(in ACString localeName, in wstring profilePath); - void selectSkinForProfile(in ACString skinName, in wstring profilePath); - +[scriptable, uuid(a1208469-47cf-4776-9062-f8b431afb6fa)] +interface nsIXULChromeRegistry : nsIChromeRegistry +{ /* Should be called when locales change to reload all chrome (including XUL). */ void reloadChrome(); - /* runtimeProvider == true: don't assert the runtime change */ - void setRuntimeProvider(in boolean runtimeProvider); - - boolean checkThemeVersion(in ACString skinName); - boolean checkLocaleVersion(in ACString localeName); - - /* Apply skin/locale to a specific package */ - void selectSkinForPackage(in ACString skinName, - in wstring packageName, - in boolean useProfile); - - void selectLocaleForPackage(in ACString localeName, - in wstring packageName, - in boolean useProfile); - - void deselectSkinForPackage(in ACString skinName, - in wstring packageName, - in boolean useProfile); - - void deselectLocaleForPackage(in ACString localeName, - in wstring packageName, - in boolean useProfile); - - boolean isSkinSelectedForPackage(in ACString skinName, - in wstring packageName, - in boolean useProfile); - - boolean isLocaleSelectedForPackage(in ACString localeName, - in wstring packageName, - in boolean useProfile); - ACString getSelectedLocale(in ACString packageName); - ACString getSelectedSkin(in ACString packageName); /* Should be called when skins change. Reloads only stylesheets. */ void refreshSkins(); diff --git a/mail/app/profile/all-thunderbird.js b/mail/app/profile/all-thunderbird.js index 84583e9691d4..84a1a21c0bc9 100644 --- a/mail/app/profile/all-thunderbird.js +++ b/mail/app/profile/all-thunderbird.js @@ -39,6 +39,8 @@ pref("general.useragent.vendor", "Thunderbird"); pref("general.useragent.vendorSub", #expand __APP_VERSION__ ); +pref("general.useragent.locale", "en-US"); +pref("general.skins.selectedSkin", "classic/1.0"); // This is this application's unique identifier used by the Extension System to identify // this application as an extension target, and by the SmartUpdate system to identify @@ -145,7 +147,6 @@ pref("mail.checkDefaultNews", false); ///////////////////////////////////////////////////////////////// // l12n and i18n -pref("general.useragent.locale", "chrome://global/locale/intl.properties"); pref("intl.charsetmenu.mailedit", "chrome://global/locale/intl.properties"); pref("intl.accept_languages", "chrome://global/locale/intl.properties"); // collationOption is only set on linux for japanese. see bug 18338 and 62015 diff --git a/profile/src/Makefile.in b/profile/src/Makefile.in index 47d1d8f439ca..0de85d87658a 100644 --- a/profile/src/Makefile.in +++ b/profile/src/Makefile.in @@ -60,6 +60,7 @@ REQUIRES = xpcom \ pref \ prefmigr \ appshell \ + chrome \ uconv \ windowwatcher \ profdirserviceprovider \ diff --git a/profile/src/nsProfile.cpp b/profile/src/nsProfile.cpp index 61eba137c8fd..5b190b40a9a0 100644 --- a/profile/src/nsProfile.cpp +++ b/profile/src/nsProfile.cpp @@ -76,7 +76,7 @@ #include "nsIDirectoryService.h" #include "nsDirectoryServiceDefs.h" #include "nsAppDirectoryServiceDefs.h" -#include "nsIChromeRegistry.h" // chromeReg +#include "nsIChromeRegistrySea.h" #include "nsIStringBundle.h" #include "nsIObserverService.h" #include "nsHashtable.h" @@ -396,7 +396,7 @@ nsProfile::StartupWithArgs(nsICmdLineService *cmdLineArgs, PRBool canInteract) } gLocaleProfiles->Remove(&key); - nsCOMPtr chromeRegistry = + nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; @@ -1674,7 +1674,7 @@ nsProfile::CreateNewProfileWithLocales(const PRUnichar* profileName, rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, getter_AddRefs(profDefaultsDir)); if (NS_FAILED(rv)) return rv; - nsCOMPtr chromeRegistry = + nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { @@ -1695,7 +1695,7 @@ nsProfile::CreateNewProfileWithLocales(const PRUnichar* profileName, // -UILocale and -contentLocale) by GetSelectedLocale() which // is done in nsAppRunner.cpp::InstallGlobalLocale() - nsCOMPtr packageRegistry = do_QueryInterface(chromeRegistry); + nsCOMPtr packageRegistry = do_QueryInterface(chromeRegistry); if ((!aUILocale || !aUILocale[0]) && packageRegistry) { nsCAutoString currentUILocaleName; rv = packageRegistry->GetSelectedLocale(NS_LITERAL_CSTRING("global"), @@ -2120,7 +2120,7 @@ nsProfile::DefineLocaleDefaultsDir() rv = directoryService->Get(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, NS_GET_IID(nsIFile), getter_AddRefs(localeDefaults)); if (NS_SUCCEEDED(rv)) { - nsCOMPtr packageRegistry = + nsCOMPtr packageRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { diff --git a/rdf/chrome/Makefile.in b/rdf/chrome/Makefile.in index 2dfdd119410f..e1deb7b00baa 100644 --- a/rdf/chrome/Makefile.in +++ b/rdf/chrome/Makefile.in @@ -1,4 +1,3 @@ -# # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 # @@ -42,7 +41,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = src build tools +DIRS = public src build tools include $(topsrcdir)/config/rules.mk diff --git a/rdf/chrome/public/Makefile.in b/rdf/chrome/public/Makefile.in new file mode 100644 index 000000000000..d3678338b5c1 --- /dev/null +++ b/rdf/chrome/public/Makefile.in @@ -0,0 +1,48 @@ +# ***** 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.org code. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corporation. +# Portions created by the Initial Developer are Copyright (C) 1998 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either of 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 ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = chrome + +XPIDLSRCS = nsIChromeRegistrySea.idl + +include $(topsrcdir)/config/rules.mk diff --git a/rdf/chrome/public/nsIChromeRegistrySea.idl b/rdf/chrome/public/nsIChromeRegistrySea.idl new file mode 100644 index 000000000000..0d26e48dcf17 --- /dev/null +++ b/rdf/chrome/public/nsIChromeRegistrySea.idl @@ -0,0 +1,92 @@ +/* -*- Mode: C++; tab-width: 2; 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 the Mozilla browser. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1999 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * pav + * Blake Ross (blaker@netscape.com) + * Benjamin Smedberg + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 "nsISupports.idl" +#include "nsIChromeRegistry.idl" + +[scriptable, uuid(ed47f6b3-8b7e-4dba-8cbd-d0560274ba4a)] +interface nsIChromeRegistrySea : nsIXULChromeRegistry +{ + /* Applies a skin or locale to all possible packages */ + void selectSkin(in ACString skinName, in boolean useProfile); + void selectLocale(in ACString localeName, in boolean useProfile); + void deselectSkin(in ACString skinName, in boolean useProfile); + void deselectLocale(in ACString localeName, in boolean useProfile); + PRInt32 isSkinSelected(in ACString skinName, in boolean useProfile); + PRInt32 isLocaleSelected(in ACString localeName, in boolean useProfile); + + //Special additional APIs for locales and skin. + void selectLocaleForProfile(in ACString localeName, in wstring profilePath); + void selectSkinForProfile(in ACString skinName, in wstring profilePath); + + /* runtimeProvider == true: don't assert the runtime change */ + void setRuntimeProvider(in boolean runtimeProvider); + + boolean checkThemeVersion(in ACString skinName); + boolean checkLocaleVersion(in ACString localeName); + + /* Apply skin/locale to a specific package */ + void selectSkinForPackage(in ACString skinName, + in wstring packageName, + in boolean useProfile); + + void selectLocaleForPackage(in ACString localeName, + in wstring packageName, + in boolean useProfile); + + void deselectSkinForPackage(in ACString skinName, + in wstring packageName, + in boolean useProfile); + + void deselectLocaleForPackage(in ACString localeName, + in wstring packageName, + in boolean useProfile); + + boolean isSkinSelectedForPackage(in ACString skinName, + in wstring packageName, + in boolean useProfile); + + boolean isLocaleSelectedForPackage(in ACString localeName, + in wstring packageName, + in boolean useProfile); + + ACString getSelectedSkin(in ACString packageName); +}; diff --git a/rdf/chrome/src/nsChromeRegistry.cpp b/rdf/chrome/src/nsChromeRegistry.cpp index 856cb06e0a7f..fdca05dc8a77 100644 --- a/rdf/chrome/src/nsChromeRegistry.cpp +++ b/rdf/chrome/src/nsChromeRegistry.cpp @@ -188,9 +188,10 @@ nsChromeRegistry::~nsChromeRegistry() } -NS_IMPL_THREADSAFE_ISUPPORTS5(nsChromeRegistry, +NS_IMPL_THREADSAFE_ISUPPORTS6(nsChromeRegistry, nsIChromeRegistry, nsIXULChromeRegistry, + nsIChromeRegistrySea, nsIXULOverlayProvider, nsIObserver, nsISupportsWeakReference) diff --git a/rdf/chrome/src/nsChromeRegistry.h b/rdf/chrome/src/nsChromeRegistry.h index a82aa2aebbdc..b127147015a2 100644 --- a/rdf/chrome/src/nsChromeRegistry.h +++ b/rdf/chrome/src/nsChromeRegistry.h @@ -50,6 +50,7 @@ class nsIDOMWindowInternal; class nsIDocument; #include "nsIChromeRegistry.h" +#include "nsIChromeRegistrySea.h" #include "nsIXULOverlayProvider.h" #include "nsIRDFCompositeDataSource.h" #include "nsIObserver.h" @@ -63,7 +64,7 @@ class nsIDocument; #define NS_CHROMEREGISTRY_CID \ { 0xd8c7d8a2, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } } -class nsChromeRegistry : public nsIXULChromeRegistry, +class nsChromeRegistry : public nsIChromeRegistrySea, public nsIXULOverlayProvider, public nsIObserver, public nsSupportsWeakReference @@ -75,6 +76,7 @@ public: NS_DECL_NSICHROMEREGISTRY NS_DECL_NSIXULCHROMEREGISTRY NS_DECL_NSIXULOVERLAYPROVIDER + NS_DECL_NSICHROMEREGISTRYSEA NS_DECL_NSIOBSERVER diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 52f98f2beff7..3df14b1d212b 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -93,9 +93,8 @@ function Startup() .getService(Components.interfaces.nsIPrefBranch); if (!isExtensions) { gExtensionsView.addEventListener("richview-select", onThemeSelect, false); - var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"] - .getService(Components.interfaces.nsIXULChromeRegistry); - gCurrentTheme = cr.getSelectedSkin("global"); + + gCurrentTheme = pref.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN); var useThemeButton = document.getElementById("useThemeButton"); useThemeButton.hidden = false; @@ -634,23 +633,14 @@ var gExtensionsViewController = { cmd_useTheme: function (aSelectedItem) { - var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"] - .getService(Components.interfaces.nsIXULChromeRegistry); var pref = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); gCurrentTheme = aSelectedItem.getAttribute("internalName"); - var inUse = cr.isSkinSelected(gCurrentTheme , true); - if (inUse == Components.interfaces.nsIChromeRegistry.FULL) - return; - - pref.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, gCurrentTheme); - + // Set this pref so the user can reset the theme in safe mode pref.setCharPref(PREF_EM_LAST_SELECTED_SKIN, gCurrentTheme); - cr.selectSkin(gCurrentTheme, true); - cr.refreshSkins(); - - + pref.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, gCurrentTheme); + // disable the useThemeButton gExtensionsViewController.onCommandUpdate(); }, diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index e2f0ef7bf950..64f72a61c017 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -70,8 +70,6 @@ #include "nsIEventQueueService.h" #include "nsIExtensionManager.h" #include "nsIIOService.h" -#include "nsILocaleService.h" -#include "nsILookAndFeel.h" #include "nsIObserverService.h" #include "nsINativeAppSupport.h" #include "nsIPref.h" @@ -89,7 +87,6 @@ #include "nsCRT.h" #include "nsCOMPtr.h" #include "nsNetUtil.h" -#include "nsWidgetsCID.h" #include "nsXPCOM.h" #include "nsXPIDLString.h" @@ -145,9 +142,6 @@ #define DEBUG_CMD_LINE #endif -#define UILOCALE_CMD_LINE_ARG "-UILocale" -#define CONTENTLOCALE_CMD_LINE_ARG "-contentLocale" - extern "C" void ShowOSAlert(const char* aMessage); #define HELP_SPACER_1 "\t" @@ -769,100 +763,6 @@ DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool heedGeneralStartupPrefs, P return NS_OK; } -// match OS locale -static char kMatchOSLocalePref[] = "intl.locale.matchOS"; - -nsresult -getCountry(const nsAString& lc_name, nsAString& aCountry) -{ - - nsresult result = NS_OK; - - PRInt32 dash = lc_name.FindChar('-'); - if (dash > 0) - aCountry = Substring(lc_name, dash+1, lc_name.Length()-dash); - else - result = NS_ERROR_FAILURE; - - return result; -} - -static nsresult -getUILangCountry(nsAString& aUILang, nsAString& aCountry) -{ - nsresult result; - // get a locale service - nsCOMPtr localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &result); - NS_ASSERTION(NS_SUCCEEDED(result),"getUILangCountry: get locale service failed"); - - result = localeService->GetLocaleComponentForUserAgent(aUILang); - NS_ASSERTION(NS_SUCCEEDED(result), - "getUILangCountry: get locale componet for user agent failed"); - result = getCountry(aUILang, aCountry); - return result; -} - -// update global locale if possible (in case when user-*.rdf can be updated) -// so that any apps after this can be invoked in the UILocale and contentLocale -static nsresult InstallGlobalLocale(nsICmdLineService *cmdLineArgs) -{ - nsresult rv = NS_OK; - - // check the pref first - nsCOMPtr prefService(do_GetService(NS_PREF_CONTRACTID)); - PRBool matchOS = PR_FALSE; - if (prefService) - prefService->GetBoolPref(kMatchOSLocalePref, &matchOS); - - // match os locale - nsAutoString uiLang; - nsAutoString country; - if (matchOS) { - // compute lang and region code only when needed! - rv = getUILangCountry(uiLang, country); - } - - nsXPIDLCString cmdUI; - rv = cmdLineArgs->GetCmdLineValue(UILOCALE_CMD_LINE_ARG, getter_Copies(cmdUI)); - if (NS_SUCCEEDED(rv)){ - if (cmdUI) { - nsCAutoString UILocaleName(cmdUI); - nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); - if (chromeRegistry) - rv = chromeRegistry->SelectLocale(UILocaleName, PR_FALSE); - } - } - // match OS when no cmdline override - if (!cmdUI && matchOS) { - nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); - if (chromeRegistry) { - chromeRegistry->SetRuntimeProvider(PR_TRUE); - rv = chromeRegistry->SelectLocale(NS_ConvertUCS2toUTF8(uiLang), PR_FALSE); - } - } - - nsXPIDLCString cmdContent; - rv = cmdLineArgs->GetCmdLineValue(CONTENTLOCALE_CMD_LINE_ARG, getter_Copies(cmdContent)); - if (NS_SUCCEEDED(rv)){ - if (cmdContent) { - nsCAutoString contentLocaleName(cmdContent); - nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); - if(chromeRegistry) - rv = chromeRegistry->SelectLocale(contentLocaleName, PR_FALSE); - } - } - // match OS when no cmdline override - if (!cmdContent && matchOS) { - nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); - if (chromeRegistry) { - chromeRegistry->SetRuntimeProvider(PR_TRUE); - rv = chromeRegistry->SelectLocale(NS_ConvertUCS2toUTF8(country), PR_FALSE); - } - } - - return NS_OK; -} - // English text needs to go into a dtd file. // But when this is called we have no components etc. These strings must either be // here, or in a native resource file. @@ -958,7 +858,6 @@ public: nsresult RegisterProfileService(nsIToolkitProfileService* aProfileService); nsresult InitEventQueue(); nsresult SetWindowCreator(nsINativeAppSupport* native); - void CheckAccessibleSkin(); private: nsIServiceManager* mServiceManager; @@ -1086,33 +985,6 @@ ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native) return wwatch->SetWindowCreator(creator); } -NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); - -void -ScopedXPCOMStartup::CheckAccessibleSkin() -{ - nsCOMPtr lookAndFeel (do_GetService(kLookAndFeelCID)); - - if (lookAndFeel) { - PRInt32 useAccessibilityTheme = 0; - - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_UseAccessibilityTheme, - useAccessibilityTheme); - - if (useAccessibilityTheme) { - // If OS accessibility is active, use the classic skin, which obeys the - // system accessibility colors. - nsCOMPtr chromeRegistry - (do_GetService(NS_CHROMEREGISTRY_CONTRACTID)); - if (chromeRegistry) { - // Make change this session only - chromeRegistry->SetRuntimeProvider(PR_TRUE); - chromeRegistry->SelectSkin(NS_LITERAL_CSTRING("classic/1.0"), PR_TRUE); - } - } - } -} - // don't modify aAppDir directly... clone it first static int VerifyInstallation(nsIFile* aAppDir) @@ -1429,8 +1301,6 @@ ShowProfileManager(nsIToolkitProfileService* aProfileSvc, NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); { //extra scoping is needed so we release these components before xpcom shutdown - xpcom.CheckAccessibleSkin(); - nsCOMPtr windowWatcher (do_GetService(NS_WINDOWWATCHER_CONTRACTID)); nsCOMPtr ioParamBlock @@ -2036,8 +1906,6 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) io->SetOffline(PR_TRUE); } - xpcom.CheckAccessibleSkin(); - { NS_TIMELINE_ENTER("startupNotifier"); nsCOMPtr startupNotifier @@ -2118,10 +1986,6 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) (do_GetService("@mozilla.org/appshell/commandLineService;1")); NS_ENSURE_TRUE(cmdLineArgs, 1); - NS_TIMELINE_ENTER("InstallGlobalLocale"); - InstallGlobalLocale(cmdLineArgs); - NS_TIMELINE_LEAVE("InstallGlobalLocale"); - // This will go away once Components are handling there own commandlines // if we have no command line arguments, we need to heed the // "general.startup.*" prefs diff --git a/xpfe/bootstrap/Makefile.in b/xpfe/bootstrap/Makefile.in index 1531a3d624c4..1630a8337159 100644 --- a/xpfe/bootstrap/Makefile.in +++ b/xpfe/bootstrap/Makefile.in @@ -87,6 +87,7 @@ REQUIRES = xpcom \ docshell \ locale \ profile \ + chrome \ $(NULL) # for jprof REQUIRES += jprof diff --git a/xpfe/bootstrap/nsAppRunner.cpp b/xpfe/bootstrap/nsAppRunner.cpp index 007984398b4d..f18cbca45ebb 100644 --- a/xpfe/bootstrap/nsAppRunner.cpp +++ b/xpfe/bootstrap/nsAppRunner.cpp @@ -76,7 +76,7 @@ #include "nsICategoryManager.h" #include "nsXPIDLString.h" #include "nsIXULWindow.h" -#include "nsIChromeRegistry.h" +#include "nsIChromeRegistrySea.h" #include "nsIEventQueueService.h" #include "nsDirectoryServiceDefs.h" #include "nsBuildID.h" @@ -868,14 +868,14 @@ static nsresult InstallGlobalLocale(nsICmdLineService *cmdLineArgs) if (NS_SUCCEEDED(rv)){ if (cmdUI) { nsCAutoString UILocaleName(cmdUI); - nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); + nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); if (chromeRegistry) rv = chromeRegistry->SelectLocale(UILocaleName, PR_FALSE); } } // match OS when no cmdline override if (!cmdUI && matchOS) { - nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); + nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); if (chromeRegistry) { chromeRegistry->SetRuntimeProvider(PR_TRUE); rv = chromeRegistry->SelectLocale(NS_ConvertUCS2toUTF8(uiLang), PR_FALSE); @@ -887,14 +887,14 @@ static nsresult InstallGlobalLocale(nsICmdLineService *cmdLineArgs) if (NS_SUCCEEDED(rv)){ if (cmdContent) { nsCAutoString contentLocaleName(cmdContent); - nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); + nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); if(chromeRegistry) rv = chromeRegistry->SelectLocale(contentLocaleName, PR_FALSE); } } // match OS when no cmdline override if (!cmdContent && matchOS) { - nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); + nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv); if (chromeRegistry) { chromeRegistry->SetRuntimeProvider(PR_TRUE); rv = chromeRegistry->SelectLocale(NS_ConvertUCS2toUTF8(country), PR_FALSE); @@ -918,7 +918,7 @@ static void CheckUseAccessibleSkin() if (useAccessibilityTheme) { // Use classic skin, it obeys the system's accessibility theme - nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID); + nsCOMPtr chromeRegistry = do_GetService(NS_CHROMEREGISTRY_CONTRACTID); if (chromeRegistry) { chromeRegistry->SetRuntimeProvider(PR_TRUE); // The skin change isn't permanent chromeRegistry->SelectSkin(NS_LITERAL_CSTRING("classic/1.0"), PR_TRUE); diff --git a/xpfe/browser/resources/content/navigator.js b/xpfe/browser/resources/content/navigator.js index fb06708f4ce3..93467ed92ca8 100644 --- a/xpfe/browser/resources/content/navigator.js +++ b/xpfe/browser/resources/content/navigator.js @@ -1875,7 +1875,7 @@ function applyTheme(themeName) return; var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"] - .getService(Components.interfaces.nsIXULChromeRegistry); + .getService(Components.interfaces.nsIChromeRegistrySea); var oldTheme = false; try { @@ -2342,7 +2342,7 @@ function checkTheme() { var theSkinKids = document.getElementById("theme"); var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"] - .getService(Components.interfaces.nsIXULChromeRegistry); + .getService(Components.interfaces.nsIChromeRegistrySea); for (var i = 0; i < theSkinKids.childNodes.length; ++i) { var child = theSkinKids.childNodes[i]; var id=child.getAttribute("id"); diff --git a/xpfe/components/prefwindow/resources/content/nsPrefWindow.js b/xpfe/components/prefwindow/resources/content/nsPrefWindow.js index b0624e5600c8..aa45b2efaac6 100644 --- a/xpfe/components/prefwindow/resources/content/nsPrefWindow.js +++ b/xpfe/components/prefwindow/resources/content/nsPrefWindow.js @@ -98,7 +98,7 @@ nsPrefWindow.prototype = try { this.pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(null); - this.chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService(Components.interfaces.nsIXULChromeRegistry); + this.chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService(Components.interfaces.nsIChromeRegistrySea); this.observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); } catch(e) diff --git a/xpfe/components/prefwindow/resources/content/pref-themes.js b/xpfe/components/prefwindow/resources/content/pref-themes.js index 7e40e93e009e..e61fd1d25bf8 100644 --- a/xpfe/components/prefwindow/resources/content/pref-themes.js +++ b/xpfe/components/prefwindow/resources/content/pref-themes.js @@ -44,9 +44,8 @@ var gShowDescription = true; var gData; try { - var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService(); - if (chromeRegistry) - chromeRegistry = chromeRegistry.QueryInterface(Components.interfaces.nsIXULChromeRegistry); + var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"]. + getService(Components.interfaces.nsIChromeRegistrySea); } catch(e) {} @@ -108,9 +107,8 @@ function applySkin() if (theme == data.name) return; try { - var reg = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService(); - if (reg) - reg = reg.QueryInterface(Components.interfaces.nsIXULChromeRegistry); + var reg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]. + getService(Components.interfaces.nsIChromeRegistrySea); } catch(e) {} diff --git a/xpinstall/packager/packages-os2 b/xpinstall/packager/packages-os2 index 6c9f0ad1de54..c58ad724e7e8 100644 --- a/xpinstall/packager/packages-os2 +++ b/xpinstall/packager/packages-os2 @@ -88,6 +88,7 @@ bin/components/appshell.dll bin/components/appcomps.dll bin/components/autocomplete.xpt bin/components/bookmarks.xpt +bin/components/chrome.xpt bin/components/directory.xpt bin/components/downloadmanager.xpt ;bin/components/embedcomponents.dll diff --git a/xpinstall/packager/packages-unix b/xpinstall/packager/packages-unix index 949b9b9bece3..4e3bc4fed1ad 100644 --- a/xpinstall/packager/packages-unix +++ b/xpinstall/packager/packages-unix @@ -96,6 +96,7 @@ bin/components/search.xpt bin/components/autocomplete.xpt bin/components/appshell.xpt bin/components/caps.xpt +bin/components/chrome.xpt bin/components/cookie.xpt bin/components/libjsd.so bin/components/jsdservice.xpt diff --git a/xpinstall/packager/packages-win b/xpinstall/packager/packages-win index 07ac7f2ed0ae..a2a33bf6330a 100644 --- a/xpinstall/packager/packages-win +++ b/xpinstall/packager/packages-win @@ -79,6 +79,7 @@ bin\components\autocomplete.xpt bin\components\bookmarks.xpt bin\components\directory.xpt bin\components\downloadmanager.xpt +bin\components\chrome.xpt ; These 3 files need to be in browser.xpi as well as xpcom.xpi (listed in xpcom-win.pkg) bin\nspr4.dll diff --git a/xpinstall/src/Makefile.in b/xpinstall/src/Makefile.in index f85188b9992d..d22a4abf5902 100644 --- a/xpinstall/src/Makefile.in +++ b/xpinstall/src/Makefile.in @@ -79,6 +79,7 @@ REQUIRES = xpcom \ docshell \ cookie \ layout \ + chrome \ $(ZLIB_REQUIRES) \ $(NULL) diff --git a/xpinstall/src/nsSoftwareUpdateRun.cpp b/xpinstall/src/nsSoftwareUpdateRun.cpp index 30449fc0449c..e7690f91834d 100644 --- a/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -71,6 +71,10 @@ #include "nsIJAR.h" #include "nsIPrincipal.h" +#ifndef MOZ_XUL_APP +#include "nsIChromeRegistrySea.h" +#endif + static NS_DEFINE_CID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); @@ -606,6 +610,9 @@ extern "C" void RunChromeInstallOnThread(void *data) // make sure we've got a chrome registry -- can't proceed if not nsIXULChromeRegistry* reg = info->GetChromeRegistry(); +#ifndef MOZ_XUL_APP + nsCOMPtr cr = do_QueryInterface(reg); +#endif if (reg) { // build up jar: URL @@ -636,21 +643,27 @@ extern "C" void RunChromeInstallOnThread(void *data) if ( isSkin ) { rv = reg->InstallSkin(spec.get(), PR_TRUE, PR_FALSE); - if (NS_SUCCEEDED(rv) && selected) - { - NS_ConvertUCS2toUTF8 utf8Args(info->GetArguments()); - rv = reg->SelectSkin(utf8Args, PR_TRUE); - } + +#ifndef MOZ_XUL_APP + if (NS_SUCCEEDED(rv) && selected && cr) + { + NS_ConvertUCS2toUTF8 utf8Args(info->GetArguments()); + cr->SelectSkin(utf8Args, PR_TRUE); + } +#endif } if ( isLocale ) { rv = reg->InstallLocale(spec.get(), PR_TRUE); - if (NS_SUCCEEDED(rv) && selected) + +#ifndef MOZ_XUL_APP + if (NS_SUCCEEDED(rv) && selected && cr) { NS_ConvertUCS2toUTF8 utf8Args(info->GetArguments()); - rv = reg->SelectLocale(utf8Args, PR_TRUE); + cr->SelectLocale(utf8Args, PR_TRUE); } +#endif } // now that all types are registered try to activate