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.
5 #include "chrome/browser/extensions/chrome_component_extension_resource_manager.h"
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"
14 #if defined(OS_CHROMEOS)
15 #include "ui/file_manager/file_manager_resource_util.h"
19 #include "ui/keyboard/keyboard_util.h"
22 namespace extensions
{
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
},
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
);
53 size_t keyboard_resource_size
;
54 const GritResourceMap
* keyboard_resources
=
55 keyboard::GetKeyboardExtensionResources(&keyboard_resource_size
);
56 AddComponentResourceEntries(
58 keyboard_resource_size
);
62 ChromeComponentExtensionResourceManager::
63 ~ChromeComponentExtensionResourceManager() {}
65 bool ChromeComponentExtensionResourceManager::IsComponentExtensionResource(
66 const base::FilePath
& extension_path
,
67 const base::FilePath
& resource_path
,
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
)) {
76 relative_path
= relative_path
.Append(resource_path
);
77 relative_path
= relative_path
.NormalizePathSeparators();
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
;
84 return entry
!= path_to_resource_id_
.end();
87 void ChromeComponentExtensionResourceManager::AddComponentResourceEntries(
88 const GritResourceMap
* entries
,
90 for (size_t i
= 0; i
< size
; ++i
) {
91 base::FilePath resource_path
= base::FilePath().AppendASCII(
93 resource_path
= resource_path
.NormalizePathSeparators();
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
;
101 } // namespace extensions