|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef CRASHREPORTER_H__ |
|
6 #define CRASHREPORTER_H__ |
|
7 |
|
8 #ifdef _MSC_VER |
|
9 # pragma warning( push ) |
|
10 // Disable exception handler warnings. |
|
11 # pragma warning( disable : 4530 ) |
|
12 #endif |
|
13 |
|
14 #include <string> |
|
15 #include <map> |
|
16 #include <vector> |
|
17 #include <stdlib.h> |
|
18 #include <stdio.h> |
|
19 #include <iostream> |
|
20 #include <fstream> |
|
21 |
|
22 #define MAX_COMMENT_LENGTH 500 |
|
23 |
|
24 #if defined(XP_WIN32) |
|
25 |
|
26 #include <windows.h> |
|
27 |
|
28 #define UI_SNPRINTF _snprintf |
|
29 #define UI_DIR_SEPARATOR "\\" |
|
30 |
|
31 std::string WideToUTF8(const std::wstring& wide, bool* success = 0); |
|
32 |
|
33 #else |
|
34 |
|
35 #define UI_SNPRINTF snprintf |
|
36 #define UI_DIR_SEPARATOR "/" |
|
37 |
|
38 #endif |
|
39 |
|
40 typedef std::map<std::string, std::string> StringTable; |
|
41 |
|
42 #define ST_CRASHREPORTERTITLE "CrashReporterTitle" |
|
43 #define ST_CRASHREPORTERVENDORTITLE "CrashReporterVendorTitle" |
|
44 #define ST_CRASHREPORTERERROR "CrashReporterErrorText" |
|
45 #define ST_CRASHREPORTERPRODUCTERROR "CrashReporterProductErrorText2" |
|
46 #define ST_CRASHREPORTERHEADER "CrashReporterSorry" |
|
47 #define ST_CRASHREPORTERDESCRIPTION "CrashReporterDescriptionText2" |
|
48 #define ST_CRASHREPORTERDEFAULT "CrashReporterDefault" |
|
49 #define ST_VIEWREPORT "Details" |
|
50 #define ST_VIEWREPORTTITLE "ViewReportTitle" |
|
51 #define ST_COMMENTGRAYTEXT "CommentGrayText" |
|
52 #define ST_EXTRAREPORTINFO "ExtraReportInfo" |
|
53 #define ST_CHECKSUBMIT "CheckSendReport" |
|
54 #define ST_CHECKURL "CheckIncludeURL" |
|
55 #define ST_CHECKEMAIL "CheckAllowEmail" |
|
56 #define ST_EMAILGRAYTEXT "EmailGrayText" |
|
57 #define ST_REPORTPRESUBMIT "ReportPreSubmit2" |
|
58 #define ST_REPORTDURINGSUBMIT "ReportDuringSubmit2" |
|
59 #define ST_REPORTSUBMITSUCCESS "ReportSubmitSuccess" |
|
60 #define ST_SUBMITFAILED "ReportSubmitFailed" |
|
61 #define ST_QUIT "Quit2" |
|
62 #define ST_RESTART "Restart" |
|
63 #define ST_OK "Ok" |
|
64 #define ST_CLOSE "Close" |
|
65 |
|
66 #define ST_ERROR_BADARGUMENTS "ErrorBadArguments" |
|
67 #define ST_ERROR_EXTRAFILEEXISTS "ErrorExtraFileExists" |
|
68 #define ST_ERROR_EXTRAFILEREAD "ErrorExtraFileRead" |
|
69 #define ST_ERROR_EXTRAFILEMOVE "ErrorExtraFileMove" |
|
70 #define ST_ERROR_DUMPFILEEXISTS "ErrorDumpFileExists" |
|
71 #define ST_ERROR_DUMPFILEMOVE "ErrorDumpFileMove" |
|
72 #define ST_ERROR_NOPRODUCTNAME "ErrorNoProductName" |
|
73 #define ST_ERROR_NOSERVERURL "ErrorNoServerURL" |
|
74 #define ST_ERROR_NOSETTINGSPATH "ErrorNoSettingsPath" |
|
75 #define ST_ERROR_CREATEDUMPDIR "ErrorCreateDumpDir" |
|
76 #define ST_ERROR_ENDOFLIFE "ErrorEndOfLife" |
|
77 |
|
78 //============================================================================= |
|
79 // implemented in crashreporter.cpp |
|
80 //============================================================================= |
|
81 |
|
82 namespace CrashReporter { |
|
83 extern StringTable gStrings; |
|
84 extern std::string gSettingsPath; |
|
85 extern int gArgc; |
|
86 extern char** gArgv; |
|
87 |
|
88 void UIError(const std::string& message); |
|
89 |
|
90 // The UI finished sending the report |
|
91 void SendCompleted(bool success, const std::string& serverResponse); |
|
92 |
|
93 bool ReadStrings(std::istream& in, |
|
94 StringTable& strings, |
|
95 bool unescape); |
|
96 bool ReadStringsFromFile(const std::string& path, |
|
97 StringTable& strings, |
|
98 bool unescape); |
|
99 bool WriteStrings(std::ostream& out, |
|
100 const std::string& header, |
|
101 StringTable& strings, |
|
102 bool escape); |
|
103 bool WriteStringsToFile(const std::string& path, |
|
104 const std::string& header, |
|
105 StringTable& strings, |
|
106 bool escape); |
|
107 void LogMessage(const std::string& message); |
|
108 void DeleteDump(); |
|
109 bool ShouldEnableSending(); |
|
110 |
|
111 static const unsigned int kSaveCount = 10; |
|
112 } |
|
113 |
|
114 //============================================================================= |
|
115 // implemented in the platform-specific files |
|
116 //============================================================================= |
|
117 |
|
118 bool UIInit(); |
|
119 void UIShutdown(); |
|
120 |
|
121 // Run the UI for when the app was launched without a dump file |
|
122 void UIShowDefaultUI(); |
|
123 |
|
124 // Run the UI for when the app was launched with a dump file |
|
125 // Return true if the user sent (or tried to send) the crash report, |
|
126 // false if they chose not to, and it should be deleted. |
|
127 bool UIShowCrashUI(const std::string& dumpfile, |
|
128 const StringTable& queryParameters, |
|
129 const std::string& sendURL, |
|
130 const std::vector<std::string>& restartArgs); |
|
131 |
|
132 void UIError_impl(const std::string& message); |
|
133 |
|
134 bool UIGetIniPath(std::string& path); |
|
135 bool UIGetSettingsPath(const std::string& vendor, |
|
136 const std::string& product, |
|
137 std::string& settingsPath); |
|
138 bool UIEnsurePathExists(const std::string& path); |
|
139 bool UIFileExists(const std::string& path); |
|
140 bool UIMoveFile(const std::string& oldfile, const std::string& newfile); |
|
141 bool UIDeleteFile(const std::string& oldfile); |
|
142 std::ifstream* UIOpenRead(const std::string& filename); |
|
143 std::ofstream* UIOpenWrite(const std::string& filename, bool append=false); |
|
144 void UIPruneSavedDumps(const std::string& directory); |
|
145 |
|
146 #ifdef _MSC_VER |
|
147 # pragma warning( pop ) |
|
148 #endif |
|
149 |
|
150 #endif |