OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/shared_resources_data_source.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/memory/ref_counted_memory.h" | |
9 #include "base/threading/thread_restrictions.h" | |
10 #include "content/public/common/content_client.h" | |
11 #include "content/public/common/url_constants.h" | |
12 #include "grit/webui_resources_map.h" | |
13 #include "net/base/mime_util.h" | |
14 | |
15 namespace { | |
16 | |
17 int PathToIDR(const std::string& path) { | |
18 int idr = -1; | |
19 for (size_t i = 0; i < kWebuiResourcesSize; ++i) { | |
20 if (kWebuiResources[i].name == path) { | |
21 idr = kWebuiResources[i].value; | |
22 break; | |
23 } | |
24 } | |
25 | |
26 return idr; | |
27 } | |
28 | |
29 } // namespace | |
30 | |
31 SharedResourcesDataSource::SharedResourcesDataSource() { | |
32 } | |
33 | |
34 SharedResourcesDataSource::~SharedResourcesDataSource() { | |
35 } | |
36 | |
37 std::string SharedResourcesDataSource::GetSource() { | |
38 return chrome::kChromeUIResourcesHost; | |
39 } | |
40 | |
41 void SharedResourcesDataSource::StartDataRequest( | |
42 const std::string& path, | |
43 bool is_incognito, | |
44 const content::URLDataSource::GotDataCallback& callback) { | |
45 int idr = PathToIDR(path); | |
46 DCHECK_NE(-1, idr) << " path: " << path; | |
47 scoped_refptr<base::RefCountedStaticMemory> bytes( | |
48 content::GetContentClient()->GetDataResourceBytes(idr)); | |
49 | |
50 callback.Run(bytes); | |
51 } | |
52 | |
53 std::string SharedResourcesDataSource::GetMimeType( | |
54 const std::string& path) const { | |
55 // Requests should not block on the disk! On POSIX this goes to disk. | |
56 // http://code.google.com/p/chromium/issues/detail?id=59849 | |
57 | |
58 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
59 std::string mime_type; | |
60 net::GetMimeTypeFromFile(FilePath().AppendASCII(path), &mime_type); | |
61 return mime_type; | |
62 } | |
OLD | NEW |