michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef CRASHREPORTER_H__ michael@0: #define CRASHREPORTER_H__ michael@0: michael@0: #ifdef _MSC_VER michael@0: # pragma warning( push ) michael@0: // Disable exception handler warnings. michael@0: # pragma warning( disable : 4530 ) michael@0: #endif michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #define MAX_COMMENT_LENGTH 500 michael@0: michael@0: #if defined(XP_WIN32) michael@0: michael@0: #include michael@0: michael@0: #define UI_SNPRINTF _snprintf michael@0: #define UI_DIR_SEPARATOR "\\" michael@0: michael@0: std::string WideToUTF8(const std::wstring& wide, bool* success = 0); michael@0: michael@0: #else michael@0: michael@0: #define UI_SNPRINTF snprintf michael@0: #define UI_DIR_SEPARATOR "/" michael@0: michael@0: #endif michael@0: michael@0: typedef std::map StringTable; michael@0: michael@0: #define ST_CRASHREPORTERTITLE "CrashReporterTitle" michael@0: #define ST_CRASHREPORTERVENDORTITLE "CrashReporterVendorTitle" michael@0: #define ST_CRASHREPORTERERROR "CrashReporterErrorText" michael@0: #define ST_CRASHREPORTERPRODUCTERROR "CrashReporterProductErrorText2" michael@0: #define ST_CRASHREPORTERHEADER "CrashReporterSorry" michael@0: #define ST_CRASHREPORTERDESCRIPTION "CrashReporterDescriptionText2" michael@0: #define ST_CRASHREPORTERDEFAULT "CrashReporterDefault" michael@0: #define ST_VIEWREPORT "Details" michael@0: #define ST_VIEWREPORTTITLE "ViewReportTitle" michael@0: #define ST_COMMENTGRAYTEXT "CommentGrayText" michael@0: #define ST_EXTRAREPORTINFO "ExtraReportInfo" michael@0: #define ST_CHECKSUBMIT "CheckSendReport" michael@0: #define ST_CHECKURL "CheckIncludeURL" michael@0: #define ST_CHECKEMAIL "CheckAllowEmail" michael@0: #define ST_EMAILGRAYTEXT "EmailGrayText" michael@0: #define ST_REPORTPRESUBMIT "ReportPreSubmit2" michael@0: #define ST_REPORTDURINGSUBMIT "ReportDuringSubmit2" michael@0: #define ST_REPORTSUBMITSUCCESS "ReportSubmitSuccess" michael@0: #define ST_SUBMITFAILED "ReportSubmitFailed" michael@0: #define ST_QUIT "Quit2" michael@0: #define ST_RESTART "Restart" michael@0: #define ST_OK "Ok" michael@0: #define ST_CLOSE "Close" michael@0: michael@0: #define ST_ERROR_BADARGUMENTS "ErrorBadArguments" michael@0: #define ST_ERROR_EXTRAFILEEXISTS "ErrorExtraFileExists" michael@0: #define ST_ERROR_EXTRAFILEREAD "ErrorExtraFileRead" michael@0: #define ST_ERROR_EXTRAFILEMOVE "ErrorExtraFileMove" michael@0: #define ST_ERROR_DUMPFILEEXISTS "ErrorDumpFileExists" michael@0: #define ST_ERROR_DUMPFILEMOVE "ErrorDumpFileMove" michael@0: #define ST_ERROR_NOPRODUCTNAME "ErrorNoProductName" michael@0: #define ST_ERROR_NOSERVERURL "ErrorNoServerURL" michael@0: #define ST_ERROR_NOSETTINGSPATH "ErrorNoSettingsPath" michael@0: #define ST_ERROR_CREATEDUMPDIR "ErrorCreateDumpDir" michael@0: #define ST_ERROR_ENDOFLIFE "ErrorEndOfLife" michael@0: michael@0: //============================================================================= michael@0: // implemented in crashreporter.cpp michael@0: //============================================================================= michael@0: michael@0: namespace CrashReporter { michael@0: extern StringTable gStrings; michael@0: extern std::string gSettingsPath; michael@0: extern int gArgc; michael@0: extern char** gArgv; michael@0: michael@0: void UIError(const std::string& message); michael@0: michael@0: // The UI finished sending the report michael@0: void SendCompleted(bool success, const std::string& serverResponse); michael@0: michael@0: bool ReadStrings(std::istream& in, michael@0: StringTable& strings, michael@0: bool unescape); michael@0: bool ReadStringsFromFile(const std::string& path, michael@0: StringTable& strings, michael@0: bool unescape); michael@0: bool WriteStrings(std::ostream& out, michael@0: const std::string& header, michael@0: StringTable& strings, michael@0: bool escape); michael@0: bool WriteStringsToFile(const std::string& path, michael@0: const std::string& header, michael@0: StringTable& strings, michael@0: bool escape); michael@0: void LogMessage(const std::string& message); michael@0: void DeleteDump(); michael@0: bool ShouldEnableSending(); michael@0: michael@0: static const unsigned int kSaveCount = 10; michael@0: } michael@0: michael@0: //============================================================================= michael@0: // implemented in the platform-specific files michael@0: //============================================================================= michael@0: michael@0: bool UIInit(); michael@0: void UIShutdown(); michael@0: michael@0: // Run the UI for when the app was launched without a dump file michael@0: void UIShowDefaultUI(); michael@0: michael@0: // Run the UI for when the app was launched with a dump file michael@0: // Return true if the user sent (or tried to send) the crash report, michael@0: // false if they chose not to, and it should be deleted. michael@0: bool UIShowCrashUI(const std::string& dumpfile, michael@0: const StringTable& queryParameters, michael@0: const std::string& sendURL, michael@0: const std::vector& restartArgs); michael@0: michael@0: void UIError_impl(const std::string& message); michael@0: michael@0: bool UIGetIniPath(std::string& path); michael@0: bool UIGetSettingsPath(const std::string& vendor, michael@0: const std::string& product, michael@0: std::string& settingsPath); michael@0: bool UIEnsurePathExists(const std::string& path); michael@0: bool UIFileExists(const std::string& path); michael@0: bool UIMoveFile(const std::string& oldfile, const std::string& newfile); michael@0: bool UIDeleteFile(const std::string& oldfile); michael@0: std::ifstream* UIOpenRead(const std::string& filename); michael@0: std::ofstream* UIOpenWrite(const std::string& filename, bool append=false); michael@0: void UIPruneSavedDumps(const std::string& directory); michael@0: michael@0: #ifdef _MSC_VER michael@0: # pragma warning( pop ) michael@0: #endif michael@0: michael@0: #endif