nsChromeRegistry.h (4915B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef nsChromeRegistry_h 7 #define nsChromeRegistry_h 8 9 #include "nsIToolkitChromeRegistry.h" 10 #include "nsIObserver.h" 11 #include "nsWeakReference.h" 12 13 #include "nsString.h" 14 #include "nsURIHashKey.h" 15 #include "nsInterfaceHashtable.h" 16 #include "nsXULAppAPI.h" 17 18 #include "mozilla/FileLocation.h" 19 #include "mozilla/intl/LocaleService.h" 20 21 class nsPIDOMWindowOuter; 22 class nsIPrefBranch; 23 class nsIURL; 24 25 // The chrome registry is actually split between nsChromeRegistryChrome and 26 // nsChromeRegistryContent. The work/data that is common to both resides in 27 // the shared nsChromeRegistry implementation, with operations that only make 28 // sense for one side erroring out in the other. 29 30 // for component registration 31 // {47049e42-1d87-482a-984d-56ae185e367a} 32 #define NS_CHROMEREGISTRY_CID \ 33 {0x47049e42, 0x1d87, 0x482a, {0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a}} 34 35 class nsChromeRegistry : public nsIToolkitChromeRegistry, 36 public nsIObserver, 37 public nsSupportsWeakReference { 38 public: 39 NS_DECL_ISUPPORTS 40 41 // nsIXULChromeRegistry methods: 42 NS_IMETHOD AllowScriptsForPackage(nsIURI* url, bool* _retval) override; 43 NS_IMETHOD AllowContentToAccess(nsIURI* url, bool* _retval) override; 44 NS_IMETHOD CanLoadURLRemotely(nsIURI* url, bool* _retval) override; 45 NS_IMETHOD MustLoadURLRemotely(nsIURI* url, bool* _retval) override; 46 47 NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI** aResult) override; 48 49 // nsChromeRegistry methods: 50 nsChromeRegistry() : mInitialized(false) {} 51 52 virtual nsresult Init(); 53 54 static already_AddRefed<nsIChromeRegistry> GetService(); 55 56 static nsChromeRegistry* gChromeRegistry; 57 58 // This method can change its parameter, so due to thread safety issues 59 // it should only be called for nsCOMPtr<nsIURI> that is on the stack, 60 // unless you know what you are doing. 61 static nsresult Canonify(nsCOMPtr<nsIURI>& aChromeURL); 62 63 protected: 64 virtual ~nsChromeRegistry(); 65 66 void FlushSkinCaches(); 67 void FlushAllCaches(); 68 69 static void LogMessage(const char* aMsg, ...) MOZ_FORMAT_PRINTF(1, 2); 70 static void LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber, 71 uint32_t flags, const char* aMsg, ...) 72 MOZ_FORMAT_PRINTF(4, 5); 73 74 virtual nsIURI* GetBaseURIFromPackage(const nsCString& aPackage, 75 const nsCString& aProvider, 76 const nsCString& aPath) = 0; 77 virtual nsresult GetFlagsFromPackage(const nsCString& aPackage, 78 uint32_t* aFlags) = 0; 79 80 static nsresult RefreshWindow(nsPIDOMWindowOuter* aWindow); 81 static nsresult GetProviderAndPath(nsIURI* aChromeURL, nsACString& aProvider, 82 nsACString& aPath); 83 84 public: 85 static already_AddRefed<nsChromeRegistry> GetSingleton(); 86 87 struct ManifestProcessingContext { 88 ManifestProcessingContext(NSLocationType aType, 89 mozilla::FileLocation& aFile) 90 : mType(aType), mFile(aFile) {} 91 92 ~ManifestProcessingContext() {} 93 94 nsIURI* GetManifestURI(); 95 already_AddRefed<nsIURI> ResolveURI(const char* uri); 96 97 NSLocationType mType; 98 mozilla::FileLocation mFile; 99 nsCOMPtr<nsIURI> mManifestURI; 100 }; 101 102 virtual void ManifestContent(ManifestProcessingContext& cx, int lineno, 103 char* const* argv, int flags) = 0; 104 virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno, 105 char* const* argv, int flags) = 0; 106 virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno, 107 char* const* argv, int flags) = 0; 108 virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno, 109 char* const* argv, int flags) = 0; 110 virtual void ManifestResource(ManifestProcessingContext& cx, int lineno, 111 char* const* argv, int flags) = 0; 112 113 // Available flags 114 enum { 115 // This package should use the new XPCNativeWrappers to separate 116 // content from chrome. This flag is currently unused (because we call 117 // into xpconnect at registration time). 118 XPCNATIVEWRAPPERS = 1 << 1, 119 120 // Content script may access files in this package 121 CONTENT_ACCESSIBLE = 1 << 2, 122 123 // Package may be loaded remotely 124 REMOTE_ALLOWED = 1 << 3, 125 126 // Package must be loaded remotely 127 REMOTE_REQUIRED = 1 << 4, 128 }; 129 130 bool mInitialized; 131 132 // "Override" table (chrome URI string -> real URI) 133 nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable; 134 }; 135 136 #endif // nsChromeRegistry_h