OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/bug_report_util.h" | 5 #include "chrome/browser/bug_report_util.h" |
6 | 6 |
| 7 #include <sstream> |
7 #include <string> | 8 #include <string> |
8 | 9 |
| 10 #include "app/l10n_util.h" |
| 11 #include "base/command_line.h" |
9 #include "base/file_version_info.h" | 12 #include "base/file_version_info.h" |
| 13 #include "base/file_util.h" |
| 14 #include "base/singleton.h" |
10 #include "base/string_util.h" | 15 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_list.h" |
12 #include "chrome/browser/browser_process_impl.h" | 18 #include "chrome/browser/browser_process_impl.h" |
13 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
| 23 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/net/url_fetcher.h" | 24 #include "chrome/common/net/url_fetcher.h" |
18 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 #include "grit/generated_resources.h" |
19 #include "grit/locale_settings.h" | 27 #include "grit/locale_settings.h" |
| 28 #include "grit/theme_resources.h" |
20 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
21 #include "unicode/locid.h" | 30 #include "unicode/locid.h" |
22 | 31 |
| 32 #if defined(OS_CHROMEOS) |
| 33 #include "chrome/browser/chromeos/notifications/system_notification.h" |
| 34 #endif |
| 35 |
23 namespace { | 36 namespace { |
24 | 37 |
25 const int kBugReportVersion = 1; | 38 const int kBugReportVersion = 1; |
26 | 39 |
27 const char kReportPhishingUrl[] = | 40 const char kReportPhishingUrl[] = |
28 "http://www.google.com/safebrowsing/report_phish/"; | 41 "http://www.google.com/safebrowsing/report_phish/"; |
29 | 42 |
30 // URL to post bug reports to. | 43 // URL to post bug reports to. |
31 const char* const kBugReportPostUrl = | 44 static char const kBugReportPostUrl[] = |
32 "https://www.google.com/tools/feedback/chrome/__submit"; | 45 "https://www.google.com/tools/feedback/chrome/__submit"; |
33 | 46 |
34 const char* const kProtBufMimeType = "application/x-protobuf"; | 47 static char const kProtBufMimeType[] = "application/x-protobuf"; |
35 const char* const kPngMimeType = "image/png"; | 48 static char const kPngMimeType[] = "image/png"; |
36 | 49 |
37 // Tags we use in product specific data | 50 // Tags we use in product specific data |
38 const char* const kPageTitleTag = "PAGE TITLE"; | 51 static char const kPageTitleTag[] = "PAGE TITLE"; |
39 const char* const kProblemTypeIdTag = "PROBLEM TYPE ID"; | 52 static char const kProblemTypeIdTag[] = "PROBLEM TYPE ID"; |
40 const char* const kProblemTypeTag = "PROBLEM TYPE"; | 53 static char const kProblemTypeTag[] = "PROBLEM TYPE"; |
41 const char* const kChromeVersionTag = "CHROME VERSION"; | 54 static char const kChromeVersionTag[] = "CHROME VERSION"; |
42 const char* const kOsVersionTag = "OS VERSION"; | 55 static char const kOsVersionTag[] = "OS VERSION"; |
| 56 |
| 57 static char const kNotificationId[] = "feedback.chromeos"; |
| 58 |
| 59 static int const kHttpPostSuccessNoContent = 204; |
| 60 static int const kHttpPostFailNoConnection = -1; |
| 61 static int const kHttpPostFailClientError = 400; |
| 62 static int const kHttpPostFailServerError = 500; |
| 63 |
| 64 } // namespace |
43 | 65 |
44 | 66 |
45 } // namespace | 67 #if defined(OS_CHROMEOS) |
| 68 class FeedbackNotification { |
| 69 public: |
| 70 // Previous notification cleanup is handled by scoped_ptr. |
| 71 // Note: notification will show only on one profile at a time. |
| 72 void Show(Profile* profile, const string16& message, bool urgent) { |
| 73 notification_.reset( |
| 74 new chromeos::SystemNotification(profile, kNotificationId, |
| 75 IDR_STATUSBAR_FEEDBACK, |
| 76 l10n_util::GetStringUTF16( |
| 77 IDS_BUGREPORT_NOTIFICATION_TITLE))); |
| 78 notification_->Show(message, urgent); |
| 79 } |
| 80 |
| 81 private: |
| 82 FeedbackNotification() {} |
| 83 friend struct DefaultSingletonTraits<FeedbackNotification>; |
| 84 |
| 85 scoped_ptr<chromeos::SystemNotification> notification_; |
| 86 DISALLOW_COPY_AND_ASSIGN(FeedbackNotification); |
| 87 }; |
| 88 #endif |
46 | 89 |
47 // Simple URLFetcher::Delegate to clean up URLFetcher on completion. | 90 // Simple URLFetcher::Delegate to clean up URLFetcher on completion. |
48 class BugReportUtil::PostCleanup : public URLFetcher::Delegate { | 91 class BugReportUtil::PostCleanup : public URLFetcher::Delegate { |
49 public: | 92 public: |
| 93 #if defined(OS_CHROMEOS) |
| 94 explicit PostCleanup(Profile* profile); |
| 95 #else |
50 PostCleanup(); | 96 PostCleanup(); |
51 | 97 #endif |
52 // Overridden from URLFetcher::Delegate. | 98 // Overridden from URLFetcher::Delegate. |
53 virtual void OnURLFetchComplete(const URLFetcher* source, | 99 virtual void OnURLFetchComplete(const URLFetcher* source, |
54 const GURL& url, | 100 const GURL& url, |
55 const URLRequestStatus& status, | 101 const URLRequestStatus& status, |
56 int response_code, | 102 int response_code, |
57 const ResponseCookies& cookies, | 103 const ResponseCookies& cookies, |
58 const std::string& data); | 104 const std::string& data); |
59 | 105 |
60 protected: | 106 protected: |
61 virtual ~PostCleanup() {} | 107 virtual ~PostCleanup() {} |
62 | 108 |
63 private: | 109 private: |
| 110 Profile* profile_; |
| 111 |
64 DISALLOW_COPY_AND_ASSIGN(PostCleanup); | 112 DISALLOW_COPY_AND_ASSIGN(PostCleanup); |
65 }; | 113 }; |
66 | 114 |
67 BugReportUtil::PostCleanup::PostCleanup() { | 115 #if defined(OS_CHROMEOS) |
| 116 BugReportUtil::PostCleanup::PostCleanup(Profile* profile) |
| 117 : profile_(profile) { |
| 118 #else |
| 119 BugReportUtil::PostCleanup::PostCleanup() { |
| 120 #endif |
68 } | 121 } |
69 | 122 |
70 void BugReportUtil::PostCleanup::OnURLFetchComplete( | 123 void BugReportUtil::PostCleanup::OnURLFetchComplete( |
71 const URLFetcher* source, | 124 const URLFetcher* source, |
72 const GURL& url, | 125 const GURL& url, |
73 const URLRequestStatus& status, | 126 const URLRequestStatus& status, |
74 int response_code, | 127 int response_code, |
75 const ResponseCookies& cookies, | 128 const ResponseCookies& cookies, |
76 const std::string& data) { | 129 const std::string& data) { |
77 // if not 204, something went wrong | 130 |
78 if (response_code != 204) | 131 std::stringstream error_stream; |
79 LOG(WARNING) << "Submission to feedback server failed. Response code: " << | 132 if (response_code == kHttpPostSuccessNoContent) { |
80 response_code << std::endl; | 133 error_stream << "Success"; |
| 134 } else if (response_code == kHttpPostFailNoConnection) { |
| 135 error_stream << "No connection to server."; |
| 136 } else if ((response_code > kHttpPostFailClientError) && |
| 137 (response_code < kHttpPostFailServerError)) { |
| 138 error_stream << "Client error: HTTP response code " << response_code; |
| 139 } else if (response_code > kHttpPostFailServerError) { |
| 140 error_stream << "Server error: HTTP response code " << response_code; |
| 141 } else { |
| 142 error_stream << "Unknown error: HTTP response code " << response_code; |
| 143 } |
| 144 |
| 145 LOG(WARNING) << "Submission to feedback server (" << url << |
| 146 ") status: " << error_stream.str() << std::endl; |
| 147 |
| 148 #if defined(OS_CHROMEOS) |
| 149 // Show the notification to the user; this notification will stay active till |
| 150 // either the user closes it, or we display another notification. |
| 151 if (response_code == kHttpPostSuccessNoContent) { |
| 152 Singleton<FeedbackNotification>()->Show(profile_, l10n_util::GetStringUTF16( |
| 153 IDS_BUGREPORT_FEEDBACK_STATUS_SUCCESS), false); |
| 154 } else { |
| 155 Singleton<FeedbackNotification>()->Show(profile_, |
| 156 l10n_util::GetStringFUTF16(IDS_BUGREPORT_FEEDBACK_STATUS_FAIL, |
| 157 ASCIIToUTF16(error_stream.str())), |
| 158 true); |
| 159 } |
| 160 #endif |
| 161 |
81 // Delete the URLFetcher. | 162 // Delete the URLFetcher. |
82 delete source; | 163 delete source; |
83 // And then delete ourselves. | 164 // And then delete ourselves. |
84 delete this; | 165 delete this; |
85 } | 166 } |
86 | 167 |
87 // static | 168 // static |
88 void BugReportUtil::SetOSVersion(std::string *os_version) { | 169 void BugReportUtil::SetOSVersion(std::string *os_version) { |
89 #if defined(OS_WIN) | 170 #if defined(OS_WIN) |
90 OSVERSIONINFO osvi; | 171 OSVERSIONINFO osvi; |
(...skipping 14 matching lines...) Expand all Loading... |
105 int32 minor; | 186 int32 minor; |
106 int32 bugFix; | 187 int32 bugFix; |
107 base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugFix); | 188 base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugFix); |
108 *os_version = StringPrintf("%d.%d.%d", major, minor, bugFix); | 189 *os_version = StringPrintf("%d.%d.%d", major, minor, bugFix); |
109 #else | 190 #else |
110 *os_version = "unknown"; | 191 *os_version = "unknown"; |
111 #endif | 192 #endif |
112 } | 193 } |
113 | 194 |
114 // static | 195 // static |
| 196 std::string BugReportUtil::feedback_server_(""); |
| 197 |
| 198 // static |
| 199 void BugReportUtil::SetFeedbackServer(const std::string& server) { |
| 200 feedback_server_ = server; |
| 201 } |
| 202 |
| 203 |
| 204 // static |
115 void BugReportUtil::AddFeedbackData( | 205 void BugReportUtil::AddFeedbackData( |
116 userfeedback::ExternalExtensionSubmit* feedback_data, | 206 userfeedback::ExternalExtensionSubmit* feedback_data, |
117 const std::string& key, const std::string& value) { | 207 const std::string& key, const std::string& value) { |
| 208 // We have no reason to log any empty values - gives us no data |
| 209 if (value == "") return; |
118 // Create log_value object and add it to the web_data object | 210 // Create log_value object and add it to the web_data object |
119 userfeedback::ProductSpecificData log_value; | 211 userfeedback::ProductSpecificData log_value; |
120 log_value.set_key(key); | 212 log_value.set_key(key); |
121 log_value.set_value(value); | 213 log_value.set_value(value); |
122 userfeedback::WebData* web_data = feedback_data->mutable_web_data(); | 214 userfeedback::WebData* web_data = feedback_data->mutable_web_data(); |
123 *(web_data->add_product_specific_data()) = log_value; | 215 *(web_data->add_product_specific_data()) = log_value; |
124 } | 216 } |
125 | 217 |
126 // static | 218 // static |
127 void BugReportUtil::SendReport(Profile* profile, | 219 void BugReportUtil::SendReport(Profile* profile, |
128 const std::string& page_title_text, | 220 const std::string& page_title_text, |
129 int problem_type, | 221 int problem_type, |
130 const std::string& page_url_text, | 222 const std::string& page_url_text, |
131 const std::string& user_email_text, | |
132 const std::string& description, | 223 const std::string& description, |
133 const char* png_data, | 224 const char* png_data, |
134 int png_data_length, | 225 int png_data_length, |
135 int png_width, | 226 int png_width, |
136 #if defined(OS_CHROMEOS) | 227 #if defined(OS_CHROMEOS) |
137 int png_height, | 228 int png_height, |
138 const std::string& problem_type_text, | 229 const std::string& user_email_text, |
139 const chromeos::LogDictionaryType* const sys_info) { | 230 const chromeos::LogDictionaryType* const sys_info) { |
140 #else | 231 #else |
141 int png_height) { | 232 int png_height) { |
142 #endif | 233 #endif |
143 GURL post_url(kBugReportPostUrl); | 234 GURL post_url; |
| 235 |
| 236 if (CommandLine::ForCurrentProcess()-> |
| 237 HasSwitch(switches::kFeedbackServer)) |
| 238 post_url = GURL(CommandLine::ForCurrentProcess()-> |
| 239 GetSwitchValueASCII(switches::kFeedbackServer)); |
| 240 else |
| 241 post_url = GURL(kBugReportPostUrl); |
144 | 242 |
145 // Create google feedback protocol buffer objects | 243 // Create google feedback protocol buffer objects |
146 userfeedback::ExternalExtensionSubmit feedback_data; | 244 userfeedback::ExternalExtensionSubmit feedback_data; |
147 // type id set to 0, unused field but needs to be initialized to 0 | 245 // type id set to 0, unused field but needs to be initialized to 0 |
148 feedback_data.set_type_id(0); | 246 feedback_data.set_type_id(0); |
149 | 247 |
150 userfeedback::CommonData* common_data = feedback_data.mutable_common_data(); | 248 userfeedback::CommonData* common_data = feedback_data.mutable_common_data(); |
151 userfeedback::WebData* web_data = feedback_data.mutable_web_data(); | 249 userfeedback::WebData* web_data = feedback_data.mutable_web_data(); |
152 | 250 |
153 // Set GAIA id to 0. We're not using gaia id's for recording | 251 // Set GAIA id to 0. We're not using gaia id's for recording |
154 // use feedback - we're using the e-mail field, allows users to | 252 // use feedback - we're using the e-mail field, allows users to |
155 // submit feedback from incognito mode and specify any mail id | 253 // submit feedback from incognito mode and specify any mail id |
156 // they wish | 254 // they wish |
157 common_data->set_gaia_id(0); | 255 common_data->set_gaia_id(0); |
158 | 256 |
159 // Add the page title. | 257 // Add the page title. |
160 AddFeedbackData(&feedback_data, std::string(kPageTitleTag), | 258 AddFeedbackData(&feedback_data, std::string(kPageTitleTag), |
161 page_title_text); | 259 page_title_text); |
162 | 260 |
163 AddFeedbackData(&feedback_data, std::string(kProblemTypeIdTag), | |
164 StringPrintf("%d\r\n", problem_type)); | |
165 | |
166 #if defined(OS_CHROMEOS) | 261 #if defined(OS_CHROMEOS) |
167 AddFeedbackData(&feedback_data, std::string(kProblemTypeTag), | |
168 problem_type_text); | |
169 #endif | |
170 | |
171 // Add the user e-mail to the feedback object | 262 // Add the user e-mail to the feedback object |
172 common_data->set_user_email(user_email_text); | 263 common_data->set_user_email(user_email_text); |
| 264 #endif |
173 | 265 |
174 // Add the description to the feedback object | 266 // Add the description to the feedback object |
175 common_data->set_description(description); | 267 common_data->set_description(description); |
176 | 268 |
177 // Add the language | 269 // Add the language |
178 std::string chrome_locale = g_browser_process->GetApplicationLocale(); | 270 std::string chrome_locale = g_browser_process->GetApplicationLocale(); |
179 common_data->set_source_descripton_language(chrome_locale); | 271 common_data->set_source_description_language(chrome_locale); |
180 | 272 |
181 // Set the url | 273 // Set the url |
182 web_data->set_url(page_url_text); | 274 web_data->set_url(page_url_text); |
183 | 275 |
184 // Add the Chrome version | 276 // Add the Chrome version |
185 std::string chrome_version; | 277 std::string chrome_version; |
186 scoped_ptr<FileVersionInfo> version_info(chrome::GetChromeVersionInfo()); | 278 scoped_ptr<FileVersionInfo> version_info(chrome::GetChromeVersionInfo()); |
187 if (version_info.get()) { | 279 if (version_info.get()) { |
188 chrome_version = WideToUTF8(version_info->product_name()) + " - " + | 280 chrome_version = WideToUTF8(version_info->product_name()) + " - " + |
189 WideToUTF8(version_info->file_version()) + | 281 WideToUTF8(version_info->file_version()) + |
(...skipping 25 matching lines...) Expand all Loading... |
215 userfeedback::Dimensions dimensions; | 307 userfeedback::Dimensions dimensions; |
216 dimensions.set_width(static_cast<float>(png_width)); | 308 dimensions.set_width(static_cast<float>(png_width)); |
217 dimensions.set_height(static_cast<float>(png_height)); | 309 dimensions.set_height(static_cast<float>(png_height)); |
218 *(screenshot.mutable_dimensions()) = dimensions; | 310 *(screenshot.mutable_dimensions()) = dimensions; |
219 screenshot.set_binary_content(std::string(png_data, png_data_length)); | 311 screenshot.set_binary_content(std::string(png_data, png_data_length)); |
220 | 312 |
221 // Set the screenshot object in feedback | 313 // Set the screenshot object in feedback |
222 *(feedback_data.mutable_screenshot()) = screenshot; | 314 *(feedback_data.mutable_screenshot()) = screenshot; |
223 } | 315 } |
224 | 316 |
| 317 // Set our Chrome specific data |
| 318 userfeedback::ChromeData chrome_data; |
| 319 #if defined(OS_CHROMEOS) |
| 320 chrome_data.set_chrome_platform( |
| 321 userfeedback::ChromeData_ChromePlatform_CHROME_OS); |
| 322 userfeedback::ChromeOsData chrome_os_data; |
| 323 chrome_os_data.set_category( |
| 324 (userfeedback::ChromeOsData_ChromeOsCategory) problem_type); |
| 325 *(chrome_data.mutable_chrome_os_data()) = chrome_os_data; |
| 326 #else |
| 327 chrome_data.set_chrome_platform( |
| 328 userfeedback::ChromeData_ChromePlatform_CHROME_BROWSER); |
| 329 userfeedback::ChromeBrowserData chrome_browser_data; |
| 330 chrome_browser_data.set_category( |
| 331 (userfeedback::ChromeBrowserData_ChromeBrowserCategory) problem_type); |
| 332 *(chrome_data.mutable_chrome_browser_data()) = chrome_browser_data; |
| 333 #endif |
| 334 |
| 335 *(feedback_data.mutable_chrome_data()) = chrome_data; |
| 336 |
225 // We have the body of our POST, so send it off to the server. | 337 // We have the body of our POST, so send it off to the server. |
226 URLFetcher* fetcher = new URLFetcher(post_url, URLFetcher::POST, | 338 URLFetcher* fetcher = new URLFetcher(post_url, URLFetcher::POST, |
227 new BugReportUtil::PostCleanup); | 339 #if defined(OS_CHROMEOS) |
| 340 new BugReportUtil::PostCleanup(profile)); |
| 341 #else |
| 342 new BugReportUtil::PostCleanup()); |
| 343 #endif |
228 fetcher->set_request_context(profile->GetRequestContext()); | 344 fetcher->set_request_context(profile->GetRequestContext()); |
229 | 345 |
230 std::string post_body; | 346 std::string post_body; |
231 feedback_data.SerializeToString(&post_body); | 347 feedback_data.SerializeToString(&post_body); |
232 fetcher->set_upload_data(std::string(kProtBufMimeType), post_body); | 348 fetcher->set_upload_data(std::string(kProtBufMimeType), post_body); |
233 fetcher->Start(); | 349 fetcher->Start(); |
234 } | 350 } |
235 | 351 |
236 // static | 352 // static |
237 void BugReportUtil::ReportPhishing(TabContents* currentTab, | 353 void BugReportUtil::ReportPhishing(TabContents* currentTab, |
238 const std::string& phishing_url) { | 354 const std::string& phishing_url) { |
239 currentTab->controller().LoadURL( | 355 currentTab->controller().LoadURL( |
240 safe_browsing_util::GeneratePhishingReportUrl( | 356 safe_browsing_util::GeneratePhishingReportUrl( |
241 kReportPhishingUrl, phishing_url), | 357 kReportPhishingUrl, phishing_url), |
242 GURL(), | 358 GURL(), |
243 PageTransition::LINK); | 359 PageTransition::LINK); |
244 } | 360 } |
OLD | NEW |