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"
14 #include "nsIXULOverlayProvider.h"
18 #include "nsURIHashKey.h"
19 #include "nsInterfaceHashtable.h"
20 #include "nsXULAppAPI.h"
21 #include "nsIXPConnect.h"
23 #include "mozilla/FileLocation.h"
29 // The chrome registry is actually split between nsChromeRegistryChrome and
30 // nsChromeRegistryContent. The work/data that is common to both resides in
31 // the shared nsChromeRegistry implementation, with operations that only make
32 // sense for one side erroring out in the other.
34 // for component registration
35 // {47049e42-1d87-482a-984d-56ae185e367a}
36 #define NS_CHROMEREGISTRY_CID \
37 { 0x47049e42, 0x1d87, 0x482a, { 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a } }
39 class nsChromeRegistry
: public nsIToolkitChromeRegistry
,
41 public nsIXULOverlayProvider
,
44 public nsSupportsWeakReference
49 // nsIXULChromeRegistry methods:
50 NS_IMETHOD
ReloadChrome() override
;
51 NS_IMETHOD
RefreshSkins() override
;
52 NS_IMETHOD
AllowScriptsForPackage(nsIURI
* url
,
53 bool* _retval
) override
;
54 NS_IMETHOD
AllowContentToAccess(nsIURI
* url
,
55 bool* _retval
) override
;
56 NS_IMETHOD
CanLoadURLRemotely(nsIURI
* url
,
57 bool* _retval
) override
;
58 NS_IMETHOD
MustLoadURLRemotely(nsIURI
* url
,
59 bool* _retval
) override
;
61 // nsIChromeRegistry methods:
62 NS_IMETHOD_(bool) WrappersEnabled(nsIURI
*aURI
) override
;
63 NS_IMETHOD
ConvertChromeURL(nsIURI
* aChromeURI
, nsIURI
* *aResult
) override
;
65 // nsChromeRegistry methods:
66 nsChromeRegistry() : mInitialized(false) { }
68 virtual nsresult
Init();
70 static already_AddRefed
<nsIChromeRegistry
> GetService();
72 static nsChromeRegistry
* gChromeRegistry
;
74 static nsresult
Canonify(nsIURL
* aChromeURL
);
77 virtual ~nsChromeRegistry();
79 void FlushSkinCaches();
80 void FlushAllCaches();
82 // Update the selected locale used by the chrome registry, and fire a
83 // notification about this change
84 virtual nsresult
UpdateSelectedLocale() = 0;
86 static void LogMessage(const char* aMsg
, ...);
87 static void LogMessageWithContext(nsIURI
* aURL
, uint32_t aLineNumber
, uint32_t flags
,
88 const char* aMsg
, ...);
90 virtual nsIURI
* GetBaseURIFromPackage(const nsCString
& aPackage
,
91 const nsCString
& aProvider
,
92 const nsCString
& aPath
) = 0;
93 virtual nsresult
GetFlagsFromPackage(const nsCString
& aPackage
,
94 uint32_t* aFlags
) = 0;
96 nsresult
SelectLocaleFromPref(nsIPrefBranch
* prefs
);
98 static nsresult
RefreshWindow(nsIDOMWindow
* aWindow
);
99 static nsresult
GetProviderAndPath(nsIURL
* aChromeURL
,
100 nsACString
& aProvider
, nsACString
& aPath
);
103 static already_AddRefed
<nsChromeRegistry
> GetSingleton();
105 struct ManifestProcessingContext
107 ManifestProcessingContext(NSLocationType aType
, mozilla::FileLocation
&aFile
)
112 ~ManifestProcessingContext()
115 nsIURI
* GetManifestURI();
116 nsIXPConnect
* GetXPConnect();
118 already_AddRefed
<nsIURI
> ResolveURI(const char* uri
);
120 NSLocationType mType
;
121 mozilla::FileLocation mFile
;
122 nsCOMPtr
<nsIURI
> mManifestURI
;
123 nsCOMPtr
<nsIXPConnect
> mXPConnect
;
126 virtual void ManifestContent(ManifestProcessingContext
& cx
, int lineno
,
127 char *const * argv
, int flags
) = 0;
128 virtual void ManifestLocale(ManifestProcessingContext
& cx
, int lineno
,
129 char *const * argv
, int flags
) = 0;
130 virtual void ManifestSkin(ManifestProcessingContext
& cx
, int lineno
,
131 char *const * argv
, int flags
) = 0;
132 virtual void ManifestOverlay(ManifestProcessingContext
& cx
, int lineno
,
133 char *const * argv
, int flags
) = 0;
134 virtual void ManifestStyle(ManifestProcessingContext
& cx
, int lineno
,
135 char *const * argv
, int flags
) = 0;
136 virtual void ManifestOverride(ManifestProcessingContext
& cx
, int lineno
,
137 char *const * argv
, int flags
) = 0;
138 virtual void ManifestResource(ManifestProcessingContext
& cx
, int lineno
,
139 char *const * argv
, int flags
) = 0;
143 // This is a "platform" package (e.g. chrome://global-platform/).
144 // Appends one of win/ unix/ mac/ to the base URI.
145 PLATFORM_PACKAGE
= 1 << 0,
147 // This package should use the new XPCNativeWrappers to separate
148 // content from chrome. This flag is currently unused (because we call
149 // into xpconnect at registration time).
150 XPCNATIVEWRAPPERS
= 1 << 1,
152 // Content script may access files in this package
153 CONTENT_ACCESSIBLE
= 1 << 2,
155 // Package may be loaded remotely
156 REMOTE_ALLOWED
= 1 << 3,
158 // Package must be loaded remotely
159 REMOTE_REQUIRED
= 1 << 4,
164 // "Override" table (chrome URI string -> real URI)
165 nsInterfaceHashtable
<nsURIHashKey
, nsIURI
> mOverrideTable
;
168 #endif // nsChromeRegistry_h