bug 380421 - get crash reporter params from nsXULAppInfo. r=bsmedberg

This commit is contained in:
ted.mielczarek@gmail.com 2007-05-16 10:14:59 -07:00
parent 57fb6d92d8
commit 8b8fb2dc58
12 changed files with 103 additions and 39 deletions

View File

@ -51,3 +51,7 @@ MaxVersion=@GRE_BUILD_ID@
[XRE]
EnableProfileMigrator=1
EnableExtensionManager=1
[Crash Reporter]
Enabled=0
ServerURL=https://crash-reports.mozilla.com/submit

View File

@ -44,7 +44,7 @@
#include "nsBuildID.h"
static const nsXREAppData kAppData = {
offsetof(nsXREAppData, xreDirectory),
sizeof(nsXREAppData),
nsnull,
"Mozilla",
"Firefox",
@ -53,7 +53,11 @@ static const nsXREAppData kAppData = {
"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
"Copyright (c) 1998 - 2007 mozilla.org",
NS_XRE_ENABLE_PROFILE_MIGRATOR |
NS_XRE_ENABLE_EXTENSION_MANAGER
NS_XRE_ENABLE_EXTENSION_MANAGER,
nsnull, // xreDirectory
nsnull, // minVersion
nsnull, // maxVersion
"https://crash-reports.mozilla.com/submit"
};
int main(int argc, char* argv[])

View File

@ -39,6 +39,8 @@
#include "crashreporter.h"
// Disable exception handler warnings.
#pragma warning( disable : 4530 )
#include <fstream>
#include <sstream>
@ -53,12 +55,9 @@ StringTable gStrings;
int gArgc;
const char** gArgv;
static string gSendURL;
static string gDumpFile;
static string gExtraFile;
static string gSettingsPath;
static bool gDeleteDump = true;
static string kExtraDataExtension = ".extra";
@ -98,11 +97,6 @@ static bool ReadConfig()
if (!ReadStringsFromFile(iniPath, gStrings))
return false;
gSendURL = gStrings["URL"];
string deleteSetting = gStrings["Delete"];
gDeleteDump = deleteSetting.empty() || atoi(deleteSetting.c_str()) != 0;
return true;
}
@ -196,12 +190,10 @@ bool CrashReporterSendCompleted(bool success,
const string& serverResponse)
{
if (success) {
if (gDeleteDump) {
if (!gDumpFile.empty())
UIDeleteFile(gDumpFile);
if (!gExtraFile.empty())
UIDeleteFile(gExtraFile);
}
if (!gDumpFile.empty())
UIDeleteFile(gDumpFile);
if (!gExtraFile.empty())
UIDeleteFile(gExtraFile);
return AddSubmittedReport(serverResponse);
}
@ -246,6 +238,11 @@ int main(int argc, const char** argv)
return 0;
}
if (queryParameters.find("ServerURL") == queryParameters.end()) {
UIError("No server URL specified");
return 0;
}
string product = queryParameters["ProductName"];
string vendor = queryParameters["Vendor"];
if (!UIGetSettingsPath(vendor, product, gSettingsPath)) {
@ -259,7 +256,19 @@ int main(int argc, const char** argv)
return 0;
}
UIShowCrashUI(gDumpFile, queryParameters, gSendURL);
string sendURL = queryParameters["ServerURL"];
// we don't need to actually send this
queryParameters.erase("ServerURL");
// allow override of the server url via environment variable
//XXX: remove this in the far future when our robot
// masters force everyone to use XULRunner
char* urlEnv = getenv("MOZ_CRASHREPORTER_URL");
if (urlEnv && *urlEnv) {
sendURL = urlEnv;
}
UIShowCrashUI(gDumpFile, queryParameters, sendURL);
}
UIShutdown();

View File

@ -1,6 +1,9 @@
#ifndef CRASHREPORTER_H__
#define CRASHREPORTER_H__
#pragma warning( push )
// Disable exception handler warnings.
#pragma warning( disable : 4530 )
#include <string>
#include <map>
#include <stdlib.h>
@ -71,4 +74,5 @@ bool UIEnsurePathExists(const std::string& path);
bool UIMoveFile(const std::string& oldfile, const std::string& newfile);
bool UIDeleteFile(const std::string& oldfile);
#pragma warning( pop )
#endif

View File

@ -14,6 +14,3 @@ SubmitSuccess=Crash report submitted successfully
SubmitFailed=Failed to submit crash report
CrashID=Crash ID: %s
CrashDetailsURL=You can view details of this crash at %s
[Settings]
URL=https://crash-reports.mozilla.com/submit

View File

@ -430,10 +430,11 @@ bool UIEnsurePathExists(const string& path)
bool UIMoveFile(const string& oldfile, const string& newfile)
{
return MoveFile(UTF8ToWide(oldfile).c_str(), UTF8ToWide(newfile).c_str());
return MoveFile(UTF8ToWide(oldfile).c_str(), UTF8ToWide(newfile).c_str())
== TRUE;
}
bool UIDeleteFile(const string& oldfile)
{
return DeleteFile(UTF8ToWide(oldfile).c_str());
return DeleteFile(UTF8ToWide(oldfile).c_str()) == TRUE;
}

View File

@ -288,21 +288,14 @@ static nsresult GetExecutablePath(nsString& exePath)
#endif
}
nsresult SetExceptionHandler(nsILocalFile* aXREDirectory)
nsresult SetExceptionHandler(nsILocalFile* aXREDirectory,
const char* aServerURL)
{
nsresult rv;
if (gExceptionHandler)
return NS_ERROR_ALREADY_INITIALIZED;
// check environment var to see if we're enabled.
// we're off by default until we sort out the
// rest of the infrastructure,
// so it must exist and be set to a non-empty value.
const char* airbagEnv = PR_GetEnv("MOZ_AIRBAG");
if (airbagEnv == NULL || *airbagEnv == '\0')
return NS_ERROR_NOT_AVAILABLE;
// this environment variable prevents us from launching
// the crash reporter client
const char* noReportEnv = PR_GetEnv("MOZ_CRASHREPORTER_NO_REPORT");
@ -363,7 +356,7 @@ nsresult SetExceptionHandler(nsILocalFile* aXREDirectory)
return NS_ERROR_NOT_IMPLEMENTED;
#endif
// finally, set the exception handler
// now set the exception handler
gExceptionHandler = new google_breakpad::
ExceptionHandler(CONVERT_UTF16_TO_XP_CHAR(tempPath).get(),
nsnull,
@ -374,6 +367,11 @@ nsresult SetExceptionHandler(nsILocalFile* aXREDirectory)
if (!gExceptionHandler)
return NS_ERROR_OUT_OF_MEMORY;
// store server URL with the API data
if (aServerURL)
AnnotateCrashReport(NS_LITERAL_CSTRING("ServerURL"),
nsDependentCString(aServerURL));
return NS_OK;
}

View File

@ -43,7 +43,8 @@
#include "nsStringGlue.h"
namespace CrashReporter {
nsresult SetExceptionHandler(nsILocalFile* aXREDirectory);
nsresult SetExceptionHandler(nsILocalFile* aXREDirectory,
const char* aServerURL);
nsresult SetMinidumpPath(const nsAString& aPath);
nsresult UnsetExceptionHandler();
nsresult AnnotateCrashReport(const nsACString &key, const nsACString &data);

View File

@ -63,7 +63,7 @@ char *
test_init_exception_handler()
{
mu_assert("CrashReporter::SetExceptionHandler",
CrashReporter::SetExceptionHandler(nsnull));
CrashReporter::SetExceptionHandler(nsnull, nsnull));
return 0;
}

View File

@ -83,6 +83,10 @@ ScopedAppData::ScopedAppData(const nsXREAppData* aAppData)
SetAllocatedString(this->minVersion, aAppData->minVersion);
SetAllocatedString(this->maxVersion, aAppData->maxVersion);
}
if (aAppData->size > offsetof(nsXREAppData, crashReporterURL)) {
SetAllocatedString(this->crashReporterURL, aAppData->crashReporterURL);
}
}
ScopedAppData::~ScopedAppData()
@ -99,6 +103,8 @@ ScopedAppData::~ScopedAppData()
SetStrongPtr(this->xreDirectory, (nsILocalFile*) nsnull);
SetAllocatedString(this->minVersion, nsnull);
SetAllocatedString(this->maxVersion, nsnull);
SetAllocatedString(this->crashReporterURL, nsnull);
}
nsresult
@ -211,6 +217,19 @@ XRE_ParseAppData(nsILocalFile* aINIFile, nsXREAppData *aAppData)
ReadStrings(parser, strings2);
}
if (aAppData->size > offsetof(nsXREAppData, crashReporterURL)) {
ReadString strings3[] = {
{ "Crash Reporter", "ServerURL", &aAppData->crashReporterURL },
{ nsnull }
};
ReadStrings(parser, strings3);
ReadFlag flags2[] = {
{ "Crash Reporter", "Enabled", NS_XRE_ENABLE_CRASH_REPORTER },
{ nsnull }
};
ReadFlags(parser, flags2, &aAppData->flags);
}
return NS_OK;
}

View File

@ -2188,8 +2188,15 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
#endif
#ifdef MOZ_AIRBAG
if (NS_SUCCEEDED(
CrashReporter::SetExceptionHandler(aAppData->xreDirectory))) {
//XXX: remove me when we turn this on by default
const char* airbagEnv = PR_GetEnv("MOZ_AIRBAG");
//XXX: can't set the flag here, since aAppData is const
if (((airbagEnv && *airbagEnv) ||
((aAppData->flags & NS_XRE_ENABLE_CRASH_REPORTER) &&
aAppData->crashReporterURL)) &&
NS_SUCCEEDED(CrashReporter::SetExceptionHandler(aAppData->xreDirectory,
aAppData->crashReporterURL)))
{
// pass some basic info from the app data
if (aAppData->vendor)
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Vendor"),
@ -2308,6 +2315,13 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
}
}
#ifdef MOZ_AIRBAG
//XXX: remove me when this is on by default
if (airbagEnv && *airbagEnv) {
appData.flags |= NS_XRE_ENABLE_CRASH_REPORTER;
}
#endif
ScopedLogging log;
if (!appData.xreDirectory) {
@ -2565,7 +2579,8 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
//////////////////////// NOW WE HAVE A PROFILE ////////////////////////
#ifdef MOZ_AIRBAG
MakeOrSetMinidumpPath(profD);
if (appData.flags & NS_XRE_ENABLE_CRASH_REPORTER)
MakeOrSetMinidumpPath(profD);
#endif
PRBool upgraded = PR_FALSE;
@ -2894,7 +2909,8 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
rv = LaunchChild(nativeApp, appInitiatedRestart, upgraded ? -1 : 0);
#ifdef MOZ_AIRBAG
CrashReporter::UnsetExceptionHandler();
if (appData.flags & NS_XRE_ENABLE_CRASH_REPORTER)
CrashReporter::UnsetExceptionHandler();
#endif
return rv == NS_ERROR_LAUNCHED_CHILD_PROCESS ? 0 : 1;
@ -2902,7 +2918,8 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
}
#ifdef MOZ_AIRBAG
CrashReporter::UnsetExceptionHandler();
if (appData.flags & NS_XRE_ENABLE_CRASH_REPORTER)
CrashReporter::UnsetExceptionHandler();
#endif
return NS_FAILED(rv) ? 1 : 0;

View File

@ -133,6 +133,11 @@ struct nsXREAppData
*/
const char *minVersion;
const char *maxVersion;
/**
* The server URL to send crash reports to.
*/
const char *crashReporterURL;
};
/**
@ -147,6 +152,11 @@ struct nsXREAppData
*/
#define NS_XRE_ENABLE_EXTENSION_MANAGER (1 << 2)
/**
* Indicates whether or not to use Breakpad crash reporting.
*/
#define NS_XRE_ENABLE_CRASH_REPORTER (1 << 3)
/**
* The contract id for the nsIXULAppInfo service.
*/