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 "nsURIHashKey.h"
15 #include "nsInterfaceHashtable.h"
16 #include "nsXULAppAPI.h"
18 #include "mozilla/FileLocation.h"
20 class nsPIDOMWindowOuter
;
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 \
33 0x47049e42, 0x1d87, 0x482a, { \
34 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a \
38 class nsChromeRegistry
: public nsIToolkitChromeRegistry
,
40 public nsSupportsWeakReference
{
44 // nsIXULChromeRegistry methods:
45 NS_IMETHOD
RefreshSkins() override
;
46 NS_IMETHOD
AllowScriptsForPackage(nsIURI
* url
, bool* _retval
) override
;
47 NS_IMETHOD
AllowContentToAccess(nsIURI
* url
, bool* _retval
) override
;
48 NS_IMETHOD
CanLoadURLRemotely(nsIURI
* url
, bool* _retval
) override
;
49 NS_IMETHOD
MustLoadURLRemotely(nsIURI
* url
, bool* _retval
) override
;
51 NS_IMETHOD
ConvertChromeURL(nsIURI
* aChromeURI
, nsIURI
** aResult
) override
;
53 // nsChromeRegistry methods:
54 nsChromeRegistry() : mInitialized(false) {}
56 virtual nsresult
Init();
58 static already_AddRefed
<nsIChromeRegistry
> GetService();
60 static nsChromeRegistry
* gChromeRegistry
;
62 // This method can change its parameter, so due to thread safety issues
63 // it should only be called for nsCOMPtr<nsIURI> that is on the stack,
64 // unless you know what you are doing.
65 static nsresult
Canonify(nsCOMPtr
<nsIURI
>& aChromeURL
);
68 virtual ~nsChromeRegistry();
70 void FlushSkinCaches();
71 void FlushAllCaches();
73 static void LogMessage(const char* aMsg
, ...) MOZ_FORMAT_PRINTF(1, 2);
74 static void LogMessageWithContext(nsIURI
* aURL
, uint32_t aLineNumber
,
75 uint32_t flags
, const char* aMsg
, ...)
76 MOZ_FORMAT_PRINTF(4, 5);
78 virtual nsIURI
* GetBaseURIFromPackage(const nsCString
& aPackage
,
79 const nsCString
& aProvider
,
80 const nsCString
& aPath
) = 0;
81 virtual nsresult
GetFlagsFromPackage(const nsCString
& aPackage
,
82 uint32_t* aFlags
) = 0;
84 static nsresult
RefreshWindow(nsPIDOMWindowOuter
* aWindow
);
85 static nsresult
GetProviderAndPath(nsIURI
* aChromeURL
, nsACString
& aProvider
,
88 bool GetDirectionForLocale(const nsACString
& aLocale
);
90 void SanitizeForBCP47(nsACString
& aLocale
);
93 static already_AddRefed
<nsChromeRegistry
> GetSingleton();
95 struct ManifestProcessingContext
{
96 ManifestProcessingContext(NSLocationType aType
,
97 mozilla::FileLocation
& aFile
)
98 : mType(aType
), mFile(aFile
) {}
100 ~ManifestProcessingContext() {}
102 nsIURI
* GetManifestURI();
103 already_AddRefed
<nsIURI
> ResolveURI(const char* uri
);
105 NSLocationType mType
;
106 mozilla::FileLocation mFile
;
107 nsCOMPtr
<nsIURI
> mManifestURI
;
110 virtual void ManifestContent(ManifestProcessingContext
& cx
, int lineno
,
111 char* const* argv
, int flags
) = 0;
112 virtual void ManifestLocale(ManifestProcessingContext
& cx
, int lineno
,
113 char* const* argv
, int flags
) = 0;
114 virtual void ManifestSkin(ManifestProcessingContext
& cx
, int lineno
,
115 char* const* argv
, int flags
) = 0;
116 virtual void ManifestOverride(ManifestProcessingContext
& cx
, int lineno
,
117 char* const* argv
, int flags
) = 0;
118 virtual void ManifestResource(ManifestProcessingContext
& cx
, int lineno
,
119 char* const* argv
, int flags
) = 0;
123 // This package should use the new XPCNativeWrappers to separate
124 // content from chrome. This flag is currently unused (because we call
125 // into xpconnect at registration time).
126 XPCNATIVEWRAPPERS
= 1 << 1,
128 // Content script may access files in this package
129 CONTENT_ACCESSIBLE
= 1 << 2,
131 // Package may be loaded remotely
132 REMOTE_ALLOWED
= 1 << 3,
134 // Package must be loaded remotely
135 REMOTE_REQUIRED
= 1 << 4,
140 // "Override" table (chrome URI string -> real URI)
141 nsInterfaceHashtable
<nsURIHashKey
, nsIURI
> mOverrideTable
;
144 #endif // nsChromeRegistry_h