Back to index

lightning-sunbird  0.9+nobinonly
nsChromeRegistry.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Original Author: David W. Hyatt (hyatt@netscape.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 class nsIAtom;
00040 class nsICSSStyleSheet;
00041 class nsIRDFService;
00042 class nsIRDFDataSource;
00043 class nsIRDFResource;
00044 class nsIRDFNode;
00045 class nsISimpleEnumerator;
00046 class nsSupportsHashtable;
00047 class nsIRDFContainer;
00048 class nsIRDFContainerUtils;
00049 class nsIDOMWindowInternal;
00050 class nsIDocument;
00051 
00052 #include "nsIChromeRegistry.h"
00053 #include "nsIChromeRegistrySea.h"
00054 #include "nsIXULOverlayProvider.h"
00055 #include "nsIRDFCompositeDataSource.h"
00056 #include "nsIObserver.h"
00057 #include "nsWeakReference.h"
00058 #include "nsString.h"
00059 #include "nsIZipReader.h"
00060 #include "nsCOMArray.h"
00061      
00062 // for component registration
00063 // {D8C7D8A2-E84C-11d2-BF87-00105A1B0627}
00064 #define NS_CHROMEREGISTRY_CID \
00065 { 0xd8c7d8a2, 0xe84c, 0x11d2, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
00066 
00067 class nsChromeRegistry : public nsIChromeRegistrySea,
00068                          public nsIXULOverlayProvider,
00069                          public nsIObserver,
00070                          public nsSupportsWeakReference
00071 {
00072 public:
00073   NS_DECL_ISUPPORTS
00074 
00075   // nsIChromeRegistry methods:
00076   NS_DECL_NSICHROMEREGISTRY
00077   NS_DECL_NSIXULCHROMEREGISTRY
00078   NS_DECL_NSIXULOVERLAYPROVIDER
00079   NS_DECL_NSICHROMEREGISTRYSEA
00080 
00081   NS_DECL_NSIOBSERVER
00082 
00083   // nsChromeRegistry methods:
00084   nsChromeRegistry();
00085   virtual ~nsChromeRegistry();
00086 
00087   nsresult Init();
00088 
00089   // used by the protocol handler
00090   static nsresult Canonify(nsIURI* aChromeURL);
00091 
00092 public:
00093   static nsresult FollowArc(nsIRDFDataSource *aDataSource,
00094                             nsACString& aResult,
00095                             nsIRDFResource* aChromeResource,
00096                             nsIRDFResource* aProperty);
00097 
00098   static nsresult UpdateArc(nsIRDFDataSource *aDataSource, nsIRDFResource* aSource, nsIRDFResource* aProperty, 
00099                             nsIRDFNode *aTarget, PRBool aRemove);
00100 
00101 protected:
00102   nsresult GetDynamicDataSource(nsIURI *aChromeURL, PRBool aIsOverlay, PRBool aUseProfile, PRBool aCreateDS, nsIRDFDataSource **aResult);
00103   nsresult GetURIList(nsIRDFDataSource *aDS, nsIRDFResource *aResource, nsCOMArray<nsIURI>& aArray);
00104   nsresult GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOverlay, nsISimpleEnumerator **aResult);
00105 
00106   PRBool   IsOverlayAllowed(nsIURI *aChromeURI);
00107 
00108   nsresult GetResource(const nsACString& aChromeType, nsIRDFResource** aResult);
00109   
00110   nsresult UpdateDynamicDataSource(nsIRDFDataSource *aDataSource,
00111                                    nsIRDFResource *aResource,
00112                                    PRBool aIsOverlay, PRBool
00113                                    aUseProfile, PRBool aRemove);
00114   nsresult UpdateDynamicDataSources(nsIRDFDataSource *aDataSource,
00115                                     PRBool aIsOverlay,
00116                                     PRBool aUseProfile, PRBool
00117                                     aRemove);
00118   nsresult WriteInfoToDataSource(const char *aDocURI,
00119                                  const PRUnichar *aOverlayURI,
00120                                  PRBool aIsOverlay, PRBool
00121                                  aUseProfile, PRBool aRemove);
00122  
00123   nsresult LoadStyleSheetWithURL(nsIURI* aURL, PRBool aAllowUnsafeRules,
00124                                  nsICSSStyleSheet** aSheet);
00125 
00126   nsresult LoadInstallDataSource();
00127   nsresult LoadProfileDataSource();
00128 
00129   void FlushSkinCaches();
00130   void FlushAllCaches();
00131 
00132 private:
00133   nsresult LoadDataSource(const nsACString &aFileName,
00134                           nsIRDFDataSource **aResult,
00135                           PRBool aUseProfileDirOnly = PR_FALSE,
00136                           const char *aProfilePath = nsnull);
00137 
00138   static nsresult GetProfileRoot(nsACString& aFileURL);
00139   static nsresult GetInstallRoot(nsIFile** aFileURL);
00140 
00141   nsresult RefreshWindow(nsIDOMWindowInternal* aWindow);
00142 
00143   nsresult GetArcs(nsIRDFDataSource* aDataSource,
00144                    const nsACString& aType,
00145                    nsISimpleEnumerator** aResult);
00146 
00147   nsresult AddToCompositeDataSource(PRBool aUseProfile);
00148 
00149   nsresult FlagXPCNativeWrappers();
00150 
00151   nsresult GetBaseURL(const nsACString& aPackage,
00152                       const nsACString& aProvider, 
00153                       nsACString& aBaseURL);
00154 
00155   nsresult InitOverrideJAR();
00156   nsresult GetOverrideURL(const nsACString& aPackage,
00157                           const nsACString& aProvider,
00158                           const nsACString& aPath,
00159                           nsACString& aResult);
00160   
00161   nsresult VerifyCompatibleProvider(nsIRDFResource* aPackageResource,
00162                                     nsIRDFResource* aProviderResource,
00163                                     nsIRDFResource* aArc,
00164                                     PRBool *aAcceptable);
00165 
00166   nsresult FindProvider(const nsACString& aPackage,
00167                         const nsACString& aProvider,
00168                         nsIRDFResource *aArc,
00169                         nsIRDFNode **aSelectedProvider);
00170 
00171   nsresult SelectPackageInProvider(nsIRDFResource *aPackageList,
00172                                    const nsACString& aPackage,
00173                                    const nsACString& aProvider,
00174                                    const nsACString& aProviderName,
00175                                    nsIRDFResource *aArc,
00176                                    nsIRDFNode **aSelectedProvider);
00177 
00178   nsresult SetProvider(const nsACString& aProvider,
00179                        nsIRDFResource* aSelectionArc,
00180                        const nsACString& aProviderName,
00181                        PRBool aAllUsers, 
00182                        const char *aProfilePath, 
00183                        PRBool aIsAdding);
00184 
00185   nsresult SetProviderForPackage(const nsACString& aProvider,
00186                                  nsIRDFResource* aPackageResource, 
00187                                  nsIRDFResource* aProviderPackageResource, 
00188                                  nsIRDFResource* aSelectionArc, 
00189                                  PRBool aAllUsers, const char *aProfilePath, 
00190                                  PRBool aIsAdding);
00191 
00192   nsresult SelectProviderForPackage(const nsACString& aProviderType,
00193                                     const nsACString& aProviderName, 
00194                                     const PRUnichar *aPackageName, 
00195                                     nsIRDFResource* aSelectionArc, 
00196                                     PRBool aUseProfile, PRBool aIsAdding);
00197 
00198   nsresult GetSelectedProvider(const nsACString& aPackage,
00199                                const nsACString& aProviderName,
00200                                nsIRDFResource* aSelectionArc,
00201                                nsACString& aResult);
00202   
00203   nsresult CheckProviderVersion (const nsACString& aProviderType,
00204                                  const nsACString& aProviderName,
00205                                  nsIRDFResource* aSelectionArc,
00206                                  PRBool *aCompatible);
00207 
00208   nsresult IsProviderSelected(const nsACString& aProvider,
00209                               const nsACString& aProviderName,
00210                               nsIRDFResource* aSelectionArc,
00211                               PRBool aUseProfile, PRInt32* aResult);
00212   
00213   nsresult IsProviderSelectedForPackage(const nsACString& aProviderType,
00214                                         const nsACString& aProviderName, 
00215                                         const PRUnichar *aPackageName, 
00216                                         nsIRDFResource* aSelectionArc, 
00217                                         PRBool aUseProfile, PRBool* aResult);
00218   nsresult IsProviderSetForPackage(const nsACString& aProvider,
00219                                      nsIRDFResource* aPackageResource, 
00220                                      nsIRDFResource* aProviderPackageResource, 
00221                                      nsIRDFResource* aSelectionArc, 
00222                                      PRBool aUseProfile, PRBool* aResult);
00223 
00224   nsresult InstallProvider(const nsACString& aProviderType,
00225                              const nsACString& aBaseURL,
00226                              PRBool aUseProfile, PRBool aAllowScripts, PRBool aRemove);
00227   nsresult UninstallProvider(const nsACString& aProviderType, const nsACString& aProviderName, PRBool aUseProfile);
00228 
00229   nsresult ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength);
00230 
00231   PRBool GetProviderCount(const nsACString& aProviderType, nsIRDFDataSource* aDataSource);
00232 
00233 protected:
00234   nsCString mProfileRoot;
00235   nsCString mInstallRoot;
00236 
00237   nsCOMPtr<nsIRDFCompositeDataSource> mChromeDataSource;
00238   nsCOMPtr<nsIRDFDataSource> mInstallDirChromeDataSource;
00239   nsCOMPtr<nsIRDFDataSource> mUIDataSource;
00240 
00241   nsSupportsHashtable* mDataSourceTable;
00242   nsIRDFService* mRDFService;
00243   nsIRDFContainerUtils* mRDFContainerUtils;
00244 
00245   // Resources
00246   nsCOMPtr<nsIRDFResource> mSelectedSkin;
00247   nsCOMPtr<nsIRDFResource> mSelectedLocale;
00248   nsCOMPtr<nsIRDFResource> mBaseURL;
00249   nsCOMPtr<nsIRDFResource> mPackages;
00250   nsCOMPtr<nsIRDFResource> mPackage;
00251   nsCOMPtr<nsIRDFResource> mName;
00252   nsCOMPtr<nsIRDFResource> mImage;
00253   nsCOMPtr<nsIRDFResource> mLocType;
00254   nsCOMPtr<nsIRDFResource> mAllowScripts;
00255   nsCOMPtr<nsIRDFResource> mHasOverlays;
00256   nsCOMPtr<nsIRDFResource> mHasStylesheets;
00257   nsCOMPtr<nsIRDFResource> mSkinVersion;
00258   nsCOMPtr<nsIRDFResource> mLocaleVersion;
00259   nsCOMPtr<nsIRDFResource> mPackageVersion;
00260   nsCOMPtr<nsIRDFResource> mDisabled;
00261   nsCOMPtr<nsIRDFResource> mXPCNativeWrappers;
00262 
00263   nsCOMPtr<nsIZipReader> mOverrideJAR;
00264   nsCString              mOverrideJARURL;
00265   
00266   // useful atoms - these are static atoms, so don't use nsCOMPtr
00267   static nsIAtom* sCPrefix;            // "c"
00268   
00269   PRPackedBool mInstallInitialized;
00270   PRPackedBool mProfileInitialized;
00271   
00272   PRPackedBool mRuntimeProvider;
00273 
00274   // Boolean that indicates we should batch flushes of the main
00275   // chrome.rdf file.
00276   PRPackedBool mBatchInstallFlushes;
00277 
00278   // make sure we only look once for the JAR override
00279   PRPackedBool mSearchedForOverride;
00280   
00281   // if we find an old profile overlayinfo/ directory structure, use it
00282   // else use the new flat files
00283   PRPackedBool mLegacyOverlayinfo;
00284 };