OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/webui/bug_report_ui.h" | 5 #include "chrome/browser/ui/webui/bug_report_ui.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 120 } |
121 | 121 |
122 return -1; | 122 return -1; |
123 } | 123 } |
124 | 124 |
125 } // namespace | 125 } // namespace |
126 | 126 |
127 | 127 |
128 namespace browser { | 128 namespace browser { |
129 | 129 |
130 // TODO(rkc): Eventually find a better way to do this | |
131 std::vector<unsigned char>* last_screenshot_png = 0; | |
132 gfx::Rect screen_size; | |
stevenjb
2011/08/03 01:55:20
Eliminated global variables (including a non basic
| |
133 | |
134 void RefreshLastScreenshot(Browser* browser) { | |
135 if (last_screenshot_png) | |
136 last_screenshot_png->clear(); | |
137 else | |
138 last_screenshot_png = new std::vector<unsigned char>; | |
139 | |
140 gfx::NativeWindow native_window = browser->window()->GetNativeHandle(); | |
141 screen_size = browser::GrabWindowSnapshot(native_window, last_screenshot_png); | |
142 } | |
143 | |
144 void ShowHtmlBugReportView(Browser* browser, | 130 void ShowHtmlBugReportView(Browser* browser, |
145 const std::string& description_template, | 131 const std::string& description_template, |
146 size_t issue_type) { | 132 size_t issue_type) { |
147 // First check if we're already open (we cannot depend on ShowSingletonTab | 133 // First check if we're already open (we cannot depend on ShowSingletonTab |
148 // for this functionality since we need to make *sure* we never get | 134 // for this functionality since we need to make *sure* we never get |
149 // instantiated again while we are open - with singleton tabs, that can | 135 // instantiated again while we are open - with singleton tabs, that can |
150 // happen) | 136 // happen) |
151 int feedback_tab_index = GetIndexOfFeedbackTab(browser); | 137 int feedback_tab_index = GetIndexOfFeedbackTab(browser); |
152 if (feedback_tab_index >= 0) { | 138 if (feedback_tab_index >= 0) { |
153 // Do not refresh screenshot, do not create a new tab | 139 // Do not refresh screenshot, do not create a new tab |
154 browser->ActivateTabAt(feedback_tab_index, true); | 140 browser->ActivateTabAt(feedback_tab_index, true); |
155 return; | 141 return; |
156 } | 142 } |
157 | 143 |
158 RefreshLastScreenshot(browser); | 144 std::vector<unsigned char>* last_screenshot_png = |
145 BugReportUtil::GetScreenshotPng(); | |
146 last_screenshot_png->clear(); | |
147 | |
148 gfx::NativeWindow native_window = browser->window()->GetNativeHandle(); | |
149 BugReportUtil::SetScreenshotSize( | |
150 browser::GrabWindowSnapshot(native_window, last_screenshot_png)); | |
151 | |
159 std::string bug_report_url = std::string(chrome::kChromeUIBugReportURL) + | 152 std::string bug_report_url = std::string(chrome::kChromeUIBugReportURL) + |
160 "#" + base::IntToString(browser->active_index()) + | 153 "#" + base::IntToString(browser->active_index()) + |
161 "?description=" + EscapeUrlEncodedData(description_template, false) + | 154 "?description=" + EscapeUrlEncodedData(description_template, false) + |
162 "&issueType=" + base::IntToString(issue_type); | 155 "&issueType=" + base::IntToString(issue_type); |
163 browser->ShowSingletonTab(GURL(bug_report_url)); | 156 browser->ShowSingletonTab(GURL(bug_report_url)); |
164 } | 157 } |
165 | 158 |
166 } // namespace browser | 159 } // namespace browser |
167 | 160 |
168 | 161 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 | 372 |
380 std::string full_html = jstemplate_builder::GetI18nTemplateHtml( | 373 std::string full_html = jstemplate_builder::GetI18nTemplateHtml( |
381 bug_report_html_, &localized_strings); | 374 bug_report_html_, &localized_strings); |
382 | 375 |
383 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); | 376 SendResponse(request_id, base::RefCountedString::TakeString(&full_html)); |
384 } | 377 } |
385 | 378 |
386 | 379 |
387 //////////////////////////////////////////////////////////////////////////////// | 380 //////////////////////////////////////////////////////////////////////////////// |
388 // | 381 // |
389 // BugReportData | |
390 // | |
391 //////////////////////////////////////////////////////////////////////////////// | |
392 void BugReportData::SendReport() { | |
stevenjb
2011/08/03 01:55:20
BugReportData member function moved to its proper
| |
393 #if defined(OS_CHROMEOS) | |
394 // In case we already got the syslogs and sent the report, leave | |
395 if (sent_report_) return; | |
396 // Set send_report_ so that no one else processes SendReport | |
397 sent_report_ = true; | |
398 #endif | |
399 | |
400 int image_data_size = image_.size(); | |
401 char* image_data = image_data_size ? | |
402 reinterpret_cast<char*>(&(image_.front())) : NULL; | |
403 BugReportUtil::SendReport(profile_ | |
404 , problem_type_ | |
405 , page_url_ | |
406 , description_ | |
407 , image_data | |
408 , image_data_size | |
409 , browser::screen_size.width() | |
410 , browser::screen_size.height() | |
411 #if defined(OS_CHROMEOS) | |
412 , user_email_ | |
413 , zip_content_ ? zip_content_->c_str() : NULL | |
414 , zip_content_ ? zip_content_->length() : 0 | |
415 , send_sys_info_ ? sys_info_ : NULL | |
416 #endif | |
417 ); | |
418 | |
419 #if defined(OS_CHROMEOS) | |
420 if (sys_info_) { | |
421 delete sys_info_; | |
422 sys_info_ = NULL; | |
423 } | |
424 if (zip_content_) { | |
425 delete zip_content_; | |
426 zip_content_ = NULL; | |
427 } | |
428 #endif | |
429 | |
430 // Once the report has been sent, this object has no purpose in life, delete | |
431 // ourselves. | |
432 delete this; | |
433 } | |
434 | |
435 | |
436 //////////////////////////////////////////////////////////////////////////////// | |
437 // | |
438 // BugReportHandler | 382 // BugReportHandler |
439 // | 383 // |
440 //////////////////////////////////////////////////////////////////////////////// | 384 //////////////////////////////////////////////////////////////////////////////// |
441 BugReportHandler::BugReportHandler(TabContents* tab) | 385 BugReportHandler::BugReportHandler(TabContents* tab) |
442 : tab_(tab), | 386 : tab_(tab), |
443 screenshot_source_(NULL), | 387 screenshot_source_(NULL), |
444 bug_report_(NULL) | 388 bug_report_(NULL) |
445 #if defined(OS_CHROMEOS) | 389 #if defined(OS_CHROMEOS) |
446 , syslogs_handle_(0) | 390 , syslogs_handle_(0) |
447 #endif | 391 #endif |
448 { | 392 { |
449 } | 393 } |
450 | 394 |
451 BugReportHandler::~BugReportHandler() { | 395 BugReportHandler::~BugReportHandler() { |
James Cook
2011/08/03 17:06:49
Should this call BugReportUtil::GetScreenshotPng()
stevenjb
2011/08/03 19:11:39
It should be getting called in ClobberScreenshotsS
| |
452 // Just in case we didn't send off bug_report_ to SendReport | 396 // Just in case we didn't send off bug_report_ to SendReport |
453 if (bug_report_) { | 397 if (bug_report_) { |
454 // If we're deleting the report object, cancel feedback collection first | 398 // If we're deleting the report object, cancel feedback collection first |
455 CancelFeedbackCollection(); | 399 CancelFeedbackCollection(); |
456 delete bug_report_; | 400 delete bug_report_; |
457 } | 401 } |
458 } | 402 } |
459 | 403 |
460 void BugReportHandler::ClobberScreenshotsSource() { | 404 void BugReportHandler::ClobberScreenshotsSource() { |
461 // Re-create our screenshots data source (this clobbers the last source) | 405 // Re-create our screenshots data source (this clobbers the last source) |
462 // setting the screenshot to NULL, effectively disabling the source | 406 // setting the screenshot to NULL, effectively disabling the source |
463 // TODO(rkc): Once there is a method to 'remove' a source, change this code | 407 // TODO(rkc): Once there is a method to 'remove' a source, change this code |
464 Profile* profile = Profile::FromBrowserContext(tab_->browser_context()); | 408 Profile* profile = Profile::FromBrowserContext(tab_->browser_context()); |
465 profile->GetChromeURLDataManager()->AddDataSource(new ScreenshotSource(NULL)); | 409 profile->GetChromeURLDataManager()->AddDataSource(new ScreenshotSource(NULL)); |
466 | 410 |
467 // clobber last screenshot | 411 // clobber last screenshot |
468 if (browser::last_screenshot_png) | 412 BugReportUtil::GetScreenshotPng()->clear(); |
469 browser::last_screenshot_png->clear(); | |
470 } | 413 } |
471 | 414 |
472 void BugReportHandler::SetupScreenshotsSource() { | 415 void BugReportHandler::SetupScreenshotsSource() { |
473 // If we don't already have a screenshot source object created, create one. | 416 // If we don't already have a screenshot source object created, create one. |
474 if (!screenshot_source_) | 417 if (!screenshot_source_) { |
475 screenshot_source_ = new ScreenshotSource(browser::last_screenshot_png); | 418 screenshot_source_ = |
476 | 419 new ScreenshotSource(BugReportUtil::GetScreenshotPng()); |
420 } | |
477 // Add the source to the data manager. | 421 // Add the source to the data manager. |
478 Profile* profile = Profile::FromBrowserContext(tab_->browser_context()); | 422 Profile* profile = Profile::FromBrowserContext(tab_->browser_context()); |
479 profile->GetChromeURLDataManager()->AddDataSource(screenshot_source_); | 423 profile->GetChromeURLDataManager()->AddDataSource(screenshot_source_); |
480 } | 424 } |
481 | 425 |
482 WebUIMessageHandler* BugReportHandler::Attach(WebUI* web_ui) { | 426 WebUIMessageHandler* BugReportHandler::Attach(WebUI* web_ui) { |
483 SetupScreenshotsSource(); | 427 SetupScreenshotsSource(); |
484 return WebUIMessageHandler::Attach(web_ui); | 428 return WebUIMessageHandler::Attach(web_ui); |
485 } | 429 } |
486 | 430 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 #endif | 483 #endif |
540 web_ui_->RegisterMessageCallback("sendReport", | 484 web_ui_->RegisterMessageCallback("sendReport", |
541 NewCallback(this, &BugReportHandler::HandleSendReport)); | 485 NewCallback(this, &BugReportHandler::HandleSendReport)); |
542 web_ui_->RegisterMessageCallback("cancel", | 486 web_ui_->RegisterMessageCallback("cancel", |
543 NewCallback(this, &BugReportHandler::HandleCancel)); | 487 NewCallback(this, &BugReportHandler::HandleCancel)); |
544 web_ui_->RegisterMessageCallback("openSystemTab", | 488 web_ui_->RegisterMessageCallback("openSystemTab", |
545 NewCallback(this, &BugReportHandler::HandleOpenSystemTab)); | 489 NewCallback(this, &BugReportHandler::HandleOpenSystemTab)); |
546 } | 490 } |
547 | 491 |
548 void BugReportHandler::HandleGetDialogDefaults(const ListValue*) { | 492 void BugReportHandler::HandleGetDialogDefaults(const ListValue*) { |
493 // Will delete itself when bug_report_->SendReport() is called. | |
549 bug_report_ = new BugReportData(); | 494 bug_report_ = new BugReportData(); |
550 | 495 |
551 // send back values which the dialog js needs initially | 496 // send back values which the dialog js needs initially |
552 ListValue dialog_defaults; | 497 ListValue dialog_defaults; |
553 | 498 |
554 // 0: current url | 499 // 0: current url |
555 if (target_tab_url_.length()) | 500 if (target_tab_url_.length()) |
556 dialog_defaults.Append(new StringValue(target_tab_url_)); | 501 dialog_defaults.Append(new StringValue(target_tab_url_)); |
557 else | 502 else |
558 dialog_defaults.Append(new StringValue("")); | 503 dialog_defaults.Append(new StringValue("")); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
749 AddMessageHandler((handler)->Attach(this)); | 694 AddMessageHandler((handler)->Attach(this)); |
750 | 695 |
751 // The handler's init will specify which html | 696 // The handler's init will specify which html |
752 // resource we'll display to the user | 697 // resource we'll display to the user |
753 BugReportUIHTMLSource* html_source = | 698 BugReportUIHTMLSource* html_source = |
754 new BugReportUIHTMLSource(handler->Init()); | 699 new BugReportUIHTMLSource(handler->Init()); |
755 // Set up the chrome://bugreport/ source. | 700 // Set up the chrome://bugreport/ source. |
756 Profile* profile = Profile::FromBrowserContext(tab->browser_context()); | 701 Profile* profile = Profile::FromBrowserContext(tab->browser_context()); |
757 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 702 profile->GetChromeURLDataManager()->AddDataSource(html_source); |
758 } | 703 } |
OLD | NEW |