/src/mozilla-central/chrome/nsChromeRegistry.h
Line | Count | Source |
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 | | #include "nsString.h" |
14 | | #include "nsURIHashKey.h" |
15 | | #include "nsInterfaceHashtable.h" |
16 | | #include "nsXULAppAPI.h" |
17 | | |
18 | | #include "mozilla/FileLocation.h" |
19 | | |
20 | | class nsPIDOMWindowOuter; |
21 | | class nsIPrefBranch; |
22 | | class nsIURL; |
23 | | |
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. |
28 | | |
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 } } |
33 | | |
34 | | class nsChromeRegistry : public nsIToolkitChromeRegistry, |
35 | | public nsIObserver, |
36 | | public nsSupportsWeakReference |
37 | | { |
38 | | public: |
39 | | NS_DECL_ISUPPORTS |
40 | | |
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; |
51 | | |
52 | | // nsIChromeRegistry methods: |
53 | | NS_IMETHOD_(bool) WrappersEnabled(nsIURI *aURI) override; |
54 | | NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult) override; |
55 | | |
56 | | // nsChromeRegistry methods: |
57 | 3 | nsChromeRegistry() : mInitialized(false) { } |
58 | | |
59 | | virtual nsresult Init(); |
60 | | |
61 | | static already_AddRefed<nsIChromeRegistry> GetService(); |
62 | | |
63 | | static nsChromeRegistry* gChromeRegistry; |
64 | | |
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); |
69 | | |
70 | | protected: |
71 | | virtual ~nsChromeRegistry(); |
72 | | |
73 | | void FlushSkinCaches(); |
74 | | void FlushAllCaches(); |
75 | | |
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); |
81 | | |
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; |
87 | | |
88 | | static nsresult RefreshWindow(nsPIDOMWindowOuter* aWindow); |
89 | | static nsresult GetProviderAndPath(nsIURI* aChromeURL, |
90 | | nsACString& aProvider, nsACString& aPath); |
91 | | |
92 | | bool GetDirectionForLocale(const nsACString& aLocale); |
93 | | |
94 | | void SanitizeForBCP47(nsACString& aLocale); |
95 | | |
96 | | public: |
97 | | static already_AddRefed<nsChromeRegistry> GetSingleton(); |
98 | | |
99 | | struct ManifestProcessingContext |
100 | | { |
101 | | ManifestProcessingContext(NSLocationType aType, mozilla::FileLocation &aFile) |
102 | | : mType(aType) |
103 | | , mFile(aFile) |
104 | 12 | { } |
105 | | |
106 | | ~ManifestProcessingContext() |
107 | 12 | { } |
108 | | |
109 | | nsIURI* GetManifestURI(); |
110 | | already_AddRefed<nsIURI> ResolveURI(const char* uri); |
111 | | |
112 | | NSLocationType mType; |
113 | | mozilla::FileLocation mFile; |
114 | | nsCOMPtr<nsIURI> mManifestURI; |
115 | | }; |
116 | | |
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; |
127 | | |
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, |
134 | | |
135 | | // Content script may access files in this package |
136 | | CONTENT_ACCESSIBLE = 1 << 2, |
137 | | |
138 | | // Package may be loaded remotely |
139 | | REMOTE_ALLOWED = 1 << 3, |
140 | | |
141 | | // Package must be loaded remotely |
142 | | REMOTE_REQUIRED = 1 << 4, |
143 | | }; |
144 | | |
145 | | bool mInitialized; |
146 | | |
147 | | // "Override" table (chrome URI string -> real URI) |
148 | | nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable; |
149 | | }; |
150 | | |
151 | | #endif // nsChromeRegistry_h |