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/time.h" | 16 #include "base/time.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 "chrome/browser/browser_process.h" |
19 #include "chrome/browser/download/download_prefs.h" | 20 #include "chrome/browser/download/download_prefs.h" |
20 #include "chrome/browser/feedback/feedback_data.h" | 21 #include "chrome/browser/feedback/feedback_data.h" |
21 #include "chrome/browser/feedback/feedback_util.h" | 22 #include "chrome/browser/feedback/feedback_util.h" |
| 23 #include "chrome/browser/prefs/pref_service.h" |
22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
25 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
26 #include "chrome/browser/ui/browser_window.h" | 28 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/singleton_tabs.h" | 29 #include "chrome/browser/ui/singleton_tabs.h" |
28 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 30 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
29 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 31 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
30 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 32 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
31 #include "chrome/browser/ui/webui/screenshot_source.h" | 33 #include "chrome/browser/ui/webui/screenshot_source.h" |
32 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | 34 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
33 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
| 36 #include "chrome/common/pref_names.h" |
34 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
35 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/navigation_controller.h" | 39 #include "content/public/browser/navigation_controller.h" |
37 #include "content/public/browser/navigation_entry.h" | 40 #include "content/public/browser/navigation_entry.h" |
38 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
39 #include "content/public/browser/web_ui.h" | 42 #include "content/public/browser/web_ui.h" |
40 #include "content/public/browser/web_ui_message_handler.h" | 43 #include "content/public/browser/web_ui_message_handler.h" |
41 #include "grit/browser_resources.h" | 44 #include "grit/browser_resources.h" |
42 #include "grit/chromium_strings.h" | 45 #include "grit/chromium_strings.h" |
43 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 #if defined(OS_CHROMEOS) | 164 #if defined(OS_CHROMEOS) |
162 // For ChromeOS, don't use the browser window but the root window | 165 // For ChromeOS, don't use the browser window but the root window |
163 // instead to grab the screenshot. We want everything on the screen, not | 166 // instead to grab the screenshot. We want everything on the screen, not |
164 // just the current browser. | 167 // just the current browser. |
165 native_window = ash::Shell::GetPrimaryRootWindow(); | 168 native_window = ash::Shell::GetPrimaryRootWindow(); |
166 snapshot_bounds = gfx::Rect(native_window->bounds()); | 169 snapshot_bounds = gfx::Rect(native_window->bounds()); |
167 #else | 170 #else |
168 native_window = browser->window()->GetNativeWindow(); | 171 native_window = browser->window()->GetNativeWindow(); |
169 snapshot_bounds = gfx::Rect(browser->window()->GetBounds().size()); | 172 snapshot_bounds = gfx::Rect(browser->window()->GetBounds().size()); |
170 #endif | 173 #endif |
171 bool success = chrome::GrabWindowSnapshot(native_window, | 174 bool success = chrome::GrabWindowSnapshot(native_window, last_screenshot_png, |
172 last_screenshot_png, | |
173 snapshot_bounds); | 175 snapshot_bounds); |
174 FeedbackUtil::SetScreenshotSize(success ? snapshot_bounds : gfx::Rect()); | 176 FeedbackUtil::SetScreenshotSize(success ? snapshot_bounds : gfx::Rect()); |
175 | 177 |
176 std::string feedback_url = std::string(chrome::kChromeUIFeedbackURL) + "?" + | 178 std::string feedback_url = std::string(chrome::kChromeUIFeedbackURL) + "?" + |
177 kSessionIDParameter + base::IntToString(browser->session_id().id()) + | 179 kSessionIDParameter + base::IntToString(browser->session_id().id()) + |
178 "&" + kTabIndexParameter + base::IntToString(browser->active_index()) + | 180 "&" + kTabIndexParameter + base::IntToString(browser->active_index()) + |
179 "&" + kDescriptionParameter + | 181 "&" + kDescriptionParameter + |
180 net::EscapeUrlEncodedData(description_template, false) + "&" + | 182 net::EscapeUrlEncodedData(description_template, false) + "&" + |
181 kCategoryTagParameter + net::EscapeUrlEncodedData(category_tag, false); | 183 kCategoryTagParameter + net::EscapeUrlEncodedData(category_tag, false); |
182 | 184 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 base::Unretained(this))); | 435 base::Unretained(this))); |
434 web_ui()->RegisterMessageCallback("openSystemTab", | 436 web_ui()->RegisterMessageCallback("openSystemTab", |
435 base::Bind(&FeedbackHandler::HandleOpenSystemTab, | 437 base::Bind(&FeedbackHandler::HandleOpenSystemTab, |
436 base::Unretained(this))); | 438 base::Unretained(this))); |
437 } | 439 } |
438 | 440 |
439 void FeedbackHandler::HandleGetDialogDefaults(const ListValue*) { | 441 void FeedbackHandler::HandleGetDialogDefaults(const ListValue*) { |
440 // Will delete itself when feedback_data_->SendReport() is called. | 442 // Will delete itself when feedback_data_->SendReport() is called. |
441 feedback_data_ = new FeedbackData(); | 443 feedback_data_ = new FeedbackData(); |
442 | 444 |
443 // send back values which the dialog js needs initially | 445 // Send back values which the dialog js needs initially. |
444 ListValue dialog_defaults; | 446 DictionaryValue dialog_defaults; |
445 | 447 |
446 // 0: current url | 448 // Current url. |
447 if (target_tab_url_.length()) | 449 dialog_defaults.SetString("currentUrl", target_tab_url_); |
448 dialog_defaults.Append(new StringValue(target_tab_url_)); | 450 |
449 else | 451 // Are screenshots disabled? |
450 dialog_defaults.Append(new StringValue("")); | 452 dialog_defaults.SetBoolean( |
| 453 "disableScreenshots", |
| 454 g_browser_process->local_state()->GetBoolean(prefs::kDisableScreenshots)); |
451 | 455 |
452 #if defined(OS_CHROMEOS) | 456 #if defined(OS_CHROMEOS) |
453 // 1: about:system | |
454 dialog_defaults.Append(new StringValue(chrome::kChromeUISystemInfoURL)); | |
455 // Trigger the request for system information here. | 457 // Trigger the request for system information here. |
456 chromeos::system::SyslogsProvider* provider = | 458 chromeos::system::SyslogsProvider* provider = |
457 chromeos::system::SyslogsProvider::GetInstance(); | 459 chromeos::system::SyslogsProvider::GetInstance(); |
458 if (provider) { | 460 if (provider) { |
459 syslogs_handle_ = provider->RequestSyslogs( | 461 syslogs_handle_ = provider->RequestSyslogs( |
460 true, // don't compress. | 462 true, // don't compress. |
461 chromeos::system::SyslogsProvider::SYSLOGS_FEEDBACK, | 463 chromeos::system::SyslogsProvider::SYSLOGS_FEEDBACK, |
462 &syslogs_consumer_, | 464 &syslogs_consumer_, |
463 base::Bind(&FeedbackData::SyslogsComplete, | 465 base::Bind(&FeedbackData::SyslogsComplete, |
464 base::Unretained(feedback_data_))); | 466 base::Unretained(feedback_data_))); |
465 } | 467 } |
466 // 2: user e-mail | 468 // User e-mail |
467 dialog_defaults.Append(new StringValue(GetUserEmail())); | 469 dialog_defaults.SetString("userEmail", GetUserEmail()); |
468 #endif | 470 #endif |
469 | 471 |
470 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults); | 472 web_ui()->CallJavascriptFunction("setupDialogDefaults", dialog_defaults); |
471 } | 473 } |
472 | 474 |
473 void FeedbackHandler::HandleRefreshCurrentScreenshot(const ListValue*) { | 475 void FeedbackHandler::HandleRefreshCurrentScreenshot(const ListValue*) { |
474 std::string current_screenshot(kCurrentScreenshotUrl); | 476 std::string current_screenshot(kCurrentScreenshotUrl); |
475 StringValue screenshot(current_screenshot); | 477 StringValue screenshot(current_screenshot); |
476 web_ui()->CallJavascriptFunction("setupCurrentScreenshot", screenshot); | 478 web_ui()->CallJavascriptFunction("setupCurrentScreenshot", screenshot); |
477 } | 479 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 size_t sort_size = std::min(max_saved, screenshot_filepaths.size()); | 649 size_t sort_size = std::min(max_saved, screenshot_filepaths.size()); |
648 std::partial_sort(screenshot_filepaths.begin(), | 650 std::partial_sort(screenshot_filepaths.begin(), |
649 screenshot_filepaths.begin() + sort_size, | 651 screenshot_filepaths.begin() + sort_size, |
650 screenshot_filepaths.end(), | 652 screenshot_filepaths.end(), |
651 ScreenshotTimestampComp); | 653 ScreenshotTimestampComp); |
652 for (size_t i = 0; i < sort_size; ++i) | 654 for (size_t i = 0; i < sort_size; ++i) |
653 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + | 655 saved_screenshots->push_back(std::string(kSavedScreenshotsUrl) + |
654 screenshot_filepaths[i]); | 656 screenshot_filepaths[i]); |
655 } | 657 } |
656 #endif | 658 #endif |
OLD | NEW |