MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / chrome / browser / extensions / chrome_component_extension_resource_manager.cc
blobb531556895359a552457be16f51e71f30aaa8424
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"
16 #endif
18 #if defined(USE_AURA)
19 #include "ui/keyboard/keyboard_util.h"
20 #endif
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},
36 #endif
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(
57 keyboard_resources,
58 keyboard_resource_size);
59 #endif
62 ChromeComponentExtensionResourceManager::
63 ~ChromeComponentExtensionResourceManager() {}
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;
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,
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();
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