bug 380421 - get crash reporter params from nsXULAppInfo. r=bsmedberg
authorted.mielczarek@gmail.com
Tue, 24 Jul 2007 18:06:03 -0700
changeset 3883 79a76a05a4798947eedc32f24deb57a5762ad2af
parent 3882 e7346ae77d75d070312c65e143ce581cb09904a4
child 3884 cada7ae9112c39e486e3672cd001117157b85a98
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs380421
milestone1.9a7pre
bug 380421 - get crash reporter params from nsXULAppInfo. r=bsmedberg
toolkit/crashreporter/client/crashreporter.cpp
toolkit/crashreporter/client/crashreporter.h
toolkit/crashreporter/client/crashreporter.ini
toolkit/crashreporter/client/crashreporter_win.cpp
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/crashreporter/nsExceptionHandler.h
toolkit/crashreporter/test/TestCrashReporterAPI.cpp
--- a/toolkit/crashreporter/client/crashreporter.cpp
+++ b/toolkit/crashreporter/client/crashreporter.cpp
@@ -34,36 +34,35 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * 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 "crashreporter.h"
 
+// Disable exception handler warnings.
+#pragma warning( disable : 4530 )
 #include <fstream>
 #include <sstream>
 
 using std::string;
 using std::istream;
 using std::ifstream;
 using std::istringstream;
 using std::ostream;
 using std::ofstream;
 
 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";
 
 static bool ReadStrings(istream &in, StringTable &strings)
 {
   string currentSection;
   while (!in.eof()) {
     string line;
@@ -93,21 +92,16 @@ static bool ReadConfig()
 {
   string iniPath;
   if (!UIGetIniPath(iniPath))
     return false;
 
   if (!ReadStringsFromFile(iniPath, gStrings))
     return false;
 
-  gSendURL = gStrings["URL"];
-
-  string deleteSetting = gStrings["Delete"];
-  gDeleteDump = deleteSetting.empty() || atoi(deleteSetting.c_str()) != 0;
-
   return true;
 }
 
 static string GetExtraDataFilename(const string& dumpfile)
 {
   string filename(dumpfile);
   int dot = filename.rfind('.');
   if (dot < 0)
@@ -191,22 +185,20 @@ static bool AddSubmittedReport(const str
   return true;
 
 }
 
 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);
   }
   return true;
 }
 
 int main(int argc, const char** argv)
 {
@@ -241,30 +233,47 @@ int main(int argc, const char** argv)
       return 0;
     }
 
     if (queryParameters.find("ProductName") == queryParameters.end()) {
       UIError("No product name specified");
       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)) {
       UIError("Couldn't get settings path");
       return 0;
     }
 
     string pendingDir = gSettingsPath + UI_DIR_SEPARATOR + "pending";
     if (!MoveCrashData(pendingDir, gDumpFile, gExtraFile)) {
       UIError("Couldn't move crash data");
       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();
 
   return 0;
 }
 
 #if defined(XP_WIN) && !defined(__GNUC__)
--- a/toolkit/crashreporter/client/crashreporter.h
+++ b/toolkit/crashreporter/client/crashreporter.h
@@ -1,11 +1,14 @@
 #ifndef CRASHREPORTER_H__
 #define CRASHREPORTER_H__
 
+#pragma warning( push )
+// Disable exception handler warnings.
+#pragma warning( disable : 4530 )
 #include <string>
 #include <map>
 #include <stdlib.h>
 #include <stdio.h>
 
 #if defined(XP_WIN32)
 
 #include <windows.h>
@@ -66,9 +69,10 @@ void UIError(const std::string& message)
 bool UIGetIniPath(std::string& path);
 bool UIGetSettingsPath(const std::string& vendor,
                        const std::string& product,
                        std::string& settingsPath);
 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
--- a/toolkit/crashreporter/client/crashreporter.ini
+++ b/toolkit/crashreporter/client/crashreporter.ini
@@ -9,11 +9,8 @@ CrashReporterTitle=Mozilla Crash Reporte
 CrashReporterDescription=Crash reporting blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
 RadioEnable=Enable Crash Reporting
 RadioDisable=Disable Crash Reporting
 SendTitle=Sending Crash Report...
 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
--- a/toolkit/crashreporter/client/crashreporter_win.cpp
+++ b/toolkit/crashreporter/client/crashreporter_win.cpp
@@ -425,15 +425,16 @@ bool UIEnsurePathExists(const string& pa
       return false;
   }
 
   return true;
 }
 
 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;
 }
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -283,31 +283,24 @@ static nsresult GetExecutablePath(nsStri
   path[len + 1] = '\0';
 
   exePath = NS_ConvertUTF8toUTF16(path);
 
   return NS_OK;
 #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");
   if (noReportEnv && *noReportEnv)
     doReport = false;
 
   // allocate our strings
   crashReporterAPIData = new nsCString();
@@ -358,27 +351,32 @@ nsresult SetExceptionHandler(nsILocalFil
     return NS_ERROR_FAILURE;
   tempPath = NS_ConvertUTF8toUTF16(path);
 
 #else
   //XXX: implement get temp path on other platforms
   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,
                      MinidumpCallback,
                      nsnull,
                      true);
 
   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;
 }
 
 nsresult SetMinidumpPath(const nsAString& aPath)
 {
   if (!gExceptionHandler)
     return NS_ERROR_NOT_INITIALIZED;
 
--- a/toolkit/crashreporter/nsExceptionHandler.h
+++ b/toolkit/crashreporter/nsExceptionHandler.h
@@ -38,15 +38,16 @@
 #ifndef nsAirbagExceptionHandler_h__
 #define nsAirbagExceptionHandler_h__
 
 #include "nscore.h"
 #include "nsXPCOM.h"
 #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);
 }
 
 #endif /* nsAirbagExceptionHandler_h__ */
--- a/toolkit/crashreporter/test/TestCrashReporterAPI.cpp
+++ b/toolkit/crashreporter/test/TestCrashReporterAPI.cpp
@@ -58,17 +58,17 @@
 #define mu_run_test(test) do { char *message = test(); tests_run++; \
                                 if (message) return message; } while (0)
 int tests_run;
 
 char *
 test_init_exception_handler()
 {
   mu_assert("CrashReporter::SetExceptionHandler",
-            CrashReporter::SetExceptionHandler(nsnull));
+            CrashReporter::SetExceptionHandler(nsnull, nsnull));
   return 0;
 }
 
 char *
 test_set_minidump_path()
 {
   nsresult rv;
   nsCOMPtr<nsIProperties> directoryService =