Add support for PrefSubmitReports in crash reporter's nsExceptionHandler on Mac OS X, which syncs with crash reporter client. Exposes crash submission pref in Firefox. b=542379 r=ted
authorJosh Aas <joshmoz@gmail.com>
Sun, 20 Jun 2010 22:07:59 -0400
changeset 43879 0a95d72de4d4e0faae4ede9137ec0debace4cf10
parent 43878 e0c8f11c3892a584076bbb64d1cce355ba5a870f
child 43880 658b1f7e53c023a5d16e89dfb25fdb51832e1443
push idunknown
push userunknown
push dateunknown
reviewersted
bugs542379
milestone1.9.3a6pre
Add support for PrefSubmitReports in crash reporter's nsExceptionHandler on Mac OS X, which syncs with crash reporter client. Exposes crash submission pref in Firefox. b=542379 r=ted
toolkit/crashreporter/client/crashreporter_osx.mm
toolkit/crashreporter/mac_utils.h
toolkit/crashreporter/mac_utils.mm
toolkit/crashreporter/nsExceptionHandler.cpp
--- a/toolkit/crashreporter/client/crashreporter_osx.mm
+++ b/toolkit/crashreporter/client/crashreporter_osx.mm
@@ -267,18 +267,19 @@ static bool RestartApplication()
 {
   [NSApp terminate:self];
 }
 
 -(IBAction)submitReportClicked:(id)sender
 {
   [self updateSubmit];
   NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
-  [userDefaults setBool:[mSubmitReportButton state] == NSOnState
-   forKey:@"submitReport"];
+  [userDefaults setBool:([mSubmitReportButton state] == NSOnState)
+                 forKey:@"submitReport"];
+  [userDefaults synchronize];
 }
 
 -(IBAction)viewReportClicked:(id)sender
 {
   [self showReportInfo];
   [NSApp beginSheet:mViewReportWindow modalForWindow:mWindow
    modalDelegate:nil didEndSelector:nil contextInfo:nil];
 }
--- a/toolkit/crashreporter/mac_utils.h
+++ b/toolkit/crashreporter/mac_utils.h
@@ -35,18 +35,12 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef toolkit_breakpad_mac_utils_h__
 #define toolkit_breakpad_mac_utils_h__
 
 #include "nsStringGlue.h"
 
-/*
- * Look up a setting in our user defaults indicating
- * that the user wants to see the OS crash reporting dialog.
- */
-bool PassToOSCrashReporter();
-
 // Given an Objective-C NSException object, put exception info into a string.
 void GetObjCExceptionInfo(void* inException, nsACString& outString);
 
 #endif /* toolkit_breakpad_mac_utils_h__ */
--- a/toolkit/crashreporter/mac_utils.mm
+++ b/toolkit/crashreporter/mac_utils.mm
@@ -34,33 +34,18 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include <Foundation/Foundation.h>
 
 #include "mac_utils.h"
-#include "nsObjCExceptions.h"
 #include "nsXPCOM.h"
 
-bool PassToOSCrashReporter()
-{
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
-
-  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
-  NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
-  BOOL osCrashReporter = [userDefaults boolForKey:@"OSCrashReporter"];
-  [pool release];
-
-  return osCrashReporter == YES;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
-}
-
 void GetObjCExceptionInfo(void* inException, nsACString& outString)
 {
   NSException* e = (NSException*)inException;
 
   NSString* name = [e name];
   NSString* reason = [e reason];
   unsigned int nameLength = [name length];
   unsigned int reasonLength = [reason length];
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -50,16 +50,17 @@
 #endif
 #include "client/windows/handler/exception_handler.h"
 #include <DbgHelp.h>
 #include <string.h>
 #elif defined(XP_MACOSX)
 #include "client/mac/handler/exception_handler.h"
 #include <string>
 #include <Carbon/Carbon.h>
+#include <CoreFoundation/CoreFoundation.h>
 #include <fcntl.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include "mac_utils.h"
 #elif defined(XP_LINUX)
 #include "nsDirectoryServiceUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIINIParser.h"
@@ -93,16 +94,20 @@
 #include "nsIFileStreams.h"
 #include "nsInterfaceHashtable.h"
 #include "prprf.h"
 #include "nsIXULAppInfo.h"
 
 #if defined(MOZ_IPC)
 #include "nsIUUIDGenerator.h"
 
+#if defined(XP_MACOSX)
+CFStringRef reporterClientAppID = CFSTR("org.mozilla.crashreporter");
+#endif
+
 #if !defined(XP_MACOSX)
 using google_breakpad::CrashGenerationServer;
 using google_breakpad::ClientInfo;
 #endif
 
 using mozilla::Mutex;
 using mozilla::MutexAutoLock;
 #endif
@@ -548,17 +553,22 @@ nsresult SetExceptionHandler(nsILocalFil
   XP_TTOA(time(NULL), timeString, 10);
   AnnotateCrashReport(NS_LITERAL_CSTRING("StartupTime"),
                       nsDependentCString(timeString));
 
 #if defined(XP_MACOSX)
   // On OS X, many testers like to see the OS crash reporting dialog
   // since it offers immediate stack traces.  We allow them to set
   // a default to pass exceptions to the OS handler.
-  showOSCrashReporter = PassToOSCrashReporter();
+  Boolean keyExistsAndHasValidFormat = false;
+  Boolean prefValue = ::CFPreferencesGetAppBooleanValue(CFSTR("OSCrashReporter"),
+                                                        kCFPreferencesCurrentApplication,
+                                                        &keyExistsAndHasValidFormat);
+  if (keyExistsAndHasValidFormat)
+    showOSCrashReporter = prefValue;
 #endif
 
   return NS_OK;
 }
 
 bool GetEnabled()
 {
   return gExceptionHandler != nsnull;
@@ -1090,18 +1100,35 @@ static nsresult PrefSubmitReports(PRBool
     value = 1;
     rv = NS_OK;
   }
   regKey->Close();
 
   *aSubmitReports = !!value;
   return NS_OK;
 #elif defined(XP_MACOSX)
-  // TODO: Implement for OSX (bug 542379)
-  return NS_ERROR_NOT_IMPLEMENTED;
+  rv = NS_OK;
+  if (writePref) {
+    CFPropertyListRef cfValue = (CFPropertyListRef)(*aSubmitReports ? kCFBooleanTrue : kCFBooleanFalse);
+    ::CFPreferencesSetAppValue(CFSTR("submitReport"),
+                               cfValue,
+                               reporterClientAppID);
+    if (!::CFPreferencesAppSynchronize(reporterClientAppID))
+      rv = NS_ERROR_FAILURE;
+  }
+  else {
+    *aSubmitReports = PR_TRUE;
+    Boolean keyExistsAndHasValidFormat = false;
+    Boolean prefValue = ::CFPreferencesGetAppBooleanValue(CFSTR("submitReport"),
+                                                          reporterClientAppID,
+                                                          &keyExistsAndHasValidFormat);
+    if (keyExistsAndHasValidFormat)
+      *aSubmitReports = !!prefValue;
+  }
+  return rv;
 #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);