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"
19 #include "mozilla/intl/LocaleService.h"
21 class nsPIDOMWindowOuter
;
25 // The chrome registry is actually split between nsChromeRegistryChrome and
26 // nsChromeRegistryContent. The work/data that is common to both resides in
27 // the shared nsChromeRegistry implementation, with operations that only make
28 // sense for one side erroring out in the other.
30 // for component registration
31 // {47049e42-1d87-482a-984d-56ae185e367a}
32 #define NS_CHROMEREGISTRY_CID \
34 0x47049e42, 0x1d87, 0x482a, { \
35 0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a \
39 class nsChromeRegistry
: public nsIToolkitChromeRegistry
,
41 public nsSupportsWeakReference
{
45 // nsIXULChromeRegistry methods:
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
,
89 static already_AddRefed
<nsChromeRegistry
> GetSingleton();
91 struct ManifestProcessingContext
{
92 ManifestProcessingContext(NSLocationType aType
,
93 mozilla::FileLocation
& aFile
)
94 : mType(aType
), mFile(aFile
) {}
96 ~ManifestProcessingContext() {}
98 nsIURI
* GetManifestURI();
99 already_AddRefed
<nsIURI
> ResolveURI(const char* uri
);
101 NSLocationType mType
;
102 mozilla::FileLocation mFile
;
103 nsCOMPtr
<nsIURI
> mManifestURI
;
106 virtual void ManifestContent(ManifestProcessingContext
& cx
, int lineno
,
107 char* const* argv
, int flags
) = 0;
108 virtual void ManifestLocale(ManifestProcessingContext
& cx
, int lineno
,
109 char* const* argv
, int flags
) = 0;
110 virtual void ManifestSkin(ManifestProcessingContext
& cx
, int lineno
,
111 char* const* argv
, int flags
) = 0;
112 virtual void ManifestOverride(ManifestProcessingContext
& cx
, int lineno
,
113 char* const* argv
, int flags
) = 0;
114 virtual void ManifestResource(ManifestProcessingContext
& cx
, int lineno
,
115 char* const* argv
, int flags
) = 0;
119 // This package should use the new XPCNativeWrappers to separate
120 // content from chrome. This flag is currently unused (because we call
121 // into xpconnect at registration time).
122 XPCNATIVEWRAPPERS
= 1 << 1,
124 // Content script may access files in this package
125 CONTENT_ACCESSIBLE
= 1 << 2,
127 // Package may be loaded remotely
128 REMOTE_ALLOWED
= 1 << 3,
130 // Package must be loaded remotely
131 REMOTE_REQUIRED
= 1 << 4,
136 // "Override" table (chrome URI string -> real URI)
137 nsInterfaceHashtable
<nsURIHashKey
, nsIURI
> mOverrideTable
;
140 #endif // nsChromeRegistry_h