Bug 540532 - allow setting report submission preference via XPCOM. r=gavin, r=ted

This commit is contained in:
Justin Dolske 2010-02-09 17:05:31 -08:00
Родитель 368d0fe318
Коммит 2135ff316c
9 изменённых файлов: 251 добавлений и 2 удалений

Просмотреть файл

@ -66,6 +66,9 @@ var gAdvancedPane = {
this.updateModeItems();
#endif
this.updateOfflineApps();
#ifdef MOZ_CRASHREPORTER
this.initSubmitCrashes();
#endif
},
/**
@ -139,6 +142,35 @@ var gAdvancedPane = {
return checkbox.checked ? (this._storedSpellCheck == 2 ? 2 : 1) : 0;
},
/**
*
*/
initSubmitCrashes: function ()
{
var checkbox = document.getElementById("submitCrashesBox");
try {
var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"].
getService(Components.interfaces.nsICrashReporter);
checkbox.checked = cr.submitReports;
} catch (e) {
checkbox.style.display = "none";
}
},
/**
*
*/
updateSubmitCrashes: function ()
{
var checkbox = document.getElementById("submitCrashesBox");
try {
var cr = Components.classes["@mozilla.org/toolkit/crash-reporter;1"].
getService(Components.interfaces.nsICrashReporter);
cr.submitReports = checkbox.checked;
} catch (e) { }
},
// NETWORK TAB
/*

Просмотреть файл

@ -184,7 +184,7 @@
#ifdef HAVE_SHELL_SERVICE
<!-- System Defaults -->
<groupbox id="systemDefaultsGroup" orient="horizontal">
<groupbox id="systemDefaultsGroup" orient="vertical">
<caption label="&systemDefaults.label;"/>
<hbox id="checkDefaultBox" align="center" flex="1">
@ -196,6 +196,11 @@
oncommand="gAdvancedPane.checkNow()"
preference="pref.general.disable_button.default_browser"/>
</hbox>
#ifdef MOZ_CRASHREPORTER
<checkbox id="submitCrashesBox" flex="1"
oncommand="gAdvancedPane.updateSubmitCrashes();"
label="&submitCrashes.label;" accesskey="&submitCrashes.accesskey;"/>
#endif
</groupbox>
#endif
</tabpanel>

Просмотреть файл

@ -25,6 +25,8 @@
<!ENTITY alwaysCheckDefault.accesskey "w">
<!ENTITY checkNow.label "Check Now">
<!ENTITY checkNow.accesskey "N">
<!ENTITY submitCrashes.label "Submit crash reports">
<!ENTITY submitCrashes.accesskey "S">
<!ENTITY networkTab.label "Network">

Просмотреть файл

@ -98,6 +98,11 @@ static const char kIniFile[] = "crashreporter.ini";
static void LoadSettings()
{
/*
* NOTE! This code needs to stay in sync with the preference checking
* code in in nsExceptionHandler.cpp.
*/
StringTable settings;
if (ReadStringsFromFile(gSettingsPath + "/" + kIniFile, settings, true)) {
if (settings.find("Email") != settings.end()) {
@ -125,6 +130,11 @@ static void LoadSettings()
static void SaveSettings()
{
/*
* NOTE! This code needs to stay in sync with the preference setting
* code in in nsExceptionHandler.cpp.
*/
StringTable settings;
ReadStringsFromFile(gSettingsPath + "/" + kIniFile, settings, true);

Просмотреть файл

@ -181,6 +181,10 @@ static bool CheckBoolKey(const wchar_t* key,
const wchar_t* valueName,
bool* enabled)
{
/*
* NOTE! This code needs to stay in sync with the preference checking
* code in in nsExceptionHandler.cpp.
*/
*enabled = false;
bool found = false;
HKEY hRegKey;
@ -208,6 +212,10 @@ static bool CheckBoolKey(const wchar_t* key,
static void SetBoolKey(const wchar_t* key, const wchar_t* value, bool enabled)
{
/*
* NOTE! This code needs to stay in sync with the preference setting
* code in in nsExceptionHandler.cpp.
*/
HKEY hRegKey;
// remove the old value from the registry if it exists

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
* Justin Dolske <dolske@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -43,6 +44,7 @@
#undef WIN32_LEAN_AND_MEAN
#endif
#include "nsIWindowsRegKey.h"
#if defined(MOZ_IPC)
# include "client/windows/crash_generation/crash_generation_server.h"
#endif
@ -58,6 +60,9 @@
#include <unistd.h>
#include "mac_utils.h"
#elif defined(XP_LINUX)
#include "nsDirectoryServiceUtils.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIINIParser.h"
#if defined(MOZ_IPC)
# include "client/linux/crash_generation/client_info.h"
# include "client/linux/crash_generation/crash_generation_server.h"
@ -88,6 +93,7 @@
#include "nsDataHashtable.h"
#include "nsInterfaceHashtable.h"
#include "prprf.h"
#include "nsIXULAppInfo.h"
#if defined(MOZ_IPC)
using google_breakpad::CrashGenerationServer;
@ -966,6 +972,172 @@ nsresult AppendObjCExceptionInfoToAppNotes(void *inException)
}
#endif
/*
* Combined code to get/set the crash reporter submission pref on
* different platforms.
*/
static nsresult PrefSubmitReports(PRBool* aSubmitReports, bool writePref)
{
nsresult rv;
#if defined(XP_WIN32)
/*
* NOTE! This needs to stay in sync with the preference checking code
* in toolkit/crashreporter/client/crashreporter_win.cpp
*/
nsCOMPtr<nsIXULAppInfo> appinfo =
do_GetService("@mozilla.org/xre/app-info;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString appVendor, appName;
rv = appinfo->GetVendor(appVendor);
NS_ENSURE_SUCCESS(rv, rv);
rv = appinfo->GetName(appName);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIWindowsRegKey> regKey
(do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString regPath;
regPath.AppendLiteral("Software\\");
if(!appVendor.IsEmpty()) {
regPath.Append(appVendor);
regPath.AppendLiteral("\\");
}
regPath.Append(appName);
regPath.AppendLiteral("\\Crash Reporter");
// If we're saving the pref value, just write it to ROOT_KEY_CURRENT_USER
// and we're done.
if (writePref) {
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
NS_ConvertUTF8toUTF16(regPath),
nsIWindowsRegKey::ACCESS_SET_VALUE);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 value = *aSubmitReports ? 1 : 0;
rv = regKey->WriteIntValue(NS_LITERAL_STRING("SubmitCrashReport"), value);
regKey->Close();
return rv;
}
// We're reading the pref value, so we need to first look under
// ROOT_KEY_LOCAL_MACHINE to see if it's set there, and then fall back to
// ROOT_KEY_CURRENT_USER. If it's not set in either place, the pref defaults
// to "true".
PRUint32 value;
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE,
NS_ConvertUTF8toUTF16(regPath),
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_SUCCEEDED(rv)) {
rv = regKey->ReadIntValue(NS_LITERAL_STRING("SubmitCrashReport"), &value);
regKey->Close();
if (NS_SUCCEEDED(rv)) {
*aSubmitReports = !!value;
return NS_OK;
}
}
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
NS_ConvertUTF8toUTF16(regPath),
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv)) {
*aSubmitReports = PR_TRUE;
return NS_OK;
}
rv = regKey->ReadIntValue(NS_LITERAL_STRING("SubmitCrashReport"), &value);
// default to true on failure
if (NS_FAILED(rv)) {
value = 1;
rv = NS_OK;
}
regKey->Close();
*aSubmitReports = !!value;
return NS_OK;
#elif defined(XP_UNIX)
/*
* NOTE! This needs to stay in sync with the preference checking code
* in toolkit/crashreporter/client/crashreporter_linux.cpp
*/
nsCOMPtr<nsIFile> reporterINI;
rv = NS_GetSpecialDirectory("UAppData", getter_AddRefs(reporterINI));
NS_ENSURE_SUCCESS(rv, rv);
reporterINI->AppendNative(NS_LITERAL_CSTRING("Crash Reports"));
reporterINI->AppendNative(NS_LITERAL_CSTRING("crashreporter.ini"));
PRBool exists;
rv = reporterINI->Exists(&exists);
NS_ENSURE_SUCCESS(rv, rv);
if (!exists) {
if (!writePref) {
// If reading the pref, default to true if .ini doesn't exist.
*aSubmitReports = PR_TRUE;
return NS_OK;
}
// Create the file so the INI processor can write to it.
rv = reporterINI->Create(nsIFile::NORMAL_FILE_TYPE, 0600);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIINIParserFactory> iniFactory =
do_GetService("@mozilla.org/xpcom/ini-processor-factory;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(reporterINI);
NS_ENSURE_TRUE(localFile, NS_ERROR_FAILURE);
nsCOMPtr<nsIINIParser> iniParser;
rv = iniFactory->CreateINIParser(localFile,
getter_AddRefs(iniParser));
NS_ENSURE_SUCCESS(rv, rv);
// If we're writing the pref, just set and we're done.
if (writePref) {
nsCOMPtr<nsIINIParserWriter> iniWriter = do_QueryInterface(iniParser);
NS_ENSURE_TRUE(iniWriter, NS_ERROR_FAILURE);
rv = iniWriter->SetString(NS_LITERAL_CSTRING("Crash Reporter"),
NS_LITERAL_CSTRING("SubmitReport"),
*aSubmitReports ? NS_LITERAL_CSTRING("1") :
NS_LITERAL_CSTRING("0"));
NS_ENSURE_SUCCESS(rv, rv);
rv = iniWriter->WriteFile(NULL);
return rv;
}
nsCAutoString submitReportValue;
rv = iniParser->GetString(NS_LITERAL_CSTRING("Crash Reporter"),
NS_LITERAL_CSTRING("SubmitReport"),
submitReportValue);
// Default to "true" if the pref can't be found.
if (NS_FAILED(rv))
*aSubmitReports = PR_TRUE;
else if (submitReportValue.EqualsASCII("0"))
*aSubmitReports = PR_FALSE;
else
*aSubmitReports = PR_TRUE;
return NS_OK;
#else
// TODO: Implement for OSX (bug 542379)
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
nsresult GetSubmitReports(PRBool* aSubmitReports)
{
return PrefSubmitReports(aSubmitReports, false);
}
nsresult SetSubmitReports(PRBool aSubmitReports)
{
return PrefSubmitReports(&aSubmitReports, true);
}
#if defined(MOZ_IPC)
//-----------------------------------------------------------------------------
// Out-of-process crash reporting API wrappers

Просмотреть файл

@ -70,6 +70,8 @@ nsresult SetupExtraData(nsILocalFile* aAppDataDirectory,
#ifdef XP_MACOSX
nsresult AppendObjCExceptionInfoToAppNotes(void *inException);
#endif
nsresult GetSubmitReports(PRBool* aSubmitReport);
nsresult SetSubmitReports(PRBool aSubmitReport);
#ifdef MOZ_IPC
// Out-of-process crash reporter API.

Просмотреть файл

@ -975,6 +975,19 @@ nsXULAppInfo::AppendObjCExceptionInfoToAppNotes(void* aException)
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
NS_IMETHODIMP
nsXULAppInfo::GetSubmitReports(PRBool* aEnabled)
{
return CrashReporter::GetSubmitReports(aEnabled);
}
NS_IMETHODIMP
nsXULAppInfo::SetSubmitReports(PRBool aEnabled)
{
return CrashReporter::SetSubmitReports(aEnabled);
}
#endif
static const nsXULAppInfo kAppInfo;

Просмотреть файл

@ -47,7 +47,7 @@ interface nsIURL;
* future releases.
*/
[scriptable, uuid(44650737-59f7-4c9b-adbe-2b6d4dfee86a)]
[scriptable, uuid(56761088-57ad-4f5c-bd61-f678c2807fe0)]
interface nsICrashReporter : nsISupports
{
/**
@ -117,4 +117,9 @@ interface nsICrashReporter : nsISupports
* @param aException NSException object to append note for
*/
[noscript] void appendObjCExceptionInfoToAppNotes(in voidPtr aException);
/**
* User preference for submitting crash reports.
*/
attribute boolean submitReports;
};