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

Side by Side Diff: chrome/browser/ui/webui/chromeos/gdata_source.cc

Issue 9965069: MHTML loading fix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | « no previous file | net/base/mime_util.cc » ('j') | 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/chromeos/gdata_source.h" 5 #include "chrome/browser/ui/webui/chromeos/gdata_source.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
12 #include "base/file_util.h" 13 #include "base/file_util.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/sequenced_worker_pool.h" 15 #include "base/threading/sequenced_worker_pool.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 17 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
17 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" 18 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
18 #include "chrome/browser/history/top_sites.h" 19 #include "chrome/browser/history/top_sites.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "net/base/escape.h" 23 #include "net/base/escape.h"
23 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
24 25
25 using content::BrowserThread; 26 using content::BrowserThread;
26 27
27 namespace { 28 namespace {
28 29
29 const int kBufferSize = 8*1024; 30 const int kBufferSize = 8*1024;
30 const char kMimeTypeOctetStream[] = "application/octet-stream"; 31 const char kMimeTypeOctetStream[] = "application/octet-stream";
31 const net::UnescapeRule::Type kUrlPathUnescapeMask = 32 const net::UnescapeRule::Type kUrlPathUnescapeMask =
32 net::UnescapeRule::SPACES | 33 net::UnescapeRule::SPACES |
33 net::UnescapeRule::URL_SPECIAL_CHARS | 34 net::UnescapeRule::URL_SPECIAL_CHARS |
34 net::UnescapeRule::CONTROL_CHARS; 35 net::UnescapeRule::CONTROL_CHARS;
35 36
37 const struct MimeTypeReplacement {
38 const char* original_type;
39 const char* new_type;
40 } kMimeTypeReplacements[] = {
41 {"message/rfc822", "multipart/related"}
42 };
43
36 // Helper function that reads file size. 44 // Helper function that reads file size.
37 void GetFileSizeOnIOThreadPool(const FilePath& file_path, 45 void GetFileSizeOnIOThreadPool(const FilePath& file_path,
38 int64* file_size) { 46 int64* file_size) {
39 if (!file_util::GetFileSize(file_path, file_size)) 47 if (!file_util::GetFileSize(file_path, file_size))
40 *file_size = 0; 48 *file_size = 0;
41 } 49 }
42 50
51 std::string FixupMimeType(const std::string& type) {
52 for (size_t i = 0; i < arraysize(kMimeTypeReplacements); i++) {
53 if (type == kMimeTypeReplacements[i].original_type)
54 return kMimeTypeReplacements[i].new_type;
55 }
56 return type;
57 }
58
43 bool ParseGDataUrlPath(const std::string& path, 59 bool ParseGDataUrlPath(const std::string& path,
44 std::string* resource_id, 60 std::string* resource_id,
45 std::string* file_name) { 61 std::string* file_name) {
46 std::vector<std::string> components; 62 std::vector<std::string> components;
47 FilePath url_path= FilePath::FromUTF8Unsafe(path); 63 FilePath url_path= FilePath::FromUTF8Unsafe(path);
48 url_path.GetComponents(&components); 64 url_path.GetComponents(&components);
49 if (components.size() != 2) { 65 if (components.size() != 2) {
50 LOG(WARNING) << "Invalid path: " << url_path.value(); 66 LOG(WARNING) << "Invalid path: " << url_path.value();
51 return false; 67 return false;
52 } 68 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 if (!system_service_) 167 if (!system_service_)
152 return kMimeTypeOctetStream; 168 return kMimeTypeOctetStream;
153 169
154 std::string resource_id; 170 std::string resource_id;
155 std::string unused_file_name; 171 std::string unused_file_name;
156 if (!ParseGDataUrlPath(path, &resource_id, &unused_file_name)) 172 if (!ParseGDataUrlPath(path, &resource_id, &unused_file_name))
157 return kMimeTypeOctetStream; 173 return kMimeTypeOctetStream;
158 174
159 GetFileMimeTypeDelegate delegate; 175 GetFileMimeTypeDelegate delegate;
160 system_service_->file_system()->FindFileByResourceIdSync(resource_id, 176 system_service_->file_system()->FindFileByResourceIdSync(resource_id,
161 &delegate); 177 &delegate);
162 if (delegate.mime_type().empty()) 178 if (delegate.mime_type().empty())
163 return kMimeTypeOctetStream; 179 return kMimeTypeOctetStream;
164 180
165 return delegate.mime_type(); 181 return FixupMimeType(delegate.mime_type());
166 } 182 }
167 183
168 184
169 void GDataSource::OnGetFileForResourceId( 185 void GDataSource::OnGetFileForResourceId(
170 int request_id, 186 int request_id,
171 base::PlatformFileError error, 187 base::PlatformFileError error,
172 const FilePath& file_path, 188 const FilePath& file_path,
173 const std::string& mime_type, 189 const std::string& mime_type,
174 GDataFileType file_type) { 190 GDataFileType file_type) {
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 if (read_value != net::ERR_IO_PENDING) { 297 if (read_value != net::ERR_IO_PENDING) {
282 LOG(WARNING) << "Failed to read file for request " 298 LOG(WARNING) << "Failed to read file for request "
283 << context->file_path.value(); 299 << context->file_path.value();
284 SendResponse(context->request_id, 300 SendResponse(context->request_id,
285 reinterpret_cast<RefCountedMemory*>(NULL)); 301 reinterpret_cast<RefCountedMemory*>(NULL));
286 return; 302 return;
287 } 303 }
288 } 304 }
289 305
290 } // namespace gdata 306 } // namespace gdata
OLDNEW
« no previous file with comments | « no previous file | net/base/mime_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698