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_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 url_canon::RawCanonOutputT<char16> decoded; | 97 url_canon::RawCanonOutputT<char16> decoded; |
98 url_util::DecodeURLEscapeSequences( | 98 url_util::DecodeURLEscapeSequences( |
99 filename.data(), filename.size(), &decoded); | 99 filename.data(), filename.size(), &decoded); |
100 // Screenshot filenames don't use non-ascii characters. | 100 // Screenshot filenames don't use non-ascii characters. |
101 std::string decoded_filename = UTF16ToASCII(string16( | 101 std::string decoded_filename = UTF16ToASCII(string16( |
102 decoded.data(), decoded.length())); | 102 decoded.data(), decoded.length())); |
103 | 103 |
104 int64 file_size = 0; | 104 int64 file_size = 0; |
105 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( | 105 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext( |
106 ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext()); | 106 ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext()); |
107 FilePath file = download_prefs->download_path().Append(decoded_filename); | 107 FilePath file = download_prefs->DownloadPath().Append(decoded_filename); |
108 if (!file_util::GetFileSize(file, &file_size)) { | 108 if (!file_util::GetFileSize(file, &file_size)) { |
109 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); | 109 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); |
110 return; | 110 return; |
111 } | 111 } |
112 | 112 |
113 read_bytes->resize(file_size); | 113 read_bytes->resize(file_size); |
114 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()), | 114 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()), |
115 static_cast<int>(file_size))) | 115 static_cast<int>(file_size))) |
116 read_bytes->clear(); | 116 read_bytes->clear(); |
117 | 117 |
118 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); | 118 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); |
119 } | 119 } |
120 #endif | 120 #endif |
121 | 121 |
122 void ScreenshotSource::CacheAndSendScreenshot( | 122 void ScreenshotSource::CacheAndSendScreenshot( |
123 const std::string& screenshot_path, | 123 const std::string& screenshot_path, |
124 int request_id, | 124 int request_id, |
125 ScreenshotDataPtr bytes) { | 125 ScreenshotDataPtr bytes) { |
126 cached_screenshots_[screenshot_path] = bytes; | 126 cached_screenshots_[screenshot_path] = bytes; |
127 SendResponse(request_id, new base::RefCountedBytes(*bytes)); | 127 SendResponse(request_id, new base::RefCountedBytes(*bytes)); |
128 } | 128 } |
OLD | NEW |