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/shared_resources_data_source.h" | 5 #include "chrome/browser/ui/webui/shared_resources_data_source.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
12 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
14 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
15 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
16 #include "grit/shared_resources.h" | 15 #include "grit/shared_resources.h" |
17 #include "grit/shared_resources_map.h" | 16 #include "grit/shared_resources_map.h" |
18 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
19 #include "grit/ui_resources.h" | 18 #include "grit/ui_resources.h" |
20 #include "net/base/mime_util.h" | 19 #include "net/base/mime_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
22 | 21 |
23 namespace { | 22 namespace { |
(...skipping 20 matching lines...) Expand all Loading... |
44 SharedResourcesDataSource::SharedResourcesDataSource() { | 43 SharedResourcesDataSource::SharedResourcesDataSource() { |
45 } | 44 } |
46 | 45 |
47 SharedResourcesDataSource::~SharedResourcesDataSource() { | 46 SharedResourcesDataSource::~SharedResourcesDataSource() { |
48 } | 47 } |
49 | 48 |
50 std::string SharedResourcesDataSource::GetSource() { | 49 std::string SharedResourcesDataSource::GetSource() { |
51 return chrome::kChromeUIResourcesHost; | 50 return chrome::kChromeUIResourcesHost; |
52 } | 51 } |
53 | 52 |
54 void SharedResourcesDataSource::StartDataRequest(const std::string& path, | 53 void SharedResourcesDataSource::StartDataRequest( |
55 bool is_incognito, | 54 const std::string& path, |
56 int request_id) { | 55 bool is_incognito, |
| 56 const content::URLDataSource::GotDataCallback& callback) { |
57 int idr = PathToIDR(path); | 57 int idr = PathToIDR(path); |
58 DCHECK_NE(-1, idr) << " path: " << path; | 58 DCHECK_NE(-1, idr) << " path: " << path; |
59 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 59 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
60 scoped_refptr<base::RefCountedStaticMemory> bytes( | 60 scoped_refptr<base::RefCountedStaticMemory> bytes( |
61 rb.LoadDataResourceBytes(idr)); | 61 rb.LoadDataResourceBytes(idr)); |
62 | 62 |
63 url_data_source()->SendResponse(request_id, bytes); | 63 callback.Run(bytes); |
64 } | 64 } |
65 | 65 |
66 std::string SharedResourcesDataSource::GetMimeType( | 66 std::string SharedResourcesDataSource::GetMimeType( |
67 const std::string& path) const { | 67 const std::string& path) const { |
68 // Requests should not block on the disk! On Windows this goes to the | 68 // Requests should not block on the disk! On Windows this goes to the |
69 // registry. | 69 // registry. |
70 // http://code.google.com/p/chromium/issues/detail?id=59849 | 70 // http://code.google.com/p/chromium/issues/detail?id=59849 |
71 base::ThreadRestrictions::ScopedAllowIO allow_io; | 71 base::ThreadRestrictions::ScopedAllowIO allow_io; |
72 | 72 |
73 std::string mime_type; | 73 std::string mime_type; |
74 net::GetMimeTypeFromFile(FilePath().AppendASCII(path), &mime_type); | 74 net::GetMimeTypeFromFile(FilePath().AppendASCII(path), &mime_type); |
75 return mime_type; | 75 return mime_type; |
76 } | 76 } |
OLD | NEW |