| 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/views/ash/screenshot_taker.h" | 5 #include "chrome/browser/ui/views/ash/screenshot_taker.h" |
| 6 | 6 |
| 7 #include <climits> | 7 #include <climits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_delegate.h" | 11 #include "ash/shell_delegate.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 16 #include "base/i18n/time_formatting.h" | 16 #include "base/i18n/time_formatting.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
| 19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
| 20 #include "base/time.h" | 20 #include "base/time.h" |
| 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/download/download_prefs.h" | 22 #include "chrome/browser/download/download_prefs.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_manager.h" | 25 #include "chrome/browser/profiles/profile_manager.h" |
| 25 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | 26 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 28 #include "ui/aura/root_window.h" | 29 #include "ui/aura/root_window.h" |
| 29 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
| 30 | 31 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 103 } |
| 103 | 104 |
| 104 if (static_cast<size_t>(file_util::WriteFile( | 105 if (static_cast<size_t>(file_util::WriteFile( |
| 105 screenshot_path, | 106 screenshot_path, |
| 106 reinterpret_cast<char*>(&(png_data->data()[0])), | 107 reinterpret_cast<char*>(&(png_data->data()[0])), |
| 107 png_data->size())) != png_data->size()) { | 108 png_data->size())) != png_data->size()) { |
| 108 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); | 109 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); |
| 109 } | 110 } |
| 110 } | 111 } |
| 111 | 112 |
| 112 bool GrabWindowSnapshot(aura::Window* window, | 113 bool GrabWindowSnapshotIfPermitted(aura::Window* window, |
| 113 const gfx::Rect& snapshot_bounds, | 114 const gfx::Rect& snapshot_bounds, |
| 114 std::vector<unsigned char>* png_data) { | 115 std::vector<unsigned char>* png_data) { |
| 115 #if defined(OS_LINUX) | 116 #if defined(OS_LINUX) |
| 117 // browser::GrabWindowSnapshotIfPermitted checks this too, |
| 118 // but RootWindow::GrabSnapshot does not. The statement below is only to |
| 119 // support linux-specific XGetImage optimization. |
| 120 if (g_browser_process->local_state()->GetBoolean(prefs::kDisableScreenshots)) |
| 121 return false; |
| 122 |
| 116 // We use XGetImage() for Linux/ChromeOS for performance reasons. | 123 // We use XGetImage() for Linux/ChromeOS for performance reasons. |
| 117 // See crbug.com/119492 | 124 // See crbug.com/119492 |
| 118 // TODO(mukai): remove this when the performance issue has been fixed. | 125 // TODO(mukai): remove this when the performance issue has been fixed. |
| 119 if (window->GetRootWindow()->GrabSnapshot(snapshot_bounds, png_data)) | 126 if (window->GetRootWindow()->GrabSnapshot(snapshot_bounds, png_data)) |
| 120 return true; | 127 return true; |
| 121 #endif // OS_LINUX | 128 #endif // OS_LINUX |
| 122 | 129 |
| 123 return browser::GrabWindowSnapshot(window, png_data, snapshot_bounds); | 130 return browser::GrabWindowSnapshotIfPermitted(window, png_data, |
| 131 snapshot_bounds); |
| 124 } | 132 } |
| 125 | 133 |
| 126 // How opaque should the layer that we flash onscreen to provide visual | 134 // How opaque should the layer that we flash onscreen to provide visual |
| 127 // feedback after the screenshot is taken be? | 135 // feedback after the screenshot is taken be? |
| 128 const float kVisualFeedbackLayerOpacity = 0.25f; | 136 const float kVisualFeedbackLayerOpacity = 0.25f; |
| 129 | 137 |
| 130 // How long should the visual feedback layer be displayed? | 138 // How long should the visual feedback layer be displayed? |
| 131 const int64 kVisualFeedbackLayerDisplayTimeMs = 100; | 139 const int64 kVisualFeedbackLayerDisplayTimeMs = 100; |
| 132 | 140 |
| 133 } // namespace | 141 } // namespace |
| (...skipping 22 matching lines...) Expand all Loading... |
| 156 screenshot_directory = download_prefs->download_path(); | 164 screenshot_directory = download_prefs->download_path(); |
| 157 } else { | 165 } else { |
| 158 if (!file_util::GetTempDir(&screenshot_directory)) { | 166 if (!file_util::GetTempDir(&screenshot_directory)) { |
| 159 LOG(ERROR) << "Failed to find temporary directory."; | 167 LOG(ERROR) << "Failed to find temporary directory."; |
| 160 return; | 168 return; |
| 161 } | 169 } |
| 162 } | 170 } |
| 163 | 171 |
| 164 bool use_24hour_clock = ShouldUse24HourClock(); | 172 bool use_24hour_clock = ShouldUse24HourClock(); |
| 165 | 173 |
| 166 if (GrabWindowSnapshot(window, rect, &png_data->data())) { | 174 if (GrabWindowSnapshotIfPermitted(window, rect, &png_data->data())) { |
| 167 DisplayVisualFeedback(rect); | 175 DisplayVisualFeedback(rect); |
| 168 content::BrowserThread::PostTask( | 176 content::BrowserThread::PostTask( |
| 169 content::BrowserThread::FILE, FROM_HERE, | 177 content::BrowserThread::FILE, FROM_HERE, |
| 170 base::Bind(&SaveScreenshot, screenshot_directory, use_24hour_clock, | 178 base::Bind(&SaveScreenshot, screenshot_directory, use_24hour_clock, |
| 171 png_data)); | 179 png_data)); |
| 172 } else { | 180 } else { |
| 173 LOG(ERROR) << "Failed to grab the window screenshot"; | 181 LOG(ERROR) << "Failed to grab the window screenshot"; |
| 174 } | 182 } |
| 175 } | 183 } |
| 176 | 184 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 193 ash::internal::kShellWindowId_OverlayContainer)->layer(); | 201 ash::internal::kShellWindowId_OverlayContainer)->layer(); |
| 194 parent->Add(visual_feedback_layer_.get()); | 202 parent->Add(visual_feedback_layer_.get()); |
| 195 visual_feedback_layer_->SetVisible(true); | 203 visual_feedback_layer_->SetVisible(true); |
| 196 | 204 |
| 197 MessageLoopForUI::current()->PostDelayedTask( | 205 MessageLoopForUI::current()->PostDelayedTask( |
| 198 FROM_HERE, | 206 FROM_HERE, |
| 199 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer, | 207 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer, |
| 200 base::Unretained(this)), | 208 base::Unretained(this)), |
| 201 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs)); | 209 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs)); |
| 202 } | 210 } |
| OLD | NEW |