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();
51 NS_IMETHOD
RefreshSkins();
52 NS_IMETHOD
AllowScriptsForPackage(nsIURI
* url
,
54 NS_IMETHOD
AllowContentToAccess(nsIURI
* url
,
57 // nsIChromeRegistry methods:
58 NS_IMETHOD_(bool) WrappersEnabled(nsIURI
*aURI
);
59 NS_IMETHOD
ConvertChromeURL(nsIURI
* aChromeURI
, nsIURI
* *aResult
);
61 // nsChromeRegistry methods:
62 nsChromeRegistry() : mInitialized(false) { }
64 virtual nsresult
Init();
66 static already_AddRefed
<nsIChromeRegistry
> GetService();
68 static nsChromeRegistry
* gChromeRegistry
;
70 static nsresult
Canonify(nsIURL
* aChromeURL
);
73 virtual ~nsChromeRegistry();
75 void FlushSkinCaches();
76 void FlushAllCaches();
78 // Update the selected locale used by the chrome registry, and fire a
79 // notification about this change
80 virtual nsresult
UpdateSelectedLocale() = 0;
82 static void LogMessage(const char* aMsg
, ...);
83 static void LogMessageWithContext(nsIURI
* aURL
, uint32_t aLineNumber
, uint32_t flags
,
84 const char* aMsg
, ...);
86 virtual nsIURI
* GetBaseURIFromPackage(const nsCString
& aPackage
,
87 const nsCString
& aProvider
,
88 const nsCString
& aPath
) = 0;
89 virtual nsresult
GetFlagsFromPackage(const nsCString
& aPackage
,
90 uint32_t* aFlags
) = 0;
92 nsresult
SelectLocaleFromPref(nsIPrefBranch
* prefs
);
94 static nsresult
RefreshWindow(nsIDOMWindow
* aWindow
);
95 static nsresult
GetProviderAndPath(nsIURL
* aChromeURL
,
96 nsACString
& aProvider
, nsACString
& aPath
);
99 static already_AddRefed
<nsChromeRegistry
> GetSingleton();
101 struct ManifestProcessingContext
103 ManifestProcessingContext(NSLocationType aType
, mozilla::FileLocation
&aFile
)
108 ~ManifestProcessingContext()
111 nsIURI
* GetManifestURI();
112 nsIXPConnect
* GetXPConnect();
114 already_AddRefed
<nsIURI
> ResolveURI(const char* uri
);
116 NSLocationType mType
;
117 mozilla::FileLocation mFile
;
118 nsCOMPtr
<nsIURI
> mManifestURI
;
119 nsCOMPtr
<nsIXPConnect
> mXPConnect
;
122 virtual void ManifestContent(ManifestProcessingContext
& cx
, int lineno
,
123 char *const * argv
, bool platform
,
124 bool contentaccessible
) = 0;
125 virtual void ManifestLocale(ManifestProcessingContext
& cx
, int lineno
,
126 char *const * argv
, bool platform
,
127 bool contentaccessible
) = 0;
128 virtual void ManifestSkin(ManifestProcessingContext
& cx
, int lineno
,
129 char *const * argv
, bool platform
,
130 bool contentaccessible
) = 0;
131 virtual void ManifestOverlay(ManifestProcessingContext
& cx
, int lineno
,
132 char *const * argv
, bool platform
,
133 bool contentaccessible
) = 0;
134 virtual void ManifestStyle(ManifestProcessingContext
& cx
, int lineno
,
135 char *const * argv
, bool platform
,
136 bool contentaccessible
) = 0;
137 virtual void ManifestOverride(ManifestProcessingContext
& cx
, int lineno
,
138 char *const * argv
, bool platform
,
139 bool contentaccessible
) = 0;
140 virtual void ManifestResource(ManifestProcessingContext
& cx
, int lineno
,
141 char *const * argv
, bool platform
,
142 bool contentaccessible
) = 0;
146 // This is a "platform" package (e.g. chrome://global-platform/).
147 // Appends one of win/ unix/ mac/ to the base URI.
148 PLATFORM_PACKAGE
= 1 << 0,
150 // This package should use the new XPCNativeWrappers to separate
151 // content from chrome. This flag is currently unused (because we call
152 // into xpconnect at registration time).
153 XPCNATIVEWRAPPERS
= 1 << 1,
155 // Content script may access files in this package
156 CONTENT_ACCESSIBLE
= 1 << 2
161 // "Override" table (chrome URI string -> real URI)
162 nsInterfaceHashtable
<nsURIHashKey
, nsIURI
> mOverrideTable
;
165 #endif // nsChromeRegistry_h