Source code

Revision control

Other Tools

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
#include "mozilla/intl/LocaleService.h"
20
21
class nsPIDOMWindowOuter;
22
class nsIPrefBranch;
23
class nsIURL;
24
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.
29
30
// for component registration
31
// {47049e42-1d87-482a-984d-56ae185e367a}
32
#define NS_CHROMEREGISTRY_CID \
33
{ \
34
0x47049e42, 0x1d87, 0x482a, { \
35
0x98, 0x4d, 0x56, 0xae, 0x18, 0x5e, 0x36, 0x7a \
36
} \
37
}
38
39
class nsChromeRegistry : public nsIToolkitChromeRegistry,
40
public nsIObserver,
41
public nsSupportsWeakReference {
42
public:
43
NS_DECL_ISUPPORTS
44
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;
50
51
NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI** aResult) override;
52
53
// nsChromeRegistry methods:
54
nsChromeRegistry() : mInitialized(false) {}
55
56
virtual nsresult Init();
57
58
static already_AddRefed<nsIChromeRegistry> GetService();
59
60
static nsChromeRegistry* gChromeRegistry;
61
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);
66
67
protected:
68
virtual ~nsChromeRegistry();
69
70
void FlushSkinCaches();
71
void FlushAllCaches();
72
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);
77
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;
83
84
static nsresult RefreshWindow(nsPIDOMWindowOuter* aWindow);
85
static nsresult GetProviderAndPath(nsIURI* aChromeURL, nsACString& aProvider,
86
nsACString& aPath);
87
88
public:
89
static already_AddRefed<nsChromeRegistry> GetSingleton();
90
91
struct ManifestProcessingContext {
92
ManifestProcessingContext(NSLocationType aType,
93
mozilla::FileLocation& aFile)
94
: mType(aType), mFile(aFile) {}
95
96
~ManifestProcessingContext() {}
97
98
nsIURI* GetManifestURI();
99
already_AddRefed<nsIURI> ResolveURI(const char* uri);
100
101
NSLocationType mType;
102
mozilla::FileLocation mFile;
103
nsCOMPtr<nsIURI> mManifestURI;
104
};
105
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;
116
117
// Available flags
118
enum {
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,
123
124
// Content script may access files in this package
125
CONTENT_ACCESSIBLE = 1 << 2,
126
127
// Package may be loaded remotely
128
REMOTE_ALLOWED = 1 << 3,
129
130
// Package must be loaded remotely
131
REMOTE_REQUIRED = 1 << 4,
132
};
133
134
bool mInitialized;
135
136
// "Override" table (chrome URI string -> real URI)
137
nsInterfaceHashtable<nsURIHashKey, nsIURI> mOverrideTable;
138
};
139
140
#endif // nsChromeRegistry_h