Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef nsXREAppData_h
8 : #define nsXREAppData_h
9 :
10 : #include <stdint.h>
11 : #include "mozilla/Attributes.h"
12 : #include "nsCOMPtr.h"
13 : #include "nsCRTGlue.h"
14 : #include "nsIFile.h"
15 :
16 : #if defined(XP_WIN) && defined(MOZ_SANDBOX)
17 : namespace sandbox {
18 : class BrokerServices;
19 : }
20 : namespace mozilla {
21 : namespace sandboxing {
22 : class PermissionsService;
23 : }
24 : }
25 : #endif
26 :
27 : namespace mozilla {
28 :
29 : struct StaticXREAppData;
30 :
31 : /**
32 : * Application-specific data needed to start the apprunner.
33 : */
34 : class XREAppData
35 : {
36 : public:
37 0 : XREAppData() { }
38 0 : ~XREAppData() { }
39 : XREAppData(const XREAppData& aOther)
40 : {
41 : *this = aOther;
42 : }
43 :
44 1 : explicit XREAppData(const StaticXREAppData& aOther)
45 1 : {
46 1 : *this = aOther;
47 1 : }
48 :
49 : XREAppData& operator=(const StaticXREAppData& aOther);
50 : XREAppData& operator=(const XREAppData& aOther);
51 : XREAppData& operator=(XREAppData&& aOther) = default;
52 :
53 : struct NSFreePolicy
54 : {
55 0 : void operator()(const void* ptr) {
56 0 : NS_Free(const_cast<void*>(ptr));
57 0 : }
58 : };
59 :
60 : // Lots of code reads these fields directly like a struct, so rather
61 : // than using UniquePtr directly, use an auto-converting wrapper.
62 : class CharPtr
63 : {
64 : public:
65 12 : explicit CharPtr() = default;
66 : explicit CharPtr(const char* v)
67 : {
68 : *this = v;
69 : }
70 : CharPtr(CharPtr&&) = default;
71 0 : ~CharPtr() = default;
72 :
73 12 : CharPtr& operator=(const char* v)
74 : {
75 12 : if (v) {
76 9 : mValue.reset(NS_strdup(v));
77 : } else {
78 3 : mValue = nullptr;
79 : }
80 12 : return *this;
81 : }
82 0 : CharPtr& operator=(const CharPtr& v)
83 : {
84 0 : *this = (const char*) v;
85 0 : return *this;
86 : }
87 :
88 296 : operator const char*() const {
89 296 : return mValue.get();
90 : }
91 :
92 : private:
93 : UniquePtr<const char, NSFreePolicy> mValue;
94 : };
95 :
96 : /**
97 : * The directory of the application to be run. May be null if the
98 : * xulrunner and the app are installed into the same directory.
99 : */
100 : nsCOMPtr<nsIFile> directory;
101 :
102 : /**
103 : * The name of the application vendor. This must be ASCII, and is normally
104 : * mixed-case, e.g. "Mozilla". Optional (may be null), but highly
105 : * recommended. Must not be the empty string.
106 : */
107 : CharPtr vendor;
108 :
109 : /**
110 : * The name of the application. This must be ASCII, and is normally
111 : * mixed-case, e.g. "Firefox". Required (must not be null or an empty
112 : * string).
113 : */
114 : CharPtr name;
115 :
116 : /**
117 : * The internal name of the application for remoting purposes. When left
118 : * unspecified, "name" is used instead. This must be ASCII, and is normally
119 : * lowercase, e.g. "firefox". Optional (may be null but not an empty string).
120 : */
121 : CharPtr remotingName;
122 :
123 : /**
124 : * The major version, e.g. "0.8.0+". Optional (may be null), but
125 : * required for advanced application features such as the extension
126 : * manager and update service. Must not be the empty string.
127 : */
128 : CharPtr version;
129 :
130 : /**
131 : * The application's build identifier, e.g. "2004051604"
132 : */
133 : CharPtr buildID;
134 :
135 : /**
136 : * The application's UUID. Used by the extension manager to determine
137 : * compatible extensions. Optional, but required for advanced application
138 : * features such as the extension manager and update service.
139 : *
140 : * This has traditionally been in the form
141 : * "{AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}" but for new applications
142 : * a more readable form is encouraged: "appname@vendor.tld". Only
143 : * the following characters are allowed: a-z A-Z 0-9 - . @ _ { } *
144 : */
145 : CharPtr ID;
146 :
147 : /**
148 : * The copyright information to print for the -h commandline flag,
149 : * e.g. "Copyright (c) 2003 mozilla.org".
150 : */
151 : CharPtr copyright;
152 :
153 : /**
154 : * Combination of NS_XRE_ prefixed flags (defined below).
155 : */
156 : uint32_t flags = 0;
157 :
158 : /**
159 : * The location of the XRE. XRE_main may not be able to figure this out
160 : * programatically.
161 : */
162 : nsCOMPtr<nsIFile> xreDirectory;
163 :
164 : /**
165 : * The minimum/maximum compatible XRE version.
166 : */
167 : CharPtr minVersion;
168 : CharPtr maxVersion;
169 :
170 : /**
171 : * The server URL to send crash reports to.
172 : */
173 : CharPtr crashReporterURL;
174 :
175 : /**
176 : * The profile directory that will be used. Optional (may be null). Must not
177 : * be the empty string, must be ASCII. The path is split into components
178 : * along the path separator characters '/' and '\'.
179 : *
180 : * The application data directory ("UAppData", see below) is normally
181 : * composed as follows, where $HOME is platform-specific:
182 : *
183 : * UAppData = $HOME[/$vendor]/$name
184 : *
185 : * If present, the 'profile' string will be used instead of the combination of
186 : * vendor and name as follows:
187 : *
188 : * UAppData = $HOME/$profile
189 : */
190 : CharPtr profile;
191 :
192 : /**
193 : * The application name to use in the User Agent string.
194 : */
195 : CharPtr UAName;
196 :
197 : #if defined(XP_WIN) && defined(MOZ_SANDBOX)
198 : /**
199 : * Chromium sandbox BrokerServices.
200 : */
201 : sandbox::BrokerServices* sandboxBrokerServices = nullptr;
202 : mozilla::sandboxing::PermissionsService* sandboxPermissionsService;
203 : #endif
204 : };
205 :
206 : /**
207 : * Indicates whether or not the profile migrator service may be
208 : * invoked at startup when creating a profile.
209 : */
210 : #define NS_XRE_ENABLE_PROFILE_MIGRATOR (1 << 1)
211 :
212 : /**
213 : * Indicates whether or not to use Breakpad crash reporting.
214 : */
215 : #define NS_XRE_ENABLE_CRASH_REPORTER (1 << 3)
216 :
217 : /**
218 : * A static version of the XRE app data is compiled into the application
219 : * so that it is not necessary to read application.ini at startup.
220 : *
221 : * This structure is initialized into and matches nsXREAppData
222 : */
223 : struct StaticXREAppData
224 : {
225 : const char* vendor;
226 : const char* name;
227 : const char* remotingName;
228 : const char* version;
229 : const char* buildID;
230 : const char* ID;
231 : const char* copyright;
232 : uint32_t flags;
233 : const char* minVersion;
234 : const char* maxVersion;
235 : const char* crashReporterURL;
236 : const char* profile;
237 : const char* UAName;
238 : };
239 :
240 : } // namespace mozilla
241 :
242 : #endif // XREAppData_h
|