Bug 380540 - crash reporter client on linux, r=luser
authordcamp@mozilla.com
Tue, 24 Jul 2007 18:06:08 -0700
changeset 3905 023456fb738894d07fb766a1ea47ae6334ec3566
parent 3904 af9b2f64a38055ebae2e5ed7f276b1fe14f6c7ac
child 3906 f6f7878656d576a6534a1abfa0bf7eed8427d4a9
push idunknown
push userunknown
push dateunknown
reviewersluser
bugs380540
milestone1.9a7pre
Bug 380540 - crash reporter client on linux, r=luser
toolkit/crashreporter/client/Makefile.in
toolkit/crashreporter/client/crashreporter.cpp
toolkit/crashreporter/client/crashreporter.h
toolkit/crashreporter/client/crashreporter_linux.cpp
toolkit/crashreporter/client/crashreporter_osx.mm
toolkit/crashreporter/client/crashreporter_win.cpp
--- a/toolkit/crashreporter/client/Makefile.in
+++ b/toolkit/crashreporter/client/Makefile.in
@@ -53,51 +53,59 @@ DIST_FILES = crashreporter.ini
 
 LOCAL_INCLUDES = -I$(srcdir)/../airbag/src
 
 CPPSRCS = crashreporter.cpp
 
 ifeq ($(OS_ARCH),WINNT)
 CPPSRCS += crashreporter_win.cpp
 LIBS += \
-	$(DEPTH)/toolkit/airbag/airbag/src/client/windows/sender/$(LIB_PREFIX)crash_report_sender_s.$(LIB_SUFFIX) \
-	$(DEPTH)/toolkit/airbag/airbag/src/common/windows/$(LIB_PREFIX)breakpad_windows_common_s.$(LIB_SUFFIX) \
-	$(NULL)
+  $(DEPTH)/toolkit/airbag/airbag/src/client/windows/sender/$(LIB_PREFIX)crash_report_sender_s.$(LIB_SUFFIX) \
+  $(DEPTH)/toolkit/airbag/airbag/src/common/windows/$(LIB_PREFIX)breakpad_windows_common_s.$(LIB_SUFFIX) \
+  $(NULL)
 LOCAL_INCLUDES += -I$(srcdir)
 RCINCLUDE = crashreporter.rc
 DEFINES += -DUNICODE -D_UNICODE
 OS_LIBS += $(call EXPAND_LIBNAME,comctl32 shell32 wininet shlwapi)
 MOZ_WINCONSOLE = 0
 endif
 
 ifeq ($(OS_ARCH),Darwin)
 CMMSRCS += crashreporter_osx.mm
 OS_LIBS += -framework Cocoa
 LIBS += \
-	$(DEPTH)/toolkit/airbag/airbag/src/client/mac/handler/$(LIB_PREFIX)exception_handler_s.$(LIB_SUFFIX) \
-	$(DEPTH)/toolkit/airbag/airbag/src/common/mac/$(LIB_PREFIX)breakpad_mac_common_s.$(LIB_SUFFIX) \
-	$(NULL)
+  $(DEPTH)/toolkit/airbag/airbag/src/client/mac/handler/$(LIB_PREFIX)exception_handler_s.$(LIB_SUFFIX) \
+  $(DEPTH)/toolkit/airbag/airbag/src/common/mac/$(LIB_PREFIX)breakpad_mac_common_s.$(LIB_SUFFIX) \
+  $(NULL)
 
 LOCAL_INCLUDES += -I$(srcdir) -I$(srcdir)/../airbag/src/common/mac/
 endif
 
 ifeq ($(OS_ARCH),Linux)
 CPPSRCS += crashreporter_linux.cpp
 LIBS += \
   $(DEPTH)/toolkit/airbag/airbag/src/common/linux/$(LIB_PREFIX)breakpad_linux_common_s.$(LIB_SUFFIX) \
   $(NULL)
 LOCAL_INCLUDES += -I$(srcdir)
+OS_CXXFLAGS += $(MOZ_GTK2_CFLAGS) $(MOZ_LIBCURL_CFLAGS)
+OS_LIBS += $(MOZ_GTK2_LIBS) $(MOZ_LIBCURL_LIBS)
+CPPSRCS += http_upload.cc
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 ifeq ($(OS_ARCH),Darwin)
 libs::
 	$(NSINSTALL) -D $(DIST)/bin/crashreporter.app
 	rsync -a -C --exclude "*.in" $(srcdir)/macbuild/Contents $(DIST)/bin/crashreporter.app 
 	sed -e "s/%APP_NAME%/$(MOZ_APP_DISPLAYNAME)/" $(srcdir)/macbuild/Contents/Resources/English.lproj/InfoPlist.strings.in | \
 	  iconv -f UTF-8 -t UTF-16 > $(DIST)/bin/crashreporter.app/Contents/Resources/English.lproj/InfoPlist.strings
 	$(NSINSTALL) -D $(DIST)/bin/crashreporter.app/Contents/MacOS
 	$(NSINSTALL) $(DIST)/bin/crashreporter $(DIST)/bin/crashreporter.app/Contents/MacOS
 	rm -f $(DIST)/bin/crashreporter
 	$(NSINSTALL) $(DIST)/bin/crashreporter.ini $(DIST)/bin/crashreporter.app/Contents/MacOS
 	rm -f $(DIST)/bin/crashreporter.ini
 endif
+
+ifeq ($(OS_ARCH),Linux)
+export:: $(srcdir)/../airbag/src/common/linux/http_upload.cc
+	$(INSTALL) $^ .
+endif
--- a/toolkit/crashreporter/client/crashreporter.cpp
+++ b/toolkit/crashreporter/client/crashreporter.cpp
@@ -51,23 +51,25 @@ using std::string;
 using std::istream;
 using std::ifstream;
 using std::istringstream;
 using std::ostringstream;
 using std::ostream;
 using std::ofstream;
 using std::vector;
 
+namespace CrashReporter {
+
 StringTable  gStrings;
+string       gSettingsPath;
 int          gArgc;
-const char** gArgv;
+char**       gArgv;
 
 static string       gDumpFile;
 static string       gExtraFile;
-static string       gSettingsPath;
 
 static string kExtraDataExtension = ".extra";
 
 static string Unescape(const string& str)
 {
   string ret;
   for (string::const_iterator iter = str.begin();
        iter != str.end();
@@ -84,17 +86,37 @@ static string Unescape(const string& str
     } else {
       ret.push_back(*iter);
     }
   }
 
   return ret;
 }
 
-static bool ReadStrings(istream& in, StringTable& strings, bool unescape)
+static string Escape(const string& str)
+{
+  string ret;
+  for (string::const_iterator iter = str.begin();
+       iter != str.end();
+       iter++) {
+    if (*iter == '\\') {
+      ret += "\\\\";
+    } else if (*iter == '\n') {
+      ret += "\\n";
+    } else if (*iter == '\t') {
+      ret += "\\t";
+    } else {
+      ret.push_back(*iter);
+    }
+  }
+
+  return ret;
+}
+
+bool ReadStrings(istream& in, StringTable& strings, bool unescape)
 {
   string currentSection;
   while (!in.eof()) {
     string line;
     std::getline(in, line);
     int sep = line.find('=');
     if (sep >= 0) {
       string key, value;
@@ -104,26 +126,58 @@ static bool ReadStrings(istream& in, Str
         value = Unescape(value);
       strings[key] = value;
     }
   }
 
   return true;
 }
 
-static bool ReadStringsFromFile(const string& path,
-                                StringTable& strings,
-                                bool unescape)
+bool ReadStringsFromFile(const string& path,
+                         StringTable& strings,
+                         bool unescape)
 {
   ifstream f(path.c_str(), std::ios::in);
   if (!f.is_open()) return false;
 
   return ReadStrings(f, strings, unescape);
 }
 
+bool WriteStrings(ostream& out,
+                  const string& header,
+                  StringTable& strings,
+                  bool escape)
+{
+  out << "[" << header << "]" << std::endl;
+  for (StringTable::iterator iter = strings.begin();
+       iter != strings.end();
+       iter++) {
+    out << iter->first << "=";
+    if (escape)
+      out << Escape(iter->second);
+    else
+      out << iter->second;
+
+    out << std::endl;
+  }
+
+  return true;
+}
+
+bool WriteStringsToFile(const string& path,
+                        const string& header,
+                        StringTable& strings,
+                        bool escape)
+{
+  ofstream f(path.c_str(), std::ios::out);
+  if (!f.is_open()) return false;
+
+  return WriteStrings(f, header, strings, escape);
+}
+
 static bool ReadConfig()
 {
   string iniPath;
   if (!UIGetIniPath(iniPath))
     return false;
 
   if (!ReadStringsFromFile(iniPath, gStrings, true))
     return false;
@@ -209,34 +263,37 @@ static bool AddSubmittedReport(const str
   }
 
   file.close();
 
   return true;
 
 }
 
-bool CrashReporterSendCompleted(bool success,
-                                const string& serverResponse)
+bool SendCompleted(bool success, const string& serverResponse)
 {
   if (success) {
     const char* noDelete = getenv("MOZ_CRASHREPORTER_NO_DELETE_DUMP");
     if (!noDelete || *noDelete == '\0') {
       if (!gDumpFile.empty())
         UIDeleteFile(gDumpFile);
       if (!gExtraFile.empty())
         UIDeleteFile(gExtraFile);
     }
 
     return AddSubmittedReport(serverResponse);
   }
   return true;
 }
 
-int main(int argc, const char** argv)
+} // namespace CrashReporter
+
+using namespace CrashReporter;
+
+int main(int argc, char** argv)
 {
   gArgc = argc;
   gArgv = argv;
 
   if (!ReadConfig()) {
     UIError("Couldn't read configuration");
     return 0;
   }
@@ -344,11 +401,11 @@ int main(int argc, const char** argv)
 }
 
 #if defined(XP_WIN) && !defined(__GNUC__)
 // We need WinMain in order to not be a console app.  This function is unused
 // if we are a console application.
 int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR args, int )
 {
   // Do the real work.
-  return main(__argc, (const char**)__argv);
+  return main(__argc, __argv);
 }
 #endif
--- a/toolkit/crashreporter/client/crashreporter.h
+++ b/toolkit/crashreporter/client/crashreporter.h
@@ -7,16 +7,17 @@
 # pragma warning( disable : 4530 )
 #endif
 
 #include <string>
 #include <map>
 #include <vector>
 #include <stdlib.h>
 #include <stdio.h>
+#include <iostream>
 
 #if defined(XP_WIN32)
 
 #include <windows.h>
 #define UI_SNPRINTF _snprintf
 #define UI_DIR_SEPARATOR "\\"
 
 #else
@@ -39,23 +40,41 @@ typedef std::map<std::string, std::strin
 #define ST_CLOSE                    "Close"
 #define ST_RESTART                  "Restart"
 #define ST_SUBMITFAILED             "SubmitFailed"
 
 //=============================================================================
 // implemented in crashreporter.cpp
 //=============================================================================
 
-extern StringTable  gStrings;
-extern int          gArgc;
-extern const char** gArgv;
+namespace CrashReporter {
+  extern StringTable  gStrings;
+  extern std::string  gSettingsPath;
+  extern int          gArgc;
+  extern char**       gArgv;
+
+  // The UI finished sending the report
+  bool SendCompleted(bool success, const std::string& serverResponse);
 
-// The UI finished sending the report
-bool CrashReporterSendCompleted(bool success,
-                                const std::string& serverResponse);
+  bool ReadStrings(std::istream& in,
+                   StringTable& strings,
+                   bool unescape);
+  bool ReadStringsFromFile(const std::string& path,
+                           StringTable& strings,
+                           bool unescape);
+  bool WriteStrings(std::ostream& out,
+                    const std::string& header,
+                    StringTable& strings,
+                    bool escape);
+  bool WriteStringsToFile(const std::string& path,
+                          const std::string& header,
+                          StringTable& strings,
+                          bool escape);
+
+}
 
 //=============================================================================
 // implemented in the platform-specific files
 //=============================================================================
 
 bool UIInit();
 void UIShutdown();
 
--- a/toolkit/crashreporter/client/crashreporter_linux.cpp
+++ b/toolkit/crashreporter/client/crashreporter_linux.cpp
@@ -42,47 +42,398 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include <errno.h>
 
 #include <algorithm>
 #include <cctype>
 
+#include <gtk/gtkhbbox.h>
+#include <gtk/gtkcheckbutton.h>
+#include <gtk/gtkcontainer.h>
+#include <gtk/gtkdialog.h>
+#include <gtk/gtkentry.h>
+#include <gtk/gtkexpander.h>
+#include <gtk/gtkhbox.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkmain.h>
+#include <gtk/gtkmessagedialog.h>
+#include <gtk/gtkscrolledwindow.h>
+#include <gtk/gtktextview.h>
+#include <gtk/gtktextbuffer.h>
+#include <gtk/gtktogglebutton.h>
+#include <gtk/gtkvbox.h>
+#include <gtk/gtkwindow.h>
+
+#include "common/linux/http_upload.h"
+
 using std::string;
 using std::vector;
 
+using namespace CrashReporter;
+
+static GtkWidget* gWindow = 0;
+static GtkWidget* gViewReportTextView = 0;
+static GtkWidget* gSubmitReportCheck = 0;
+static GtkWidget* gEmailMeCheck = 0;
+static GtkWidget* gEmailEntry = 0;
+
+static bool gInitialized = false;
+static string gDumpFile;
+static StringTable gQueryParameters;
+static string gSendURL;
+static vector<string> gRestartArgs;
+
+static const char kIniFile[] = "crashreporter.ini";
+
+static void LoadSettings()
+{
+  StringTable settings;
+  if (ReadStringsFromFile(gSettingsPath + "/" + kIniFile, settings, true)) {
+    if (settings.find("Email") != settings.end()) {
+      gtk_entry_set_text(GTK_ENTRY(gEmailEntry), settings["Email"].c_str());
+    }
+    if (settings.find("EmailMe") != settings.end()) {
+      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gEmailMeCheck),
+                                   settings["EmailMe"][0] != '0');
+    }
+    if (settings.find("SubmitReport") != settings.end()) {
+      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck),
+                                   settings["SubmitReport"][0] != '0');
+    }
+  }
+}
+
+static void SaveSettings()
+{
+  StringTable settings;
+
+  ReadStringsFromFile(gSettingsPath + "/" + kIniFile, settings, true);
+  settings["Email"] = gtk_entry_get_text(GTK_ENTRY(gEmailEntry));
+  settings["EmailMe"] =
+    gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gEmailMeCheck)) ? "1" : "0";
+
+  settings["SubmitReport"] =
+    gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck))
+    ? "1" : "0";
+
+  WriteStringsToFile(gSettingsPath + "/" + kIniFile,
+                     "Crash Reporter", settings, true);
+}
+
+static bool RestartApplication()
+{
+  char** argv = reinterpret_cast<char**>(
+    malloc(sizeof(char*) * (gRestartArgs.size() + 1)));
+
+  if (!argv) return false;
+
+  unsigned int i;
+  for (i = 0; i < gRestartArgs.size(); i++) {
+    argv[i] = (char*)gRestartArgs[i].c_str();
+  }
+  argv[i] = 0;
+
+  pid_t pid = fork();
+  if (pid == -1)
+    return false;
+  else if (pid == 0) {
+    (void)execv(argv[0], argv);
+    _exit(1);
+  }
+
+  free(argv);
+
+  return true;
+}
+
+static gboolean SendReportIdle(gpointer userData)
+{
+  string response;
+  bool success = google_breakpad::HTTPUpload::SendRequest
+    (gSendURL,
+     gQueryParameters,
+     gDumpFile,
+     "upload_file_minidump",
+     "", "",
+     &response);
+  SendCompleted(success, response);
+
+  if (!success) {
+    GtkWidget* errorDialog =
+      gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
+                             GTK_MESSAGE_ERROR,
+                             GTK_BUTTONS_CLOSE,
+                             "%s", gStrings[ST_SUBMITFAILED].c_str());
+
+    gtk_window_set_title(GTK_WINDOW(errorDialog),
+                         gStrings[ST_CRASHREPORTERTITLE].c_str());
+    gtk_dialog_run(GTK_DIALOG(errorDialog));
+  }
+  gtk_main_quit();
+
+  return FALSE;
+}
+
+static void SendReport()
+{
+  // On the other platforms we spawn off a thread here.  Because the window
+  // should be hidden before the report is sent, don't bother to spawn
+  // a thread here.  Just kick it out to an idle handler (to give
+  // gtk_widget_hide() a chance to take)
+  g_idle_add(SendReportIdle, 0);
+}
+
+static void ShowReportInfo()
+{
+  GtkTextBuffer* buffer =
+    gtk_text_view_get_buffer(GTK_TEXT_VIEW(gViewReportTextView));
+
+  GtkTextIter start, end;
+  gtk_text_buffer_get_start_iter(buffer, &start);
+  gtk_text_buffer_get_end_iter(buffer, &end);
+
+  gtk_text_buffer_delete(buffer, &start, &end);
+
+  for (StringTable::iterator iter = gQueryParameters.begin();
+       iter != gQueryParameters.end();
+       iter++) {
+    gtk_text_buffer_insert(buffer, &end, iter->first.c_str(), -1);
+    gtk_text_buffer_insert(buffer, &end, ": ", -1);
+    gtk_text_buffer_insert(buffer, &end, iter->second.c_str(), -1);
+    gtk_text_buffer_insert(buffer, &end, "\n", -1);
+  }
+
+  gtk_text_buffer_insert(buffer, &end, "\n", -1);
+  gtk_text_buffer_insert(buffer, &end,
+                         gStrings[ST_EXTRAREPORTINFO].c_str(), -1);
+}
+
+static gboolean WindowDeleted(GtkWidget* window,
+                              GdkEvent* event,
+                              gpointer userData)
+{
+  SaveSettings();
+  gtk_main_quit();
+  return TRUE;
+}
+
+static void CloseClicked(GtkButton* button,
+                         gpointer userData)
+{
+  SaveSettings();
+  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck))) {
+    gtk_widget_hide(gWindow);
+    SendReport();
+  } else {
+    gtk_main_quit();
+  }
+}
+
+static void RestartClicked(GtkButton* button,
+                           gpointer userData)
+{
+  SaveSettings();
+  RestartApplication();
+
+  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck))) {
+    gtk_widget_hide(gWindow);
+    SendReport();
+  } else {
+    gtk_main_quit();
+  }
+}
+
+static void UpdateEmail()
+{
+  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gEmailMeCheck))) {
+    gQueryParameters["Email"] = gtk_entry_get_text(GTK_ENTRY(gEmailEntry));
+  } else {
+    gQueryParameters.erase("Email");
+  }
+}
+
+static void EmailMeClicked(GtkButton* sender, gpointer userData)
+{
+  UpdateEmail();
+  ShowReportInfo();
+}
+
+static void EmailChanged(GtkEditable* editable, gpointer userData)
+{
+  // Email text changed, assume they want the "Email me" checkbox
+  // updated appropriately
+  const char* email = gtk_entry_get_text(GTK_ENTRY(editable));
+  if (email[0] == '\0')
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gEmailMeCheck), FALSE);
+  else
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gEmailMeCheck), TRUE);
+
+  UpdateEmail();
+  ShowReportInfo();
+}
+
+/* === Crashreporter UI Functions === */
+
 bool UIInit()
 {
-  //XXX: implement me
-  return true;
+  if (gtk_init_check(&gArgc, &gArgv)) {
+    gInitialized = true;
+    return true;
+  }
+
+  return false;
 }
 
 void UIShutdown()
 {
-  //XXX: implement me
 }
 
 void UIShowDefaultUI()
 {
-  //XXX: implement me
+  GtkWidget* errorDialog =
+    gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
+                           GTK_MESSAGE_ERROR,
+                           GTK_BUTTONS_CLOSE,
+                           "%s", gStrings[ST_CRASHREPORTERDEFAULT].c_str());
+
+  gtk_window_set_title(GTK_WINDOW(errorDialog),
+                       gStrings[ST_CRASHREPORTERTITLE].c_str());
+  gtk_dialog_run(GTK_DIALOG(errorDialog));
 }
 
 void UIShowCrashUI(const string& dumpfile,
                    const StringTable& queryParameters,
                    const string& sendURL,
                    const vector<string>& restartArgs)
 {
-  //XXX: implement me
+  gDumpFile = dumpfile;
+  gQueryParameters = queryParameters;
+  gSendURL = sendURL;
+  gRestartArgs = restartArgs;
+
+  gWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_title(GTK_WINDOW(gWindow),
+                       gStrings[ST_CRASHREPORTERTITLE].c_str());
+  gtk_window_set_resizable(GTK_WINDOW(gWindow), FALSE);
+  gtk_container_set_border_width(GTK_CONTAINER(gWindow), 12);
+  g_signal_connect(gWindow, "delete-event", G_CALLBACK(WindowDeleted), 0);
+
+  GtkWidget* vbox = gtk_vbox_new(FALSE, 6);
+  gtk_container_add(GTK_CONTAINER(gWindow), vbox);
+
+  GtkWidget* titleLabel = gtk_label_new("");
+  gtk_box_pack_start(GTK_BOX(vbox), titleLabel, FALSE, FALSE, 0);
+  gtk_misc_set_alignment(GTK_MISC(titleLabel), 0, 0.5);
+  char* markup = g_strdup_printf("<b>%s</b>",
+                                 gStrings[ST_CRASHREPORTERHEADER].c_str());
+  gtk_label_set_markup(GTK_LABEL(titleLabel), markup);
+  g_free(markup);
+
+  GtkWidget* descriptionLabel =
+    gtk_label_new(gStrings[ST_CRASHREPORTERDESCRIPTION].c_str());
+  gtk_box_pack_start(GTK_BOX(vbox), descriptionLabel, TRUE, TRUE, 0);
+  // force the label to line wrap
+  gtk_widget_set_size_request(descriptionLabel, 400, -1);
+  gtk_label_set_line_wrap(GTK_LABEL(descriptionLabel), TRUE);
+  gtk_label_set_selectable(GTK_LABEL(descriptionLabel), TRUE);
+  gtk_misc_set_alignment(GTK_MISC(descriptionLabel), 0, 0.5);
+
+  // this is honestly how they suggest you indent a section
+  GtkWidget* indentBox = gtk_hbox_new(FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(vbox), indentBox, FALSE, FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(indentBox), gtk_label_new(""), FALSE, FALSE, 6);
+
+  GtkWidget* innerVBox = gtk_vbox_new(FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(indentBox), innerVBox, TRUE, TRUE, 0);
+
+  GtkWidget* expander = gtk_expander_new(gStrings[ST_VIEWREPORT].c_str());
+  gtk_box_pack_start(GTK_BOX(innerVBox), expander, FALSE, FALSE, 6);
+
+  GtkWidget* scrolled = gtk_scrolled_window_new(0, 0);
+  gtk_container_add(GTK_CONTAINER(expander), scrolled);
+  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
+                                 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+  gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled),
+                                      GTK_SHADOW_IN);
+
+  gViewReportTextView = gtk_text_view_new();
+  gtk_container_add(GTK_CONTAINER(scrolled), gViewReportTextView);
+  gtk_text_view_set_editable(GTK_TEXT_VIEW(gViewReportTextView), FALSE);
+  gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(gViewReportTextView),
+                              GTK_WRAP_WORD);
+  gtk_widget_set_size_request(GTK_WIDGET(gViewReportTextView), -1, 100);
+
+  gSubmitReportCheck =
+    gtk_check_button_new_with_label(gStrings[ST_CHECKSUBMIT].c_str());
+  gtk_box_pack_start(GTK_BOX(innerVBox), gSubmitReportCheck, FALSE, FALSE, 0);
+
+  gEmailMeCheck =
+    gtk_check_button_new_with_label(gStrings[ST_CHECKEMAIL].c_str());
+  gtk_box_pack_start(GTK_BOX(innerVBox), gEmailMeCheck, FALSE, FALSE, 0);
+  g_signal_connect(gEmailMeCheck, "clicked", G_CALLBACK(EmailMeClicked), 0);
+
+  GtkWidget* emailIndentBox = gtk_hbox_new(FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(innerVBox), emailIndentBox, FALSE, FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(emailIndentBox), gtk_label_new(""),
+                     FALSE, FALSE, 9);
+
+  gEmailEntry = gtk_entry_new();
+  gtk_box_pack_start(GTK_BOX(emailIndentBox), gEmailEntry, TRUE, TRUE, 0);
+  g_signal_connect(gEmailEntry, "changed", G_CALLBACK(EmailChanged), 0);
+
+  GtkWidget* buttonBox = gtk_hbutton_box_new();
+  gtk_box_pack_end(GTK_BOX(vbox), buttonBox, FALSE, FALSE, 0);
+  gtk_box_set_spacing(GTK_BOX(buttonBox), 6);
+  gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END);
+
+  GtkWidget* closeButton =
+    gtk_button_new_with_label(gStrings[ST_CLOSE].c_str());
+  gtk_box_pack_start(GTK_BOX(buttonBox), closeButton, FALSE, FALSE, 0);
+  GTK_WIDGET_SET_FLAGS(closeButton, GTK_CAN_DEFAULT);
+  g_signal_connect(closeButton, "clicked", G_CALLBACK(CloseClicked), 0);
+
+  GtkWidget* restartButton = 0;
+  if (restartArgs.size() > 0) {
+    restartButton = gtk_button_new_with_label(gStrings[ST_RESTART].c_str());
+    gtk_box_pack_start(GTK_BOX(buttonBox), restartButton, FALSE, FALSE, 0);
+    GTK_WIDGET_SET_FLAGS(restartButton, GTK_CAN_DEFAULT);
+    g_signal_connect(restartButton, "clicked", G_CALLBACK(RestartClicked), 0);
+  }
+
+  gtk_widget_grab_focus(gEmailEntry);
+
+  gtk_widget_grab_default(restartButton ? restartButton : closeButton);
+
+  LoadSettings();
+  ShowReportInfo();
+
+  gtk_widget_show_all(gWindow);
+
+  gtk_main();
 }
 
 void UIError(const string& message)
 {
-  //XXX: implement me
-  printf("Error: %s\n", message.c_str());
+  if (!gInitialized) {
+    // Didn't initialize, this is the best we can do
+    printf("Error: %s\n", message.c_str());
+    return;
+  }
+
+  GtkWidget* errorDialog =
+    gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
+                           GTK_MESSAGE_ERROR,
+                           GTK_BUTTONS_CLOSE,
+                           "%s", message.c_str());
+
+  gtk_window_set_title(GTK_WINDOW(errorDialog),
+                       gStrings[ST_CRASHREPORTERTITLE].c_str());
+  gtk_dialog_run(GTK_DIALOG(errorDialog));
 }
 
 bool UIGetIniPath(string& path)
 {
   path = gArgv[0];
   path.append(".ini");
 
   return true;
@@ -108,17 +459,16 @@ bool UIGetSettingsPath(const string& ven
     std::transform(vendor.begin(), vendor.end(), back_inserter(lc_vendor),
 		   (int(*)(int)) std::tolower);
     settingsPath += lc_vendor + "/";
   }
   string lc_product;
   std::transform(product.begin(), product.end(), back_inserter(lc_product),
 		 (int(*)(int)) std::tolower);
   settingsPath += lc_product + "/Crash Reports";
-  printf("settingsPath: %s\n", settingsPath.c_str());
   return UIEnsurePathExists(settingsPath);
 }
 
 bool UIEnsurePathExists(const string& path)
 {
   int ret = mkdir(path.c_str(), S_IRWXU);
   int e = errno;
   if (ret == -1 && e != EEXIST)
--- a/toolkit/crashreporter/client/crashreporter_osx.mm
+++ b/toolkit/crashreporter/client/crashreporter_osx.mm
@@ -42,16 +42,18 @@
 #include "crashreporter_osx.h"
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
 
 using std::string;
 using std::vector;
 
+using namespace CrashReporter;
+
 static NSAutoreleasePool* gMainPool;
 static CrashReporterUI* gUI = 0;
 static string gDumpFile;
 static StringTable gQueryParameters;
 static string gSendURL;
 static vector<string> gRestartArgs;
 
 #define NSSTR(s) [NSString stringWithUTF8String:(s).c_str()]
@@ -377,17 +379,17 @@ static bool RestartApplication()
         CFStringConvertIANACharSetNameToEncoding((CFStringRef)encodingName));
     } else {
       encoding = NSISOLatin1StringEncoding;
     }
     NSString* r = [[NSString alloc] initWithData: data encoding: encoding];
     reply = [r UTF8String];
   }
 
-  CrashReporterSendCompleted(success, reply);
+  SendCompleted(success, reply);
 
   if (success) {
     [NSApp terminate:self];
   } else {
     [self showErrorUI:gStrings[ST_SUBMITFAILED]];
   }
 }
 
--- a/toolkit/crashreporter/client/crashreporter_win.cpp
+++ b/toolkit/crashreporter/client/crashreporter_win.cpp
@@ -63,16 +63,18 @@
 #define WM_UPLOADCOMPLETE WM_APP
 
 using std::string;
 using std::wstring;
 using std::map;
 using std::vector;
 using std::set;
 
+using namespace CrashReporter;
+
 typedef struct {
   HWND hDlg;
   wstring dumpFile;
   map<wstring,wstring> queryParameters;
   wstring sendURL;
 
   wstring serverResponse;
 } SendThreadData;
@@ -577,17 +579,17 @@ static BOOL CALLBACK CrashReporterDialog
       }
     }
 
     return FALSE;
   }
   case WM_UPLOADCOMPLETE: {
     WaitForSingleObject(gThreadHandle, INFINITE);
     success = (wParam == 1);
-    CrashReporterSendCompleted(success, WideToUTF8(gSendData.serverResponse));
+    SendCompleted(success, WideToUTF8(gSendData.serverResponse));
     if (!success) {
       MessageBox(hwndDlg,
                  Str(ST_SUBMITFAILED).c_str(),
                  Str(ST_CRASHREPORTERTITLE).c_str(),
                  MB_OK | MB_ICONERROR);
     }
     EndCrashReporterDialog(hwndDlg, success ? 1 : 0);
     return TRUE;