| 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/screenshot_source.h" | 5 #include "chrome/browser/ui/webui/screenshot_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/i18n/time_formatting.h" | 11 #include "base/i18n/time_formatting.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/download/download_prefs.h" | 19 #include "chrome/browser/download/download_prefs.h" |
| 20 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
| 23 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "googleurl/src/url_canon.h" | 27 #include "googleurl/src/url_canon.h" |
| 27 #include "googleurl/src/url_util.h" | 28 #include "googleurl/src/url_util.h" |
| 28 | 29 |
| 29 #if defined(USE_ASH) | 30 #if defined(USE_ASH) |
| 30 #include "ash/shell.h" | 31 #include "ash/shell.h" |
| 31 #include "ash/shell_delegate.h" | 32 #include "ash/shell_delegate.h" |
| 32 #endif | 33 #endif |
| (...skipping 25 matching lines...) Expand all Loading... |
| 58 if (profile) { | 59 if (profile) { |
| 59 return profile->GetPrefs()->GetBoolean(prefs::kUse24HourClock); | 60 return profile->GetPrefs()->GetBoolean(prefs::kUse24HourClock); |
| 60 } | 61 } |
| 61 #endif | 62 #endif |
| 62 return base::GetHourClockType() == base::k24HourClock; | 63 return base::GetHourClockType() == base::k24HourClock; |
| 63 } | 64 } |
| 64 | 65 |
| 65 ScreenshotSource::ScreenshotSource( | 66 ScreenshotSource::ScreenshotSource( |
| 66 std::vector<unsigned char>* current_screenshot, | 67 std::vector<unsigned char>* current_screenshot, |
| 67 Profile* profile) | 68 Profile* profile) |
| 68 : DataSource(chrome::kChromeUIScreenshotPath, MessageLoop::current()), | 69 : profile_(profile) { |
| 69 profile_(profile) { | |
| 70 // Setup the last screenshot taken. | 70 // Setup the last screenshot taken. |
| 71 if (current_screenshot) | 71 if (current_screenshot) |
| 72 current_screenshot_.reset(new ScreenshotData(*current_screenshot)); | 72 current_screenshot_.reset(new ScreenshotData(*current_screenshot)); |
| 73 else | 73 else |
| 74 current_screenshot_.reset(new ScreenshotData()); | 74 current_screenshot_.reset(new ScreenshotData()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 ScreenshotSource::~ScreenshotSource() {} | 77 ScreenshotSource::~ScreenshotSource() {} |
| 78 | 78 |
| 79 // static | 79 // static |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 if (!file_util::GetTempDir(directory)) { | 133 if (!file_util::GetTempDir(directory)) { |
| 134 LOG(ERROR) << "Failed to find temporary directory."; | 134 LOG(ERROR) << "Failed to find temporary directory."; |
| 135 return false; | 135 return false; |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 return true; | 138 return true; |
| 139 } | 139 } |
| 140 | 140 |
| 141 #endif | 141 #endif |
| 142 | 142 |
| 143 std::string ScreenshotSource::GetSource() { |
| 144 return chrome::kChromeUIScreenshotPath; |
| 145 } |
| 146 |
| 143 void ScreenshotSource::StartDataRequest(const std::string& path, bool, | 147 void ScreenshotSource::StartDataRequest(const std::string& path, bool, |
| 144 int request_id) { | 148 int request_id) { |
| 145 SendScreenshot(path, request_id); | 149 SendScreenshot(path, request_id); |
| 146 } | 150 } |
| 147 | 151 |
| 148 std::string ScreenshotSource::GetMimeType(const std::string&) const { | 152 std::string ScreenshotSource::GetMimeType(const std::string&) const { |
| 149 // We need to explicitly return a mime type, otherwise if the user tries to | 153 // We need to explicitly return a mime type, otherwise if the user tries to |
| 150 // drag the image they get no extension. | 154 // drag the image they get no extension. |
| 151 return "image/png"; | 155 return "image/png"; |
| 152 } | 156 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 #endif | 258 #endif |
| 255 | 259 |
| 256 void ScreenshotSource::CacheAndSendScreenshot( | 260 void ScreenshotSource::CacheAndSendScreenshot( |
| 257 const std::string& screenshot_path, | 261 const std::string& screenshot_path, |
| 258 int request_id, | 262 int request_id, |
| 259 ScreenshotDataPtr bytes) { | 263 ScreenshotDataPtr bytes) { |
| 260 // Strip the query from the screenshot path. | 264 // Strip the query from the screenshot path. |
| 261 std::string path = screenshot_path.substr( | 265 std::string path = screenshot_path.substr( |
| 262 0, screenshot_path.find_first_of("?")); | 266 0, screenshot_path.find_first_of("?")); |
| 263 cached_screenshots_[path] = bytes; | 267 cached_screenshots_[path] = bytes; |
| 264 SendResponse(request_id, new base::RefCountedBytes(*bytes)); | 268 url_data_source()->SendResponse( |
| 269 request_id, new base::RefCountedBytes(*bytes)); |
| 265 } | 270 } |
| OLD | NEW |