Bug 1589531 [wpt PR 19775] - [LayoutNG] Reland flex-item alignment, a=testonly
[gecko.git] / chrome / nsChromeRegistry.h
blobe5b124dc20a500a32929ea40e6386bf26f5d8729
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/. */
6 #ifndef nsChromeRegistry_h
7 #define nsChromeRegistry_h
9 #include "nsIToolkitChromeRegistry.h"
10 #include "nsIObserver.h"
11 #include "nsWeakReference.h"
13 #include "nsString.h"
14 #include "nsURIHashKey.h"
15 #include "nsInterfaceHashtable.h"
16 #include "nsXULAppAPI.h"
18 #include "mozilla/FileLocation.h"
20 class nsPIDOMWindowOuter;
21 class nsIPrefBranch;
22 class nsIURL;
24 // The chrome registry is actually split between nsChromeRegistryChrome and
25 // nsChromeRegistryContent. The work/data that is common to both resides in
26 // the shared nsChromeRegistry implementation, with operations that only make
27 // sense for one side erroring out in the other.
29 // for component registration
30 // {47049e42-1d87-482a-984d-56ae185e367a}
31 #define NS_CHROMEREGISTRY_CID \
32 { \
33 0x47049e42, 0x1d87, 0x482a, { \
34 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a \
35 } \
38 class nsChromeRegistry : public nsIToolkitChromeRegistry,
39 public nsIObserver,
40 public nsSupportsWeakReference {
41 public:
42 NS_DECL_ISUPPORTS
44 // nsIXULChromeRegistry methods:
45 NS_IMETHOD AllowScriptsForPackage(nsIURI* url, bool* _retval) override;
46 NS_IMETHOD AllowContentToAccess(nsIURI* url, bool* _retval) override;
47 NS_IMETHOD CanLoadURLRemotely(nsIURI* url, bool* _retval) override;
48 NS_IMETHOD MustLoadURLRemotely(nsIURI* url, bool* _retval) override;
50 NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI** aResult) override;
52 // nsChromeRegistry methods:
53 nsChromeRegistry() : mInitialized(false) {}
55 virtual nsresult Init();
57 static already_AddRefed<nsIChromeRegistry> GetService();
59 static nsChromeRegistry* gChromeRegistry;
61 // This method can change its parameter, so due to thread safety issues
62 // it should only be called for nsCOMPtr<nsIURI> that is on the stack,
63 // unless you know what you are doing.
64 static nsresult Canonify(nsCOMPtr<nsIURI>& aChromeURL);
66 protected:
67 virtual ~nsChromeRegistry();
69 void FlushSkinCaches();
70 void FlushAllCaches();
72 static void LogMessage(const char* aMsg, ...) MOZ_FORMAT_PRINTF(1, 2);
73 static void LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber,
74 uint32_t flags, const char* aMsg, ...)
75 MOZ_FORMAT_PRINTF(4, 5);
77 virtual nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
78 const nsCString& aProvider,
79 const nsCString& aPath) = 0;
80 virtual nsresult GetFlagsFromPackage(const nsCString& aPackage,
81 uint32_t* aFlags) = 0;
83 static nsresult RefreshWindow(nsPIDOMWindowOuter* aWindow);
84 static nsresult GetProviderAndPath(nsIURI* aChromeURL, nsACString& aProvider,
85 nsACString& aPath);
87 bool GetDirectionForLocale(const nsACString& aLocale);
89 void SanitizeForBCP47(nsACString& aLocale);
91 public:
92 static already_AddRefed<nsChromeRegistry> GetSingleton();
94 struct ManifestProcessingContext {
95 ManifestProcessingContext(NSLocationType aType,
96 mozilla::FileLocation& aFile)
97 : mType(aType), mFile(aFile) {}
99 ~ManifestProcessingContext() {}
101 nsIURI* GetManifestURI();
102 already_AddRefed<nsIURI> ResolveURI(const char* uri);
104 NSLocationType mType;
105 mozilla::FileLocation mFile;
106 nsCOMPtr<nsIURI> mManifestURI;
109 virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
110 char* const* argv, int flags) = 0;
111 virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
112 char* const* argv, int flags) = 0;
113 virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
114 char* const* argv, int flags) = 0;
115 virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
116 char* const* argv, int flags) = 0;
117 virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
118 char* const* argv, int flags) = 0;
120 // Available flags
121 enum {
122 // This package should use the new XPCNativeWrappers to separate
123 // content from chrome. This flag is currently unused (because we call
124 // into xpconnect at registration time).
125 XPCNATIVEWRAPPERS = 1 << 1,
127 // Content script may access files in this package
128 CONTENT_ACCESSIBLE = 1 << 2,
130 // Package may be loaded remotely
131 REMOTE_ALLOWED = 1 << 3,
133 // Package must be loaded remotely
134 REMOTE_REQUIRED = 1 << 4,
137 bool mInitialized;
139 // "Override" table (chrome URI string -> real URI)
140 nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable;
143 #endif // nsChromeRegistry_h