chrome/src/nsChromeRegistry.h

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:867d92693fc5
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 #ifdef MOZ_XUL
14 #include "nsIXULOverlayProvider.h"
15 #endif
16
17 #include "nsString.h"
18 #include "nsURIHashKey.h"
19 #include "nsInterfaceHashtable.h"
20 #include "nsXULAppAPI.h"
21 #include "nsIXPConnect.h"
22
23 #include "mozilla/FileLocation.h"
24
25 class nsIDOMWindow;
26 class nsIPrefBranch;
27 class nsIURL;
28
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.
33
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 } }
38
39 class nsChromeRegistry : public nsIToolkitChromeRegistry,
40 #ifdef MOZ_XUL
41 public nsIXULOverlayProvider,
42 #endif
43 public nsIObserver,
44 public nsSupportsWeakReference
45 {
46 public:
47 NS_DECL_ISUPPORTS
48
49 // nsIXULChromeRegistry methods:
50 NS_IMETHOD ReloadChrome();
51 NS_IMETHOD RefreshSkins();
52 NS_IMETHOD AllowScriptsForPackage(nsIURI* url,
53 bool* _retval);
54 NS_IMETHOD AllowContentToAccess(nsIURI* url,
55 bool* _retval);
56
57 // nsIChromeRegistry methods:
58 NS_IMETHOD_(bool) WrappersEnabled(nsIURI *aURI);
59 NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult);
60
61 // nsChromeRegistry methods:
62 nsChromeRegistry() : mInitialized(false) { }
63 virtual ~nsChromeRegistry();
64
65 virtual nsresult Init();
66
67 static already_AddRefed<nsIChromeRegistry> GetService();
68
69 static nsChromeRegistry* gChromeRegistry;
70
71 static nsresult Canonify(nsIURL* aChromeURL);
72
73 protected:
74 void FlushSkinCaches();
75 void FlushAllCaches();
76
77 // Update the selected locale used by the chrome registry, and fire a
78 // notification about this change
79 virtual nsresult UpdateSelectedLocale() = 0;
80
81 static void LogMessage(const char* aMsg, ...);
82 static void LogMessageWithContext(nsIURI* aURL, uint32_t aLineNumber, uint32_t flags,
83 const char* aMsg, ...);
84
85 virtual nsIURI* GetBaseURIFromPackage(const nsCString& aPackage,
86 const nsCString& aProvider,
87 const nsCString& aPath) = 0;
88 virtual nsresult GetFlagsFromPackage(const nsCString& aPackage,
89 uint32_t* aFlags) = 0;
90
91 nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
92
93 static nsresult RefreshWindow(nsIDOMWindow* aWindow);
94 static nsresult GetProviderAndPath(nsIURL* aChromeURL,
95 nsACString& aProvider, nsACString& aPath);
96
97 public:
98 static already_AddRefed<nsChromeRegistry> GetSingleton();
99
100 struct ManifestProcessingContext
101 {
102 ManifestProcessingContext(NSLocationType aType, mozilla::FileLocation &aFile)
103 : mType(aType)
104 , mFile(aFile)
105 { }
106
107 ~ManifestProcessingContext()
108 { }
109
110 nsIURI* GetManifestURI();
111 nsIXPConnect* GetXPConnect();
112
113 already_AddRefed<nsIURI> ResolveURI(const char* uri);
114
115 NSLocationType mType;
116 mozilla::FileLocation mFile;
117 nsCOMPtr<nsIURI> mManifestURI;
118 nsCOMPtr<nsIXPConnect> mXPConnect;
119 };
120
121 virtual void ManifestContent(ManifestProcessingContext& cx, int lineno,
122 char *const * argv, bool platform,
123 bool contentaccessible) = 0;
124 virtual void ManifestLocale(ManifestProcessingContext& cx, int lineno,
125 char *const * argv, bool platform,
126 bool contentaccessible) = 0;
127 virtual void ManifestSkin(ManifestProcessingContext& cx, int lineno,
128 char *const * argv, bool platform,
129 bool contentaccessible) = 0;
130 virtual void ManifestOverlay(ManifestProcessingContext& cx, int lineno,
131 char *const * argv, bool platform,
132 bool contentaccessible) = 0;
133 virtual void ManifestStyle(ManifestProcessingContext& cx, int lineno,
134 char *const * argv, bool platform,
135 bool contentaccessible) = 0;
136 virtual void ManifestOverride(ManifestProcessingContext& cx, int lineno,
137 char *const * argv, bool platform,
138 bool contentaccessible) = 0;
139 virtual void ManifestResource(ManifestProcessingContext& cx, int lineno,
140 char *const * argv, bool platform,
141 bool contentaccessible) = 0;
142
143 // Available flags
144 enum {
145 // This is a "platform" package (e.g. chrome://global-platform/).
146 // Appends one of win/ unix/ mac/ to the base URI.
147 PLATFORM_PACKAGE = 1 << 0,
148
149 // This package should use the new XPCNativeWrappers to separate
150 // content from chrome. This flag is currently unused (because we call
151 // into xpconnect at registration time).
152 XPCNATIVEWRAPPERS = 1 << 1,
153
154 // Content script may access files in this package
155 CONTENT_ACCESSIBLE = 1 << 2
156 };
157
158 bool mInitialized;
159
160 // "Override" table (chrome URI string -> real URI)
161 nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable;
162 };
163
164 #endif // nsChromeRegistry_h

mercurial