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

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
« no previous file with comments | « chrome/browser/ui/webui/screenshot_source.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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::SendSavedScreenshot,
kinaba 2012/08/15 09:01:55 This time, SendSavedScreenshot is called back on t
Jun Mukai 2012/08/15 09:18:45 Done.
105 base::Unretained(this), screenshot_path, request_id),
106 gdata::GetContentCallback());
107 } else {
108 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
109 base::Bind(&ScreenshotSource::SendSavedScreenshot,
110 base::Unretained(this),
111 screenshot_path,
112 request_id,
113 gdata::GDATA_FILE_OK,
114 download_path.Append(decoded_filename),
115 "",
116 gdata::REGULAR_FILE));
117 }
83 #endif 118 #endif
84 } else { 119 } else {
85 CacheAndSendScreenshot( 120 CacheAndSendScreenshot(
86 path, request_id, ScreenshotDataPtr(new ScreenshotData())); 121 path, request_id, ScreenshotDataPtr(new ScreenshotData()));
87 } 122 }
88 } 123 }
89 124
90 #if defined(OS_CHROMEOS) 125 #if defined(OS_CHROMEOS)
91 void ScreenshotSource::SendSavedScreenshot(const std::string& screenshot_path, 126 void ScreenshotSource::SendSavedScreenshot(
92 int request_id) { 127 const std::string& screenshot_path,
128 int request_id,
129 gdata::GDataFileError error,
130 const FilePath& file,
131 const std::string& mime_type,
132 gdata::GDataFileType file_type) {
93 ScreenshotDataPtr read_bytes(new ScreenshotData); 133 ScreenshotDataPtr read_bytes(new ScreenshotData);
94 std::string filename = screenshot_path.substr( 134 int64 file_size = 0;
95 strlen(kSavedScreenshotsBasePath));
96 135
97 url_canon::RawCanonOutputT<char16> decoded; 136 if (error != gdata::GDATA_FILE_OK ||
98 url_util::DecodeURLEscapeSequences( 137 file_type != gdata::REGULAR_FILE ||
99 filename.data(), filename.size(), &decoded); 138 !file_util::GetFileSize(file, &file_size)) {
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)) {
109 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); 139 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes);
110 return; 140 return;
111 } 141 }
112 142
113 read_bytes->resize(file_size); 143 read_bytes->resize(file_size);
114 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()), 144 if (!file_util::ReadFile(file, reinterpret_cast<char*>(&read_bytes->front()),
115 static_cast<int>(file_size))) 145 static_cast<int>(file_size)))
116 read_bytes->clear(); 146 read_bytes->clear();
117 147
118 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes); 148 CacheAndSendScreenshot(screenshot_path, request_id, read_bytes);
119 } 149 }
120 #endif 150 #endif
121 151
122 void ScreenshotSource::CacheAndSendScreenshot( 152 void ScreenshotSource::CacheAndSendScreenshot(
123 const std::string& screenshot_path, 153 const std::string& screenshot_path,
124 int request_id, 154 int request_id,
125 ScreenshotDataPtr bytes) { 155 ScreenshotDataPtr bytes) {
126 cached_screenshots_[screenshot_path] = bytes; 156 cached_screenshots_[screenshot_path] = bytes;
127 SendResponse(request_id, new base::RefCountedBytes(*bytes)); 157 SendResponse(request_id, new base::RefCountedBytes(*bytes));
128 } 158 }
OLDNEW
« no previous file with comments | « 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