1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/chrome/src/nsChromeRegistry.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsChromeRegistry_h 1.10 +#define nsChromeRegistry_h 1.11 + 1.12 +#include "nsIToolkitChromeRegistry.h" 1.13 +#include "nsIObserver.h" 1.14 +#include "nsWeakReference.h" 1.15 + 1.16 +#ifdef MOZ_XUL 1.17 +#include "nsIXULOverlayProvider.h" 1.18 +#endif 1.19 + 1.20 +#include "nsString.h" 1.21 +#include "nsURIHashKey.h" 1.22 +#include "nsInterfaceHashtable.h" 1.23 +#include "nsXULAppAPI.h" 1.24 +#include "nsIXPConnect.h" 1.25 + 1.26 +#include "mozilla/FileLocation.h" 1.27 + 1.28 +class nsIDOMWindow; 1.29 +class nsIPrefBranch; 1.30 +class nsIURL; 1.31 + 1.32 +// The chrome registry is actually split between nsChromeRegistryChrome and 1.33 +// nsChromeRegistryContent. The work/data that is common to both resides in 1.34 +// the shared nsChromeRegistry implementation, with operations that only make 1.35 +// sense for one side erroring out in the other. 1.36 + 1.37 +// for component registration 1.38 +// {47049e42-1d87-482a-984d-56ae185e367a} 1.39 +#define NS_CHROMEREGISTRY_CID \ 1.40 +{ 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } } 1.41 + 1.42 +class nsChromeRegistry : public nsIToolkitChromeRegistry, 1.43 +#ifdef MOZ_XUL 1.44 + public nsIXULOverlayProvider, 1.45 +#endif 1.46 + public nsIObserver, 1.47 + public nsSupportsWeakReference 1.48 +{ 1.49 +public: 1.50 + NS_DECL_ISUPPORTS 1.51 + 1.52 + // nsIXULChromeRegistry methods: 1.53 + NS_IMETHOD ReloadChrome(); 1.54 + NS_IMETHOD RefreshSkins(); 1.55 + NS_IMETHOD AllowScriptsForPackage(nsIURI* url, 1.56 + bool* _retval); 1.57 + NS_IMETHOD AllowContentToAccess(nsIURI* url, 1.58 + bool* _retval); 1.59 + 1.60 + // nsIChromeRegistry methods: 1.61 + NS_IMETHOD_(bool) WrappersEnabled(nsIURI *aURI); 1.62 + NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult); 1.63 + 1.64 + // nsChromeRegistry methods: 1.65 + nsChromeRegistry() : mInitialized(false) { } 1.66 + virtual ~nsChromeRegistry(); 1.67 + 1.68 + virtual nsresult Init(); 1.69 + 1.70 + static already_AddRefed<nsIChromeRegistry> GetService(); 1.71 + 1.72 + static nsChromeRegistry* gChromeRegistry; 1.73 + 1.74 + static nsresult Canonify(nsIURL* aChromeURL); 1.75 + 1.76 +protected: 1.77 + void FlushSkinCaches(); 1.78 + void FlushAllCaches(); 1.79 + 1.80 + // Update the selected locale used by the chrome registry, and fire a 1.81 + // notification about this change 1.82 + virtual nsresult UpdateSelectedLocale() = 0; 1.83 + 1.84 + static void LogMessage(const char* aMsg, ...); 1.85 + static void LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber, uint32_t flags, 1.86 + const char* aMsg, ...); 1.87 + 1.88 + virtual nsIURI* GetBaseURIFromPackage(const nsCString& aPackage, 1.89 + const nsCString& aProvider, 1.90 + const nsCString& aPath) = 0; 1.91 + virtual nsresult GetFlagsFromPackage(const nsCString& aPackage, 1.92 + uint32_t* aFlags) = 0; 1.93 + 1.94 + nsresult SelectLocaleFromPref(nsIPrefBranch* prefs); 1.95 + 1.96 + static nsresult RefreshWindow(nsIDOMWindow* aWindow); 1.97 + static nsresult GetProviderAndPath(nsIURL* aChromeURL, 1.98 + nsACString& aProvider, nsACString& aPath); 1.99 + 1.100 +public: 1.101 + static already_AddRefed<nsChromeRegistry> GetSingleton(); 1.102 + 1.103 + struct ManifestProcessingContext 1.104 + { 1.105 + ManifestProcessingContext(NSLocationType aType, mozilla::FileLocation &aFile) 1.106 + : mType(aType) 1.107 + , mFile(aFile) 1.108 + { } 1.109 + 1.110 + ~ManifestProcessingContext() 1.111 + { } 1.112 + 1.113 + nsIURI* GetManifestURI(); 1.114 + nsIXPConnect* GetXPConnect(); 1.115 + 1.116 + already_AddRefed<nsIURI> ResolveURI(const char* uri); 1.117 + 1.118 + NSLocationType mType; 1.119 + mozilla::FileLocation mFile; 1.120 + nsCOMPtr<nsIURI> mManifestURI; 1.121 + nsCOMPtr<nsIXPConnect> mXPConnect; 1.122 + }; 1.123 + 1.124 + virtual void ManifestContent(ManifestProcessingContext& cx, int lineno, 1.125 + char *const * argv, bool platform, 1.126 + bool contentaccessible) = 0; 1.127 + virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno, 1.128 + char *const * argv, bool platform, 1.129 + bool contentaccessible) = 0; 1.130 + virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno, 1.131 + char *const * argv, bool platform, 1.132 + bool contentaccessible) = 0; 1.133 + virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno, 1.134 + char *const * argv, bool platform, 1.135 + bool contentaccessible) = 0; 1.136 + virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno, 1.137 + char *const * argv, bool platform, 1.138 + bool contentaccessible) = 0; 1.139 + virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno, 1.140 + char *const * argv, bool platform, 1.141 + bool contentaccessible) = 0; 1.142 + virtual void ManifestResource(ManifestProcessingContext& cx, int lineno, 1.143 + char *const * argv, bool platform, 1.144 + bool contentaccessible) = 0; 1.145 + 1.146 + // Available flags 1.147 + enum { 1.148 + // This is a "platform" package (e.g. chrome://global-platform/). 1.149 + // Appends one of win/ unix/ mac/ to the base URI. 1.150 + PLATFORM_PACKAGE = 1 << 0, 1.151 + 1.152 + // This package should use the new XPCNativeWrappers to separate 1.153 + // content from chrome. This flag is currently unused (because we call 1.154 + // into xpconnect at registration time). 1.155 + XPCNATIVEWRAPPERS = 1 << 1, 1.156 + 1.157 + // Content script may access files in this package 1.158 + CONTENT_ACCESSIBLE = 1 << 2 1.159 + }; 1.160 + 1.161 + bool mInitialized; 1.162 + 1.163 + // "Override" table (chrome URI string -> real URI) 1.164 + nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable; 1.165 +}; 1.166 + 1.167 +#endif // nsChromeRegistry_h