OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/feedback_ui.h" | 5 #include "chrome/browser/ui/webui/feedback_ui.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/feedback/feedback_data.h" | 19 #include "chrome/browser/feedback/feedback_data.h" |
20 #include "chrome/browser/feedback/feedback_util.h" | 20 #include "chrome/browser/feedback/feedback_util.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
24 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 26 #include "chrome/browser/ui/webui/chrome_url_data_manager_factory.h" |
26 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 27 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
27 #include "chrome/browser/ui/webui/screenshot_source.h" | 28 #include "chrome/browser/ui/webui/screenshot_source.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/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/navigation_controller.h" | 33 #include "content/public/browser/navigation_controller.h" |
33 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
35 #include "content/public/browser/web_ui.h" | 36 #include "content/public/browser/web_ui.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 298 } |
298 // Make sure we don't leave any screenshot data around. | 299 // Make sure we don't leave any screenshot data around. |
299 FeedbackUtil::ClearScreenshotPng(); | 300 FeedbackUtil::ClearScreenshotPng(); |
300 } | 301 } |
301 | 302 |
302 void FeedbackHandler::ClobberScreenshotsSource() { | 303 void FeedbackHandler::ClobberScreenshotsSource() { |
303 // Re-create our screenshots data source (this clobbers the last source) | 304 // Re-create our screenshots data source (this clobbers the last source) |
304 // setting the screenshot to NULL, effectively disabling the source | 305 // setting the screenshot to NULL, effectively disabling the source |
305 // TODO(rkc): Once there is a method to 'remove' a source, change this code | 306 // TODO(rkc): Once there is a method to 'remove' a source, change this code |
306 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); | 307 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); |
307 profile->GetChromeURLDataManager()->AddDataSource(new ScreenshotSource(NULL)); | 308 ChromeURLDataManagerFactory::GetForProfile(profile)-> |
| 309 AddDataSource(new ScreenshotSource(NULL)); |
308 | 310 |
309 FeedbackUtil::ClearScreenshotPng(); | 311 FeedbackUtil::ClearScreenshotPng(); |
310 } | 312 } |
311 | 313 |
312 void FeedbackHandler::SetupScreenshotsSource() { | 314 void FeedbackHandler::SetupScreenshotsSource() { |
313 // If we don't already have a screenshot source object created, create one. | 315 // If we don't already have a screenshot source object created, create one. |
314 if (!screenshot_source_) { | 316 if (!screenshot_source_) { |
315 screenshot_source_ = | 317 screenshot_source_ = |
316 new ScreenshotSource(FeedbackUtil::GetScreenshotPng()); | 318 new ScreenshotSource(FeedbackUtil::GetScreenshotPng()); |
317 } | 319 } |
318 // Add the source to the data manager. | 320 // Add the source to the data manager. |
319 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); | 321 Profile* profile = Profile::FromBrowserContext(tab_->GetBrowserContext()); |
320 profile->GetChromeURLDataManager()->AddDataSource(screenshot_source_); | 322 ChromeURLDataManagerFactory::GetForProfile(profile)-> |
| 323 AddDataSource(screenshot_source_); |
321 } | 324 } |
322 | 325 |
323 bool FeedbackHandler::Init() { | 326 bool FeedbackHandler::Init() { |
324 std::string page_url; | 327 std::string page_url; |
325 if (tab_->GetController().GetActiveEntry()) { | 328 if (tab_->GetController().GetActiveEntry()) { |
326 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec(); | 329 page_url = tab_->GetController().GetActiveEntry()->GetURL().spec(); |
327 } | 330 } |
328 | 331 |
329 url_parse::Parsed parts; | 332 url_parse::Parsed parts; |
330 ParseStandardURL(page_url.c_str(), page_url.length(), &parts); | 333 ParseStandardURL(page_url.c_str(), page_url.length(), &parts); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 FeedbackUI::FeedbackUI(content::WebUI* web_ui) : HtmlDialogUI(web_ui) { | 582 FeedbackUI::FeedbackUI(content::WebUI* web_ui) : HtmlDialogUI(web_ui) { |
580 FeedbackHandler* handler = new FeedbackHandler(web_ui->GetWebContents()); | 583 FeedbackHandler* handler = new FeedbackHandler(web_ui->GetWebContents()); |
581 web_ui->AddMessageHandler(handler); | 584 web_ui->AddMessageHandler(handler); |
582 | 585 |
583 // The handler's init will determine whether we show the error html page. | 586 // The handler's init will determine whether we show the error html page. |
584 ChromeWebUIDataSource* html_source = | 587 ChromeWebUIDataSource* html_source = |
585 CreateFeedbackUIHTMLSource(handler->Init()); | 588 CreateFeedbackUIHTMLSource(handler->Init()); |
586 | 589 |
587 // Set up the chrome://feedback/ source. | 590 // Set up the chrome://feedback/ source. |
588 Profile* profile = Profile::FromWebUI(web_ui); | 591 Profile* profile = Profile::FromWebUI(web_ui); |
589 profile->GetChromeURLDataManager()->AddDataSource(html_source); | 592 ChromeURLDataManagerFactory::GetForProfile(profile)-> |
| 593 AddDataSource(html_source); |
590 } | 594 } |
591 | 595 |
592 #if defined(OS_CHROMEOS) | 596 #if defined(OS_CHROMEOS) |
593 // static | 597 // static |
594 void FeedbackUI::GetMostRecentScreenshots( | 598 void FeedbackUI::GetMostRecentScreenshots( |
595 const FilePath& filepath, | 599 const FilePath& filepath, |
596 std::vector<std::string>* saved_screenshots, | 600 std::vector<std::string>* saved_screenshots, |
597 size_t max_saved) { | 601 size_t max_saved) { |
598 file_util::FileEnumerator screenshots(filepath, false, | 602 file_util::FileEnumerator screenshots(filepath, false, |
599 file_util::FileEnumerator::FILES, | 603 file_util::FileEnumerator::FILES, |
600 std::string(kScreenshotPattern)); | 604 std::string(kScreenshotPattern)); |
601 FilePath screenshot = screenshots.Next(); | 605 FilePath screenshot = screenshots.Next(); |
602 | 606 |
603 std::vector<std::string> screenshot_filepaths; | 607 std::vector<std::string> screenshot_filepaths; |
604 while (!screenshot.empty()) { | 608 while (!screenshot.empty()) { |
605 screenshot_filepaths.push_back(screenshot.BaseName().value()); | 609 screenshot_filepaths.push_back(screenshot.BaseName().value()); |
606 screenshot = screenshots.Next(); | 610 screenshot = screenshots.Next(); |
607 } | 611 } |
608 | 612 |
609 size_t sort_size = std::min(max_saved, screenshot_filepaths.size()); | 613 size_t sort_size = std::min(max_saved, screenshot_filepaths.size()); |
610 std::partial_sort(screenshot_filepaths.begin(), | 614 std::partial_sort(screenshot_filepaths.begin(), |
611 screenshot_filepaths.begin() + sort_size, | 615 screenshot_filepaths.begin() + sort_size, |
612 screenshot_filepaths.end(), | 616 screenshot_filepaths.end(), |
613 ScreenshotTimestampComp); | 617 ScreenshotTimestampComp); |
614 for (size_t i = 0; i < sort_size; ++i) | 618 for (size_t i = 0; i < sort_size; ++i) |
615 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + | 619 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + |
616 screenshot_filepaths[i]); | 620 screenshot_filepaths[i]); |
617 } | 621 } |
618 #endif | 622 #endif |
OLD | NEW |