OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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/extensions/chrome_component_extension_resource_manager. h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/path_service.h" | |
9 #include "chrome/common/chrome_paths.h" | |
10 #include "grit/chrome_unscaled_resources.h" | |
11 #include "grit/component_extension_resources_map.h" | |
12 #include "grit/theme_resources.h" | |
13 | |
14 #if defined(OS_CHROMEOS) | |
15 #include "ui/file_manager/file_manager_resource_util.h" | |
16 #endif | |
17 | |
18 #if defined(USE_AURA) | |
19 #include "ui/keyboard/keyboard_util.h" | |
20 #endif | |
21 | |
22 namespace extensions { | |
23 | |
24 ChromeComponentExtensionResourceManager:: | |
25 ChromeComponentExtensionResourceManager() { | |
26 static const GritResourceMap kExtraComponentExtensionResources[] = { | |
27 {"web_store/webstore_icon_128.png", IDR_WEBSTORE_ICON}, | |
28 {"web_store/webstore_icon_16.png", IDR_WEBSTORE_ICON_16}, | |
29 {"chrome_app/product_logo_128.png", IDR_PRODUCT_LOGO_128}, | |
30 {"chrome_app/product_logo_16.png", IDR_PRODUCT_LOGO_16}, | |
31 #if defined(ENABLE_SETTINGS_APP) | |
32 {"settings_app/settings_app_icon_128.png", IDR_SETTINGS_APP_ICON_128}, | |
33 {"settings_app/settings_app_icon_16.png", IDR_SETTINGS_APP_ICON_16}, | |
34 {"settings_app/settings_app_icon_32.png", IDR_SETTINGS_APP_ICON_32}, | |
35 {"settings_app/settings_app_icon_48.png", IDR_SETTINGS_APP_ICON_48}, | |
36 #endif | |
37 }; | |
38 | |
39 AddComponentResourceEntries( | |
40 kComponentExtensionResources, | |
41 kComponentExtensionResourcesSize); | |
42 AddComponentResourceEntries( | |
43 kExtraComponentExtensionResources, | |
44 arraysize(kExtraComponentExtensionResources)); | |
45 #if defined(OS_CHROMEOS) | |
46 size_t file_manager_resource_size; | |
47 const GritResourceMap* file_manager_resources = | |
48 file_manager::GetFileManagerResources(&file_manager_resource_size); | |
49 AddComponentResourceEntries( | |
50 file_manager_resources, | |
51 file_manager_resource_size); | |
52 | |
53 size_t keyboard_resource_size; | |
54 const GritResourceMap* keyboard_resources = | |
55 keyboard::GetKeyboardExtensionResources(&keyboard_resource_size); | |
56 AddComponentResourceEntries( | |
57 keyboard_resources, | |
58 keyboard_resource_size); | |
59 #endif | |
60 } | |
61 | |
62 ChromeComponentExtensionResourceManager:: | |
63 ~ChromeComponentExtensionResourceManager() {} | |
64 | |
65 bool ChromeComponentExtensionResourceManager::IsComponentExtensionResource( | |
66 const base::FilePath& extension_path, | |
67 const base::FilePath& resource_path, | |
68 int* resource_id) { | |
69 base::FilePath directory_path = extension_path; | |
70 base::FilePath resources_dir; | |
71 base::FilePath relative_path; | |
72 if (!PathService::Get(chrome::DIR_RESOURCES, &resources_dir) || | |
73 !resources_dir.AppendRelativePath(directory_path, &relative_path)) { | |
74 return false; | |
75 } | |
76 relative_path = relative_path.Append(resource_path); | |
77 relative_path = relative_path.NormalizePathSeparators(); | |
78 | |
79 std::map<base::FilePath, int>::const_iterator entry = | |
80 path_to_resource_id_.find(relative_path); | |
81 if (entry != path_to_resource_id_.end()) | |
82 *resource_id = entry->second; | |
83 | |
84 return entry != path_to_resource_id_.end(); | |
85 } | |
86 | |
87 void ChromeComponentExtensionResourceManager::AddComponentResourceEntries( | |
James Cook
2014/06/17 22:01:04
I think there was a comment for this function in t
Jun Mukai
2014/06/17 23:53:02
file removed -- also added (copied) the old commen
| |
88 const GritResourceMap* entries, | |
89 size_t size) { | |
90 for (size_t i = 0; i < size; ++i) { | |
91 base::FilePath resource_path = base::FilePath().AppendASCII( | |
92 entries[i].name); | |
93 resource_path = resource_path.NormalizePathSeparators(); | |
94 | |
95 DCHECK(path_to_resource_id_.find(resource_path) == | |
96 path_to_resource_id_.end()); | |
97 path_to_resource_id_[resource_path] = entries[i].value; | |
98 } | |
99 } | |
100 | |
101 } // namespace extensions | |
OLD | NEW |