Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: chrome/browser/ui/webui/screenshot_source.cc

Issue 10837253: Allow /drive files in "Report Issue" page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/string16.h" 13 #include "base/string16.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "chrome/browser/download/download_prefs.h" 15 #include "chrome/browser/download/download_prefs.h"
16 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
18 #include "googleurl/src/url_canon.h" 18 #include "googleurl/src/url_canon.h"
19 #include "googleurl/src/url_util.h" 19 #include "googleurl/src/url_util.h"
20 20
21 #if defined(OS_CHROMEOS) 21 #if defined(OS_CHROMEOS)
22 #include "ash/shell.h" 22 #include "ash/shell.h"
23 #include "ash/shell_delegate.h" 23 #include "ash/shell_delegate.h"
24 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h"
25 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
26 #include "chrome/browser/chromeos/gdata/gdata_util.h"
24 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
25 #endif 28 #endif
26 29
27 static const char kCurrentScreenshotFilename[] = "current"; 30 static const char kCurrentScreenshotFilename[] = "current";
28 #if defined(OS_CHROMEOS) 31 #if defined(OS_CHROMEOS)
29 static const char kSavedScreenshotsBasePath[] = "saved/"; 32 static const char kSavedScreenshotsBasePath[] = "saved/";
30 #endif 33 #endif
31 34
32 ScreenshotSource::ScreenshotSource( 35 ScreenshotSource::ScreenshotSource(
33 std::vector<unsigned char>* current_screenshot) 36 std::vector<unsigned char>* current_screenshot,
34 : DataSource(chrome::kChromeUIScreenshotPath, MessageLoop::current()) { 37 Profile* profile)
38 : DataSource(chrome::kChromeUIScreenshotPath, MessageLoop::current()),
39 profile_(profile) {
35 // Setup the last screenshot taken. 40 // Setup the last screenshot taken.
36 if (current_screenshot) 41 if (current_screenshot)
37 current_screenshot_.reset(new ScreenshotData(*current_screenshot)); 42 current_screenshot_.reset(new ScreenshotData(*current_screenshot));
38 else 43 else
39 current_screenshot_.reset(new ScreenshotData()); 44 current_screenshot_.reset(new ScreenshotData());
40 } 45 }
41 46
42 ScreenshotSource::~ScreenshotSource() {} 47 ScreenshotSource::~ScreenshotSource() {}
43 48
44 void ScreenshotSource::StartDataRequest(const std::string& path, bool, 49 void ScreenshotSource::StartDataRequest(const std::string& path, bool,
(...skipping 24 matching lines...) Expand all
69 // Strip the query param value - we only use it as a hack to ensure our 74 // Strip the query param value - we only use it as a hack to ensure our
70 // image gets reloaded instead of being pulled from the browser cache 75 // image gets reloaded instead of being pulled from the browser cache
71 std::string path = screenshot_path.substr( 76 std::string path = screenshot_path.substr(
72 0, screenshot_path.find_first_of("?")); 77 0, screenshot_path.find_first_of("?"));
73 if (path == kCurrentScreenshotFilename) { 78 if (path == kCurrentScreenshotFilename) {
74 CacheAndSendScreenshot(path, request_id, current_screenshot_); 79 CacheAndSendScreenshot(path, request_id, current_screenshot_);
75 #if defined(OS_CHROMEOS) 80 #if defined(OS_CHROMEOS)
76 } else if (path.compare(0, strlen(kSavedScreenshotsBasePath), 81 } else if (path.compare(0, strlen(kSavedScreenshotsBasePath),
77 kSavedScreenshotsBasePath) == 0) { 82 kSavedScreenshotsBasePath) == 0) {
78 using content::BrowserThread; 83 using content::BrowserThread;
79 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 84
80 base::Bind(&ScreenshotSource::SendSavedScreenshot, 85 std::string filename = screenshot_path.substr(
81 base::Unretained(this), path, 86 strlen(kSavedScreenshotsBasePath));
82 request_id)); 87
88 url_canon::RawCanonOutputT<char16> decoded;
89 url_util::DecodeURLEscapeSequences(
90 filename.data(), filename.size(), &decoded);
91 // Screenshot filenames don't use non-ascii characters.
92 std::string decoded_filename = UTF16ToASCII(string16(
93 decoded.data(), decoded.length()));
94
95 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
96 ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext());
97 FilePath download_path = download_prefs->DownloadPath();
98 if (gdata::util::IsUnderGDataMountPoint(download_path)) {
99 gdata::GDataFileSystemInterface* file_system =
100 gdata::GDataSystemServiceFactory::GetForProfile(
101 profile_)->file_system();
102 file_system->GetFileByResourceId(
103 decoded_filename,
104 base::Bind(&ScreenshotSource::GetSavedScreenshotCallback,
105 base::Unretained(this), screenshot_path, request_id),
106 gdata::GetContentCallback());
107 } else {
108 BrowserThread::PostTask(
109 BrowserThread::FILE, FROM_HERE,
110 base::Bind(&ScreenshotSource::SendSavedScreenshot,
111 base::Unretained(this),
112 screenshot_path,
113 request_id, download_path.Append(decoded_filename)));
114 }
83 #endif 115 #endif
84 } else { 116 } else {
85 CacheAndSendScreenshot( 117 CacheAndSendScreenshot(
86 path, request_id, ScreenshotDataPtr(new ScreenshotData())); 118 path, request_id, ScreenshotDataPtr(new ScreenshotData()));
87 } 119 }
88 } 120 }
89 121
90 #if defined(OS_CHROMEOS) 122 #if defined(OS_CHROMEOS)
91 void ScreenshotSource::SendSavedScreenshot(const std::string& screenshot_path, 123 void ScreenshotSource::SendSavedScreenshot(
92 int request_id) { 124 const std::string& screenshot_path,
125 int request_id,
126 const FilePath& file) {
93 ScreenshotDataPtr read_bytes(new ScreenshotData); 127 ScreenshotDataPtr read_bytes(new ScreenshotData);
94 std::string filename = screenshot_path.substr( 128 int64 file_size = 0;
95 strlen(kSavedScreenshotsBasePath));
96 129
97 url_canon::RawCanonOutputT<char16> decoded;
98 url_util::DecodeURLEscapeSequences(
99 filename.data(), filename.size(), &decoded);
100 // Screenshot filenames don't use non-ascii characters.
101 std::string decoded_filename = UTF16ToASCII(string16(
102 decoded.data(), decoded.length()));
103
104 int64 file_size = 0;
105 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
106 ash::Shell::GetInstance()->delegate()->GetCurrentBrowserContext());
107 FilePath file = download_prefs->DownloadPath().Append(decoded_filename);
108 if (!file_util::GetFileSize(file, &file_size)) { 130 if (!file_util::GetFileSize(file, &file_size)) {
109 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); 131 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes);
110 return; 132 return;
111 } 133 }
112 134
113 read_bytes->resize(file_size); 135 read_bytes->resize(file_size);
114 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()), 136 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()),
115 static_cast<int>(file_size))) 137 static_cast<int>(file_size)))
116 read_bytes->clear(); 138 read_bytes->clear();
117 139
118 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); 140 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes);
119 } 141 }
142
143 void ScreenshotSource::GetSavedScreenshotCallback(
144 const std::string& screenshot_path,
145 int request_id,
146 gdata::GDataFileError error,
147 const FilePath& file,
148 const std::string& unused_mime_type,
149 gdata::GDataFileType file_type) {
150 if (error != gdata::GDATA_FILE_OK || file_type != gdata::REGULAR_FILE) {
151 ScreenshotDataPtr read_bytes(new ScreenshotData);
152 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes);
153 return;
154 }
155
156 content::BrowserThread::PostTask(
157 content::BrowserThread::FILE, FROM_HERE,
158 base::Bind(&ScreenshotSource::SendSavedScreenshot,
159 base::Unretained(this), screenshot_path, request_id, file));
160 }
120 #endif 161 #endif
121 162
122 void ScreenshotSource::CacheAndSendScreenshot( 163 void ScreenshotSource::CacheAndSendScreenshot(
123 const std::string& screenshot_path, 164 const std::string& screenshot_path,
124 int request_id, 165 int request_id,
125 ScreenshotDataPtr bytes) { 166 ScreenshotDataPtr bytes) {
126 cached_screenshots_[screenshot_path] = bytes; 167 cached_screenshots_[screenshot_path] = bytes;
127 SendResponse(request_id, new base::RefCountedBytes(*bytes)); 168 SendResponse(request_id, new base::RefCountedBytes(*bytes));
128 } 169 }
OLDNEW
« chrome/browser/ui/webui/feedback_ui.cc ('K') | « chrome/browser/ui/webui/screenshot_source.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698