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/ash/screenshot_taker.h" | 5 #include "chrome/browser/ui/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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 105 } |
105 | 106 |
106 if (static_cast<size_t>(file_util::WriteFile( | 107 if (static_cast<size_t>(file_util::WriteFile( |
107 screenshot_path, | 108 screenshot_path, |
108 reinterpret_cast<char*>(&(png_data->data()[0])), | 109 reinterpret_cast<char*>(&(png_data->data()[0])), |
109 png_data->size())) != png_data->size()) { | 110 png_data->size())) != png_data->size()) { |
110 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); | 111 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); |
111 } | 112 } |
112 } | 113 } |
113 | 114 |
| 115 bool AreScreenshotsDisabled() { |
| 116 return g_browser_process->local_state()->GetBoolean( |
| 117 prefs::kDisableScreenshots); |
| 118 } |
| 119 |
114 bool GrabWindowSnapshot(aura::Window* window, | 120 bool GrabWindowSnapshot(aura::Window* window, |
115 const gfx::Rect& snapshot_bounds, | 121 const gfx::Rect& snapshot_bounds, |
116 std::vector<unsigned char>* png_data) { | 122 std::vector<unsigned char>* png_data) { |
117 #if defined(OS_LINUX) | 123 #if defined(OS_LINUX) |
| 124 // browser::GrabWindowSnapshot checks this too, but RootWindow::GrabSnapshot |
| 125 // does not. The statement below is only to support linux-specific XGetImage |
| 126 // optimization. |
| 127 if (AreScreenshotsDisabled()) |
| 128 return false; |
| 129 |
118 // We use XGetImage() for Linux/ChromeOS for performance reasons. | 130 // We use XGetImage() for Linux/ChromeOS for performance reasons. |
119 // See crbug.com/119492 | 131 // See crbug.com/119492 |
120 // TODO(mukai): remove this when the performance issue has been fixed. | 132 // TODO(mukai): remove this when the performance issue has been fixed. |
121 if (window->GetRootWindow()->GrabSnapshot(snapshot_bounds, png_data)) | 133 if (window->GetRootWindow()->GrabSnapshot(snapshot_bounds, png_data)) |
122 return true; | 134 return true; |
123 #endif // OS_LINUX | 135 #endif // OS_LINUX |
124 | 136 |
125 return chrome::GrabWindowSnapshot(window, png_data, snapshot_bounds); | 137 return chrome::GrabWindowSnapshot(window, png_data, snapshot_bounds); |
126 } | 138 } |
127 | 139 |
(...skipping 13 matching lines...) Expand all Loading... |
141 } | 153 } |
142 | 154 |
143 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) { | 155 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) { |
144 HandleTakePartialScreenshot(window, window->bounds()); | 156 HandleTakePartialScreenshot(window, window->bounds()); |
145 } | 157 } |
146 | 158 |
147 void ScreenshotTaker::HandleTakePartialScreenshot( | 159 void ScreenshotTaker::HandleTakePartialScreenshot( |
148 aura::Window* window, const gfx::Rect& rect) { | 160 aura::Window* window, const gfx::Rect& rect) { |
149 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 161 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
150 | 162 |
| 163 if (AreScreenshotsDisabled()) |
| 164 return; |
| 165 |
151 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes); | 166 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes); |
152 | 167 |
153 bool is_logged_in = true; | 168 bool is_logged_in = true; |
154 #if defined(OS_CHROMEOS) | 169 #if defined(OS_CHROMEOS) |
155 is_logged_in = chromeos::UserManager::Get()->IsUserLoggedIn(); | 170 is_logged_in = chromeos::UserManager::Get()->IsUserLoggedIn(); |
156 #endif | 171 #endif |
157 | 172 |
158 FilePath screenshot_directory; | 173 FilePath screenshot_directory; |
159 if (is_logged_in) { | 174 if (is_logged_in) { |
160 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( | 175 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 ash::internal::kShellWindowId_OverlayContainer)->layer(); | 218 ash::internal::kShellWindowId_OverlayContainer)->layer(); |
204 parent->Add(visual_feedback_layer_.get()); | 219 parent->Add(visual_feedback_layer_.get()); |
205 visual_feedback_layer_->SetVisible(true); | 220 visual_feedback_layer_->SetVisible(true); |
206 | 221 |
207 MessageLoopForUI::current()->PostDelayedTask( | 222 MessageLoopForUI::current()->PostDelayedTask( |
208 FROM_HERE, | 223 FROM_HERE, |
209 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer, | 224 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer, |
210 base::Unretained(this)), | 225 base::Unretained(this)), |
211 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs)); | 226 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs)); |
212 } | 227 } |
OLD | NEW |