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/common/extensions/extension_file_util.h" | 5 #include "chrome/common/extensions/extension_file_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/json/json_file_value_serializer.h" | 12 #include "base/json/json_file_value_serializer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/scoped_temp_dir.h" | 16 #include "base/scoped_temp_dir.h" |
17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_action.h" | 23 #include "chrome/common/extensions/extension_action.h" |
24 #include "chrome/common/extensions/extension_l10n_util.h" | 24 #include "chrome/common/extensions/extension_l10n_util.h" |
25 #include "chrome/common/extensions/extension_manifest_constants.h" | 25 #include "chrome/common/extensions/extension_manifest_constants.h" |
26 #include "chrome/common/extensions/extension_messages.h" | 26 #include "chrome/common/extensions/extension_messages.h" |
27 #include "chrome/common/extensions/extension_resource.h" | 27 #include "chrome/common/extensions/extension_resource.h" |
28 #include "chrome/common/extensions/message_bundle.h" | 28 #include "chrome/common/extensions/message_bundle.h" |
| 29 #include "grit/component_extension_resources_map.h" |
29 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 31 #include "grit/theme_resources.h" |
30 #include "net/base/escape.h" | 32 #include "net/base/escape.h" |
31 #include "net/base/file_stream.h" | 33 #include "net/base/file_stream.h" |
32 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
33 | 35 |
34 using extensions::Extension; | 36 using extensions::Extension; |
35 | 37 |
36 namespace errors = extension_manifest_errors; | 38 namespace errors = extension_manifest_errors; |
37 | 39 |
38 namespace { | 40 namespace { |
39 | 41 |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 if (result == SUCCESS) | 786 if (result == SUCCESS) |
785 return temp_path; | 787 return temp_path; |
786 | 788 |
787 return FilePath(); | 789 return FilePath(); |
788 } | 790 } |
789 | 791 |
790 void DeleteFile(const FilePath& path, bool recursive) { | 792 void DeleteFile(const FilePath& path, bool recursive) { |
791 file_util::Delete(path, recursive); | 793 file_util::Delete(path, recursive); |
792 } | 794 } |
793 | 795 |
| 796 bool IsComponentExtensionResource(const Extension* extension, |
| 797 const FilePath& resource_path, |
| 798 int* resource_id) { |
| 799 static const GritResourceMap kExtraComponentExtensionResources[] = { |
| 800 {"web_store/webstore_icon_128.png", IDR_WEBSTORE_ICON}, |
| 801 {"web_store/webstore_icon_16.png", IDR_WEBSTORE_ICON_16}, |
| 802 {"chrome_app/product_logo_128.png", IDR_PRODUCT_LOGO_128}, |
| 803 {"chrome_app/product_logo_16.png", IDR_PRODUCT_LOGO_16}, |
| 804 }; |
| 805 static const size_t kExtraComponentExtensionResourcesSize = |
| 806 arraysize(kExtraComponentExtensionResources); |
| 807 |
| 808 if (extension->location() != Extension::COMPONENT) |
| 809 return false; |
| 810 |
| 811 FilePath directory_path = extension->path(); |
| 812 FilePath relative_path = directory_path.BaseName().Append(resource_path); |
| 813 relative_path = relative_path.NormalizePathSeparators(); |
| 814 |
| 815 // TODO(tc): Make a map of FilePath -> resource ids so we don't have to |
| 816 // covert to FilePaths all the time. This will be more useful as we add |
| 817 // more resources. |
| 818 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) { |
| 819 FilePath resource_path = |
| 820 FilePath().AppendASCII(kComponentExtensionResources[i].name); |
| 821 resource_path = resource_path.NormalizePathSeparators(); |
| 822 |
| 823 if (relative_path == resource_path) { |
| 824 *resource_id = kComponentExtensionResources[i].value; |
| 825 return true; |
| 826 } |
| 827 } |
| 828 for (size_t i = 0; i < kExtraComponentExtensionResourcesSize; ++i) { |
| 829 FilePath resource_path = |
| 830 FilePath().AppendASCII(kExtraComponentExtensionResources[i].name); |
| 831 resource_path = resource_path.NormalizePathSeparators(); |
| 832 |
| 833 if (relative_path == resource_path) { |
| 834 *resource_id = kExtraComponentExtensionResources[i].value; |
| 835 return true; |
| 836 } |
| 837 } |
| 838 return false; |
| 839 } |
| 840 |
794 } // namespace extension_file_util | 841 } // namespace extension_file_util |
OLD | NEW |