OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/dom_ui/bug_report_ui.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" |
| 9 #include "base/callback.h" |
| 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" |
| 14 #include "base/singleton.h" |
| 15 #include "base/string_piece.h" |
| 16 #include "base/string_util.h" |
| 17 #include "base/string_number_conversions.h" |
| 18 #include "base/thread.h" |
| 19 #include "base/time.h" |
| 20 #include "base/values.h" |
| 21 #include "base/weak_ptr.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 23 #include "chrome/browser/browser.h" |
| 24 #include "chrome/browser/browser_list.h" |
| 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/browser_window.h" |
| 27 #include "chrome/browser/bug_report_util.h" |
| 28 #include "chrome/browser/chrome_thread.h" |
| 29 #include "chrome/browser/dom_ui/dom_ui_screenshot_source.h" |
| 30 #include "chrome/browser/download/download_manager.h" |
| 31 #include "chrome/browser/download/download_util.h" |
| 32 #include "chrome/browser/history/history_types.h" |
| 33 #include "chrome/browser/metrics/user_metrics.h" |
| 34 #include "chrome/browser/profile.h" |
| 35 #include "chrome/browser/tab_contents/tab_contents.h" |
| 36 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
| 37 #include "chrome/common/chrome_paths.h" |
| 38 #include "chrome/common/jstemplate_builder.h" |
| 39 #include "chrome/common/time_format.h" |
| 40 #include "chrome/common/url_constants.h" |
| 41 #include "chrome/common/net/url_fetcher.h" |
| 42 #include "gfx/codec/png_codec.h" |
| 43 #include "net/base/escape.h" |
| 44 #include "views/window/window.h" |
| 45 |
| 46 #include "grit/browser_resources.h" |
| 47 #include "grit/chromium_strings.h" |
| 48 #include "grit/generated_resources.h" |
| 49 #include "grit/locale_settings.h" |
| 50 |
| 51 #if defined(OS_LINUX) |
| 52 #include "app/x11_util.h" |
| 53 #elif defined(OS_MACOSX) |
| 54 #include "base/mac_util.h" |
| 55 #else |
| 56 #include "app/win_util.h" |
| 57 #endif |
| 58 |
| 59 #if defined(OS_CHROMEOS) |
| 60 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 61 #include "chrome/browser/chromeos/cros/syslogs_library.h" |
| 62 #include "chrome/browser/chromeos/login/user_manager.h" |
| 63 #endif |
| 64 |
| 65 static const char kScreenshotBaseUrl[] = "chrome://screenshots/"; |
| 66 static const char kCurrentScreenshotUrl[] = "chrome://screenshots/current"; |
| 67 #if defined(OS_CHROMEOS) |
| 68 static const char kSavedScreenshotsUrl[] = "chrome://screenshots/saved/"; |
| 69 |
| 70 static const char kScreenshotPattern[] = "*.png"; |
| 71 static const char kScreenshotsRelativePath[] = "/Screenshots"; |
| 72 #endif |
| 73 |
| 74 namespace { |
| 75 #if defined(OS_CHROMEOS) |
| 76 |
| 77 void GetSavedScreenshots(std::vector<std::string>* saved_screenshots, |
| 78 base::WaitableEvent* done) { |
| 79 saved_screenshots->clear(); |
| 80 |
| 81 FilePath fileshelf_path; |
| 82 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, |
| 83 &fileshelf_path)) { |
| 84 done->Signal(); |
| 85 return; |
| 86 } |
| 87 |
| 88 // TODO(rkc): Change this to use FilePath.Append() once the cros |
| 89 // issue with it is fixed |
| 90 FilePath screenshots_path(fileshelf_path.value() + |
| 91 std::string(kScreenshotsRelativePath)); |
| 92 file_util::FileEnumerator screenshots(screenshots_path, false, |
| 93 file_util::FileEnumerator::FILES, |
| 94 std::string(kScreenshotPattern)); |
| 95 FilePath screenshot = screenshots.Next(); |
| 96 while (!screenshot.empty()) { |
| 97 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + |
| 98 screenshot.BaseName().value()); |
| 99 screenshot = screenshots.Next(); |
| 100 } |
| 101 done->Signal(); |
| 102 } |
| 103 |
| 104 // This fuction posts a task to the file thread to create/list all the current |
| 105 // and saved screenshots. |
| 106 void GetScreenshotUrls(std::vector<std::string>* saved_screenshots) { |
| 107 base::WaitableEvent done(true, false); |
| 108 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, |
| 109 NewRunnableFunction(&GetSavedScreenshots, |
| 110 saved_screenshots, &done)); |
| 111 done.Wait(); |
| 112 } |
| 113 |
| 114 std::string GetUserEmail() { |
| 115 chromeos::UserManager* manager = chromeos::UserManager::Get(); |
| 116 if (!manager) |
| 117 return std::string(); |
| 118 else |
| 119 return manager->logged_in_user().email(); |
| 120 } |
| 121 |
| 122 chromeos::LogDictionaryType* GetSystemInformation() { |
| 123 chromeos::LogDictionaryType* sys_info = NULL; |
| 124 chromeos::SyslogsLibrary* syslogs_lib = |
| 125 chromeos::CrosLibrary::Get()->GetSyslogsLibrary(); |
| 126 |
| 127 if (syslogs_lib) |
| 128 sys_info = syslogs_lib->GetSyslogs(NULL); |
| 129 |
| 130 return sys_info; |
| 131 } |
| 132 #endif |
| 133 |
| 134 |
| 135 } // namespace |
| 136 |
| 137 |
| 138 namespace browser { |
| 139 |
| 140 // TODO(rkc): Eventually find a better way to do this |
| 141 std::vector<unsigned char>* last_screenshot_png = 0; |
| 142 gfx::Rect screen_size; |
| 143 |
| 144 void RefreshLastScreenshot(views::Window* parent) { |
| 145 // Grab an exact snapshot of the window that the user is seeing (i.e. as |
| 146 // rendered--do not re-render, and include windowed plugins). |
| 147 if (last_screenshot_png) |
| 148 last_screenshot_png->clear(); |
| 149 else |
| 150 last_screenshot_png = new std::vector<unsigned char>; |
| 151 |
| 152 #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
| 153 screen_size = parent->GetBounds(); |
| 154 x11_util::GrabWindowSnapshot(parent->GetNativeWindow(), last_screenshot_png); |
| 155 #elif defined(OS_MACOSX) |
| 156 int width = 0, height = 0; |
| 157 mac_util::GrabWindowSnapshot(parent->GetNativeWindow(), last_screenshot_png, |
| 158 &width, &height); |
| 159 #else |
| 160 screen_size = parent->GetBounds(); |
| 161 win_util::GrabWindowSnapshot(parent->GetNativeWindow(), last_screenshot_png); |
| 162 #endif |
| 163 } |
| 164 |
| 165 // Global "display this dialog" function declared in browser_dialogs.h. |
| 166 void ShowHtmlBugReportView(views::Window* parent, Browser* browser) { |
| 167 std::string bug_report_url = std::string(chrome::kChromeUIBugReportURL) + |
| 168 base::IntToString(browser->selected_index()); |
| 169 |
| 170 RefreshLastScreenshot(parent); |
| 171 browser->ShowSingletonTab(GURL(bug_report_url)); |
| 172 } |
| 173 |
| 174 } // namespace browser |
| 175 |
| 176 |
| 177 class BugReportUIHTMLSource : public ChromeURLDataManager::DataSource { |
| 178 public: |
| 179 explicit BugReportUIHTMLSource(base::StringPiece html); |
| 180 |
| 181 // Called when the network layer has requested a resource underneath |
| 182 // the path we registered. |
| 183 virtual void StartDataRequest(const std::string& path, |
| 184 bool is_off_the_record, |
| 185 int request_id); |
| 186 virtual std::string GetMimeType(const std::string&) const { |
| 187 return "text/html"; |
| 188 } |
| 189 |
| 190 private: |
| 191 base::StringPiece bug_report_html_; |
| 192 ~BugReportUIHTMLSource() {} |
| 193 |
| 194 DISALLOW_COPY_AND_ASSIGN(BugReportUIHTMLSource); |
| 195 }; |
| 196 |
| 197 class TaskProxy; |
| 198 |
| 199 // The handler for Javascript messages related to the "bug report" dialog |
| 200 class BugReportHandler : public DOMMessageHandler, |
| 201 public base::SupportsWeakPtr<BugReportHandler> { |
| 202 public: |
| 203 explicit BugReportHandler(TabContents* tab); |
| 204 virtual ~BugReportHandler(); |
| 205 |
| 206 // Init work after Attach. |
| 207 base::StringPiece Init(); |
| 208 |
| 209 // DOMMessageHandler implementation. |
| 210 virtual DOMMessageHandler* Attach(DOMUI* dom_ui); |
| 211 virtual void RegisterMessages(); |
| 212 void OnURLFetchComplete(const URLFetcher* source, |
| 213 const GURL& url, |
| 214 const URLRequestStatus& status, |
| 215 int response_code, |
| 216 const ResponseCookies& cookies, |
| 217 const std::string& data); |
| 218 |
| 219 void HandleGetDialogDefaults(const ListValue*); |
| 220 void HandleRefreshScreenshots(const ListValue*); |
| 221 void HandleSendReport(const ListValue* list_value); |
| 222 void HandleCancel(const ListValue*); |
| 223 |
| 224 void SetupScreenshotsSource(); |
| 225 void ClobberScreenshotsSource(); |
| 226 |
| 227 private: |
| 228 Browser* browser_; |
| 229 std::string page_url_; |
| 230 Profile* profile_; |
| 231 TabContents* tab_; |
| 232 TabContents* target_tab_; |
| 233 DOMUIScreenshotSource* screenshot_source_; |
| 234 #if defined (OS_CHROMEOS) |
| 235 chromeos::LogDictionaryType* sys_info_; |
| 236 #endif |
| 237 |
| 238 DISALLOW_COPY_AND_ASSIGN(BugReportHandler); |
| 239 }; |
| 240 |
| 241 //////////////////////////////////////////////////////////////////////////////// |
| 242 // |
| 243 // BugReportHTMLSource |
| 244 // |
| 245 //////////////////////////////////////////////////////////////////////////////// |
| 246 |
| 247 BugReportUIHTMLSource::BugReportUIHTMLSource(base::StringPiece html) |
| 248 : DataSource(chrome::kChromeUIBugReportHost, MessageLoop::current()) { |
| 249 bug_report_html_ = html; |
| 250 } |
| 251 |
| 252 void BugReportUIHTMLSource::StartDataRequest(const std::string& path, |
| 253 bool is_off_the_record, |
| 254 int request_id) { |
| 255 DictionaryValue localized_strings; |
| 256 localized_strings.SetString(std::string("title"), |
| 257 l10n_util::GetStringUTF8(IDS_BUGREPORT_TITLE)); |
| 258 localized_strings.SetString(std::string("issue-with"), |
| 259 l10n_util::GetStringUTF8(IDS_BUGREPORT_ISSUE_WITH)); |
| 260 localized_strings.SetString(std::string("page-url"), |
| 261 l10n_util::GetStringUTF8(IDS_BUGREPORT_REPORT_URL_LABEL)); |
| 262 localized_strings.SetString(std::string("description"), |
| 263 l10n_util::GetStringUTF8(IDS_BUGREPORT_DESCRIPTION_LABEL)); |
| 264 localized_strings.SetString(std::string("screenshot"), |
| 265 l10n_util::GetStringUTF8(IDS_BUGREPORT_SCREENSHOT_LABEL)); |
| 266 #if defined(OS_CHROMEOS) |
| 267 localized_strings.SetString(std::string("user-email"), |
| 268 l10n_util::GetStringUTF8(IDS_BUGREPORT_USER_EMAIL_LABEL)); |
| 269 localized_strings.SetString(std::string("currentscreenshots"), |
| 270 l10n_util::GetStringUTF8(IDS_BUGREPORT_CURRENT_SCREENSHOTS)); |
| 271 localized_strings.SetString(std::string("savedscreenshots"), |
| 272 l10n_util::GetStringUTF8(IDS_BUGREPORT_SAVED_SCREENSHOTS)); |
| 273 localized_strings.SetString(std::string("sysinfo"), |
| 274 l10n_util::GetStringUTF8( |
| 275 IDS_BUGREPORT_INCLUDE_SYSTEM_INFORMATION_CHKBOX)); |
| 276 #else |
| 277 localized_strings.SetString(std::string("currentscreenshots"), |
| 278 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NEW_SCREEN_IMAGE)); |
| 279 #endif |
| 280 localized_strings.SetString(std::string("noscreenshot"), |
| 281 l10n_util::GetStringUTF8(IDS_BUGREPORT_INCLUDE_NO_SCREENSHOT)); |
| 282 |
| 283 localized_strings.SetString(std::string("send-report"), |
| 284 l10n_util::GetStringUTF8(IDS_BUGREPORT_SEND_REPORT)); |
| 285 localized_strings.SetString(std::string("cancel"), |
| 286 l10n_util::GetStringUTF8(IDS_CANCEL)); |
| 287 |
| 288 // Option strings for the "issue with" drop-down. |
| 289 localized_strings.SetString(std::string("issue-choose"), |
| 290 l10n_util::GetStringUTF8(IDS_BUGREPORT_CHOOSE_ISSUE)); |
| 291 |
| 292 localized_strings.SetString(std::string("no-issue-selected"), |
| 293 l10n_util::GetStringUTF8(IDS_BUGREPORT_NO_ISSUE_SELECTED)); |
| 294 |
| 295 |
| 296 // TODO(rkc): Find some way to ensure this order of dropdowns is in sync |
| 297 // with the order in the userfeedback ChromeData proto buffer |
| 298 #if defined(OS_CHROMEOS) |
| 299 // Dropdown for ChromeOS: |
| 300 // |
| 301 // Connectivity |
| 302 // Sync |
| 303 // Crash |
| 304 // Page Formatting |
| 305 // Extensions or Apps |
| 306 // Standby or Resume |
| 307 // Phishing Page |
| 308 // General Feedback/Other |
| 309 |
| 310 localized_strings.SetString(std::string("issue-connectivity"), |
| 311 l10n_util::GetStringUTF8(IDS_BUGREPORT_CONNECTIVITY)); |
| 312 localized_strings.SetString(std::string("issue-sync"), |
| 313 l10n_util::GetStringUTF8(IDS_BUGREPORT_SYNC)); |
| 314 localized_strings.SetString(std::string("issue-crashes"), |
| 315 l10n_util::GetStringUTF8(IDS_BUGREPORT_CRASHES)); |
| 316 localized_strings.SetString(std::string("issue-page-formatting"), |
| 317 l10n_util::GetStringUTF8(IDS_BUGREPORT_PAGE_FORMATTING)); |
| 318 localized_strings.SetString(std::string("issue-extensions"), |
| 319 l10n_util::GetStringUTF8(IDS_BUGREPORT_EXTENSIONS)); |
| 320 localized_strings.SetString(std::string("issue-standby"), |
| 321 l10n_util::GetStringUTF8(IDS_BUGREPORT_STANDBY_RESUME)); |
| 322 localized_strings.SetString(std::string("issue-phishing"), |
| 323 l10n_util::GetStringUTF8(IDS_BUGREPORT_PHISHING_PAGE)); |
| 324 localized_strings.SetString(std::string("issue-other"), |
| 325 l10n_util::GetStringUTF8(IDS_BUGREPORT_GENERAL)); |
| 326 #else |
| 327 // Dropdown for Chrome: |
| 328 // |
| 329 // Page formatting or layout |
| 330 // Pages not loading |
| 331 // Plug-ins (e.g. Adobe Flash Player, Quicktime, etc) |
| 332 // Tabs or windows |
| 333 // Synced preferences |
| 334 // Crashes |
| 335 // Extensions or apps |
| 336 // Phishing |
| 337 // Other |
| 338 |
| 339 localized_strings.SetString(std::string("issue-page-formatting"), |
| 340 l10n_util::GetStringUTF8(IDS_BUGREPORT_PAGE_FORMATTING)); |
| 341 localized_strings.SetString(std::string("issue-page-load"), |
| 342 l10n_util::GetStringUTF8(IDS_BUGREPORT_PAGE_LOAD)); |
| 343 localized_strings.SetString(std::string("issue-plugins"), |
| 344 l10n_util::GetStringUTF8(IDS_BUGREPORT_PLUGINS)); |
| 345 localized_strings.SetString(std::string("issue-tabs"), |
| 346 l10n_util::GetStringUTF8(IDS_BUGREPORT_TABS)); |
| 347 localized_strings.SetString(std::string("issue-sync"), |
| 348 l10n_util::GetStringUTF8(IDS_BUGREPORT_SYNC)); |
| 349 localized_strings.SetString(std::string("issue-crashes"), |
| 350 l10n_util::GetStringUTF8(IDS_BUGREPORT_CRASHES)); |
| 351 localized_strings.SetString(std::string("issue-extensions"), |
| 352 l10n_util::GetStringUTF8(IDS_BUGREPORT_EXTENSIONS)); |
| 353 localized_strings.SetString(std::string("issue-phishing"), |
| 354 l10n_util::GetStringUTF8(IDS_BUGREPORT_PHISHING_PAGE)); |
| 355 localized_strings.SetString(std::string("issue-other"), |
| 356 l10n_util::GetStringUTF8(IDS_BUGREPORT_OTHER)); |
| 357 #endif |
| 358 |
| 359 SetFontAndTextDirection(&localized_strings); |
| 360 |
| 361 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( |
| 362 bug_report_html_, &localized_strings); |
| 363 |
| 364 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); |
| 365 html_bytes->data.resize(full_html.size()); |
| 366 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); |
| 367 |
| 368 SendResponse(request_id, html_bytes); |
| 369 } |
| 370 |
| 371 //////////////////////////////////////////////////////////////////////////////// |
| 372 // |
| 373 // BugErportHandler |
| 374 // |
| 375 //////////////////////////////////////////////////////////////////////////////// |
| 376 BugReportHandler::BugReportHandler(TabContents* tab) |
| 377 : profile_(NULL), tab_(tab), screenshot_source_(NULL) { |
| 378 browser_ = BrowserList::GetLastActive(); |
| 379 } |
| 380 |
| 381 BugReportHandler::~BugReportHandler() { |
| 382 } |
| 383 |
| 384 void BugReportHandler::ClobberScreenshotsSource() { |
| 385 // Re-create our screenshots data source (this clobbers the last source) |
| 386 // setting the screenshot to NULL, effectively disabling the source |
| 387 // TODO(rkc): Once there is a method to 'remove' a source, change this code |
| 388 ChromeThread::PostTask( |
| 389 ChromeThread::IO, FROM_HERE, |
| 390 NewRunnableMethod( |
| 391 Singleton<ChromeURLDataManager>::get(), |
| 392 &ChromeURLDataManager::AddDataSource, |
| 393 make_scoped_refptr(new DOMUIScreenshotSource(NULL)))); |
| 394 |
| 395 // clobber last screenshot |
| 396 if (browser::last_screenshot_png) |
| 397 browser::last_screenshot_png->clear(); |
| 398 } |
| 399 |
| 400 void BugReportHandler::SetupScreenshotsSource() { |
| 401 // If we don't already have a screenshot source object created, create one. |
| 402 if (!screenshot_source_) |
| 403 screenshot_source_ = new DOMUIScreenshotSource( |
| 404 browser::last_screenshot_png); |
| 405 |
| 406 // Add the source to the data manager. |
| 407 ChromeThread::PostTask( |
| 408 ChromeThread::IO, FROM_HERE, |
| 409 NewRunnableMethod( |
| 410 Singleton<ChromeURLDataManager>::get(), |
| 411 &ChromeURLDataManager::AddDataSource, |
| 412 make_scoped_refptr(screenshot_source_))); |
| 413 } |
| 414 |
| 415 DOMMessageHandler* BugReportHandler::Attach(DOMUI* dom_ui) { |
| 416 SetupScreenshotsSource(); |
| 417 return DOMMessageHandler::Attach(dom_ui); |
| 418 } |
| 419 |
| 420 base::StringPiece BugReportHandler::Init() { |
| 421 std::string page_url; |
| 422 if (tab_->controller().GetActiveEntry()) { |
| 423 page_url = tab_->controller().GetActiveEntry()->url().spec(); |
| 424 } |
| 425 |
| 426 std::string params = page_url.substr(strlen(chrome::kChromeUIBugReportURL)); |
| 427 |
| 428 int index = 0; |
| 429 if (!base::StringToInt(params, &index)) { |
| 430 ClobberScreenshotsSource(); |
| 431 return base::StringPiece( |
| 432 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 433 IDR_BUGREPORT_HTML_INVALID)); |
| 434 } |
| 435 |
| 436 // Sanity checks. |
| 437 if (((index == 0) && (params != "0")) || (index >= browser_->tab_count())) { |
| 438 ClobberScreenshotsSource(); |
| 439 return base::StringPiece( |
| 440 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 441 IDR_BUGREPORT_HTML_INVALID)); |
| 442 } |
| 443 |
| 444 if (browser_) |
| 445 target_tab_ = browser_->GetTabContentsAt(index); |
| 446 else |
| 447 LOG(FATAL) << "Failed to get last active browser."; |
| 448 |
| 449 return base::StringPiece( |
| 450 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 451 #if defined(OS_CHROMEOS) |
| 452 IDR_BUGREPORT_HTML_CHROMEOS)); |
| 453 #else |
| 454 IDR_BUGREPORT_HTML)); |
| 455 #endif |
| 456 } |
| 457 |
| 458 void BugReportHandler::RegisterMessages() { |
| 459 dom_ui_->RegisterMessageCallback("getDialogDefaults", |
| 460 NewCallback(this, &BugReportHandler::HandleGetDialogDefaults)); |
| 461 dom_ui_->RegisterMessageCallback("refreshScreenshots", |
| 462 NewCallback(this, &BugReportHandler::HandleRefreshScreenshots)); |
| 463 dom_ui_->RegisterMessageCallback("sendReport", |
| 464 NewCallback(this, &BugReportHandler::HandleSendReport)); |
| 465 dom_ui_->RegisterMessageCallback("cancel", |
| 466 NewCallback(this, &BugReportHandler::HandleCancel)); |
| 467 } |
| 468 |
| 469 void BugReportHandler::HandleGetDialogDefaults(const ListValue*) { |
| 470 // send back values which the dialog js needs initially |
| 471 ListValue dialog_defaults; |
| 472 |
| 473 // 0: current url |
| 474 if (target_tab_) |
| 475 dialog_defaults.Append(new StringValue( |
| 476 target_tab_->controller().GetActiveEntry()->url().spec())); |
| 477 else |
| 478 dialog_defaults.Append(new StringValue("")); |
| 479 |
| 480 #if defined(OS_CHROMEOS) |
| 481 // 1: user e-mail |
| 482 sys_info_ = GetSystemInformation(); |
| 483 dialog_defaults.Append(new StringValue(chrome::kAboutSystemURL)); |
| 484 |
| 485 // 2: user e-mail |
| 486 dialog_defaults.Append(new StringValue(GetUserEmail())); |
| 487 #endif |
| 488 |
| 489 dom_ui_->CallJavascriptFunction(L"setupDialogDefaults", dialog_defaults); |
| 490 } |
| 491 |
| 492 void BugReportHandler::HandleRefreshScreenshots(const ListValue*) { |
| 493 ListValue screenshots; |
| 494 screenshots.Append(new StringValue(std::string(kCurrentScreenshotUrl))); |
| 495 |
| 496 |
| 497 #if defined(OS_CHROMEOS) |
| 498 std::vector<std::string> saved_screenshots; |
| 499 GetScreenshotUrls(&saved_screenshots); |
| 500 |
| 501 ListValue* saved_screenshot_list = new ListValue(); |
| 502 for (size_t i = 0; i < saved_screenshots.size(); ++i) |
| 503 saved_screenshot_list->Append(new StringValue(saved_screenshots[i])); |
| 504 screenshots.Append(saved_screenshot_list); |
| 505 #endif |
| 506 dom_ui_->CallJavascriptFunction(L"setupScreenshots", screenshots); |
| 507 } |
| 508 |
| 509 void BugReportHandler::HandleSendReport(const ListValue* list_value) { |
| 510 ListValue::const_iterator i = list_value->begin(); |
| 511 if (i == list_value->end()) { |
| 512 LOG(ERROR) << "Incorrect data passed to sendReport."; |
| 513 return; |
| 514 } |
| 515 |
| 516 // #0 - Problem type. |
| 517 std::string problem_type_str; |
| 518 int problem_type = 0; |
| 519 (*i)->GetAsString(&problem_type_str); |
| 520 if (!base::StringToInt(problem_type_str, &problem_type)) { |
| 521 LOG(ERROR) << "Incorrect data passed to sendReport."; |
| 522 return; |
| 523 } |
| 524 if (++i == list_value->end()) { |
| 525 LOG(ERROR) << "Incorrect data passed to sendReport."; |
| 526 return; |
| 527 } |
| 528 |
| 529 // #1 - Page url. |
| 530 std::string page_url; |
| 531 (*i)->GetAsString(&page_url); |
| 532 if (++i == list_value->end()) { |
| 533 LOG(ERROR) << "Incorrect data passed to sendReport."; |
| 534 return; |
| 535 } |
| 536 |
| 537 // #2 - Description. |
| 538 std::string description; |
| 539 (*i)->GetAsString(&description); |
| 540 if (++i == list_value->end()) { |
| 541 LOG(ERROR) << "Incorrect data passed to sendReport."; |
| 542 return; |
| 543 } |
| 544 |
| 545 // #3 - Screenshot to send. |
| 546 std::string screenshot_path; |
| 547 (*i)->GetAsString(&screenshot_path); |
| 548 screenshot_path.erase(0, strlen(kScreenshotBaseUrl)); |
| 549 #if defined(OS_CHROMEOS) |
| 550 if (++i == list_value->end()) { |
| 551 LOG(ERROR) << "Incorrect data passed to sendReport."; |
| 552 return; |
| 553 } |
| 554 |
| 555 // #4 - User e-mail |
| 556 std::string user_email; |
| 557 (*i)->GetAsString(&user_email); |
| 558 if (++i == list_value->end()) { |
| 559 LOG(ERROR) << "Incorrect data passed to sendReport."; |
| 560 return; |
| 561 } |
| 562 |
| 563 // #5 - System info checkbox. |
| 564 std::string sys_info_checkbox; |
| 565 (*i)->GetAsString(&sys_info_checkbox); |
| 566 #endif |
| 567 |
| 568 // Get the image to send in the report. |
| 569 char* image_data = NULL; |
| 570 int image_data_size = 0; |
| 571 // Make sure this object remains in scope till SendReport returns. |
| 572 std::vector<unsigned char> image; |
| 573 if (screenshot_path.size() > 0) { |
| 574 image = screenshot_source_->GetScreenshot(screenshot_path); |
| 575 image_data = reinterpret_cast<char*>(&(image.front())); |
| 576 image_data_size = image.size(); |
| 577 } |
| 578 |
| 579 BugReportUtil::SendReport(browser_->profile(), |
| 580 UTF16ToUTF8(target_tab_->GetTitle()), |
| 581 problem_type, |
| 582 page_url, |
| 583 description, |
| 584 image_data, |
| 585 image_data_size, browser::screen_size.width(), |
| 586 #if defined(OS_CHROMEOS) |
| 587 browser::screen_size.height(), |
| 588 user_email, |
| 589 ((sys_info_checkbox == "true") ? |
| 590 GetSystemInformation() : NULL)); |
| 591 #else |
| 592 browser::screen_size.height()); |
| 593 #endif |
| 594 |
| 595 browser_->CloseTabContents(tab_); |
| 596 ClobberScreenshotsSource(); |
| 597 } |
| 598 |
| 599 void BugReportHandler::HandleCancel(const ListValue*) { |
| 600 browser_->CloseTabContents(tab_); |
| 601 ClobberScreenshotsSource(); |
| 602 } |
| 603 |
| 604 |
| 605 |
| 606 //////////////////////////////////////////////////////////////////////////////// |
| 607 // |
| 608 // BugReportUI |
| 609 // |
| 610 //////////////////////////////////////////////////////////////////////////////// |
| 611 BugReportUI::BugReportUI(TabContents* tab) : HtmlDialogUI(tab) { |
| 612 BugReportHandler* handler = new BugReportHandler(tab); |
| 613 AddMessageHandler((handler)->Attach(this)); |
| 614 |
| 615 // The handler's init will specify which html |
| 616 // resource we'll display to the user |
| 617 BugReportUIHTMLSource* html_source = |
| 618 new BugReportUIHTMLSource(handler->Init()); |
| 619 // Set up the chrome://bugreport/ source. |
| 620 ChromeThread::PostTask( |
| 621 ChromeThread::IO, FROM_HERE, |
| 622 NewRunnableMethod( |
| 623 Singleton<ChromeURLDataManager>::get(), |
| 624 &ChromeURLDataManager::AddDataSource, |
| 625 make_scoped_refptr(html_source))); |
| 626 } |
OLD | NEW |