Skip to content

Commit e7e3ace

Browse files
Send crash reports to console URL specified in distribution.ini
1 parent fe28284 commit e7e3ace

File tree

7 files changed

+64
-0
lines changed

7 files changed

+64
-0
lines changed

browser/branding/branding-common.mozbuild

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ def FirefoxBranding():
4040
JS_PREFERENCE_FILES += [
4141
"pref/firefox-enterprise.js",
4242
]
43+
FINAL_TARGET_FILES[".."].distribution += [
44+
"distribution.ini",
45+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Default partner distribution configuration file
2+
# Must be replaced as part of a repack for Enterprise builds
3+
4+
[Preferences]
5+
enterprise.console.address=https://console.enterfox.eu

browser/installer/package-manifest.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@
168168
@BINPATH@/@MOZ_APP_NAME@
169169
#endif
170170
@RESPATH@/application.ini
171+
#ifdef MOZ_ENTERPRISE
172+
@RESPATH@/distribution/distribution.ini
173+
#endif
171174
#ifdef MOZ_UPDATER
172175
# update-settings.ini has been removed on macOS.
173176
#ifndef XP_MACOSX

browser/moz.configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ imply_option("--with-app-name", "firefox", when="--enable-enterprise")
4040
imply_option(
4141
"--with-branding", "browser/branding/enterprise", when="--enable-enterprise"
4242
)
43+
# Clear the default value to avoid mozilla.com url compiled into product
44+
imply_option("--with-crashreporter-url", "", when="--enable-enterprise")
4345

4446
# Set UA name to "Firefox" for enterprise builds
4547
imply_option("MOZ_APP_UA_NAME", "Firefox", when="--enable-enterprise")

toolkit/xre/CreateAppData.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "nsXULAppAPI.h"
77
#include "nsINIParser.h"
88
#include "nsIFile.h"
9+
#include "nsURLHelper.h"
910
#include "mozilla/XREAppData.h"
1011

1112
// This include must appear early in the unified cpp file for toolkit/xre to
@@ -75,3 +76,35 @@ nsresult XRE_ParseAppData(nsIFile* aINIFile, XREAppData& aAppData) {
7576

7677
return NS_OK;
7778
}
79+
80+
#if defined(MOZ_ENTERPRISE)
81+
static nsresult ParseConsoleUrlFromDistribution(XREAppData& aAppData,
82+
nsACString& consoleUrl) {
83+
nsCOMPtr<nsIFile> distributionFile;
84+
nsresult rv = aAppData.xreDirectory->Clone(getter_AddRefs(distributionFile));
85+
NS_ENSURE_SUCCESS(rv, rv);
86+
rv = distributionFile->Append(u"distribution"_ns);
87+
NS_ENSURE_SUCCESS(rv, rv);
88+
rv = distributionFile->Append(u"distribution.ini"_ns);
89+
NS_ENSURE_SUCCESS(rv, rv);
90+
nsINIParser parser;
91+
rv = parser.Init(distributionFile);
92+
NS_ENSURE_SUCCESS(rv, rv);
93+
rv =
94+
parser.GetString("Preferences", "enterprise.console.address", consoleUrl);
95+
return rv;
96+
}
97+
98+
nsresult XRE_ParseEnterpriseServerURL(XREAppData& aAppData) {
99+
nsCString serverUrl;
100+
nsresult rv = ParseConsoleUrlFromDistribution(aAppData, serverUrl);
101+
NS_ENSURE_SUCCESS(rv, rv);
102+
if (serverUrl.Last() != '/') {
103+
serverUrl.Append('/');
104+
}
105+
serverUrl.Append("api/browser/crash-reports/submit");
106+
aAppData.crashReporterURL = serverUrl.get();
107+
108+
return NS_OK;
109+
}
110+
#endif

toolkit/xre/nsAppRunner.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4282,6 +4282,12 @@ int XREMain::XRE_mainInit(bool* aExitFlag) {
42824282
}
42834283
}
42844284

4285+
#if defined(MOZ_ENTERPRISE)
4286+
XRE_ParseEnterpriseServerURL(*mAppData);
4287+
// Ignoring nsresult. If console url is not found in a release build, the
4288+
// default server url is empty and crash reports will fail to submit.
4289+
#endif
4290+
42854291
// Check sanity and correctness of app data.
42864292

42874293
if (!mAppData->name) {

xpcom/build/nsXULAppAPI.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,18 @@ nsresult XRE_AddManifestLocation(NSLocationType aType, nsIFile* aLocation);
250250
*/
251251
nsresult XRE_ParseAppData(nsIFile* aINIFile, mozilla::XREAppData& aAppData);
252252

253+
#if defined(MOZ_ENTERPRISE)
254+
/**
255+
* Parse the distribution.ini file to read the enterprise console address. Use
256+
* the console address to build the crash report URL to set in an existing
257+
* nsXREAppData structure.
258+
*
259+
* @param aAppData The nsXREAppData structure on which to set the
260+
* crashReporterURL.
261+
*/
262+
nsresult XRE_ParseEnterpriseServerURL(mozilla::XREAppData& aAppData);
263+
#endif
264+
253265
const char* XRE_GeckoProcessTypeToString(GeckoProcessType aProcessType);
254266
const char* XRE_ChildProcessTypeToAnnotation(GeckoProcessType aProcessType);
255267

0 commit comments

Comments
 (0)