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/dom_ui/bug_report_ui.h" | 5 #include "chrome/browser/dom_ui/bug_report_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/singleton.h" | 14 #include "base/singleton.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "base/weak_ptr.h" | 19 #include "base/weak_ptr.h" |
20 #include "chrome/browser/browser_thread.h" | 20 #include "chrome/browser/browser_thread.h" |
21 #include "chrome/browser/bug_report_data.h" | 21 #include "chrome/browser/bug_report_data.h" |
22 #include "chrome/browser/bug_report_util.h" | 22 #include "chrome/browser/bug_report_util.h" |
23 #include "chrome/browser/dom_ui/web_ui_screenshot_source.h" | 23 #include "chrome/browser/dom_ui/web_ui_screenshot_source.h" |
| 24 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/tab_contents/tab_contents.h" | 25 #include "chrome/browser/tab_contents/tab_contents.h" |
25 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
27 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
28 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | 29 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
29 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
30 #include "chrome/common/jstemplate_builder.h" | 31 #include "chrome/common/jstemplate_builder.h" |
31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
32 #include "grit/browser_resources.h" | 33 #include "grit/browser_resources.h" |
33 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 delete this; | 426 delete this; |
426 } | 427 } |
427 | 428 |
428 | 429 |
429 //////////////////////////////////////////////////////////////////////////////// | 430 //////////////////////////////////////////////////////////////////////////////// |
430 // | 431 // |
431 // BugReportHandler | 432 // BugReportHandler |
432 // | 433 // |
433 //////////////////////////////////////////////////////////////////////////////// | 434 //////////////////////////////////////////////////////////////////////////////// |
434 BugReportHandler::BugReportHandler(TabContents* tab) | 435 BugReportHandler::BugReportHandler(TabContents* tab) |
435 : tab_(tab) | 436 : tab_(tab), |
436 , screenshot_source_(NULL) | 437 screenshot_source_(NULL), |
437 , bug_report_(NULL) | 438 bug_report_(NULL) |
438 #if defined(OS_CHROMEOS) | 439 #if defined(OS_CHROMEOS) |
439 , syslogs_handle_(0) | 440 , syslogs_handle_(0) |
440 #endif | 441 #endif |
441 { | 442 { |
442 } | 443 } |
443 | 444 |
444 BugReportHandler::~BugReportHandler() { | 445 BugReportHandler::~BugReportHandler() { |
445 // Just in case we didn't send off bug_report_ to SendReport | 446 // Just in case we didn't send off bug_report_ to SendReport |
446 if (bug_report_) { | 447 if (bug_report_) { |
447 // If we're deleting the report object, cancel feedback collection first | 448 // If we're deleting the report object, cancel feedback collection first |
448 CancelFeedbackCollection(); | 449 CancelFeedbackCollection(); |
449 delete bug_report_; | 450 delete bug_report_; |
450 } | 451 } |
451 } | 452 } |
452 | 453 |
453 void BugReportHandler::ClobberScreenshotsSource() { | 454 void BugReportHandler::ClobberScreenshotsSource() { |
454 // Re-create our screenshots data source (this clobbers the last source) | 455 // Re-create our screenshots data source (this clobbers the last source) |
455 // setting the screenshot to NULL, effectively disabling the source | 456 // setting the screenshot to NULL, effectively disabling the source |
456 // TODO(rkc): Once there is a method to 'remove' a source, change this code | 457 // TODO(rkc): Once there is a method to 'remove' a source, change this code |
457 BrowserThread::PostTask( | 458 tab_->profile()->GetChromeURLDataManager()->AddDataSource( |
458 BrowserThread::IO, FROM_HERE, | 459 new WebUIScreenshotSource(NULL)); |
459 NewRunnableMethod( | |
460 ChromeURLDataManager::GetInstance(), | |
461 &ChromeURLDataManager::AddDataSource, | |
462 make_scoped_refptr(new WebUIScreenshotSource(NULL)))); | |
463 | 460 |
464 // clobber last screenshot | 461 // clobber last screenshot |
465 if (browser::last_screenshot_png) | 462 if (browser::last_screenshot_png) |
466 browser::last_screenshot_png->clear(); | 463 browser::last_screenshot_png->clear(); |
467 } | 464 } |
468 | 465 |
469 void BugReportHandler::SetupScreenshotsSource() { | 466 void BugReportHandler::SetupScreenshotsSource() { |
470 // If we don't already have a screenshot source object created, create one. | 467 // If we don't already have a screenshot source object created, create one. |
471 if (!screenshot_source_) | 468 if (!screenshot_source_) |
472 screenshot_source_ = new WebUIScreenshotSource( | 469 screenshot_source_ = new WebUIScreenshotSource( |
473 browser::last_screenshot_png); | 470 browser::last_screenshot_png); |
474 | 471 |
475 // Add the source to the data manager. | 472 // Add the source to the data manager. |
476 BrowserThread::PostTask( | 473 tab_->profile()->GetChromeURLDataManager()->AddDataSource(screenshot_source_); |
477 BrowserThread::IO, FROM_HERE, | |
478 NewRunnableMethod( | |
479 ChromeURLDataManager::GetInstance(), | |
480 &ChromeURLDataManager::AddDataSource, | |
481 make_scoped_refptr(screenshot_source_))); | |
482 } | 474 } |
483 | 475 |
484 WebUIMessageHandler* BugReportHandler::Attach(DOMUI* dom_ui) { | 476 WebUIMessageHandler* BugReportHandler::Attach(DOMUI* dom_ui) { |
485 SetupScreenshotsSource(); | 477 SetupScreenshotsSource(); |
486 return WebUIMessageHandler::Attach(dom_ui); | 478 return WebUIMessageHandler::Attach(dom_ui); |
487 } | 479 } |
488 | 480 |
489 base::StringPiece BugReportHandler::Init() { | 481 base::StringPiece BugReportHandler::Init() { |
490 std::string page_url; | 482 std::string page_url; |
491 if (tab_->controller().GetActiveEntry()) { | 483 if (tab_->controller().GetActiveEntry()) { |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 //////////////////////////////////////////////////////////////////////////////// | 734 //////////////////////////////////////////////////////////////////////////////// |
743 BugReportUI::BugReportUI(TabContents* tab) : HtmlDialogUI(tab) { | 735 BugReportUI::BugReportUI(TabContents* tab) : HtmlDialogUI(tab) { |
744 BugReportHandler* handler = new BugReportHandler(tab); | 736 BugReportHandler* handler = new BugReportHandler(tab); |
745 AddMessageHandler((handler)->Attach(this)); | 737 AddMessageHandler((handler)->Attach(this)); |
746 | 738 |
747 // The handler's init will specify which html | 739 // The handler's init will specify which html |
748 // resource we'll display to the user | 740 // resource we'll display to the user |
749 BugReportUIHTMLSource* html_source = | 741 BugReportUIHTMLSource* html_source = |
750 new BugReportUIHTMLSource(handler->Init()); | 742 new BugReportUIHTMLSource(handler->Init()); |
751 // Set up the chrome://bugreport/ source. | 743 // Set up the chrome://bugreport/ source. |
752 BrowserThread::PostTask( | 744 tab->profile()->GetChromeURLDataManager()->AddDataSource(html_source); |
753 BrowserThread::IO, FROM_HERE, | |
754 NewRunnableMethod( | |
755 ChromeURLDataManager::GetInstance(), | |
756 &ChromeURLDataManager::AddDataSource, | |
757 make_scoped_refptr(html_source))); | |
758 } | 745 } |
OLD | NEW |