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

Side by Side Diff: chrome/browser/dom_ui/shared_resources_data_source.cc

Issue 2817026: Move the files in resources/shared/ into resources.pak (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Rebase after tony's commit Created 10 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 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/dom_ui/shared_resources_data_source.h"
6
7 #include "app/resource_bundle.h"
8 #include "base/singleton.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_thread.h"
11 #include "chrome/browser/dom_ui/chrome_url_data_manager.h"
12 #include "chrome/browser/io_thread.h"
13 #include "chrome/common/url_constants.h"
14 #include "grit/generated_resources.h"
15 #include "grit/shared_resources.h"
16 #include "grit/shared_resources_map.h"
17 #include "grit/app_resources.h"
18 #include "grit/theme_resources.h"
19 #include "net/base/mime_util.h"
20
21 namespace {
22
23 int PathToIDR(const std::string& path) {
24 int idr = -1;
25 if (path == "images/bookmark_bar_folder_mac.png") {
26 idr = IDR_BOOKMARK_BAR_FOLDER;
27 } else if (path == "images/folder_closed.png") {
28 idr = IDR_FOLDER_CLOSED;
29 } else if (path == "images/folder_closed_rtl.png") {
30 idr = IDR_FOLDER_CLOSED_RTL;
31 } else if (path == "images/folder_open.png") {
32 idr = IDR_FOLDER_OPEN;
33 } else if (path == "images/folder_open_rtl.png") {
34 idr = IDR_FOLDER_OPEN_RTL;
35 } else {
36 // The name of the files in the grd list are prefixed with the following
37 // directory:
38 std::string key("shared/");
39 key += path;
40
41 for (size_t i = 0; i < kSharedResourcesSize; ++i) {
42 if (kSharedResources[i].name == key) {
43 idr = kSharedResources[i].value;
44 break;
45 }
46 }
47 }
48
49 return idr;
50 }
51
52 } // namespace
53
54 // static
55 void SharedResourcesDataSource::Register() {
56 SharedResourcesDataSource* source = new SharedResourcesDataSource();
57 ChromeThread::PostTask(
58 ChromeThread::IO, FROM_HERE,
59 NewRunnableMethod(
60 Singleton<ChromeURLDataManager>::get(),
61 &ChromeURLDataManager::AddDataSource,
62 make_scoped_refptr(source)));
63 }
64
65 SharedResourcesDataSource::SharedResourcesDataSource()
66 : DataSource(chrome::kChromeUIResourcesHost, NULL) {
67 }
68
69 SharedResourcesDataSource::~SharedResourcesDataSource() {
70 }
71
72 void SharedResourcesDataSource::StartDataRequest(const std::string& path,
73 bool is_off_the_record,
74 int request_id) {
75 int idr = PathToIDR(path);
76 DCHECK_NE(-1, idr);
77 const ResourceBundle& rb = ResourceBundle::GetSharedInstance();
78 scoped_refptr<RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes(idr));
79 SendResponse(request_id, bytes);
80 }
81
82 std::string SharedResourcesDataSource::GetMimeType(
83 const std::string& path) const {
84 std::string mime_type;
85 net::GetMimeTypeFromFile(FilePath().AppendASCII(path), &mime_type);
86 return mime_type;
87 }
88
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/shared_resources_data_source.h ('k') | chrome/browser/resources/shared_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698