Bug 1492908 [wpt PR 13122] - Update wpt metadata, a=testonly
[gecko.git] / chrome / nsChromeRegistry.h
blobb5dd03c8c68ae876340ec78af38b60c2dcc6a2e5
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 { 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } }
34 class nsChromeRegistry : public nsIToolkitChromeRegistry,
35 public nsIObserver,
36 public nsSupportsWeakReference
38 public:
39 NS_DECL_ISUPPORTS
41 // nsIXULChromeRegistry methods:
42 NS_IMETHOD RefreshSkins() override;
43 NS_IMETHOD AllowScriptsForPackage(nsIURI* url,
44 bool* _retval) override;
45 NS_IMETHOD AllowContentToAccess(nsIURI* url,
46 bool* _retval) override;
47 NS_IMETHOD CanLoadURLRemotely(nsIURI* url,
48 bool* _retval) override;
49 NS_IMETHOD MustLoadURLRemotely(nsIURI* url,
50 bool* _retval) override;
52 // nsIChromeRegistry methods:
53 NS_IMETHOD_(bool) WrappersEnabled(nsIURI *aURI) override;
54 NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult) override;
56 // nsChromeRegistry methods:
57 nsChromeRegistry() : mInitialized(false) { }
59 virtual nsresult Init();
61 static already_AddRefed<nsIChromeRegistry> GetService();
63 static nsChromeRegistry* gChromeRegistry;
65 // This method can change its parameter, so due to thread safety issues
66 // it should only be called for nsCOMPtr<nsIURI> that is on the stack,
67 // unless you know what you are doing.
68 static nsresult Canonify(nsCOMPtr<nsIURI>& aChromeURL);
70 protected:
71 virtual ~nsChromeRegistry();
73 void FlushSkinCaches();
74 void FlushAllCaches();
76 static void LogMessage(const char* aMsg, ...)
77 MOZ_FORMAT_PRINTF(1, 2);
78 static void LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber, uint32_t flags,
79 const char* aMsg, ...)
80 MOZ_FORMAT_PRINTF(4, 5);
82 virtual nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
83 const nsCString& aProvider,
84 const nsCString& aPath) = 0;
85 virtual nsresult GetFlagsFromPackage(const nsCString& aPackage,
86 uint32_t* aFlags) = 0;
88 static nsresult RefreshWindow(nsPIDOMWindowOuter* aWindow);
89 static nsresult GetProviderAndPath(nsIURI* aChromeURL,
90 nsACString& aProvider, nsACString& aPath);
92 bool GetDirectionForLocale(const nsACString& aLocale);
94 void SanitizeForBCP47(nsACString& aLocale);
96 public:
97 static already_AddRefed<nsChromeRegistry> GetSingleton();
99 struct ManifestProcessingContext
101 ManifestProcessingContext(NSLocationType aType, mozilla::FileLocation &aFile)
102 : mType(aType)
103 , mFile(aFile)
106 ~ManifestProcessingContext()
109 nsIURI* GetManifestURI();
110 already_AddRefed<nsIURI> ResolveURI(const char* uri);
112 NSLocationType mType;
113 mozilla::FileLocation mFile;
114 nsCOMPtr<nsIURI> mManifestURI;
117 virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
118 char *const * argv, int flags) = 0;
119 virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
120 char *const * argv, int flags) = 0;
121 virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
122 char *const * argv, int flags) = 0;
123 virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
124 char *const * argv, int flags) = 0;
125 virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
126 char *const * argv, int flags) = 0;
128 // Available flags
129 enum {
130 // This package should use the new XPCNativeWrappers to separate
131 // content from chrome. This flag is currently unused (because we call
132 // into xpconnect at registration time).
133 XPCNATIVEWRAPPERS = 1 << 1,
135 // Content script may access files in this package
136 CONTENT_ACCESSIBLE = 1 << 2,
138 // Package may be loaded remotely
139 REMOTE_ALLOWED = 1 << 3,
141 // Package must be loaded remotely
142 REMOTE_REQUIRED = 1 << 4,
145 bool mInitialized;
147 // "Override" table (chrome URI string -> real URI)
148 nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable;
151 #endif // nsChromeRegistry_h